@@ -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 }
0 commit comments