prop-amm: add oracle-quoted proprietary AMM example#108
Merged
Conversation
A market-making firm funds a market with its own capital and quotes both sides at the oracle price plus/minus a spread — the Lifinity / SolFi / HumidiFi design that now fills most Solana swap volume via Jupiter routing. No curve, no liquidity providers, no pool shares: the operator is the only capital in the market. Ships all three sibling components: - anchor: two-program workspace (prop-amm + mock-switchboard, following the perpetual-futures template) with five handlers — initialize_market, deposit_inventory, withdraw_inventory (the operator's unconditional exit), set_quote (re-spread or pull quotes), and a permissionless swap priced at oracle +/- spread with pool-favoring rounding, staleness / confidence / slippage / inventory gates, and a post-math assert that output value never exceeds input value at the raw oracle price. LiteSVM tests verify the quote math to the minor unit in both directions ($165 NVDAx/USDC, 10 bps spread, 3.30 USDC round trip) and that every gate shuts. - quasar: port matching the Anchor design and math; quasar-svm pinned to cb7565d because HEAD (sbpf v3) cannot co-resolve with the quasar-lang rev the other examples pin. - kani-proofs: proves the quote brackets the oracle with exact roundings, the buy/sell oracle-value invariant (the swap handler's assert can never fire), and that a round trip never profits the trader. Registered in both kani.yml matrices. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MjDPoqwPYDGnLoMoXsto8r
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.
Adds
finance/prop-amm: an oracle-quoted proprietary AMM — a market-making firm funds a market with its own capital and quotes both sides at the oracle price ± a spread. This is the Lifinity / SolFi / HumidiFi design that now fills most Solana swap volume via Jupiter routing, and it pairs with a new "The Prop AMM" chapter in the book (slotted after The Constant-Product AMM).The teaching contrast with
finance/token-swap: no curve, no liquidity providers, no pool shares (so no inflation attack — there is nothing to dilute), no price impact and nothing to sandwich (the price doesn't depend on the pool's balances). The risks move to stale quotes and adverse selection, which is where the design's oracle gates andset_quotepause live.What's included
anchor/— two-program workspace following the perpetual-futures template (prop-amm+mock-switchboard):initialize_market— pins pair, oracle feed, scale, spread, confidence limit; one market per pair (the deployment is the firm)deposit_inventory/withdraw_inventory— operator-only; withdrawal is unconditional, up to everything, because nobody else has a claimset_quote— re-spread or pull quotes (paused flag)swap— permissionless; ask = ceil(oracle × (1 + spread)), bid = floor(oracle × (1 − spread)), outputs floored (every rounding favors the market); gates for staleness (150 slots), confidence band, slippage minimum, inventory, pause; plus a post-math assert that output value never exceeds input value at the raw oracle pricequasar/— port matching the Anchor design and math, with the feed injected as raw account bytes in tests (perps precedent). Note:quasar-svmis pinned tocb7565d— upstream HEAD (c63afd2, sbpf v3) moved tosolana-program-runtime4.1 /solana-address2.6, which cannot co-resolve with thequasar-langrev all the Quasar examples pin. The existing examples hit the same resolution failure on a freshcargoresolve today; their next CI run against a changed lockfile will too, so the other eight Quasar examples may want the same pin as a follow-up.kani-proofs/— proves the quote brackets the oracle with exact roundings (over- and under-rounding both fail), the buy/sell oracle-value invariant (the swap handler'sInvariantViolatedassert can never fire while the math is intact), and that a round trip never profits the trader. Registered in bothkani.ymlmatrices; plain unit tests pin the same numbers the LiteSVM tests and the book chapter use.Also adds the Prop AMM section to the root README under Financial software.
Testing
cargo check --testsclean (no warnings) for the Anchor workspace;cargo check --testsclean for the Quasar port;cargo testgreen inkani-proofsanchor build && cargo testruns in CI — the SBF toolchain isn't installable in my sandbox (network policy), so CI is the test gate, as with token-fundraiser: let a maker retire a failed raise and raise again #107🤖 Generated with Claude Code
https://claude.ai/code/session_01MjDPoqwPYDGnLoMoXsto8r
Generated by Claude Code