Development of Aave Liquidation Bot
In September 2023, during a sharp market drop, ~$47M in liquidatable positions became available on Aave v3 on Ethereum. Bots that executed liquidations first collectively earned millions in liquidation bonus (5-15% of debt). Bots that sent transactions 200ms later got reverts and only lost gas.
The gap between "succeeded" and "failed" comes from architectural decisions made months in advance.
Liquidation Mechanics in Aave v3
Health Factor and When Position Opens
A position becomes liquidatable when healthFactor < 1. Formula:
HF = Σ(collateral_i * liquidationThreshold_i) / totalDebt
Liquidation threshold depends on asset: 82.5% for ETH, 75% for WBTC, 65% and lower for volatile assets. When HF < 1, anyone can call liquidationCall() and receive the borrower's collateral at a discount equal to the liquidation bonus.
Important Aave v3 nuance: you cannot liquidate more than 50% of debt in one call (close factor = 0.5) if HF > 0.95. If HF drops below 0.95, you can liquidate 100% in one call. This changes profitability: during deep drops, one transaction closes the entire position.
Data Sources on Positions
Three approaches with different latency/completeness trade-offs:
| Source | Latency | Completeness | Best For |
|---|---|---|---|
| The Graph (subgraph) | 15-60 sec | All positions | Background scan |
| Aave API (positions) | 5-30 sec | All positions | Periodic polling |
On-chain getUserAccountData |
~1 block | Specific addresses | Watchlist monitoring |
Borrow event + recalc |
Real-time | New positions | Watchlist addition |
Working architecture: background scan via The Graph to build base of all positions with HF < 1.3 (pre-liquidation watchlist), plus real-time monitoring via WebSocket on Borrow, Repay, LiquidationCall, ReserveDataUpdated events to update watchlist HF.
On price change (event ReserveDataUpdated), recalculate HF for entire watchlist and immediately send transactions for positions where HF dropped below 1.
Critical Implementation Details
Flash Loan for Capital-Efficient Liquidation
Aave liquidationCall requires providing the repaid asset upfront. To liquidate a $500k debt position, you need $500k in the wallet? No. Use flash loan from Aave itself: borrow debtAsset → call liquidationCall → receive collateral at discount → sell part of collateral via Uniswap v3/Paraswap to repay flash loan → keep profit.
All in one atomic transaction. If profit < gas cost, transaction reverts; you only lose gas.
Liquidator contract implements IFlashLoanSimpleReceiver (Aave v3). In executeOperation callback:
- Call
POOL.liquidationCall(collateralAsset, debtAsset, user, debtToCover, receiveAToken) - Verify received collateral amount
- Swap via Uniswap v3 with max slippage 0.5% (otherwise liquidation is unprofitable)
- Return flash loan + fee (0.05% for Aave v3)
Profitability Calculation Before Submission
Sending without pre-calculation is gas waste. Simulate entire liquidation flow via eth_call, get expected collateral output, compute swap output via Uniswap v3 Quoter (quoteExactInputSingle), subtract flash loan fee and gas cost at current baseFee.
Minimum profitability threshold—configurable parameter. Typical: $50-200 minimum profit per transaction, otherwise skip.
MEV and Competition
Liquidations are highly competitive. During volatility, hundreds of bots attack the same positions simultaneously. Without prioritization: MEV sandwich or front-running.
Options:
- Flashbots bundle on Ethereum: transaction goes directly to validator, invisible in mempool. No MEV sandwich but compete by bribe size
- Higher priorityFee: simple and works but expensive during high competition
- Private RPC (bloXroute, MEV Blocker): front-running protection without Flashbots
On Arbitrum and Polygon, Flashbots doesn't work, but latency is lower and competition less—direct transactions with slightly higher gasPrice usually suffice.
Multi-Network Support
Aave v3 is on Ethereum, Polygon, Arbitrum, Optimism, Base, Avalanche, Gnosis, Metis. Each network has its own pool contracts, liquidation rates, competitive environment. Ethereum has max competition but larger position sums. Polygon and Arbitrum have fewer competitors, faster finality.
How We Build the Bot
Liquidator contract (Solidity). Implements IFlashLoanSimpleReceiver, integrated with Uniswap v3 Swap Router. Parametrized: supports multiple DEXs for swaps (fallback from Uniswap to Paraswap if slippage high). Deploy via Foundry with forge script, automatic Etherscan verification.
Off-chain engine (Node.js/TypeScript + viem). Watchlist management, event monitoring, profitability calculation, transaction submission. Config via .env: HF thresholds, minimum profit, supported networks, Flashbots RPC.
Infrastructure. Own node or premium RPC (Alchemy Growth/Business tier) for stable WebSocket. On Ethereum—mandatory; on L2—as needed.
Monitoring. Grafana dashboard: positions scanned, liquidations (successful/failed), P&L daily, gas spent vs profit.
Timeline Estimates
Basic bot for one network (Ethereum or Polygon) with flash loan and Uniswap swap: 1-1.5 weeks. Multi-network with Flashbots, dynamic DEX routing via multiple DEXs, full monitoring: 2-3 weeks. Timeline affected by gas management complexity and infrastructure requirements.
Cost discussed individually after analyzing target networks and desired functionality.







