Skip to content

Fix/issues 403 404 405 406#415

Merged
hman38705 merged 4 commits intosolutions-plug:mainfrom
goldemaverick-ui:fix/issues-403-404-405-406
Mar 29, 2026
Merged

Fix/issues 403 404 405 406#415
hman38705 merged 4 commits intosolutions-plug:mainfrom
goldemaverick-ui:fix/issues-403-404-405-406

Conversation

@goldemaverick-ui
Copy link
Copy Markdown
Contributor

fix: resolve governance types, timelock constants, oracle event metadata, and status query performance (#403 #404 #405 #406)

Summary

This PR addresses four contract-level issues across types.rs, governance.rs, oracles.rs, events.rs, markets.rs, and queries.rs.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

#403 — Add missing timelock config key and bounds constants

governance.rs referenced ConfigKey::TimelockDuration, TIMELOCK_MIN_SECONDS, and TIMELOCK_MAX_SECONDS which were absent from types.rs. Added the missing
TimelockDuration enum variant and the two bound constants (6h min, 7d max). set_timelock_duration now enforces these bounds and the contract builds
cleanly.

#404 — Define missing governance types

types.rs had UpgradeStats and PendingGuardianRemoval defined twice (duplicate struct blocks), causing compile errors. Removed the duplicates, keeping
single canonical definitions with #[contracttype] derives for serialization compatibility. Both types are used correctly by governance.rs and lib.rs.

#405 — Emit accurate oracle source metadata in oracle result events

emit_oracle_result_set was emitting e.current_contract_address() as the oracle address, which is always the PredictIQ contract itself — not the actual
Pyth oracle. The function signature now takes oracle_id: u32 and oracle_source: Address explicitly. set_oracle_result in oracles.rs passes the real oracle
address from market.oracle_config.oracle_address. Updated indexer-facing schema:
topics: [oracle_ok, market_id: u64, oracle_source: Address]
data: (oracle_id: u32, outcome: u32)

All events_test.rs call sites updated to the new signature.

#406 — Optimize status query path to avoid full reverse scan

get_markets_by_status previously iterated all markets in reverse to filter by status — O(N) regardless of how many results were needed. Introduced a
status index using ConfigKey::StatusIndex(status_tag, market_id) persistent keys as a per-status membership set. Status transitions are maintained
automatically in update_market, create_market, and prune_market. get_markets_by_status now probes only the index keys for the requested status bucket,
loading full market records only for confirmed members — reducing complexity to O(limit) storage reads.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Closes #403
Closes #404
Closes #405
Closes #406

… types and timelock constants

- Remove duplicate UpgradeStats and PendingGuardianRemoval struct definitions
  that caused compile errors (types.rs had them defined twice)
- Add TIMELOCK_MIN_SECONDS (6h) and TIMELOCK_MAX_SECONDS (7d) constants
  referenced by governance.rs set_timelock_duration bounds check
- Add ConfigKey::StatusIndex(u32, u64) variant for solutions-plug#406 status index
- Add status_tag() helper mapping MarketStatus to a stable u32 bucket key
- All contracttype derives preserved for serialization compatibility
…scan in get_markets_by_status

- Add ConfigKey::StatusIndex(status_tag, market_id) persistent keys as a
  per-status membership set; each key is O(1) to write and read
- index_market_status(): write index entry on market creation
- deindex_market_status(): remove old bucket entry on status transition
- has_status_index(): probe-only check used by the query path
- update_market(): automatically transitions the index when status changes
- create_market(): indexes new markets under Active on creation
- prune_market(): removes the index entry before deleting the market record
- Remove duplicate get_outcome_stake / set_outcome_stake / set_outcome_bet_count
  / increment_outcome_bet_count definitions that caused compile errors
… index (O(limit) vs O(total))

- Replace full reverse scan with status index probe via has_status_index()
- Only deserialize market records that are confirmed members of the requested
  status bucket — avoids loading every market just to check its status field
- Pagination (offset/limit) preserved with identical semantics
- Gas cost now scales with the number of results returned, not total market count
…le result events

- emit_oracle_result_set() now takes oracle_id (u32) and oracle_source (Address)
  as explicit parameters instead of using e.current_contract_address()
- oracles.rs set_oracle_result(): passes oracle_id and the real oracle contract
  address from market.oracle_config.oracle_address as oracle_source
- Indexer-facing event schema:
    topics: [oracle_ok, market_id: u64, oracle_source: Address]
    data:   (oracle_id: u32, outcome: u32)
- Remove duplicate emit_monitoring_state_reset definition in events.rs
- Update all events_test.rs call sites to new (oracle_id, oracle_source) signature
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Mar 29, 2026

@goldemaverick-ui Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@hman38705 hman38705 merged commit 59221ab into solutions-plug:main Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants