-
Notifications
You must be signed in to change notification settings - Fork 0
/
SST-01-006.sol
331 lines (248 loc) · 10.1 KB
/
SST-01-006.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
*Submitted for verification at Etherscan.io on 2020-06-15
*/
pragma solidity 0.5.10;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string internal _name;
string internal _symbol;
uint8 internal _decimals;
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
library Roles {
struct Role {
mapping (address => bool) bearer;
}
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}
interface ApproveAndCallFallBack {
function receiveApproval(address from, uint256 amount, address token, bytes calldata extraData) external;
}
contract SimbaStorageToken is ERC20, Ownable {
address private boss = 0x96f9ED1C9555060da2A04b6250154C9941c1BA5a;
address private admin = 0x0D968ab967290731c75204A9713856f9954dfEc4;
mapping (address => uint256) freezed;
modifier notFreezed(address account) {
require(block.timestamp >= freezed[account]);
_;
}
modifier onlyOwnerAndBoss() {
require(msg.sender == owner() || msg.sender == boss);
_;
}
uint256 internal INITIAL_SUPPLY = 100000000 * (10 ** 18);
constructor(address recipient) public {
_name = "SIMBA Storage Token";
_symbol = "SST";
_decimals = 18;
_mint(recipient, INITIAL_SUPPLY);
}
function _transfer(address sender, address recipient, uint256 amount) internal notFreezed(sender) {
super._transfer(sender, recipient, amount);
}
function _freeze(address account, uint256 period) internal {
require(account != address(0));
freezed[account] = block.timestamp.add(period);
emit OnFreezed(msg.sender, account, period, block.timestamp);
}
function freeze(address[] memory accounts, uint256[] memory periods) public onlyOwnerAndBoss {
for (uint256 i = 0; i < accounts.length; i++) {
_freeze(accounts[i], periods[i]);
}
}
function freezeAndTransfer(address recipient, uint256 amount, uint256 period) public {
require(msg.sender == boss || msg.sender == admin);
_freeze(recipient, period);
transfer(recipient, amount);
}
function deputeBoss(address newBoss) public onlyOwnerAndBoss {
require(newBoss != address(0));
emit OnBossDeputed(boss, newBoss, block.timestamp);
boss = newBoss;
}
function deputeAdmin(address newAdmin) public onlyOwnerAndBoss {
require(newAdmin != address(0));
emit OnAdminDeputed(admin, newAdmin, block.timestamp);
admin = newAdmin;
}
function approveAndCall(address spender, uint256 amount, bytes calldata extraData) external returns (bool) {
require(approve(spender, amount));
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData);
return true;
}
function withdrawERC20(address ERC20Token, address recipient) external {
require(msg.sender == boss || msg.sender == admin);
uint256 amount = IERC20(ERC20Token).balanceOf(address(this));
require(amount > 0);
IERC20(ERC20Token).transfer(recipient, amount);
}
function setName(string memory newName, string memory newSymbol) public onlyOwner {
emit OnNameSet(_name, _symbol, newName, newSymbol, now);
_name = newName;
_symbol = newSymbol;
}
function releaseDate(address account) public view returns(uint256) {
return freezed[account];
}
event OnFreezed (
address indexed sender,
address indexed account,
uint256 period,
uint256 timestamp
);
event OnBossDeputed (
address indexed former,
address indexed current,
uint256 timestamp
);
event OnAdminDeputed (
address indexed former,
address indexed current,
uint256 timestamp
);
event OnNameSet (
string oldName,
string oldSymbol,
string newName,
string newSymbol,
uint256 timestamp
);
}