forked from kriosfinance/Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Respect.sol
1051 lines (878 loc) · 32.5 KB
/
Respect.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
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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
RRRRRRRRRRRRRRRRR
R::::::::::::::::R
R::::::RRRRRR:::::R
RR:::::R R:::::R
R::::R R:::::R
R::::R R:::::R
R::::RRRRRR:::::R
R:::::::::::::RR
R::::RRRRRR:::::R
R::::R R:::::R
R::::R R:::::R
R::::R R:::::R
:::::R R:::::R
:::::R R:::::R
:::::R R:::::R
RRRRRRR RRRRRRR
Respect Finance - Ultra High APY Autocompounding Protocol powered by Cronos
Website: https://respect.finance
*/
pragma solidity ^0.7.4;
library SafeMathInt {
int256 private constant MIN_INT256 = int256(1) << 255;
int256 private constant MAX_INT256 = ~(int256(1) << 255);
function mul(int256 a, int256 b) internal pure returns (int256) {
int256 c = a * b;
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
function div(int256 a, int256 b) internal pure returns (int256) {
require(b != -1 || a != MIN_INT256);
return a / b;
}
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
function abs(int256 a) internal pure returns (int256) {
require(a != MIN_INT256);
return a < 0 ? -a : a;
}
}
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) {
require(b != 0);
return a % b;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender)
external
view
returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
interface IPancakeSwapPair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IPancakeSwapRouter{
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface IPancakeSwapFactory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
contract Ownable {
address private _owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_owner = msg.sender;
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner());
_;
}
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(_owner);
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
abstract contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
}
interface IUSDCReceiver {
function initialize(address) external;
function withdraw() external;
function withdrawUnsupportedAsset(address, uint256) external;
function transferOwnership(address) external;
}
contract USDCReceiver is Ownable {
address public usdc;
address public token;
constructor() Ownable() {
token = msg.sender;
}
function initialize(address _usdc) public onlyOwner {
require(usdc == address(0x0), "Already initialized");
usdc = _usdc;
}
function withdraw() public {
require(msg.sender == token, "Caller is not token");
IERC20(usdc).transfer(token, IERC20(usdc).balanceOf(address(this)));
}
function withdrawUnsupportedAsset(address _token, uint256 _amount) public onlyOwner {
if(_token == address(0x0))
payable(owner()).transfer(_amount);
else
IERC20(_token).transfer(owner(), _amount);
}
}
contract Respect is ERC20Detailed, Ownable {
using SafeMath for uint256;
using SafeMathInt for int256;
event LogRebase(uint256 indexed epoch, uint256 totalSupply);
event SwapEnabled();
string public _name = "Respect Finance";
string public _symbol = "RSPCT";
uint8 public _decimals = 5;
IPancakeSwapPair public pairContract;
mapping(address => bool) _isFeeExempt;
modifier validRecipient(address to) {
require(to != address(0x0));
_;
}
uint256 public constant DECIMALS = 5;
uint256 public constant MAX_UINT256 = ~uint256(0);
uint8 public constant RATE_DECIMALS = 7;
uint256 public constant TIME_STEP = 1 days;
uint256 private constant INITIAL_FRAGMENTS_SUPPLY = 300 * 10**4 * 10**DECIMALS;
uint256 public liquidityFee = 50;
uint256 public treasuryFee = 30;
uint256 public rspctInsuranceFundFee = 50;
uint256 public sellFee = 20;
uint256 public blackholeFee = 10;
uint256 public nftFee = 20;
uint256 public totalFee = liquidityFee.add(treasuryFee).add(rspctInsuranceFundFee).add(blackholeFee);
uint256 public feeDenominator = 1000;
uint256 public startTime;
uint256 public sellLimit = 0;
uint256 public holdLimit = 0;
uint256 public limitDenominator = 10000;
address DEAD = 0x000000000000000000000000000000000000dEaD;
address ZERO = 0x0000000000000000000000000000000000000000;
address USDC = 0xc21223249CA28397B4B6541dfFaEcC539BfF0c59;
address ROUTER = 0x145677FC4d9b8F19B5D56d1820c48e0443049a30;
address public autoLiquidityReceiver;
address public treasuryReceiver;
address public rspctInsuranceFundReceiver;
address public usdcReceiver;
address public blackhole;
address public nftFeeReceiver;
address public pairAddress;
bool public swapEnabled = false;
IPancakeSwapRouter public router;
address public pair;
bool inSwap = false;
modifier swapping() {
inSwap = true;
_;
inSwap = false;
}
uint256 private constant TOTAL_GONS = MAX_UINT256 - (MAX_UINT256 % INITIAL_FRAGMENTS_SUPPLY);
uint256 private constant MAX_SUPPLY = 300 * 10**8 * 10**DECIMALS;
bool public _autoRebase;
bool public _autoAddLiquidity;
uint256 public _initRebaseStartTime;
uint256 public _lastRebasedTime;
uint256 public _lastAddLiquidityTime;
uint256 public _totalSupply;
uint256 private _gonsPerFragment;
mapping(address => uint256) private _gonBalances;
mapping(address => mapping(address => uint256)) private _allowedFragments;
mapping(address => bool) public blacklist;
mapping(address => mapping(uint256 => uint256)) public sold;
mapping(address => bool) public _excludeFromLimit;
modifier checkLimit(address from, address to, uint256 value) {
if(!_excludeFromLimit[from]) {
require(sold[from][getCurrentDay()] + value <= getUserSellLimit(), "Cannot sell or transfer more than limit.");
}
_;
if(!_excludeFromLimit[to]) {
require(_gonBalances[to].div(_gonsPerFragment) <= getUserHoldLimit(), "Cannot buy more than limit.");
}
}
constructor() ERC20Detailed("Respect Finance", "RSPCT", uint8(DECIMALS)) Ownable() {
bytes memory bytecode = type(USDCReceiver).creationCode;
bytes32 salt = keccak256(abi.encodePacked(USDC));
address receiver;
assembly {
receiver := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
IUSDCReceiver(receiver).initialize(USDC);
usdcReceiver = receiver;
router = IPancakeSwapRouter(ROUTER);
pair = IPancakeSwapFactory(router.factory()).createPair(
USDC,
address(this)
);
autoLiquidityReceiver = 0xce8ACeE54A536B2e14b5B34c30470eef7D45F115;
treasuryReceiver = 0x025009D6B0Dd556De0266CdfBa4201faaB30119e;
rspctInsuranceFundReceiver = 0xF9A64cB8Eb42FeCdcd027B1ceA088aC8f3c71b30;
blackhole = DEAD;
nftFeeReceiver = 0x8A27A021323754D1D95dc9FDe216e3C3Da92f570;
_allowedFragments[address(this)][address(router)] = uint256(-1);
pairAddress = pair;
pairContract = IPancakeSwapPair(pair);
_totalSupply = INITIAL_FRAGMENTS_SUPPLY;
_gonBalances[treasuryReceiver] = TOTAL_GONS;
_gonsPerFragment = TOTAL_GONS.div(_totalSupply);
_initRebaseStartTime = block.timestamp;
_lastRebasedTime = block.timestamp;
startTime = block.timestamp;
_autoRebase = true;
_autoAddLiquidity = true;
_isFeeExempt[treasuryReceiver] = true;
_isFeeExempt[address(this)] = true;
_isFeeExempt[msg.sender] = true;
_excludeFromLimit[address(this)] = true;
_excludeFromLimit[pair] = true;
_excludeFromLimit[msg.sender]=true;
IUSDCReceiver(receiver).transferOwnership(treasuryReceiver);
_transferOwnership(treasuryReceiver);
emit Transfer(address(0x0), treasuryReceiver, _totalSupply);
}
function rebase() internal {
if ( inSwap ) return;
uint256 rebaseRate;
uint256 deltaTimeFromInit = block.timestamp - _initRebaseStartTime;
uint256 deltaTime = block.timestamp - _lastRebasedTime;
uint256 times = deltaTime.div(12 minutes);
uint256 epoch = times.mul(12);
if (deltaTimeFromInit < (365 days)) {
rebaseRate = 2000;
} else if (deltaTimeFromInit >= (7 * 365 days)) {
rebaseRate = 2;
} else if (deltaTimeFromInit >= (548 days)) {
rebaseRate = 14;
} else {
rebaseRate = 211;
}
for (uint256 i = 0; i < times; i++) {
_totalSupply = _totalSupply
.mul((10**RATE_DECIMALS).add(rebaseRate))
.div(10**RATE_DECIMALS);
}
_gonsPerFragment = TOTAL_GONS.div(_totalSupply);
_lastRebasedTime = _lastRebasedTime.add(times.mul(12 minutes));
pairContract.sync();
emit LogRebase(epoch, _totalSupply);
}
function transfer(address to, uint256 value)
external
override
validRecipient(to)
returns (bool)
{
_transferFrom(msg.sender, to, value);
return true;
}
function transferFrom(
address from,
address to,
uint256 value
) external override validRecipient(to) returns (bool) {
if (_allowedFragments[from][msg.sender] != uint256(-1)) {
_allowedFragments[from][msg.sender] = _allowedFragments[from][
msg.sender
].sub(value, "Insufficient Allowance");
}
_transferFrom(from, to, value);
return true;
}
function _basicTransfer(
address from,
address to,
uint256 amount
) internal returns (bool) {
uint256 gonAmount = amount.mul(_gonsPerFragment);
_gonBalances[from] = _gonBalances[from].sub(gonAmount);
_gonBalances[to] = _gonBalances[to].add(gonAmount);
return true;
}
function _transferFrom(
address sender,
address recipient,
uint256 amount
) internal checkLimit(sender, recipient, amount) returns (bool) {
if(sender != owner() && recipient != owner()) {
require(swapEnabled, "Swap is not enabled");
}
require(!blacklist[sender] && !blacklist[recipient], "in_blacklist");
if (inSwap) {
return _basicTransfer(sender, recipient, amount);
}
if (shouldRebase()) {
rebase();
}
if (shouldAddLiquidity()) {
addLiquidity();
}
if (shouldSwapBack()) {
swapBack();
}
uint256 gonAmount = amount.mul(_gonsPerFragment);
_gonBalances[sender] = _gonBalances[sender].sub(gonAmount);
uint256 gonAmountReceived = shouldTakeFee(sender, recipient)
? takeFee(sender, recipient, gonAmount)
: gonAmount;
_gonBalances[recipient] = _gonBalances[recipient].add(
gonAmountReceived
);
sold[sender][getCurrentDay()] = sold[sender][getCurrentDay()].add(amount);
emit Transfer(
sender,
recipient,
gonAmountReceived.div(_gonsPerFragment)
);
return true;
}
function takeFee(
address sender,
address recipient,
uint256 gonAmount
) internal returns (uint256) {
uint256 _totalFee = totalFee;
uint256 _treasuryFee = treasuryFee;
uint256 _nftFee = 0;
if (recipient == pair) {
_totalFee = totalFee.add(sellFee).add(nftFee);
_treasuryFee = treasuryFee.add(sellFee);
_nftFee = nftFee;
}
uint256 feeAmount = gonAmount.div(feeDenominator).mul(_totalFee);
_gonBalances[blackhole] = _gonBalances[blackhole].add(
gonAmount.div(feeDenominator).mul(blackholeFee)
);
_gonBalances[address(this)] = _gonBalances[address(this)].add(
gonAmount.div(feeDenominator).mul(_treasuryFee.add(rspctInsuranceFundFee))
);
_gonBalances[autoLiquidityReceiver] = _gonBalances[autoLiquidityReceiver].add(
gonAmount.div(feeDenominator).mul(liquidityFee)
);
_gonBalances[nftFeeReceiver] = _gonBalances[nftFeeReceiver].add(
gonAmount.div(feeDenominator).mul(_nftFee)
);
emit Transfer(sender, address(this), feeAmount.div(_gonsPerFragment));
return gonAmount.sub(feeAmount);
}
function addLiquidity() internal swapping {
uint256 autoLiquidityAmount = _gonBalances[autoLiquidityReceiver].div(
_gonsPerFragment
);
_gonBalances[address(this)] = _gonBalances[address(this)].add(
_gonBalances[autoLiquidityReceiver]
);
_gonBalances[autoLiquidityReceiver] = 0;
uint256 amountToLiquify = autoLiquidityAmount.div(2);
uint256 amountToSwap = autoLiquidityAmount.sub(amountToLiquify);
if( amountToSwap == 0 ) {
return;
}
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = USDC;
uint256 balanceBefore = IERC20(USDC).balanceOf(address(this));
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
usdcReceiver,
block.timestamp
);
IUSDCReceiver(usdcReceiver).withdraw();
uint256 amountUSDCLiquidity = IERC20(USDC).balanceOf(address(this)).sub(balanceBefore);
IERC20(USDC).approve(ROUTER, amountUSDCLiquidity);
if (amountToLiquify > 0 && amountUSDCLiquidity > 0) {
router.addLiquidity(
address(this),
USDC,
amountToLiquify,
amountUSDCLiquidity,
0,
0,
autoLiquidityReceiver,
block.timestamp
);
}
_lastAddLiquidityTime = block.timestamp;
}
function swapBack() internal swapping {
uint256 amountToSwap = _gonBalances[address(this)].div(_gonsPerFragment);
if( amountToSwap == 0) {
return;
}
uint256 balanceBefore = IERC20(USDC).balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = USDC;
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
usdcReceiver,
block.timestamp
);
IUSDCReceiver(usdcReceiver).withdraw();
uint256 amountUSDCToTreasuryAndKIF = IERC20(USDC).balanceOf(address(this)).sub(balanceBefore);
IERC20(USDC).transfer(treasuryReceiver, amountUSDCToTreasuryAndKIF.mul(treasuryFee).div(treasuryFee.add(rspctInsuranceFundFee)));
IERC20(USDC).transfer(rspctInsuranceFundReceiver, amountUSDCToTreasuryAndKIF.mul(rspctInsuranceFundFee).div(treasuryFee.add(rspctInsuranceFundFee)));
}
function withdrawAllToTreasury() external swapping onlyOwner {
uint256 amountToSwap = _gonBalances[address(this)].div(_gonsPerFragment);
require( amountToSwap > 0,"There is no respect deposited in token contract");
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = USDC;
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
treasuryReceiver,
block.timestamp
);
}
function shouldTakeFee(address from, address to)
internal
view
returns (bool)
{
return
(pair == from || pair == to) &&
!_isFeeExempt[from];
}
function shouldRebase() internal view returns (bool) {
return
_autoRebase &&
(_totalSupply < MAX_SUPPLY) &&
msg.sender != pair &&
!inSwap &&
block.timestamp >= (_lastRebasedTime + 12 minutes);
}
function shouldAddLiquidity() internal view returns (bool) {
return
_autoAddLiquidity &&
!inSwap &&
msg.sender != pair &&
block.timestamp >= (_lastAddLiquidityTime + 8 hours);
}
function shouldSwapBack() internal view returns (bool) {
return
!inSwap &&
msg.sender != pair ;
}
function setAutoRebase(bool _flag) external onlyOwner {
if (_flag) {
_autoRebase = _flag;
_lastRebasedTime = block.timestamp;
} else {
_autoRebase = _flag;
}
}
function setAutoAddLiquidity(bool _flag) external onlyOwner {
if(_flag) {
_autoAddLiquidity = _flag;
_lastAddLiquidityTime = block.timestamp;
} else {
_autoAddLiquidity = _flag;
}
}
function toggleSwap() public onlyOwner {
swapEnabled = true;
emit SwapEnabled();
}
function allowance(address owner_, address spender)
external
view
override
returns (uint256)
{
return _allowedFragments[owner_][spender];
}
function decreaseAllowance(address spender, uint256 subtractedValue)
external
returns (bool)
{
uint256 oldValue = _allowedFragments[msg.sender][spender];
if (subtractedValue >= oldValue) {
_allowedFragments[msg.sender][spender] = 0;
} else {
_allowedFragments[msg.sender][spender] = oldValue.sub(
subtractedValue
);
}
emit Approval(
msg.sender,
spender,
_allowedFragments[msg.sender][spender]
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
external
returns (bool)
{
_allowedFragments[msg.sender][spender] = _allowedFragments[msg.sender][
spender
].add(addedValue);
emit Approval(
msg.sender,
spender,
_allowedFragments[msg.sender][spender]
);
return true;
}
function approve(address spender, uint256 value)
external
override
returns (bool)
{
_allowedFragments[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function checkFeeExempt(address _addr) external view returns (bool) {
return _isFeeExempt[_addr];
}
function getCirculatingSupply() public view returns (uint256) {
return
(TOTAL_GONS.sub(_gonBalances[DEAD]).sub(_gonBalances[ZERO])).sub(_gonBalances[blackhole]).div(
_gonsPerFragment
);
}
function getCurrentDay() public view returns (uint256) {
return minZero(block.timestamp, startTime).div(TIME_STEP);
}
function getUserHoldLimit() public view returns (uint256) {
return getCirculatingSupply().mul(holdLimit).div(limitDenominator);
}
function getUserSellLimit() public view returns (uint256) {
return getCirculatingSupply().mul(sellLimit).div(limitDenominator);
}
function isNotInSwap() external view returns (bool) {
return !inSwap;
}
function manualSync() external {
IPancakeSwapPair(pair).sync();
}
function setFeeReceivers(
address _autoLiquidityReceiver,
address _treasuryReceiver,
address _rspctInsuranceFundReceiver,
address _blackhole,
address _nftFeeReceiver
) external onlyOwner {
autoLiquidityReceiver = _autoLiquidityReceiver;
treasuryReceiver = _treasuryReceiver;
rspctInsuranceFundReceiver = _rspctInsuranceFundReceiver;
blackhole = _blackhole;
nftFeeReceiver = _nftFeeReceiver;
}
function getLiquidityBacking(uint256 accuracy)
public
view
returns (uint256)
{
uint256 liquidityBalance = _gonBalances[pair].div(_gonsPerFragment);
return
accuracy.mul(liquidityBalance.mul(2)).div(getCirculatingSupply());
}
function setWhitelist(address _addr) external onlyOwner {