2025-11-18 23:49:44 +03:00
2025-11-22 20:35:01 +03:00
2025-11-18 23:49:44 +03:00

๐Ÿ† BetFun Arena

Prediction Markets Meet Gaming on Solana

A full-featured prediction market platform with live battle arenas, advanced trading, and gamification. Built on Solana with Next.js 14, Anchor, and real-time infrastructure.

License: MIT Solana Next.js


โœจ Features

Core Trading

  • ๐ŸŽฏ Prediction Markets - Create and trade on any outcome
  • ๐Ÿ’Ž Share Tokens - SPL tokens representing outcomes
  • ๐ŸŠ AMM Pools - Automated market making with liquidity
  • ๐Ÿ“š Order Book - Limit orders with smart routing
  • ๐Ÿงฎ Advanced Trading - Stop-loss, iceberg, TWAP orders
  • ๐Ÿ“Š Portfolio Tracking - Real-time P&L and positions

Unique Features

  • โš”๏ธ Live Battles - Real-time multiplayer game arenas (Moddio)
  • ๐Ÿš€ Token Launches - Create tokens for outcomes (Indie.fun)
  • ๐Ÿ† Trophy NFTs - Compressed NFTs for winners
  • ๐ŸŽฎ Gamification - Achievements, leaderboards, streaks
  • ๐Ÿ‘ฅ Social - Profiles, comments, followers
  • ๐Ÿ“ˆ Analytics - Platform and user metrics

Technical

  • โšก Real-time - WebSocket updates for everything
  • ๐Ÿ”’ Secure - Anchor smart contracts with security features
  • ๐Ÿ“ฑ Responsive - Mobile-first PWA design
  • ๐ŸŒ Scalable - Redis caching, database pooling
  • ๐Ÿ“ก Indexed - Complete on-chain data indexing

๐Ÿš€ Quick Start

Prerequisites

# Required
node >= 18.0.0
npm >= 9.0.0
rust >= 1.70.0
solana-cli >= 1.16.0
anchor-cli >= 0.29.0

# Optional but recommended
redis-server
docker

Installation

# Clone the repository
git clone https://github.com/betfun-arena/betfun-arena.git
cd betfun-arena

# Install dependencies
npm install

# Setup environment variables
npm run setup:env
# Follow the prompts to configure your environment

# Start all services
npm run dev

The app will be available at:


๐Ÿ“ Project Structure

betfun-arena/
โ”œโ”€โ”€ apps/
โ”‚   โ””โ”€โ”€ web/              # Next.js 14 frontend
โ”‚       โ”œโ”€โ”€ app/          # App router pages
โ”‚       โ”œโ”€โ”€ components/   # React components
โ”‚       โ”œโ”€โ”€ hooks/        # Custom hooks
โ”‚       โ””โ”€โ”€ lib/          # Utilities
โ”‚
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ anchor/           # Solana smart contracts
โ”‚   โ”‚   โ””โ”€โ”€ programs/
โ”‚   โ”‚       โ””โ”€โ”€ betfun/   # Main program
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ sdk/              # TypeScript SDK
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ shares.ts # Share token functions
โ”‚   โ”‚       โ”œโ”€โ”€ amm.ts    # AMM functions
โ”‚   โ”‚       โ””โ”€โ”€ router.ts # Order routing
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ api/              # REST API service
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ””โ”€โ”€ index.ts  # Express server
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ websocket/        # WebSocket service
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ””โ”€โ”€ index.ts  # Socket.io server
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ indexer/          # Solana indexer
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ””โ”€โ”€ index.ts  # Event processor
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ services/         # Shared services
โ”‚       โ””โ”€โ”€ matching-engine.ts
โ”‚
โ”œโ”€โ”€ scripts/              # Utility scripts
โ”œโ”€โ”€ docs/                 # Documentation
โ””โ”€โ”€ DATABASE_SCHEMA.sql   # Database schema

๐Ÿ”ง Development

Running Individual Services

# Frontend only
npm run dev:web

# API only
npm run dev:api

# WebSocket only
npm run dev:ws

# Indexer only
npm run dev:indexer

# All services
npm run dev

Building

# Build everything
npm run build

# Build smart contracts
npm run build:contracts

# Build frontend
cd apps/web && npm run build

# Build backend services
cd packages/api && npm run build
cd packages/websocket && npm run build
cd packages/indexer && npm run build

Testing

# Run all tests
npm test

# Run smart contract tests
cd packages/anchor && anchor test

# Run frontend tests
cd apps/web && npm test

