Skip to content

Latest commit

ย 

History

1 Commit

Folders and files

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

Repository files navigation

๐ŸŽ๏ธ Oracle Racer

A Decentralized Racing Game Powered by RedStone Pull Oracles

Race crypto assets in real-time using live price movements. Each player selects a cryptocurrency (ETH, BTC, SOL, etc.) and competes to see whose asset performs best during the race duration.

ETH BTC SOL AVAX LINK UNI AAVE ARB

๐Ÿ Race crypto assets in real-time! ๐Ÿ


๐ŸŽฎ What is Oracle Racer?

Oracle Racer is a multiplayer on-chain racing game where:

  • Players race crypto assets, not traditional cars
  • Each race lasts 30-300 seconds
  • Winners are determined by real-time price performance
  • Prices are fetched using RedStone Pull Oracles (only 2 reads per race)
  • Automatic race start when full
  • Points-based leaderboard system

๐ŸŽ๏ธ The Racing Cars

Each cryptocurrency asset is represented as a racing car on the track. Here are all the available cars you can race with:

ETH Car BTC Car SOL Car AVAX Car LINK Car UNI Car AAVE Car ARB Car

Supported Assets

The game supports 8 different cryptocurrency assets, each with its own unique logo displayed as racing cars during races:

๐ŸŽ๏ธ Available Racing Cars

ETH
ETH
Ethereum
BTC
BTC
Bitcoin
SOL
SOL
Solana
AVAX
AVAX
Avalanche
LINK
LINK
Chainlink
UNI
UNI
Uniswap
AAVE
AAVE
Aave
ARB
ARB
Arbitrum

These asset logos are displayed as racing cars on the track, moving in real-time based on price performance. Each car represents a player's chosen cryptocurrency, and their position on the track reflects how well that asset is performing compared to others.


โœจ Features

๐Ÿ Gameplay

  • Create & Join Races - Set duration (30-300s) and player count (2-8)
  • Auto-Start - Race begins automatically when full
  • Live Racing - Watch cars move in real-time based on price changes
  • Dynamic Commentary - Real-time race updates in English
  • Points System - Earn points based on race position (100, 70, 50, 35, 25, 15, 10, 5)
  • Global Leaderboard - Compete for the top spot

๐Ÿ”ฎ Oracle Integration

  • RedStone Pull Model - On-demand price fetching
  • Minimal Gas Usage - Only 2 oracle reads per race
  • Fresh Prices - Always up-to-date data from RedStone Gateway
  • No On-Chain Storage - Prices read directly from transaction calldata

๐ŸŽจ Modern UI

  • Glassmorphism Design - Beautiful glass-effect cards
  • Real-Time Updates - Live price feeds every second during races
  • Responsive Layout - Works on desktop and mobile
  • Smooth Animations - Cars move based on price performance

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    USER (Wallet)                         โ”‚
โ”‚              createRace() / joinRace()                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              FRONTEND (Next.js + Wagmi)                  โ”‚
โ”‚  - Race list & creation                                  โ”‚
โ”‚  - Live race visualization                               โ”‚
โ”‚  - Leaderboard & history                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         BACKEND RELAYER (Next.js API Routes)             โ”‚
โ”‚  - Auto-finish races                                     โ”‚
โ”‚  - Fetch RedStone price data                             โ”‚
โ”‚  - Send transactions with oracle payload                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              REDSTONE GATEWAY                            โ”‚
โ”‚  - Signed price data packages                            โ”‚
โ”‚  - 3+ independent signers                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           BASE SEPOLIA BLOCKCHAIN                        โ”‚
โ”‚                                                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚
โ”‚  โ”‚   OracleRacerSimple.sol             โ”‚                 โ”‚
โ”‚  โ”‚  - Game logic                       โ”‚                 โ”‚
โ”‚  โ”‚  - Oracle Pull reads                โ”‚                 โ”‚
โ”‚  โ”‚  - Scoring & winner                 โ”‚                 โ”‚
โ”‚  โ”‚  - Leaderboard                      โ”‚                 โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • A wallet with Base Sepolia ETH for gas
  • Git

Installation

  1. Clone the repository

    git clone <repository-url>
    cd oracle-racer-v2
  2. Install dependencies

    npm install
  3. Configure environment variables

    cp .env.example .env.local

    Edit .env.local with your configuration:

    PRIVATE_KEY=your_relayer_private_key
    NEXT_PUBLIC_CONTRACT_ADDRESS=0x27DDfB306Fb37868ED865F84e69b8444A8A405E9
    NEXT_PUBLIC_RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_API_KEY
    NEXT_PUBLIC_REDSTONE_GATEWAY_URL=https://oracle-gateway-1.a.redstone.finance
    NEXT_PUBLIC_REDSTONE_DATA_SERVICE=redstone-primary-prod
    NEXT_PUBLIC_REDSTONE_UNIQUE_SIGNERS=3
    NEXT_PUBLIC_FALLBACK_RPC_URL=https://sepolia.base.org
  4. Run development server

    npm run dev
  5. Open your browser

    http://localhost:3000
    

๐ŸŽฏ How It Works

Race Lifecycle

  1. Create Race

    • Choose duration (30-300 seconds)
    • Set player count (2-8)
    • Select your asset (ETH, BTC, SOL, etc.)
    • Race is created and you automatically join
  2. Join Race

    • Other players join with different assets
    • Each asset can only be used once per race
    • Race auto-starts when full
  3. Race Active

    • Watch cars move in real-time
    • Positions update based on price performance
    • Live commentary provides race updates
    • Prices fetched every second for visualization
  4. Race Finish

    • Final prices recorded on-chain
    • Winner determined by best price performance
    • Points awarded to all participants
    • Leaderboard updated

