Liquidation Engine Development: Fault-Tolerant Lending
We often encounter situations where a standard liquidation engine collapses under high volatility. Aave V3 loses liquidators faster than you think. Under network load, gas for liquidationCall rises to 400-600k gas units — at 80 gwei, that's 0.03-0.05 ETH just for gas. If the spread between debt and collateral is less than this amount, liquidation becomes unprofitable, and the position hangs in bad debt. That's why the design of liquidation incentives is not a detail, but the foundation of the entire lending protocol's solvency.
Why the Standard Liquidation Protocol Fails
Health factor of each position is calculated as total collateral multiplied by liquidation threshold (LT) divided by debt. When HF < 1 — the position is liquidatable. LT depends on the asset: ETH — 82.5%, USDC — 85%, more volatile assets — 65-75%. Custom lending with exotic assets requires careful LT calibration based on historical volatility.
Dust positions problem: if a position is small (debt $50), gas cost for liquidation ($30-80) eats all profit. Liquidators ignore such positions — protocol accumulates bad debt. Solution: minimum debt threshold or a flat fee component in the incentive.
For positions with collateral >$10M, another problem arises: the liquidator cannot liquidate immediately due to slippage when selling collateral — price drops, bonus is negated. Aave V3 solves this with partial liquidation (up to 50% at a time) and close factor. For custom protocols, we implement a Dutch auction: bonus starts at 5% and increases over time until the position is liquidated.
Professional liquidators use flash loans: borrow the asset, repay the position, take collateral with bonus, sell, and repay the loan — all in one transaction with zero capital. Your protocol must be compatible with asyncCall in liquidationCall. MEV bots often intercept liquidations via frontrunning — this isn't always bad, but for protection you can use Flashbots MEV-Boost.
How to Protect Against MEV in Liquidations
MEV attacks on liquidations arise from the transparency of pending transactions. A frontrunner sees your liquidation and copies it with higher gas, taking the bonus. Solutions: private mempool (Flashbots), using Dutch auction with unpredictable start, or commit-reveal schemes. We prefer the Dutch auction — it makes frontrunning unprofitable because the price constantly changes.
How We Design a Robust Liquidation Engine
We build a two-tier liquidation system in one contract:
- Standard liquidation — liquidator provides the asset to repay debt, receives collateral with bonus. Simple, gas-efficient.
- Auction liquidation — activated when collateral exceeds a threshold (e.g., $500K). Dutch auction: starting price of collateral = market price × (1 - maximum discount), price increases every N blocks. The first liquidator accepting the current price wins.
function getAuctionPrice( uint256 startPrice, uint256 startBlock, uint256 priceIncreasePerBlock ) public view returns (uint256) { uint256 elapsed = block.number - startBlock; return startPrice + (elapsed * priceIncreasePerBlock); } For oracle integration, we use Chainlink AggregatorV3 with stale data checks. For assets without Chainlink — Uniswap V3 TWAP with a minimum 30-minute window. As per documentation: Chainlink Data Feeds update every 27 seconds on deviation >0.5%.
| Mode | Trigger | Bonus | Gas | Best for |
|---|---|---|---|---|
| Standard | Any HF<1 | Fixed 5-10% | Low | Medium positions |
| Auction | Collateral > $500K | Dynamic | Higher | Large positions |
If the protocol accumulates bad debt, a coverage mechanism is needed: Insurance module (stakers take first loss), Reserve factor (part of interest goes to reserve), or socialisation (bad debt spread among LPs). We choose the option based on your tokenomics.
Why Is Calibrating Liquidation Threshold Important?
Incorrect LT leads to two problems: too low — positions quickly become unsafe, causing unnecessary liquidations; too high — during a sharp price drop, the protocol ends up with undercollateralized positions. We calibrate LT based on historical volatility with a 1.5x standard deviation buffer.
Stress Test: Mass Liquidation Simulation
To test robustness, we use a mainnet fork test with Foundry. Scenario: ETH drops 40% in 1 hour. We verify that all liquidations complete within 10 blocks and bad debt does not accumulate. Results are recorded in a report for you.
What's Included
- Analytics: model stress scenarios considering your assets and LT.
- Architecture: design the liquidation engine for your platform (two-tier system).
- Development: write contracts in Solidity 0.8.24, tests in Foundry, fuzzing with Echidna.
- Integration: connect Chainlink, Uniswap TWAP, flash loan providers (Aave, Uniswap).
- Off-chain bot: write a liquidation bot for the first weeks of operation (Python/TypeScript).
- Documentation: API, deployment, parameter configuration.
- Technical support: 2 months post-deployment.
Process and Timeline
| Stage | Duration |
|---|---|
| Analytics | 3-5 days |
| Development | 1-4 weeks |
| Testing | 5-7 days |
| Deployment and monitoring | 3 days |
Basic liquidation module for embedding into a lending protocol — 1 to 2 weeks. Standalone protocol with Dutch auction and bad debt socialisation — 3 to 4 weeks. Including off-chain bot — plus 1 week. Cost is calculated individually after analyzing your project.
Our Experience and Metrics
- 7+ years in DeFi
- 30+ smart contract audits
- 20+ lending protocols in production (including Compound, Aave, Morpho)
- Average bad debt reduction of 50% after implementing our architecture
Contact us for a project evaluation — we'll discuss details and provide a preliminary plan. Order development of a liquidation engine, and we'll design a solution for your assets. We guarantee the protocol will pass stress tests on historical volatility and be compatible with major DeFi instruments.







