robotBuilding Liquidation Bots

Building Liquidation Bots on Fervent Finance

This page provides an overview for developers on how to interact with Fervent Finance smart contracts to detect and execute liquidations and calculate potential profits.

Understanding Liquidations

In Fervent Finance :

  • Borrowers maintain a health factor determined by the value of their collateral vs. borrowed assets.

  • If a borrower's health factor drops below 1, their position becomes liquidatable.

  • Liquidators can repay a portion of the borrower's debt in exchange for seizing collateral plus a liquidation incentive.

Finding Borrowers and Checking Liquidatability

1. Identify Borrowers

  • Event-based approach (on-chain): Listen to Borrow and Repay events from each cToken contract. Each event contains the borrower’s address.

// Example: Fetch past borrow events
const borrowEvents = await cToken.queryFilter(cToken.filters.Borrow());
const borrowers = [...new Set(borrowEvents.map(e => e.args.borrower))];
  • Off-chain/indexed approach: Use a subgraph or database tracking all borrowers per market. This is faster for large-scale monitoring.

2. Check if Borrowers are Liquidatable

Once you have a list of borrowers, call getAccountLiquidity for each one:

Notes:

  • Using getAccountLiquidity handles multiple borrowed assets and price updates automatically.

  • It’s more reliable than manually calculating health factors.

  • For efficiency, you can batch requests or filter borrowers using an off-chain index.

3. Executing Liquidations

Once a borrower is liquidatable, call liquidateBorrow on the relevant cToken:

  • Important:

    • Fervent Finance provides an 8% liquidation bonus.

    • Always factor in gas fees and maximum repayable amounts.

4. Calculating Profit

The profit from a liquidation comes from the seized collateral plus the 8% bonus, minus the debt repaid and gas costs:

  • Tips for maximizing profit:

    • Target borrowers with high collateral-to-debt ratios.

    • Consider market prices and slippage.

    • Monitor multiple borrowers to catch opportunities early.

Workflow Summary

  1. Fetch borrowers from borrow events or an indexer.

  2. Check liquidity using getAccountLiquidity.

  3. Liquidate positions that have shortfalls.

  4. Calculate profits using collateral seized and liquidation reward.

Example

Last updated