Flash Loans
Overview
Key Concepts
What is a Flash Loan?
Flash Loan Fee
Implementation Steps
Step 1: Implement the IFlashLoan Interface
function onFlashLoan(
uint256 assets,
uint256 assetsReturned,
bytes calldata data
) external returns (bytes32) {
// Verify the callback is from the expected BorrowableCToken
require(msg.sender == borrowableCToken, "Unauthorized callback");
// Your custom logic here.
// At this point, you have received 'assets' amount of tokens.
// IMPORTANT: You must approve the BorrowableCToken to pull back
// the loan amount + fee before this function returns.
SafeTransferLib.safeApprove(asset, borrowableCToken, assetsReturned);
// Return value (not currently checked by the BorrowableCToken contract).
return keccak256("ERC3156FlashBorrower.onFlashLoan");
}Step 2: Initiate the Flash Loan
Flash Loan Execution Flow
Important Considerations
1. Available liquidity
2. Fee Calculation
3. Token Approval
Error Handling
Error
Cause
Solution
Last updated
Was this helpful?