Successfully migrated InvoiceX from Hardhat to Foundry framework.
-
✅ Installed Foundry
- forge 1.5.0-stable
- cast 1.5.0-stable
- anvil 1.5.0-stable
- chisel 1.5.0-stable
-
✅ Removed Hardhat Configuration
- Deleted
hardhat.config.ts - Removed TypeScript configs for Hardhat
- Cleaned up Hardhat-specific files
- Deleted
-
✅ Initialized Foundry Project
- Created proper directory structure
- Installed OpenZeppelin Contracts v5.0.0
- Set up forge-std for testing
-
✅ Created Foundry Configuration (
foundry.toml)- Solidity 0.8.20
- Shanghai EVM version
- Optimized compiler settings
- Mantle Network RPC endpoints
- Gas reporting configuration
- Multiple build profiles (default, ci, local, production, coverage)
-
✅ Updated Project Structure
invoicex/ ├── src/ │ ├── core/ # Core protocol contracts │ ├── oracle/ # Oracle contracts │ ├── compliance/ # KYB/ZK verification │ ├── defi/ # DeFi components │ └── interfaces/ # Contract interfaces ├── test/ │ ├── unit/ # Unit tests │ ├── integration/ # Integration tests │ └── helpers/ # Test utilities │ └── TestHelper.sol # Base test contract ├── script/ # Deployment scripts │ └── Deploy.s.sol # Main deployment script ├── lib/ # Dependencies │ ├── forge-std/ # Foundry standard library │ └── openzeppelin-contracts/ # OpenZeppelin v5.0.0 └── out/ # Compiled artifacts -
✅ Created Test Infrastructure
TestHelper.sol- Base contract for all tests with:- Common constants (USDT decimals, advance rates, fees)
- Test account setup (admin, sellers, investors, buyers, oracle)
- Helper functions (time manipulation, calculations, hashing)
- Pre-configured test actors with labels
Setup.t.sol- Verification tests proving setup works
-
✅ Updated package.json
- Removed Hardhat dependencies
- Added Foundry-compatible scripts:
forge build- Compile contractsforge test- Run testsforge test --gas-report- Gas reportingforge coverage- Coverage reportsforge fmt- Code formatting- Deployment scripts for Mantle testnet/mainnet
-
✅ Created Deployment Scripts
script/Deploy.s.sol- Template for protocol deployment- Configured for Mantle Network
- Includes verification support
-
✅ Updated Documentation
- New README.md with Foundry instructions
- Installation guide
- Testing commands
- Deployment procedures
All 5 tests passing:
Ran 5 tests for test/Setup.t.sol:SetupTest
[PASS] test_Constants() (gas: 738)
[PASS] test_HelperFunctions() (gas: 1265)
[PASS] test_InvoiceNumberGeneration() (gas: 4465)
[PASS] test_SetupComplete() (gas: 7395)
[PASS] test_TimeHelpers() (gas: 3832)
Suite result: ok. 5 passed; 0 failed; 0 skipped- Faster Compilation - Solidity native compiler
- Better Testing - Tests in Solidity, no context switching
- Gas Optimization - Built-in gas reporting and snapshots
- Fuzz Testing - Native fuzzing support
- Simpler Setup - No Node.js dependencies for contracts
- Better Developer Experience - Fast, reliable, predictable
Ready to start building features! The development workflow is:
-
Build a Feature:
# Write contract in src/ forge build -
Write Tests:
# Write tests in test/ forge test -vvv
-
Check Coverage:
forge coverage
-
Deploy:
forge script script/Deploy.s.sol --rpc-url mantle_testnet --broadcast
| Task | Command |
|---|---|
| Build | forge build |
| Test | forge test -vvv |
| Test (gas report) | forge test --gas-report |
| Coverage | forge coverage |
| Format | forge fmt |
| Clean | forge clean |
| Deploy Testnet | forge script script/Deploy.s.sol --rpc-url mantle_testnet --broadcast --verify |
| Deploy Mainnet | forge script script/Deploy.s.sol --rpc-url mantle --broadcast --verify |
- All contract imports use
@openzeppelin/contracts/prefix - Tests inherit from
TestHelperfor common utilities - Use
vm.cheatcodes for testing (warp, prank, expectRevert, etc.) - Gas snapshots available with
forge snapshot - Fuzz testing with
forge test --fuzz-runs 1000
Migration Completed: December 20, 2025 Status: ✅ Clean Migration - No Bugs Ready for: Feature Development