Skip to content

feat: Multi-Chain Support Implementation#17

Merged
caxtonacollins merged 18 commits intomainfrom
devII
Apr 9, 2026
Merged

feat: Multi-Chain Support Implementation#17
caxtonacollins merged 18 commits intomainfrom
devII

Conversation

@caxtonacollins
Copy link
Copy Markdown
Owner

Multi-Chain Support Implementation for betting

Overview

This PR adds comprehensive multi-chain support to the Aviator game, enabling operations across Base and Celo networks.

Key Changes

Backend

  • Chain Registry (backend/src/config/chains.ts): Centralized chain configuration with support for Base (8453) and Celo (42220), including RPC URLs, contract addresses, and explorer links
  • API Endpoints: Updated admin and rounds endpoints to accept optional chainId parameter for chain-specific operations
  • Services: Updated ChainService, GameEngine, and related services to be chain-aware
  • Tests: Updated chain service tests for multi-chain support

Frontend

  • API Client (frontend/lib/api.ts): All admin and game functions now support chainId parameter for multi-chain operations
  • Admin Dashboard (frontend/app/admin/page.tsx): Refactored UI to allow switching between chains and managing operations per chain
  • Game Hook (frontend/hooks/useGame.ts): Enhanced to support chainId parameter for chain-aware game state

Impact

  • Enables seamless switching between supported chains
  • Maintains backward compatibility with existing single-chain deployments
  • Simplifies multi-chain deployment and management
  • Reduces documentation overhead by consolidating setup guides

Files Changed

  • backend/src/config/chains.ts (new)
  • backend/src/routes/admin.ts
  • backend/src/routes/rounds.ts
  • backend/src/services/chain.service.ts
  • backend/src/services/game-engine.service.ts
  • backend/src/__tests__/chain.service.spec.ts
  • frontend/lib/api.ts
  • frontend/app/admin/page.tsx
  • frontend/hooks/useGame.ts
  • .gitignore

- Add CORS configuration to Socket.IO server matching Express CORS
- Support dynamic ngrok URLs via NGROK_URL environment variable
- Allow any *.ngrok-free.app URL via regex pattern
- Fixes WebSocket connection failures on ngrok tunnels
- Add polling as fallback transport when websocket fails
- Configure reconnection strategy (1-5s delays, 5 attempts)
- Improves connection stability on unstable networks like ngrok
- Poll USDC balance every 5 seconds
- Handles ngrok's slower response times gracefully
- Prevents balance from showing stale or zero values
- Add mounted state to prevent SSR/client mismatch
- Prevents hydration errors when chain info is unavailable during SSR
- Eliminates flickering on page load
- Add mounted state to prevent SSR/client mismatch
- Prevents hydration errors when chain switching is unavailable during SSR
- Eliminates flickering on page load
- Add mounted state to prevent SSR/client mismatch
- Return minimal header during SSR to avoid wallet-dependent rendering
- Prevents hydration errors and wallet connection flickering
- Read NGROK_URL from environment variable
- Add ngrok URL to allowedDevOrigins at build time
- Fixes 'Blocked cross-origin request' errors for /_next/* resources
- Add frontend/.env.example with API/WS URL setup instructions
- Add NGROK_URL documentation to backend/.env.example
- Include commented examples for ngrok configuration
- Add getChainConfig() to support both numeric chain IDs and string keys
- Validates chain configuration and contract address availability
- Provides clear error messages for unsupported chains
- Add optional chainId parameter to constructor
- Store chainId as instance property for reference
- Add contract debugging logs for troubleshooting
- Improve error logging with additional context (player, amount, roundId)
- Add optional chainId parameter to placeBet() method
- Add optional chainId parameter to cashOutById() method
- Create chain-specific ChainService instances when chainId provided
- Improve error logging with chainId context
- Add chainId parameter to placeBet endpoint
- Add chainId parameter to cashOut endpoint
- Pass chainId through to GameEngine methods
- Remove global chainService instance
- Add getChainServiceForRequest() helper for chain-specific operations
- Update all admin endpoints to support chainId parameter
- Include chain info (label, chainId) in all responses
- Support chainId from both request body and query parameters
- Add chainId parameter to placeBetRest() and cashOutRest()
- Add admin API functions for contract management:
  - adminFetchContractStatus()
  - adminGetHouseBalance()
  - adminWithdrawHouse()
  - adminFundHouse()
  - adminPauseContract()
  - adminUnpauseContract()
  - adminSetOperator()
  - adminWithdrawETH()
- All admin functions support optional chainId parameter
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 9, 2026

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

Project Deployment Actions Updated (UTC)
aviator Ready Ready Preview, Comment Apr 9, 2026 1:17pm

@caxtonacollins caxtonacollins merged commit 0c890ba into main Apr 9, 2026
5 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.

1 participant