Flash Loans: Earning Off Someone Else’s Capital
To borrow tokens in the lending protocol, you usually need to post collateral whose value exceeds the loan amount. Still, there is a complicated way to borrow tokens without collateral, which is to take on a flash loan.
Let’s understand how flash loans work, what they can be used for, and why it’s difficult to take on.
How Flash Loans Work
Bob has a nice car and Alice has an urge to post cool Instagram stories. Bob is willing to let Alice in the car in exchange for her phone number, which is his commission. Little flames on Direct, likes on posts, and new followers are Alice’s profit.
Flash loans work about the same way: the user takes the right amount of tokens from the liquidity pool, uses them, and gives them back in one transaction.
In lending protocols, the borrower always deposits collateral that exceeds the loan amount. It guarantees that the lender won’t lose the funds if the borrower doesn’t repay.
In flash loans, no collateral is needed because the terms guarantee that the borrower will repay the funds and interest during their transaction. This works because the loan is only used if all the terms of the contract are met.
For example, Bob sees that the tez/kUSD rate on QuipuSwap is $1.4 and the rate on Vortex is $1.5. He studies pool liquidity at QuipuSwap and Vortex to find the parameters of the most profitable arbitrage deal, for example, 1,000 kUSD.
Bob creates a smart contract that will combine and consistently execute a complex transaction:
- Take 1,000 kUSD from a pool of flash loans.
- Buy 710 tez with them on Quipuswap.
- Sell 710 tez on Vortex for 1050 kUSD.
- Return 1,000.5 kUSD to the flash loan pool.
In this case, the smart contract will execute the flash loan and move the funds only when all transactions are executed. If there is not enough liquidity in the flash loan pool at the time of processing, or if Bob is left at a loss at the end, the contract will cancel all actions and the transaction will not get to the block. The flash loan protocol will lose nothing, and Bob will only lose commissions for the gas spent.
Flash loans are quite popular. For example, the total volume of loans on the largest such protocol AAVE is $5 billion, with loan amounts ranging from $200 to $1,000 in stabelcoins.
How to Use Flash Loans
Because of the need to use the loan in a single transaction, flash loan opportunities boil down to four cases:
- DEX arbitrage;
- self-liquidation of a synthetic asset or algorithmic stablcoin vault;
- creation of a leveraged position using a synthetic asset or stabelcoin;
- replacement of the collateral currency in the vault.
On Tezos, flash loans are only available on SpicySwap yet — self-liquidation and leverage on youves. We mentioned them in our review of the SalsaDAO ecosystem.
There is some good news, though: last week, a spokesperson for the DeFi protocol Kord.fi announced the launch of flash loans. Most likely, users will be able to borrow tez and tzBTC for arbitrage.
Besides those positive cases, however, flash loans have a downside: borrowed capital can be used to manipulate the prices of internal oracles and steal funds. For example, when attacking PancakeBunny, a hacker used this scheme:
- Borrowed $700 million in BNB and $3 million in USDT.
- Borrowed $3 million in BNB and all USDT into the WBNB-USDT liquidity pool to get LP tokens and the rights for his share of the pool.
- Swapped $697 million in BNB in the pool for USDT so that his LP tokens would represent far more BNB than they should.
- Used LP tokens to mine 7 million native BUNNY tokens worth over $1 billion at the time of the attack.
- Sold most of BUNNY for BNB and USDT.
- Paid off flash loans and ended up with $40 million: $100K in BNB and $700K in BUNNY.
Attacks like this happen more often than you might think. The last occurred as recently as on September 8, when a hacker used flash loans to steal $1.25 million from the Free DAO protocol.
Subscribe and never miss updates from the world of Tezos: