Skip to content

feat(contract): pool validations + multisig emergency cancel (#1119, #1122, #1130, #1131)#1308

Merged
Yunusabdul38 merged 1 commit into
Web3Novalabs:mainfrom
Divine-designs:feat/issues-1119-1122-1130-1131-pool-validations
Jun 30, 2026
Merged

feat(contract): pool validations + multisig emergency cancel (#1119, #1122, #1130, #1131)#1308
Yunusabdul38 merged 1 commit into
Web3Novalabs:mainfrom
Divine-designs:feat/issues-1119-1122-1130-1131-pool-validations

Conversation

@Divine-designs

Copy link
Copy Markdown
Contributor

Summary

Four contract-safety / hardening enhancements in one PR, all touching contracts/predifi-contract/.

Issue #1122 — Validate outcome descriptions bounds on creation

  • New constants MAX_OUTCOME_DESCRIPTION_LEN = 128 and MIN_OUTCOME_DESCRIPTION_LEN = 1.
  • validate_pool_invariants panics on empty or oversized outcome labels.
  • New typed errors OutcomeDescriptionTooLong = 130, OutcomeDescriptionEmpty = 131.

Issue #1130 — Validate staking deadlines are in the future

  • create_pool raises PredifiError::DeadlineInPast = 132 when end_time < current_time (typed, machine-checkable) or when a non-zero start_time is strictly in the past.
  • The legacy assert!(end_time > current_time, ...) is preserved as a boundary diagnostic for end_time == current_time.
  • start_time == 0 remains the "open immediately" sentinel.

Issue #1131 — Add initial liquidity safety margin checks

  • New constant INITIAL_LIQUIDITY_SAFETY_MARGIN_BPS = 100 (1%).
  • When max_total_stake > 0, initial_liquidity must be ≥ max_total_stake * 1%; otherwise InitialLiquidityBelowSafetyMargin = 133 is raised. Skipped entirely when max_total_stake == 0 (uncapped pool).

Issue #1119 — Support multi-sig emergency cancellation

  • New entry point emergency_cancel_pool(approver, pool_id, reason) and read-only get_emergency_cancel_approvals(pool_id) -> Vec<Address>.
  • Threshold EMERGENCY_CANCEL_MULTISIG_THRESHOLD = 2 distinct admin/operator approvals. First approval records intent + reason; subsequent distinct approvals are added; once threshold is met the pool transitions to Canceled via the same path as cancel_pool.
  • Same-address re-approval → EmergencyCancelAlreadyApproved = 135. Non-privileged caller → Unauthorized = 10.
  • New DataKey variants EmergencyCancelApprovers(pool_id) and EmergencyCancelReason(pool_id), both cleared on execution.

Baseline-fix included

main did not compile in test mode on entry:

  • lib.rs referenced ClaimWindowUpdateEvent without importing it (recently moved into events mod).
  • lib.rs referenced PredifiError::TimeConstraintError which did not exist on the local enum.

The PR re-exports events into the lib module (pub use events::*;) and adds the missing TimeConstraintError = 84 variant so both cargo build --release --target wasm32-unknown-unknown and cargo test --lib now succeed.

Tests

Verification

cd contract
cargo build --release --target wasm32-unknown-unknown -p predifi-contract   #
cargo test -p predifi-contract --lib                                         # ✅ 386 passed, 0 failed

Closes #1119
Closes #1122
Closes #1130
Closes #1131

…alabs#1119, Web3Novalabs#1122, Web3Novalabs#1130, Web3Novalabs#1131)

Closes Web3Novalabs#1119, Web3Novalabs#1122, Web3Novalabs#1130, Web3Novalabs#1131.

Issue Web3Novalabs#1122 — outcome description bounds:
- New constants MAX_OUTCOME_DESCRIPTION_LEN (128) and MIN_OUTCOME_DESCRIPTION_LEN (1).
- validate_pool_invariants now panics if any outcome description is empty
  or exceeds 128 bytes, preventing unbounded persistent-storage growth
  and useless empty labels.
- New errors OutcomeDescriptionTooLong (130) and OutcomeDescriptionEmpty (131).

Issue Web3Novalabs#1130 — staking deadlines must be in the future:
- create_pool now returns the typed PredifiError::DeadlineInPast (132)
  when end_time < current_time, replacing the legacy assert string
  ("end_time must be in the future") which remains as a boundary
  diagnostic for end_time == current_time.
- Non-zero start_time strictly in the past is also rejected.
- start_time == 0 remains the "open immediately" sentinel.

Issue Web3Novalabs#1131 — initial-liquidity safety margin:
- New constant INITIAL_LIQUIDITY_SAFETY_MARGIN_BPS (100 = 1%).
- When max_total_stake > 0, initial_liquidity must cover at least 1% of
  max_total_stake; otherwise PredifiError::InitialLiquidityBelowSafetyMargin
  (133) is raised. Skipped entirely when max_total_stake == 0 ("no cap").

Issue Web3Novalabs#1119 — multi-sig emergency cancellation:
- New constant EMERGENCY_CANCEL_MULTISIG_THRESHOLD (2 distinct approvals).
- New entry point `emergency_cancel_pool(approver, pool_id, reason)`.
  Admin/operator addresses each call once; the first call records the
  reason and proposer's approval, subsequent distinct calls add their
  approval. Once the threshold is reached the pool transitions to
  MarketState::Canceled via the same path as cancel_pool. Same-address
  re-approval is rejected with EmergencyCancelAlreadyApproved (135).
  Non-privileged callers are rejected with Unauthorized (10).
- New DataKey variants EmergencyCancelApprovers(pool_id) and
  EmergencyCancelReason(pool_id), both cleared on execution.
- New read-only `get_emergency_cancel_approvals(pool_id) -> Vec<Address>`.

Baseline fix (required for any test build to succeed):
- `mod events; pub use events::*;` re-exports event types into the lib
  module so usages like `ClaimWindowUpdateEvent` resolve.
- Added missing `TimeConstraintError = 84` variant referenced in two
  existing call sites. These broke the lib test build on main; the
  baseline now compiles cleanly for both `cargo build --release
  --target wasm32-unknown-unknown` and `cargo test --lib`.

Tests:
- 13 new tests covering all four issues (3 for Web3Novalabs#1122, 3 for Web3Novalabs#1130,
  3 for Web3Novalabs#1131, 4 for Web3Novalabs#1119).
- 1 existing test (test_pool_end_time_at_leap_day_already_past)
  updated to expect the typed `Web3Novalabs#132` error instead of the legacy
  assert message — same behavior, stronger error reporting.

Verification:
- `cargo test -p predifi-contract --lib` → 386 passed, 0 failed.
- `cargo build --release --target wasm32-unknown-unknown -p predifi-contract` → clean.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Divine-designs is attempting to deploy a commit to the shola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Divine-designs 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

@Yunusabdul38 Yunusabdul38 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for your contribution

@Yunusabdul38 Yunusabdul38 merged commit 535b4c1 into Web3Novalabs:main Jun 30, 2026
0 of 3 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

2 participants