Flash Loan

Maximizing Your Arbitrage using Flash loans

By Equalizer Team
April 18, 2022
Arbitrage

What is arbitrage?

Arbitrage is literally a "buy low sell high" strategy in business. So let's say 1 ton of wheat sells for $200 in the USA and it goes for $300 in Europe. So a simple way to make money would be for me to buy wheat at $200 in the USA and then sell it in Europe for $300. A smooth profit of $100 there, isn't it? It gets more interesting when I buy hundreds of tons for $200/ton in the US and hope the price per ton in Europe remains $300 or even higher. Arbitrage is really as simple and sweet as that. But there is one big issue. If I buy hundreds or thousands of tons of wheat from the United States only to discover on my return to Europe that the price has dropped by half to $150, then I would suffer a significant loss on that one.

‍

How does crypto arbitrage trading work?

Bringing this idea home, crypto arbitrage trading is when an asset has different prices on different exchanges. Let's look at two decentralized exchanges: Uniswap and dYdX.

‍

What is arbitrage?

‍

Arbitrage works this way: If one ether is worth 180 LINK on Uniswap and 200 LINK on dYdX, I can purchase 1 ETH on Uniswap and immediately sell it on dYdX. This means I’m making a profit of 20 LINK(minus the gas fees). This kind of transaction is a typical profitable arbitrage trade.

In essence, arbitrage trading is all about finding the right opportunities and acting as fast as possible because the opportunity might go almost immediately you find out. This brings perhaps the biggest challenge of arbitrage trading in the sense that you'd have to pray the opportunity would be there by the time you're ready to act on it or, better still, that you can act on it right when it comes. Otherwise, you may incur huge losses while trying to make profits. This challenge is prevented with Flash Loans, a very profound tool in the DeFi ecosystem. So what are flash loans, and how do they eliminate the arbitrage challenge?

What is a flash loan?

‍

What is a flash loan?

‍

A flash loan could be defined as a sort of uncollateralized lending system widespread across many Ethereum based Defi protocols where you can receive a loan, do whatever you want with the borrowed asset, and return it to the lender all in one transaction.

‍

What are collateralized loans?

To truly appreciate the concept of flash loans, let's review what traditional loans look like. For example, if you want to take a loan from a bank or a financial institution, the process usually goes thus:

  • You make a formal request, and the bank ensures the relevant documents you have submitted are valid.
  • If they are, the bank shares the agreement terms and requests a collateral asset that is usually worth more than your intended loan.
  • You review the agreement terms, introduce your collateral, and initiate the loan process. At this point, your collateral asset becomes locked up until you pay up.
  • If you don't repay the loan within the agreed period, the bank takes control of your asset.

This completely centralized financial system is plagued by paperwork, non-transparency, and high fees. They are also relatively exclusive to people with good financial records. The emergence of decentralized finance systems has solved many of these challenges. DeFi protocols require no paperwork and allow anyone to use loans. They also charge very low fees and are more traditional loans. However, you need a collateral value to take this kind of loan. Indeed, your collateral value has to be higher than your debt value, or else you won't be allowed to take this loan.

‍

What are the challenges of collateralized loans?

Collateralized loans in the DeFi world do not eradicate some of the problems of traditional loans. Indeed, collateralized loans in centralized and decentralized spaces share some challenges. The biggest challenge with both forms of loans is in presenting a collateral asset to borrow from the lending entity (whether banks or DeFi platforms). If you don't have a collateral asset worth more than the intended loan, you will find it very difficult to get access to such loans. The thing about collateralized loans is that they are risky for both borrower and lender. There is the risk of getting liquidated due to an inability to repay the loan. For instance, the status of an arbitrage trade may change in a bit of time due to the unpredictability of the crypto market.‍

‍

What are the characteristics of flash loans?

Flash loans have the following unique properties:

Unsecured loan: Flash loans are usually unsecured loans, that is, they do not require collaterals. Despite the absence of collateral, lenders are still guaranteed their money because the borrowers repay immediately.

‍

