Flash Loans Explained: Real Use Cases for DeFi Arbitrage and Liquidations
Imagine borrowing $10 million to buy a house, flipping it for profit, and paying back the loan-all before your neighbor finishes their morning coffee. That sounds like magic, but in Decentralized Finance (DeFi), it’s just Tuesday. This is the power of flash loans. They are uncollateralized loans that must be borrowed and repaid within the same blockchain transaction. If you can’t pay them back by the time the block closes, the entire transaction reverts as if it never happened.
First introduced by Aave in February 2020, flash loans have processed over $15 billion in volume across Ethereum, Polygon, and Avalanche. But why would anyone need this? It’s not about holding cash; it’s about leveraging temporary capital to exploit inefficiencies, fix broken positions, or execute complex trades without risking your own money upfront. Let’s break down exactly how people use these financial primitives today.
Arbitrage: Exploiting Price Discrepancies
The most common legitimate use case for flash loans is arbitrage. In traditional finance, arbitrage requires significant capital because you need to buy an asset on one exchange and sell it on another simultaneously. With flash loans, you don’t need your own capital. You borrow the asset from a lending pool, buy it cheap on Exchange A, sell it high on Exchange B, repay the loan plus a tiny fee, and keep the difference.
For example, if WETH is trading at $2,000 on Uniswap but $2,010 on Balancer, a bot can borrow WETH, swap it on Uniswap, then swap the proceeds on Balancer to get more WETH than it started with. After repaying the loan and fees, the surplus is pure profit. According to Nansen data, stablecoins like DAI and USDC dominate these transactions, accounting for nearly 70% of all flash loan activity due to their price stability reducing risk.
Liquidations: Keeping Protocols Solvent
DeFi lending platforms like Compound and Aave require borrowers to post collateral. If the value of that collateral drops too low, the position becomes undercollateralized and must be liquidated. This is where flash loans shine. A liquidator doesn’t need to hold huge reserves of the collateral token. Instead, they borrow the debt token via a flash loan, repay the borrower’s debt, receive the discounted collateral as a reward, sell the collateral on the open market, and repay the flash loan.
This mechanism ensures protocols remain solvent even during volatile market crashes. Stani Kulechov, founder of Aave, noted in 2023 that 26% of all flash loans on his protocol were used for liquidations. Without flash loans, only whales with massive capital could perform these duties, leading to slower liquidations and potential bad debt for lenders. Flash loans democratize this role, allowing any developer with a smart contract to compete for liquidation rewards.
Self-Liquidation: Saving Your Own Position
Sometimes, you’re the one who needs to be liquidated. Maybe you took out a loan against ETH, and ETH’s price crashed. Rather than letting a third-party liquidator take your collateral at a steep discount, you can use a flash loan to save yourself. You borrow enough funds to repay your original debt, withdraw your full collateral, swap part of it to repay the flash loan, and keep the rest.
This strategy avoids the liquidation penalty, which can range from 5% to 10%. For large positions, saving that percentage is worth the gas fees and flash loan fee (typically 0.09% on Aave). It’s a self-service safety net that gives users control over their financial destiny in a permissionless system.
Cross-Chain Swaps and Collateral Swapping
As DeFi expands beyond Ethereum to Layer 2s like Arbitrum and Optimism, moving assets between chains has become a bottleneck. Flash loans facilitate cross-chain swaps by acting as the bridge’s liquidity source. A user can initiate a swap on Chain A, use a flash loan to provide immediate liquidity on Chain B, and settle the final balance once the bridge confirms the transfer. This reduces wait times from minutes to seconds.
Similarly, collateral swapping allows users to change their collateral type without closing their loan. If you’re worried about BTC volatility but want to keep your USDC loan open, you can use a flash loan to swap your WBTC collateral for USDC, repay the flash loan, and instantly update your collateral profile. This flexibility was impossible in traditional banking without closing and reopening credit lines.
| Protocol | Fee Structure | Key Feature | Market Share (Q2 2024) |
|---|---|---|---|
| Aave V3 | 0.09% | Isolated pools, multi-chain support | 62.3% |
| Balancer V2 | 0.30% | Balanced pools, customizable weights | 21.7% |
| Uniswap V3 | Variable (swap fee) | Flash swaps (withdraw first, pay later) | 16.0% |
The Risks: When Flash Loans Go Wrong
It’s not all profit. Flash loans are also the weapon of choice for attackers. Because they allow instant access to massive liquidity, malicious actors can manipulate oracle prices or exploit smart contract vulnerabilities. The infamous Harvest Finance hack in October 2020, which cost $30 million, was largely driven by flash loan attacks that manipulated yield strategies.
OpenZeppelin’s 2024 Threat Report highlights that flash loan attacks account for 34% of all DeFi exploits. The danger lies in "oracle manipulation." If a protocol relies on a single spot price from a small DEX, an attacker can use a flash loan to buy up all the liquidity in that pool, skewing the price, triggering a false liquidation or minting event, and then selling off the assets-all in one transaction. This is why modern protocols now use Time-Weighted Average Prices (TWAP) or multiple oracles to mitigate these risks.
Getting Started: Technical Requirements
You can’t click a button to get a flash loan; you need code. Implementing one requires writing a smart contract in Solidity that inherits from the protocol’s interface (like `IFlashLoanReceiver` for Aave). You must implement the `executeOperation` function, which defines what happens between borrowing and repaying.
Most successful operators spend 3-6 months learning Solidity and DeFi mechanics before their first profitable run. Tools like Tenderly help simulate transactions to catch errors before spending real gas. Remember, if your logic fails, the transaction reverts, but you still pay the gas fee. During Ethereum congestion, failed attempts can cost $10-$30 each, so testing on testnets like Sepolia is non-negotiable.
Do I need my own money to start using flash loans?
No, you do not need collateral or upfront capital for the loan itself. However, you do need enough ETH in your wallet to cover the gas fees for the transaction. If the transaction fails, you lose the gas fee, but you don't lose principal.
What is the typical fee for a flash loan?
Fees vary by protocol. Aave charges 0.09%, while Balancer charges 0.3%. Uniswap uses its standard swap fee structure. These fees are deducted from the profit generated by the operation, so your arbitrage spread must exceed the sum of the flash loan fee and gas costs.
Can flash loans be used on Layer 2 networks?
Yes. Major protocols like Aave and Balancer have deployed on Layer 2 solutions such as Arbitrum, Optimism, and Polygon. Using L2s significantly reduces gas costs, making smaller arbitrage opportunities profitable compared to Ethereum mainnet.
Why did the Harvest Finance hack happen?
The attacker used flash loans to manipulate the price of yUSD tokens on Curve Finance. By skewing the spot price, they forced the protocol to issue shares at an incorrect valuation, draining $30 million in assets. This highlighted the risk of relying on manipulable spot prices for critical operations.
Are flash loans legal?
Regulatory frameworks are evolving. In the EU, MiCA regulations classify flash loans as crypto-asset service activities requiring licensing. In the US, the SEC has scrutinized specific implementations, but generally, they are viewed as technical tools rather than securities themselves, provided they don't involve investment contracts.