BitPredict is a Clarity smart contract enabling trustless BTC/USD price speculation markets on Stacks L2. The protocol combines Bitcoin settlement security with Layer 2 scalability, featuring automated market resolution and anti-manipulation mechanisms through Bitcoin-finalized blocks.
- Bitcoin-Native Settlement: Direct price speculation anchored to BTC value
- Enterprise-Grade Throughput: Optimized for high-frequency trading via Stacks L2
- Dynamic Reward Engine: Automated profit distribution with protocol fee capture
- Oracle-Protected Markets: Price resolution through authorized oracle nodes
- Capital Efficiency: Pooled liquidity model with minimized slippage
- Market Structure
{
opening-price: uint, // Initial BTC price in satoshis
closing-price: uint, // Final resolved BTC price
bull-commitment: uint, // Total long positions (STX)
bear-commitment: uint, // Total short positions (STX)
activation-block: uint, // Market start height
expiration-block: uint, // Market end height
resolution-status: bool // Settlement status
}
- Position Management
{
direction: "bull"|"bear", // Market position direction
amount: uint, // STX committed
claimed: bool // Reward claim status
}
- Purpose: Initialize new prediction market
- Parameters:
opening-price
: Initial BTC/USD price (sats)activation-block
: Market start blockexpiration-block
: Market end block
clarinet console> (contract-call? .bitpredict create-market u65000 u15000 u18000)
- Requirements:
- Minimum stake: Configurable (default 1 STX)
- Active market window
- Directions: "bull" (long) or "bear" (short)
clarinet console> (contract-call? .bitpredict take-position u0 "bull" u1000000)
- Oracle Requirements:
- Called by authorized oracle address
- After expiration block
- Sets: Final closing price and resolution status
clarinet console> (contract-call? .bitpredict settle-market u0 u68000)
- Calculation:
gross_reward = (position_amount / winning_pool) * total_commitment protocol_fee = gross_reward * 2% net_payout = gross_reward - protocol_fee
clarinet console> (contract-call? .bitpredict claim-rewards u0)
clarinet console> (contract-call? .bitpredict update-oracle 'STNEWORACLE)
clarinet console> (contract-call? .bitpredict adjust-stake u500000)
clarinet console> (contract-call? .bitpredict get-market-data u0)
clarinet console> (contract-call? .bitpredict get-user-position u0 'STUSER)
Code | Description |
---|---|
100 | Owner-only function |
101 | Invalid parameter |
102 | Resource not found |
103 | Market inactive/closed |
104 | Invalid prediction direction |
105 | Insufficient balance |
106 | Rewards already claimed |
-
Oracle Protection
- Market resolution restricted to pre-authorized oracle
- Final settlement price immutable once set
-
Capital Safeguards
- Funds held in contract escrow until resolution
- STX transfers via Clarity's built-in security
-
Temporal Controls
- Block-height based market windows
- No late positions accepted