-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuySellFee.sol
More file actions
114 lines (91 loc) · 3.5 KB
/
BuySellFee.sol
File metadata and controls
114 lines (91 loc) · 3.5 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface IPancakeRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
}
interface IPancakeFactory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
contract PancakeFeeToken is ERC20, Ownable {
IPancakeRouter public pancakeRouter;
address public pancakePair;
uint256 public buyFee = 1; // 1% buy fee
uint256 public sellFee = 5; // 5% sell fee
address public feeWallet;
address public constant PancakeRouterAdd = address(0xD99D1c33F9fC3444f8101754aBC46c52416550D1);
mapping(address => bool) private _isExcludedFromFees;
event UpdatePancakeRouter(address indexed newAddress, address indexed oldAddress);
event ExcludeFromFees(address indexed account, bool isExcluded);
event SetFees(uint256 buyFee, uint256 sellFee);
event SetFeeWallet(address indexed newWallet);
constructor(
string memory name,
string memory symbol,
uint256 totalSupply,
address wallet
) ERC20(name, symbol) Ownable(msg.sender) {
feeWallet = wallet;
// Initialize PancakeSwap Router
IPancakeRouter _pancakeRouter = IPancakeRouter(PancakeRouterAdd);
pancakeRouter = _pancakeRouter;
// Create PancakeSwap pair
pancakePair = IPancakeFactory(_pancakeRouter.factory())
.createPair(address(this), _pancakeRouter.WETH());
// Exclude from fees
_isExcludedFromFees[owner()] = true;
_isExcludedFromFees[wallet] = true;
_isExcludedFromFees[address(this)] = true;
_mint(msg.sender, totalSupply * (10 ** decimals()));
}
function excludeFromFees(address account, bool excluded) external onlyOwner {
_isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
function setFees(uint256 _buyFee, uint256 _sellFee) external onlyOwner {
require(_buyFee <= 10 && _sellFee <= 10, "Fees cannot be more than 10%");
buyFee = _buyFee;
sellFee = _sellFee;
emit SetFees(_buyFee, _sellFee);
}
function setFeeWallet(address _wallet) external onlyOwner {
require(_wallet != address(0), "Cannot be zero address");
feeWallet = _wallet;
emit SetFeeWallet(_wallet);
}
function _update(
address from,
address to,
uint256 amount
) internal override {
if (amount == 0) {
super._update(from, to, 0);
return;
}
bool takeFee = true;
// Skip fees for excluded accounts
if (_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
takeFee = false;
}
// Only take fees on buys/sells, do not take on wallet transfers
if (takeFee) {
uint256 fees = 0;
// Buy fees
if (from == pancakePair) {
fees = (amount * buyFee) / 100;
}
// Sell fees
else if (to == pancakePair) {
fees = (amount * sellFee) / 100;
}
if (fees > 0) {
super._update(from, feeWallet, fees);
amount = amount - fees;
}
}
super._update(from, to, amount);
}
receive() external payable {}
}