-
Notifications
You must be signed in to change notification settings - Fork 4
/
CREDToken.sol
195 lines (149 loc) · 5.44 KB
/
CREDToken.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/token/CappedToken.sol';
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import './MonthlyTokenVesting.sol';
contract CREDToken is CappedToken {
using SafeMath for uint256;
/**
* Constant fields
*/
string public constant name = "Verify Token";
uint8 public constant decimals = 18;
string public constant symbol = "CRED";
/**
* Immutable state variables
*/
// Time when team and reserved tokens are unlocked
uint256 public reserveUnlockTime;
address public teamWallet;
address public reserveWallet;
address public advisorsWallet;
/**
* State variables
*/
uint256 teamLocked;
uint256 reserveLocked;
uint256 advisorsLocked;
// Are the tokens non-transferrable?
bool public locked = true;
// When tokens can be unfreezed.
uint256 public unfreezeTime = 0;
bool public unlockedReserveAndTeamFunds = false;
MonthlyTokenVesting public advisorsVesting = MonthlyTokenVesting(address(0));
/**
* Events
*/
event MintLocked(address indexed to, uint256 amount);
event Unlocked(address indexed to, uint256 amount);
/**
* Modifiers
*/
// Tokens must not be locked.
modifier whenLiquid {
require(!locked);
_;
}
modifier afterReserveUnlockTime {
require(now >= reserveUnlockTime);
_;
}
modifier unlockReserveAndTeamOnce {
require(!unlockedReserveAndTeamFunds);
_;
}
/**
* Constructor
*/
function CREDToken(
uint256 _cap,
uint256 _yearLockEndTime,
address _teamWallet,
address _reserveWallet,
address _advisorsWallet
)
CappedToken(_cap)
public
{
require(_yearLockEndTime != 0);
require(_teamWallet != address(0));
require(_reserveWallet != address(0));
require(_advisorsWallet != address(0));
reserveUnlockTime = _yearLockEndTime;
teamWallet = _teamWallet;
reserveWallet = _reserveWallet;
advisorsWallet = _advisorsWallet;
}
// Mint a certain number of tokens that are locked up.
// _value has to be bounded not to overflow.
function mintAdvisorsTokens(uint256 _value) public onlyOwner canMint {
require(advisorsLocked == 0);
require(_value.add(totalSupply) <= cap);
advisorsLocked = _value;
MintLocked(advisorsWallet, _value);
}
function mintTeamTokens(uint256 _value) public onlyOwner canMint {
require(teamLocked == 0);
require(_value.add(totalSupply) <= cap);
teamLocked = _value;
MintLocked(teamWallet, _value);
}
function mintReserveTokens(uint256 _value) public onlyOwner canMint {
require(reserveLocked == 0);
require(_value.add(totalSupply) <= cap);
reserveLocked = _value;
MintLocked(reserveWallet, _value);
}
/// Finalise any minting operations. Resets the owner and causes normal tokens
/// to be frozen. Also begins the countdown for locked-up tokens.
function finalise() public onlyOwner {
require(reserveLocked > 0);
require(teamLocked > 0);
require(advisorsLocked > 0);
advisorsVesting = new MonthlyTokenVesting(advisorsWallet, now, 92 days, 2 years, false);
mint(advisorsVesting, advisorsLocked);
finishMinting();
owner = 0;
unfreezeTime = now + 1 weeks;
}
// Causes tokens to be liquid 1 week after the tokensale is completed
function unfreeze() public {
require(unfreezeTime > 0);
require(now >= unfreezeTime);
locked = false;
}
/// Unlock any now freeable tokens that are locked up for team and reserve accounts .
function unlockTeamAndReserveTokens() public whenLiquid afterReserveUnlockTime unlockReserveAndTeamOnce {
require(totalSupply.add(teamLocked).add(reserveLocked) <= cap);
totalSupply = totalSupply.add(teamLocked).add(reserveLocked);
balances[teamWallet] = balances[teamWallet].add(teamLocked);
balances[reserveWallet] = balances[reserveWallet].add(reserveLocked);
teamLocked = 0;
reserveLocked = 0;
unlockedReserveAndTeamFunds = true;
Transfer(address(0), teamWallet, teamLocked);
Transfer(address(0), reserveWallet, reserveLocked);
Unlocked(teamWallet, teamLocked);
Unlocked(reserveWallet, reserveLocked);
}
function unlockAdvisorTokens() public whenLiquid {
advisorsVesting.release(this);
}
/**
* Methods overriding some OpenZeppelin functions to prevent calling them when token is not liquid.
*/
function transfer(address _to, uint256 _value) public whenLiquid returns (bool) {
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public whenLiquid returns (bool) {
return super.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public whenLiquid returns (bool) {
return super.approve(_spender, _value);
}
function increaseApproval(address _spender, uint256 _addedValue) public whenLiquid returns (bool) {
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint256 _subtractedValue) public whenLiquid returns (bool) {
return super.decreaseApproval(_spender, _subtractedValue);
}
}