Overview
TheBorrower abstract contract establishes a standardized foundation for developing flash loan provider adapters. It applies the Template Method design pattern, handling shared operations — including authentication, fund management, and router callbacks — while delegating provider-specific flash loan logic to concrete implementations.
Contract Details
- Source:
src/Borrower.sol - License: GPL-3.0-or-later
- Solidity: ^0.8.28
- Type: Abstract contract (cannot be deployed directly)
- Implements:
IBorrower
State Variables
Immutable
| Variable | Type | Description |
|---|---|---|
router | IFlashLoanRouter | The Flash Loan Router that coordinates execution |
settlementContract | ICowSettlement | CoW Protocol settlement contract for authorization |
Constructor
Functions
flashLoanAndCallBack
triggerFlashLoan method.
Parameters:
lender: Flash loan provider contract addresstoken: ERC-20 token to borrowamount: Amount of tokens to requestcallBackData: Data to pass back to the router unchanged
approve
token: ERC-20 token to approvetarget: Address to approve spending for (typically the lender)amount: Amount to approve
triggerFlashLoan (abstract)
flashLoanCallBack (internal)
Modifiers
onlyRouter
onlySettlementContract
Implementation Guide
To create a new adapter, extend theBorrower contract and implement the provider’s callback interface:
Implementation Steps
- Inherit
Borrowerand the provider’s callback interface - Override
triggerFlashLoan: Map standard parameters to the provider’s flash loan request format - Implement provider callback: Receive the callback from the provider and call
flashLoanCallBack(callBackData) - Deploy: Use the FlashLoanRouter address as the constructor argument
Security Model
- Immutable references: Router and settlement contract addresses cannot be changed after deployment
- Access control: Critical functions are restricted to authorized callers only
- No fund retention: Adapters should not hold funds between transactions
- Approval management: Only the settlement contract can set ERC-20 approvals