Scoring System

The winner is determined by the highest price percentage change:

score = (endPrice - startPrice) * 1e12 / startPrice

Points Distribution:

  • ๐Ÿฅ‡ 1st place: 100 points
  • ๐Ÿฅˆ 2nd place: 70 points
  • ๐Ÿฅ‰ 3rd place: 50 points
  • 4th: 35 points
  • 5th: 25 points
  • 6th: 15 points
  • 7th: 10 points
  • 8th: 5 points

๐Ÿ”ง Smart Contract

OracleRacerSimple.sol

Deployed on Base Sepolia: 0x27DDfB306Fb37868ED865F84e69b8444A8A405E9

Key Functions:

  • createRace(duration, maxPlayers, feedId) - Create and join a race
  • joinRace(raceId, feedId) - Join an existing race
  • finishRace(raceId) - Finish race and determine winner (requires RedStone payload)

Oracle Integration:

// Start prices (recorded when race auto-starts)
racer.startPrice = getOracleNumericValueFromTxMsg(racer.feedId);

// End prices (recorded when race finishes)
racer.endPrice = getOracleNumericValueFromTxMsg(racer.feedId);

Only 2 Oracle Reads Per Race:

  1. When the last player joins โ†’ race auto-starts โ†’ start prices recorded
  2. When race finishes โ†’ end prices recorded โ†’ winner determined

๐Ÿ› ๏ธ Development

Build for Production

npm run build

Deploy to Vercel

  1. Push your code to GitHub
  2. Import project in Vercel
  3. Add environment variables in Vercel dashboard
  4. Deploy!

Required Environment Variables on Vercel:

  • PRIVATE_KEY - Relayer private key (for auto-finishing races)
  • NEXT_PUBLIC_CONTRACT_ADDRESS - Deployed contract address
  • NEXT_PUBLIC_RPC_URL - Base Sepolia RPC endpoint
  • NEXT_PUBLIC_REDSTONE_GATEWAY_URL - RedStone Gateway URL
  • NEXT_PUBLIC_REDSTONE_DATA_SERVICE - RedStone data service name
  • NEXT_PUBLIC_REDSTONE_UNIQUE_SIGNERS - Number of required signers

๐Ÿ“ Project Structure

oracle-racer-v2/
โ”œโ”€โ”€ contracts/
โ”‚   โ””โ”€โ”€ racer_game.sol          # Main game contract
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ images/                  # Asset logos
โ”‚       โ”œโ”€โ”€ eth.png
โ”‚       โ”œโ”€โ”€ btc.png
โ”‚       โ”œโ”€โ”€ sol.png
โ”‚       โ””โ”€โ”€ ...
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ finish-race/     # Auto-finish race endpoint
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ prices/          # CoinGecko prices API
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ redstone-prices/ # RedStone prices API
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ RaceCard.tsx         # Individual race display
โ”‚   โ”‚   โ”œโ”€โ”€ RaceList.tsx         # List of all races
โ”‚   โ”‚   โ”œโ”€โ”€ CreateRace.tsx      # Race creation form
โ”‚   โ”‚   โ”œโ”€โ”€ Leaderboard.tsx      # Global leaderboard
โ”‚   โ”‚   โ”œโ”€โ”€ History.tsx          # User race history
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ”œโ”€โ”€ contract.ts         # Contract ABI
โ”‚   โ”‚   โ””โ”€โ”€ wagmi.ts            # Wagmi configuration
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ””โ”€โ”€ redstone.ts          # RedStone integration
โ””โ”€โ”€ package.json

๐Ÿ” Security

  • โœ… RedStone Signature Verification - All prices are cryptographically signed
  • โœ… Reentrancy Protection - Using OpenZeppelin's ReentrancyGuard
  • โœ… Relayer Locking - Prevents concurrent race settlements
  • โœ… Input Validation - All parameters validated on-chain
  • โœ… Access Control - Owner-only functions protected

๐ŸŽจ UI Features

Race Visualization

During active races, you'll see:

  • Live race track with cars moving based on price performance
  • Real-time prices updating every second
  • Dynamic commentary providing race updates
  • Timer showing time remaining
  • Price changes displayed in real-time

Asset Selection

Choose from 8 supported cryptocurrencies:

  • Each asset has a unique logo and color
  • Assets are displayed in a grid for easy selection
  • Only available assets can be selected (no duplicates)

๐Ÿ“Š Technology Stack

  • Frontend: Next.js 15, React 19, TypeScript
  • Styling: Tailwind CSS with custom glassmorphism theme
  • Web3: Wagmi v2, Viem, Ethers.js
  • Oracle: RedStone Pull Model
  • Blockchain: Base Sepolia
  • Deployment: Vercel

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“ License

MIT License


๐Ÿ”— Links


๐Ÿ™ Acknowledgments

  • RedStone Finance for the amazing oracle infrastructure
  • Base for the fast and affordable L2
  • OpenZeppelin for security best practices

Built with โค๏ธ using RedStone Pull Oracles

๐ŸŽ๏ธ Race on! ๐ŸŽ๏ธ

About

๐ŸŽ๏ธ On-chain racing game where crypto assets race on live prices โ€” powered by RedStone pull oracles (2 reads per race).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages