Skip to main content
When a position’s losses eat too far into its collateral, it has to be closed out before those losses could exceed what’s actually backing it. This process is called liquidation, and on Perpetra it always runs through the same dedicated system, kept separate from everything else so it can be verified and reasoned about on its own. Only approved keeper bots, see Keeper System, are allowed to trigger a liquidation.

Isolated positions vs. cross positions

The two margin modes are liquidated differently:
  • Isolated positions are liquidated one at a time, or in a batch where each one is handled independently.
  • Cross positions are liquidated as a whole. If any position in a trader’s cross-margined book for a given token needs liquidating, the entire book for that token is closed out together, not one position at a time. This is deliberate, positions in the same cross book share the same collateral, so they have to be resolved as a set to be accurate.

How a single liquidation works

Before anything is settled, the position’s health is checked again using the current price, a stale or already-healthy position is rejected rather than closed. Once confirmed, the position is settled: any funding owed, the keeper’s fee, and the position’s profit or loss are all accounted for, and whatever collateral remains goes back to the trader. The keeper is always paid their full fee one way or another. If the position’s own collateral covers it, that’s where it comes from. If it falls short, or there’s nothing left at all, the Insurance Fund covers the difference, or the whole fee.

Liquidating in bulk

A keeper can submit a batch of positions to check at once. Each one is handled independently, if one turns out to be healthy or invalid, it’s simply skipped and the rest of the batch still goes through. One bad entry in a batch doesn’t block the others.

Cross-book liquidation

When an entire cross-margined book needs to be liquidated, the keeper has to include every open position in that book for that collateral token, not a hand-picked subset. This prevents a keeper from strategically leaving out a healthy position that would otherwise offset the unhealthy ones and change the outcome. The whole book is then settled together: profit, loss, and funding across every position are combined into one total, and the same “keeper gets paid, leftover to trader, Insurance Fund tops up if needed” logic runs once against that combined total, rather than position by position.

Checking before it happens

Before ever attempting a real liquidation, a keeper can check whether a position currently qualifies, cheaply and without spending any real transaction cost. This lets bots avoid wasting effort on positions that are actually healthy.