Simply 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.
The figure above illustrates the four steps in a flash swap happening under the hood
- Call the
flashLoanfunction 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
flashLoanfunction call is not null, the pool contract will call the
- After the
DPPFlashLoanCallis 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
Code sample: DODOFlashloan.sol
Once 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.