Blockchain

Flashloans, DeFi and Sorrow

All you need to know about flashloans.

Dorcas Wokocha
September 28, 2023
7
min read

Picture this: A trader obtains an outrageous loan of $200M without providing collateral, and invests the borrowed asset, only to make a sparse profit of $3!

As ludicrous as the illustration above may seem, do not be quick to write it off as fiction. It is, in fact, a true tale. 

On the 14th of June 2023, an anonymous trader utilized a cryptocurrency trading bot to borrow $200M worth of DAI stablecoin from the DeFi lending protocol MakerDAO, only to realize a net profit of $3. What's more, the entire process of borrowing, trading and repaying the loan lasted only about a couple of seconds.

A few puzzling and controversial questions may arise: 

• Who gives out a $200M loan?

• Who gives out a $200M loan to a bot? 

• Who gives out a $200M loan without collateral?

• Why does the process from lending to refund span only a few seconds?

To begin with, this type of loan leveraged by our bot friend is common in Decentralized Finance and it is known as a "Flash loan". This article will give a detailed explanation of the concept of flash loans, what it is used for and how it works.

INTRODUCTION

The core promise of DeFi is to make financial instruments from the traditional finance world accessible to everyone in the decentralised on-chain ecosystem. Since the emergence of DeFi, financial services from the traditional system, such as lending and borrowing, have been adopted for this purpose. Through decentralised loans, anyone can access large capital without KYC verifications and the protocols that come with the secular system, courtesy of the underlying blockchain technology and the permissionless composability of smart contracts.

WHAT ARE FLASH LOANS?

A flash loan is a type of loan in DeFi that allows users to borrow crypto assets without providing collateral, credit score, proof of income or any form of KYC. In this type of loan, the borrowed assets are repaid within the same blockchain transaction; otherwise, the transaction is reverted. This clarifies that the borrowing process is only considered complete upon repayment of the loan. This mechanism ensures the return of assets in case the borrower defaults on payment.

Flash loans are run by smart contracts, usually on the Ethereum blockchain and integrated with the liquidity pool of DeFi lending protocols. According to recent data from Eigenphi, flash loans averaging $448 million are borrowed weekly from different lending platforms on Ethereum, indicating its ever-increasing usage.

Source

HOW DO FLASH LOANS WORK?

To streamline the process,  a flash loan is executed in four simple 4 steps: 

1. The borrower creates a smart contract specifying the amount to be borrowed, the liquidity pool to borrow from, components for  interacting with other DeFi protocols and loan repayment.

2. The smart contract triggers the flash loan, which usually involves placing a quick trade.

3. The borrowed asset, along with the incurred fee is returned to the liquidity pool.

4. Transaction is complete.

If no profit is realized,  the transaction is reversed as though it never happened. 

It is noteworthy that the entire transaction, from borrowing to repayment, is concluded within a 14-second window, which aligns with the maximum time required to create a single block on the Ethereum chain. 

THE UTILITY OF FLASH LOANS

Sadly, flash loans are not intended for long-term investments. They are designed for rapid, predefined purposes. While originally designed for developers, traders with a measure of technical expertise can now request flash loans through lending platforms. These loans are typically utilized by crypto traders for the following: 

  • Arbitrage Trading

It is a recurring phenomenon in the crypto market for the same asset to trade at slightly different prices on various  exchanges  (DEX) at the same time. Leveraging these price discrepancies to maximize profits is known as arbitrage trading and it is the most common use of flash loans. 

 Here's an example of how it works :

Token A is trading at $100 in DEX A while simultaneously trading at $101 in DEX B. While the price difference may seem to be a mere $1, a smart trader can request a flash loan to capitalize on this price discrepancy, potentially generating significant profit with a large capital investment.

Let's say the trader takes out a flashloan of $100,000 to purchase Token A from DEX A at $100 each and then sells them at DEX B for $101 each,  this will realise a profit of $101,000. The transaction is completed as the initial  $100,000 loan is repaid, leaving the trader with a profit of $1,000.

DeFi aggregators like Yearn Finance  monitor multiple DeFi lending platforms, reflecting asset prices across various markets and highlighting arbitrage opportunities. 

