Skip to content

pkprajapati7402/dike-protocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DIKE Protocol β€” The Multiverse Market

A Next-Generation Prediction Market with Branching Predictions, AMM Liquidity, and Human-Verified Outcomes

DIKE Protocol Solidity Next.js

🌌 Overview

DIKE Protocol reimagines prediction markets by introducing prediction trees and multiverse branching. Traditional prediction markets force users to split capital between predictions, limiting upside. DIKE changes that by allowing users to leverage up to 60% of their initial capital to create "child" predictions without needing additional fundsβ€”creating a compounding effect where wins branch into further wins, multiplying outcomes far beyond the usual 2x ceiling.

Key Innovations

  • 🌳 Prediction Trees: Start with one stake, branch into multiple predictions using leverage
  • πŸ’° AMM-Powered Liquidity: Enter and exit positions at fair, liquid prices without order books
  • βœ… Human-Verified Resolution: Outcomes resolved by KYCed validators verified using Self protocol
  • πŸ” Risk-Managed Leverage: Protocol loans for branching, reclaimed with interest upon resolution
  • πŸ“Š Stable Trading Environment: PyUSD stablecoin base for volatility protection
  • πŸ›‘οΈ Sybil-Resistant Validation: Decentralized identity verification prevents manipulation

πŸ—οΈ Project Structure

dike-protocol/
β”œβ”€β”€ client/                    # Frontend application (Next.js)
β”‚   β”œβ”€β”€ app/                   # Next.js app directory
β”‚   β”‚   β”œβ”€β”€ api/               # API routes (resolution, verification)
β”‚   β”‚   β”œβ”€β”€ chains/            # Chain-specific pages
β”‚   β”‚   β”œβ”€β”€ create-predic/     # Prediction creation interface
β”‚   β”‚   β”œβ”€β”€ dashboard/         # User dashboard
β”‚   β”‚   β”œβ”€β”€ predictions/       # Predictions listing
β”‚   β”‚   β”œβ”€β”€ profile/           # User profile
β”‚   β”‚   β”œβ”€β”€ swap/              # Swap interface
β”‚   β”‚   └── landing/           # Landing page
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ ui/                # Reusable UI components (badge, button, card, etc.)
β”‚   β”‚   β”œβ”€β”€ prediction-details-modal.tsx
β”‚   β”‚   β”œβ”€β”€ chain-visualization.tsx
β”‚   β”‚   β”œβ”€β”€ opportunity-card.tsx
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ createOpportunity.ts
β”‚   β”‚   β”œβ”€β”€ useInvestInPrediction.ts
β”‚   β”‚   β”œβ”€β”€ useIPFS.ts
β”‚   β”‚   β”œβ”€β”€ useReadChains.ts
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ lib/                   # Utility functions
β”‚   β”‚   β”œβ”€β”€ ipfs.ts
β”‚   β”‚   β”œβ”€β”€ utils.ts
β”‚   β”‚   └── ...
β”‚   └── package.json           # Frontend dependencies
β”‚
└── dike-contracts/            # Smart contracts (Solidity)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ Dike.sol           # Core protocol contract
    β”‚   β”œβ”€β”€ FullDike.sol       # Extended protocol features
    β”‚   β”œβ”€β”€ Swap.sol           # Swap/AMM logic
    β”‚   └── Counter.sol        # Example contract
    β”œβ”€β”€ test/                  # Test files
    β”‚   β”œβ”€β”€ Dike.t.sol
    β”‚   β”œβ”€β”€ Swap.t.sol
    β”‚   └── Counter.t.sol
    β”œβ”€β”€ script/                # Deployment scripts
    β”‚   β”œβ”€β”€ DeployDike.s.sol
    β”‚   β”œβ”€β”€ DeployFullDike.s.sol
    β”‚   └── DeploySwap.s.sol
    β”œβ”€β”€ lib/                   # Dependencies (Foundry)
    β”‚   β”œβ”€β”€ forge-std/
    β”‚   β”œβ”€β”€ openzeppelin-contracts/
    β”‚   β”œβ”€β”€ pyth-sdk-solidity/
    β”‚   └── openzeppelin-foundry-upgrades/
    β”œβ”€β”€ foundry.toml           # Foundry configuration
    └── package.json           # Contract dependencies

