Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
integrate tare in factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Le Bars committed Jul 20, 2018
1 parent 65adb76 commit 52b2a69
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ pragma solidity ^0.4.23;

import "./EIP20Interface.sol";

contract RGEToken is EIP20Interface {
contract RGETokenInterface is EIP20Interface {

mapping (address => uint256) public balances;

string public name;
string public symbol;
uint8 public decimals;
Expand Down
12 changes: 7 additions & 5 deletions contracts/RougeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import "./RougeRegistry.sol";
contract RougeFactory is RougeRegistry {

// The Rouge Token contract address
RGEToken public rge;

RGETokenInterface public rge;
uint256 public tare;

address owner;

mapping (address => uint256) public deposit; // per campaign ...
Expand All @@ -30,15 +31,16 @@ contract RougeFactory is RougeRegistry {
_;
}

function setParams ( address _rge ) onlyBy(owner) public {
rge = RGEToken(_rge);
function setParams (address _rge, uint256 _tare) onlyBy(owner) public {
rge = RGETokenInterface(_rge);
tare = _tare;
}

event NewRougeCampaign(address issuer, address campaign, uint32 _issuance);

function createCampaign(address _issuer, uint32 _issuance, uint256 _tokens) public {

SimpleRougeCampaign c = new SimpleRougeCampaign(_issuer, _issuance, rge, this);
SimpleRougeCampaign c = new SimpleRougeCampaign(_issuer, _issuance, rge, tare, this);

// XXX no need to check rge set ? transfer would revert ...
rge.transfer(c, _tokens); // transfer tokens to the campaign contract ...
Expand Down
29 changes: 29 additions & 0 deletions contracts/RougeFactoryInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Abstract contract for Rouge Factory contracts
*/

pragma solidity ^0.4.23;

import "./RGETokenInterface.sol";

contract RougeFactoryInterface {

// The Rouge Token contract address
RGETokenInterface public rge;

// Price in RGE of the tare deposit (per token)
uint256 public tare;

// owner of the factory
address owner;

// owner can (re)set tare price or RGE contract address
function setParams (address _rge, uint256 _tare) public;

event NewRougeCampaign(address issuer, address campaign, uint32 _issuance);

function createCampaign(address _issuer, uint32 _issuance, uint256 _tokens) public;

}
6 changes: 0 additions & 6 deletions contracts/RougeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ contract RougeRegistry is RougeRegistryInterface {

string public version = 'v0.2';

address owner;

address[] issuers;
address[] all_campaigns;

mapping (address => bool) public is_issuer;
mapping (address => bool) public is_campaign;
mapping (address => address[]) campaigns;

constructor() public {
owner = msg.sender;
}

function add_campaign(address _issuer, address _a) internal {
if (!is_issuer[_issuer]) {
is_issuer[_issuer] = true;
Expand Down
38 changes: 24 additions & 14 deletions contracts/SimpleRougeCampaign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

pragma solidity ^0.4.23;

import "./RGEInterface.sol";
import "./RGETokenInterface.sol";

import "./RougeFactoryInterface.sol";

contract SimpleRougeCampaign {

string public version = 'v0.7';

// The Rouge Token contract address
RGEToken public rge;
address public factory;
RGETokenInterface public rge;

// Factory address & tare settings (1 RGE)
RougeFactoryInterface public factory;
uint256 public tare;

address issuer; // XXX todo owner = initial potential issuer, issuer can be changed ?

Expand All @@ -28,11 +33,12 @@ contract SimpleRougeCampaign {
uint32 public acquired = 0;
uint32 public redeemed = 0;

constructor(address _issuer, uint32 _issuance, address _rge, address _factory) public {
constructor(address _issuer, uint32 _issuance, address _rge, uint256 _tare, address _factory) public {
issuer = _issuer;
issuance = _issuance;
rge = RGEToken(_rge);
/* factory = RougeFactory(_factory); */
rge = RGETokenInterface(_rge);
tare = _tare;
factory = RougeFactoryInterface(_factory);
}

string public name;
Expand All @@ -41,7 +47,9 @@ contract SimpleRougeCampaign {

function issue(string _name, uint _campaignExpiration) onlyBy(issuer) public {

// XXX check if campaign as any RGE , fail otherwise
// still possible to send RGE post creation, before issuing the campaign
uint256 rgeBalance = rge.balanceOf(this);
require(rgeBalance > issuance * tare);

name = _name;
campaignIssued = true;
Expand Down Expand Up @@ -75,8 +83,8 @@ contract SimpleRougeCampaign {
}

function distributeNote(address _to) CampaignOpen private returns (bool success) {
require(_to != issuer); /* RULE issuer and bearer need to be diffrent */
require(!hasNote(_to)); /* RULE only one note per address (but not bearer) */
require(_to != issuer); /* RULE: issuer and bearer need to be diffrent */
require(!hasNote(_to)); /* RULE: only one note per address (but not bearer) */
if (available > 0) {
available -= 1;
acquired += 1;
Expand Down Expand Up @@ -134,14 +142,16 @@ contract SimpleRougeCampaign {
return redeemNote(msg.sender);
}

function letsBurn(uint256 _value) onlyBy(issuer) public {

rge.burn(_value);

}
/* function letsBurn(uint256 _value) onlyBy(issuer) public { */
/* rge.burn(_value); */
/* } */

function kill() onlyBy(issuer) public {

// burn the tare

rge.burn(tare * (issuance - redeemed));

// transfer all remaining tokens and ETH to the issuer

uint256 rgeBalance = rge.balanceOf(this);
Expand Down
10 changes: 6 additions & 4 deletions contracts/TestRGEToken.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
Same interface as RGEToken but for test purpose only
Same interface/code as RGEToken but for test purpose only
*/
with a giveMeRGE faucet like function...
import "./EIP20.sol";
*/

pragma solidity ^0.4.23;

import "./EIP20.sol";

contract TestRGEToken is EIP20 {

/* ERC20 */
Expand All @@ -32,7 +34,7 @@ contract TestRGEToken is EIP20 {
balances[owner] = totalSupply;
}

function giveMeRGE(uint32 _value) public returns (bool success) {
function giveMeRGE(uint256 _value) public returns (bool success) {
require(balances[owner] >= _value);
balances[owner] -= _value;
balances[msg.sender] += _value;
Expand Down
2 changes: 1 addition & 1 deletion migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async function(deployer) {

results = await Promise.all([
rge.setFactory(factory.address),
factory.setParams(rge.address)
factory.setParams(rge.address,100000)
]);

};
24 changes: 17 additions & 7 deletions test/RougeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract('RougeFactory', function(accounts) {
it("create a simple Rouge campaign", async function() {

var user = accounts[1];
var tokens = 1000 * 10**6;
var tokens = 1000 * 10**6; /* 1K RGE tokens */

var issuance = 10;
var deposit = 50 * 10**6;
Expand All @@ -19,15 +19,15 @@ contract('RougeFactory', function(accounts) {
let user_balance_before = await rge.balanceOf.call(user);
assert.equal(user_balance_before.toNumber(), 0, "user has no rge tokens to start with");

await await rge.giveMeRGE(tokens, {from: user});
await rge.giveMeRGE(tokens, {from: user});

let user_balance_post = await rge.balanceOf.call(user);
assert.equal(user_balance_post.toNumber(), tokens, "user has receive tokens to create a campaign");

await rge.newCampaign(issuance, deposit, {from: user, gas: 2000000, gasPrice: web3.toWei(1, "gwei")})

let user_balance_after = await rge.balanceOf.call(user);
assert.equal(user_balance_after.toNumber(), tokens - deposit, "user has sent tokens ase deposit to the factory");
assert.equal(user_balance_after.toNumber(), tokens - deposit, "user has sent tokens as a deposit to the factory");

let campaign_count = await factory.get_all_count.call();
assert.equal(campaign_count.toNumber(), 1, "one campaign has been created");
Expand All @@ -42,7 +42,9 @@ contract('RougeFactory', function(accounts) {

});

it("burning tokens test", async function() {
it("simple tare burning test", async function() {

var tare = 0.1 * 10**6; /* price price is 0.1 rge in beta phase */

var user = accounts[2];
var tokens = 1000 * 10**6;
Expand All @@ -53,10 +55,13 @@ contract('RougeFactory', function(accounts) {
let rge = await RGEToken.deployed();
let factory = await Factory.deployed();

await await rge.giveMeRGE(tokens, {from: user});
await rge.giveMeRGE(tokens, {from: user});
await rge.newCampaign(issuance, deposit, {from: user, gas: 2000000, gasPrice: web3.toWei(1, "gwei")})
let campaign_address = await factory.get_campaign.call(user, 0);

let ftare = await factory.tare.call();
assert.equal(ftare.toNumber(), tare, "tare price is set correctly in factory");

let campaign_balance = await rge.balanceOf.call(campaign_address);
assert.equal(campaign_balance.toNumber(), deposit, "the tokens deposit is now in the new campaign contract");

Expand All @@ -68,10 +73,15 @@ contract('RougeFactory', function(accounts) {
let available = await campaign.available.call();
assert.equal(available.toNumber(), issuance, "check notes available after issuance");

await campaign.letsBurn(100, {from: user});
await campaign.kill({from: user});

let burned = tare * issuance;

let campaign_balance_after = await rge.balanceOf.call(campaign_address);
assert.equal(campaign_balance_after.toNumber(), deposit - 100, "the contract has burned 100 tokens");
assert.equal(campaign_balance_after.toNumber(), 0, "the campaign has no more rge after kill");

let user_balance_after = await rge.balanceOf.call(user);
assert.equal(user_balance_after.toNumber(), tokens - burned, "the user has his tokens back less tare for 10 notes");

});

Expand Down

0 comments on commit 52b2a69

Please sign in to comment.