Introduction
System Architecture
Complete technical architecture and data flow for OracleMart
System Architecture
OracleMart consists of multiple layers working together to provide a seamless prediction market experience.
Complete System Diagram
Layer Breakdown
1. Blockchain Layer (Sepolia Testnet)
Location: Ethereum Sepolia (Chain ID: 11155111)
Smart Contracts:
CoreMarket.sol- Market creation & bettingResolutionEngine.sol- Oracle integration & resolutionTreasury.sol- Fee collection & managementAutomatedOracle.sol- Chainlink/UMA oracle adapter
Deployed Addresses:
{
CoreMarket: "0x36b5ebE5a161E7d1C7B75aBce457d7066d87e6DB",
ResolutionEngine: "0xdD2DBd78d4D260321735d45EF32Df965c962Ab7F",
Treasury: "0x5BCa2465a870bb0E9eaEC70256D747a48aa388E5",
AutomatedOracle: "0xc3D6365491A4d83a87351D0323F90bD9d8bFC1Ac",
ORMT: "0x5a7AD6C7ad82b163A3B561C77435B6354Cb030F1"
}2. Indexer Service
Location: /Users/obanj/Desktop/oraclemart-indexer
Runtime: Node.js + PM2
Responsibilities:
- Listen to blockchain events in real-time
- Decode event data using ABIs
- Write structured data to Supabase
- Create market snapshots for charts
- Update user statistics
- Maintain event audit log
Events Indexed:
MarketCreatedBetPlacedMarketResolvedWinningsClaimedLiquidityAddedLiquidityRemoved
Performance:
- Average processing time: <100ms per event
- Retry mechanism for failed writes
- Automatic recovery on restart
3. Database Layer (Supabase)
Type: PostgreSQL + Auto REST API
Tables:
markets
Stores all prediction markets
- market_id (bigint, PK)
- question (text)
- creator (text)
- total_yes_amount (numeric)
- total_no_amount (numeric)
- end_time (timestamp)
- resolution_type (text)
- status (text)
- winning_outcome (boolean)bets
User betting history
- bet_id (bigint, PK)
- market_id (bigint, FK)
- user_address (text)
- outcome (boolean)
- amount (numeric)
- odds (numeric)
- timestamp (timestamp)user_stats
Aggregated user statistics
- user_address (text, PK)
- total_bets (integer)
- total_wagered (numeric)
- total_winnings (numeric)
- win_rate (numeric)
- profit_loss (numeric)market_snapshots
Historical data for charts
- snapshot_id (bigint, PK)
- market_id (bigint, FK)
- yes_pool (numeric)
- no_pool (numeric)
- timestamp (timestamp)events
Blockchain events audit log
- event_id (bigint, PK)
- event_type (text)
- market_id (bigint)
- tx_hash (text)
- block_number (bigint)
- data (jsonb)
- timestamp (timestamp)Features:
- Auto REST API (PostgREST)
- Real-time subscriptions (WebSocket)
- Row Level Security (RLS)
- Automatic backups
4. Frontend Application
Location: /Users/obanj/Desktop/oracle-mart
Framework: Next.js 15.5 + React 19
Pages:
/- Landing page/markets- Browse all markets/dashboard- User dashboard with positions/leaderboard- Top traders ranking/market/[id]- Individual market details
API Routes:
/api/markets- Market endpoints/api/bets- Betting history/api/users- User statistics/api/analytics- Trending, leaderboard
Tech Stack:
- UI Framework: React 19 with Server Components
- Styling: Tailwind CSS v4 + SCSS
- Web3: Wagmi v2 + RainbowKit
- State Management: TanStack Query
- Database Client: Supabase JS
- Charts: Lightweight Charts (TradingView)
Data Flow
Creating a Market
Placing a Bet
Market Resolution
Technology Stack
Smart Contracts
- Language: Solidity ^0.8.19
- Framework: Hardhat
- Testing: Chai + Waffle
- Libraries: OpenZeppelin, Chainlink
Backend
- Runtime: Node.js 20+
- Process Manager: PM2
- Database: PostgreSQL (via Supabase)
- RPC Provider: Alchemy/Infura
Frontend
- Framework: Next.js 15.5
- UI Library: React 19
- Styling: Tailwind CSS v4, SCSS
- Web3: Wagmi v2, Viem, RainbowKit
- State: TanStack Query
- Charts: Lightweight Charts
Security Considerations
Smart Contracts
- Reentrancy guards on all state-changing functions
- Access control with role-based permissions
- Emergency pause mechanism
- Comprehensive test coverage (161/161 tests)
Backend
- Input validation on all endpoints
- Rate limiting to prevent abuse
- Secure environment variable management
- Database connection pooling
Frontend
- Wallet signature verification
- Transaction simulation before execution
- Slippage protection on bets
- Client-side validation
Performance Metrics
Smart Contracts
- Gas cost per market creation: ~200,000 gas
- Gas cost per bet: ~80,000 gas
- Gas cost per claim: ~60,000 gas
Indexer
- Event processing: <100ms average
- Database write: <50ms average
- Uptime: 99.9%
Frontend
- Initial page load: <2s
- Time to Interactive: <3s
- API response time: <200ms
Deployment Architecture
Development
- Blockchain: Sepolia Testnet
- Database: Supabase Free Tier
- Frontend: Vercel Preview
- Indexer: Local PM2
Production (Planned)
- Blockchain: Ethereum Mainnet
- Database: Supabase Pro with replicas
- Frontend: Vercel Enterprise
- Indexer: Dedicated VPS with failover
- CDN: Cloudflare