Flashloans
What is a Flash Loan?
Flash Loans allow you to borrow any available amount of assets without putting up any collateral, as long as the liquidity is returned to the protocol within the same transaction. To do a Flash Loan, you must build a contract requesting a Flash Loan. The contract will then need to execute the instructed steps and pay back the loan + fees all within the same transaction.
How do we support Flash Loans?
With Move, we implement flash loans using the hot-potato pattern. Let's go through the code to better understand it.
First, we define a Flashloan
struct without any abilities.
The struct records the number of Coin<T>
's that were borrowed. Because this struct does not have the key
or store
ability, it cannot be transferred or otherwise placed in persistent storage. Because it does not have the drop
ability, it cannot be discarded. Thus, the only way to get rid of this struct is to call repay
sometime during the transaction that created it, which is exactly what we want from a flash loan. Otherwise, your code won't even compile.
Flash Loan fee
Meridian charges a fixed 1bps flash loan fee.
Utilizing Flash Loans
Call flashloan
and pay_flashloan
in the same transaction. Here's a complete example:
Last updated