Skip to content

feat(perps): add a perpetuals exchange example app - #123

Draft
kyscott18 wants to merge 2 commits into
mainfrom
feat/perps-app
Draft

kyscott18 wants to merge 2 commits into
mainfrom
feat/perps-app

Conversation

@kyscott18

Copy link
Copy Markdown
Collaborator

Adds apps/perps: a cross-margin perpetuals exchange with one collateral. It has a FIFO price-time order book per market, an oracle and funding index the admin pushes, deposits the admin attests, and an inline liquidator in the API server. There's no frontend yet.

Mutations (11): SetAdmin, AddMarket, UpdateMarket, SetOraclePrices, AccrueFunding, Deposit, Liquidate are admin-only. CancelOrder, LimitOrder (post-only), MarketOrder (fill-or-kill), Withdrawal are for users. The model and API are in apps/perps/README.md.

Typewriter gaps: apps/perps/TYPEWRITER_GAPS.md. The biggest one: liquidations can only land in the batch after the price move.

Verification

  • forge test: 15 tests (matching priority, PnL and value conservation, funding, margin, reduce-only, self-trade, liquidation, bad debt).
  • tsc and biome are clean. forge fmt --check is clean. forge lint gives warnings only, as order-book does.
  • bun dev boots: the parser and determinism check pass, then the admin claims the seat, markets are listed, and the maker, oracle, and funding loops start.
  • scripts/liquidation.ts against the dev server: a ~9.3x BTC long, then an 8% oracle drop. The liquidator closed all 1203 lots in the next batch.
  • A manual API run hit each revert path: a non-admin Deposit/SetAdmin (NotAdmin), a crossing limit order (WouldCross), withdrawing too much (InsufficientCollateral), and withdrawing while an order rests (InsufficientMargin). Cancel followed by a full withdrawal succeeded.

🤖 Generated with Claude Code

kyscott18 and others added 2 commits November 2, 2026 21:58
Cross-margin perps with one collateral: a price-time order book per
market, an admin-pushed oracle and funding index, admin-attested
deposits, and liquidations the server submits after every accepted
batch. TYPEWRITER_GAPS.md records where Typewriter forced those
choices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…quote interval

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant