The overall design of liquidation bot

Overall Design Flowchart

Fig 1.Overview


  • Accounts

    • A0A_0 : Account 0, which is liquidator's account that calls the liquidation bot. We are using DeFi lending account here.

    • A1A_1 : Account 0, which is the trading account that help trade on trading venues.

  • Prices:

    • P0P_0 : The price of collateral on chainlink oracle from DeFiner's protocol.

    • P1P_1 : Liquidation price, which is 0.95×P00.95\times{P_0}

    • P2P_2 : The price of the collateral on trading venue.


Step A: Monitoring

  • The liquidator bot pull liquidatable account(s) from DeFiner's protocols.

  • The liquidator bot pull liquidation price forom DeFiner's protocols.

  • The liquidator bot get price of collateral on trading venue.

  • If P2/P11.01P_2 / P_1 \ge 1.01 ,which means potentially profitable, goes to Step B, otherwise stop here.

Step B: Execution on DeFi Lending

  • Liquidation bot calls smart contract to liquidate .

  • A0A_0 should receive X asset at P1P_1 .

  • After confirmation, goes to Step C.

Step C: Execution on Trading Venue

  • There are two options of trading venues:

    • C1C_1 : Execution on centralized exchanges.

    • C2C_2 : Execution on DeFi exchanges.

  • We choose C1C_1 currently.

  • Liquidator bot signals to A1A_1 execute a sell order to sell X asset at P2P_2

  • Now A1A_1 has X-X asset, XP2XP_2 USD.

Step D: Rebalance

  • When A0A_0 accumulate asset to a certain amount, the liquidator bot triggers rebalance.

  • A0A_0 transfer XX asset to A1A_1. Now A0A_0 has 0 asset, XP1-XP_1 USD. A1A_1 has XX asset, assest X-X short position and XP2XP_2 USD.

Step E: Close Position

  • Liquidator bot signals to sell X asset and close short position.

  • A1A_1 transfers the money XP2XP_2 to A0A_0.

  • A0A_0 now has X×(P2P1)X\times (P_2 - P_1) USD.