Real-time price oracle updater for prediction markets. Fetches probability prices from Stork and updates on-chain oracle contracts.
- Event Watching - Durable Object watches blockchain for
MarketCreatedevents in real-time - Initial Price - Fetches current price from Stork REST API and submits to oracle
- Real-time Updates - Subscribes to Stork WebSocket for live price feeds
- On-chain Updates - Automatically submits signed price changes to oracle contract
- Install dependencies:
npm install- Configure environment variables in
.dev.vars:
STORK_API_KEY=your_api_key
PRIVATE_KEY=0x...
BASE_SEPOLIA_RPC_URL=https://...
- Update
wrangler.tomlwith your contract addresses:
ORACLE_ADDRESS = "0x..."
MARKET_FACTORY_ADDRESS = "0x..."
WORKER_URL = "https://your-worker.workers.dev"- Add market mappings in
src/market-mappings.ts:
export const MARKET_TO_STORK_ASSET: Record<string, string> = {
'your-source-market-id': 'STORK_ASSET_ID',
};npx wrangler deployTrigger the initial connection and market sync:
curl https://your-worker.workers.dev/initGET /init- Initialize WebSocket connection and sync marketsGET /markets- List all tracked marketsPOST /add-market- Manually add a marketPOST /submit-batch- Submit price updates (called by Durable Object)GET /health- Health check
- 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
MarketCreatedevents usingviem.watchContractEvent
MIT