Skip to content

Implement core prediction market lifecycle & comprehensive documentation#1

Open
philip-hue wants to merge 5 commits intomainfrom
feature/implement-contract
Open

Implement core prediction market lifecycle & comprehensive documentation#1
philip-hue wants to merge 5 commits intomainfrom
feature/implement-contract

Conversation

@philip-hue
Copy link
Owner

Purpose

This PR introduces the foundational components for BitPredict's prediction market protocol, enabling:
✅ User participation tracking
✅ Market creation and resolution
✅ Secure reward distribution
✅ Administrative controls
✅ Developer-friendly documentation

Key Features Implemented

1. User Prediction Management (user-predictions map)

  • Composite key tracking {market-id, principal}
  • Stores prediction direction, stake amount, and claim status
  • Enables granular reward calculation per user

2. Market Interaction Functions

  • make-prediction: Validated STX staking mechanism
  • resolve-market: Oracle-controlled market finalization
  • claim-winnings: Proportional reward distribution with fee deduction

3. Administrative Controls

  • Oracle address management
  • Dynamic minimum stake configuration
  • Platform fee percentage adjustment
  • Secure fee withdrawal mechanism

4. Documentation System

  • Complete protocol specification
  • Usage examples with Clarinet commands
  • Error code reference table
  • Security best practices guide

Impact Analysis

  1. User Experience
  • Clear participation tracking through user-predictions
  • Transparent reward calculation formula
  1. Security
  • Owner-restricted administrative functions
  • STX transfer validation in make-prediction
  • Claim prevention via claimed bool flag
  1. Extensibility
  • Modular market data structure
  • Configurable fee/stake parameters
  • Oracle abstraction layer

…pation

The `user-predictions` map was introduced to enable tracking of user-specific predictions in each market. This map stores the user's prediction ("up" or "down"), their stake amount, and whether they have claimed their rewards.

Key changes:
- Added `user-predictions` map with keys `{market-id: uint, user: principal}`.
- Values include `prediction` (string-ascii 4), `stake` (uint), and `claimed` (bool).

This feature is essential for managing user participation in prediction markets, ensuring accurate reward distribution, and preventing duplicate claims.

Impact:
- Enhances the platform's ability to track user activity in markets.
- Enables secure and transparent reward claiming.
- Lays the groundwork for future features like user-specific analytics.
The `make-prediction` function was added to allow users to place stakes on active prediction markets. This function validates the market's state, ensures the user's stake meets the minimum requirement, and updates both the user's prediction and the market's total stakes.

Key changes:
- Added validation for market activity (start and end block checks).
- Ensured predictions are either "up" or "down" and stakes meet the minimum threshold.
- Transferred the stake amount from the user to the contract.
- Updated the `user-predictions` map to track user-specific predictions and stakes.
- Updated the `markets` map to reflect changes in total stakes for "up" and "down" predictions.

Impact:
- Enables users to actively participate in prediction markets.
- Ensures secure and transparent handling of user stakes.
- Provides the foundation for reward distribution based on market outcomes.
…t resolution and reward distribution

The `resolve-market` and `claim-winnings` functions were added to enable market resolution and allow users to claim their rewards based on the outcome of a prediction market.

Key changes:
- **resolve-market**: Allows the oracle to finalize a market by setting the `end-price` and marking the market as resolved. Includes validation for oracle access, market state, and input parameters.
- **claim-winnings**: Enables users to claim their rewards for a resolved market. Validates the user's prediction, calculates winnings proportionally, deducts platform fees, and transfers the payout.

Impact:
- Ensures markets are resolved securely and transparently by the designated oracle.
- Provides a mechanism for users to claim rewards while enforcing proper validation and fee deductions.
- Enhances the platform's functionality by completing the prediction market lifecycle.
… management

This update introduces administrative functions to manage key contract configurations and handle platform fees. These functions are restricted to the contract owner to ensure secure and controlled updates.

Key changes:
- **set-oracle-address**: Updates the oracle address responsible for market resolution.
- **set-minimum-stake**: Adjusts the minimum stake required for predictions.
- **set-fee-percentage**: Modifies the platform fee percentage applied to winnings.
- **withdraw-fees**: Allows the contract owner to withdraw accumulated platform fees.

Impact:
- Enhances contract flexibility by enabling dynamic updates to critical parameters.
- Provides a secure mechanism for managing platform fees and configurations.
- Ensures compliance with administrative controls for contract operations.
This update introduces a detailed README file to provide clear and structured documentation for the BitPredict project. The README covers all essential aspects of the protocol, including its features, architecture, and usage instructions.

Key changes:
- Added an overview of BitPredict's functionality and purpose.
- Documented key features such as market mechanics, economic model, and technical specifications.
- Included contract architecture details with core data structures and state management.
- Provided installation instructions for setting up the project locally.
- Listed error codes with descriptions for better debugging and understanding.
- Detailed administrative functions for contract configuration and fee management.
- Highlighted security considerations to ensure safe and reliable usage.
- Added a contributing guide for developers to collaborate on the project.

Impact:
- Improves developer onboarding by providing clear and concise documentation.
- Enhances project transparency and usability for contributors and users.
- Establishes a foundation for future updates and community engagement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant