-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBonusFinalizeAgent.sol
executable file
·60 lines (44 loc) · 1.51 KB
/
BonusFinalizeAgent.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pragma solidity ^0.4.18;
import "./Crowdsale.sol";
import "./CrowdsaleToken.sol";
import "./SafeMathLib.sol";
/**
* At the end of the successful crowdsale allocate % bonus of tokens to the team.
*
* Unlock tokens.
*
* BonusAllocationFinal must be set as the minting agent for the MintableToken.
*
*/
contract BonusFinalizeAgent is FinalizeAgent, SafeMathLib {
CrowdsaleToken public token;
Crowdsale public crowdsale;
uint256 public allocatedTokens;
uint256 tokenCap;
address walletAddress;
function BonusFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint256 _tokenCap, address _walletAddress) public {
token = _token;
crowdsale = _crowdsale;
//crowdsale address must not be 0
require(address(crowdsale) != 0);
tokenCap = _tokenCap;
walletAddress = _walletAddress;
}
/* Can we run finalize properly */
function isSane() public view returns (bool) {
return (token.mintAgents(address(this)) == true) && (token.releaseAgent() == address(this));
}
/** Called once by crowdsale finalize() if the sale was success. */
function finalizeCrowdsale() public {
// if finalized is not being called from the crowdsale
// contract then throw
require(msg.sender == address(crowdsale));
// get the total sold tokens count.
uint256 tokenSupply = token.totalSupply();
allocatedTokens = safeSub(tokenCap,tokenSupply);
if ( allocatedTokens > 0) {
token.mint(walletAddress, allocatedTokens);
}
token.releaseTokenTransfer();
}
}