Skip to content

Commit edd4683

Browse files
committed
Add TGEDeployer contract with tests
1 parent e8c09ce commit edd4683

File tree

3 files changed

+1076
-0
lines changed

3 files changed

+1076
-0
lines changed

contracts/deploy/TGEDeployer.sol

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "../LifCrowdsale.sol";
4+
5+
/**
6+
@title TGEDeployer, A deployer contract for the Winding Tree TGE
7+
8+
This contract is used to create a crowdsale and issue presale tokens in batches
9+
it will also set the weiPerUSD and transfer ownership, after that everything is
10+
ready for the TGE to succed.
11+
*/
12+
contract TGEDeployer {
13+
14+
LifCrowdsale public crowdsale;
15+
address public wallet;
16+
address public owner;
17+
18+
function TGEDeployer(
19+
uint256 startTimestamp,
20+
uint256 end1Timestamp,
21+
uint256 end2Timestamp,
22+
uint256 rate1,
23+
uint256 rate2,
24+
uint256 setWeiLockSeconds,
25+
address foundationWallet,
26+
address foundersWallet
27+
) public {
28+
crowdsale = new LifCrowdsale(
29+
startTimestamp, end1Timestamp, end2Timestamp, rate1, rate2,
30+
setWeiLockSeconds, foundationWallet, foundersWallet
31+
);
32+
wallet = foundationWallet;
33+
owner = msg.sender;
34+
}
35+
36+
// Mint a batch of presale tokens
37+
function addPresaleTokens(address[] contributors, uint256[] values, uint256 rate) public {
38+
require(msg.sender == owner);
39+
require(contributors.length == values.length);
40+
for (uint32 i = 0; i < contributors.length; i ++) {
41+
crowdsale.addPrivatePresaleTokens(contributors[i], values[i], rate);
42+
}
43+
}
44+
45+
// Set the wei per USD in the crowdsale and then transfer ownership to foundation
46+
function finish(uint256 weiPerUSDinTGE) public {
47+
require(msg.sender == owner);
48+
crowdsale.setWeiPerUSDinTGE(weiPerUSDinTGE);
49+
crowdsale.transferOwnership(wallet);
50+
}
51+
52+
}

test/deploy/TGEDeployer.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
var LifCrowdsale = artifacts.require('./LifCrowdsale.sol'),
2+
LifToken = artifacts.require('./LifToken.sol'),
3+
TGEDeployer = artifacts.require('./deploy/TGEDeployer.sol');
4+
5+
let help = require('../helpers');
6+
7+
var BigNumber = web3.BigNumber;
8+
9+
require('chai')
10+
.use(require('chai-bignumber')(BigNumber))
11+
.should();
12+
13+
var { duration } = require('../helpers/increaseTime');
14+
const _ = require('lodash');
15+
16+
const TGEDistribution = require('./TGEDistribution');
17+
18+
contract('TGE Deployer', function ([deployAddress, foundationWallet, foundersWallet]) {
19+
it('Deploy a TGE correctly', async function () {
20+
const startTimestamp = new Date('Sun, 28 Jan 2018 8:0:00 GMT').getTime() / 1000;
21+
const end1Timestamp = new Date('Sun, 28 Jan 2018 9:0:00 GMT').getTime() / 1000;
22+
const end2Timestamp = new Date('Sun, 28 Jan 2018 10:0:00 GMT').getTime() / 1000;
23+
const rate1 = 1000;
24+
const rate2 = 900;
25+
const setWeiLockSeconds = duration.hours(1);
26+
var totalSupply = new BigNumber(0);
27+
const weiPerUSDinTGE = web3.toWei(1 / 1000);
28+
29+
const deployer = await TGEDeployer.new(
30+
startTimestamp, end1Timestamp, end2Timestamp, rate1,
31+
rate2, setWeiLockSeconds, foundationWallet, foundersWallet,
32+
{ from: deployAddress }
33+
);
34+
35+
const crowdsale = LifCrowdsale.at(await deployer.crowdsale());
36+
const token = LifToken.at(await crowdsale.token());
37+
38+
help.debug('Data to create Deployer contract:');
39+
help.debug(deployer.deployedBytecode);
40+
help.debug('--------------------------------------------------');
41+
42+
// Check values
43+
assert.equal(startTimestamp, parseInt(await crowdsale.startTimestamp.call()));
44+
assert.equal(end1Timestamp, parseInt(await crowdsale.end1Timestamp.call()));
45+
assert.equal(end2Timestamp, parseInt(await crowdsale.end2Timestamp.call()));
46+
assert.equal(rate1, parseInt(await crowdsale.rate1.call()));
47+
assert.equal(rate2, parseInt(await crowdsale.rate2.call()));
48+
assert.equal(foundationWallet, parseInt(await crowdsale.foundationWallet.call()));
49+
assert.equal(foundersWallet, parseInt(await crowdsale.foundersWallet.call()));
50+
51+
var processStage = async function (stage) {
52+
// Check right amount of contributos and values
53+
assert.equal(stage.contributors.length, stage.values.length);
54+
var stageETH = new BigNumber(0);
55+
56+
// Parse ETH to wei
57+
stage.values.map(function (value, i) {
58+
stageETH = stageETH.add(stage.values[i]);
59+
stage.values[i] = web3.toWei(stage.values[i]);
60+
});
61+
62+
// Add TGE stage
63+
const contributorsChunks = _.chunk(stage.contributors, 150);
64+
const valuesChunks = _.chunk(stage.values, 150);
65+
var txs = [];
66+
for (var i = 0; i < contributorsChunks.length; i++) {
67+
const data = await deployer.contract.addPresaleTokens.getData(
68+
contributorsChunks[i], valuesChunks[i], stage.rate
69+
);
70+
await deployer.addPresaleTokens(
71+
contributorsChunks[i], valuesChunks[i], stage.rate,
72+
{ from: deployAddress }
73+
);
74+
txs.push(data);
75+
}
76+
77+
// Calculate tokens and check total supply
78+
const stageTokens = new BigNumber(stageETH).mul(stage.rate);
79+
totalSupply = totalSupply.add(stageTokens);
80+
help.debug('TXs for stage', stage.name);
81+
txs.map(function (tx, i) { help.debug('TX [', i, ']', tx); });
82+
help.debug('--------------------------------------------------');
83+
totalSupply.should.be.bignumber
84+
.equal(help.lifWei2Lif(await token.totalSupply()), 2);
85+
};
86+
87+
await processStage(TGEDistribution[0]);
88+
await processStage(TGEDistribution[1]);
89+
await processStage(TGEDistribution[2]);
90+
await processStage(TGEDistribution[3]);
91+
await processStage(TGEDistribution[4]);
92+
93+
const finalizeData = await deployer.contract.finish.getData(weiPerUSDinTGE);
94+
95+
await deployer.finish(weiPerUSDinTGE, { from: deployAddress });
96+
97+
help.debug('Data to finalize Deployer:');
98+
help.debug(finalizeData);
99+
help.debug('--------------------------------------------------');
100+
101+
assert.equal(foundationWallet, parseInt(await crowdsale.owner.call()));
102+
assert.equal(weiPerUSDinTGE, parseInt(await crowdsale.weiPerUSDinTGE.call()));
103+
104+
// Check final total supply
105+
totalSupply.should.be.bignumber
106+
.equal(help.lifWei2Lif(await token.totalSupply()), 2);
107+
});
108+
});

0 commit comments

Comments
 (0)