Add Quasar port of the order-book (CLOB) example#96
Open
mikemaccana wants to merge 1 commit into
Open
Conversation
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
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.
Ports
finance/order-book/anchorto Quasar underfinance/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:bytemuck— Quasar has noAccountLoader. An 8-byte discriminator guards the cast, and the client pre-creates the account (too large for aninitCPI, which is capped at 10 KB).MarketUser.open_ordersis a fixed[u8; 160](20 packed u64s) + length instead of a borshVec<u64>, keeping the account fixed-size so maker accounts (passed as remaining accounts) mutate in place.place_ordercrosses at mostMAX_FILLS(16) orders per call.side/ order status / order side stored asu8(zero-copy POD);place_ordertakesside: u8and anorder_idverified against the book'snext_order_id.Tests & docs
src/tests.rsdrive 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.Validation
Verified with the host toolchain:
cargo buildandcargo clippy --all-targetsare clean (only the framework'sidl-buildcfg warnings, same as the existingfinance/escrow/quasar), andcargo test --no-runcompiles and links the QuasarSVM suite. The SBF build + test run happens in the Quasar CI (quasar buildthencargo 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