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
Deploy All Contracts
For new network deployments, use theDeployAllContracts script to deploy all three contracts in a single transaction.
Dry-run the deployment
Test the deployment without broadcasting transactions:Review the output to ensure expected contract addresses and gas costs.
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.
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.Manual updates (if needed)
For networks deployed outside of Forge scripts, manually update
broadcast/networks-manual.json before regenerating.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