๐ 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.
โจ 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:
- Frontend: http://localhost:3000
- API: http://localhost:3001
- WebSocket: http://localhost:3002
๐ 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
- Create a new project at https://supabase.com
- Copy the connection details
- 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
- Deployment Guide
- Database Schema
- API Documentation
- Architecture Overview
- Trading System
- Contributing Guide
๐ค 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
- Documentation: docs/
- Discord: discord.gg/betfun
- Twitter: @BetFunArena
- Email: support@betfun.arena
๐บ๏ธ 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
betfun-arena
Description
Languages
TypeScript
81.9%
Rust
12%
PLpgSQL
3%
JavaScript
1.2%
CSS
1%
Other
0.8%