Want to be able to have 1% fees going to my wallet and 1% burned every trade. Also saw someone implement a 0 fees before presale ends how can I implement that in my code? Please review and tell if this contract can work please also suggest improvements. Thanks! Also is there any automated way to do the testing?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol";
contract testcoin is ERC20Burnable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
address TxFees = msg.sender;
constructor(uint256 initialSupply) ERC20 ("testcoin", "tt"){
_mint(msg.sender, initialSupply);
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) internal virtual override {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
uint256 amountToBurn = amount / 100;
amount -= amountToBurn;
_totalSupply -= amountToBurn;
_balances[to] += amount;
uint256 amountToTxFees = amount / 100;
amount -= amountToTxFees;
_balances[TxFees] += amountToTxFees;
_balances[to] += amount;
}
}