// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/[email protected]/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";
import "@openzeppelin/[email protected]/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";
import "@openzeppelin/[email protected]/token/ERC20/extensions/ERC20Permit.sol";
contract tst1 is ERC20, ERC20Burnable, ERC20Pausable, Ownable, ERC20Permit {
uint256 public BuyTax = 5;
uint256 public SellTax = 5;
uint256 public BurnRate = 0;
address public TaxWallet = 0x8635AeF7D60A718DB38186A9c610eE60efBA7959;
address constant BurnAddress = address (0x000000000000000000000000000000000000dEaD);
mapping (address => bool) private _isExcludedFromTax;
mapping (address => bool) private _isDexPair;
address[] public arrayOfAddresses = [0x8635AeF7D60A718DB38186A9c610eE60efBA7959];
event BuyTaxUpdated(uint256 newBuyTax);
event SellTaxUpdated(uint256 newSellTax);
event TaxWalletUpdated(address newTaxWallet);
event BurnRateUpdated(uint256 newBurnTax);
constructor(address initialOwner)
ERC20("tst1", "tst")
Ownable(initialOwner)
ERC20Permit("tst1")
{
_mint(msg.sender, 1100000000 * 10 ** decimals());
// #
for (uint i = 0; i < arrayOfAddresses.length; i++) {
_isExcludedFromTax[arrayOfAddresses[i]] = true;
}
_isExcludedFromTax[initialOwner] = true;
_isExcludedFromTax[address(this)] = true;
_isExcludedFromTax[TaxWallet] = true;
transferOwnership(initialOwner);
}
function setDexPair(address account, bool isPair)
external onlyOwner {
_isDexPair[account] = isPair;
}
// #
function isDexPair(address account) public view returns (bool) {
return _isDexPair[account];
}
function updateBuyTax(uint256 newBuyTax)
external onlyOwner {
require(newBuyTax <= 10, "Buy Tax must be less than or equal to 10%");
BuyTax = newBuyTax;
emit BuyTaxUpdated(newBuyTax);
}
function updateSellTax(uint256 newSellTax)
external onlyOwner {
require(newSellTax <= 10, "Sell Tax must be less than or equal to 10%");
SellTax = newSellTax;
emit SellTaxUpdated(newSellTax);
}
function updateTaxWallet(address newTaxWallet)
external onlyOwner {
require(newTaxWallet != address (0));
TaxWallet = newTaxWallet;
emit TaxWalletUpdated(newTaxWallet);
}
function updateBurnRate(uint256 newBurnRate)
external onlyOwner {
require(newBurnRate <= 10, "Burn tax must be less than or equal to 10%");
BurnRate = newBurnRate;
emit BurnRateUpdated(newBurnRate);
}
function excludedFromTax(address account, bool excluded)
external onlyOwner {
_isExcludedFromTax[account] = excluded;
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function _update(address from, address to, uint256 value)
internal
override(ERC20, ERC20Pausable) {
super._update(from, to, value);
}
function transfer(address recipient, uint256 amount) public virtual override returns(bool) {
_executeTransfer(_msgSender(), recipient, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_executeTransfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance(sender, _msgSender()) - amount);
return true;
}
function _executeTransfer(address from, address to, uint256 amount) internal {
uint256 fee = 0;
uint256 burnAmount = 0;
// #
if (!_isExcludedFromTax[from] && !_isExcludedFromTax[to]) {
if (isDexPair(from)) {
fee = (amount * BuyTax) / 100;
} else if (isDexPair(to)) {
fee = (amount * SellTax) / 100;
}
burnAmount = (amount * BurnRate) / 100;
}
uint256 amountAfterFee = amount - fee - burnAmount;
if (fee > 0) {
super._transfer(from, TaxWallet, fee);
}
if (burnAmount > 0) {
super._transfer(from, BurnAddress, burnAmount);
}
super._transfer(from, to, amountAfterFee);
}
}