Flash Loans
Flash loans are an advanced concept typically used by developers to write and execute smart contracts on the Ethereum Virtual Machine (EVM).
It leverages the programmability and instant execution of smart contracts, enabling users to borrow and repay assets in a single transaction without the need to possess the borrowed assets beforehand. The main applications of Flash Loans are arbitrage opportunities arising from interest rate differentials between different platforms and profit from collateral liquidation.
Necessary Conditions for Successful Flash Loans
Closing balance > Borrowing amount +Transaction fee
Execution Process
Users or contract through
Pool.flashLoan()
to apply for a certain number of assets. The protocol takes a snapshot of the asset balance.Through some verifications,
Pool
apply for transfering asset toflashLoanReceiver
(contract), and call theexecuteOperation()
;flashLoanReceiver
holds the assets from flash loans. It is accessible to do any operation inexecuteOperation()
. Such as arbitrage, liquidation;If the execution is
flashLoanSimple()
, you must repay the loan(fee) toPool
after completing it.Pool
Update the cache and interest rate, and transfer the user's borrowed amount and fees to the reserve pool.If the asset amount in the
flashLoanReceiver
contract is less than the borrowed amount + transaction fee at the end of the flash loan business, the data will be rolled back, and the transaction will fail.
If the execution is
flashLoan() and the mode
parameter is not 0, then when you are done, the borrowed amount will be generated as debt.
Flash Loan Debt Conversion
Flash Loan Debt Conversion When executing a flash loan, users can decide whether to convert the borrowed amount into a regular debt through parameter settings.
During the process, the system checks if the InterestRateMode is "none." If it is, the repayment is made directly. If not, it proceeds to the next step.
When the InterestRateMode is not "none," it means that the user is converting the flash loan into a regular debt. At this point, the user must set the interest rate model in the InterestRateMode, either variable or stable.
If the user selects the stable interest rate model, the conversion will fail if the converted amount exceeds the proportion specified by the maxStableRateBorrowSizePercent in the liquidity pool.
The contract checks if the user's collateral is sufficient and the health factor will be less than 1. If it is less than 1, the conversion fails; if it is greater than 1, it succeeds.
The Key Parameters of Flash Loan Fees
_flashLoanPremiumTotal
The Flash Loan borrower must repay the principal and the fee.
_flashLoanPremiumToProtocol
The percentage of the total surcharge in flash loans belongs to the HOPE Treasury Reserve.
Assuming_flashLoanPremiumTotal is 1%, _flashLoanPremiumToProtocol is 10%. If a user borrows 10,000 DAI, the user will need to repay the principal of 10,000 DAI plus an additional fee of 100 DAI. Out of this additional fee, 10 DAI will be allocated to the treasury, and 90 DAI will be distributed to the liquidity providers in the pool as LP rewards.
Last updated