Overview
The Flash Loan Router consists of three main contracts:- FlashLoanRouter: Main entry point for flash loan settlements
- AaveBorrower: Adapter for Aave flash loans
- ERC3156Borrower: Adapter for ERC-3156 compliant lenders (e.g., Maker)
CREATE2 with the same addresses across all supported networks.
Environment Setup
1
Create environment file
Copy the
.env.example file to .env in the project root:2
Configure environment variables
Edit
.env and set the required variables:3
Load environment variables
Source the environment file before running deployment commands:
Deploy All Contracts
For new network deployments, use theDeployAllContracts script to deploy all three contracts in a single transaction.
1
Dry-run the deployment
Test the deployment without broadcasting transactions:Review the output to ensure expected contract addresses and gas costs.
2
Broadcast deployment
Execute the actual deployment:
3
Deploy with verification
For Etherscan verification, add the
--verify flag:Ensure
ETHERSCAN_API_KEY is set in your .env file for verification to succeed.Deploy Single Contract
To deploy individual contracts on existing networks, use the single-deployment scripts.FlashLoanRouter
AaveBorrower
ERC3156Borrower
Update Deployment Records
After successful deployment, update thenetworks.json file to track contract addresses.
1
Generate networks.json
Run the generation script to update deployment records:This script reads broadcast files from
broadcast/ directory and generates the updated networks.json.2
Manual updates (if needed)
For networks deployed outside of Forge scripts, manually update
broadcast/networks-manual.json before regenerating.3
Verify addresses
Check that
networks.json contains the correct addresses for your deployed contracts:Deployment Architecture
The deployment process uses CREATE2 for deterministic addresses:- FlashLoanRouter is deployed first with the CoW Settlement contract address
- Borrower contracts are deployed with the FlashLoanRouter address as constructor argument
- All deployments use a fixed salt (
Constants.SALT) for address determinism - If a contract already exists at the computed address, deployment is skipped
Troubleshooting
CREATE2 collision error
CREATE2 collision error
This occurs when a contract already exists at the computed CREATE2 address. The deployment scripts automatically detect existing contracts and skip re-deployment.For single deployments requiring the FlashLoanRouter address, set the
FLASHLOAN_ROUTER_ADDRESS environment variable.Verification fails
Verification fails
Common causes:
- Missing or invalid
ETHERSCAN_API_KEY - Network not supported by Etherscan API
- Constructor arguments mismatch
Insufficient funds
Insufficient funds
Ensure the deployer account has sufficient native tokens (ETH, MATIC, etc.) for:
- Contract deployment gas costs
- Multiple contract deployments if using
DeployAllContracts
Next Steps
Contract Verification
Verify deployed contracts on block explorers
Supported Networks
View all deployed contract addresses by network