Skip to content

Offchain Oracle service that handles the pulling of market price data and pushing to our Probability Oracle

Notifications You must be signed in to change notification settings

metastable-labs/oracle-service

Repository files navigation

Price Oracle Feed

Real-time price oracle updater for prediction markets. Fetches probability prices from Stork and updates on-chain oracle contracts.

How It Works

  1. Event Watching - Durable Object watches blockchain for MarketCreated events in real-time
  2. Initial Price - Fetches current price from Stork REST API and submits to oracle
  3. Real-time Updates - Subscribes to Stork WebSocket for live price feeds
  4. On-chain Updates - Automatically submits signed price changes to oracle contract

Setup

  1. Install dependencies:
npm install
  1. Configure environment variables in .dev.vars:
STORK_API_KEY=your_api_key
PRIVATE_KEY=0x...
BASE_SEPOLIA_RPC_URL=https://...
  1. Update wrangler.toml with your contract addresses:
ORACLE_ADDRESS = "0x..."
MARKET_FACTORY_ADDRESS = "0x..."
WORKER_URL = "https://your-worker.workers.dev"
  1. Add market mappings in src/market-mappings.ts:
export const MARKET_TO_STORK_ASSET: Record<string, string> = {
  'your-source-market-id': 'STORK_ASSET_ID',
};

Deploy

npx wrangler deploy

Initialize

Trigger the initial connection and market sync:

curl https://your-worker.workers.dev/init

Endpoints

  • GET /init - Initialize WebSocket connection and sync markets
  • GET /markets - List all tracked markets
  • POST /add-market - Manually add a market
  • POST /submit-batch - Submit price updates (called by Durable Object)
  • GET /health - Health check

Architecture

  • Cloudflare Workers - Main worker handles HTTP requests and blockchain interactions
  • Durable Objects - Maintains persistent connections:
    • WebSocket connection to Stork for real-time price updates
    • Event watcher for MarketCreated events using viem.watchContractEvent

License

MIT

About

Offchain Oracle service that handles the pulling of market price data and pushing to our Probability Oracle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published