Skip to content

Conversation

@Jagadeeshftw
Copy link
Contributor

Summary

Implements event archive and historical query support for resolved/cancelled markets and fixes three existing payout tests that were failing because resolve_market_manual already calls distribute_payouts internally.

Changes

Test fixes (existing failures)

  • Cause: resolve_market_manual calls distribute_payouts internally, so a second call saw all winners as claimed and returned 0.
  • Update: In test_automatic_payout_distribution, test_market_state_after_claim, and test_integration_full_market_lifecycle_with_payouts:
    • Removed the extra distribute_payouts call.
    • Assert resolution and payout by checking market.state == Resolved and market.claimed for winners/losers.

Event archive and historical query (#271)

Types

  • Added EventHistoryEntry in types.rs: public metadata only (no votes, stakes, or addresses) — market_id, question, outcomes, end_time, created_at, state, winning_outcome, total_staked, archived_at, category.

New module: event_archive.rs

  • archive_event(env, admin, market_id) — Admin-only; archives a resolved or cancelled market. Uses Error::InvalidState / Error::AlreadyClaimed (no new error variants to stay within #[contracterror] limit).
  • is_archived(env, market_id) — Returns whether a market is archived.
  • query_events_history(env, from_ts, to_ts, cursor, limit) — Events by creation time range; paginated; limit capped at 30.
  • query_events_by_resolution_status(env, status, cursor, limit) — Events by MarketState (e.g. Resolved, Cancelled).
  • query_events_by_category(env, category, cursor, limit) — Events by oracle feed_id (category).

Public API in lib.rs

  • archive_event(env, admin, market_id) -> Result<(), Error>
  • query_events_history(env, from_ts, to_ts, cursor, limit) -> (Vec<EventHistoryEntry>, u32)
  • query_events_by_status(env, status, cursor, limit) -> (Vec<EventHistoryEntry>, u32) (name kept ≤ 32 chars)
  • query_events_by_category(env, category, cursor, limit) -> (Vec<EventHistoryEntry>, u32)

Security / design

  • Archive and query expose only public metadata and outcome; no sensitive data (votes, stakes, addresses).
  • Queries are gas-bounded via pagination and MAX_QUERY_LIMIT = 30.
  • Existing event storage and resolution behavior is unchanged.

Tests

  • Archive: resolved market archive, unauthorized, active market rejected, already archived (success then panic on second archive).
  • Queries: time range, by resolution status, by category, pagination, and that EventHistoryEntry contains only public fields.

Testing

  • cargo build — success
  • cargo test -p predictify-hybrid398 tests passed (including 3 fixed payout tests and 10 new archive/query tests)

Closes #271

- Introduced EventArchive module for archiving resolved/cancelled events and querying historical data.
- Implemented methods for archiving events, checking archived status, and querying events by creation time, resolution status, and category.
- Added EventHistoryEntry struct to encapsulate public metadata for historical queries.
- Updated lib.rs to expose new functionalities and added corresponding tests for event archiving and querying.
@Jagadeeshftw
Copy link
Contributor Author

@greatest0fallt1me review please

@greatest0fallt1me
Copy link
Contributor

Looks great, @Jagadeeshftw! I hope to see more of your work in the future.

@greatest0fallt1me greatest0fallt1me self-requested a review January 29, 2026 20:29
@greatest0fallt1me greatest0fallt1me merged commit 6e74598 into Predictify-org:master Jan 29, 2026
1 check 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.

feat: implement event archive and historical query support

2 participants