Skip to content

Conversation

@jannden
Copy link
Owner

@jannden jannden commented Jun 18, 2025

Closes #27

Summary by CodeRabbit

  • New Features
    • Updated the game's revenue distribution: 88% of cipher purchase revenue now goes to the prize pool and 12% to the admin.
  • Bug Fixes
    • Improved validation during cipher purchases to ensure proper admin authority is present before proceeding.
  • Documentation
    • Revised the README to reflect the new, simplified revenue distribution model.
  • Tests
    • Enhanced tests to verify correct revenue splitting between the prize pool and admin wallet during cipher purchases.

@coderabbitai
Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes implement a new revenue distribution model for cipher purchases, splitting payments into 88% for the prize pool and 12% for the admin. This affects the smart contract, TypeScript bindings, tests, and documentation. The admin wallet is now explicitly included in relevant transactions and tests, and a new constant defines the prize pool percentage.

Changes

File(s) Change Summary
README.md Updated revenue distribution description to 88% prize pool, 12% admin.
app/src/context/BlockrunnersProvider.tsx Added validation for game state/admin authority; included adminWallet in purchaseCiphers transaction.
app/src/idl/blockrunners.json
app/src/idl/blockrunners.ts
Added adminWallet account to purchaseCiphers instruction; added prizePoolPercentage constant (88).
programs/blockrunners/src/constants.rs Added PRIZE_POOL_PERCENTAGE constant (88).
programs/blockrunners/src/instructions/purchase_ciphers.rs Implemented split payment logic; added admin_wallet account; prize pool/admin transfer logic updated.
tests/helpers/constants.ts Added ADMIN_KEYPAIR and PRIZE_POOL_PERCENTAGE constants for consistent admin identity and config in tests.
tests/initialize_game.ts
tests/initialize_player.ts
tests/join_game.ts
Updated to use shared ADMIN_KEYPAIR for admin identity in test setup.
tests/move.ts Updated to pass adminWallet in purchaseCiphers calls; imported BN from anchor.
tests/purchase_ciphers.ts Refactored to verify split payments; added checks for prize pool/admin shares; updated to use ADMIN_KEYPAIR and constant.

Sequence Diagram(s)

