-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSantaDoge.sol
922 lines (789 loc) · 30 KB
/
SantaDoge.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
/**
*Submitted for verification at BscScan.com on 2024-12-05
*/
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
}
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
);
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IUniswapV2Factory {
event PairCreated(
address indexed token0,
address indexed token1,
address pair,
uint256
);
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(uint256) external view returns (address pair);
function allPairsLength() external view returns (uint256);
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Pair {
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event Transfer(address indexed from, address indexed to, uint256 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 (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(
address owner,
address spender
) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 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 (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Burn(
address indexed sender,
uint256 amount0,
uint256 amount1,
address indexed to
);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
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 (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function burn(
address to
) external returns (uint256 amount0, uint256 amount1);
function swap(
uint256 amount0Out,
uint256 amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(
uint256 amountOut,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function quote(
uint256 amountA,
uint256 reserveA,
uint256 reserveB
) external pure returns (uint256 amountB);
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountOut);
function getAmountIn(
uint256 amountOut,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountIn);
function getAmountsOut(
uint256 amountIn,
address[] calldata path
) external view returns (uint256[] memory amounts);
function getAmountsIn(
uint256 amountOut,
address[] calldata path
) external view returns (uint256[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
contract SantaDoge is Context, IERC20, Ownable,ReentrancyGuard {
//Mapping section for better tracking.
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isPresaleNoFee;
//Loging and Event Information for better troubleshooting.
event ExcludeStatus(address, bool);
event UpdateMarketingWallet(address);
event UpdateTokensToSwap(uint256);
event UpdateBuyFee(uint256);
event UpdateSellFee(uint256);
event UpdateTransferFee(uint256);
event TransferStatus(bool);
event RecoveredETH(uint256);
event RecoveredTokens(uint256);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapTokensForETH(uint256 amountIn, address[] path);
event AuditLog(string, address);
string public constant name = "Santa Doge";
string public constant symbol = "SDOGE";
uint8 public constant decimals = 18;
//Supply Definition.
//change _tTotal = to the customer supply.
uint256 private _tTotal = 1_000_000_000 ether;
//Marketing Wallet Definition, Change wallet to Customer Marketing Wallet.
address payable public marketingWallet =
payable(0xE0C867432E45FAbaA202CcC6E1bfBd5123A65fBC);
//Taxes Definition.
//Change buyFee to the desired buy Tax.
//Change transferFee to the desired transfer Tax.
//Change sellFee to the desired sell Tax.
uint public buyFee = 5;
uint256 public transferFee = 0;
uint256 public sellFee = 5;
//leave as default and dont modify it.
uint256 public marketingTokensCollected = 0;
//Trading Controls added for SAFU Requirements
bool public tradingEnabled;
uint256 public minimumTokensBeforeSwap = 10_000 ether;
//Router and Pair Configuration.
IUniswapV2Router02 public immutable uniswapV2Router;
address public immutable uniswapV2Pair;
address private immutable WETH;
//Tracking of Automatic Swap vs Manual Swap.
bool public inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
modifier lockTheSwap() {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor() {
_tOwned[_msgSender()] = _tTotal;
address currentRouter;
//Adding Variables for all the routers for easier deployment for our customers.
if (block.chainid == 56) {
currentRouter = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS Router
_isPresaleNoFee[
0x407993575c91ce7643a4d4cCACc9A98c36eE1BBE
] = true; //PinkSale Lock
} else if (block.chainid == 97) {
currentRouter = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1; // PCS Testnet
_isPresaleNoFee[
0x5E5b9bE5fd939c578ABE5800a90C566eeEbA44a5
] = true; //PinkSale Lock
} else if (block.chainid == 43114) {
currentRouter = 0x60aE616a2155Ee3d9A68541Ba4544862310933d4; //Avax Mainnet
} else if (block.chainid == 137) {
currentRouter = 0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff; //Polygon Ropsten
} else if (block.chainid == 6066) {
currentRouter = 0x4169Db906fcBFB8b12DbD20d98850Aee05B7D889; //Tres Chain
} else if (block.chainid == 250) {
currentRouter = 0xF491e7B69E4244ad4002BC14e878a34207E38c29; //SpookySwap FTM
} else if (block.chainid == 42161) {
currentRouter = 0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506; //Arbitrum Sushi
_isPresaleNoFee[
0xeBb415084Ce323338CFD3174162964CC23753dFD
] = true; //PinkSale Lock
} else if (block.chainid == 1 || block.chainid == 5) {
currentRouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; //Mainnet
_isPresaleNoFee[
0x71B5759d73262FBb223956913ecF4ecC51057641
] = true; //PinkSale Lock
} else {
revert("Not the correct route.");
}
//End of Router Variables.
//Create Pair in the contructor, this may fail on some blockchains and can be done in a separate line if needed.
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(currentRouter);
WETH = _uniswapV2Router.WETH();
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), WETH);
uniswapV2Router = _uniswapV2Router;
//Approve router to be used.
_approve(msg.sender, address(uniswapV2Router), type(uint256).max);
_approve(address(this), address(uniswapV2Router), type(uint256).max);
//Exclude from Fees
_isPresaleNoFee[owner()] = true;
_isPresaleNoFee[address(this)] = true;
_isPresaleNoFee[address(uniswapV2Router)] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
//Readable Functions.
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _tOwned[account];
}
//ERC 20 Standard Transfer Functions
function transfer(
address recipient,
uint256 amount
) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
//ERC 20 Standard Allowance Function
function allowance(
address _owner,
address spender
) public view override returns (uint256) {
return _allowances[_owner][spender];
}
//ERC 20 Standard Approve Function
function approve(
address spender,
uint256 amount
) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
//ERC 20 Standard Transfer From
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
uint currentAllowance = _allowances[sender][_msgSender()];
require(
currentAllowance >= amount,
"ERC20: transfer amount exceeds allowance"
);
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
//ERC 20 Standard increase Allowance
function increaseAllowance(
address spender,
uint256 addedValue
) public virtual returns (bool) {
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] + addedValue
);
return true;
}
//ERC 20 Standard decrease Allowance
function decreaseAllowance(
address spender,
uint256 subtractedValue
) public virtual returns (bool) {
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] - subtractedValue
);
return true;
}
//Approve Function
function _approve(address _owner, address spender, uint256 amount) private {
require(_owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[_owner][spender] = amount;
emit Approval(_owner, spender, amount);
}
//Transfer function, validate correct wallet structure, take fees, and other custom taxes are done during the transfer.
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(_tOwned[from] >= amount,"ERC20: transfer amount exceeds balance");
//Enable Trade after sale is finilized
require(tradingEnabled || _isPresaleNoFee[from] || _isPresaleNoFee[to], "Trading not yet enabled!");
//Adding logic for automatic swap.
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >=
minimumTokensBeforeSwap;
uint fee = 0;
bool fromLP = from == uniswapV2Pair;
bool toLP = to == uniswapV2Pair;
//if any account belongs to _isPresaleNoFee account then remove the fee
if (
!inSwapAndLiquify &&
!fromLP &&
overMinimumTokenBalance &&
swapAndLiquifyEnabled
) {
swapAndLiquify();
}
// This saves a bit of gas on transfers
bool NOTfromExcluded = !_isPresaleNoFee[from];
bool NOTtoExcluded = !_isPresaleNoFee[to];
// Apply tax when necessary
if (toLP && NOTfromExcluded) {
fee = (sellFee * amount) / 100;
} else if (fromLP && NOTtoExcluded) {
fee = (buyFee * amount) / 100;
} else if (NOTtoExcluded && NOTfromExcluded) {
fee = (transferFee * amount) / 100;
}
amount -= fee;
if (fee > 0) {
_tokenTransfer(from, address(this), fee);
marketingTokensCollected += fee;
}
_tokenTransfer(from, to, amount);
}
//Swap Tokens for BNB or to add liquidity either automatically or manual, due to SAFU this was changed to Automatic after enable trading.
//Corrected newBalance bug, it sending bnb to wallet and any remaining is on contract and can be recoverred.
function swapAndLiquify() public lockTheSwap {
uint256 totalTokens = balanceOf(address(this));
swapTokensForEth(totalTokens);
uint ethBalance = address(this).balance;
transferToAddressETH(marketingWallet, ethBalance);
marketingTokensCollected = 0;
}
//swap for eth is to support the converstion of tokens to weth during swapandliquify this is a supporting function
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WETH;
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this), // The contract
block.timestamp
);
emit SwapTokensForETH(tokenAmount, path);
}
//ERC 20 standard transfer, only added if taking fees to countup the amount of fees for better tracking and split purpose.
function _tokenTransfer(
address sender,
address recipient,
uint256 amount
) private {
_tOwned[sender] -= amount;
_tOwned[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
//View the wallets that are excluded from view.
function isPresaleNoFee(address account) external view returns (bool) {
return _isPresaleNoFee[account];
}
//exclude wallets from fees, this is needed for launch or other contracts.
function setPresaleAddress(address account) external onlyOwner {
require(
_isPresaleNoFee[account] != true,
"The wallet is already excluded!"
);
_isPresaleNoFee[account] = true;
emit ExcludeStatus(account, true);
}
//include wallet back in fees.
function includeInFee(address account) external onlyOwner {
require(
_isPresaleNoFee[account] != false,
"The wallet is already included!"
);
_isPresaleNoFee[account] = false;
emit ExcludeStatus(account, false);
}
//Automatic Swap Configuration.
function setTokensToSwap(
uint256 _minimumTokensBeforeSwap
) external onlyOwner {
require(
_minimumTokensBeforeSwap >= 100 ether,
"You need to enter more than 100 tokens."
);
minimumTokensBeforeSwap = _minimumTokensBeforeSwap;
emit UpdateTokensToSwap(_minimumTokensBeforeSwap);
}
function setSwapAndLiquifyEnabled(bool _enabled) external onlyOwner {
require(swapAndLiquifyEnabled != _enabled, "Value already set");
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
//set a new marketing wallet.
function setMarketingWallet(address _marketingWallet) external onlyOwner {
require(_marketingWallet != address(0), "setmarketingWallet: ZERO");
marketingWallet = payable(_marketingWallet);
emit UpdateMarketingWallet(marketingWallet);
}
//This function allow to configure the transfer tax.
function setZeroFee() external onlyOwner {
require(sellFee != 0, "Sell Fee is already 0%");
require(buyFee != 0, "Buy Fee is alreazy 0%");
sellFee = 0;
buyFee = 0;
emit UpdateBuyFee(buyFee);
emit UpdateSellFee(sellFee);
}
function transferToAddressETH(
address payable recipient,
uint256 amount
) private {
if (amount == 0) return;
(bool succ, ) = recipient.call{value: amount}("");
emit TransferStatus(succ);
}
//to recieve ETH from uniswapV2Router when swaping
receive() external payable {}
// Withdraw ETH that's potentially stuck in the Contract
function recoverETHfromContract() external nonReentrant {
uint ethBalance = address(this).balance;
(bool succ, ) = payable(marketingWallet).call{value: ethBalance}("");
emit TransferStatus(succ);
emit RecoveredETH(ethBalance);
}
// Withdraw ERC20 tokens that are potentially stuck in Contract
function recoverTokensFromContract(
address _tokenAddress,
uint256 _amount
) external nonReentrant {
require(
_tokenAddress != address(this),
"Owner can't claim contract's balance of its own tokens"
);
bool succ = IERC20(_tokenAddress).transfer(marketingWallet, _amount);
emit TransferStatus(succ);
emit RecoveredTokens(_amount);
}
//Trading Controls for SAFU Contract
function enableTrading() external onlyOwner{
require(!tradingEnabled, "Trading already enabled.");
tradingEnabled = true;
swapAndLiquifyEnabled = true;
emit AuditLog("We have Enable Trading and Automatic Swaps:", msg.sender);
}
}