Skip to content

feat: update binary prediction token authority#110

Merged
dhruvja merged 3 commits into
mainfrom
dhruvja/feat/binary-prediction-token-authority
Jul 7, 2026
Merged

feat: update binary prediction token authority#110
dhruvja merged 3 commits into
mainfrom
dhruvja/feat/binary-prediction-token-authority

Conversation

@dhruvja

@dhruvja dhruvja commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Updates binary prediction token custody so the pool token account is owned by the Pool PDA.
  • Removes the need for pool-token approval before settlement payouts.
  • Updates place_bet so wallet bets transfer stake with the user signer, while session bets require the session signer to be approved as the user token delegate.
  • Covers both wallet and session betting flows in the integration test.

Testing

  • anchor build
  • yarn lint:fix && yarn lint
  • yarn test:local

Summary by CodeRabbit

  • New Features

    • Betting and settlement now work with a pool that is derived from the selected token mint, improving support for mint-specific pools.
    • Session-based betting flow now supports direct signer transfers when the bettor and fee payer are the same.
  • Bug Fixes

    • Improved payout handling so winners, ties, and losses follow the expected transfer path.
    • Reduced unnecessary token delegation requirements in betting and settlement flows, making transactions more reliable.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@dhruvja, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7b1d3767-9d22-4cde-8cdb-f540d739d340

📥 Commits

Reviewing files that changed from the base of the PR and between 9108ad2 and 642f054.

📒 Files selected for processing (1)
  • binary-prediction/programs/binary-prediction/src/lib.rs

Walkthrough

This PR refactors the binary-prediction Anchor program to derive pool authority from the pool PDA (seeded with the mint) rather than a separate pool_authority signer. Transfer helpers are updated (pool_signed_transfer gains a pool_mint parameter; a new signer_transfer helper is added), instruction logic in place_bet and settle is adjusted for conditional delegation and updated payout paths, account constraints are updated accordingly, and the integration test suite is refactored to use a local transaction-sending helper.

Changes

Pool PDA Authority Migration

Layer / File(s) Summary
Pool state and transfer helper contracts
binary-prediction/programs/binary-prediction/src/state.rs, binary-prediction/programs/binary-prediction/src/utils.rs
Pool docs updated to describe PDA-based custody/authority; pool_signed_transfer gains a pool_mint parameter used in signer seed derivation; new signer_transfer helper added for direct-authority transfers.
Initialize instruction and account constraints
binary-prediction/programs/binary-prediction/src/lib.rs
initialize derives pool.authority from the pool PDA, updates EATA/vault transfer authority and seeds, and Initialize account struct switches PDA seeds and authority constraints to use pool keyed by mint.
place_bet and settle instruction logic
binary-prediction/programs/binary-prediction/src/lib.rs
place_bet requires delegation only when payer differs from user and uses signer_transfer for stake; settle removes delegation checks and calls pool_signed_transfer with the pool mint; PlaceBet/Settle structs add a mint field and switch owner constraints to pool.key().
Integration test refactor for new pool PDA and local transaction flow
binary-prediction/tests/binary-prediction.ts
Adds sendLocalTransaction helper; updates pool/session setup and conditional oracle feed delegation; converts initialize/bet/delegate/settle/undelegate/withdraw flows from .rpc()/sendAndConfirm() to .transaction() plus local sending.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: jonasXchen

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating the binary prediction token authority.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dhruvja/feat/binary-prediction-token-authority

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dhruvja dhruvja requested a review from jonasXchen July 6, 2026 10:30
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
counter-session-keys Ready Ready Preview, Comment Jul 6, 2026 7:15pm
er-rolldice Ready Ready Preview, Comment Jul 6, 2026 7:15pm
magicblock-counter-example Ready Ready Preview, Comment Jul 6, 2026 7:15pm
magicblock-engine-examples Ready Ready Preview, Comment Jul 6, 2026 7:15pm
magicblock-rewards-dashboard Ready Ready Preview, Comment Jul 6, 2026 7:15pm
rps-example Ready Ready Preview, Comment Jul 6, 2026 7:15pm
spl-tokens Ready Ready Preview, Comment Jul 6, 2026 7:15pm

Request Review

@jonasXchen jonasXchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

More flexible if pool has the authority!

@dhruvja dhruvja merged commit fcf0157 into main Jul 7, 2026
29 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