Flash Loan
#
What is Flash LoanSimply put, you are allowed to pay on credit on DODO! When you buy tokens DODO, you can first get the tokens you want to buy, do anything you want with the tokens, and pay for them later.
#
How Does Flash Loan WorkThe figure above illustrates the four steps in a flash swap happening under the hood
- Call the
flashLoan
function from the smart contract - Pool transfers the base tokens and quote tokens to the message sender (baseAmount or quoteAmount can equals to zero)
- If the parameter
data
of theflashLoan
function call is not null, the pool contract will call theDVMFlashLoanCall
orDPPFlashLoanCall
method. - After the
DVMFlashLoanCall
orDPPFlashLoanCall
is executed, the contract will calculate whether the pool is losing money, if it loses, the transaction will fail directly.
ps: DODO V2 flashLoan will preview a transaction that equalize the base and quote token to the initial state. using the preview transaction fee as the flashloan fee. No more fee will be charged in other situations.
Requires users implement the IDODOCallee
interface.
#
How to use DODO Flash LoanCode sample: DODOFlashloan.sol
#
Some Thoughts on Flash LoanOnce you have a deep understanding of flash swap, you will realize the superiority of the DeFi world over the centralized world. The composability of smart contracts has elevated the fund utilization of DeFi to an unprecedented level. Thanks to trustlessness, the cost of credit in DeFi is incredibly low. Once this financial system is integrated into the real world, its potential for improving our society and productivity will be truly boundless. The DODO team hopes that flash swap serves as a primer for DeFi builders and beginners alike to gain an appreciation for the power of DeFi.