Skip to main content
This guide covers deploying the Flash Loan Router contracts to blockchain networks using Forge deployment scripts.

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)
All contracts are deployed deterministically using 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:
cp .env.example .env
2

Configure environment variables

Edit .env and set the required variables:
# Network configuration
CHAIN_ID=1  # Target network chain ID
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
PRIVATE_KEY=0x...  # Deployer private key

# Optional: For contract verification
ETHERSCAN_API_KEY=your_etherscan_api_key

# Optional: For single contract deployments
# FLASHLOAN_ROUTER_ADDRESS=0x9da8B48441583a2b93e2eF8213aAD0EC0b392C69
3

Load environment variables

Source the environment file before running deployment commands:
source .env

Deploy All Contracts

For new network deployments, use the DeployAllContracts script to deploy all three contracts in a single transaction.
1

Dry-run the deployment

Test the deployment without broadcasting transactions:
forge script script/DeployAllContracts.s.sol:DeployAllContracts \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY
Review the output to ensure expected contract addresses and gas costs.
2

Broadcast deployment

Execute the actual deployment:
forge script script/DeployAllContracts.s.sol:DeployAllContracts \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast
3

Deploy with verification

For Etherscan verification, add the --verify flag:
forge script script/DeployAllContracts.s.sol:DeployAllContracts \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify
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

forge script script/single-deployment/DeployFlashLoanRouter.s.sol:DeployFlashLoanRouter \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast

AaveBorrower

forge script script/single-deployment/DeployAAVEBorrower.s.sol:DeployAAVEBorrower \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast

ERC3156Borrower

forge script script/single-deployment/DeployERC3156Borrower.s.sol:DeployERC3156Borrower \
  --rpc-url $ETH_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast

Update Deployment Records

After successful deployment, update the networks.json file to track contract addresses.
1

Generate networks.json

Run the generation script to update deployment records:
bash script/generate-networks-file.sh > networks.json
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:
{
  "FlashLoanRouter": {
    "1": {
      "address": "0x9da8b48441583a2b93e2ef8213aad0ec0b392c69",
      "transactionHash": "0x..."
    }
  },
  "AaveBorrower": { ... },
  "ERC3156Borrower": { ... }
}

Deployment Architecture

The deployment process uses CREATE2 for deterministic addresses:
  1. FlashLoanRouter is deployed first with the CoW Settlement contract address
  2. Borrower contracts are deployed with the FlashLoanRouter address as constructor argument
  3. All deployments use a fixed salt (Constants.SALT) for address determinism
  4. If a contract already exists at the computed address, deployment is skipped

Troubleshooting

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.
Common causes:
  • Missing or invalid ETHERSCAN_API_KEY
  • Network not supported by Etherscan API
  • Constructor arguments mismatch
See the Contract Verification guide for manual verification steps.
Ensure the deployer account has sufficient native tokens (ETH, MATIC, etc.) for:
  • Contract deployment gas costs
  • Multiple contract deployments if using DeployAllContracts

Next Steps

Last modified on March 4, 2026