| 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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790 |
2×
2×
2×
298×
4×
4×
298×
1×
1×
298×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
87×
2×
1×
1×
1×
2×
1×
1×
1×
1×
89×
89×
1×
6×
1×
4×
657×
316×
84×
84×
14×
14×
214×
213×
213×
2×
2×
326×
326×
326×
16×
16×
10×
16×
16×
16×
5×
5×
2×
5×
4×
4×
1×
1×
163×
163×
27×
27×
27×
27×
27×
27×
27×
27×
27×
27×
29×
29×
29×
29×
22×
22×
29×
30×
30×
30×
30×
22×
22×
30×
28×
6×
6×
28×
28×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
4×
4×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
297×
715×
715×
715×
715×
715×
78×
78×
78×
715×
715×
1485×
211×
194×
194×
194×
3×
231×
231×
231×
231×
5×
104×
70×
14×
298×
298×
298×
298×
298×
194×
298×
298×
104×
298×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
298×
298×
298×
194×
104×
70×
70×
104×
297×
5×
16×
275×
1×
297×
194×
103×
1×
1×
1×
1×
1×
1×
1×
1×
275×
275×
275×
275×
275×
275×
16×
16×
16×
16×
16×
16×
16×
5×
5×
5×
5×
5×
5×
5×
297×
297×
297×
4×
297×
297×
297×
297×
891×
891×
92×
92×
92×
92×
92×
92×
297×
30×
30×
1×
1×
| // SPDX-License-Identifier: NOLICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "./TimeLockTransactions.sol";
import "./WithdrawableOwnable.sol";
import "./AntiDumpOwnable.sol";
contract UltimateERC20 is IERC20, Ownable, TimeLockTransactions, WithdrawableOwnable, AntiDumpOwnable {
using SafeMath for uint256;
using Address for address;
struct FeeTier {
uint256 ecoSystemFee;
address ecoSystem;
uint256 stakingFee;
address staking; // wallet para dividendos para detentores de HRS
uint256 liquidityFee; // fee to add funds to the DEX
uint256 taxFee;
uint256 burnFee;
}
struct FeeValues {
uint256 rAmount;
uint256 rTransferAmount;
uint256 rFee;
uint256 tTransferAmount;
uint256 tEcoSystem;
uint256 tStaking;
uint256 tLiquidity;
uint256 tFee;
uint256 tBurn;
}
struct tFeeValues {
uint256 tTransferAmount;
uint256 tEcoSystem;
uint256 tStaking;
uint256 tLiquidity;
uint256 tFee;
uint256 tBurn;
}
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcludedFromReward;
// todo: improve this. we are iterating over this. and this might be costly
address[] private _excluded;
uint256 private constant MAX = type(uint256).max;
uint256 private _tTotal;
uint256 private _rTotal;
// @dev total reflect fee collected
uint256 private _tFeeTotal;
uint256 private _maxFee;
string private _name;
string private _symbol;
uint8 private _decimals;
FeeTier public _defaultFees;
FeeTier private _previousFees;
FeeTier private _emptyFees;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapFactoryAddress;
mapping(address => bool) public automatedMarketMakerPairs;
address public defaultPair;
address public _burnAddress;
// @dev which wallet will receive the ecosystem fee. If dead is used, it goes to the msgSender
address public liquidityAddress;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled;
uint256 public numTokensSellToAddToLiquidity;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 bnbReceived,
uint256 tokensIntoLiquidity
);
// @dev just a protection
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
modifier _checkIfPairIsAuthorized(address from, address to) {
// if the contract has symbol and the name is Cake-LP, it is a pancake pair
if(Address.isContract(from) && !automatedMarketMakerPairs[from]) {
try IUniswapV2Pair(from).symbol() returns (string memory _value) {
Iif(compareStrings(_value, "Cake-LP"))
revert("pair not allowed");
}
catch {}
}
if(Address.isContract(to) && !automatedMarketMakerPairs[to]) {
try IUniswapV2Pair(to).symbol() returns (string memory _value) {
Iif(compareStrings(_value, "Cake-LP"))
revert("pair not allowed");
}
catch {}
}
_;
}
// @dev the constructor
constructor (string memory __name, string memory __symbol) AntiDumpOwnable(9) {
_name = __name;
_symbol = __symbol;
_decimals = 9;
_tTotal = 1000000000 * 10**_decimals;
_rTotal = (MAX - (MAX % _tTotal));
_maxFee = 2 * 10**8; // 20%
swapAndLiquifyEnabled = false;
numTokensSellToAddToLiquidity = _tTotal.div(10**6); // 0.000001% of total supply
_burnAddress = 0x000000000000000000000000000000000000dEaD;
liquidityAddress = _burnAddress;
_rOwned[_msgSender()] = _rTotal;
uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E); // bsc mainnet router
uniswapFactoryAddress = 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73; // pancakeswap factory address
// Create a uniswap pair for this new token
defaultPair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
_setAutomatedMarketMakerPair(defaultPair, true);
//exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_burnAddress] = true;
emit ExcludeFromFee(owner());
emit ExcludeFromFee(address(this));
emit ExcludeFromFee(_burnAddress);
// // todo: check if this is really necessary
// _isExcludedFromReward[owner()] = true;
_isExcludedFromReward[address(this)] = true;
_isExcludedFromReward[_burnAddress] = true;
// set fees
// 5*10**6 is 0,5% 5*10**7 is 5%
_emptyFees = FeeTier({ecoSystemFee:0, stakingFee:0, liquidityFee:5*10**6, taxFee:5*10**6, burnFee:0, ecoSystem:address(this), staking:address(this)});
_defaultFees = FeeTier({ecoSystemFee:125*10**5, stakingFee:125*10**5, liquidityFee:25*10**6, taxFee:5*10**7, burnFee:0, ecoSystem:address(this), staking:address(this)});
emit Transfer(address(0), _msgSender(), _tTotal);
}
// @dev create and add a new pair for a given token
function addNewPair(address tokenAddress) external EonlyOwner returns (address np) {
address newPair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this) ,tokenAddress);
_setAutomatedMarketMakerPair(newPair, true);
emit AddNewPair(tokenAddress, newPair);
return newPair;
}
event AddNewPair(address indexed tokenAddress, address indexed newPair);
function setNumTokensSellToAddToLiquidity(uint256 newLimit) external EonlyOwner {
require(newLimit >= totalSupply().div(10**6), "new limit is too low");
numTokensSellToAddToLiquidity = newLimit;
emit SetNumTokensSellToAddToLiquidity(newLimit);
}
event SetNumTokensSellToAddToLiquidity(uint256 newLimit);
function setAutomatedMarketMakerPair(address pair, bool value) public EonlyOwner {
Erequire(pair != defaultPair, "cannot be removed");
_setAutomatedMarketMakerPair(pair, value);
}
function _setAutomatedMarketMakerPair(address pair, bool value) private EonlyOwner {
automatedMarketMakerPairs[pair] = value;
emit SetAutomatedMarketMakerPair(pair, value);
}
event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
// @dev the default name of the contract
function name() public view returns (string memory) {
return _name;
}
// @dev the symbol of the contract
function symbol() public view returns (string memory) {
return _symbol;
}
// @dev the numbers of decimals the token have
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcludedFromReward[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "BEP20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero"));
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcludedFromReward[account];
}
// @dev total fees collected in tax to be used in reflection(i guess)
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
// todo: is this even useful?
function reflectionFromTokenInTiers(uint256 tAmount, bool _getDefaultFee, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
FeeValues memory _values = _getValues(tAmount, _getDefaultFee);
return _values.rAmount;
} else {
FeeValues memory _values = _getValues(tAmount, _getDefaultFee);
return _values.rTransferAmount;
}
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
return reflectionFromTokenInTiers(tAmount, true, deductTransferFee);
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
Erequire(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public EonlyOwner() {
Erequire(!_isExcludedFromReward[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcludedFromReward[account] = true;
_excluded.push(account);
emit ExcludeFromReward(account);
}
event ExcludeFromReward(address account);
function includeInReward(address account) public EonlyOwner() {
Erequire(_isExcludedFromReward[account], "Account is already included");
for (uint256 i = 0; i < _excluded.length; i++) {
Iif (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcludedFromReward[account] = false;
_excluded.pop();
break;
}
}
emit IncludeInReward(account);
}
event IncludeInReward(address account);
function excludeFromFee(address account) public EonlyOwner() {
_isExcludedFromFee[account] = true;
emit ExcludeFromFee(account);
}
event ExcludeFromFee(address account);
function includeInFee(address account) public EonlyOwner() {
_isExcludedFromFee[account] = false;
emit IncludeInFee(account);
}
event IncludeInFee(address account);
function checkFeesChanged(FeeTier memory _tier, uint256 _oldFee, uint256 _newFee) internal view {
uint256 _fees = _tier.ecoSystemFee
.add(_tier.stakingFee)
.add(_tier.liquidityFee)
.add(_tier.taxFee)
.add(_tier.burnFee)
.add(_newFee)
.sub(_oldFee);
Erequire(_fees <= _maxFee, "Fees exceeded max limitation");
}
function setEcoSystemFeePercent(uint256 _empty, uint256 _default) external EonlyOwner() {
Eif(_default != _defaultFees.ecoSystemFee) {
checkFeesChanged(_defaultFees, _defaultFees.ecoSystemFee, _default);
_defaultFees.ecoSystemFee = _default;
}
Iif(_empty != _emptyFees.ecoSystemFee) {
checkFeesChanged(_emptyFees, _emptyFees.ecoSystemFee, _empty);
_emptyFees.ecoSystemFee = _empty;
}
emit SetEcoSystemFeePercent(_empty, _default);
}
event SetEcoSystemFeePercent(uint256 _empty, uint256 _default);
function setStakingFeePercent(uint256 _empty, uint256 _default) external EonlyOwner() {
Eif(_default != _defaultFees.stakingFee) {
checkFeesChanged(_defaultFees, _defaultFees.stakingFee, _default);
_defaultFees.stakingFee = _default;
}
Iif(_empty != _emptyFees.stakingFee) {
checkFeesChanged(_emptyFees, _emptyFees.stakingFee, _empty);
_emptyFees.stakingFee = _empty;
}
emit SetStakingFeePercent(_empty, _default);
}
event SetStakingFeePercent(uint256 _empty, uint256 _default);
function setLiquidityFeePercent(uint256 _empty, uint256 _default) external EonlyOwner() {
Eif(_default != _defaultFees.liquidityFee) {
checkFeesChanged(_defaultFees, _defaultFees.liquidityFee, _default);
_defaultFees.liquidityFee = _default;
}
if(_empty != _emptyFees.liquidityFee) {
checkFeesChanged(_emptyFees, _emptyFees.liquidityFee, _empty);
_emptyFees.liquidityFee = _empty;
}
emit SetLiquidityFeePercent(_empty, _default);
}
event SetLiquidityFeePercent(uint256 _empty, uint256 _default);
function setTaxFeePercent(uint256 _empty, uint256 _default) external EonlyOwner() {
Eif(_default != _defaultFees.taxFee) {
checkFeesChanged(_defaultFees, _defaultFees.taxFee, _default);
_defaultFees.taxFee = _default;
}
if(_empty != _emptyFees.taxFee) {
checkFeesChanged(_emptyFees, _emptyFees.taxFee, _empty);
_emptyFees.taxFee = _empty;
}
emit SetTaxFeePercent(_empty, _default);
}
event SetTaxFeePercent(uint256 _empty, uint256 _default);
function setBurnFeePercent(uint256 _empty, uint256 _default) external EonlyOwner() {
if(_default != _defaultFees.burnFee) {
checkFeesChanged(_defaultFees, _defaultFees.burnFee, _default);
_defaultFees.burnFee = _default;
}
Iif(_empty != _emptyFees.burnFee) {
checkFeesChanged(_emptyFees, _emptyFees.burnFee, _empty);
_emptyFees.burnFee = _empty;
}
emit SetBurnFeePercent(_empty, _default);
}
event SetBurnFeePercent(uint256 _empty, uint256 _default);
function setEcoSystemFeeAddress(address _empty, address _default) external EonlyOwner() {
Eif(_default != _defaultFees.ecoSystem) {
Erequire(_default != address(0), "Address Zero is not allowed");
includeInReward(_defaultFees.ecoSystem);
_defaultFees.ecoSystem = _default;
excludeFromReward(_default);
}
Eif(_empty != _emptyFees.ecoSystem) {
Erequire(_empty != address(0), "Address Zero is not allowed");
includeInReward(_emptyFees.ecoSystem);
_emptyFees.ecoSystem = _empty;
excludeFromReward(_empty);
}
emit SetEcoSystemFeeAddress(_empty, _default);
}
event SetEcoSystemFeeAddress(address _empty, address _default);
function setStakingFeeAddress(address _empty, address _default) external EonlyOwner() {
Eif(_default != _defaultFees.staking) {
Erequire(_default != address(0), "Address Zero is not allowed");
includeInReward(_defaultFees.staking);
_defaultFees.staking = _default;
excludeFromReward(_default);
}
Eif(_empty != _emptyFees.staking) {
Erequire(_empty != address(0), "Address Zero is not allowed");
includeInReward(_emptyFees.staking);
_emptyFees.staking = _empty;
excludeFromReward(_empty);
}
emit SetStakingFeeAddress(_empty, _default);
}
event SetStakingFeeAddress(address _empty, address _default);
// @dev set liquidity address to receive fees, id dead, the lp token goes to the user
function setLiqudityFeeAddress(address newAddress) public EonlyOwner {
Erequire(liquidityAddress != newAddress, "Liquidity address already setted");
Erequire(liquidityAddress != address(0), "Address Zero is not allowed");
includeInReward(liquidityAddress);
liquidityAddress = newAddress;
excludeFromReward(newAddress);
emit SetLiqudityFeeAddress(newAddress);
}
event SetLiqudityFeeAddress(address indexed liquidityAddress);
function updateRouter(address _uniswapV2Router) public onlyOwner() {
uniswapV2Router = IUniswapV2Router02(_uniswapV2Router);
emit UpdateRouter(_uniswapV2Router);
}
event UpdateRouter(address _uniswapV2Router);
// @dev enable the swap mechanisms. This can only be enabled. The owner cannot disable swap or lock the contract by any means.
function enableSwapAndLiquify() external EonlyOwner() {
swapAndLiquifyEnabled = true;
emit SwapAndLiquifyEnabledUpdated(true);
}
//to receive BNB from uniswapV2Router when swapping
receive() external payable {}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount, bool _getDefault) private view returns (FeeValues memory) {
tFeeValues memory tValues = _getTValues(tAmount, _getDefault);
uint256 tTransferFee = tValues.tLiquidity.add(tValues.tEcoSystem).add(tValues.tStaking).add(tValues.tBurn);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tValues.tFee, tTransferFee, _getRate());
return FeeValues(rAmount, rTransferAmount, rFee, tValues.tTransferAmount, tValues.tEcoSystem, tValues.tStaking, tValues.tLiquidity, tValues.tFee, tValues.tBurn);
}
function _getTValues(uint256 tAmount, bool _getDefault) private view returns (tFeeValues memory) {
FeeTier memory tier = _getDefault ? _defaultFees : E_emptyFees;
tFeeValues memory tValues = tFeeValues(
0,
calculateFee(tAmount, tier.ecoSystemFee),
calculateFee(tAmount, tier.stakingFee),
calculateFee(tAmount, tier.liquidityFee),
calculateFee(tAmount, tier.taxFee),
calculateFee(tAmount, tier.burnFee)
);
tValues.tTransferAmount = tAmount.sub(tValues.tEcoSystem).sub(tValues.tStaking).sub(tValues.tFee).sub(tValues.tLiquidity).sub(tValues.tBurn);
return tValues;
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTransferFee, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTransferFee = tTransferFee.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rTransferFee);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
Iif (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
Iif (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function calculateFee(uint256 _amount, uint256 _fee) private pure returns (uint256) {
if(_fee == 0) return 0;
return _amount.mul(_fee).div(
10**9
);
}
function removeAllFee() private {
_previousFees = _defaultFees;
_defaultFees = _emptyFees;
}
function restoreAllFee() private {
_defaultFees = _previousFees;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(
address owner,
address spender,
uint256 amount
)
private
{
Erequire(owner != address(0), "BEP20: approve from the zero address");
Erequire(spender != address(0), "BEP20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function compareStrings(string memory a, string memory b) public pure returns (bool) {
return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
}
function timeLockCheck(address from, address to) internal {
if(automatedMarketMakerPairs[to]) // selling tokens
lockIfCanOperateAndRevertIfNotAllowed(from);
else if(automatedMarketMakerPairs[from]) // buying tokens
lockIfCanOperateAndRevertIfNotAllowed(to);
}
function _transfer(
address from,
address to,
uint256 amount
)
private
E_checkIfPairIsAuthorized(from, to)
{
Erequire(from != address(0), "BEP20: transfer from the zero address");
Erequire(to != address(0), "BEP20: transfer to the zero address");
Erequire(amount > 0, "Transfer amount must be greater than zero");
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromFee account then remove the fee
if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
bool isDefaultFee = true;
if(takeFee) {
if(_msgSender() != from) isDefaultFee = !_isExcludedFromFee[_msgSender()];
else isDefaultFee = !_isExcludedFromFee[from];
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from, to, amount, isDefaultFee, takeFee);
}
function swapAndLiquify(uint256 contractTokenBalance, address cakeReceiver) private ElockTheSwap {
// split the contract balance into halves
uint256 half = contractTokenBalance.div(2);
uint256 otherHalf = contractTokenBalance.sub(half);
// capture the contract's current BNB balance.
// this is so that we can capture exactly the amount of BNB that the
// swap creates, and not make the liquidity event include any BNB that
// has been manually sent to the contract
uint256 initialBalance = address(this).balance;
// swap tokens for BNB
swapTokensForBnb(half);
// how much BNB did we just swap into?
uint256 newBalance = address(this).balance.sub(initialBalance);
// add liquidity to uniswap
addLiquidity(otherHalf, newBalance, cakeReceiver);
// todo: inspect if some tokens still remains in the contract caused by accumulation of small slippages when addLiquidity
emit SwapAndLiquify(half, newBalance, otherHalf);
}
function swapTokensForBnb(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> wbnb
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of BNB
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 bnbAmount, address cakeReceiver) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{ value: bnbAmount }(
address(this),
tokenAmount,
0,
0,
cakeReceiver,
block.timestamp.add(300)
);
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount, bool _isDefaultFee, bool takeFee) private {
FeeTier storage _feesWithAntiDump = _defaultFees;
uint256 _previousTaxFee = _feesWithAntiDump.taxFee;
if(!takeFee)
removeAllFee();
else { // check antidump
if(automatedMarketMakerPairs[recipient]) {
uint256 extraFee = getAntiDumpFee(recipient, amount);
// add antidump fee to reflection fee
_feesWithAntiDump.taxFee = _feesWithAntiDump.taxFee.add(extraFee);
}
// check authorized time window
timeLockCheck(sender, recipient);
}
if (_isExcludedFromReward[sender] && !_isExcludedFromReward[recipient]) {
_transferFromExcluded(sender, recipient, amount, _isDefaultFee);
} else if (!_isExcludedFromReward[sender] && _isExcludedFromReward[recipient]) {
_transferToExcluded(sender, recipient, amount, _isDefaultFee);
} else if (!_isExcludedFromReward[sender] && !_isExcludedFromReward[recipient]) {
_transferStandard(sender, recipient, amount, _isDefaultFee);
} else Eif (_isExcludedFromReward[sender] && _isExcludedFromReward[recipient]) {
_transferBothExcluded(sender, recipient, amount, _isDefaultFee);
} else {
_transferStandard(sender, recipient, amount, _isDefaultFee);
}
if(!takeFee)
restoreAllFee();
else {
_feesWithAntiDump.taxFee = _previousTaxFee; // reset tax fee
}
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount, bool _isDefaultFee) private {
FeeValues memory _values = _getValues(tAmount, _isDefaultFee);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(_values.rAmount);
_tOwned[recipient] = _tOwned[recipient].add(_values.tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(_values.rTransferAmount);
_takeFees(sender, _values, _isDefaultFee);
_reflectFee(_values.rFee, _values.tFee);
emit Transfer(sender, recipient, _values.tTransferAmount);
}
function _transferStandard(address sender, address recipient, uint256 tAmount, bool _isDefaultFee) private {
FeeValues memory _values = _getValues(tAmount, _isDefaultFee);
_rOwned[sender] = _rOwned[sender].sub(_values.rAmount);
_rOwned[recipient] = _rOwned[recipient].add(_values.rTransferAmount);
_takeFees(sender, _values, _isDefaultFee);
_reflectFee(_values.rFee, _values.tFee);
emit Transfer(sender, recipient, _values.tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount, bool _isDefaultFee) private {
FeeValues memory _values = _getValues(tAmount, _isDefaultFee);
_rOwned[sender] = _rOwned[sender].sub(_values.rAmount);
_tOwned[recipient] = _tOwned[recipient].add(_values.tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(_values.rTransferAmount);
_takeFees(sender, _values, _isDefaultFee);
_reflectFee(_values.rFee, _values.tFee);
emit Transfer(sender, recipient, _values.tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount, bool _isDefaultFee) private {
FeeValues memory _values = _getValues(tAmount, _isDefaultFee);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(_values.rAmount);
_rOwned[recipient] = _rOwned[recipient].add(_values.rTransferAmount);
_takeFees(sender, _values, _isDefaultFee);
_reflectFee(_values.rFee, _values.tFee);
emit Transfer(sender, recipient, _values.tTransferAmount);
}
function _takeFees(address sender, FeeValues memory values, bool _isDefaultFee) private {
_takeFee(sender, values.tLiquidity, address(this));
bool overMinTokenBalance = balanceOf(address(this)) >= numTokensSellToAddToLiquidity;
if (
overMinTokenBalance &&
!inSwapAndLiquify &&
!automatedMarketMakerPairs[sender] &&
swapAndLiquifyEnabled
) {
//add liquidity
if(liquidityAddress != _burnAddress) swapAndLiquify(balanceOf(address(this)), liquidityAddress);
else if (values.tLiquidity > 0) swapAndLiquify(values.tLiquidity, sender);
}
Eif(_isDefaultFee) {
_takeFee(sender, values.tEcoSystem, _defaultFees.ecoSystem);
_takeFee(sender, values.tStaking, _defaultFees.staking);
}
else {
_takeFee(sender, values.tEcoSystem, _emptyFees.ecoSystem);
_takeFee(sender, values.tStaking, _emptyFees.staking);
}
_takeBurn(sender, values.tBurn);
}
function _takeFee(address sender, uint256 tAmount, address recipient) private {
Iif(recipient == address(0)) return;
if(tAmount == 0) return;
uint256 currentRate = _getRate();
uint256 rAmount = tAmount.mul(currentRate);
_rOwned[recipient] = _rOwned[recipient].add(rAmount);
Eif(_isExcludedFromReward[recipient])
_tOwned[recipient] = _tOwned[recipient].add(tAmount);
emit Transfer(sender, recipient, tAmount);
}
function _takeBurn(address sender, uint256 _amount) private {
if(_amount == 0) return;
_tOwned[_burnAddress] = _tOwned[_burnAddress].add(_amount);
emit Transfer(sender, _burnAddress, _amount);
}
function updateBurnAddress(address _newBurnAddress) external EonlyOwner() {
_burnAddress = _newBurnAddress;
excludeFromReward(_newBurnAddress);
}
}
|