Liquidator Bot Guide
This guide covers everything you need to build and run a profitable liquidation bot for Flux Protocol. Learn how to monitor positions, execute capital-free liquidations, and optimize for maximum profit.
Overview
As a liquidator in Flux, you:
Monitor manager positions for unhealthy health ratios
Execute liquidations when positions become underwater
Profit from liquidations based on strategy-specific pricing logic
Need zero upfront capital thanks to
locked_borrow()Protect the protocol by maintaining vault solvency
Key Innovation: Flux's locked_borrow() enables capital-free liquidations—no flash loans required!
How Liquidations Work in Flux
Liquidation Triggers
A position becomes liquidatable when the strategy's evaluateLiquidation() function returns canLiquidate = true.
The strategy can use any logic to determine this. The standard ImmutableFixedRateStrategy uses:
Health Ratio < Liquidation Threshold
Where:
Health Ratio = Total Position Value / True Debt
Liquidation Threshold = 1 + minBondRatio - liquidationBufferExample with ImmutableFixedRateStrategy:
Manager's collateral: 50K USDC
True debt: 48K USDC
Health ratio: 50K / 48K = 1.042 (104.2%)
Liquidation threshold: 1.1 (110%)
Result: Liquidatable (104.2% < 110%)
Note: Custom strategies can implement different liquidation logic considering liquidity depth, volatility, off-chain data, or other factors beyond simple health ratios.
Liquidation Payment Calculation
Note: The payment calculation is strategy-specific. Each strategy implements evaluateLiquidation() to determine the minPayment. The examples below show how the standard ImmutableFixedRateStrategy calculates liquidation payments, but custom strategies can implement different pricing logic.
Case 1: Healthy Position (Collateral ≥ Debt)
Case 2: Underwater Position (Collateral < Debt)
Example:
Collateral value: 45K USDC (underwater!)
True debt: 50K USDC
Liquidation profit margin: 1%
Liquidator pays: 45K × 0.99 = 44.55K USDC
Liquidator receives: 45K USDC collateral
Liquidator profit: 450 USDC (1%)
Setting Up Your Liquidation Bot
Step 1: Deploy Executor
Liquidators need an executor to handle the callback:
Step 2: Monitor for Liquidatable Positions
Step 3: Estimate Profitability
Executing Liquidations
Capital-Free Liquidation Pattern
The key innovation: use locked_borrow() to liquidate without upfront capital!
Alternative: Flash Loan Liquidation
If you prefer using external flash loans:
Optimizing Liquidation Profits
1. Gas Optimization
2. Swap Optimization
3. MEV Protection
4. Partial Liquidations
For very large positions, liquidate partially to minimize market impact:
Monitoring and Alerting
Real-Time Position Monitoring
Profitability Dashboard
Complete Liquidation Bot Example
Best Practices
1. Always Verify Profitability First
2. Handle Failed Liquidations Gracefully
3. Monitor Gas Prices
4. Keep Detailed Logs
Troubleshooting
Common Issues
Issue: "Position not liquidatable"
Cause: Health ratio still above threshold
Solution: Wait for health to drop further or oracle prices to update
Issue: "Insufficient profit"
Cause: Liquidation margin too low or gas costs too high
Solution: Only target larger positions or wait for better gas prices
Issue: "Transaction reverted"
Cause: Position already liquidated or health improved
Solution: Check position status before executing
Issue: "Swap slippage too high"
Cause: Low liquidity for seized collateral
Solution: Use DEX aggregators or split swaps
Read More
Last updated