Comment on page
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.
THE INTERACTION ABOUT FLASH LOANS
- 1.Users or contract through
Pool.flashLoan()to apply for a certain number of assets. The protocol takes a snapshot of the asset balance.
- 2.Through some verifications,
Poolapply for transfering asset to
flashLoanReceiver(contract), and call the
flashLoanReceiverholds the assets from flash loans. It is accessible to do any operation in
executeOperation(). Such as arbitrage, liquidation；
- If the execution is
flashLoanSimple(), you must repay the loan(fee) to
Poolafter completing it.
PoolUpdate the cache and interest rate, and transfer the user's borrowed amount and fees to the reserve pool.
- If the asset amount in the
flashLoanReceivercontract 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 modeparameter is not 0, then when you are done, the borrowed amount will be generated as debt.
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 Flash Loan borrower must repay the principal and the fee.
- 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.