-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenContract.sol
99 lines (78 loc) · 3.21 KB
/
TokenContract.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
// SPDX-License-Identifier: UNLICENSE
pragma solidity ^0.8.0;
contract MyToken {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => bool) public excludedFromFees;
address public DexWallet;
address public developmentWallet;
address public marketingWallet;
uint256 public feePercentage = 7;
event Transfer(address indexed from, address indexed to, uint256 value);
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals,
uint256 _initialSupply
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply * 10**uint256(decimals);
balanceOf[msg.sender] = totalSupply;
}
modifier onlyOwner() {
require(msg.sender == DexWallet, "Only the DexWallet can call this function.");
_;
}
function setDevelopmentWallet(address _developmentWallet) external onlyOwner {
developmentWallet = _developmentWallet;
}
function setMarketingWallet(address _marketingWallet) external onlyOwner {
marketingWallet = _marketingWallet;
}
function setDexWallet(address _DexWallet) external onlyOwner {
DexWallet = _DexWallet;
}
function excludeFromFees(address _address) external onlyOwner {
excludedFromFees[_address] = true;
}
function includeInFees(address _address) external onlyOwner {
excludedFromFees[_address] = false;
}
function transfer(address _to, uint256 _value) external returns (bool) {
require(_to != address(0), "Invalid recipient address.");
require(_value <= balanceOf[msg.sender], "Insufficient balance.");
if (DexWallet == msg.sender || DexWallet == _to) {
if (excludedFromFees[msg.sender] || excludedFromFees[_to]) {
// Normal transfer without fee
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
} else {
// Deduct fee and distribute
uint256 feeAmount = (_value * feePercentage) / 100;
uint256 transferAmount = _value - feeAmount;
require(
transferAmount > 0 && balanceOf[developmentWallet] + balanceOf[marketingWallet] + transferAmount == _value,
"Fee distribution error."
);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += transferAmount;
balanceOf[developmentWallet] += feeAmount / 2;
balanceOf[marketingWallet] += feeAmount / 2;
emit Transfer(msg.sender, _to, transferAmount);
emit Transfer(msg.sender, developmentWallet, feeAmount / 2);
emit Transfer(msg.sender, marketingWallet, feeAmount / 2);
}
} else {
// Normal transfer without fees
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
}
emit Transfer(msg.sender, _to, _value);
return true;
}
}