Skip to content

Commit 3b0470f

Browse files
committed
Make deploy of MVM optional
1 parent 9d5a91e commit 3b0470f

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

contracts/LifCrowdsale.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,18 @@ contract LifCrowdsale is Ownable, Pausable {
265265
@dev Internal. Forwards funds to the foundation wallet and in case the soft
266266
cap was exceeded it also creates and funds the Market Validation Mechanism.
267267
*/
268-
function forwardFunds() internal {
268+
function forwardFunds(bool deployMVM) internal {
269269

270270
// calculate the max amount of wei for the foundation
271271
uint256 foundationBalanceCapWei = maxFoundationCapUSD.mul(weiPerUSDinTGE);
272272

273-
// If the minimiun cap for the MVM is not reached transfer all funds to foundation
274-
// else if the min cap for the MVM is reached, create it and send the remaining funds.
273+
// If the minimiun cap for the MVM is not reached or the MVM cant be deployed
274+
// transfer all funds to foundation else if the min cap for the MVM is reached,
275+
// create it and send the remaining funds.
275276
// We use weiRaised to compare becuase that is the total amount of wei raised in all TGE
276277
// but we have to distribute the balance using `this.balance` because thats the amount
277278
// raised by the crowdsale
278-
if (weiRaised <= foundationBalanceCapWei) {
279+
if ((weiRaised <= foundationBalanceCapWei) || !deployMVM) {
279280

280281
foundationWallet.transfer(this.balance);
281282

@@ -415,13 +416,13 @@ contract LifCrowdsale is Ownable, Pausable {
415416
Mechanism in case the soft cap was exceeded. It also unpauses the token to
416417
enable transfers. It can be called only once, after `end2Timestamp`
417418
*/
418-
function finalize() public onlyOwner hasEnded {
419+
function finalize(bool deployMVM) public onlyOwner hasEnded {
419420
require(!isFinalized);
420421

421422
// foward founds and unpause token only if minCap is reached
422423
if (funded()) {
423424

424-
forwardFunds();
425+
forwardFunds(deployMVM);
425426

426427
// finish the minting of the token
427428
token.finishMinting();

test/Crowdsale.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ contract('LifToken Crowdsale', function (accounts) {
281281
await crowdsale.buyTokens(beneficiary, { value: weiAmount, from: accounts[5] });
282282

283283
await increaseTimeTestRPCTo(end2 + 2);
284-
await crowdsale.finalize();
284+
await crowdsale.finalize(true);
285285

286286
// TO DO: Find out why the balance difference in this assert
287287
// const balanceBeforeClaim = web3.eth.getBalance(beneficiary);
@@ -307,7 +307,7 @@ contract('LifToken Crowdsale', function (accounts) {
307307
await crowdsale.buyTokens(accounts[6], { value: weiAmount, from: accounts[5] });
308308

309309
await increaseTimeTestRPCTo(end2 + 2);
310-
await crowdsale.finalize();
310+
await crowdsale.finalize(true);
311311

312312
try {
313313
await crowdsale.claimEth({ from: accounts[6] });
@@ -361,7 +361,7 @@ contract('LifToken Crowdsale', function (accounts) {
361361
await crowdsale.buyTokens(beneficiary, { value: weiAmount, from: accounts[5] });
362362

363363
await increaseTimeTestRPCTo(end2 + 2);
364-
await crowdsale.finalize();
364+
await crowdsale.finalize(true);
365365

366366
try {
367367
await crowdsale.claimEth({ from: accounts[8] });
@@ -390,10 +390,10 @@ contract('LifToken Crowdsale', function (accounts) {
390390
await crowdsale.buyTokens(beneficiary, { value: weiAmount, from: accounts[5] });
391391

392392
await increaseTimeTestRPCTo(end2 + 2);
393-
await crowdsale.finalize();
393+
await crowdsale.finalize(true);
394394

395395
try {
396-
await crowdsale.finalize();
396+
await crowdsale.finalize(true);
397397
assert(false, 'should have thrown');
398398
} catch (e) {
399399
assert(help.isInvalidOpcodeEx(e));
@@ -419,7 +419,7 @@ contract('LifToken Crowdsale', function (accounts) {
419419
await crowdsale.buyTokens(beneficiary, { value: weiAmount, from: accounts[5] });
420420

421421
await increaseTimeTestRPCTo(end2 + 2);
422-
await crowdsale.finalize();
422+
await crowdsale.finalize(true);
423423

424424
const MVMAddress = await crowdsale.MVM.call();
425425
assert(MVMAddress !== help.zeroAddress);
@@ -447,7 +447,7 @@ contract('LifToken Crowdsale', function (accounts) {
447447
await crowdsale.buyTokens(beneficiary, { value: weiAmount, from: accounts[5] });
448448

449449
await increaseTimeTestRPCTo(end2 + 2);
450-
await crowdsale.finalize();
450+
await crowdsale.finalize(true);
451451

452452
const MVMAddress = await crowdsale.MVM.call();
453453
assert(MVMAddress === help.zeroAddress, 'no MVM should have been created: ' + MVMAddress);

test/commands.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ async function runFinalizeCrowdsaleCommand (command, state) {
283283
let crowdsaleFunded = (state.weiRaised >= state.crowdsaleData.minCapUSD * state.weiPerUSDinTGE);
284284

285285
help.debug('finishing crowdsale on block', nextTimestamp, ', from address:', gen.getAccount(command.fromAccount), ', funded:', crowdsaleFunded);
286-
287-
let tx = await state.crowdsaleContract.finalize({ from: account });
286+
let tx = await state.crowdsaleContract.finalize(true, { from: account });
288287
help.debug('gas used in finalize:', tx.receipt.gasUsed);
289288

290289
if (!help.inCoverage()) { // gas cannot be measured correctly when running coverage

test/deploy/TGEDeployer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const _ = require('lodash');
1616
const TGEDistribution = require('./TGEDistribution');
1717

1818
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;
19+
it.only('Deploy a TGE correctly', async function () {
20+
const startTimestamp = new Date('Sun, 28 Jan 2018 15:00:00 GMT-3').getTime() / 1000;
21+
const end1Timestamp = new Date('Sun, 28 Jan 2018 24:00:00 GMT-3').getTime() / 1000;
22+
const end2Timestamp = new Date('Mon, 29 Jan 2018 12:00:00 GMT-3').getTime() / 1000;
2323
const rate1 = 1000;
2424
const rate2 = 900;
25-
const setWeiLockSeconds = duration.hours(1);
25+
const setWeiLockSeconds = duration.minutes(30);
2626
var totalSupply = new BigNumber(0);
2727
const weiPerUSDinTGE = web3.toWei(1 / 1000);
2828

test/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = {
9191
if (balances[i] > 0) { await crowdsale.sendTransaction({ value: web3.toWei(balances[i] / rate, 'ether'), from: accounts[i + 1] }); }
9292
}
9393
await increaseTimeTestRPCTo(endTime + 1);
94-
await crowdsale.finalize();
94+
await crowdsale.finalize(true);
9595
let token = LifToken.at(await crowdsale.token());
9696
await token.unpause();
9797
return crowdsale;

0 commit comments

Comments
 (0)