Flash Loans are special uncollateralised loans that allow the borrowing of an asset, as long as the borrowed amount (and a fee) is returned before the end of the transaction. There is no real world analogy to Flash Loans, so it requires some basic understanding of how state is managed within blocks in blockchains.

Flash Loans are an advanced concept aimed at developers. You must have a good understanding of Ethereum, programming, and smart contracts to take advantage of them.

Overview

For developers, a helpful mental model to consider when developing your solution:

  1. Your contract calls the LendingPool contract, requesting a Flash Loan of a certain amounts of reserves using [flashLoan()](notion://www.notion.so/developers/the-core-protocol/lendingpool#flashloan).
  2. After some sanity checks, the LendingPool transfers the requested amounts of the reserves to your contract, then calls executeOperation() on your contract (or another contract that you specify as the _receiver).
  3. Your contract, now holding the flash loaned amounts, executes any arbitrary operation in its code.
  4. All of the above happens in 1 transaction (hence in a single ethereum block).

Applications of Flash Loans

Aave Flash Loans are already used extensively with Aave v2 for swapping and/or migrating positions. Other examples in the wild include:

Flash loan fee

The flash loan fee is currently 0.09%, changeable via the normal governance process. To get the current value, call FLASHLOAN_PREMIUM_TOTAL() on the LendingPool contract, e.g. number 1 here.

Step By Step Guide

TL;DR: A reference example flash loan contract can be found on Kovan etherscan and Github code examples repo.

1. Setting up