-
Notifications
You must be signed in to change notification settings - Fork 0
/
BusdAutoMine.sol
489 lines (423 loc) · 19.9 KB
/
BusdAutoMine.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
/**
* ____ _ _ ____ ____ _ _ _ _____ ___ __ __ ___ _ _ _____
* | __ )| | | / ___|| _ \ / \ | | | |_ _/ _ \| \/ |_ _| \ | | ____|
* | _ \| | | \___ \| | | | / _ \| | | | | || | | | |\/| || || \| | _|
* | |_) | |_| |___) | |_| | / ___ \ |_| | | || |_| | | | || || |\ | |___
* |____/ \___/|____/|____/ /_/ \_\___/ |_| \___/|_| |_|___|_| \_|_____|
*
*/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
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);
}
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size; assembly {
size := extcodesize(account)
} return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target,bytes memory data,string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target,bytes memory data,uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target,bytes memory data,uint256 value,string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target,bytes memory data,string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target,bytes memory data,string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(bool success,bytes memory returndata,string memory errorMessage) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token,address spender,uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token,address spender,uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
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) {
require(b <= a, "SafeMath: subtraction overflow");
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) {
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
return c;
}
}
//libraries
struct User {
uint256 startDate;
uint256 divs;
uint256 refBonus;
uint256 totalInits;
uint256 totalWiths;
uint256 totalAccrued;
uint256 lastWith;
uint256 timesCmpd;
uint256 keyCounter;
Depo [] depoList;
}
struct Depo {
uint256 key;
uint256 depoTime;
uint256 amt;
address reffy;
bool initialWithdrawn;
}
struct Main {
uint256 ovrTotalDeps;
uint256 ovrTotalWiths;
uint256 users;
uint256 compounds;
}
struct DivPercs{
uint256 daysInSeconds; // updated to be in seconds
uint256 divsPercentage;
}
struct FeesPercs{
uint256 daysInSeconds;
uint256 feePercentage;
}
contract BUSDAutoMine {
using SafeMath for uint256;
uint256 constant launch = 1662138000;
uint256 constant hardDays = 86400;
uint256 constant minStakeAmt = 50 * 10**18;
uint256 constant percentdiv = 1000;
uint256 refPercentage = 100;
uint256 devPercentage = 100;
mapping (address => mapping(uint256 => Depo)) public DeposMap;
mapping (address => User) public UsersKey;
mapping (uint256 => DivPercs) public PercsKey;
mapping (uint256 => FeesPercs) public FeesKey;
mapping (uint256 => Main) public MainKey;
using SafeERC20 for IERC20;
IERC20 public BUSD;
address public owner;
constructor() {
owner = msg.sender;
PercsKey[10] = DivPercs(864000, 15);
PercsKey[20] = DivPercs(1728000, 25);
PercsKey[30] = DivPercs(2592000, 35);
PercsKey[40] = DivPercs(3456000, 45);
PercsKey[50] = DivPercs(4320000, 55);
FeesKey[10] = FeesPercs(864000, 200);
FeesKey[20] = FeesPercs(1728000, 180);
FeesKey[30] = FeesPercs(3456000, 150);
FeesKey[40] = FeesPercs(4320000, 120);
BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
}
function stakeStablecoins(uint256 amtx, address ref) external {
require(block.timestamp >= launch, "App did not launch yet.");
require(ref != msg.sender, "You cannot refer yourself!");
require(amtx >= minStakeAmt, "You should stake at least 50.");
BUSD.safeTransferFrom(msg.sender, address(this), amtx);
User storage user = UsersKey[msg.sender];
User storage user2 = UsersKey[ref];
Main storage main = MainKey[1];
if (user.lastWith == 0){
user.lastWith = block.timestamp;
user.startDate = block.timestamp;
}
uint256 userStakePercentAdjustment = 1000 - devPercentage;
uint256 adjustedAmt = amtx.mul(userStakePercentAdjustment).div(percentdiv);
uint256 stakeFee = amtx.mul(devPercentage).div(percentdiv);
user.totalInits += adjustedAmt;
uint256 refAmtx = adjustedAmt.mul(refPercentage).div(percentdiv);
if (ref != 0x000000000000000000000000000000000000dEaD) {
user2.refBonus += refAmtx;
}
user.depoList.push(Depo({
key: user.depoList.length,
depoTime: block.timestamp,
amt: adjustedAmt,
reffy: ref,
initialWithdrawn: false
}));
user.keyCounter += 1;
main.ovrTotalDeps += 1;
main.users += 1;
BUSD.safeTransfer(owner, stakeFee);
}
function userInfo() view external returns (Depo [] memory depoList) {
User storage user = UsersKey[msg.sender];
return(
user.depoList
);
}
function withdrawDivs() external returns (uint256 withdrawAmount) {
User storage user = UsersKey[msg.sender];
Main storage main = MainKey[1];
uint256 x = calcdiv(msg.sender);
for (uint i = 0; i < user.depoList.length; i++){
if (user.depoList[i].initialWithdrawn == false) {
user.depoList[i].depoTime = block.timestamp;
}
}
uint256 userWithdrawPercentAdjustment = 1000 - devPercentage;
uint256 adjustedAmt = x.mul(userWithdrawPercentAdjustment).div(percentdiv);
uint256 withdrawFee = x.mul(devPercentage).div(percentdiv);
main.ovrTotalWiths += x;
user.lastWith = block.timestamp;
BUSD.safeTransfer(msg.sender, adjustedAmt);
BUSD.safeTransfer(owner, withdrawFee);
return x;
}
function withdrawInitial(uint256 keyy) external {
User storage user = UsersKey[msg.sender];
require(user.depoList[keyy].initialWithdrawn == false, "This has already been withdrawn.");
uint256 initialAmt = user.depoList[keyy].amt;
uint256 currDays1 = user.depoList[keyy].depoTime;
uint256 currTime = block.timestamp;
uint256 currDays = currTime - currDays1;
uint256 transferAmt;
if (currDays < FeesKey[10].daysInSeconds){ // LESS THAN 10 DAYS STAKED
uint256 minusAmt = initialAmt.mul(FeesKey[10].feePercentage).div(percentdiv); //20% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[10].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else if (currDays >= FeesKey[10].daysInSeconds && currDays < FeesKey[20].daysInSeconds){ // BETWEEN 20 and 30 DAYS
uint256 minusAmt = initialAmt.mul(FeesKey[20].feePercentage).div(percentdiv); //18% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[10].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else if (currDays >= FeesKey[20].daysInSeconds && currDays < FeesKey[30].daysInSeconds){ // BETWEEN 30 and 40 DAYS
uint256 minusAmt = initialAmt.mul(FeesKey[30].feePercentage).div(percentdiv); //15% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[20].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else if (currDays >= FeesKey[30].daysInSeconds && currDays < FeesKey[40].daysInSeconds){ // BETWEEN 30 and 40 DAYS
uint256 minusAmt = initialAmt.mul(FeesKey[40].feePercentage).div(percentdiv); //15% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[30].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else if (currDays >= FeesKey[40].daysInSeconds && currDays < FeesKey[50].daysInSeconds){ // BETWEEN 30 and 40 DAYS
uint256 minusAmt = initialAmt.mul(FeesKey[40].feePercentage).div(percentdiv); //12% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[40].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else if (currDays >= FeesKey[50].daysInSeconds){ // 40+ DAYS
uint256 minusAmt = initialAmt.mul(FeesKey[40].feePercentage).div(percentdiv); //12% fee
uint256 dailyReturn = initialAmt.mul(PercsKey[50].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(currDays).div(hardDays);
transferAmt = initialAmt + currentReturn - minusAmt;
user.depoList[keyy].amt = 0;
user.depoList[keyy].initialWithdrawn = true;
user.depoList[keyy].depoTime = block.timestamp;
BUSD.safeTransfer(msg.sender, transferAmt);
BUSD.safeTransfer(owner, minusAmt);
} else {
revert("Could not calculate the # of days youv've been staked.");
}
}
function withdrawRefBonus() external {
User storage user = UsersKey[msg.sender];
uint256 amtz = user.refBonus;
user.refBonus = 0;
BUSD.safeTransfer(msg.sender, amtz);
}
function stakeRefBonus() external {
User storage user = UsersKey[msg.sender];
Main storage main = MainKey[1];
require(user.refBonus > 10);
uint256 refferalAmount = user.refBonus;
user.refBonus = 0;
address ref = 0x000000000000000000000000000000000000dEaD; //DEAD ADDRESS
user.depoList.push(Depo({
key: user.keyCounter,
depoTime: block.timestamp,
amt: refferalAmount,
reffy: ref,
initialWithdrawn: false
}));
user.keyCounter += 1;
main.ovrTotalDeps += 1;
}
function calcdiv(address dy) public view returns (uint256 totalWithdrawable) {
User storage user = UsersKey[dy];
uint256 with;
for (uint256 i = 0; i < user.depoList.length; i++){
uint256 elapsedTime = block.timestamp.sub(user.depoList[i].depoTime);
uint256 amount = user.depoList[i].amt;
if (user.depoList[i].initialWithdrawn == false){
if (elapsedTime <= PercsKey[20].daysInSeconds){
uint256 dailyReturn = amount.mul(PercsKey[10].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(elapsedTime).div(PercsKey[10].daysInSeconds / 10);
with += currentReturn;
}
if (elapsedTime > PercsKey[20].daysInSeconds && elapsedTime <= PercsKey[30].daysInSeconds){
uint256 dailyReturn = amount.mul(PercsKey[20].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(elapsedTime).div(PercsKey[10].daysInSeconds / 10);
with += currentReturn;
}
if (elapsedTime > PercsKey[30].daysInSeconds && elapsedTime <= PercsKey[40].daysInSeconds){
uint256 dailyReturn = amount.mul(PercsKey[30].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(elapsedTime).div(PercsKey[10].daysInSeconds / 10);
with += currentReturn;
}
if (elapsedTime > PercsKey[40].daysInSeconds && elapsedTime <= PercsKey[50].daysInSeconds){
uint256 dailyReturn = amount.mul(PercsKey[40].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(elapsedTime).div(PercsKey[10].daysInSeconds / 10);
with += currentReturn;
}
if (elapsedTime > PercsKey[50].daysInSeconds){
uint256 dailyReturn = amount.mul(PercsKey[50].divsPercentage).div(percentdiv);
uint256 currentReturn = dailyReturn.mul(elapsedTime).div(PercsKey[10].daysInSeconds / 10);
with += currentReturn;
}
}
}
return with;
}
function compound() external {
User storage user = UsersKey[msg.sender];
Main storage main = MainKey[1];
uint256 y = calcdiv(msg.sender);
for (uint i = 0; i < user.depoList.length; i++){
if (user.depoList[i].initialWithdrawn == false) {
user.depoList[i].depoTime = block.timestamp;
}
}
user.depoList.push(Depo({
key: user.keyCounter,
depoTime: block.timestamp,
amt: y,
reffy: 0x000000000000000000000000000000000000dEaD,
initialWithdrawn: false
}));
user.keyCounter += 1;
main.ovrTotalDeps += 1;
main.compounds += 1;
user.lastWith = block.timestamp;
}
}