The Secret Sauce Behind Aave
Aave has catapulted to the forefront of the DeFi space thanks to what they call Flash Loan.
In simple terms, Flash Loans are Unsecured Loans — loans that require no collateral and no authorization based on factors such as credit score, use-cases, and others. In other words, you can get a loan of $10,000,000 without being asked any questions.
Flash Loans work by requiring borrowers to repay the funds in the same transaction where they were borrowed. This might sound impossible, but with DeFi smart contracts a new world of opportunities emerge.
In the case of a Flash Loans a basic transaction consists as a series of contained operations such as the following:
- Borrow a 10,000 ETH Flash Loan
- Exchange the ETH for some DAI on exchange A
- Exchange the DAI for some ETH on exchange B
- Reimburse the Loan+ fee
These operations can be programmed by the user to perform any tasks of their choice. The only rule is that whatever strategy the borrower takes, it must take place in the same transaction where they are borrowed and repaid the funds.
This means anyone can borrow millions of dollars worth of currencies without being required to have any liquidity prior to taking the loan. All the user needs to pay is the gas fee.
Taking it to the Next Level
You might be thinking, “if I have to repay the funds as soon as I borrow them how can I make money?”. The answer is that the use cases are endless but, the three most common options are as follows:
This works similar to traditional arbitrage where the aim is to exploit inconsistencies in token prices between exchanges. For example:
- The exchange rate for ETH/DAI on Exchange A is 1/2000
- The exchange rate for ETH/DAI on Exchange B is 1/2010
Step 1: Borrow 1,000 ETH from Exchange A (a value of 2,000,000 DAI)
Step 2: Exchange the 1,000 ETH for 2,010,000 DAI on Exchange B
Step 3: Exchange the 2,010,000 DAI for 1,005 ETH on Exchange A
Step 4: Reimburse the initial loan with the 1,000 ETH, keeping 5 ETH as profit
This simple scenario would yield a profit of $10,000 (without counting for fees). To perform arbitrage successfully you will need a program which execute trades very quickly to avoid missing the window.
2) Collateral Swaps
Collateral Swapping involves replacing existing collateral positions with the Flash Loan borrowed asset.
Take this hypothetical situation: a borrower is providing collateral to Decentralized Exchange A using token X, but they notice a decline in token X’s price, a Flash Loan on another token Y could be used to swap the collateral and avoid liquidation.
3) Low Transaction Fees
As mentioned above, an intrinsic characteristic of a Flash Loan is that all operations are performed within the same transaction. On blockchains such as Ethereum where transaction fees are extremely high and the gas for a transaction can reach three digits, being able to condense different actions within one optimized transaction can save hundreds if not thousands of dollars worth of fees overall.
Dangers of Flash Loans
While ripe with opportunity , there are many obstacles to creating a successful flash loan.
If you’re not careful, arbitrage opportunities can turn into your worst nightmare if the price begins to fall quickly.
In the race to cashing in on an arbitrage opportunity, someone else might beat you someone else might front-run you and get their transaction confirmed first. In this case you will miss the price window and end up paying a higher price.
By using flash loans at scale, groups can manipulate the oracle price so you they can get a cheaper price for ETH.
A reentrancy attack is where an attacker could put a hidden call in your contract’s callback function and cause damage to your contract.
Flash Loans are amazing financial tool which showcase the power of DeFi, but at the same time can come with high risk so traders should be sure to take small bets and educate themselves before diving in.