REAL LIFE Profitable Flashloan examples

Investment Rookie
25 followers
5 Video Views·Oct 28, 2022
In case you haven't noticed yet, everybody in crypto is obsessed by flash loans.
In Telegram groups, on Twitter, in the comments on YouTube, people ask,
how can I make my own flash loans? Flash loans allow you to borrow a lot of money on the
blockchain but without providing any collateral. If you combine this free money with an arbitrage
strategy, you can make some real profit. Really? Can you really make some profit
with flash loans? Or is it just some bullshit? Yes, you can absolutely make some profit with
flash loans and in this video, I will show you three examples of real-life flash loans that
actually happen on Ethereum. The profits of these flash loans range from just a few bucks
to 1 million dollars. So let's start with the first flash loan. The first flash loan happened
at the beginning of January 2020 and was done by a spot contract called Arbitrage DAO. It only made
$5.45 of profit but it did prove that it was possible to make profits with flash loans.
So let's see how it worked. You are probably familiar with DAI, the stablecoin of MakerDAO.
What you might not know is that there are two different versions of DAI token. So there is
DAI, the multi-collateral stablecoin, and SAI, the single collateral stablecoin, which is the old
version of DAI. Both DAI and SAI are supposed to always be equal to one dollar. But in January,
someone spotted a temporary difference in price. SAI was abnormally more expensive than DAI.
So here is what happened. First, DAI was borrowed with a flash loan on Aave. Then,
DAI was converted to SAI by using the migration smart contract of MakerDAO. So that will get you
one SAI for one DAI. Then, SAI was sold against DAI on Uniswap. If you don't know Uniswap,
that's a decentralized exchange for ERC20 tokens. Because there was a price mismatch between SAI
and DAI, they received more DAI than the number of SAI tokens that they initially sent. Then,
DAI was reimbursed to the Aave flash loan and they kept the extra DAI returned by Uniswap.
So that's an example of a simple flash loan. But can we make more money than just a few bucks?
Yes, we can. And that's what I'm going to show you in our next flash loan example.
The flash loan I'm about to show you made $716 of profits and was made by Instadap. If you don't
know Instadap, that's an all-in-one tool to manage all your DeFi investments at the same place.
In this flash loan, we will take advantage of a mismatch between two stablecoins,
DAI and USDC. Normally, both of them are supposed to always equal $1. But at one point,
USDC was priced higher. So in this flash loan arbitrage, first DAI was borrowed with a flash
loan provided by Instadap. Then, DAI was converted to USDC by using Oasis, which is a decentralized
exchange of MakerDAO. At this point, the dollar value of the USDC tokens was higher than the
dollar value of the DAI token provided in Input. Then a new MakerVault was opened. A vault is how
you create new DAI tokens by locking some collateral in the MakerDAO system. Then all
the USDC coming from Oasis was locked in the MakerVault. Then DAI was drawn from this vault.
Then using this DAI, the flash loan was repaid. In the end, we are left with the MakerVault.
The collateral locked in the MakerVault minus the debt is higher than the capital that we started
with, which gives us a profit of about 700 USD. But there was some controversy about this because
the trade is actually not finished to actually realize the profit the team of Instadap needed
to liquidate the vault and sell the USDC and hope that at that time the price of USDC would still be
higher than the price of DAI. But this is not a guarantee. A real flash loan arbitrage is supposed
to be atomic, inside a single transaction, so that there is no risk. Either all the steps are
executed at once or none of them is executed. 700 dollars profit is cool but can we do even
better than this? Yes, we can. The total profit of the flash loan I'm about to show you is 1 million
dollars. Yes, you heard well, 1 million dollars. But that's not really a flash loan arbitrage.
That's actually a flash loan hack. The people who did this took advantage of a flaw in a smart
contract. Yes, some of you may have guessed I'm of course talking of the hack of the BZX protocol
that happened in February 2020. There was actually two different flash loan hacks. The first one that
made 350,000 dollars and another one a few days later that made about 700,000 dollars.
And I'm going to focus on the first one. The first step was to borrow a lot of ether from the flash
loan of DYDX. DYDX is an advanced decentralized exchange but for this attack all that matters is
that it provides a flash loan API. Then about half of this money was sent to Compound. Compound is a
lending platform to borrow or lend ether or ETH20 tokens. The ETH that was sent to Compound was used
as a collateral to borrow WRAPBTC or WBTC. WBTC is an ETH20 token that tracks the value of Bitcoin.
Part of the remaining ETH was sent as a collateral to the BZX protocol. BZX is a margin trading
platform. It allows you to go long or short for certain crypto assets with a leverage. With the
ETH collateral, a short leverage position was opened where ETH was short against WRAPBTC.
So this was actually a leverage long position on WRAPBTC. Behind the hood, BZX executed this
trade on CaboSwap which itself executed this on Uniswap. As a consequence of this big leverage
position on WRAPBTC the price of WRAPBTC increased a lot on Uniswap. Then the WRAPBTC
that was borrowed from Compound was sold against ETH on Uniswap at an inflated price.
With this ETH, it was more than enough to repay the flash loan on DYDX. In the end, the attacker
has some surplus coming from the sale of WRAPBTC on Uniswap and also coming from the unused portion
of the DYDX flash loan. And who was left holding the bag? The BZX protocol who now had an
undercollateralized position. What's interesting to learn from this is that a flash loan can be
quite complex and a lot of the more profitable opportunities might be hidden below a lot of
indirections. But you should keep in mind that what I explained to you is a hack, not a fair use
of flash loan. So exercise your judgment wisely before you do something harmful. So after seeing
all these profitable flash loans, you probably start to think what about me? Can I do my own
profitable flash loan arbitrage? Yes you can! Doing your own profitable flash loan arbitrage is
possible but this is not always easy. You need to be well prepared so that when an arbitrage
opportunity strikes, you can jump on it right away and be the first one to trade. And for that, you
will need to put your hand in the code of Solidity Smart Contracts. And to learn how to do that,
go register for my free training on flash loans. I'll see you there!
