Skip to content

Latest commit

ย 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ† Prediction Royale (PR)

Predict. Compete. Survive. โ€” A gamified prediction market where players stake ETH, predict BTC price movements, and compete in elimination rounds until one winner takes the pot.


โœจ Features

  • Multi-round tournaments โ€” 3โ€“20 rounds per game with progressive elimination
  • Commit-reveal scheme โ€” Prevents front-running of predictions using on-chain hashed commitments
  • Oracle-powered โ€” Chainlink price feeds for BTC/USD and ETH/USD resolution
  • Real-time eliminations โ€” Bottom players eliminated each round
  • 70/20/10 payout โ€” Winner takes 70%, 2nd gets 20%, 3rd gets 10%
  • ERC-721 badges โ€” Participation NFTs with on-chain SVG metadata
  • Live leaderboard โ€” Real-time score updates via Supabase Realtime
  • Wallet-first โ€” No email/password. Connect MetaMask, WalletConnect, or Coinbase Wallet

๐Ÿ— Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Contract Architecture               โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  GameFactoryโ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚    GameLobby (per game)  โ”‚  โ”‚
โ”‚  โ”‚  (Solidity) โ”‚      โ”‚    (Solidity)            โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                  โ”‚                   โ”‚
โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚              โ”‚                   โ”‚              โ”‚    โ”‚
โ”‚              โ–ผ                   โ–ผ              โ–ผ    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚  โ”‚  ScoreEngine     โ”‚  โ”‚  PrizeVault  โ”‚  โ”‚ Oracle  โ”‚โ”‚
โ”‚  โ”‚  (Solidity)      โ”‚  โ”‚  (Solidity)  โ”‚  โ”‚Adapter  โ”‚โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚         ParticipationNFT (ERC-721)           โ”‚   โ”‚
โ”‚  โ”‚              (Solidity)                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow

User โ†’ Frontend (Next.js) โ†’ RainbowKit/wagmi โ†’ Smart Contracts (Arbitrum Sepolia)
                                   โ†“
                            Event Indexer (ethers.js)
                                   โ†“
                            PostgreSQL (Supabase)
                                   โ†“
                            Realtime WebSocket โ†’ Frontend

๐Ÿ›  Tech Stack

Layer Technology
Smart Contracts Solidity 0.8.x
Framework Foundry (forge, cast, anvil)
L2 Network Arbitrum Sepolia
Oracle Chainlink Price Feeds
Frontend Next.js 16 + TypeScript + Tailwind CSS
Web3 wagmi v2 + viem + RainbowKit
State Zustand + React Query
Charts Recharts
Animations Framer Motion
Backend Node.js + Express
Database PostgreSQL (Supabase)
Realtime Supabase Realtime (WebSocket)

๐Ÿ“ Project Structure

pr/
โ”œโ”€โ”€ contracts/           # Foundry project (Smart Contracts)
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ GameFactory.sol      # Lobby factory & registry
โ”‚   โ”‚   โ”œโ”€โ”€ GameLobby.sol        # Core game logic
โ”‚   โ”‚   โ”œโ”€โ”€ ScoreEngine.sol      # Scoring & ranking
โ”‚   โ”‚   โ”œโ”€โ”€ PrizeVault.sol       # Prize pool management
โ”‚   โ”‚   โ”œโ”€โ”€ ParticipationNFT.sol # ERC-721 badges
โ”‚   โ”‚   โ”œโ”€โ”€ OracleAdapter.sol    # Chainlink feed wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ interfaces/          # Solidity interfaces
โ”‚   โ”‚   โ””โ”€โ”€ mocks/               # Test mocks
โ”‚   โ”œโ”€โ”€ test/                    # Foundry tests
โ”‚   โ”œโ”€โ”€ script/                  # Deployment scripts
โ”‚   โ””โ”€โ”€ foundry.toml
โ”‚
โ”œโ”€โ”€ frontend/            # Next.js application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app/                # Pages (landing, lobby, game, profile)
โ”‚   โ”‚   โ”œโ”€โ”€ components/         # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ lib/                # Utilities, ABI, contracts config
โ”‚   โ”‚   โ””โ”€โ”€ store/              # Zustand state
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ backend/             # Express API + Supabase
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ routes/             # REST endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ db/                 # Schema + queries
โ”‚   โ”‚   โ””โ”€โ”€ server.ts
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ indexer/             # Blockchain event indexer
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ eventListener.ts
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Node.js 20+
  • Foundry (forge, cast, anvil)
  • Git

