-
Notifications
You must be signed in to change notification settings - Fork 2
/
Acorn.sol
266 lines (200 loc) · 8.03 KB
/
Acorn.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
pragma solidity ^ 0.4.19;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function mul(uint a, uint b) internal pure returns(uint) {
uint c = a * b;
require(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal pure returns(uint) {
require(b > 0);
uint c = a / b;
require(a == b * c + a % b);
return c;
}
function sub(uint a, uint b) internal pure returns(uint) {
require(b <= a);
return a - b;
}
function add(uint a, uint b) internal pure returns(uint) {
uint c = a + b;
require(c >= a);
return c;
}
function max64(uint64 a, uint64 b) internal pure returns(uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal pure returns(uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal pure returns(uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal pure returns(uint256) {
return a < b ? a : b;
}
}
// ----------------------------------------------------------------------------
// Ownable contract
// ----------------------------------------------------------------------------
contract Ownable {
address public owner;
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
if (newOwner != address(0)) {
owner = newOwner;
}
}
}
contract TST20Basic {
uint public totalSupply;
function balanceOf(address who) public view returns(uint);
function transfer(address to, uint value) public;
event Transfer(address indexed from, address indexed to, uint value);
}
contract TST20 is TST20Basic {
function allowance(address owner, address spender) public view returns(uint);
function transferFrom(address from, address to, uint value) public;
function approve(address spender, uint value) public;
event Approval(address indexed owner, address indexed spender, uint value);
}
contract BasicLockedToken is TST20Basic, Ownable {
using SafeMath for uint;
mapping(address => uint) balances;
struct LockedData {
uint256 lockedTime;
uint256 lockedValue;
}
mapping(address => LockedData) public lockedAccounts;
bool public transferEnable = true;
mapping(address => bool) public admins;
event AccountLocked(address indexed _address, uint256 _lockValue, uint256 _lockTime);
modifier hasAdminRole() {
require(isAdmin(msg.sender) || msg.sender == owner);
_;
}
function transfer(address _to, uint _value) public {
require(_value > 0 && _to != address(0));
checkTransferAuth(msg.sender, _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}
function balanceOf(address _owner) public view returns(uint balance) {
return balances[_owner];
}
//A special feature for the ACN airdrop
//Allow owner or admin to transfer ACN and lock 70% ACN for a month
function transferAndLock(address _to, uint256 _value) hasAdminRole public {
require(_value > 0 && _to != address(0));
LockedData storage account = lockedAccounts[_to];
uint256 newLockValue = _value.mul(70).div(100); //lock 70%
account.lockedValue = account.lockedValue.add(newLockValue);
uint256 secondsPerDay = 86400;
account.lockedTime = block.timestamp.add(secondsPerDay.mul(30)); //lock 30 days
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
AccountLocked(_to, newLockValue, account.lockedTime);
}
//Allow owner to lock some amount and some time for a address
function lock(address _to, uint256 _lockValue, uint256 _lockTime) onlyOwner public {
require(_lockValue > 0 && _to != address(0));
LockedData storage account = lockedAccounts[_to];
account.lockedValue = _lockValue;
account.lockedTime = _lockTime;
AccountLocked(_to, _lockValue, _lockTime);
}
//Allow owner to unlock a address
function unlock(address _to) onlyOwner public {
require(_to != address(0));
LockedData storage account = lockedAccounts[_to];
account.lockedValue = 0;
account.lockedTime = 0;
AccountLocked(_to, 0, 0);
}
function lockedBalanceOf(address _owner) public view returns(uint256 balance) {
return lockedAccounts[_owner].lockedValue;
}
function lockedTimeOf(address _owner) public view returns(uint256 lockedTime) {
return lockedAccounts[_owner].lockedTime;
}
function isLocked(address _owner) public view returns(bool) {
LockedData storage account = lockedAccounts[_owner];
return (account.lockedValue > 0) && (account.lockedTime > block.timestamp);
}
function checkTransferAuth(address _from, uint256 _transferValue) internal view {
require(transferEnable);
LockedData storage account = lockedAccounts[_from];
require(account.lockedTime <= block.timestamp || (balanceOf(_from) > account.lockedValue && balanceOf(_from).sub(account.lockedValue) >= _transferValue));
}
//Allow owner to stop or start all the transfer
function changeTransferEnable(bool _transferEnable) onlyOwner public {
transferEnable = _transferEnable;
}
function isAdmin(address _address) public view returns(bool) {
return admins[_address];
}
//Allow owner to remove a admin address
function removeAdmin(address _address) onlyOwner public {
admins[_address] = false;
}
//Allow owner to add a admin address
function addAdmin(address _address) onlyOwner public {
admins[_address] = true;
}
}
contract StandardToken is BasicLockedToken, TST20 {
mapping(address => mapping(address => uint)) allowed;
function transferFrom(address _from, address _to, uint _value) public {
require(_value > 0 && _to != address(0));
checkTransferAuth(_from, _value);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
}
function approve(address _spender, uint _value) public {
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
function allowance(address _owner, address _spender) public constant returns(uint remaining) {
return allowed[_owner][_spender];
}
}
contract Acorn is StandardToken {
string public constant name = "Acorn";
string public constant symbol = "ACN";
uint public constant decimals = 18;
function Acorn() public {
totalSupply = 10000000000 * 10 ** decimals;
balances[msg.sender] = totalSupply; //Send all tokens to owner
}
function burn(uint _value) onlyOwner public returns(bool) {
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply = totalSupply.sub(_value);
Transfer(msg.sender, address(0), _value);
return true;
}
//Owner can claim TTC or other token of this contract to self-address
function claimToken(address _tokenAddress) onlyOwner public {
if (_tokenAddress == address(0)) {
require(owner.send(address(this).balance));
return;
}
TST20 token = TST20(_tokenAddress);
uint256 balance = token.balanceOf(this);
token.transfer(owner, balance);
}
//Accept TTC transfer
function () payable public {}
}