πŸš€ Core Features

1. Prediction Trees & Multiverse Branching

Users start with an initial stake and can create child predictions using up to 60% leverage without additional capital. This creates a branching structure where:

  • Initial prediction resolves β†’ User can branch into new predictions
  • Wins compound across branches
  • Capital efficiency maximized through protocol-provided loans

2. AMM-Powered Market Making

  • Decentralized liquidity pools replace traditional order books
  • Dynamic odds adjustment based on user trades
  • Continuous price discovery
  • Fair entry and exit prices for all participants
  • Liquidity providers earn fees

3. Human-Verified Resolution

  • Price-based predictions: Resolved via Pyth Network price feeds (tamper-proof, real-time)
  • Event-based predictions: Resolved by KYCed human validators
  • Validators verified through Self protocol QR-based identity verification
  • Sybil-attack resistant through decentralized identity validation
  • Near real-time sync between off-chain verification and on-chain validator registry

4. Protocol Loans & Risk Management

  • Leverage for branching provided as protocol loans
  • Loans reclaimed with interest upon prediction resolution
  • Liquidation protection: Positions below loan + interest threshold are liquidated
  • Self-sustaining and capital-efficient system

5. Stable Trading with PyUSD

  • PyUSD (PayPal's stablecoin) as base currency
  • Protects users from protocol token volatility
  • Creates more resilient and trustworthy market environment

πŸ› οΈ Technology Stack

Smart Contracts

  • Language: Solidity 0.8+
  • Framework: Foundry
  • Network: Sepolia testnet
  • Key Integrations:
    • Pyth Network: Price feeds for deterministic outcome resolution
    • OpenZeppelin: Contract standards and upgradeable patterns
    • PyUSD: Stablecoin for trading

Frontend

  • Framework: Next.js 14+
  • Language: TypeScript
  • Styling: CSS (custom) with Tailwind CSS support
  • State Management: React hooks, wagmi for blockchain interaction
  • UI Components: Custom component library (Badge, Button, Card, Dropdown, etc.)
  • Key Libraries:
    • Wagmi: Ethereum React hooks
    • IPFS: Distributed file storage (useIPFS hook)
    • Self SDK: KYC verification integration

Backend

  • Verification Service: Self KYC integration
  • API Routes: Next.js API routes for:
    • /api/resolution - Prediction resolution
    • /api/verify - User/validator verification
  • Chain Interaction: Direct smart contract calls for on-chain operations

πŸ“‹ API Endpoints

Verification API

POST /api/verify

Handles KYC verification through Self protocol, creates validator registry entries.

Resolution API

POST /api/resolution

Triggers prediction resolution with price feeds (Pyth) or human validators.

πŸ”„ User Journey

  1. User Registration: KYC verification through Self
  2. Create Prediction: Initialize with capital stake
  3. Trade: Use AMM to adjust positions at fair prices
  4. Branch Predictions: Leverage up to 60% for child predictions
  5. Resolution:
    • Automatic for price-based (Pyth feeds)
    • Human-verified for events (KYCed validators)
  6. Settle: Claim winnings, protocol reclaims loans + interest

πŸ“Š Prediction Market Mechanics

AMM Formula

The protocol uses custom AMM logic for dynamic odds:

  • Prices adjust based on liquidity and trade volume
  • Fairness ensured through constant product formulas
  • No order book dependencies

Leverage & Branching

Max Child Prediction Capital = Initial Stake Γ— 0.60
Number of Branches = No limit (per liquidity)
Compounding Effect = Child Wins β†’ More Capital for Grandchildren

Liquidation Threshold

If Position Value < (Loan Amount + Interest):
  β†’ Position Liquidated
  β†’ Collateral Returned (after loan repayment)

πŸ” Security & Validation

Sybil Resistance

  • All validators KYCed through Self protocol
  • QR-code based verification flow
  • Each person = one validator identity
  • Off-chain verification synced on-chain in near real-time

Outcome Verification

Prediction Type Resolution Method Security
Price Predictions Pyth Network feeds Cryptographic proof, tamper-proof
Event Predictions Human validators KYC-verified, Sybil-resistant

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • Git
  • Foundry (for smart contracts)
  • Wallet with Sepolia testnet funds

Installation

Frontend Setup

cd client
npm install
npm run dev

Smart Contracts Setup

cd dike-contracts
forge install
forge test
forge script script/DeployDike.s.sol --rpc-url sepolia

πŸ“ Smart Contracts

Core Contracts

Dike.sol

Main protocol contract handling:

  • Prediction creation and management
  • Branching logic and capital allocation
  • Loan accounting and interest calculation
  • Integration with Pyth price feeds

FullDike.sol

Extended features including:

  • Advanced branching scenarios
  • Enhanced liquidity management
  • Multi-stage predictions

Swap.sol

AMM swap and liquidity pool logic:

  • Dynamic fee calculation
  • Liquidity provider management
  • Order execution and price discovery

πŸ§ͺ Testing

Run Contract Tests

cd dike-contracts
forge test

Run Frontend Tests

cd client
npm run test

πŸ“± Frontend Pages

  • Landing (/landing): Project introduction
  • Dashboard (/dashboard): User overview and portfolio
  • Create Prediction (/create-predic): Prediction initialization
  • Predictions (/predictions): Browse all active predictions
  • Chains (/chains/[id]): Chain-specific market data
  • Swap (/swap): Direct token swapping
  • Profile (/profile): User account settings
  • KYC Test (/kyc-test): Verification workflow testing

🎯 How It's Made

  1. Smart Contracts: Solidity contracts deployed on Sepolia handle prediction trees, branching logic, loan accounting, and AMM mechanics
  2. Price Feeds: Integrated Pyth Network for tamper-proof, real-time price data
  3. Human Validation: Self KYC SDK provides decentralized identity verification with QR-code authentication
  4. Stable Base: PyUSD stablecoin ensures market stability
  5. Frontend: Next.js application with wagmi for seamless blockchain interaction
  6. Backend Bridge: API routes connect off-chain verification with on-chain contracts

Technical Highlights

  • QR-based KYC approval flow synced with contract validator registry
  • Custom AMM engine for dynamic odds without order books
  • Protocol-managed loans for leverage without external capital
  • Sybil-resistant validator selection through decentralized identity

🌐 Deployment

Contracts deployed on Sepolia testnet. Deployment scripts in dike-contracts/script/.

Broadcast Records

Deployment history tracked in dike-contracts/broadcast/

πŸ“š Documentation

  • DEPLOYMENT.md: Detailed deployment instructions
  • SELF_VERIFICATION_README.md: Self KYC integration guide
  • Smart Contract ABIs: Available in client/app/abi.ts

🀝 Contributing

Contributions welcome! Please ensure:

  • All tests pass
  • Code follows Solidity and TypeScript conventions
  • New features include tests
  • README updated for significant changes

πŸ“„ License

[Add appropriate license]

πŸ™‹ Support

For questions or issues:

  • Review documentation in contract README files
  • Check API endpoint specifications
  • Test on Sepolia testnet first

DIKE Protocol: Transforming prediction markets into living multiverse strategies where capital compounds, liquidity flows freely, and outcomes are verified by trusted, decentralized validators.

About

A Next-Generation Prediction Market with Branching Predictions, AMM Liquidity, and Human-Verified Outcomes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published