What Are Flash Loans In DeFi?

Flash loans are a type of uncollateralized lending that has become very popular, over the last year, in decentralized finance (DeFi). They have surfaced as an innovative and useful tool in the market for arbitrage and quick trades that weren’t possible before blockchains.
 
These types of loans allow borrowers to borrow without collateral or providing any personal information. Currently, they're not widely accessible to non-technical folks but they hint at what might be possible to everyone in the future.
 
 
 
Whether they a good or a bad thing is quite controversial to some, flash loans are a hugely innovative and useful tool in DeFi, primarily on the Ethereum Network, while to their detractors, these kinds of loans present an opportunity for unscrupulous actors to siphon off millions by exploiting poorly protected protocols.
 

What Are Flash Loans:

 
Aave, one of the top lending protocols in DeFi, introduced the idea of flash loans in 2020.
 
Most of us are familiar with normal loans. The lender usually takes some kind of collateral to make sure they get their money back, and the contract often takes a while to get approved. Over the specified period, the borrower pays back the loan, with interest.
 
Well, Flash loans are quite the antithesis of normal loans. Flash loans are uncollateralized loans and occur in an instant because the funds are both borrowed and returned within seconds, in the span of one transaction.
 
This is possible because of the innovative properties of smart contracts, which set out the terms and also perform instant trades on behalf of the borrower with the loaned capital. The loan is taken out and paid back within the same transaction. If the trade doesn’t make a profit and loan can't be paid back, the whole transaction is reversed to effectively undo the actions executed until that point.
 
Smart contracts are automated enforceable rules that can execute automatically when certain conditions are met. While running a flash loan, the rule is that the borrower must pay back the loan before the transaction ends, otherwise the smart contract reverses the transaction.
 
The funds that are often used are held in liquidity pools (big pools of funds used for borrowing). If they are not being used at a given moment, this creates an opportunity for someone to borrow these funds, conduct business with them, and repay them in full quite literally at the same time they're borrowed. Flash loans are typically charged at a 0.09% fee.
 
 
Source: Aave 
 
A simple example of using a flash loan can be that you can borrow some amount of an asset at one price from an exchange and sell it on a different exchange where the price is higher.
 
So, the single transaction will include the following:
  1. A user borrows X amount of asset at $100.00 from exchange A
  2. He sells X asset on exchange B for $110.00
  3. He pays back a loan to exchange A
  4. He keeps the profit minus the transaction fee
Let's say exchange B's supply dropped out of a sudden and the user can't buy enough to cover the original loan, the transaction would simply fail and roll back as if nothing happened. 
 
So, in Flash loans, not repaying a loan is out of the question, because the smart contract will entirely revert a loan transaction if it is not paid back before completion.
 

Use Cases Of Flash Loans:

 
Major use-cases of flash loans include arbitrage and debt refinancing
 

Arbitrage:

 
Arbitrage trading can be defined as a process in which a trader purchases an asset on one exchange and sells it on another exchange in order to take advantage of price differences. It simply is buying low and selling high. We have seen the example of Arbitrage above.
 

Debt Refinancing:

 
Another frequent use case is Debt Refinancing. Many times, a trader might take out a loan from a platform only to discover that another platform is also offering the same loan but with better interest rates. In such a situation, a user can switch his loan to a second platform with the help of flash loans.
 
The user can pay off the original loan using the flash loan and withdraw his collateral from Platform A. Then he can borrow a loan from the second platform using his collateral. The cycle is completed by returning back the flash loan, and the user ends up having the loan with a better interest rate in his hands.


Collateral swaps:

 
Flash loans can also be used for quickly swapping the collateral backing the user's loan for another type of collateral.
 
 
Source: Aave 
 

Lower transaction fees:

 
Flash loans roll several transactions into one. Each transaction individually costs a fee so flash loans potentially mean lower fees it does work of many transactions in one transaction.
 
 
While flash loans have proved popular and useful, these types of loans have also made headlines for being been used to exploit a number of vulnerable DeFi protocols, leading to millions of dollars in losses. As flash loans are becoming a bigger part of DeFi and along with them comes an increase in flash loan attacks.


Flash loan attacks:

 
Flash loan attacks are a type of DeFi attack where malicious users take out a flash loan from a lending protocol and use it to manipulate and trick the market in their favor.
 
Because flash loans allow a user to borrow the huge amount they want with zero capital, malicious users thrive on finding ways to manipulate the market while still abiding by a blockchain’s rules. In a most common flash loan attack, an attacker creates an arbitrage opportunity by manipulating the relative value of a trading pair of tokens. This is done by using their loaned tokens to flood a contract and create slippage.
 

Conclusion

 
The flash loan is a very unique instrument of trading that allows you to borrow a huge amount of loan from the lender without any collateral. Given their widespread use, it is most likely that flash loans will continue to be available in the future. Before investing your money in DeFi's wild west, make sure you understand the risks.