MasterToken, an ERC-20 token built in Solidity with advanced features including minting, burning, off-chain approvals via EIP-712 (permit), supply cap, pausability, and allowance adjustments. This project leverages the Foundry framework for robustness and comprehensive testing.
MasterToken is a customizable ERC-20 token with the following key features:
- Controlled Minting: Only the owner can mint tokens, respecting a maximum supply cap (
maxSupply). - Burning: Users can burn their own tokens or delegate burning via allowance.
- Advanced Allowance: Supports
increaseAllowanceanddecreaseAllowance. - Permit (EIP-712): Enables gasless off-chain approvals.
- Pausability: The owner can pause transfers and other operations in emergencies.
- Security: Includes checks for zero addresses and relies on Solidity 0.8.x overflow/underflow protection.
This project is suitable for learning, experimentation, or as a foundation for production-grade tokens.
master-token/
├── script/
│ └── MasterToken.s.sol # Deployment script
├── src/
│ └── MasterToken.sol # Main contract
├── test/
│ └── MasterToken.t.sol # Unit tests
├── .gitignore # Git ignore file
├── foundry.toml # Foundry configuration
└── README.md # This file
Before getting started, ensure you have:
- Foundry installed (
forgeandcast). - Git to clone the repository.
- Solidity 0.8.19+ (compatible via Foundry).
-
Clone the repository:
git clone https://github.com/your-username/master-token.git cd master-token -
Install Foundry dependencies:
forge install
-
Compile the project:
forge build
- ERC-20 Standard:
transfer,approve,transferFrom,balanceOf,allowance,totalSupply. - Minting:
mintfunction restricted to the owner, capped atmaxSupply(10M tokens). - Burning:
burn(self) andburnFrom(via allowance). - Allowance:
increaseAllowanceanddecreaseAllowancefor incremental adjustments. - Permit: Off-chain approvals using EIP-712 signatures.
- Access Control:
onlyOwnermodifier for administrative functions. - Pausability:
pauseandunpausefunctions for security.
Compile the contract:
forge buildRun the unit tests (29 tests covering all functionalities):
forge test -vvvvThe tests verify:
- Correct initialization (supply, name, symbol, etc.).
- Transfers, approvals, and delegated transfers.
- Minting, burning, and supply cap enforcement.
permitfunctionality with signatures.- Security (expected reverts, pausability).
Use the provided deployment script in script/MasterToken.s.sol:
forge script script/MasterToken.s.sol --rpc-url <YOUR_RPC_URL> --private-key <YOUR_PRIVATE_KEY> --broadcastReplace <YOUR_RPC_URL> and <YOUR_PRIVATE_KEY> with appropriate values (Infura, Alchemy, etc.).
- Start a local network:
anvil
- Deploy:
forge script script/MasterToken.s.sol --fork-url http://localhost:8545 --broadcast
- Solidity Version: 0.8.19
- License: MIT
- Events:
Transfer,Approval,OwnershipTransferred,Paused,Unpaused - Public Variables:
name,symbol,decimals,totalSupply,maxSupply,owner,paused, etc.
- Location:
test/MasterToken.t.sol - Coverage: 100% of public functions and failure scenarios.
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a feature branch:
git checkout -b feature/new-feature
- Commit your changes:
git commit -m "Add new feature" - Push to the remote repository:
git push origin feature/new-feature
- Open a Pull Request.
This project is licensed under the MIT License.
Questions? Feel free to reach out or open an issue!