What This Template Does
This template implements the full prediction market lifecycle using three CRE workflows that share a single PredictionMarket smart contract:
- Market Creation (Cron, hourly) โ Creates new binary prediction markets with configurable strike prices and expiration times
- Market Resolution (Cron, every 10 minutes) โ Checks expired markets and resolves them using the Chainlink BTC/USD Data Feed
- Dispute Management (LogTrigger) โ Listens for
DisputeRaisedevents and re-evaluates outcomes with fresh price data
Key Technologies:
- CRE (Chainlink Runtime Environment) โ Multi-workflow orchestration with DON consensus
- Chainlink Data Feeds โ Deterministic BTC/USD price resolution
- LogTrigger + Cron โ Event-driven disputes with periodic creation and resolution
How It Works
Market Creation
Market Resolution
Dispute Management
Project Structure
prediction-market-ts/
โโโ contracts/ # Shared contracts and bindings
โโโ market-creation/ # Workflow 1: Create markets
โโโ market-resolution/ # Workflow 2: Resolve expired markets
โโโ market-dispute/ # Workflow 3: Handle disputes
Getting Started
1 Install dependencies
cd contracts && bun install && cd ..
cd market-creation && bun install && cd ..
cd market-resolution && bun install && cd ..
cd market-dispute && bun install && cd ..
2 Run tests
cd market-creation && bun test && cd ..
cd market-resolution && bun test && cd ..
cd market-dispute && bun test && cd ..
3 Simulate workflows
Market Creation:
cre workflow simulate market-creation --target staging-settings
Market Resolution:
cre workflow simulate market-resolution --target staging-settings
Dispute Management (requires a transaction that emitted DisputeRaised):
cre workflow simulate market-dispute --target staging-settings \
--non-interactive \
--trigger-index 0 \
--evm-tx-hash <TX_THAT_EMITTED_DISPUTE_RAISED> \
--evm-event-index 0
Broadcast any workflow to write on-chain:
cre workflow simulate market-creation --target staging-settings --broadcast
4 Deploy your own contract
A demo contract is pre-deployed on Sepolia at 0xEb792aF46AB2c2f1389A774AB806423DB43aA425.
To deploy your own with Foundry:
forge create src/PredictionMarket.sol:PredictionMarket \
--broadcast --private-key $PRIVATE_KEY \
--rpc-url https://ethereum-sepolia-rpc.publicnode.com \
--constructor-args \
0x15fc6ae953e024d975e77382eeec56a9101f9f88 \
0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 \
86400
Constructor arguments:
- Forwarder:
0x15fc6ae953e024d975e77382eeec56a9101f9f88 - Price Feed:
0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43(BTC/USD on Sepolia) - Dispute Window:
86400(24 hours in seconds)
Customization
- Use a different asset โ Deploy with a different
priceFeedaddress (e.g., ETH/USD:0x694AA1769357215DE4FAC081bf1f309aDC325306) - Change market duration โ Update
durationSecondsinmarket-creation/config.staging.json - Change resolution frequency โ Update
scheduleinmarket-resolution/config.staging.json - Change dispute window โ Deploy a new contract with a different
disputeWindowarg
For full details, see the TypeScript README on GitHub.
CREATED BY CHAINLINK LABS