Skip to content

Cassxbt/Chancemarket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrivatePredict

Privacy-preserving prediction markets with multi-model AI resolution, powered by Chainlink CRE.

Chainlink Convergence Hackathon 2026


Prize Tracks

Track Prize Our Approach
Prediction Markets $16K Parimutuel markets with commit-reveal privacy, time-weighted shares, and principal protection
Privacy $16K Confidential HTTP for secret AI key handling in CRE secure enclaves
CRE & AI $17K Multi-model AI consensus (OpenAI GPT-4o-mini + Gemini 2.0 Flash) via CRE workflow
thirdweb x CRE Plans thirdweb SDK for wallet connect, contract reads/writes

Architecture

User (Browser)
  |
  v
Frontend (Next.js 16 + thirdweb SDK)
  |-- Markets board with live on-chain data
  |-- Trade ticket: commit-reveal betting flow
  |-- Create market form
  |
  v
Smart Contracts (Sepolia)
  |-- MarketFactory.sol         Deploy new prediction markets with duration
  |-- PrivateMarket.sol         Parimutuel betting + time-weighted shares + principal protection
  |-- CREConsumer.sol           ReceiverTemplate -> forwards CRE reports to markets
  |-- MockUSDC.sol              Test payment token (6 decimals)
  |
  v
CRE Workflow (private-predict)
  |-- main.ts                   Log trigger: listens for SettlementRequested events
  |-- ai-resolver.ts            Queries OpenAI + Gemini via Confidential HTTP
  |-- evm.ts                    Encodes report, signs with ECDSA, submits on-chain

How It Works

  1. Anyone creates a market with a question and duration (5 min to 30 days).
  2. Users commit private bets (YES/NO direction hidden via keccak256 hash).
  3. Early bettors get 1.0x shares; late bettors decay to 0.2x (time-weighted).
  4. 1% fee deducted on each bet.
  5. Market closes. Bettors reveal within 24h.
  6. Anyone calls requestSettlement() -> emits SettlementRequested event.
  7. CRE workflow detects the event via EVM log trigger.
  8. Workflow queries both Gemini and OpenAI via Confidential HTTP.
    • API keys injected inside CRE enclave (never in code/logs).
    • Both models return YES/NO/INCONCLUSIVE with confidence (0-10000).
  9. Multi-model consensus: both must agree or result is INCONCLUSIVE.
  10. Signed report submitted to CREConsumer.onReport() -> PrivateMarket.resolveFromOracle().
  11. Winners claim payouts: principal protection (deposit back) + share of losing pool.

Privacy Features

  • Commit-reveal betting: Directions hidden until reveal. Commitment = keccak256(sender, predictedYes, salt, amount, marketAddress).
  • Confidential HTTP: AI API keys stored in CRE vault secrets, injected at runtime inside secure enclaves.
  • Minimum bet: 1 USDC floor prevents dust analysis.
  • Reveal deadline: 24-hour window prevents indefinite exposure.
  • Unrevealed recovery: Miss the window? Reclaim full deposit via reclaimUnrevealed().

Parimutuel Model (Inspired by Pumpcade)

  • Time-weighted shares: First 10% of duration = fair launch (1.0x multiplier). Then linear decay to 0.2x.
  • Principal protection: Winners always get their net deposit back, plus proportional share of the losing pool.
  • 1% fee: Deducted before shares calculation. Owner can withdraw accumulated fees.

Project Structure

private-prediction-market/
|-- contracts/
|   |-- src/
|   |   |-- CREConsumer.sol           ReceiverTemplate implementation
|   |   |-- PrivateMarket.sol         Market logic with commit-reveal + time-weighted shares
|   |   |-- MarketFactory.sol         Factory with duration validation (5min - 30 days)
|   |   |-- MockUSDC.sol              Test ERC-20 token
|   |   |-- interfaces/               CRE receiver interfaces
|   |-- test/
|   |   |-- MarketFactory.ts          8 tests covering full lifecycle
|   |-- script/
|       |-- deploy.ts                 Deployment script
|       |-- create-market.ts          Market creation script
|
|-- cre-workflow/
|   |-- project.yaml                  RPC endpoints
|   |-- secrets.yaml                  API key mappings (OPENAI_API_KEY, GEMINI_API_KEY)
|   |-- private-predict/
|       |-- workflow.yaml             Workflow config
|       |-- config.json               Runtime config (models, chain, addresses)
|       |-- main.ts                   Log trigger + handler entry point
|       |-- ai-resolver.ts            Multi-model AI via Confidential HTTP
|       |-- evm.ts                    Report encoding + on-chain write
|       |-- types.ts                  Zod schemas + TypeScript types
|       |-- package.json              @chainlink/cre-sdk 0.0.8-alpha
|
|-- frontend/
    |-- app/                          Next.js 16 pages (markets, market detail, create, portfolio)
    |-- components/                   React components (trade ticket, evidence panel, etc.)
    |-- lib/                          On-chain reads, ABI definitions, commitment hashing

