Technical Documentation
Contract Architecture
The Prediction Protocol is implemented as a Solidity smart contract utilizing a dual-structure system for market management: proposed markets and active markets. This architecture ensures proper governance and validation of markets before they become active.
Visual representation of market contract deployment process
Core Data Structures
Market Struct
struct Market { string question; string subject; string[] outcomes; mapping(uint => uint) outcomeBets; mapping(address => mapping(uint => uint)) userBets; mapping(address => bool) hasWithdrawn; uint resolutionOutcome; bool resolved; uint totalPool; address[] bettors; uint resolutionDate; bool approved; }
Key Mechanisms
Market Proposal Flow
- Requires 1,000 PP Token proposal fee
- Validates resolution date and outcome parameters
- Emits MarketProposed event for indexing
Betting Mechanism
- Implements a 1% platform fee
- Uses proportional payout system based on bet distribution
Resolution & Payout
- Owner-controlled market resolution
- Automatic proportional winnings distribution
- Anti-double-withdrawal protection
Technical Specifications
Contract Details
- Solidity Version: ^0.8.0
- License: MIT
- State Variables: 6
- Public Functions: 7
Gas Optimization
- Efficient mapping structures
- Minimal storage operations
- Optimized array handling
Security Considerations
The contract leverages Solidity 0.8.0's built-in security features, protecting against several critical vulnerabilities:
Automatic Overflow Protection
- Integer overflow/underflow checks (SafeMath no longer required)
- Automatic reversion on arithmetic operations that would overflow
- Protection against wrap-around vulnerabilities in pool calculations
Additional Security Features
- Explicit function visibility requirements
- Stricter type inference rules
- Custom errors for gas optimization
- Prevention of uninitialized storage pointers
Advanced Implementation Details
Memory Management
- Efficient storage packing for gas optimization
- Strategic use of memory vs storage for array operations
- Optimized string handling for market questions and subjects
Event Emission Strategy
// Key Events for External Tracking event MarketCreated(uint marketId, string question, string subject); event BetPlaced(uint marketId, address indexed user, uint outcome, uint amount, uint fee); event MarketResolved(uint marketId, uint outcome); event WinningsDistributed(uint marketId, address indexed user, uint amount);
Mathematical Model
The payout mechanism implements a proportional betting system where:
Payout = (UserBet * TotalPool) / TotalWinningBets where: - UserBet: Individual's bet on winning outcome - TotalPool: Sum of all bets minus platform fees - TotalWinningBets: Sum of all bets on winning outcome
Gas Optimization Techniques
Storage Patterns
- Packed storage variables
- Minimal state modifications
- Strategic use of memory arrays
- Batch updates for gas efficiency
Optimization Metrics
- Market Creation: ~180k gas
- Bet Placement: ~120k gas
- Market Resolution: ~160k gas
- Withdrawal: ~60k gas
Integration Guidelines
Required Interface
interface IBettingMarket { function proposeMarket( string memory question, string memory subject, string[] memory outcomes, uint resolutionDate ) external payable; function placeBet(uint marketId, uint outcomeIndex) external payable; function getAllMarkets() external view returns (...); function getProposedMarkets() external view returns (...); }
Oracle System
Our decentralized oracle network ensures reliable and accurate market resolution through a reputation-based consensus mechanism.
Key Features
- Decentralized network of data providers
- Reputation-weighted consensus mechanism
- Token-based incentive structure
- Real-time accuracy tracking
Technical Implementation
- Secure API endpoints for data submission
- Multi-signature validation process
- Automated reward distribution
- Slashing conditions for malicious behavior
For more details about our oracle system and how to become a data provider, visit our dedicated oracle documentation.
Learn more about our Oracle NetworkFor detailed implementation examples and integration guides, visit our GitHub repository.