Sneak peek at Flash Loans

Marc Zeller
Feb 7, 2020 · 7 min read

Aave protocol launched a bit less than a month ago and is already gaining traction with a bit more than 11M$ in protocol Market Size.

from Zero to 11,3M$ in less than a month

Among Aave’s new features, the Flashloans are probably the most discussed in the ecosystem!

Flashloans are a textbook example of a feature that is designed for third-party developers to generate profits or can be leveraged to offer new features or services to their users.

A more resilient ecosystem with liquidations

DeFi is currently built on the foundation of overcollateralization — lock assets into Aave (or any other protocol) and borrow up to 75% of their current value. If the deposit value increases, the borrowing power increases as well. On the other hand, if the deposit valuation declines, a liquidation event can be triggered. The collateralization ensures that the deposit is available to any third-party liquidator to pay back the debt on behalf of the borrower and that they get paid a liquidation bonus for the service.

This mechanism is the cornerstone of the whole DeFi ecosystem. The safety of the protocol relies on these liquidations. If they fail, most of them enter emergency mode with several lines of defense.

Borrowed assets are almost never the same asset as the one initially deposited by the borrower. Until now, liquidators had to have a huge amount of liquidity in several fluctuating assets to be able to swiftly liquidate a position.

With Flashloans, no capital is needed to execute a liquidation, borrow funds from Aave, pay back the debt on behalf of the borrower, collect their deposit, trade it for the best available price on and return the assets to Aave with a small fee all in a single transaction. The remaining assets are yours to keep!

By removing the need to hold any capital, we aim to democratize the liquidation market and enable faster and easier liquidations. The safety of the whole ecosystem will be better and the risk of “bad debts” much lower.

The liquidation game without the need for capital.

Self-Hedging for reckless traders

A Borrower willing to take risks in leveraging long, just like the legendary CDP 3228, can decide to use Aave to hedge their risk by building a flash loan script to wind down a debt position

1) borrow some DAI from Aave

2) pay back part of their debt

3) withdraw some ETH

4) convert it to DAI with or

5) payback Aave

All of this in a single and almost instant transaction!

This feature can be built to run on autopilot to keep the collateralization at a targeted collateralization ratio just a touch above the liquidation threshold!

Self Liquidation

But why stop here? In the DeFi ecosystem, the liquidations penalties for loans are currently in a range of 3 to 15% depending on the platform, a pretty high price on multi-million $ positions.

By leveraging Flashloans, services allowing self-liquidation can be built. If you have a position open and are not near the devices needed to access your funds, simple market events (that are not very rare in our highly fluctuating markets) can trigger a liquidation.

To avoid that, a simple script to self-liquidate your loans can use flash loans and your own deposit to pay it back. Flash loans are not free, but it’s much better to pay a 0,09% fee than a 15% liquidation penalty right?

For CDP 3228, if Flashloans were an option, that would have saved him $183k in liquidation cost!

Arbitrage, The Flash Boys 3.0

Launched by the crazy folks from Stake Capital, the ArbitrageDAO, immediately nicknamed “The Flash Boys” as a reference to Lewis Bestseller, is a DAO specialized in market making arbitrage opportunities and leveraging flash loans to avoid any requirement of capital.

Their scripts were unleashed into the mainnet in late January and did a bit more than $150 of profits on 10k$ of volume in one day.

This showcase was promoted in Julien Bouteloup’s blogpost. They raised capital and announced the official launch of their arbitrage bots during ETHDenver 2020.

Highly automated and optimized to beat frontrunners, the ArbitrageDAO will leverage Aave’s liquidity to take advantage of a wide range of currency pairs and liquidation opportunities.

They make money, and we have less spread between platforms and more decentralized volume. Quite a win-win scenario.

Collateral Swap

All DeFi lending protocols are now allowing multi-collateral deposits. In our highly fluctuating markets, some assets might be more bullish than others, so why not simply swap collateral to keep a trading position and add a passive “long” by holding another asset as collateral?

If the new asset used as a deposit overperforms the original one it leads to higher profits.

Before Flash Loans, we would have to pay back the opened loan, swap collateral, and re-open a loan, requiring many transactions to “wind down” the debt if you don’t have a lot of capital at hand to execute the operation.

With Aave, the process is instant as explained by Haydens from Uniswap :

Collateral swap on makerDAO has already been implemented by David Truong but it can be easily implemented on any DeFi protocol such as Compound or DyDx.

Debt refinancing — ‘Interest Rate Swap’

Collateral swaps are not limited to be executed from within a single protocol, Aave is decentralized permissionless and agnostic if you have an open position on and witnessed on our friends from dashboard that rates are favorable on Dydx, Flashloans can be used to :

  1. Borrow Asset from Aave liquidity
  2. payback debt on Compound
  3. withdraw collateral from Compound
  4. deposit collateral on Dydx
  5. mint debt on Dydx
  6. return liquidity to Aave

All of that in a single transaction. DeFi is all about synergy and composability.

We do not believe in walled gardens — users should be free to seek the best opportunities and always have the liberty to choose what’s best for them. Our job is simply to be the protocol with the best features and opportunities.

Debt refinancing — ‘Currency Swap’

The above use-case example demonstrates how Aave Protocol and Flash Loans are used to refinance debt to a lower possible interest rate in another lending protocol. The above example could be extended to swapping the rate to another currency where the rate is even lower either temporary or for the whole loan period by adding an additional transaction for the Flash Loan circuit where the current borrow currency is sold to another one:

  1. User has a Compound loan with 8% on Dai borrow
  2. Dai is borrowed as a Flash Loan from Aave
  3. Compound borrow is closed and ETH is unlocked from the collateral
  4. ETH is sent to DyDx where the there might be 5% on USDC
  5. USDC is borrowed from DyDx
  6. USDC is sent to UniSwap or Kyber and converted back to Dai
  7. Dai Flash Loan is repaid to Aave

The result is that the borrower refinanced the loan from 8% Dai to 5% USDC without returning the Dai loan. This function could be even extended to work algorithmically by rebalancing to a rate that is always the lowest stablecoin rate. Additionally, a function could be added where the borrower could repay the loan with any stablecoin to close the borrower’s position (stablecoins are sent to UniSwap or Kyber and converted to borrow currency and repaid).

And much more to come…

As we said, these use cases are just the tip of the iceberg for flash loan capabilities. A lot of developers are currently building incredible features leveraging Aave protocol. If you want to be a part of this, join us in the #developers channel of our Discord server. We will be more than happy to help you navigate our Documentation!

Aave Blog

Headquartered in London, Aave is made out of a team of…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store