sequenceDiagram
    participant Player
    participant Frontend
    participant Program
    participant PrizePool
    participant AdminWallet

    Player->>Frontend: Initiate cipher purchase (amount)
    Frontend->>Program: purchaseCiphers(amount, accounts)
    Program->>PrizePool: Transfer 88% of amount
    Program->>AdminWallet: Transfer 12% of amount
    Program-->>Frontend: Transaction confirmation
    Frontend-->>Player: Update balances/UI
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement revenue split: 88% prize pool, 12% admin (#27)
Modify cipher purchase to split funds according to distribution rules (#27)
Send admin's share to contract deployer on every prize pool increase (#27)
Update README and in-game info to reflect new distribution (#27)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • IhorMuliar

Poem

A cipher is bought, the coins split anew,
Eighty-eight for the prize, twelve for admin's due.
The contract now shares, both fair and precise,
With tests and docs updated, the logic is nice!
🐇✨
Revenue flows as the bunnies decree—
Hop, hop, hooray for transparency!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/an/ch/anchor-lang, error: Permission denied (os error 13)
Downloading crates ...
Downloaded solana-log-collector v2.2.4
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9caefa and ce5a4aa.

📒 Files selected for processing (16)
  • README.md (1 hunks)
  • app/src/context/BlockrunnersProvider.tsx (1 hunks)
  • app/src/idl/blockrunners.json (2 hunks)
  • app/src/idl/blockrunners.ts (2 hunks)
  • programs/blockrunners/src/constants.rs (1 hunks)
  • programs/blockrunners/src/instructions/initialize_player.rs (1 hunks)
  • programs/blockrunners/src/instructions/join_game.rs (1 hunks)
  • programs/blockrunners/src/instructions/purchase_ciphers.rs (5 hunks)
  • programs/blockrunners/src/utils/randomness_request.rs (1 hunks)
  • programs/blockrunners/src/utils/randomness_reveal.rs (1 hunks)
  • tests/helpers/constants.ts (1 hunks)
  • tests/initialize_game.ts (2 hunks)
  • tests/initialize_player.ts (2 hunks)
  • tests/join_game.ts (2 hunks)
  • tests/move.ts (9 hunks)
  • tests/purchase_ciphers.ts (15 hunks)
✅ Files skipped from review due to trivial changes (4)
  • programs/blockrunners/src/instructions/initialize_player.rs
  • programs/blockrunners/src/instructions/join_game.rs
  • programs/blockrunners/src/utils/randomness_request.rs
  • programs/blockrunners/src/utils/randomness_reveal.rs
🚧 Files skipped from review as they are similar to previous changes (11)
  • tests/initialize_game.ts
  • tests/initialize_player.ts
  • programs/blockrunners/src/constants.rs
  • tests/join_game.ts
  • tests/helpers/constants.ts
  • app/src/context/BlockrunnersProvider.tsx
  • app/src/idl/blockrunners.json
  • app/src/idl/blockrunners.ts
  • tests/move.ts
  • programs/blockrunners/src/instructions/purchase_ciphers.rs
  • tests/purchase_ciphers.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: jannden
PR: jannden/blockrunners#47
File: app/src/lib/constants.ts:18-27
Timestamp: 2025-04-13T19:06:34.047Z
Learning: In the blockrunners project, the IDL defines constants in UPPER_SNAKE_CASE format (e.g., "CIPHER_COST", "GAME_STATE_SEED"), while TypeScript types are translated to camelCase.
README.md (1)
Learnt from: jannden
PR: jannden/blockrunners#47
File: app/src/lib/constants.ts:18-27
Timestamp: 2025-04-13T19:06:34.047Z
Learning: In the blockrunners project, the IDL defines constants in UPPER_SNAKE_CASE format (e.g., "CIPHER_COST", "GAME_STATE_SEED"), while TypeScript types are translated to camelCase.
🪛 markdownlint-cli2 (0.17.2)
README.md

46-46: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


53-53: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


62-62: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


72-72: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


79-79: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


96-96: Bare URL used

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
README.md (1)

48-52: README percentages match on‐chain constants

  • In programs/blockrunners/src/constants.rs, PRIZE_POOL_PERCENTAGE: u8 = 88
  • Admin fee is implicitly 100 – 88 = 12%

No drift detected—README’s “88% prize pool / 12% admin” aligns with the on-chain constant.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (8)
README.md (1)

68-70: Minor grammar: “fewer” for countable nouns

-  3. **Swift** - The next step costs two less ciphers than it would.
+  3. **Swift** - The next step costs two fewer ciphers than it would.
tests/helpers/constants.ts (2)

5-7: Consider using a deterministic test admin keypair

Keypair.generate() creates a fresh keypair every time tests start.
While Node's module cache makes sure the same instance is reused within a single Jest/Mocha run, the private key differs between runs, so balances/history accumulated on a local validator will not survive a restart.
If you rely on fixtures or wish to debug fund flows between runs, consider:

-export const ADMIN_KEYPAIR = Keypair.generate();
+export const ADMIN_KEYPAIR = Keypair.fromSeed(
+  Uint8Array.from(Array(32).fill(1)) // <–– any 32-byte seed you like
+);

This keeps tests reproducible and avoids “unknown signer” surprises when re-using the same ledger.


13-13: Potential precision loss when parsing on-chain constants

prizePoolPercentage is an on-chain u64, but it is cast to JS Number, which is IEEE-754 and loses precision above 2⁵³-1.
88 is safe, yet if the constant ever becomes something larger (e.g. 10 000 = 100.00 %), the cast would still be safe but the pattern invites future mistakes. Prefer BN for unsigned 64-bit ints to stay type-aligned:

-export const PRIZE_POOL_PERCENTAGE = Number(getConstantOrThrow("prizePoolPercentage"));
+export const PRIZE_POOL_PERCENTAGE = new BN(
+  getConstantOrThrow("prizePoolPercentage")
+).toNumber(); // or expose the BN directly
app/src/idl/blockrunners.ts (1)

513-516: Account list lacks explicit signer field – intentional?

Other signer accounts (e.g. player) explicitly declare "signer": true.
Leaving the field out defaults to false, which is correct for adminWallet, but adding it explicitly improves self-documentation and avoids accidental behavioural changes if Anchor’s defaults ever evolve.

tests/move.ts (1)

2-3: Redundant BN import

You import BN on line 2 but still instantiate anchor.BN throughout the file (e.g. line 94).
Either:

  1. drop the extra import, or
  2. switch to the standalone BN for consistency.

This avoids confusion and dead imports.

app/src/context/BlockrunnersProvider.tsx (1)

219-223: Guard clause is good – surface the error to the UI as well

Early-returning on missing gameState.authority prevents a crash, but the user receives no feedback.
Consider bubbling the error up (toast/snackbar, state flag, etc.) so the front-end isn’t silently inert.

-  console.error("Purchase ciphers: Game state or admin authority not found");
+  const msg = "Game not initialised – please refresh or try again later.";
+  console.error(msg);
+  // expose a setter or toast helper here
tests/purchase_ciphers.ts (1)

101-113: Remove noisy console logging or guard it behind a debug flag
These eleven consecutive logs clutter test output and slow CI. Either delete them or emit them only when process.env.DEBUG is set.

programs/blockrunners/src/instructions/purchase_ciphers.rs (1)

100-102: Avoid float math in on-chain programs
Casting to f64 and back sacrifices determinism and can truncate large values unexpectedly. Compute the percentage with integer math:

let increase_percentage = (prize_pool_amount * 100) / old_prize_pool;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 905a5fc and e9caefa.

📒 Files selected for processing (12)
  • README.md (1 hunks)
  • app/src/context/BlockrunnersProvider.tsx (1 hunks)
  • app/src/idl/blockrunners.json (2 hunks)
  • app/src/idl/blockrunners.ts (2 hunks)
  • programs/blockrunners/src/constants.rs (1 hunks)
  • programs/blockrunners/src/instructions/purchase_ciphers.rs (5 hunks)
  • tests/helpers/constants.ts (1 hunks)
  • tests/initialize_game.ts (2 hunks)
  • tests/initialize_player.ts (2 hunks)
  • tests/join_game.ts (2 hunks)
  • tests/move.ts (9 hunks)
  • tests/purchase_ciphers.ts (15 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[grammar] ~70-~70: Did you mean “fewer”? The noun “ciphers” is countable.
Context: ... 3. Swift - The next step costs two less ciphers than it would. **Balancing Mec...

(FEWER_LESS)

🪛 markdownlint-cli2 (0.17.2)
README.md

46-46: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


53-53: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


62-62: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


72-72: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


79-79: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


96-96: Bare URL used
null

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (6)
tests/initialize_game.ts (1)

7-21: Great move to a shared ADMIN_KEYPAIR

Centralising the admin identity removes noise from the tests and mirrors the on-chain assumption of a single admin wallet.
No further issues spotted here.

tests/join_game.ts (1)

6-18: Consistent admin usage across tests

Importing ADMIN_KEYPAIR keeps the test matrix predictable and avoids mismatched PDAs/accounts. Looks good.

tests/initialize_player.ts (1)

6-18: Aligned with the new revenue split flow

Using the shared admin keypair ensures that any purchase-related side effects in later tests reflect the real admin wallet. Implementation is sound.

app/src/idl/blockrunners.ts (1)

1139-1146: u64 for percentage looks wasteful

Storing an 8-bit percentage in a 64-bit constant costs 7 extra bytes in every instruction that serialises the constant. Using u8 (consistent with MOVE_SUCCESS_PROBABILITY) would tighten account data and instruction payloads.

tests/move.ts (1)

95-101: ```shell
#!/bin/bash
set -e
rg ".purchaseCiphers" -n tests/move.ts
rg "playerStatePda" -n tests/move.ts
rg "gameStatePda" -n tests/move.ts
rg ".accounts\s*(" -n tests/move.ts


</details>
<details>
<summary>app/src/idl/blockrunners.json (1)</summary>

`1075-1081`: **`PRIZE_POOL_PERCENTAGE` could be a `u8`**

Similar to the TS IDL, a full 64-bit integer for an 0-100 percentage seems excessive.  
Down-sizing to `u8` saves 7 bytes per constant read and matches semantic intent.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@jannden jannden mentioned this pull request Jun 17, 2025
5 tasks
@jannden jannden merged commit 16732fb into main Jul 14, 2025
2 checks passed
@jannden jannden deleted the jannden/feats branch July 14, 2025 14:04
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.

Revenue Distribution

2 participants