Add Quasar port of the betting-market example#100
Merged
Conversation
Port finance/betting-market/anchor to finance/betting-market/quasar, sharing the same program ID so clients and PDA derivations work against either build, and link it in the root README example index. The parimutuel mechanics, fee model, and payout math are preserved. Quasar-specific adaptations: - Variable-length fields are fixed-capacity: Event.description ([u8; 200]), Outcome.label ([u8; 64]), and the User position index (a packed [u8; 1024] of up to 32 addresses) plus explicit lengths, instead of borsh String / Vec<Pubkey>. Every account stays fixed-size, so each mutation is a plain in-place set_inner with no realloc. - The pool vault is a program-derived token account (["vault", event]) rather than an associated token account, matching the other Quasar finance examples. - Enums (event status) are stored as u8. Includes QuasarSVM integration tests covering the full lifecycle (open a market, add outcomes, place opposing bets, settle, claim winnings, close the losing bet), the cancel-and-refund path, and an admin-authorization rejection, plus 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/betting-market/anchorto Quasar underfinance/betting-market/quasar, alongside the existing Quasar examples, and links it in the root README index. Both builds share the same program ID (7LyqAeLR3mK9dfj9LqxWzfKH61VVHzuNpkgW5Y32De74).What's preserved
The parimutuel mechanics, fee model, and payout math are faithful to the Anchor build: winners split the losing pool pro-rata to their stake, the fee is charged only on the losing side, and Bet accounts close on claim/refund/loser-close to prevent double claims. All 9 instructions are ported (
initialize_config,create_event,add_outcome,place_bet,settle_event,claim_winnings,close_losing_bet,cancel_event,claim_refund).Quasar-specific adaptations
Quasar is zero-copy and fixed-layout, so:
Event.descriptionbecomes[u8; 200],Outcome.labelbecomes[u8; 64], and theUserposition index becomes a packed[u8; 1024](up to 32 addresses), each with an explicit length, instead of borshString/Vec<Pubkey>. Every account stays fixed-size, so each mutation is a plain in-placeset_innerwith no reallocation and no read-your-own-buffer aliasing.["vault", event]) rather than an associated token account, matching how the other Quasar finance examples (lending, perpetual-futures) hold pool funds.u8.Tests & docs
src/tests.rsdrive the full lifecycle (open a market, add two outcomes, place opposing bets, settle to the larger pool, claim the winnings, close the losing bet), the cancel-and-refund path, and an admin-authorization rejection, asserting on-chain state, token balances, and fee accounting.Validation
cargo buildandcargo clippy --libare clean (only the framework'sidl-buildcfg warnings), 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