Flash Loan Arbitrage Bot
A flash loan arbitrage bot borrows uncollateralized capital from a DeFi lending protocol, executes a multi-step arbitrage path, and repays the loan plus fee — all inside a single Ethereum transaction. If the arbitrage doesn't profit, the entire transaction reverts and the loan is undone. This makes flash loans the most powerful tool in DeFi MEV: zero-capital, zero-risk, atomic. Aave V3 is the most-used flash loan provider on Ethereum mainnet (0.05% fee), with Balancer V2 offering fee-free flash loans for the major assets and Uniswap V3 supporting flash swaps for in-pool arbitrage. Production flash loan arbitrage bots can borrow $1–10 million per opportunity and execute a 3–6 leg path through Uniswap, Curve, and Balancer in a single 300k–600k gas transaction.
Flash loans are a subset of crypto arbitrage strategies, made possible by Ethereum's atomicity guarantee. This guide covers Aave flash loans, Balancer's fee-free flash loans, Uniswap V3 flash swaps, and the smart-contract patterns production bots use.
- What is a flash loan?
- Aave flash loans
- Balancer flash loans (fee-free)
- Uniswap V3 flash swaps
- How to build a flash loan arbitrage bot
- Flash loan vs capital-based arbitrage
What is a flash loan?
A flash loan is an uncollateralized loan that must be borrowed and repaid in the same transaction. The lender sends you funds; you execute arbitrary logic; you repay the funds plus a small fee. If you don't repay by the end of the transaction, the entire transaction reverts as if it never happened — including the original transfer. The lender takes no credit risk because reversion is atomic.
Flash loans were introduced by Aave in early 2020 and are now offered by Aave V3, Balancer V2, dYdX (now sunset), Maker DSS, Euler (now in receivership), and the Uniswap V3 protocol via flash swaps. They unlock arbitrage opportunities that would otherwise require millions in working capital.
Aave flash loans
Aave V3 is the most-used flash loan provider on Ethereum mainnet. The protocol charges a 0.05% fee on the borrowed amount. Your contract calls pool.flashLoan(receiver, asset, amount, params); Aave transfers the asset to your contract; your contract's executeOperation callback runs your arbitrage logic; finally Aave pulls back the principal + fee.
Aave supports multi-asset flash loans (borrow several assets in one call) and very large notional sizes. The 0.05% fee adds up — on a $1M flash loan, the arbitrage spread must exceed $500 to net any profit.
Balancer flash loans (fee-free)
Balancer V2 offers flash loans with zero fee. This is why most production MEV arbitrage bots route their flash loans through Balancer when possible. The interface is similar to Aave: call vault.flashLoan(recipient, tokens, amounts, userData), implement receiveFlashLoan, repay before the call returns.
The trade-off: Balancer's Vault holds smaller amounts of less-common tokens than Aave does. For WETH, USDC, USDT, WBTC, DAI — Balancer almost always has enough liquidity. For long-tail tokens, you may need Aave or Uniswap V3 flash swaps instead.
Uniswap V3 flash swaps
Uniswap V3 doesn't offer flash loans directly, but it offers something nearly equivalent: flash swaps. You can call swap() on a pool with arbitrary data; the pool transfers the output tokens to your contract first, then calls your uniswapV3SwapCallback; you have until the callback returns to deposit the input tokens. This is effectively a same-pool flash loan: borrow token X from the pool, execute arbitrary logic, repay token X (or its equivalent in token Y, given the pool's price). Production arbitrage bots use Uniswap V3 flash swaps for path-internal flash loans where the arbitrage starts and ends in the same pool.
How to build a flash loan arbitrage bot
At the smart-contract layer, a flash loan arbitrage bot needs three components:
- An entry contract that the off-chain bot calls — it triggers the flash loan and sets up the path.
- A callback handler that receives the flash-loaned funds and executes the multi-hop swap path through the relevant DEX routers (Uniswap V2, Uniswap V3 SwapRouter02, Curve, Balancer Vault.swap, SushiSwap RouterProcessor3).
- A profit check + repayment step that verifies the path returned more than the loan + fee, then transfers the principal back to the lender. If the check fails, revert.
The off-chain bot does the heavy lifting: monitoring pool states, computing optimal paths via Bellman-Ford or SPFA, sizing the loan, and submitting bundles to block builders. The on-chain contract is intentionally minimal — every byte of bytecode adds gas. A well-optimized flash-loan arbitrage transaction on Ethereum is typically 300k–600k gas. See the build a MEV bot guide for the full stack.
Flash loan vs capital-based arbitrage
Capital-based arbitrage holds inventory: stable balances of WETH, USDC, WBTC across DEXs and CEXs that the bot can use to capture opportunities instantly. Flash-loan arbitrage holds zero inventory and borrows fresh capital per opportunity. The trade-off: capital-based arbitrage is faster (no flash-loan callback overhead) but requires millions in working capital; flash-loan arbitrage is slightly slower per transaction but scales without capital. Production operators usually run both — flash loans for opportunistic large arbs, capital-based for the highest-frequency steady opportunities. The reference deployment behind MevLex combines both.
Further reading and references
- Aave flash loan documentation — Official Aave V3 flash loan integration guide — the dominant flash-loan provider for MEV bots.
- Balancer flash loans — Fee-free flash loans from Balancer V2, used by sophisticated arb bots when Aave fees would erase the spread.
- Paradigm flash loan research — Famous "dark forest" essay framing the bot-vs-human MEV landscape.
- Uniswap V3 flash swap docs — Reference for using Uniswap V3 pools as a 0.3%-fee flash-loan source inside an arbitrage callback.
- dYdX protocol architecture (historical) — dYdX V3 introduced the original 0%-fee flash loan in DeFi; now sunset on Ethereum but historically the cheapest source of flash capital.
On-chain arbitrage — funded from its own capital (zero flash-loan fees) or flash loans (zero capital at risk), whichever nets more — runs from managed low-latency infrastructure, every trade settling on-chain and independently verifiable. Backed by a 30-day money-back guarantee.
See plans →