Replace reserve-and-cap with haircut risk model in perpetual futures#83
Open
mikemaccana wants to merge 1 commit into
Open
Replace reserve-and-cap with haircut risk model in perpetual futures#83mikemaccana wants to merge 1 commit into
mikemaccana wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
reserved_liquidityfield and all up-front reserve accountingreserved + size > liquidityHaircut Mechanism:
haircut_ratio()function that computesh = min(1, backing / liability)where:backing = liquidity + insurance_fundliability = max(0, traders' aggregate unrealized profit)h < 1, every closing winner is paid the same fraction of their profit, preventing selective defaultshrises automatically without governance interventionProfit Maturation Gate:
profit_warmup_slotsparameter to prevent oracle-spike arbitragecurrent_slot >= entry_slot + profit_warmup_slotsclose_positionbefore haircut is computedInsurance Fund:
insurance_fundfieldinsurance_fee_bpsparameter: fraction of every open/close fee routed to insuranceFee Splitting:
split_fee()helper to divide fees between insurance fund and protocol feesState Changes:
Pool: removedreserved_liquidity, addedinsurance_fundandprofit_warmup_slotsPosition: addedentry_slotto track when profit maturation window beganPoolParameters: addedinsurance_fee_bpsandprofit_warmup_slotsfieldsImplementation Details
Testing
Added 8 new tests covering:
https://claude.ai/code/session_012D5CfmXC1Ztae1NMrD7Yrm