Installation

# Clone the repository
git clone <repo-url>
cd pmbr

# Install frontend dependencies
cd frontend && npm install

# Install backend dependencies
cd ../backend && npm install

# Install indexer dependencies
cd ../indexer && npm install

Environment Variables

Copy .env.example to .env and fill in:

# Required for deployment
ARB_SEPOLIA_RPC=https://sepolia-rollup.arbitrum.io/rpc
PRIVATE_KEY=your_deployer_private_key
ARBISCAN_API_KEY=your_arbiscan_api_key

# Required for frontend
NEXT_PUBLIC_ARB_SEPOLIA_RPC=https://sepolia-rollup.arbitrum.io/rpc
NEXT_PUBLIC_GAME_FACTORY_ADDRESS=deployed_factory_address
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_walletconnect_project_id
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key

# Required for backend
SUPABASE_URL=your_supabase_url
SUPABASE_SERVICE_KEY=your_supabase_service_role_key

Run Tests

cd contracts
forge test -vvv

Deploy Contracts

cd contracts
forge script script/DeployAll.s.sol \
  --rpc-url $ARB_SEPOLIA_RPC \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify

Run Frontend (Dev)

cd frontend
npm run dev

Run Backend

cd backend
npm run dev

Run Indexer

cd indexer
npm run start

๐ŸŽฎ Game Flow

  1. Connect Wallet โ€” MetaMask / WalletConnect on Arbitrum Sepolia
  2. Browse/Create Lobby โ€” Set stake, max players, rounds
  3. Join & Wait โ€” Pay stake, wait for players or countdown
  4. Commit Phase (30s) โ€” Submit hashed prediction (YES/NO on price move)
  5. Reveal Phase (60s) โ€” Reveal prediction with salt
  6. Oracle Resolution โ€” Chainlink fetches real price
  7. Elimination โ€” Bottom players removed per round
  8. Repeat โ€” Until 1 player remains or all rounds complete
  9. Payout โ€” Winner 70%, 2nd 20%, 3rd 10% (3% protocol fee)

๐Ÿ“œ Smart Contract Overview

GameFactory.sol

Factory contract that deploys and tracks all GameLobby instances.

Function Description
createGame() Deploy new game lobby with params
getActiveGames() List all open lobbies
getGamesByPlayer() Player's game history

GameLobby.sol

Core game logic โ€” round management, commit-reveal, scoring, elimination, payouts.

Function Description
joinGame() Pay stake to join
submitCommitment() Commit hashed prediction
revealPrediction() Reveal value + salt
resolveRound() Fetch oracle price, compute scores
eliminatePlayers() Remove bottom scorers
claimPayout() Withdraw winnings

ScoreEngine.sol

Scoring: accuracy % + time bonus. Rankings via bubble sort.

PrizeVault.sol

Isolated escrow with non-reentrant claims.

ParticipationNFT.sol

ERC-721 badges with on-chain SVG showing rank, game ID, rounds survived.

OracleAdapter.sol

Chainlink AggregatorV3Interface wrapper with staleness check (5 min).


๐Ÿ”’ Security

  • ReentrancyGuard on all payable functions
  • Commit-reveal prevents front-running
  • No admin rug โ€” PrizeVault has no owner withdrawal
  • Oracle staleness check โ€” rejects prices >5 minutes old
  • Max 100 players โ€” prevents gas griefing
  • Solidity 0.8.x โ€” built-in overflow protection

About

Players stake crypto, predict live events each round. Wrong predictions eliminate you. Last standing wins the pot. Built on Arbitrum for sub-cent fees, oracle-verified results. It's Polymarket meets Fortnite turning passive speculation into competitive, accessible, addictive entertainment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages