Skip to main content

Overview

Borrower adapters serve as intermediaries between the Flash-Loan Router and flash loan providers. Each adapter implements a standardized interface while handling provider-specific loan request and callback logic.

Adapter Architecture

The adapter system uses an abstract base contract that provides common functionality:

Key Components

  • Router Reference: Immutable reference to the Flash-Loan Router that coordinates execution
  • Settlement Reference: Direct reference to CoW Settlement contract for authorization
  • Standard Interface: Common IBorrower interface for router interaction
  • Access Control: Modifiers ensuring only authorized callers

Core Functions

Router Interaction

Parameters:
  • lender: The flash loan provider contract address
  • token: The ERC-20 token to borrow
  • amount: The amount of tokens to request
  • callBackData: Data to pass back to the router unchanged

Fund Management

Only the settlement contract can set approvals, preventing unauthorized access to borrowed funds.

Implementing an Adapter

To support a new flash loan provider:
  1. Inherit the abstract Borrower contract
  2. Implement triggerFlashLoan for provider-specific requests
  3. Implement the provider’s callback interface
  4. Forward callbacks to flashLoanCallBack

Required Implementation

Example: Aave Adapter

Key Points:
  • Inherit both Borrower and provider interface
  • Implement triggerFlashLoan with provider-specific logic
  • Implement provider’s callback and forward to base
Parameter Mapping:
  • assets: Single-element array with token address
  • amounts: Single-element array with loan amount
  • interestRateModes: Set to [0] to avoid opening debt positions
  • params: Pass through callBackData unchanged
  • referralCode: Set to 0 (currently inactive)

Example: ERC-3156 Adapter

Key Points:
  • Simpler than Aave due to standardized interface
  • Must return specific success constant

Access Control

Router-Only Access

Only the registered router can trigger flash loans through the adapter.

Settlement-Only Access

Only the settlement contract can approve token transfers from the adapter. Security Assurances:
  • Only the router can initiate loans
  • Only settlements can access borrowed funds
  • External callers cannot disrupt execution flow

Fund Flow

Adding New Providers

Steps to follow:
  1. Research Provider API: Understand the provider’s flash loan request and callback mechanisms
  2. Create Adapter Contract:
  1. Implement triggerFlashLoan: Map standard parameters to provider-specific request format
  2. Implement Provider Callback: Forward the provider’s callback to flashLoanCallBack(callBackData)
  3. Deploy and Test: Deploy the adapter and test with the router on testnets
  4. Update Documentation: Document the new provider and its adapter address

Best Practices

Always Pass Data Unchanged

The callBackData parameter must be passed to the router exactly as received:

Handle Provider-Specific Requirements

Each provider has unique requirements:
  • Aave requires arrays and specific return values
  • ERC-3156 requires returning a success constant
  • Some providers may charge fees

Validate Provider Responses

Check for success conditions specific to the provider:

Use Immutable References

Router and settlement references should be immutable for security:

Next Steps

Flash Loans

Learn about flash loan fundamentals

Security Model

Understand security guarantees
Last modified on March 4, 2026