Skip to content

Add Quasar port of the betting-market example#100

Merged
mikemaccana merged 1 commit into
mainfrom
claude/quasar-betting-market
Jul 7, 2026
Merged

Add Quasar port of the betting-market example#100
mikemaccana merged 1 commit into
mainfrom
claude/quasar-betting-market

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Ports finance/betting-market/anchor to Quasar under finance/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:

  • Variable-length fields are fixed-capacity. Event.description becomes [u8; 200], Outcome.label becomes [u8; 64], and the User position index becomes a packed [u8; 1024] (up to 32 addresses), each with an explicit length, instead of borsh String / Vec<Pubkey>. Every account stays fixed-size, so each mutation is a plain in-place set_inner with no reallocation and no read-your-own-buffer aliasing.
  • The pool vault is a program-derived token account (["vault", event]) rather than an associated token account, matching how the other Quasar finance examples (lending, perpetual-futures) hold pool funds.
  • Enums are stored as u8.

Tests & docs

  • QuasarSVM integration tests in src/tests.rs drive 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.
  • README documents the mechanics, accounts/PDAs, custody, and every adaptation.

Validation

cargo build and cargo clippy --lib are clean (only the framework's idl-build cfg warnings), 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/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
@mikemaccana mikemaccana merged commit 841adab into main Jul 7, 2026
26 checks passed
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