This DeFi instrument is called a Flash Loan - so how does it work?
A flash loan allows you to borrow money (up to very large amounts) without any collateral
The catch is that you have to return the money in the very same transaction.
Here’s how a standard database (web2) transaction works. Let’s say @jack is sending $100 to
@elonmusk through a regular bank transfer.
2 things must happen when the money is sent. The bank must update:
(1) +$100 for Elon (2) -$100 for Jack
1 cannot happen without
1 happens, but
2 does not, then the entire transaction is rolled back (voided).
Similarly, if you take a flash loan, you must return the borrowed amount in the SAME transaction as where you borrowed it.
You might now be wondering:
Why would anyone want to take a flash loan if you have to return the money in the same transaction?
One purpose is for arbitrage opportunities.
Let’s say you have $1,000 at your disposal.
In this trade, you have profited $10. Minus gas fees. Not bad. But you could alternatively use a flash loan to make the same trade with a bigger lever.
- You borrow $1M from @AaveAave protocol at 0.09% interest
- You buy 1,000,000 DAI tokens for $1M
- You sell 1,000,000 DAI tokens for $1,010,000
- You repay the $1M loan + $900 as interest
Your profit here is $10,000 - $900 = $9,100 USD. Minus gas fees.
$9,100 is slightly better than $10, yeah?
What happens if a step fails?
Now suppose step 3 fails.
Then the entire transaction fails - you lose your gas fees, but that’s it.
It’s a single transaction with multiple steps, not multiple transactions.
There’s also no risk to the lender because they have nothing to lose.
If the return step (4) fails, then the borrow step (1) never went through either.
Flash loans are also used for collateral swaps and liquidations
@furucombo is a DeFi app that lets you create custom strategies using flash loans with a drag and drop UI.
There are other great ones too.
For those who'd like to see a video explainer about this, here's a great video by @finematics
And another great one by @WhiteboardCryp1:
Hope this helped explain the concept!