Skip to content

Add LeaderboardV4: startGame tracking and abandoned game resolution#101

Open
bh2smith wants to merge 5 commits into
mainfrom
feat/leaderboard-v4-start-game
Open

Add LeaderboardV4: startGame tracking and abandoned game resolution#101
bh2smith wants to merge 5 commits into
mainfrom
feat/leaderboard-v4-start-game

Conversation

@bh2smith

Copy link
Copy Markdown
Owner

Summary

  • Add CardRoomLeaderboardV4 contract with game session tracking
  • startGame(gameId) records when a player enters a game, emits GameStarted event
  • recordSoloResult / recordVsAiResult clear the active game on completion (backward compatible — works without calling startGame)
  • resolveAbandoned(gameId, players[]) lets the owner batch-record losses for players who started but never finished
  • Full test suite (16 tests) including V3 → V4 upgrade path

New contract functions

Function Caller Purpose
startGame(uint8 gameId) Player Mark game session as active
resolveAbandoned(uint8 gameId, address[] players) Owner Record losses for abandoned games

New events

Event Fields
GameStarted(uint8 gameId, address player, uint256 timestamp) Indexed: gameId, player
GameAbandoned(uint8 gameId, address player, uint256 timestamp) Indexed: gameId, player

Upgrade instructions

Prerequisites: PR #100 (V3) must be merged and deployed first.

1. Deploy (simulation):

forge script script/UpgradeV4.s.sol --rpc-url https://rpc.gnosischain.com --sender <OWNER_ADDRESS>

2. Deploy (broadcast):

forge script script/UpgradeV4.s.sol \
  --rpc-url https://rpc.gnosischain.com \
  --broadcast --verify \
  --account <ACCOUNT_NAME>

3. Verify:

cast call 0x5b46017EF62efa405579D5397B35FC70E0eD8A87 \
  "gameStartedAt(uint8,address)(uint64)" 0 0x0000000000000000000000000000000000000000 \
  --rpc-url https://rpc.gnosischain.com
# Should return 0 (no active game)

Frontend integration

After upgrade, call startGame(gameId) when a player enters a game (before dealing). No changes needed for recordSoloResult / recordVsAiResult — they continue to work as before.

To resolve abandoned games, query GameStarted events without matching GameResult events (e.g., via Dune), then call resolveAbandoned with the stale players.

Test plan

  • forge test --match-contract CardRoomLeaderboardV4Test (16 tests)
  • Upgrade from V3 preserves all existing data
  • startGame emits event and sets gameStartedAt
  • recordResult clears gameStartedAt
  • recordResult still works without calling startGame first
  • resolveAbandoned records loss with max cards for solo, 0 for vs-AI
  • resolveAbandoned reverts for players without active games

@vercel

vercel Bot commented May 25, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
cards Ready Ready Preview, Comment May 25, 2026 5:45am

bh2smith added 5 commits May 25, 2026 07:44
Track when players enter a game so abandoned sessions can be
detected and resolved as losses. Adds startGame(gameId) for
players, resolveAbandoned(gameId, players) for the owner, and
GameStarted/GameAbandoned events for analytics.
Add startGame ABI and encodeStartGame helper. Entry gate now sends
startGame(gameId) in the same batch transaction as the CRC entry fee,
so abandoned games are trackable on-chain from the moment a player
pays to enter.
Anyone can resolve abandoned games once the abandonmentTimeout (default
1 hour) has elapsed since startGame was called. Owner can adjust the
timeout via setAbandonmentTimeout.
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.

1 participant