Skip to content

Prediction Market Solana powered by Meteora DLMM, built with the Anchor framework

Notifications You must be signed in to change notification settings

Novus-Tech-LLC/Prediction-Market-Solana

Repository files navigation

Solana Prediction Market

The Solana Prediction Market is a decentralized trading platform that leverages Meteora's Dynamic Liquidity Market Makers (DLMM) SDK and the Anchor framework. It enables participants to express their outlook on market events through YES/NO positions while maintaining deep, balanced liquidity across outcomes.

flowchart TD
    A[Frontend\nNext.js] --> B[Backend\nAPI Routes]
    B --> C[Supabase\nDatabase]
    A --> D[Solana\nBlockchain]
    D --> E[prediction-market\nProgram]
    E --> F[Pyth Oracle]
    C -->|Market Data| A
    E -->|On-chain Data| A
Loading

Overview

This project demonstrates how liquidity depth can be used as the primary signal for market confidence and price discovery. Instead of simply tracking token price fluctuations, the platform derives market odds from the balance and depth of the underlying liquidity pools. The richer the liquidity on a given outcome, the stronger the conviction reflected in the market price.

Key Features

  • Dual Pool Architecture: Maintains separate YES and NO liquidity pools for every market.
  • Liquidity-Weighted Odds: Calculates market confidence based on available liquidity rather than spot prices alone.
  • Automated Oracle Resolution: Integrates with the Pyth Network for trustworthy market outcomes.
  • Adaptive Fee Model: Adjusts fees dynamically to discourage pool imbalance and incentivize participation.
  • Robust Safeguards: Includes validation layers and overflow protection to preserve market integrity.
  • Solana-Native Performance: Built to take advantage of Solana’s high-throughput execution environment.

Contact & Support

Questions, feedback, or partnership inquiries can be directed via Telegram.

Related Projects

Architecture

Core Components

  1. Global State: Program-wide configuration and statistics
  2. Markets: Individual prediction markets with metadata
  3. Pools: YES/NO liquidity pools using constant product AMM
  4. Positions: User trading positions and P&L tracking
  5. Users: User statistics and activity tracking
classDiagram
    class Market {
        +creator: Pubkey
        +title: String
        +status: MarketStatus
        +yes_pool: Pubkey
        +no_pool: Pubkey
        +oracle_account: Option<Pubkey>
    }
    
    class Pool {
        +liquidity: u64
        +fee_rate: u8
        +token_mint: Pubkey
    }
    
    class User {
        +positions: Vec<Pubkey>
        +balance: u64
    }
    
    Market "1" *-- "2" Pool
    User "1" *-- "*" Position
Loading

Account Structure

Market Account

pub struct Market {
    pub creator: Pubkey,           // Market creator
    pub title: [u8; 64],          // Market question
    pub status: MarketStatus,      // Active/Resolved/Cancelled
    pub end_time: i64,             // Resolution deadline
    pub yes_pool: Pubkey,          // YES outcome pool
    pub no_pool: Pubkey,           // NO outcome pool
    pub oracle_account: Option<Pubkey>, // Price feed
    pub target_price: Option<u64>, // Oracle target
    // ... additional fields
}

Development Environment

Frontend Architecture

  • Next.js 14 App Router
  • Tailwind CSS with custom configuration
  • Radix UI component library
  • Wallet integration through @solana/wallet-adapter
graph TD
    App[App Router] --> Layout
    Layout --> Navbar
    Layout --> ThemeProvider
    App --> MarketGrid
    MarketGrid --> MarketCard
    MarketCard --> TradingInterface
    TradingInterface --> WalletButton
Loading

Testing

Run the full test suite:

pnpm test:all  # Runs both frontend and program tests

Deployment

# Frontend
pnpm build
pnpm start

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

Contributing Guidelines

  1. Fork the repository.
  2. Create a feature branch for your update.
  3. Open a pull request with a clear summary of the changes.

Known Issues and Roadmap

Critical Priority

Database Relationships

  • Issue: Manual joins in lib/database-service-relationship-fix.ts instead of relying on database constraints.
  • Solution:
    • Add foreign key constraints in the Supabase schema.
    • Update definitions in scripts/001-initial-schema.sql.
    • Remove manual join logic from the service layer.
  • Files to Modify:
    • scripts/001-initial-schema.sql
    • lib/database-service-relationship-fix.ts

Fee Distribution

  • Issue: Fee accounting is unimplemented in lib/dlmm-real-fixed.ts.
  • Solution:
    • Implement fee collection during swaps.
    • Distribute fees proportionally to liquidity providers.
    • Add fee tracking within the database.
  • Files to Modify:
    • lib/dlmm-real-fixed.ts
    • lib/database-service-fixed.ts
    • types/database-fixed.ts

Oracle Integration

  • Issue: Market coverage is limited to ETH, BTC, and SOL in lib/dlmm-real-fixed.ts.
  • Solution:
    • Make the oracle symbol configurable per market.
    • Add dynamic price-feed resolution.
    • Support custom target prices.
  • Files to Modify:
    • lib/dlmm-real-fixed.ts
    • types/market.ts
    • programs/pool-odds/src/lib.rs

Token Mints

  • Issue: Placeholder tokens remain in the swap workflow (lib/dlmm-real-fixed.ts).
  • Solution:
    • Use production token mints from market configuration.
    • Add token mint validation.
    • Update the swap transaction builder.
  • Files to Modify:
    • lib/dlmm-real-fixed.ts
    • lib/transaction-service.ts
    • types/dlmm.ts

High Priority

  • Service Consolidation: Competing fixed vs standard implementations.
  • Market Resolution: Complete support for all market types.
  • Error Handling: Enhance recovery logic and consistency.
  • Configuration: Replace hardcoded values with a configuration system.

Medium Priority

  • UI Loading States: Add skeletons and better loading indicators.
  • Market Stats: Provide tooltips and supporting explanations.
  • Health Checks: Implement comprehensive system monitoring.
  • Testing: Expand automated coverage.

Low Priority (Technical Debt)

  • Style System: Standardize CSS classes.
  • Error States: Improve UI for error conditions.
  • Fallbacks: Refine fallback mechanisms.
  • Logging: Enhance logging granularity.

License

MIT

Prediction-Market-Solana

About

Prediction Market Solana powered by Meteora DLMM, built with the Anchor framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published