Skip to content

Add Quasar port of the order-book (CLOB) example#96

Open
mikemaccana wants to merge 1 commit into
mainfrom
claude/quasar-solana-orderbook-port-4mcr6j
Open

Add Quasar port of the order-book (CLOB) example#96
mikemaccana wants to merge 1 commit into
mainfrom
claude/quasar-solana-orderbook-port-4mcr6j

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Ports finance/order-book/anchor to Quasar under finance/order-book/quasar, alongside the existing Quasar examples. Both builds share the same program ID (C69UJ8irfmHq5ysyLek7FKApHR86FBeupiz4JnoyPzzx), so clients and PDA derivations work against either unchanged.

What's preserved

The trading logic, fee model, two-lot pricing, and the OpenBook-derived critbit matching engine are faithful to the Anchor build. A side-by-side review confirmed the fee/lock/rebate/cancel arithmetic and the Bid/Ask fill-credit branches are identical.

Quasar-specific adaptations

Quasar is zero-copy, no_std, and zero-allocation, so a few things differ by necessity:

  • Order book (~180 KB, two zero-copy slabs) is accessed by casting the raw account bytes with bytemuck — Quasar has no AccountLoader. An 8-byte discriminator guards the cast, and the client pre-creates the account (too large for an init CPI, which is capped at 10 KB).
  • MarketUser.open_orders is a fixed [u8; 160] (20 packed u64s) + length instead of a borsh Vec<u64>, keeping the account fixed-size so maker accounts (passed as remaining accounts) mutate in place.
  • The slab is heap-free: fixed-array traversal stack (critbit depth ≤ 128), two write-only upstream stacks removed, and place_order crosses at most MAX_FILLS (16) orders per call.
  • side / order status / order side stored as u8 (zero-copy POD); place_order takes side: u8 and an order_id verified against the book's next_order_id.

Tests & docs

  • QuasarSVM integration tests in src/tests.rs drive the full lifecycle — initialize a market, create users, rest an ask, cross it with a bid, settle both sides, withdraw the fee — asserting on-chain state, token balances, and fee accounting, plus an authorization rejection.
  • README documents the accounts/PDAs, the two-lot model, the instruction lifecycle, the matching engine, and every Quasar-specific adaptation.

Validation

Verified with the host toolchain: cargo build and cargo clippy --all-targets are clean (only the framework's idl-build cfg warnings, same as the existing finance/escrow/quasar), and cargo test --no-run compiles and links the QuasarSVM suite. The SBF build + test run happens in the Quasar CI (quasar build then cargo test); it couldn't run in the authoring sandbox because Solana platform-tools weren't reachable there.

🤖 Generated with Claude Code

https://claude.ai/code/session_016ATxCcgrZxaL5dMZSyWj1K


Generated by Claude Code

Port finance/order-book/anchor to Quasar under finance/order-book/quasar,
sharing the same program ID so clients and PDA derivations work against
either build.

The trading logic, fee model, two-lot pricing, and the OpenBook-derived
critbit matching engine are preserved. Quasar-specific adaptations:

- Order book (~180 KB, two zero-copy slabs) is accessed by casting the raw
  account bytes with bytemuck, since Quasar has no AccountLoader. An 8-byte
  discriminator guards the cast.
- MarketUser.open_orders is a fixed [u8; 160] (20 packed u64s) + length
  instead of a borsh Vec<u64>, keeping the account fixed-size so maker
  remaining-accounts mutate in place.
- The slab is heap-free: fixed-array traversal stack, two write-only
  upstream stacks removed, and place_order crosses at most MAX_FILLS orders.
- side / order status / order side stored as u8 (zero-copy POD); place_order
  takes side:u8 and an order_id verified against the book's next_order_id.

Includes QuasarSVM integration tests covering the full lifecycle (init,
create users, rest an ask, cross with a bid, settle both sides, withdraw
fees) plus an authorization rejection, and a README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ATxCcgrZxaL5dMZSyWj1K
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.

2 participants