Chainlink CRE Files

All CRE workflow files are in cre-workflow/private-predict/:

File Purpose
main.ts Entry point: EVM log trigger for SettlementRequested, handler calls AI + submits report
ai-resolver.ts Confidential HTTP requests to OpenAI + Gemini, multi-model consensus aggregation
evm.ts ABI-encodes settlement report, signs with ECDSA/keccak256, writes via EVMClient.writeReport()
types.ts Zod config schema, AI response validation, TypeScript types
config.json Runtime config: model names, chain selector, market addresses, consumer address
workflow.yaml Workflow name, artifact paths
../project.yaml RPC endpoints for Sepolia
../secrets.yaml Secret name mappings for vault

Setup

Prerequisites

  • Node.js 18+ and Bun
  • CRE CLI (curl -sSL https://cre.chain.link/install.sh | bash)
  • Sepolia testnet ETH
  • API keys: OpenAI, Gemini
  • thirdweb client ID

Install & Deploy

# Contracts
cd contracts
npm install
npx hardhat compile
npx hardhat test               # 8 tests pass
npx hardhat run script/deploy.ts --network sepolia

# CRE Workflow
cd cre-workflow/private-predict
bun install                    # runs cre-setup postinstall
cre login                      # authenticate with CRE

# Set API keys for simulation
export OPENAI_API_KEY_VAR=sk-...
export GEMINI_API_KEY_VAR=AIza...

# Simulate workflow (needs a SettlementRequested tx hash)
cre workflow simulate private-predict --target local-simulation

# Frontend
cd frontend
npm install
npm run dev                    # http://localhost:3000

Environment Variables

# .env (root)
SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
PRIVATE_KEY=0x...
NEXT_PUBLIC_FACTORY_ADDRESS=0x...
NEXT_PUBLIC_CRE_CONSUMER_ADDRESS=0x...
NEXT_PUBLIC_THIRDWEB_CLIENT_ID=...
NEXT_PUBLIC_CHAIN_ID=11155111
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=AIza...

Smart Contract API

MarketFactory

Function Description
createMarket(question, duration) Deploy a new market (duration: 5min - 30 days)
getMarkets(offset, limit) Paginated market address list
totalMarkets() Count of deployed markets

PrivateMarket

Function Description
placeBet(commitment, amount) Commit encrypted bet (min 1 USDC, 1% fee)
calculateShares(netAmount) View time-weighted share calculation
revealBet(predictedYes, salt) Reveal within 24h after close
requestSettlement() Emit SettlementRequested for CRE
claimPayout() Claim winnings (principal + share of losers)
claimRefund() Full refund if market cancelled
reclaimUnrevealed() Reclaim if reveal window missed
getPotentialPayout(bettor) View expected payout

CREConsumer

Function Description
onReport(metadata, report) CRE entry point (forwarder only)

Deployed Contracts (Sepolia)

Contract Address
MarketFactory 0xeA22DD09934Bf7cbFcE2E6A69A42E81337096607
CREConsumer 0xfef343d4091aAE2bE292693D864c4286522cE80b

Live Markets

Market Address
Will the Fed deliver at least one rate cut by June 2026? 0x1f38938C92545986b96fEA4305C4A2208A8b4D87
Will G7 announce expanded coordinated sanctions before Aug 2026? 0x0DA3eE89A5FEfD4CffBABE4D8573CE6791bBCf67
Will Nigeria headline CPI print below 20% by Dec 2026? 0x4A2C6dA438020B4EA6B279f04338E48989Fab73C

Tests

8 tests covering the full market lifecycle:

  PrivatePredict core contracts
    ✓ creates a market with duration and pays winner with principal protection
    ✓ applies time-weighted shares correctly (early vs late bettor)
    ✓ rejects onReport from non-forwarder address
    ✓ rejects bets below minimum amount
    ✓ returns full amount (including fee) when market is cancelled
    ✓ assigns sequential market IDs
    ✓ rejects invalid durations
    ✓ allows fee withdrawal by owner

Technology Stack

Layer Technology
Smart Contracts Solidity 0.8.24, Hardhat, OpenZeppelin
CRE Workflow TypeScript, @chainlink/cre-sdk 0.0.8-alpha, Zod
AI Models OpenAI GPT-4o-mini, Google Gemini 2.0 Flash
Frontend Next.js 16, React 19, thirdweb SDK
Chain Ethereum Sepolia Testnet

License

MIT

About

Privacy-preserving prediction markets. Commit-reveal betting, multi-model AI resolution via Chainlink CRE, parimutuel payouts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors