Skip to content

Conversation

@nkrishang
Copy link
Collaborator

@nkrishang nkrishang commented Jan 29, 2026

Monorepo Restructure with Contracts, Indexer, and Leaderboard

image

Summary

This PR restructures the 2048 frontend into a monorepo containing three packages: contracts, frontend, and indexer. It introduces a real-time leaderboard feature powered by an Envio indexer that tracks game scores, move counts, and gas usage from on-chain events.

Changes

Monorepo Architecture

Converted the single-package frontend into a pnpm workspace monorepo with:

  • packages/contracts - Foundry-based Solidity smart contracts for the 2048 game logic
  • packages/frontend - React/Vite frontend application
  • packages/indexer - Envio-based blockchain indexer for game event tracking

Smart Contracts (packages/contracts)

Added the complete 2048 game smart contracts:

  • Monad2048.sol - Main game contract managing state, move validation, and replay prevention
  • LibBoard.sol - Pure library implementing 2048 game mechanics (tile compression, merging, move processing)
  • Comprehensive test suite with LibBoardTest.t.sol and Monad2048Test.t.sol
  • Deployment scripts and broadcast logs for Monad mainnet

Indexer (packages/indexer)

Built an Envio indexer that processes NewGame and NewMove events to maintain:

  • Game entity - Tracks score, highest tile, move count, board state, and gas metrics per game
  • Player entity - Aggregates total games played, moves, MON burned, and best score per address
  • GameMove entity - Records each move with board states, score delta, and gas costs
  • IndexerStatus entity - Exposes sync progress for frontend state management

The indexer calculates scores by detecting merged tiles from board state diffs, matching the frontend's scoring logic.

Frontend Updates

Leaderboard Feature:

  • Leaderboard.tsx - Animated top 10 high scores display with rank indicators, player stats (moves, gas, MON burned), and current player highlighting
  • useLeaderboard.ts - Hook with 5-second polling, visibility-aware updates, and "new entry" detection
  • useIndexerStatus.ts - Hook for indexer sync status
  • State-aware UI with loading, syncing, empty, and error states

Bug Fixes:

  • Fixed score calculation sync between local state and indexer
  • Clear board state on logout to prevent stale game data
  • Fixed toast explorer link URLs
  • Updated UI layout for leaderboard integration

Configuration:

  • Removed testnet toggle, defaulting to mainnet only
  • Simplified network context

CI/CD

Added ci.yml with parallel jobs for:

  • Frontend - Lint and build
  • Contracts - Forge format check, build, and test
  • Indexer - Envio codegen and test

Documentation

  • ARCHITECTURE.md - Technical overview of contract design, board encoding, and transaction flow
  • FEATURE.md - Leaderboard feature specification and implementation details
  • MIGRATION.md - Migration guide for the monorepo restructure

@nkrishang nkrishang self-assigned this Jan 29, 2026
@vercel
Copy link

vercel bot commented Jan 29, 2026

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: 2048-frontend.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@nkrishang nkrishang marked this pull request as ready for review January 29, 2026 09:39
@nkrishang nkrishang requested a review from marcuspang January 29, 2026 10:25
@vercel
Copy link

vercel bot commented Jan 29, 2026

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

Project Deployment Review Updated (UTC)
2048-frontend Ready Ready Preview, Comment Jan 29, 2026 1:21pm

Request Review

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.

3 participants