Untitled
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract TESTER is ERC20, Ownable { uint256 private constant _initialSupply = 100000 * 10**18; mapping(address => bool) private _whitelist; mapping(address => bool) private _blacklist; mapping(address => uint256) private _lastTransactionTime; bool public presaleActive = true; uint256 private constant MIN_TRANSACTION_INTERVAL = 15 seconds; event WhitelistAdded(address indexed account); event WhitelistRemoved(address indexed account); event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event PresaleEnded(); constructor() ERC20("TESTER", "TST") Ownable(msg.sender) { _mint(msg.sender, _initialSupply); } modifier onlyWhitelisted() { require(_whitelist[msg.sender], "Not whitelisted"); _; } modifier notBlacklisted(address account) { require(!_blacklist[account], "Blacklisted"); _; } function addToWhitelist(address account) external onlyOwner { _whitelist[account] = true; emit WhitelistAdded(account); } function removeFromWhitelist(address account) external onlyOwner { _whitelist[account] = false; emit WhitelistRemoved(account); } function addToBlacklist(address account) external onlyOwner { _blacklist[account] = true; emit BlacklistAdded(account); } function removeFromBlacklist(address account) external onlyOwner { _blacklist[account] = false; emit BlacklistRemoved(account); } function endPresale() external onlyOwner { presaleActive = false; emit PresaleEnded(); } function transfer(address recipient, uint256 amount) public virtual override notBlacklisted(msg.sender) notBlacklisted(recipient) returns (bool) { require(block.timestamp >= _lastTransactionTime[msg.sender] + MIN_TRANSACTION_INTERVAL, "Anti-bot: Too soon since last transaction"); require(block.timestamp >= _lastTransactionTime[recipient] + MIN_TRANSACTION_INTERVAL, "Anti-bot: Too soon since last transaction"); _lastTransactionTime[msg.sender] = block.timestamp; _lastTransactionTime[recipient] = block.timestamp; if (presaleActive) { require(msg.sender == owner() || _whitelist[recipient], "Presale: Only whitelisted accounts can buy during presale"); } return super.transfer(recipient, amount); } function transferFrom(address sender, address recipient, uint256 amount) public virtual override notBlacklisted(sender) notBlacklisted(recipient) returns (bool) { require(block.timestamp >= _lastTransactionTime[sender] + MIN_TRANSACTION_INTERVAL, "Anti-bot: Too soon since last transaction"); require(block.timestamp >= _lastTransactionTime[recipient] + MIN_TRANSACTION_INTERVAL, "Anti-bot: Too soon since last transaction"); _lastTransactionTime[sender] = block.timestamp; _lastTransactionTime[recipient] = block.timestamp; if (presaleActive) { require(sender == owner() || _whitelist[recipient], "Presale: Only whitelisted accounts can buy during presale"); } return super.transferFrom(sender, recipient, amount); } }
Leave a Comment