Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prediction Markets Protocol - Smart Contract Description
Overview
The Prediction Markets Protocol is a decentralized binary prediction market platform built on the Stacks blockchain using Clarity smart contract language. It enables users to create event-based markets, stake STX tokens on YES/NO outcomes, and receive proportional payouts when markets are resolved.
Core Mechanics
Market Lifecycle
Creation Phase: Any user can create a prediction market by defining a question (up to 256 characters), an end-time for betting, and a resolution-time when outcomes can be determined.
Betting Phase: Users place bets by locking STX tokens on either YES or NO outcomes. All funds are held in the contract and contribute to the total prize pool. Bets can only be placed while the market is open and before the end-time block height is reached.
Resolution Phase: After the resolution-time, the designated resolver (typically the market creator) declares the winning outcome. This finalizes the market and enables winners to claim their rewards.
Claiming Phase: Users who bet on the winning outcome can claim their proportional share of the entire prize pool, calculated as:
(user_winning_bet / total_winning_bets) × total_pool_size - platform_fee.Payout Distribution
The protocol uses a parimutuel betting system where:
Example: If the total pool is 300 STX (100 on YES, 200 on NO) and YES wins, a user who bet 50 STX on YES receives:
(50/100) × 300 = 150 STX - 2% fee = 147 STX(a 194% return).Key Features
Dynamic Odds Calculation
The contract provides real-time probability estimates based on the current distribution of bets:
This creates a live market where odds shift as more users participate.
Security & Access Control
Position Tracking
Each user's position is tracked independently per market, recording:
This allows users to bet multiple times on the same outcome or hedge by betting on both sides.
Technical Implementation
Data Storage
Token Flow
stx-transfer?claim-winnings, which transfers STX from the contract back to their walletError Handling
The contract implements 11 distinct error codes covering scenarios like:
Advanced Functionality
Market Management
Read-Only Queries
Users can query without gas costs:
Use Cases
Financial Markets
Sports & Entertainment
Political & Social Events
Governance & DAOs
Economic Model
Incentive Structure
Market Efficiency
As more participants join, odds converge toward true probabilities through crowd wisdom. The parimutuel system ensures the contract remains solvent since all payouts come from the pool itself, not from external reserves.
Limitations & Considerations
Oracle Problem
The contract relies on trusted resolvers to report outcomes honestly. There's no built-in dispute resolution or decentralized oracle integration, making resolver integrity critical.
Liquidity Risk
Markets with one-sided betting create poor odds for latecomers. A market with 100 STX on YES and 0 on NO offers no return for YES bettors even if they win.
Time Dependency
All timing uses block heights rather than timestamps, providing manipulation resistance but requiring block height calculations for real-world time predictions.
No Secondary Market
Users cannot exit positions before resolution or transfer betting positions to others, limiting liquidity and flexibility.
Future Enhancements
Potential upgrades could include:
Technical Specifications