-
Notifications
You must be signed in to change notification settings - Fork 0
/
ILO.sol
372 lines (271 loc) · 11.3 KB
/
ILO.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
interface ERC20 {
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
);
}
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract ILO {
using SafeMath for uint256;
ERC20 public token;
uint256 public startTime;
uint256 public weiRaised;
uint256 public tokensSold;
uint256 public tokensUnsold = SafeMath.mul(150000000, 10**(18)); // 150,000,000 ELIST
uint256 public phaseOneSupply;
uint256 public phaseTwoSupply;
uint256 public phaseThreeSupply;
uint256 public phaseOneTimeLock;
uint256 public phaseTwoTimeLock;
uint256 public phaseThreeTimeLock;
uint256 public idleTime;
uint256 public vestingPhase1;
uint256 public vestingPhase2;
uint256 public vestingPhase3;
uint256 public phase1Rate = 120;
uint256 public phase2Rate = 58;
uint256 public phase3Rate = 31;
uint256 public purchaseCount = 0;
struct Purchase {
address buyer;
uint256 weiInvested;
uint256 tokensBuyed;
}
Purchase[] public latestPurchases;
struct Investors {
address payable buyer;
uint256 tokensAmount;
uint256 weiAmountPhase1;
uint256 tokensAmountPhase1;
uint256 weiAmountPhase2;
uint256 tokensAmountPhase2;
uint256 weiAmountPhase3;
uint256 tokensAmountPhase3; }
mapping(address => Investors) public investors;
address payable public governance;
event TokenPurchase(
address indexed purchaser,
uint256 value,
uint256 amount
);
constructor(
address payable _governance,
ERC20 _token
) {
governance = _governance;
token = _token;
startTime = 1647298800; // Tue Mar 15 2022 00:00:00 GMT+0100 (hora estándar de Europa central)
idleTime = SafeMath.add(idleTime, 1440 minutes);
phaseOneTimeLock = SafeMath.add(startTime, 8640 minutes);
phaseTwoTimeLock = SafeMath.add(phaseOneTimeLock, 10080 minutes);
phaseThreeTimeLock = SafeMath.add(phaseTwoTimeLock, 11520 minutes);
vestingPhase1 = SafeMath.add(phaseThreeTimeLock, 86400 minutes);
vestingPhase2 = SafeMath.add(phaseThreeTimeLock, 43200 minutes);
vestingPhase3 = SafeMath.add(phaseThreeTimeLock, 20160 minutes);
phaseOneSupply = SafeMath.mul(40000000, 10**(18)); // 40,000,000 ELIST
phaseTwoSupply = SafeMath.mul(50000000, 10**(18)); // 50,000,000 ELIST
phaseThreeSupply = SafeMath.mul(60000000, 10**(18)); // 60,000,000 ELIST
}
receive() external payable {
buyTokens();
}
function _getTokensBasedOnPhase(uint256 _weiAmount) internal returns (uint256 _tokens) {
uint256 _now = block.timestamp;
uint256 _tokensAmount = 0;
_tokens = SafeMath.add(_tokensAmount, _weiAmount.mul(getCurrentRate()));
if (_now <= (phaseOneTimeLock - (idleTime))) {
if ((phaseOneSupply - _tokens) >= 0) {
require(
(phaseOneSupply - _tokens) >= 0,
"Phase One Supply Ended !"
);
phaseOneSupply = phaseOneSupply.sub(_tokens);
} else {
_tokens = 0;
}
} else if (
_now > (phaseOneTimeLock - (idleTime)) && _now < phaseOneTimeLock
) {
_tokens = 0;
require(0 != 0, "IDLE TIME 1 !");
phaseTwoSupply = phaseTwoSupply.sub(_tokens);
} else if (
_now > phaseOneTimeLock && _now < (phaseTwoTimeLock - (idleTime))
) {
if ((phaseTwoSupply - _tokens) >= 0) {
require(
(phaseTwoSupply - _tokens) >= 0,
"Phase Two Supply Ended !"
);
phaseTwoSupply = phaseTwoSupply.sub(_tokens);
} else {
_tokens = 0;
}
} else if (
_now > (phaseTwoTimeLock - (idleTime)) && _now < phaseTwoTimeLock
) {
_tokens = 0;
require(0 != 0, "IDLE TIME 2 !");
phaseTwoSupply = phaseTwoSupply - _tokens;
} else if (_now > phaseTwoTimeLock && _now < (phaseThreeTimeLock)) {
if (phaseThreeSupply - _tokens >= 0) {
require(
(phaseThreeSupply - _tokens) >= 0,
"Phase Three Supply Ended !"
);
phaseThreeSupply = phaseThreeSupply.sub(_tokens);
} else {
_tokens = 0;
}
}
return _tokens;
}
function buyTokens() public payable {
uint256 weiAmount = msg.value;
require(
weiAmount >= 0.0000000000001 ether,
"investment should be more than 0.0000000000001 EWT"
);
require(block.timestamp <= phaseThreeTimeLock, "ELIST ILO is Closed !");
require(block.timestamp >= startTime, "ELIST ILO is not open yet!");
Investors storage investor = investors[msg.sender];
uint256 tokens = 0;
tokens = _getTokensBasedOnPhase(weiAmount);
require(tokens > 0, "NOT POSSIBLE TO PURCHASE ELIST");
weiRaised = weiRaised.add(weiAmount);
investor.buyer = payable(msg.sender);
latestPurchases.push(
Purchase(msg.sender, weiAmount, tokens)
);
purchaseCount = purchaseCount + 1;
if(block.timestamp < (phaseOneTimeLock-idleTime)){
investor.weiAmountPhase1 = investor.weiAmountPhase1 + weiAmount;
investor.tokensAmountPhase1 = investor.tokensAmountPhase1 + tokens;
}else if( block.timestamp > phaseOneTimeLock && block.timestamp < (phaseTwoTimeLock-idleTime)){
investor.weiAmountPhase2 = investor.weiAmountPhase2 + weiAmount;
investor.tokensAmountPhase2 = investor.tokensAmountPhase2 + tokens;
}else if(block.timestamp > phaseTwoTimeLock && block.timestamp < phaseThreeTimeLock){
investor.weiAmountPhase3 = investor.weiAmountPhase3 + weiAmount;
investor.tokensAmountPhase3 = investor.tokensAmountPhase3 + tokens;
}
investor.tokensAmount = investor.tokensAmount + tokens;
tokensSold = tokensSold.add(tokens);
tokensUnsold = tokensUnsold.sub(tokens);
governance.transfer(weiAmount);
emit TokenPurchase(msg.sender, weiAmount, tokens);
}
function withdrawTokens() public returns (bool success) {
Investors storage investor = investors[msg.sender];
address buyer = investor.buyer;
require(msg.sender == buyer, "Not valid investor to withdraw !");
require(block.timestamp >= vestingPhase3,"ELIST still locked");
if(investor.tokensAmountPhase3 > 0 && block.timestamp >= vestingPhase3){
require(block.timestamp >= vestingPhase3, "Still in Vesting PH3");
require(token.transfer(buyer, investor.tokensAmountPhase3), "Can NOT transfer ELIST from Phase 3");
investor.tokensAmount = SafeMath.sub(investor.tokensAmount, investor.tokensAmountPhase3);
investor.tokensAmountPhase3 = 0;
}
if(investor.tokensAmountPhase2 > 0 && block.timestamp >= vestingPhase2){
require(block.timestamp >= vestingPhase2, "Still in Vesting PH2");
require(token.transfer(buyer, investor.tokensAmountPhase2), "Can NOT transfer ELIST from Phase 2");
investor.tokensAmount = SafeMath.sub(investor.tokensAmount, investor.tokensAmountPhase2);
investor.tokensAmountPhase2 = 0;
}
if(investor.tokensAmountPhase1 > 0 && block.timestamp >= vestingPhase1){
require(block.timestamp >= vestingPhase1, "Still in Vesting PH1");
require(token.transfer(buyer, investor.tokensAmountPhase1), "Can NOT transfer ELIST from Phase 1");
investor.tokensAmount = SafeMath.sub(investor.tokensAmount, investor.tokensAmountPhase1);
investor.tokensAmountPhase1 = 0;
}
return true;
}
function getTokenCount() public view returns (uint256) {
Investors storage investor = investors[msg.sender];
uint256 _totalTokens = investor.tokensAmountPhase1 + investor.tokensAmountPhase2 + investor.tokensAmountPhase3;
return _totalTokens;
}
function withdrawUnsoldTokens() public returns (bool success) {
require(msg.sender == governance, "!governance");
require(block.timestamp > phaseThreeTimeLock, "ELIST ILO is not finished");
require(token.transfer(governance, tokensUnsold), "Transfer not successful");
return true;
}
function setGovernance(address payable _governance) public returns (bool success) {
require(msg.sender == governance, "!governance");
governance = _governance;
return true;
}
function withdrawEthers(uint256 _weiAmount) public returns (bool success) {
require(msg.sender == governance, "!governance");
governance.transfer(_weiAmount);
return true;
}
function getCurrentRate() public view returns (uint256) {
if(block.timestamp < phaseOneTimeLock){
return phase1Rate;
}else if(block.timestamp < phaseTwoTimeLock && block.timestamp >= phaseOneTimeLock){
return phase2Rate;
}else if(block.timestamp < phaseThreeTimeLock || block.timestamp > phaseThreeTimeLock){
return phase3Rate;
}
return 0;
}
}