-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimple.sol
More file actions
433 lines (313 loc) · 14.2 KB
/
Copy pathSimple.sol
File metadata and controls
433 lines (313 loc) · 14.2 KB
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
// SPDX-License-Identifier: MIT
/*
Dynamic Fees:
Any time someone trades, their price impact is calculated and added onto the sell fee before their sell. The buy fee goes down by the same amount. Fees revert back to 10% at a rate of 1% per minute.
There is a maximum trade fee of 30%, and minimum buy fee of -10% (ie, a 10% bonus on trades in).
Hourly Biggest Buyer:
Every hour, 5% of the tokens from liquidity will be rewarded to the biggest trader of the previous hour. Fully automated on-chain.
Vested Dividends:
fees are converted to ETH and paid as ETH dividends to holders. Dividends vest continuously over 3 days. If you sell early, you will miss out on some rewards. Hold and behold.
HUGE THANKS TO ASHONCHAIN
*/
pragma solidity ^0.8.4;
import "./DividendTracker.sol";
import "./SafeMath.sol";
import "./IterableMapping.sol";
import "./Ownable.sol";
import "./IUniswapV2Pair.sol";
import "./IUniswapV2Factory.sol";
import "./IUniswapV2Router.sol";
import "./UniswapV2PriceImpactCalculator.sol";
import "./LiquidityBurnCalculator.sol";
import "./MaxWalletCalculator.sol";
import "./Storage.sol";
contract SIMPLE is ERC20, Ownable {
using SafeMath for uint256;
using Storage for Storage.Data;
using Fees for Fees.Data;
using BiggestTrader for Biggestrader.Data;
using Referrals for Referrals.Data;
using Transfers for Transfers.Data;
Storage.Data private _storage;
uint256 public constant MAX_SUPPLY = 1000000 * (10**18);
uint256 private hatchTime;
bool private swapping;
uint256 public liquidityTokensAvailableToBurn;
uint256 public liquidityBurnTime;
DividendTracker public dividendTracker;
uint256 private swapTokensAtAmount = 200 * (10**18);
uint256 private swapTokensMaxAmount = 1000 * (10**18);
// exlcude from fees and max transaction amount
mapping (address => bool) public isExcludedFromFees;
event UpdateDividendTracker(address indexed newAddress);
event ExcludeFromFees(address indexed account, bool isExcluded);
event ExcludeMultipleAccountsFromFees(address[] accounts, bool isExcluded);
event LiqudityBurn(uint256 value);
event LiquidityBurn(
uint256 amount
);
event ClaimTokens(
address indexed account,
uint256 amount
);
event UpdateMysteryContract(address mysteryContract);
constructor() ERC20("Simple", "$SIMP) {
_storage.router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
_storage.pair = IUniswapV2Pair(
IUniswapV2Factory(_storage.router.factory()
).createPair(address(this), _storage.router.WETH()));
_mint(owner(), MAX_SUPPLY);
_approve(address(this), address(_storage.router), type(uint).max);
IUniswapV2Pair(_storage.pair).approve(address(_storage.router), type(uint).max);
_storage.fees.init(_storage, address(_storage.pair));
_storage.biggestBuyer.init();
_storage.referrals.init();
_storage.transfers.init(address(_storage.router), address(_storage.pair));
_storage.dividendTracker = new ChameleonDividendTracker(payable(address(this)), address(_storage.pair), _storage.router.WETH());
setupDividendTracker();
_storage.marketingWallet1 = 0xeD9017c2c910967a4dab176160E68544f451716C;
_storage.marketingWallet2 = 0x768b5315282bC0A84a9fE4762621336246C3c364;
excludeFromFees(owner(), true);
excludeFromFees(address(this), true);
excludeFromFees(address(_storage.router), true);
excludeFromFees(address(_storage.dividendTracker), true);
excludeFromFees(_storage.marketingWallet1, true);
excludeFromFees(_storage.marketingWallet2, true);
}
receive() external payable {
}
function approve(address spender, uint256 amount) public override returns (bool) {
//Piggyback off approvals to burn tokens
burnLiquidityTokens();
return super.approve(spender, amount);
}
function approveWithoutBurn(address spender, uint256 amount) public returns (bool) {
return super.approve(spender, amount);
}
function updateMysteryContract(address mysteryContract) public onlyOwner {
_storage.mysteryContract = IMysteryContract(mysteryContract);
emit UpdateMysteryContract(mysteryContract);
isExcludedFromFees[mysteryContract] = true;
//ensure the functions exist
_storage.mysteryContract.handleBuy(address(0), 0, 0);
_storage.mysteryContract.handleSell(address(0), 0, 0);
}
function updateBaseFee(uint256 baseFee) public onlyOwner {
_storage.fees.updateBaseFee(baseFee);
}
function updateFeeImpacts(uint256 sellImpact, uint256 timeImpact) public onlyOwner {
_storage.fees.updateFeeSellImpact(sellImpact);
_storage.fees.updateFeeTimeImpact(timeImpact);
}
function updateFeeDestinationPercents(uint256 dividendsPercent, uint256 marketingPercent, uint256 mysteryPercent) public onlyOwner {
_storage.fees.updateFeeDestinationPercents(_storage, dividendsPercent, marketingPercent, mysteryPercent);
}
function updateBiggestBuyerRewardFactor(uint256 value) public onlyOwner {
_storage.biggestBuyer.updateRewardFactor(value);
}
function updateReferrals(uint256 referralBonus, uint256 referredBonus, uint256 tokensNeeded) public onlyOwner {
_storage.referrals.updateReferralBonus(referralBonus);
_storage.referrals.updateReferredBonus(referredBonus);
_storage.referrals.updateTokensNeededForReferralNumber(tokensNeeded);
}
function updateDividendTracker(address newAddress) public onlyOwner {
_storage.dividendTracker = ChameleonDividendTracker(payable(newAddress));
require(_storage.dividendTracker.owner() == address(this));
setupDividendTracker();
emit UpdateDividendTracker(newAddress);
}
function setupDividendTracker() private {
_storage.dividendTracker.excludeFromDividends(address(_storage.dividendTracker));
_storage.dividendTracker.excludeFromDividends(address(this));
_storage.dividendTracker.excludeFromDividends(owner());
_storage.dividendTracker.excludeFromDividends(address(_storage.router));
_storage.dividendTracker.excludeFromDividends(address(_storage.pair));
}
function excludeFromFees(address account, bool excluded) public onlyOwner {
isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
function excludeFromDividends(address account) public onlyOwner {
_storage.dividendTracker.excludeFromDividends(account);
}
function updateVestingDuration(uint256 vestingDuration) external onlyOwner {
_storage.dividendTracker.updateVestingDuration(vestingDuration);
}
function updateUnvestedDividendsMarketingFee(uint256 unvestedDividendsMarketingFee) external onlyOwner {
_storage.dividendTracker.updateUnvestedDividendsMarketingFee(unvestedDividendsMarketingFee);
}
function setSwapTokensAtAmount(uint256 amount) external onlyOwner {
require(amount < 1000 * (10**18));
swapTokensAtAmount = amount;
}
function setSwapTokensMaxAmount(uint256 amount) external onlyOwner {
require(amount < 10000 * (10**18));
swapTokensMaxAmount = amount;
}
function manualSwapAccumulatedFees() external onlyOwner {
_storage.fees.swapAccumulatedFees(_storage, balanceOf(address(this)));
}
function getData(address account) external view returns (uint256[] memory dividendInfo, uint256 referralCode, int256 buyFee, uint256 sellFee, address biggestBuyerCurrentHour, uint256 biggestBuyerAmountCurrentHour, uint256 biggestBuyerRewardCurrentHour, address biggestBuyerPreviousHour, uint256 biggestBuyerAmountPreviousHour, uint256 biggestBuyerRewardPreviousHour, uint256 blockTimestamp) {
dividendInfo = _storage.dividendTracker.getDividendInfo(account);
referralCode = _storage.referrals.getReferralCode(account);
(buyFee,
sellFee) = _storage.fees.getCurrentFees();
uint256 hour = _storage.biggestBuyer.getHour();
(biggestBuyerCurrentHour, biggestBuyerAmountCurrentHour,) = _storage.biggestBuyer.getBiggestBuyer(hour);
biggestBuyerRewardCurrentHour = _storage.biggestBuyer.calculateBiggestBuyerReward(getLiquidityTokenBalance());
if(hour > 0) {
(biggestBuyerPreviousHour, biggestBuyerAmountPreviousHour, biggestBuyerRewardPreviousHour) = _storage.biggestBuyer.getBiggestBuyer(hour - 1);
if(biggestBuyerPreviousHour != address(0) &&
biggestBuyerRewardPreviousHour == 0) {
biggestBuyerRewardPreviousHour = biggestBuyerRewardCurrentHour;
}
}
blockTimestamp = block.timestamp;
}
function getLiquidityTokenBalance() private view returns (uint256) {
return balanceOf(address(_storage.pair));
}
function claimDividends() external {
_storage.dividendTracker.claimDividends(
msg.sender,
_storage.marketingWallet1,
_storage.marketingWallet2,
false);
}
function burnLiquidityTokens() public {
uint256 burnAmount = LiquidityBurnCalculator.calculateBurn(
getLiquidityTokenBalance(),
liquidityTokensAvailableToBurn,
liquidityBurnTime);
if(burnAmount == 0) {
return;
}
liquidityBurnTime = block.timestamp;
liquidityTokensAvailableToBurn -= burnAmount;
_burn(address(_storage.pair), burnAmount);
_storage.pair.sync();
emit LiquidityBurn(burnAmount);
}
function hatch() external onlyOwner {
require(hatchTime == 0);
_storage.router.addLiquidityETH {
value: address(this).balance
} (
address(this),
balanceOf(address(this)),
0,
0,
owner(),
block.timestamp
);
hatchTime = block.timestamp;
}
function takeFees(address from, uint256 amount, uint256 feeFactor) private returns (uint256) {
uint256 fees = Fees.calculateFees(amount, feeFactor);
amount = amount.sub(fees);
super._transfer(from, address(this), fees);
return amount;
}
function mintFromLiquidity(address account, uint256 amount) private {
if(amount == 0) {
return;
}
liquidityTokensAvailableToBurn += amount;
_mint(account, amount);
}
function handleNewBalanceForReferrals(address account) private {
if(isExcludedFromFees[account]) {
return;
}
if(account == address(_storage.pair)) {
return;
}
_storage.referrals.handleNewBalance(account, balanceOf(account));
}
function payBiggestBuyer(uint256 hour) public {
uint256 liquidityTokenBalance = getLiquidityTokenBalance();
(address winner, uint256 amountWon) = _storage.biggestBuyer.payBiggestBuyer(hour, liquidityTokenBalance);
if(winner != address(0)) {
mintFromLiquidity(winner, amountWon);
handleNewBalanceForReferrals(winner);
_storage.dividendTracker.setBalance(winner, balanceOf(winner));
}
}
function maxWallet() public view returns (uint256) {
return MaxWalletCalculator.calculateMaxWallet(MAX_SUPPLY, hatchTime);
}
function executePossibleSwap(address from, address to, uint256 amount) private {
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapTokensAtAmount;
if(from != owner() && to != owner()) {
if(
to != address(this) &&
to != address(_storage.pair) &&
to != address(_storage.router)
) {
require(balanceOf(to) + amount <= maxWallet());
}
if(
canSwap &&
!swapping &&
from != address(_storage.pair) &&
hatchTime > 0 &&
block.timestamp > hatchTime
) {
swapping = true;
uint256 swapAmount = contractTokenBalance;
if(swapAmount > swapTokensMaxAmount) {
swapAmount = swapTokensMaxAmount;
}
_approve(address(this), address(_storage.router), swapAmount);
_storage.fees.swapAccumulatedFees(_storage, swapAmount);
swapping = false;
}
}
}
function _transfer(address from, address to, uint256 amount) internal override {
require(from != address(0));
require(to != address(0));
if(amount == 0) {
super._transfer(from, to, 0);
return;
}
executePossibleSwap(from, to, amount);
bool takeFee = !swapping &&
!isExcludedFromFees[from] &&
!isExcludedFromFees[to];
uint256 originalAmount = amount;
int256 transferFees = 0;
if(takeFee) {
address referrer = _storage.referrals.getReferrerFromTokenAmount(amount);
if(!_storage.referrals.isValidReferrer(referrer, balanceOf(referrer), to)) {
referrer = address(0);
}
(uint256 fees,
uint256 buyerMint,
uint256 referrerMint) =
_storage.transfers.handleTransferWithFees(_storage, from, to, amount, referrer);
transferFees = int256(fees) - int256(buyerMint);
if(fees > 0) {
amount -= fees;
super._transfer(from, address(this), fees);
}
if(buyerMint > 0) {
mintFromLiquidity(to, buyerMint);
}
if(referrerMint > 0) {
mintFromLiquidity(referrer, referrerMint);
_storage.dividendTracker.setBalance(referrer, balanceOf(referrer));
}
}
super._transfer(from, to, amount);
handleNewBalanceForReferrals(to);
uint256 hour = _storage.biggestBuyer.getHour();
if(hour > 0) {
payBiggestBuyer(hour - 1);
}
_storage.dividendTracker.setBalance(from, balanceOf(from));
_storage.dividendTracker.setBalance(to, balanceOf(to));
_storage.handleTransfer(from, to, originalAmount, transferFees);
}
}