Skip to content

Commit 99e921c

Browse files
authored
Merge pull request #15 from OpenSTFoundation/final-tokensale
Final token sale specifications
2 parents ac1b56c + 17482e7 commit 99e921c

File tree

12 files changed

+3179
-20
lines changed

12 files changed

+3179
-20
lines changed

contracts/ERC20Token.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ contract ERC20Token is ERC20Interface, Owned {
2424
string private tokenName;
2525
string private tokenSymbol;
2626
uint8 private tokenDecimals;
27-
uint256 private tokenTotalSupply;
27+
uint256 internal tokenTotalSupply;
2828

2929
mapping(address => uint256) balances;
3030
mapping(address => mapping (address => uint256)) allowed;
@@ -107,4 +107,5 @@ contract ERC20Token is ERC20Interface, Owned {
107107

108108
return true;
109109
}
110+
110111
}

contracts/SimpleToken.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ contract SimpleToken is ERC20Token, OpsManaged, SimpleTokenConfig {
3939

4040

4141
// Events
42+
event Burnt(address indexed _from, uint256 _amount);
4243
event Finalized();
4344

4445

@@ -79,6 +80,19 @@ contract SimpleToken is ERC20Token, OpsManaged, SimpleTokenConfig {
7980
require(isOwnerOrOps(_sender) || _to == owner);
8081
}
8182

83+
// Implement a burn function to permit msg.sender to reduce its balance
84+
// which also reduces tokenTotalSupply
85+
function burn(uint256 _value) public returns (bool success) {
86+
require(_value <= balances[msg.sender]);
87+
88+
balances[msg.sender] = balances[msg.sender].sub(_value);
89+
tokenTotalSupply = tokenTotalSupply.sub(_value);
90+
91+
Burnt(msg.sender, _value);
92+
93+
return true;
94+
}
95+
8296

8397
// Finalize method marks the point where token transfers are finally allowed for everybody.
8498
function finalize() external onlyAdmin returns (bool success) {

contracts/TokenSale.sol

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import "./SafeMath.sol";
6363
// addPresale x
6464
// pause / unpause x
6565
// reclaimTokens x
66+
// burnUnsoldTokens x
6667
// finalize x
6768
//
6869

@@ -118,11 +119,12 @@ contract TokenSale is OpsManaged, Pausable, TokenSaleConfig { // Pausable is als
118119
event Initialized();
119120
event PresaleAdded(address indexed _account, uint256 _baseTokens, uint256 _bonusTokens);
120121
event WhitelistUpdated(address indexed _account, uint8 _phase);
121-
event TokensPurchased(address indexed _beneficiary, uint256 _cost, uint256 _tokens);
122+
event TokensPurchased(address indexed _beneficiary, uint256 _cost, uint256 _tokens, uint256 _totalSold);
122123
event TokensPerKEtherUpdated(uint256 _amount);
123124
event Phase1AccountTokensMaxUpdated(uint256 _tokens);
124125
event WalletChanged(address _newWallet);
125126
event TokensReclaimed(uint256 _amount);
127+
event UnsoldTokensBurnt(uint256 _amount);
126128
event Finalized();
127129

128130

@@ -212,6 +214,12 @@ contract TokenSale is OpsManaged, Pausable, TokenSaleConfig { // Pausable is als
212214
_;
213215
}
214216

217+
modifier onlyAfterSale() {
218+
// require finalized is stronger than hasSaleEnded
219+
require(finalized);
220+
_;
221+
}
222+
215223

216224
function hasSaleEnded() private view returns (bool) {
217225
// if sold out or finalized, sale has ended
@@ -345,7 +353,7 @@ contract TokenSale is OpsManaged, Pausable, TokenSaleConfig { // Pausable is als
345353
// Transfer the contribution to the wallet
346354
wallet.transfer(msg.value.sub(refund));
347355

348-
TokensPurchased(msg.sender, cost, tokensBought);
356+
TokensPurchased(msg.sender, cost, tokensBought, totalTokensSold);
349357

350358
// If all tokens available for sale have been sold out, finalize the sale automatically.
351359
if (totalTokensSold == TOKENS_SALE) {
@@ -437,17 +445,32 @@ contract TokenSale is OpsManaged, Pausable, TokenSaleConfig { // Pausable is als
437445
}
438446

439447

440-
// Allows the admin to reclaim all tokens assigned to the sale contract.
441-
// This should only be used in case of emergency.
442-
function reclaimTokens() external onlyAdmin returns (bool) {
448+
// Allows the admin to move bonus tokens still available in the sale contract
449+
// out before burning all remaining unsold tokens in burnUnsoldTokens().
450+
// Used to distribute bonuses to token sale participants when the sale has ended
451+
// and all bonuses are known.
452+
function reclaimTokens(uint256 _amount) external onlyAfterSale onlyAdmin returns (bool) {
443453
uint256 ownBalance = tokenContract.balanceOf(address(this));
444-
454+
require(_amount <= ownBalance);
455+
445456
address tokenOwner = tokenContract.owner();
446457
require(tokenOwner != address(0));
447458

448-
require(tokenContract.transfer(tokenOwner, ownBalance));
459+
require(tokenContract.transfer(tokenOwner, _amount));
460+
461+
TokensReclaimed(_amount);
462+
463+
return true;
464+
}
465+
466+
467+
// Allows the admin to burn all unsold tokens in the sale contract.
468+
function burnUnsoldTokens() external onlyAfterSale onlyAdmin returns (bool) {
469+
uint256 ownBalance = tokenContract.balanceOf(address(this));
470+
471+
require(tokenContract.burn(ownBalance));
449472

450-
TokensReclaimed(ownBalance);
473+
UnsoldTokensBurnt(ownBalance);
451474

452475
return true;
453476
}

contracts/TokenSaleConfig.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ contract TokenSaleConfig is SimpleTokenConfig {
1717

1818
uint256 public constant PHASE1_START_TIME = 1510664400; // 2017-11-14, 13:00:00 UTC
1919
uint256 public constant PHASE2_START_TIME = 1510750800; // 2017-11-15, 13:00:00 UTC
20-
uint256 public constant END_TIME = 1511269199; // 2017-11-21, 12:59:59 UTC
20+
uint256 public constant END_TIME = 1512133199; // 2017-12-01, 12:59:59 UTC
2121
uint256 public constant CONTRIBUTION_MIN = 0.1 ether;
2222
uint256 public constant CONTRIBUTION_MAX = 10000.0 ether;
2323

0 commit comments

Comments
 (0)