This repository contains an ERC‑20 token implementation along with deployment and management scripts. The project is built with Foundry and leverages OpenZeppelin contracts for secure and standardized token development.
- ERC‑20 Standard Token: Secure implementation using OpenZeppelin's audited contracts.
- UUPS Upgradeable Pattern:
- Secure contract upgrades using OpenZeppelin's UUPS pattern
- Proxy contract for maintaining contract address
- Access-controlled upgrade mechanism
- Storage-compatible upgrades
- Enhanced Deployment Scripts:
- Automatic network detection (Sepolia/Mainnet/Local)
- Gas cost estimation and balance validation
- Detailed deployment status and progress
- Automatic Etherscan verification instructions
- Smart Transfer Management:
- Pre-transfer balance checks
- Gas cost estimation
- Detailed transaction reporting
- Network-aware error messages
- Environment Management: Uses environment variables for secure handling of sensitive configurations.
- Sepolia Network:
- Token Address (Proxy):
0x844303bcC1a347bE6B409Ae159b4040d84876024
- Token Address (Proxy):
- Foundry installed
- An Ethereum wallet with testnet ETH (for deploying to networks like Sepolia)
-
Clone the repository with submodules:
git clone --recursive https://github.com/theblitlabs/parity-token.git cd parity-token
If you've already cloned the repository without
--recursive
, run:make install
This will initialize and update all required submodules.
-
Install Git Hooks:
make install-hooks
This will install pre-commit hooks for:
- Code formatting checks
- Linting
- Test execution
- Conventional commit message validation
-
Dependencies: The project uses git submodules for dependency management:
forge-std
: Foundry's standard library for testing and scriptingopenzeppelin-contracts
: OpenZeppelin's secure contract library
Dependencies are pinned to specific commits for reproducible builds.
-
Configure Environment Variables:
-
Copy the environment template:
cp .env.example .env
-
Update
.env
with your credentials:# Network RPC URLs SEPOLIA_RPC_URL="your RPC URL" MAINNET_RPC_URL="your mainnet RPC URL" # Optional # Wallet Configuration PRIVATE_KEY="your wallet private key" # with 0x prefix # API Keys ETHERSCAN_API_KEY="your etherscan key" # Optional, for verification # Contract Information (Auto-populated by deployment scripts) TOKEN_ADDRESS= # Will be set automatically after deployment PROXY_ADDRESS= # Will be set automatically after deployment IMPLEMENTATION_ADDRESS= # Will be set automatically after deployment
-
For detailed Foundry usage, visit: https://book.getfoundry.sh/
The project includes a Makefile for common operations. Here are the main commands:
# Install/update dependencies
$ make install
# Build the project
$ make build
# Run tests
$ make test
# Run tests with gas reporting
$ make test-gas
# Format code
$ make format
# Clean build artifacts
$ make clean
# Update dependencies
$ make update
# Start local node
$ make anvil
# Deploy upgradeable contract locally
$ make deploy-upgradeable-local
# Deploy upgradeable contract to Sepolia
$ make deploy-upgradeable-sepolia
# Transfer tokens locally
$ make transfer-local ADDRESS="recipient-address" AMOUNT="amount"
# Transfer tokens on Sepolia
$ make transfer-sepolia ADDRESS="recipient-address" AMOUNT="amount"
The ParityToken contract uses the UUPS (Universal Upgradeable Proxy Standard) pattern for upgrades. This allows the contract logic to be upgraded while maintaining the same address and state.
The initial deployment creates two contracts:
- The implementation contract (
ParityToken
) - The proxy contract that delegates calls to the implementation
# Deploy upgradeable contract locally
$ make deploy-upgradeable-local
# Or deploy to Sepolia
$ make deploy-upgradeable-sepolia
The deployment script will automatically:
- Deploy the implementation contract
- Deploy the proxy contract
- Initialize the contract with initial settings
- Update your
.env
file with:PROXY_ADDRESS
: The address of your proxy contractIMPLEMENTATION_ADDRESS
: The address of the implementationTOKEN_ADDRESS
: Same as proxy address (for convenience)
When you need to upgrade the contract:
-
Create a new version of the contract (e.g.,
ParityTokenV2.sol
) with your changes -
Ensure it maintains storage compatibility with the previous version
-
Deploy the new implementation:
# Deploy locally $ make deploy-upgradeable-local # Or deploy to Sepolia $ make deploy-upgradeable-sepolia
This will automatically update
IMPLEMENTATION_ADDRESS
in your.env
-
Run the upgrade command:
# Upgrade locally $ make upgrade-local # Or upgrade on Sepolia $ make upgrade-sepolia
Note:
- Only the contract owner can perform upgrades
- The upgrade process is atomic - either it succeeds completely or reverts
- All contract state is preserved during upgrades
- The proxy address remains the same, so users don't need to update their token address
- Storage layout must be preserved between versions
The deployment script will:
- Detect the network automatically
- Use environment variables from
.env
for configuration - Estimate gas costs
- Validate wallet balance
- Show detailed deployment progress
- Provide verification instructions
The transfer script will:
- Use configured token address from
.env
- Validate addresses and amounts
- Check token and ETH balances
- Estimate gas costs
- Show detailed transfer status
- Report final balances and transaction cost
Note: For testnet operations:
- Ensure your
.env
file is properly configured - Ensure sufficient ETH for gas (scripts will estimate costs)
- For Sepolia testnet, the scripts will provide faucet links if needed
This project uses Git Submodules for dependency management, ensuring reproducible builds and consistent development environments.
-
After Pulling Changes: Always run after pulling changes that modify submodules:
make install
-
Working with Dependencies:
- Update all:
make update
- View status:
git submodule status
- Update all:
-
Committing Changes:
- Submodule changes need to be committed separately
- Always test after updating dependencies
- Verify builds are reproducible
-
Local Development:
# Start local node make anvil # Deploy locally make deploy-local
-
Testing:
# Run all tests make test # Run with gas reporting make test-gas
-
Code Quality:
# Format code make format # Build and check sizes make build
- Secure Credentials: Never commit your
.env
file or expose private keys - Audited Dependencies: Using OpenZeppelin's audited contracts
- Automated Verification: Etherscan verification in deployment process
- Reproducible Builds: Dependencies pinned via git submodules
- Testing: Write comprehensive tests for all new features
- Gas Optimization: Monitor gas usage with
make test-gas
- Code Style: Use
make format
before committing - Dependencies: Document any new dependencies added
- Automated testing on pull requests
- Security analysis with Slither
- Gas usage monitoring
- Testnet deployment verification
Contributions are welcome! Please open an issue or submit a pull request if you have any enhancements or bug fixes.
This project is licensed under the MIT License.