Skip to content

Liquidator service: perplex-cli risk subcommand #151

@ozpool

Description

@ozpool

Problem

Under-collateralised positions sit on the edge with no path to forced close. The whole risk side of the exchange is missing — losses past collateral cannot be socialised, and there's no incentive payout to keep the system solvent.

Proposal

New subcommand on perplex-cli:

perplex-cli risk --edge-url ... --account 0x... --bearer $JWT

Per block (anvil tick / Sepolia block):

  • Pull every open position from the edge (/v1/positions/all — new internal endpoint, gated by an admin JWT claim).
  • For each, compute health factor = (collateral + unrealised PnL) / (notional * mmRatioBps / 10000).
  • If health < 1, submit a reduce-only IOC market order on behalf of the liquidator wallet, marked liquidation: true.
  • On-chain: pay liqBonusBps of notional from the closed position's collateral to the liquidator's address.

Acceptance

  • perplex-cli risk runs continuously, logs every health check.
  • At least one E2E test: open a position at 20x → push the oracle the wrong way (MockSource) → confirm position is closed automatically and liquidator wallet receives the bonus.
  • Metrics on :9101 (or similar) — positions scanned per block, liquidations triggered, bonus paid in USDC.

Notes

This is the biggest remaining production-blocker. Until it ships, a wallet with a busted position can hold a stale entry forever and erode the vault.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions