What are Flash Loans in DeFi?
Table of Contents
Among the useful building blocks in Decentralized Finance (DeFi), Flash Loans allow users to borrow crypto assets from a designated smart contract pool without collateral.
In this article, Liquid has discussed everything you need to know about Flash Loans, their use cases, and more.
Introduction to flash loans
In a nutshell, a flash loan has to be borrowed and repaid within the same blockchain transaction on Ethereum.
The Marble Protocol initially introduced the concept of Flash Lending to let users borrow Ether and ERC-20 tokens on Ethereum and take advantage of the resultant arbitrage opportunities.
The idea behind this concept was to let a trader borrow from the Marble bank to buy a token on one DEX and then sell it on another DEX for a higher price. A borrower would then repay the bank and churn out the arbitrage profit -- everything in a single atomic transaction.
Flash Loans were later popularized by Aave and DyDx protocols of DeFi.
In addition to seizing arbitrage opportunities, flash loans can also be used for swapping collateral and self-liquidation. More on that later.
How flash loans differ from traditional loans?
Before we get into the technicalities of flash loans, let’s quickly understand how it differs from traditional loans.
There are two broad categories of loans in the traditional sense: Secured and unsecured.
In unsecured loans, there is no collateral, an asset a lender can have if a borrower doesn’t repay the loan), and hence considered a higher risk for lenders.
As opposed to that, secured loans are where a borrower has to put up collateral.
Flash Loans ensure that unsecured loans in crypto (without collateral) are repaid instantly in the same transaction. Sounds confusing? Let us explain.
How do flash loans work?
A transaction on Ethereum represents several operations that must execute in an atomic way.
It means that either all of the operations in a transaction are executed successfully, or the entire transaction is rolled back. There is no middle ground here.
On Ethereum, all basic operations like sending ETH or ERC-20 tokens and interacting with smart contracts are executed within a transaction scope.
Transactions grouped and included in Ethereum blocks can consist of multiple steps. So what are these steps exactly?
Let’s say you want to supply ETH and DAI on Compound. At the same time, you can also swap half of the DAI you just borrowed for USDC on Curve and provide liquidity to the DAI/USDC liquidity pool on Uniswap - all in one single Ethereum transaction.
If any of these steps fail to execute successfully, the entire transaction will be rolled back, and none of the steps will occur.
So, how to execute a flash loan?
First of all, you need to find a flash loan provider.
DeFi projects like Aave and DyDx have developed smart contracts that allow users to borrow different assets from a designated pool for a certain cost. The only condition is that they are repaid within the same Ethereum transaction.
Aave, for instance, requires the borrower to repay the borrowed amount with an additional 0.09% of the total borrowed amount as fees.
This fee is then split between lenders and the platform facilitating the flash loan by integrating Aave’s flash loan API. A part of this fee is also swapped to Aave tokens & burned.
Because the loan has to be repaid within a single transaction on Ethereum, it eliminates the risk of borrowers not repaying their borrowed amount.
Why do we need flash loans?
There are three primary use cases of flash loans:
- Arbitrage opportunities
If there is a price discrepancy between two Decentralized Exchanges (DEX), flash loans can help borrowers magnify their profits by seizing a successful arbitrage opportunity.
- Collateral swap
Another use case of flash loans is a collateral swap. For example, if you have borrowed DAI from Compound with ETH as collateral, you can swap your collateral from ETH to another ERC-20 token such as BAT.
Self-liquidation can come in handy when the value of your collateral decreases and you are fast approaching the liquidation level.
For example, let’s say you have borrowed DAI against your ETH from Compound. As the price of ETH declines, you continue to approach the liquidation level.
Imagine a situation where you cannot deposit more collateral to increase your liquidation level, and you don’t have enough DAI required to repay the loan either.
You can take a flash loan from, let’s say, Aave in that case. You need to borrow the amount of DAI you owe so that you can repay your loan to Compound and withdraw your ETH.
You can then swap the ETH to DAI on Uniswap to repay the flash loan plus fees.
Although flash loans are a fairly new concept of uncollateralized loans, they surely pave the way for new possibilities in this new decentralized finance ecosystem system.
Buy and Trade cryptocurrency on Liquid
Interested in crypto? You can buy crypto via a bank transfer or instantly purchase it with your bank card.