Skip to content

Commit e90838b

Browse files
authored
Merge pull request #312 from windingtree/update-repo
Fix wrong purchases amount bug
2 parents 8d7a4ef + d8f948d commit e90838b

File tree

6 files changed

+84
-7512
lines changed

6 files changed

+84
-7512
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage
66
coverage.json
77
allFiredEvents
88
scTopics
9+
package-lock.json

contracts/LifCrowdsale.sol

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ contract LifCrowdsale is Ownable, Pausable {
229229

230230
// store wei amount in case of TGE min cap not reached
231231
weiRaised = weiRaised.add(weiAmount);
232-
purchases[beneficiary] = weiAmount;
232+
purchases[beneficiary] = purchases[beneficiary].add(weiAmount);
233233
tokensSold = tokensSold.add(tokens);
234234

235235
token.mint(beneficiary, tokens);
@@ -273,8 +273,11 @@ contract LifCrowdsale is Ownable, Pausable {
273273
// calculate the max amount of wei for the foundation
274274
uint256 foundationBalanceCapWei = maxFoundationCapUSD.mul(weiPerUSDinTGE);
275275

276-
// if the minimiun cap for the MVM is not reached transfer all funds to foundation
277-
// else if the min cap for the MVM is reached, create it and send the remaining funds
276+
// If the minimiun cap for the MVM is not reached transfer all funds to foundation
277+
// else if the min cap for the MVM is reached, create it and send the remaining funds.
278+
// We use weiRaised to compare becuase that is the total amount of wei raised in all TGE
279+
// but we have to distribute the balance using `this.balance` because thats the amount
280+
// raised by the crowdsale
278281
if (weiRaised <= foundationBalanceCapWei) {
279282

280283
foundationWallet.transfer(this.balance);
@@ -398,6 +401,12 @@ contract LifCrowdsale is Ownable, Pausable {
398401
uint256 toReturn = purchases[contributor];
399402
assert(toReturn > 0);
400403

404+
uint256 tokenBalance = token.balanceOf(contributor);
405+
406+
// Substract weiRaised and tokens sold
407+
weiRaised = weiRaised.sub(toReturn);
408+
tokensSold = tokensSold.sub(tokenBalance);
409+
token.burn(contributor, tokenBalance);
401410
purchases[contributor] = 0;
402411

403412
contributor.transfer(toReturn);
@@ -409,7 +418,7 @@ contract LifCrowdsale is Ownable, Pausable {
409418
Mechanism in case the soft cap was exceeded. It also unpauses the token to
410419
enable transfers. It can be called only once, after `end2Timestamp`
411420
*/
412-
function finalize() public whenNotPaused hasEnded {
421+
function finalize() public onlyOwner hasEnded {
413422
require(!isFinalized);
414423

415424
// foward founds and unpause token only if minCap is reached

contracts/LifToken.sol

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity ^0.4.18;
33
import "zeppelin-solidity/contracts/token/ERC827/ERC827Token.sol";
44
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
55
import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
6-
import "zeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
76
import "zeppelin-solidity/contracts/token/ERC20/PausableToken.sol";
87

98
/**
@@ -12,9 +11,9 @@ import "zeppelin-solidity/contracts/token/ERC20/PausableToken.sol";
1211
Implementation of Líf, the ERC827 token for Winding Tree, an extension of the
1312
ERC20 token with extra methods to transfer value and data to execute a call
1413
on transfer.
15-
Uses OpenZeppelin StandardToken, ERC827Token, BurnableToken, MintableToken and PausableToken.
14+
Uses OpenZeppelin StandardToken, ERC827Token, MintableToken and PausableToken.
1615
*/
17-
contract LifToken is StandardToken, ERC827Token, BurnableToken, MintableToken, PausableToken {
16+
contract LifToken is StandardToken, ERC827Token, MintableToken, PausableToken {
1817
// Token Name
1918
string public constant NAME = "Líf";
2019

@@ -30,11 +29,34 @@ contract LifToken is StandardToken, ERC827Token, BurnableToken, MintableToken, P
3029
* @param _value The amount of tokens to be burned.
3130
*/
3231
function burn(uint256 _value) public whenNotPaused {
33-
super.burn(_value);
32+
33+
require(_value <= balances[msg.sender]);
34+
35+
balances[msg.sender] = balances[msg.sender].sub(_value);
36+
totalSupply_ = totalSupply_.sub(_value);
3437

3538
// a Transfer event to 0x0 can be useful for observers to keep track of
3639
// all the Lif by just looking at those events
3740
Transfer(msg.sender, address(0), _value);
3841
}
3942

43+
/**
44+
* @dev Burns a specific amount of tokens of an address
45+
* This function can be called only by the owner in the minting process
46+
*
47+
* @param _value The amount of tokens to be burned.
48+
*/
49+
function burn(address burner, uint256 _value) public onlyOwner {
50+
51+
require(!mintingFinished);
52+
53+
require(_value <= balances[burner]);
54+
55+
balances[burner] = balances[burner].sub(_value);
56+
totalSupply_ = totalSupply_.sub(_value);
57+
58+
// a Transfer event to 0x0 can be useful for observers to keep track of
59+
// all the Lif by just looking at those events
60+
Transfer(burner, address(0), _value);
61+
}
4062
}

0 commit comments

Comments
 (0)