Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cowprotocol/flash-loan-router/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Borrower adapters are the bridge 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:src/mixin/Borrower.sol
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 interactionAccess Control
Modifiers ensuring only authorized callers
Core Functions
Router Interaction
The router calls adapters through the standard interface:src/mixin/Borrower.sol
The flash loan provider contract address
The ERC-20 token to borrow
The amount of tokens to request
Data to pass back to the router unchanged
Fund Management
Settlements can approve token transfers from borrowers:src/mixin/Borrower.sol
Security: Only the settlement contract can set approvals. This prevents unauthorized access to borrowed funds.
Implementing an Adapter
To support a new flash loan provider, create a concrete adapter by:- Inheriting the abstract
Borrowercontract - Implementing
triggerFlashLoanfor provider-specific requests - Implementing the provider’s callback interface
- Forwarding callbacks to
flashLoanCallBack
Required Implementation
Example: Aave Adapter
The Aave adapter demonstrates the pattern:Aave Implementation Details
Aave Implementation Details
Parameter Mapping:
assets: Single-element array with token addressamounts: Single-element array with loan amountinterestRateModes: Set to[0]to avoid opening debt positionsparams: Pass throughcallBackDataunchangedreferralCode: Set to0(currently inactive)
- Must implement
IAaveFlashLoanReceiver.executeOperation - Receives loan details and custom parameters
- Returns
trueto indicate success - Calls
flashLoanCallBackto continue router execution
Example: ERC-3156 Adapter
The ERC-3156 adapter shows a simpler pattern:ERC-3156 provides a standardized interface, making adapters simpler and more uniform across providers.
Access Control
Adapters enforce strict access control:Router-Only Access
src/mixin/Borrower.sol
Settlement-Only Access
src/mixin/Borrower.sol
Fund Flow
The adapter manages fund flow between lenders, router, and settlement:Adding New Providers
To add support for a new flash loan provider:Best Practices
Always Pass Data Unchanged
Always Pass Data Unchanged
The
callBackData parameter must be passed to the router exactly as received. Never modify, parse, or validate this data in the adapter.Handle Provider-Specific Requirements
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
Validate Provider Responses
Check for success conditions specific to the provider:
Use Immutable References
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