8 min read
Overview
Aave, previously known as ETHLender, has catapulted to the forefront of the DeFi space. Aave was the first in the space to come up with the idea of a Flash Loan. Before flash loans, you would have to stake an over-collateralized asset to loan another asset. For example, if I wanted to borrow one DAI, I would have to deposit another cryptocurrency that exceeded that value. In other words, you had to have money to borrow money. Flash Loans demolished this idea. And they opened up doors for a new loaning system. They did this by allowing users to borrow without putting up anything as collateral. In this tutorial, you will learn how to deploy an Aave V3 Flash loan smart contract!
Prefer a video walkthrough? Follow along with Sahil and learn how to make a flash loan using Aave in 19 minutes.
About Aave
Taken from the Aave website.
Aave is a decentralised non-custodial liquidity market protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an over collateralized (perpetually) or undercollateralized (one-block liquidity) fashion.
While that is entirely correct, it may not make much sense to you if you aren’t already familiar with all of the DeFi industry jargon. You could think of Aave as being a decentralized pseudo-bank. Instead of a central bank that validates all of the transactions, Aave has smart contracts that do all of this work in an automated fashion. Depositors put their tokens into Aave, and begin earning interest on their deposit. Borrowers on the other hand will do the opposite. They will take money out of Aave and will begin accruing interest on the amount borrowed. In order to do this, they must be overcollateralized.
There is another method for those that don’t want to deposit money into Aave, and just want to borrow. This is the Flash Loan we mentioned earlier.
About Flash Loans
The previously mentioned Flash Loan is a new way of borrowing assets on the blockchain. Initially implemented by Aave, other trending DeFi protocols such as dYdX quickly followed suit in adding this new feature. There is a property that all Ethereum transactions share that enable Flash Loans to be possible. And this key feature is atomicity.
A transaction is atomic whenever the series of its operations are indivisible and irreducible. Or in plain english— either all or none of the transaction occurs. No halfsies! The Flash Loan leverages atomicity to allow a user to borrow without posting collateral.There are two caveats to mention. First of all, whenever you borrow an asset in a Flash Loan you have to pay a fee of 0.09% of the amount loaned. Secondly, you must pay back the loan in the same transaction in which you borrowed. While this ability is great, it is somewhat limited in its use. Flash Loans are primarily used for arbitrage between assets.
Remix Setup
For the sake of simplicity, we will be using the Remix IDE.
This is a browser-based IDE. Also known as an Integrated Development Environment.
Remix comes with the ability to write, debug, deploy, and otherwise manipulate EVM Smart Contracts. In this guide, we will deploy a smart contract on Polygon Mumbai Testnet.
When you load up Remix in your browser, you will be greeted by this menu.
We won’t be doing a deep dive on the IDE, as the focus of this tutorial is on the Flash Loan. However, you will want to become familiar with the four sections highlighted: main panel, side panel, icon panel, and terminal.
Before we start writing our smart contracts we will want to download a browser extension that allows us to interface with the Ethereum blockchain. There are several tools out there that unlock such functionality, but the most popular one is MetaMask.
Creating A Polygon Mumbai Endpoint
We will use QuickNode as a custom RPC in our MetaMask wallet to propagate transactions faster. This doesn't guarantee faster transaction confirmation but increases the chances of getting the transaction in front of a validator. Sign up for a free QuickNode Polygon Mumbai RPC here.
Copy the HTTPS URL. We will need it in the next step.