✅OpenZeppelin ERC-3156
Last updated
Last updated
This ERC provides standard interfaces and processes for single-asset flash loans.
A flash loan is a smart contract transaction in which a lender smart contract lends assets to a borrower smart contract with the condition that the assets are returned, plus an optional fee, before the end of the transaction. This ERC specifies interfaces for lenders to accept flash loan requests, and for borrowers to take temporary control of the transaction within the lender execution. The process for the safe execution of flash loans is also specified.
Flash loans allow smart contracts to lend an amount of tokens without a requirement for collateral, with the condition that they must be returned within the same transaction.
Early adopters of the flash loan pattern have produced different interfaces and different use patterns. The diversification is expected to intensify, and with it the technical debt required to integrate with diverse flash lending patterns.
Some of the high level differences in the approaches across the protocols include:
Repayment approaches at the end of the transaction, where some pull the principal plus the fee from the loan receiver, and others where the loan receiver needs to manually return the principal and the fee to the lender.
Some lenders offer the ability to repay the loan using a token that is different to what was originally borrowed, which can reduce the overall complexity of the flash transaction and gas fees.
Some lenders offer a single entry point into the protocol regardless of whether you’re buying, selling, depositing or chaining them together as a flash loan, whereas other protocols offer discrete entry points.
Some lenders allow to flash mint any amount of their native token without charging a fee, effectively allowing flash loans bounded by computational constraints instead of asset ownership constraints.
Interfaces:
maxFlashLoan(address token)
-> uint256
The amount of currency available to be lended.
flashFee(address token, uint256 amount)
-> uint256
The fee to be charged for a given loan.
flashLoan(contract IERC3156FlashBorrower receiver, address token, uint256 amount, bytes data)
-> bool
Initiate a flash loan.
Interfaces:
onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes data)
→ bytes32
Receive a flash loan.