Skip to main content

Position Liquidation

Once a position has been opened in the DomFiPerp contract, we immediately begin monitoring the position's PnL percent to ensure that losses do not exceed the exchange's liquidation threshold. Note that this PnL includes the cost of funding.

Operation

The liquidation bot will perform an "update cycle" each time that a relevant perpetual exchange event is emitted on-chain -- in this case PriceUpdate events.

On each update cycle,

  1. All exchange EVM events since the last update cycle block number are imported into the database via the Query Engine.
  2. The liquidation bot identifies all open positions on the exchange. This query runs locally.
  3. We compute the current PnL of all open positions, flagging any that exceed the exchange's liquidation threshold.
  4. One or more liquidatePositions transactions are submitted for all positions flagged for liquidation.