|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.20; |
| 3 | + |
| 4 | +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
| 5 | +import "@openzeppelin/contracts/access/Ownable.sol"; |
| 6 | +import "@openzeppelin/contracts/utils/Pausable.sol"; |
| 7 | + |
| 8 | +/** |
| 9 | + * @title XSGD Token |
| 10 | + * @author @dannweeeee |
| 11 | + * @dev Implementation of the XSGD Token |
| 12 | + */ |
| 13 | +contract XSGD is ERC20, Ownable, Pausable { |
| 14 | + // Mapping to track if an address is blacklisted |
| 15 | + mapping(address => bool) private _blacklisted; |
| 16 | + |
| 17 | + // Events |
| 18 | + event TokensMinted(address indexed to, uint256 amount); |
| 19 | + event TokensBurned(address indexed from, uint256 amount); |
| 20 | + event AddressBlacklisted(address indexed account); |
| 21 | + event AddressUnblacklisted(address indexed account); |
| 22 | + |
| 23 | + constructor(string memory name, string memory symbol, uint256 initialSupply) |
| 24 | + ERC20(name, symbol) |
| 25 | + Ownable(msg.sender) |
| 26 | + { |
| 27 | + _mint(msg.sender, initialSupply); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @dev Pause token transfers |
| 32 | + */ |
| 33 | + function pause() public onlyOwner { |
| 34 | + _pause(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @dev Unpause token transfers |
| 39 | + */ |
| 40 | + function unpause() public onlyOwner { |
| 41 | + _unpause(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @dev Mint new tokens |
| 46 | + * @param to Address to receive the minted tokens |
| 47 | + * @param amount Amount of tokens to mint |
| 48 | + */ |
| 49 | + function mint(address to, uint256 amount) public onlyOwner { |
| 50 | + require(to != address(0), "Cannot mint to zero address"); |
| 51 | + require(!_blacklisted[to], "Recipient is blacklisted"); |
| 52 | + _mint(to, amount); |
| 53 | + emit TokensMinted(to, amount); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @dev Burn tokens from the caller's balance |
| 58 | + * @param amount Amount of tokens to burn |
| 59 | + */ |
| 60 | + function burn(uint256 amount) public { |
| 61 | + require(!_blacklisted[msg.sender], "Sender is blacklisted"); |
| 62 | + _burn(msg.sender, amount); |
| 63 | + emit TokensBurned(msg.sender, amount); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @dev Burn tokens from a specific address |
| 68 | + * @param account Address to burn tokens from |
| 69 | + * @param amount Amount of tokens to burn |
| 70 | + */ |
| 71 | + function burnFrom(address account, uint256 amount) public onlyOwner { |
| 72 | + require(!_blacklisted[account], "Account is blacklisted"); |
| 73 | + _burn(account, amount); |
| 74 | + emit TokensBurned(account, amount); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @dev Blacklist an address |
| 79 | + * @param account Address to blacklist |
| 80 | + */ |
| 81 | + function blacklist(address account) public onlyOwner { |
| 82 | + require(account != address(0), "Cannot blacklist zero address"); |
| 83 | + _blacklisted[account] = true; |
| 84 | + emit AddressBlacklisted(account); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @dev Remove an address from blacklist |
| 89 | + * @param account Address to unblacklist |
| 90 | + */ |
| 91 | + function unblacklist(address account) public onlyOwner { |
| 92 | + _blacklisted[account] = false; |
| 93 | + emit AddressUnblacklisted(account); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @dev Check if an address is blacklisted |
| 98 | + * @param account Address to check |
| 99 | + * @return bool True if the address is blacklisted |
| 100 | + */ |
| 101 | + function isBlacklisted(address account) public view returns (bool) { |
| 102 | + return _blacklisted[account]; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @dev Override transfer function to include blacklist check |
| 107 | + */ |
| 108 | + function transfer(address to, uint256 amount) public virtual override whenNotPaused returns (bool) { |
| 109 | + require(!_blacklisted[msg.sender], "Sender is blacklisted"); |
| 110 | + require(!_blacklisted[to], "Recipient is blacklisted"); |
| 111 | + return super.transfer(to, amount); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @dev Override transferFrom function to include blacklist check |
| 116 | + */ |
| 117 | + function transferFrom(address from, address to, uint256 amount) |
| 118 | + public |
| 119 | + virtual |
| 120 | + override |
| 121 | + whenNotPaused |
| 122 | + returns (bool) |
| 123 | + { |
| 124 | + require(!_blacklisted[from], "Sender is blacklisted"); |
| 125 | + require(!_blacklisted[to], "Recipient is blacklisted"); |
| 126 | + return super.transferFrom(from, to, amount); |
| 127 | + } |
| 128 | +} |
0 commit comments