Instant: In many cases, the entire process of a traditional loan spans weeks, months, or even years. A flash loan, on the other hand, is instantaneous. Since a flash loan's smart contracts must be completed within the same transaction that it was given out, any need to undergo another trade implies the borrower has to employ other smart contracts to be fulfilled.

‍

Smart contracts: Flash loans employ smart contracts. For example, in every flash loan, the borrower must repay the loan in that same transaction, or else the smart contract reverses the transaction- making it appear as if the loan never occurred in the first place.

‍

How do flash loans work?

‍

How do flash loans work?

‍

Flash loans ensure that when you borrow, say $1000, you pay it back in that same transaction. In principle, a flash loan prevents you from getting "stuck" with a digital asset since you won't hold the asset longer than an instant. Flash loans provide an unprecedented solution to some nagging challenges in finance. With flash loans, you can undergo arbitrage and fast trades that were impossible before blockchain was a thing.

Flash loans are uncollateralized because there are technically no risks of not paying back the loan. With flash loans, it is usually an all-or-nothing scenario, that is, you either will execute your transaction successfully and repay the initial amount you lent, or the entire transaction fails. There is no part of a flash loan where you owe the DeFi protocol or become unable to repay your loan. The only fee you'd pay is the gas fee and small premium (usually negligible) to providers such as Equalizer.

So how's that possible? How do these protocols ensure you repay your flash loan? The gist is that flash loans are encoded in a smart contract. A smart contract is a self-executing contract, and the terms of the contract between you, the borrower, and the lender are written in lines of code. Now the agreement, in this case, is that you can only get the loan if you repay the loan in the same transaction. For example, let's say you intend to undergo an arbitrage transaction between an Exchange A and an Exchange B. A flash loan gives you the leverage for this transaction because, as discussed earlier, time is the rate-limiting factor in arbitrage trading.

‍

How to maximise arbitrage trading with Flash loans

Let's return to the Uniswap/ dYdX arbitrage trade we mentioned earlier in the article to explain further. So I can execute the arbitrage trade without having 1ETH or a collateral asset in my wallet. If 1 ETH is worthΒ  20 LINK on Uniswap and 18 LINK on dYdX, this is how it will go:

  • I will request a flash loan and borrow, say, 100 LINK tokens on dYdX
  • I will then exchange 100 LINK with 5.5 ETH on Uniswap
  • I will trade 5 ETHΒ  with 100 LINK on dYdX
  • I will repay the flash loan with 100 LINK from step 3
  • My profit is 0.5 ETH.

This example shows how flash loans can be invaluable in arbitrage trades. I observed a price difference for the ETH-LINK on two platforms (dYdX and Uniswap) and maximized it with flash loans. Bar the gas fees, the process is entirely free. Additionally, all the steps are part of a single transaction on the Ethereum blockchain, making it almost risk-free for both borrower and lender

‍

DeFi Protocols Offering Flash Loans

Although many projects are willing to join the flash loan bandwagon, only a few DeFi protocols offer flash loans to their users. Some of them are listed on the table below.

‍

DeFi protocol No of tokens Fee (%)
Aave 22 0.09
Equalizer 100+ 0.05
dYdX 3 Free
Uniswap V2 100+ 0.3

‍

What are the risks of flash loans?

The risks associated with flash loans can generally be classified into two. The first class of risks is connected to the source code behind the flash loans. You must pay some gas fees and premiums to access flash loans.

The second class of risks is much more profound and is related to flash loan attacks. In May 2021, PancakeBunny, a BSC-powered yield farming aggregator, suffered a flash loan attack that caused its token to slide about 95% less than its previous value. Earlier in February 2021, Alpha Homora was drained of about $37 million due to a series of flash loan attacks. Flash loans are not illegal but β€œflash loan attackers” have learnt to exploit the process to make inordinate gains

Β 

A flash loan attack occurs when a malicious actor employs a flash loan to borrow a large amount of tokens and uses it to exploit different vulnerabilities in other DeFi protocols.For instance, a flash loan attacker can generate slippage, which refers to the price differential between an exploitable contract and the actual value of a trading pair.

