Skip to content

added coinflip game to Qusino sc - #998

Open
TakaYuPP wants to merge 9 commits into
qubic:developfrom
TakaYuPP:cflip
Open

added coinflip game to Qusino sc#998
TakaYuPP wants to merge 9 commits into
qubic:developfrom
TakaYuPP:cflip

Conversation

@TakaYuPP

@TakaYuPP TakaYuPP commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Add Coin Flip game with RANDOM-backed RNG "Result Bank"

Summary

Integrates the RANDOM smart contract into Qusino to power a new Coin Flip game, using a "Result Bank" architecture (per-game pool + shared overflow reserve) so individual bets resolve instantly instead of waiting on a live RANDOM call.

What's new

RNG Result Bank

  • refillRandomBank() — permissionless maintenance call that buys entropy from RANDOM in bulk (256 bits/call), expands it via K12 re-hashing into a 1024-entry shared reserve, and bootstraps any not-yet-seeded game's 256-entry pool from that reserve.
  • Reserve/pool arrays are sized via QUSINO_RNG_MAX_GAMES (32, headroom for future games) vs. QUSINO_RNG_ACTIVE_GAMES (1, bumped as new games launch) so this plumbing is reusable for Blackjack/Baccarat later without another state layout change.
  • Refill is blocked while the reserve still holds unspent values (so a refill never overwrites — and wastes the fee on — still-unused entropy), and rate-limited to once per 5 ticks after that.
  • getRandomBankStatus() — read-only view of pool/reserve health for frontends to poll.

Coin Flip

  • coinFlip(guess, assetType, amount) — bets QSC or STAR (never raw Qu) on heads/tails. Outcome is drawn instantly from the pool (context-mixed, then re-hashed against the drawn value so it can't be predicted or replayed), and the consumed slot is topped up from the reserve.
  • QSC bets are redeemed for Qu (QSC_PRICE); a win credits new QSC back to the caller (they redeem it for real Qu themselves via the existing redemptionQSCToQubic), a loss keeps the Qu value in the bankroll. STAR bets never touch Qu — a win mints STAR, a loss burns it, mirroring the existing vote-fee burn.

Qu game bankroll

  • bonusAmount (previously only backing the daily-claim-bonus feature) now doubles as the Qu bankroll funding both refillRandomBank's RANDOM fees and Coin Flip's QSC payouts. Funded by the game owner via the existing depositBonus.
  • Pinned at a 2.4B Qu cap (QUSINO_GAME_BANKROLL_CAP) — any deposit or loss top-up that would push it past the cap routes the excess into epochRevenue instead.
  • A QSC bet is rejected up front unless the bankroll can already cover the full win payout, so a win can never underflow the bankroll.

New return codes: QUSINO_INVALID_INPUT, QUSINO_RNG_NOT_READY, QUSINO_RNG_REFILL_TOO_SOON, QUSINO_RNG_REFILL_FAILED (reuses QUSINO_INSUFFICIENT_BONUS_AMOUNT / QUSINO_WRONG_ASSET_TYPE / QUSINO_INSUFFICIENT_QSC / QUSINO_INSUFFICIENT_STAR for the rest).

Testing

40 GoogleTest cases in contract_qusino.cpp (up from 32), covering: bank refill success/failure/rate-limiting/insufficient-bankroll paths, Coin Flip validation (bad guess/asset type/bet size/balance), QSC settlement (win credit, loss top-up, bankroll gating), STAR settlement (mint/burn, no bankroll interaction), and the bankroll cap/overflow-to-revenue behavior. All passing.

Notes for reviewers

  • bonusAmount is now shared between daily-claim-bonus and the game bankroll — a design choice, not an oversight (dailyClaimBonus payouts and Coin Flip traffic draw from the same treasury).
  • QUSINO_COINFLIP_MIN_BET and QUSINO_COINFLIP_PAYOUT_PERCENT (1.96x, ~2% house edge)

@Franziska-Mueller
Franziska-Mueller self-requested a review September 3, 2026 11:24

@fnordspace fnordspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please let us know when the PR is ready for the review.

Comment thread src/contracts/Qusino.h
Comment thread src/contracts/Qusino.h
@TakaYuPP
TakaYuPP requested a review from fnordspace September 3, 2026 13:07
@Franziska-Mueller
Franziska-Mueller removed their request for review September 3, 2026 14:13

@fnordspace fnordspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks ok to me. Please not we do not review the logic of the contract it self. Please make sure it works as intended and test your contract thoroughly.

Also this PR changes the logic of the contract and needs a Proposal to be merged.

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