|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.20; |
| 3 | + |
| 4 | +import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
| 5 | +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; |
| 6 | + |
| 7 | +contract SecurityToken is ERC20, Ownable { |
| 8 | + // Identity Registry to store KYC/AML status |
| 9 | + mapping(address => bool) public identityRegistry; |
| 10 | + |
| 11 | + // Transfer restriction status |
| 12 | + bool public transfersFrozen; |
| 13 | + |
| 14 | + // Events |
| 15 | + event AddedToIdentityRegistry(address indexed investor); |
| 16 | + event RemovedFromIdentityRegistry(address indexed investor); |
| 17 | + event TransfersFrozen(); |
| 18 | + event TransfersUnfrozen(); |
| 19 | + |
| 20 | + constructor( |
| 21 | + string memory name, |
| 22 | + string memory symbol, |
| 23 | + address initialOwner |
| 24 | + ) ERC20(name, symbol) Ownable(initialOwner) {} |
| 25 | + |
| 26 | + // Modifier to check if an address is verified |
| 27 | + modifier onlyVerified(address _address) { |
| 28 | + require(identityRegistry[_address], "Identity not verified"); |
| 29 | + _; |
| 30 | + } |
| 31 | + |
| 32 | + // Add an investor to the identity registry |
| 33 | + function addToIdentityRegistry(address investor) external onlyOwner { |
| 34 | + identityRegistry[investor] = true; |
| 35 | + emit AddedToIdentityRegistry(investor); |
| 36 | + } |
| 37 | + |
| 38 | + // Remove an investor from the identity registry |
| 39 | + function removeFromIdentityRegistry(address investor) external onlyOwner { |
| 40 | + identityRegistry[investor] = false; |
| 41 | + emit RemovedFromIdentityRegistry(investor); |
| 42 | + } |
| 43 | + |
| 44 | + // Freeze all transfers |
| 45 | + function freezeTransfers() external onlyOwner { |
| 46 | + transfersFrozen = true; |
| 47 | + emit TransfersFrozen(); |
| 48 | + } |
| 49 | + |
| 50 | + // Unfreeze all transfers |
| 51 | + function unfreezeTransfers() external onlyOwner { |
| 52 | + transfersFrozen = false; |
| 53 | + emit TransfersUnfrozen(); |
| 54 | + } |
| 55 | + |
| 56 | + // Mint new tokens (only owner) |
| 57 | + function mint( |
| 58 | + address to, |
| 59 | + uint256 amount |
| 60 | + ) external onlyOwner onlyVerified(to) { |
| 61 | + _mint(to, amount); |
| 62 | + } |
| 63 | + |
| 64 | + // Override transfer function to add compliance checks |
| 65 | + function transfer( |
| 66 | + address to, |
| 67 | + uint256 amount |
| 68 | + ) public override onlyVerified(msg.sender) onlyVerified(to) returns (bool) { |
| 69 | + require(!transfersFrozen, "Transfers are frozen"); |
| 70 | + return super.transfer(to, amount); |
| 71 | + } |
| 72 | + |
| 73 | + // Override transferFrom function to add compliance checks |
| 74 | + function transferFrom( |
| 75 | + address from, |
| 76 | + address to, |
| 77 | + uint256 amount |
| 78 | + ) public override onlyVerified(from) onlyVerified(to) returns (bool) { |
| 79 | + require(!transfersFrozen, "Transfers are frozen"); |
| 80 | + return super.transferFrom(from, to, amount); |
| 81 | + } |
| 82 | +} |
0 commit comments