DODO Docs
Search
⌃K
⚡

Flash Loans

What is a Flash Loan?

A flash loan is a mechanism that allows a user to take out a loan instantly when making a trade or any other payment. In other words, it means you can make payments on credit and pay off the debt later. When you buy tokens with flash loans, flash loans allow you to receive them first and pay for them later.

Flash Loan Mechanism

The above diagram illustrates the four steps of the DODO V2 flash loan swap.
  1. 1.
    Invoke the flashLoan function in the pool contract.
  2. 2.
    The pool sends the base and quote tokens to the applicant (where baseAmount or quoteAmount can be lent to 0).
  3. 3.
    If the flashLoan function is called with data that is not empty, the contract calls the DVMFlashLoanCall or DPPFlashLoanCall method (corresponding to public and private pools) passed by the applicant into the assetTo contract address.
  4. 4.
    After the DVMFlashLoanCall or DPPFlashLoanCall is executed, the tokens will be returned and the contract will calculate if the pool is losing money. If it is losing money, the transaction will fail immediately.
function flashLoan(
uint256 baseAmount,
uint256 quoteAmount,
address assetTo,
bytes calldata data
) external;
Note: DODO V2's flashLoan() function will preview a transaction that equalizes the base and quote tokens to the initial state. It will use the preview transaction fee as the flashloan fee, and no other fees will be charged in other situations.
Using the DODO Flash Loans API requires users implement the IDODOCallee interface.
interface IDODOCallee {
function DVMFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
​
function DPPFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
​
function DSPFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
}

How to Use

Sample code:DODOFlashloan.sol​
Some thoughts
Once you start using Flash Loans, you'll understand the advantages of the DeFi world over centralized finance. By combining smart contracts, we can increase the utilization of funds in DeFi to unprecedented levels, as the cost of trust in the DeFi world is extremely low. The DODO team hopes to get DeFi practitioners started in the DeFi world by introducing them to Flash Loans.
Note: DODO's Flash Loan feature was inspired by dYdX and Uniswap. The DODO team acknowledged the innovative work of these pioneers of the DeFi world. 👍
Last modified 2mo ago