Overview
The IFlashLoanRouter interface defines the contract API for coordinating flash loans with CoW Protocol settlements. It acts as a solver for CoW Protocol, enabling solvers to request flash loans and execute settlements in a single transaction.
Contract Details
- Source:
src/interfaces/IFlashLoanRouter.sol
- License: GPL-3.0-or-later
- Solidity: ^0.8.28
Functions
flashLoanAndSettle
function flashLoanAndSettle(
Loan.Data[] calldata loans,
bytes calldata settlement
) external;
Requests flash loans and executes a CoW Protocol settlement atomically. All specified loans are requested sequentially before the settlement is executed.
Parameters:
loans: Array of flash loan specifications, each containing:
amount (uint256): Amount of tokens to borrow
token (IERC20): Token contract address
lender (address): Flash loan provider contract
borrower (IBorrower): Adapter contract for the lender
settlement: ABI-encoded settle() call data for the CoW Settlement contract
Requirements:
- Caller must be a registered CoW Protocol solver
- No concurrent settlement in progress
- Settlement data must encode a valid
settle() call
It is the solver’s responsibility to ensure the loan is specified correctly. The router does not validate that flash loan proceeds will be available for the settlement.
borrowerCallBack
function borrowerCallBack(bytes memory loansWithSettlement) external;
Callback function for borrower contracts to signal flash loan receipt. The borrower must pass the encoded data back unmodified.
Parameters:
loansWithSettlement: Encoded remaining loans and settlement data
Requirements:
- Caller must be the expected pending borrower
- Data must match the stored hash
settlementContract
function settlementContract() external view returns (ICowSettlement);
Returns the CoW Protocol settlement contract address.
settlementAuthentication
function settlementAuthentication() external view returns (ICowAuthentication);
Returns the solver authentication contract address used to verify solver identity.
Events
Settlement
event Settlement(address indexed solver);
Emitted when a solver initiates a flash loan settlement.
Data Types
Loan.Data
struct Data {
uint256 amount;
IERC20 token;
address lender;
IBorrower borrower;
}
Specification for a single flash loan request within a settlement.
Execution Flow
- Solver calls
flashLoanAndSettle() with loan array and settlement data
- Router requests each loan sequentially through borrower adapters
- Each borrower receives funds and calls
borrowerCallBack()
- After all loans are obtained, the router executes the settlement
- Settlement repays loans through borrower approvals
Key Constraints
- Only one settlement execution per call
- Settlement data cannot be modified during execution
- Only the
settle() function can be called during execution
- Callback data must be passed through unmodified
Next Steps