Next-Generation Decentralized Prediction Market Protocol
Professional Trading Experience × UMA Oracle Decentralized Settlement × Web3 Native Architecture
Website • Documentation • Twitter • Discord
┌─────────────────────────────────────────────────────────────────────────┐
│ Foresight Technical Architecture │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ User Interface (Next.js 15) │
│ ├── Responsive design, mobile-first │
│ ├── Real-time order book depth display │
│ └── Seamless Web3 wallet integration │
│ │ │
│ ▼ │
│ Off-chain Order Book (Relayer Service) │
│ ├── EIP-712 signed orders │
│ ├── High-performance matching engine │
│ └── Supabase real-time data synchronization │
│ │ │
│ ▼ │
│ Smart Contract Layer (Polygon) │
│ ├── MarketFactory: Market factory (UUPS upgradeable) │
│ ├── OffchainBinaryMarket: Binary market template │
│ ├── OffchainMultiMarket8: Multi-outcome market template (up to 8) │
│ ├── OutcomeToken1155: ERC-1155 outcome tokens │
│ └── UMAOracleAdapterV2: UMA oracle adapter │
│ │ │
│ ▼ │
│ Settlement Layer (UMA Protocol) │
│ ├── Optimistic oracle mechanism │
│ ├── Decentralized dispute arbitration │
│ └── Economic incentives ensure truthfulness │
│ │
└─────────────────────────────────────────────────────────────────────────┘
- Security Headers & CSP
- Strict security headers configured via Next.js, production disables unsafe-inline/unsafe-eval
- Reference: next.config.ts
- Global Middleware
- Injects and propagates x-request-id throughout server logs and event chains
- Applies strict rate limiting to /api/siwe/verify (5 requests/minute/IP)
- Reference: middleware.ts
- Rate Limiting Strategy
- Upstash Redis preferred; falls back to in-memory implementation (dev environment)
- Tiers: strict/moderate/relaxed/lenient; returns remaining quota and reset time
- Reference: rateLimit.ts
- Events & RED Metrics
- logApiEvent prints in development, persists to Supabase analytics_events in production
- Admins can pull RED aggregated views by minute
- Reference: serverUtils.ts, analytics/events
- Binary Markets: YES/NO simple and intuitive predictions
- Multi-Outcome Markets: Complex events supporting 2-8 options
- Real-Time Odds: Dynamic pricing based on order book
- Zero Gas Trading: Off-chain signatures, on-chain settlement
- Follow System: Track top traders and get real-time updates on their activities
- User Cards: Hover to view any user's win rate, PnL, and professional data
- Leaderboards: Real-time profit rankings with multi-dimensional filtering (PnL, win rate, streak)
- Real-Time Discussions: Each proposal/event has a dedicated chat room, supporting images, replies, deletion, and reports; new messages pushed via Supabase Realtime
- Forum Proposals: Subject + comment tree + voting mechanism, aggregated by eventId, suitable for turning "market ideas" into reviewable proposals
- Wish Flags: Three verification paths (self/witness/official); daily check-ins + expiry settlement; tiered sticker rewards based on completion span, building a growth trajectory
API Quick Reference (consistent with docs/code)
# Chat / Discussions
GET /api/discussions?proposalId=1
POST /api/discussions
PATCH /api/discussions/[id]
DELETE /api/discussions/[id]
POST /api/discussions/report
# Flag
GET /api/flags
POST /api/flags
POST /api/flags/[id]/checkin
POST /api/flags/[id]/settle
# Forum
GET /api/forum?eventId=1
POST /api/forum
POST /api/forum/comments
POST /api/forum/vote
GET /api/forum/user-votes?eventId=1
- Limit Orders: Precise entry price control
- Market Orders: Instant execution at best price
- Depth Charts: Visualize buy/sell order distribution
- Candlestick Charts: Professional-grade price trend analysis
- UMA Oracle: Decentralized result verification
- Multi-Sig Governance: 3/5 multisig + 24h Timelock
- Flash Loan Protection: Single-block transaction limit
- Signature Security: ECDSA malleability protection
- MetaMask
- Coinbase Wallet
- WalletConnect
- More wallets coming soon...
- 🇨🇳 简体中文
- 🇺🇸 English
- 🇫🇷 Français
- 🇰🇷 한국어
- 🇪🇸 Español
- Node.js 20.x (LTS)
- npm (recommended)
- Git
# Clone the repository
git clone https://github.com/Foresight-builder/Foresight-beta.git
cd Foresight-beta
# Install dependencies
npm install
# Configure environment variables
cp .env.example .env.local
# Edit .env.local with required configuration
# Start Web + Relayer (recommended)
npm run dev
# Start Web only (optional)
# npm run dev:web
# Start Relayer only (optional)
# npm run dev:relayer
# Visit http://localhost:3000# Supabase (Web)
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
# Supabase (Relayer / Backend scripts)
SUPABASE_URL=your_supabase_url
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
# Blockchain
NEXT_PUBLIC_CHAIN_ID=80002
NEXT_PUBLIC_RPC_URL=https://rpc-amoy.polygon.technology
PRIVATE_KEY=your_deployer_private_key
# Contract addresses (Polygon Amoy)
NEXT_PUBLIC_MARKET_FACTORY_ADDRESS=0x...
NEXT_PUBLIC_OUTCOME_TOKEN_ADDRESS=0x...
NEXT_PUBLIC_UMA_ADAPTER_ADDRESS=0x...
# Relayer
NEXT_PUBLIC_RELAYER_URL=http://localhost:3001
# Relayer (Chain settlement Operator, optional: needed for settlement/AA capabilities)
OPERATOR_PRIVATE_KEY=your_operator_private_keyForesight-beta/
├── apps/
│ └── web/ # Next.js 15 frontend application
│ ├── src/
│ │ ├── app/ # App Router pages
│ │ ├── components/ # React component library
│ │ ├── contexts/ # Global state management
│ │ ├── hooks/ # Custom hooks
│ │ └── lib/ # Utility library
│ └── messages/ # i18n translation files
│
├── packages/
│ └── contracts/ # Solidity smart contracts
│ └── contracts/
│ ├── MarketFactory.sol # Market factory
│ ├── templates/ # Market templates
│ │ ├── OffchainMarketBase.sol # Base contract
│ │ ├── OffchainBinaryMarket.sol
│ │ └── OffchainMultiMarket8.sol
│ ├── tokens/
│ │ └── OutcomeToken1155.sol # ERC-1155 token
│ ├── oracles/
│ │ └── UMAOracleAdapterV2.sol # UMA adapter
│ └── governance/
│ └── ForesightTimelock.sol # Governance timelock
│
├── services/
│ └── relayer/ # Off-chain order book service
│ └── src/
│ ├── index.ts # Express server
│ ├── orderbook.ts # Order book logic
│ └── supabase.ts # Database interaction
│
├── infra/
│ └── supabase/ # Database scripts
│ ├── sql/ # SQL migration files
│ └── scripts/ # Management scripts
│
└── scripts/ # Deployment scripts
└── deploy_offchain_sprint1.ts
| Contract | Description | Audit Status |
|---|---|---|
MarketFactory |
UUPS upgradeable market | 🔄 In Progress |
OffchainBinaryMarket |
Binary market (YES/NO) | 🔄 In Progress |
OffchainMultiMarket8 |
Multi-outcome (2-8 options) | 🔄 In Progress |
OutcomeToken1155 |
ERC-1155 outcome token | 🔄 In Progress |
UMAOracleAdapterV2 |
UMA oracle integration | 🔄 In Progress |
ForesightTimelock |
Governance timelock | 🔄 In Progress |
- ✅ ReentrancyGuard reentrancy protection
- ✅ Flash loan attack protection (single-block limit)
- ✅ Batch operation size limit (DoS prevention)
- ✅ Minimum order lifetime (sandwich attack prevention)
- ✅ ECDSA signature malleability protection
- ✅ ERC-1271 smart contract wallet support
- ✅ Circuit breaker mechanism (emergency pause)
| Metric | Target |
|---|---|
| LCP | < 2.5s |
| INP | < 200ms |
| CLS | < 0.1 |
| API Response (cached) | < 50ms |
| Contract | Address |
|---|---|
| MarketFactory | 0x0762A2EeFEB20f03ceA60A542FfC8EC85FE8A30 |
| OutcomeToken1155 | 0x6dA31A9B2e9e58909836DDa3aeA7f824b1725087 |
| UMAOracleAdapterV2 | 0x5e42fce766Ad623cE175002B7b2528411C47cc92 |
| OffchainBinaryMarket (impl) | 0x846145DC2850FfB97D14C4AF79675815b6D7AF0f |
| OffchainMultiMarket8 (impl) | 0x1e8BeCF558Baf0F74cEc2D7fa7ba44F0335282e8 |
- Core smart contract development
- Off-chain order book service
- Frontend trading interface
- UMA oracle integration
- Multi-sig governance system
- Timelock mechanism
- Security audit preparation
- Attack mitigation measures
- Social feature enhancement (follows, user cards)
- Gamified Flag system deep refactor (immersive 3-step flow & luminous aesthetics)
- Leaderboard search & multi-dimensional sorting (PnL, win rate, streak)
- Real-time "Trending Now" prediction aggregation
- Personal ranking tracking (My Spot)
- Mobile App
- API开放平台
- 多链部署
- DAO治理
- 预言机网络扩展
- 机构级API
| Document | Description |
|---|---|
| DOCS.md | Developer documentation |
| SECURITY.md | Security policy |
| CHANGELOG.md | Changelog |
| CODE_OF_CONDUCT.md | Code of conduct |
| Relayer README | Relayer documentation |
Localized developer and policy documents will be added in future releases.
We welcome community contributions! Contribution guidelines will be published in this repository; in the meantime, feel free to open issues or pull requests directly.
# Fork this repository
# Create a feature branch
git checkout -b feature/amazing-feature
# Commit changes (follow Conventional Commits)
git commit -m 'feat(market): add amazing feature'
# Push to branch
git push origin feature/amazing-feature
# Create a Pull RequestThis project is licensed under the MIT License.
🌐 Website • 🐦 Twitter • 💬 Discord • 📧 Email
Built with ❤️ by the Foresight Team
Predicting the future, one market at a time.