This directory contains the Solana smart contracts (programs) that power the Foresight Protocol prediction market platform.
Foresight Protocol is a decentralized prediction market platform built on Solana that allows users to create markets, stake on outcomes, and earn rewards for accurate predictions. The platform features an innovative AI resolver mechanism for market resolution, creator tiers for fee structures, and community voting for open-ended markets.
-
Market - Represents a prediction market:
creator: The market creator's public keyquestion: The prediction market questionoutcomes: Array of possible outcomes (typically "Yes" and "No" for binary markets)ai_score: AI-generated quality score (0.0 to 1.0)market_type: Type of market (0 = Time-bound, 1 = Open-ended)deadline: The timestamp when the market expiresresolved: Whether the market has been resolvedwinning_outcome: The index of the winning outcometotal_pool: Total amount staked across all outcomescreator_fee_bps: Creator's fee in basis points (100 = 1%)protocol_fee_bps: Protocol fee in basis pointsstakes_per_outcome: Array of staked amounts per outcomeai_resolvable: Whether the market can be resolved by AI
-
Prediction - Represents a user's stake on an outcome:
user: User's public keymarket: Market public keyoutcome_index: The outcome index the user predictedamount: Amount stakedtimestamp: When the prediction was madeclaimed: Whether rewards have been claimed
-
CreatorProfile - Tracks creator stats and tier:
creator: Creator's public keymarkets_created: Number of markets createdtotal_volume: Total volume across all created marketstraction_score: Score based on market performancetier: Creator tier (0-5) determining fees
-
UserProfile - Tracks user statistics:
user: User's public keytotal_staked: Total amount stakedtotal_winnings: Total amount wontotal_predictions: Number of predictions madewinning_predictions: Number of winning predictions
-
AIResolver - Manages AI resolution authority:
authority: Authority public keyactive: Whether resolver is activeresolution_count: Number of markets resolved
- Have a specific expiration date
- Can be resolved by AI or admin after expiration
- Resolution is based on objective, verifiable outcomes
- Example: "Will Bitcoin exceed $100,000 by December 31, 2024?"
- Do not have a specific expiration date
- Resolved through community voting mechanism
- Suitable for long-term predictions with unclear timeframes
- Example: "Will humans establish a permanent colony on Mars?"
The platform implements a progressive tier system for market creators:
| Tier | Level | Fee (BPS) | Requirements |
|---|---|---|---|
| 0 | Beginner | 150 (1.5%) | None |
| 1 | Rising | 175 (1.75%) | 5+ markets, 1,000+ volume |
| 2 | Established | 200 (2%) | 20+ markets, 10,000+ volume |
| 3 | Expert | 300 (3%) | 50+ markets, 50,000+ volume, 500+ traction |
| 4 | Elite | 400 (4%) | 100+ markets, 200,000+ volume, 1,000+ traction |
| 5 | Master | 500 (5%) | 200+ markets, 500,000+ volume, 2,000+ traction |
Traction score increases based on market activity and successful resolutions.
The Foresight Protocol features an innovative AI resolution system that:
- Validates Market Quality: Evaluates market questions for clarity, measurability, and appropriate timeframe
- Scores Market Questions: Provides a quality score from 0.0 to 1.0
- Resolves Time-bound Markets: Can automatically resolve markets with high confidence (>85%)
- Provides Resolution Data: Documents evidence and confidence level for transparency
AI resolution is only applied to time-bound markets that meet specific criteria for objective, verifiable outcomes.
For open-ended markets or when AI resolution is challenged:
- Voting Period: Opens after market deadline for 15 days
- Stake-weighted Voting: Users who staked can vote with weight proportional to their stake
- Resolution Proposal: Authorities can propose outcomes after voting period
- Challenge Period: 48-hour window to challenge proposed resolutions
- Final Resolution: Determines outcome based on stake-weighted votes if challenged
- Admin Controls: Restricted functions only callable by authorized admin
- PDA-based Accounts: Uses Program Derived Addresses for secure, deterministic account creation
- Input Validation: Thorough validation of all input parameters
- Safe Math Operations: Uses checked arithmetic to prevent overflow/underflow
- Event Emission: Emits events for transparent tracking of all critical operations
- Solana CLI tools
- Anchor framework
cd contracts
anchor buildanchor testanchor deployThe Foresight Protocol includes an Oracle service responsible for:
- AI Market Validation: Analyzes proposed market questions for validity and quality
- AI Market Resolution: Resolves time-bound markets with verifiable outcomes
- Data Aggregation: Collects and analyzes data from multiple sources
- Safe Execution: Ensures secure, auditable resolution process
The Oracle service consists of:
- AI Resolver Account: On-chain account that tracks resolution authority
- Resolution Authority: Permissioned entity responsible for submitting resolutions
- Resolution Process: Multi-step verification workflow for outcome determination
pub fn initialize_ai_resolver(
ctx: Context<InitializeAIResolver>,
) -> Result<()> {
// Validate that only the authorized admin can initialize the resolver
require!(is_admin(&ctx.accounts.admin.key()), ErrorCode::Unauthorized);
let resolver = &mut ctx.accounts.ai_resolver;
resolver.authority = ctx.accounts.admin.key();
resolver.active = true;
resolver.resolution_count = 0;
resolver.bump = ctx.bumps.ai_resolver;
msg!("AI resolver initialized with authority: {}", resolver.authority);
Ok(())
}pub fn resolve_market_via_ai(
ctx: Context<ResolveMarketViaAI>,
winning_outcome_index: u8,
ai_confidence_score: f32,
resolution_data: String,
) -> Result<()> {
// Validate authority, active status, market eligibility
// ...
// Require high confidence score
require!(ai_confidence_score >= 0.85, ErrorCode::LowAIConfidence);
// Set winning outcome and mark as resolved
market.winning_outcome = Some(winning_outcome_index);
market.resolved = true;
// Increment resolution count
ctx.accounts.ai_resolver.resolution_count = ctx.accounts.ai_resolver.resolution_count.checked_add(1).unwrap();
msg!("Market resolved by AI with outcome: {}, confidence: {}", winning_outcome_index, ai_confidence_score);
msg!("Resolution data: {}", resolution_data);
Ok(())
}