Skip to content

Refactor/issue 54 cancel index#329

Merged
hman38705 merged 4 commits intosolutions-plug:mainfrom
Grace-CODE-D:refactor/issue-54-cancel-index
Mar 27, 2026
Merged

Refactor/issue 54 cancel index#329
hman38705 merged 4 commits intosolutions-plug:mainfrom
Grace-CODE-D:refactor/issue-54-cancel-index

Conversation

@Grace-CODE-D
Copy link
Copy Markdown
Contributor

Title: refactor: define and use CANCEL_OUTCOME_INDEX constant instead of raw literal

Body:

Closes #161

Summary

u32::MAX was used as an undocumented sentinel for cancellation votes in two places. This replaces it with a named
constant, making the intent explicit and the value centrally maintainable.

Changes

types.rs
rust
/// Issue #54: Reserved sentinel index for cancellation votes, distinct from any valid outcome index.
pub const CANCEL_OUTCOME_INDEX: u32 = u32::MAX;

cancellation.rs

  • Added CANCEL_OUTCOME_INDEX to the use crate::types import
  • Replaced u32::MAX in the get_tally call with CANCEL_OUTCOME_INDEX

test_cancellation.rs

  • Replaced &u32::MAX with &crate::types::CANCEL_OUTCOME_INDEX in the overflow test

No behaviour change

The constant value is identical to the previous literal — this is a pure readability/maintainability refactor.

Closes solutions-plug#47

- Remove require_admin check from prune_market in markets.rs
- Any user can now prune a resolved market after the 30-day grace period
- Existing guards (Resolved status, grace period, all rewards claimed) remain intact
- Add test_permissionless_prune_by_non_admin to verify non-admin can prune a 31-day-old resolved market
Closes solutions-plug#51

- In cancellation::withdraw_refund, detect when caller is the market creator
- Transfer creation_deposit back and zero it on the market struct (prevents double-claim)
- Emit deposit_refunded event for indexers
- Creator's bet stakes (if any) are still refunded via the normal bettor path
- Add test_creator_deposit_refunded_on_cancellation covering creator refund,
  simultaneous bettor refund, and idempotency of a second creator call
Closes solutions-plug#52

- Replace (cancel_votes * 10000) / total_votes with checked_mul/checked_div
- Overflow maps to InsufficientVotingWeight (safe conservative fallback)
- Add test_cancel_vote_threshold_no_overflow using i128::MAX / 5000 weight
… literal

Closes solutions-plug#54

- Add pub const CANCEL_OUTCOME_INDEX: u32 = u32::MAX to types.rs
- Import and use it in cancellation.rs (get_tally call)
- Replace raw u32::MAX in test_cancellation.rs with crate::types::CANCEL_OUTCOME_INDEX
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 27, 2026

@Grace-CODE-D 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 d1efaae into solutions-plug:main Mar 27, 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

Development

Successfully merging this pull request may close these issues.

Hardcoded Cancel Vote Index (u32::MAX)

2 participants