By causing slippage, an attacker can obtain a token at a low cost or sell one for a high price to the compromised contract. This allows them to deplete the contract's value by compelling it to hand up the tokens put within it. The attacker can then transfer their stolen tokens into the cryptocurrency of their choice via additional exchanges.

‍

How to get flash loans

If you want to get flash loans, you need to consider several factors such as fees, gas efficiency, and user-friendliness. Although not many DeFi protocols offer flash loans, Equalizer is one of the most promising flash loan platforms.

‍

Get flash loans on Equalizer.

Equalizer prides itself as the first dedicated flash loan marketplace to cater to the rising demand of DeFi borrowing and lending. It distinguishes itself by providing the lowest fees and transaction costs and a nearly limitless selection of token vaults. This prevents its flash loans to be subjects of flash loan attacks as the lenders deposit their tokens in these vaults and receive vault LPs that can be used any time to withdraw their funds. It also has a scalable multi-chain architecture, integration-friendly infrastructure, and a feasible roadmap.

‍

What makes Equalizer unique?

  • Top gas efficiency: The gas required for a flash loan call with Equaliser is TWO times lower than its competitors.
  • Low fees: Equaliser's 0.05% fees are very low compared to other platforms.
  • Multi-chain solution: Equaliser is adaptable with Ethereum, Binance, Polygon, and any new chain on request. It is also compatible with any token on any chain, so you're covered whether it's LINK, UNI, DAI or WBTC.
  • Standard interface: The interfaces are compliant with the EIP-3156 FL protocol to ensure easy integration.
  • Security audit: To ensure the validity of the smart contracts, they are verified by the industry-standard independent auditor Certik.io

‍

How Equalizer gas fees compare to other flash loan platforms

The operational cost of borrowing and returning flash loans on 3 platforms were tested and compared on Ethereum testnets. The results of the gas fees comparison are represented in the table below

‍

Platform Transaction cost (gas) Gas cost compared to Equalizer Gas profile Transaction code Code
Equalizer 111,752 100% Tenderly Tx Etherscan code
AAVE 204,493 183% Tenderly Tx Etherscan code
dYdX 225,223 200% Tenderly Tx Etherscan code

‍

‍FAQs

What is arbitrage trading?

Arbitrage trading is a trading method that seeks to profit by simultaneously purchasing an item in one market and selling it in another.

‍

Is crypto arbitrage trading profitable?

Yes, it is. If you understand the entire process and have access to the appropriate tools and platforms, you'd find crypto arbitrage trading profitable. However, you must understand what you are doing and be equipped with the proper tools and platforms. Arbitrage may provide a good return if you are proactive enough to capitalise on advantageous possibilities. Apart from being alert and quick, the amount of money you put into work is also essential.

‍

Are flash loans safe?

Because they are uncollateralized, flash loans are relatively risk-free from the borrower's perspective. Unfortunately, in recent years, flash loans have been plagued by several attacks leading to the loss of millions of dollars. The problem emanates from a bigger DeFi problem because smart contracts can be altered if they are not written correctly. This is why platforms like Equalizer have their smart contracts verified by industry-standard auditors.

‍

What are flash loan attacks?

A flash loan attack occurs when a malicious actor employs a flash loan to borrow a large amount of tokens and uses it to exploit different vulnerabilities in other DeFi protocols. For instance, a flash loan attacker can generate slippage, which refers to the price differential between an exploitable contract and the actual value of a trading pair.

Unfortunately, many flash loan lenders have lost millions of dollars to flash loan attacks. This is why the flash loan marketplace, Equalizer, specifically designed vaults with limited capacity in order for its flash loans not to be used in flash loan attacks. Flash loan lenders just have to deposit their tokens in these vaults and receive vault LPs that can be used anytime to withdraw their funds.

‍

What if I don’t pay back a flash loan?

If you don't pay back a flash loan, then technically, you won't receive the loan in the first place. Keep in mind that a flash loan is completed in a single transaction. The smart contract would prevent the loan from being issued if both parties (the lender and the borrower) fail to honour the agreement.