Most traders employ the use of crypto trading bots  to leverage these opportunities  for maximum profit. 

  • Collateral swaps

This technique involves closing a loan with borrowed capital to open a new loan with a different asset as collateral. This method is often used by traders to swap assets to minimise market risks from price fluctuations.

  • Liquidation

This is an advanced technique in collateralised DeFi loans.  Here, a third party can use flash loans to liquidate undercollateralized loans, thereby ensuring the lending protocol remains liquid. In turn, the third-party liquidator can be incentivized.

HOW TO GET A FLASH LOAN

Sadly, requesting a flash loan is not as simple as connecting a wallet to a decentralized application and borrowing funds. The procedure involves creating a smart contract, which could pose a significant challenge for non-developers. Fortunately, many lending platforms have improved their user interfaces to enable traders to access flashloans without the need for extensive coding skills. However, a certain level of technical proficiency is still necessary for the successful execution of a flashloan.

Some vetted protocols for accessing flashloans include:

Equalizer 

Aave 

Furucombo

•  DyDx 

DeFi saver 

Eigenphi 

Balancer 

Most of these protocols (e.g., Balancer)  provide detailed instructions on how to deploy a flash loan executing smart contract. 

LIMITATIONS OF FLASH LOANS

While flash loans are used to capitalize on trading opportunities, they come with various constraints. 

For one, flash loans have no utility outside of the defined contract. The most pressing challenge is that requesting a flash loan necessitates deep technical knowledge on the part of the end user. Additionally, borrowed funds can not be converted to fiat for use in the physical world due to their short lending window, which spans only seconds.

RISKS OF GETTING A FLASH LOAN

Lending assets may be considered risk-free for the lending protocol since the transactions are rolled back- as though the transactions never took place- if the assets are not returned.  However, as is common with any new DeFi technology, flash loans carry inherent risks. For instance, smart contracts are prone to bugs or vulnerabilities which may be exploited by cyber-criminals.

- Flash loan attacks

Flash loan attacks are malicious attempts to exploit vulnerabilities in DeFi protocols and smart contracts. According to the FBI, smart contracts have become one of the largest attack vectors in DeFi flash loans. These attacks are becoming increasingly common in the DeFi ecosystem, given that it is cheap to carry out and easy to get away with, owing to the anonymous nature of blockchain.

A recent case occurred in March 2023 when the DeFi protocol Euler lost approximately $196 million to a flash loan attack. The attack was initially discovered by security researchers at a blockchain security firm. Similarly, other attacks have been carried out in recent times, resulting in the loss of funds from lending protocols. 

- Other risk factors to consider include; market liquidity, price volatility,  regulatory risks, high gas fees, and repayment risks which may lead to transaction failure. It is important to carefully access and mitigate these risks before requesting a flash loan. 

One may ask: "can a user be successful with flash loans?"

The answer is a resounding yes. Unlike the anonymous trader who gained a meagre 3$ despite employing substantial capital, numerous individuals have used flashloans to maximize profits through arbitrage opportunities, making tangible gains.

For example, this individual amassed a staggering $74,365 profit from a flash loan of $725,151

Source

This demonstrates that flash loans can be a resourceful tool for profit-making in the DeFi space. 

CONCLUSION

DeFi marries financial instruments in the physical world to the permissionless composability of blockchain, birthing various possibilities, including flash loans. Flash loans operate within the confines of a single on-chain transaction and conclude on the repayment of borrowed assets along with accrued fees. These loans offer end users access to millions of dollars available to lend without requiring collateral or KYC verification. However, there are limitations to its usage, as they can not be used outside the digital world.

Since developers and traders with a measure of technical expertise are mostly utilizing flash loans, tax authorities are most likely to categorize these transactions as business profits. Please consult your accountant or tax lawyer for the correct categorization in your case (or reach out to us at info@o2k.tech).

Finally, due to risk factors, users seeking to obtain a flash loan should conduct thorough due diligence before requesting one and also familiarize themselves with the terms and conditions of their lending protocol of choice.

Share this post