๐ŸŽฏ Smart Contract Deployment

Deploy to Devnet

cd packages/anchor

# Configure for devnet
solana config set --url devnet

# Airdrop SOL for testing
solana airdrop 2

# Build and deploy
anchor build
anchor deploy

# Note the Program ID and update it in:
# - programs/betfun/src/lib.rs
# - apps/web/.env.local
# - All backend service .env files

Deploy to Mainnet

# Configure for mainnet
solana config set --url mainnet-beta

# Ensure you have enough SOL
solana balance

# Deploy
anchor deploy --provider.cluster mainnet-beta

# Verify
solana program show <PROGRAM_ID>

๐Ÿ“Š Database Setup

Using Supabase

  1. Create a new project at https://supabase.com
  2. Copy the connection details
  3. Run the schema:
    # Copy DATABASE_SCHEMA.sql content
    # Paste in Supabase SQL Editor
    # Execute
    

Local PostgreSQL

# Create database
createdb betfun_arena

# Run migrations
psql betfun_arena < DATABASE_SCHEMA.sql

๐Ÿ”Œ API Documentation

REST API

Base URL: http://localhost:3001/api

Markets

GET    /markets              # List all markets
GET    /markets/trending     # Trending markets
GET    /market/:id           # Single market
GET    /market/:id/trades    # Market trades
GET    /market/:id/orderbook # Order book

Users

GET    /user/:address/profile    # User profile
GET    /user/:address/positions  # User positions
GET    /user/:address/activity   # User activity

Complete API docs: API_DOCUMENTATION.md

WebSocket

URL: ws://localhost:3002

import { io } from 'socket.io-client';

const socket = io('http://localhost:3002');

// Subscribe to market updates
socket.emit('subscribe:market', { marketId: '...' });

// Listen for updates
socket.on('price:update', (data) => {
  console.log('Price updated:', data);
});

๐ŸŽจ Tech Stack

Frontend

  • Framework: Next.js 14 with App Router
  • Language: TypeScript
  • Styling: Tailwind CSS + shadcn/ui
  • Animations: Framer Motion
  • State: React Query
  • Wallet: Solana Wallet Adapter

Backend

  • Blockchain: Solana
  • Contracts: Anchor Framework (Rust)
  • API: Express.js
  • WebSocket: Socket.io
  • Database: PostgreSQL (Supabase)
  • Cache: Redis
  • Indexer: Custom (Helius webhooks)

DevOps

  • Hosting: Vercel (frontend), Railway (backend)
  • CDN: Cloudflare
  • Monitoring: Sentry
  • CI/CD: GitHub Actions

๐Ÿ“ˆ Performance

  • Page Load: < 2s (First Contentful Paint)
  • API Response: < 100ms (cached), < 500ms (uncached)
  • WebSocket Latency: < 50ms
  • Transactions: ~1,000 trades/second
  • Concurrent Users: 10,000+

๐Ÿ”’ Security

  • โœ… Anchor framework security features
  • โœ… PDA-based access control
  • โœ… Rate limiting (Redis)
  • โœ… Input sanitization
  • โœ… CORS configuration
  • โœ… 2FA support
  • โœ… API key authentication

๐Ÿ“š Documentation


๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

# Fork the repository
# Create a feature branch
git checkout -b feature/amazing-feature

# Commit your changes
git commit -m 'Add amazing feature'

# Push to the branch
git push origin feature/amazing-feature

# Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Solana - Fast, cheap, and scalable blockchain
  • Anchor - Solana development framework
  • Moddio - Real-time multiplayer game engine
  • Indie.fun - Token launch platform
  • Play Solana - Gaming SDK
  • Pyth Network - Price oracle
  • Helius - Solana infrastructure

๐Ÿ“ž Support


๐Ÿ—บ๏ธ Roadmap

Q1 2025

  • MVP Launch
  • Advanced Trading
  • Complete Platform
  • Security Audit
  • Mainnet Launch

Q2 2025

  • Mobile App (React Native)
  • Advanced Analytics
  • AI Predictions
  • Social Trading

Q3 2025

  • Institutional Features
  • Multi-chain Support
  • Advanced Governance
  • API Marketplace

Built with โค๏ธ on Solana
Prediction markets, reimagined. โš”๏ธ๐Ÿ†


๐Ÿ“Š Stats

Lines of Code Files Polymarket%20Parity Status

betfun-arena

Description
1031
Readme 1 MiB
Languages
TypeScript 81.9%
Rust 12%
PLpgSQL 3%
JavaScript 1.2%
CSS 1%
Other 0.8%