Core idea

The pvpAMM is a single-collateral perpetual pool. Traders open leveraged long and short positions against a shared collateral base, and liquidity providers (LPs) back that base. Economically the LP pool is the counterparty — trader profit is paid out of pool collateral and trader loss accrues to the pool. It is not a trader-versus-trader game with LPs merely standing aside. The pool stays solvent through psi (ψ), a pool-level wealth-adjustment multiplier that is always ≥ 1. Both trader payouts and LP redemption are scaled by the same live psi, so the pool can never pay out more than its collateral base:
  • A trader’s settled value is psi-adjusted worth: worthAdj = worthRaw * psiAtOpen / psiNow, and any payout is capped at totalActiveCollateral.
  • An LP’s redemption is fair value: mpsiReduction / psi.
When the aggregate claims of open positions would otherwise exceed the pool’s available collateral, psi rises above 1 and scales those claims down so the pool stays solvent; LPs absorb the difference (and earn fees, plus optional funding, in return). psi is recomputed live from pool state, so it also falls back toward 1 as claims shrink.

Main pieces

  • Positions store collateral, leverage, direction, entry price, psi-at-open, and exposure. A position can be Separate or Full margin (and the cross-margin variants CrossSeparate/CrossFull via a margin-account factory).
  • Liquidity lots store pool shares and optional fee-pool participation; an existing lot can be grown with addLiquidityTo. Pool shares are an LP accounting/mint unit (poolSharePrice = totalActiveCollateral / totalPoolShares); they are not how trader positions are valued.
  • psi (ψ) is recomputed from the aggregate position and LP terms on every state-changing call.
  • Optional funding: when enabled, traders pay a utilization/skew-based funding charge that accrues into the LP fair-value bucket. It is checkpointed lazily and can be poked with accrueFunding.

Lifecycle

  1. Open a position (openPosition) or add liquidity (addLiquidity / addLiquidityTo).
  2. psi is recomputed as the oracle price moves and as funding accrues.
  3. Preview a close for payout bounds, then close (closePosition) or liquidate. Liquidation is permissionless once a position’s health ratio falls below the market’s liquidation threshold.
  4. For ordinary (non-cross-margin) close/liquidation, the net payout is escrowed to pendingSettlementCollateral; withdraw it with claimSettlement. Cross-margin closes settle straight into the margin account.
  5. Remove liquidity (removeLiquidity) to exit the pool at current fair value.

Read more