-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedToken.sol
More file actions
70 lines (60 loc) · 2.26 KB
/
AdvancedToken.sol
File metadata and controls
70 lines (60 loc) · 2.26 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract AdvancedToken is ERC20, Ownable {
uint256 public transferFee; // Fee in % (e.g., 2 = 2%)
address public feeRecipient; // Wallet receiving fees
// Events
event Mint(address indexed to, uint256 amount);
event Burn(address indexed from, uint256 amount);
event TransferFeeUpdated(uint256 newFee);
event FeeRecipientUpdated(address newRecipient);
constructor(
string memory _name,
string memory _symbol,
uint256 _initialSupply,
uint256 _transferFee,
address _feeRecipient
) ERC20(_name, _symbol) Ownable(msg.sender) {
transferFee = _transferFee;
feeRecipient = _feeRecipient;
_mint(msg.sender, _initialSupply * (10 ** decimals()));
}
// ===== Minting (Owner Only) ===== //
function mint(address _to, uint256 _amount) external onlyOwner {
_mint(_to, _amount);
emit Mint(_to, _amount);
}
// ===== Burning (Anyone) ===== //
function burn(uint256 _amount) external {
_burn(msg.sender, _amount);
emit Burn(msg.sender, _amount);
}
// ===== Transfer Fees ===== //
function _update(
address from,
address to,
uint256 amount
) internal override {
if (transferFee == 0 || from == owner() || to == feeRecipient) {
super._update(from, to, amount); // No fee for owner/feeRecipient
} else {
uint256 fee = (amount * transferFee) / 100;
uint256 amountAfterFee = amount - fee;
super._update(from, feeRecipient, fee); // Send fee
super._update(from, to, amountAfterFee); // Send remaining
}
}
// ===== Admin Controls ===== //
function setTransferFee(uint256 _newFee) external onlyOwner {
require(_newFee <= 10, "Fee too high (max 10%)");
transferFee = _newFee;
emit TransferFeeUpdated(_newFee);
}
function setFeeRecipient(address _newRecipient) external onlyOwner {
require(_newRecipient != address(0), "Invalid address");
feeRecipient = _newRecipient;
emit FeeRecipientUpdated(_newRecipient);
}
}