Replace the reserve-and-cap risk model in both the Anchor and Quasar
implementations with the haircut model from Percolator
(github.com/aeyakovenko/percolator):
- Profit is a junior claim. Positions open with no up-front reserve and
no open-interest cap; profit runs uncapped. Solvency is held at exit by
a global haircut ratio h that scales every winner's profit to the
backing the pool can cover, the same fraction for all. Removes
Pool.reserved_liquidity and the per-position profit cap; provider
withdrawals are gated by the profit traders are currently owed.
- Profit maturation: positions carry entry_slot and cannot be closed in
profit until profit_warmup_slots elapse (oracle-manipulation defense).
Loss is never gated.
- Insurance fund: funded by an insurance_fee_bps cut of each fee, absorbs
bankruptcy deficits before liquidity providers, and counts as backing
in the haircut.
Both implementations build to SBF and pass their LiteSVM tests (29 Anchor,
20 Quasar), including new haircut, maturation, withdrawal-guard, and
insurance-fund cases. READMEs, TERMINOLOGY, and CHANGELOG document the
model and why Percolator's peer-to-peer A/K overhang indices do not map
onto a single-counterparty pool.
Summary
This PR replaces the reserve-and-cap risk model with the haircut model adapted from Percolator in both the Anchor and Quasar perpetual futures implementations. The key insight: trader profit is a junior claim backed by liquidity-provider capital and an insurance fund, not a capped reserve.
Key Changes
Risk Model Overhaul:
Haircut Mechanism:
Profit Maturation Gate:
Insurance Fund:
Fee Splitting:
State Changes:
Implementation Details
Testing
Added 8 new tests covering:
https://claude.ai/code/session_012D5CfmXC1Ztae1NMrD7Yrm