Skip to content

refac: update market state types and logic#136

Merged
greatest0fallt1me merged 5 commits into
Predictify-org:masterfrom
Akshola00:Akshola00/issue59
Jul 8, 2025
Merged

refac: update market state types and logic#136
greatest0fallt1me merged 5 commits into
Predictify-org:masterfrom
Akshola00:Akshola00/issue59

Conversation

@Akshola00

@Akshola00 Akshola00 commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

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

  • Added state: MarketState field to the Market struct
  • Updated Market::new() constructor to accept initial state parameter
  • Modified all market creation calls to explicitly set MarketState::Active

2. State Transition Logic

  • New MarketStateLogic module with comprehensive state management:
    • validate_state_transition(): Enforces valid state transitions
    • check_function_access_for_state(): Validates function calls against current state
    • emit_state_change_event(): Publishes state change events
    • validate_market_state_consistency(): Ensures data consistency

3. Enhanced State Transitions

  • Active → Ended/Cancelled/Closed/Disputed
  • Ended → Resolved/Disputed/Closed/Cancelled
  • Disputed → Resolved/Closed/Cancelled
  • Resolved → Closed
  • Closed/Cancelled: Terminal states

4. Method Signature Updates

All state-modifying methods now accept optional market_id parameter 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

  • Dispute submission: EndedDisputed (with event emission)
  • Resolution: Ended/DisputedResolved (with event emission)
  • Fee collection: ResolvedClosed (with event emission)

6. Market Lifecycle Improvements

  • Enhanced remove_market(): Ensures proper state transition to Closed before removal
  • Fee processing: Re-enabled market creation fee processing in MarketCreator
  • State validation: Function calls now validate against current market state

closes #59

@Akshola00

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me ptal

@greatest0fallt1me greatest0fallt1me requested review from Jagadeeshftw and greatest0fallt1me and removed request for Jagadeeshftw July 7, 2025 04:37
@Akshola00 Akshola00 marked this pull request as ready for review July 7, 2025 05:17
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Akshola00 Can you please fix the build errors?

@Akshola00

Copy link
Copy Markdown
Contributor Author

https://github.com/Predictify-org/predictify-contracts/actions/runs/16125121817/job/45500086589
@greatest0fallt1me the problem originates from the last merge not from my impl

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

@Akshola00 Its fixed now, can you please sync with master?

@greatest0fallt1me greatest0fallt1me merged commit f79892a into Predictify-org:master Jul 8, 2025
0 of 2 checks passed
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.

Create Market State Enum and State Transition Management

2 participants