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