refac: update market state types and logic#136
Merged
greatest0fallt1me merged 5 commits intoJul 8, 2025
Conversation
Contributor
Author
|
@greatest0fallt1me ptal |
Contributor
|
@Akshola00 Can you please fix the build errors? |
Contributor
Author
|
https://github.com/Predictify-org/predictify-contracts/actions/runs/16125121817/job/45500086589 |
Contributor
|
@Akshola00 Its fixed now, can you please sync with master? |
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.
Add Explicit Market State Management with State Transitions
Overview
This PR introduces explicit state management for prediction markets, replacing the previous implicit state derivation with a proper state machine implementation. This change improves reliability, clarity, and enables better event tracking for market lifecycle management.
Key Changes
1. Explicit State Field Addition
state: MarketStatefield to theMarketstructMarket::new()constructor to accept initial state parameterMarketState::Active2. State Transition Logic
MarketStateLogicmodule with comprehensive state management:validate_state_transition(): Enforces valid state transitionscheck_function_access_for_state(): Validates function calls against current stateemit_state_change_event(): Publishes state change eventsvalidate_market_state_consistency(): Ensures data consistency3. Enhanced State Transitions
4. Method Signature Updates
All state-modifying methods now accept optional
market_idparameter for event emission:add_vote()→add_vote(market_id: Option<&Symbol>)add_dispute_stake()→add_dispute_stake(market_id: Option<&Symbol>)mark_claimed()→mark_claimed(market_id: Option<&Symbol>)set_winning_outcome()→set_winning_outcome(market_id: Option<&Symbol>)mark_fees_collected()→mark_fees_collected(market_id: Option<&Symbol>)5. Automatic State Transitions
Ended→Disputed(with event emission)Ended/Disputed→Resolved(with event emission)Resolved→Closed(with event emission)6. Market Lifecycle Improvements
remove_market(): Ensures proper state transition toClosedbefore removalMarketCreatorcloses #59