Skip to content

Fix: 4 issues (#1689, #1690, #1691, #1692) - #1814

Merged
hman38705 merged 3 commits into
solutions-plug:mainfrom
AMV-AUTOS:simple/1689-1690-1691-1692
Oct 19, 2026
Merged

hman38705 merged 3 commits into
solutions-plug:mainfrom
AMV-AUTOS:simple/1689-1690-1691-1692

Conversation

@AMV-AUTOS

Copy link
Copy Markdown
Contributor

Closes #1689
Closes #1690
Closes #1691
Closes #1692

Issues

#1689 Market creator cannot reclaim the creation deposit on a cancelled market unless they also placed a bet

Summary

In withdraw_refund the bet record is loaded (and MarketNotFound returned if absent) before the creator-deposit branch runs. A creator who never bet on the market can never trigger the deposit refund, and release_creation_deposit only works for Resolved markets.

Evidence

  • contracts/predict-iq/src/modules/bets.rs – early return on missing bet
  • contracts/predict-iq/src/modules/bets.rs – deposit branch only reachable after that
  • contracts/predict-iq/src/modules/markets.rs – release requires Resolved

Suggested fix

Allow release_creation_deposit for Cancelled markets (or add a dedicated creator refund entrypoint) independent of any bet.

Acceptance criteria

  • The behaviour described above is fixed or the code/doc is removed as appropriate
  • A regression test (or CI check) covers the change
  • Related docs are updated where they describe this behaviour

Found during a repository-wide review of the code on feat/frontend-redesign; checked against the existing issue list for duplicates.

#1690 Token-mismatch and missing-bet paths return misleading error codes

Summary

place_bet and withdraw_refund return InvalidBetAmount when the supplied token isn't the market token, and withdraw_refund returns MarketNotFound when the caller simply has no bet. Clients (and docs/CONTRACT_ERRORS.md) then show the wrong remedy.

Evidence

  • contracts/predict-iq/src/modules/bets.rs:100 and – InvalidBetAmount for token mismatch
  • contracts/predict-iq/src/modules/bets.rs:351 – MarketNotFound for missing bet

Suggested fix

Add InvalidToken and use BetNotFound/NoWinnings; update CONTRACT_ERRORS.md and the frontend error map.

Acceptance criteria

  • The behaviour described above is fixed or the code/doc is removed as appropriate
  • A regression test (or CI check) covers the change
  • Related docs are updated where they describe this behaviour

Found during a repository-wide review of the code on feat/frontend-redesign; checked against the existing issue list for duplicates.

#1691 Governance guardian-removal voting reuses AlreadyVotedOnUpgrade and GuardianNotSet for unrelated failures

Summary

vote_on_guardian_removal returns AlreadyVotedOnUpgrade for a duplicate removal vote, and GuardianNotSet when the proposal has expired or doesn't exist. These make debugging and client messaging unreliable.

Evidence

  • contracts/predict-iq/src/modules/governance.rs:158 – duplicate-vote errors
  • contracts/predict-iq/src/modules/governance.rs – expired proposal returns GuardianNotSet

Suggested fix

Introduce AlreadyVotedOnRemoval, RemovalNotPending, RemovalExpired error codes and regenerate the docs table.

Acceptance criteria

  • The behaviour described above is fixed or the code/doc is removed as appropriate
  • A regression test (or CI check) covers the change
  • Related docs are updated where they describe this behaviour

Found during a repository-wide review of the code on feat/frontend-redesign; checked against the existing issue list for duplicates.

#1692 cancel_market_vote has no voting-period check and an unchecked tally sum

Summary

A Disputed market is cancelled the instant the cancel tally reaches 75% of votes cast so far — even one early voter with 100% of a tiny tally qualifies — without waiting for the voting period to end. total_votes += tally is also unchecked (panics on overflow).

Evidence

  • contracts/predict-iq/src/modules/cancellation.rs:28 – no time check; unchecked +=

Suggested fix

Require the voting window to have closed (same 72h rule as finalize_resolution) and a quorum, and use checked_add.

Acceptance criteria

  • The behaviour described above is fixed or the code/doc is removed as appropriate
  • A regression test (or CI check) covers the change
  • Related docs are updated where they describe this behaviour

Found during a repository-wide review of the code on feat/frontend-redesign; checked against the existing issue list for duplicates.

Summary

New error codes must be appended after the current maximum (161) to avoid renumbering existing codes, which would break clients and the docs drift test. The docs table is generated by scripts/check-contract-errors.js, so edit errors.rs first and regenerate rather than hand-editing the table. For #1689, prefer restructuring withdraw_refund so the creator-deposit branch is evaluated before the bet lookup, and extend release_creation_deposit to accept Cancelled; keep the zero-before-transfer ordering to prevent double refunds. For #1692, reuse the 72h voting window constant used by finalize_resolution and define an explicit quorum constant; return ArithmeticOverflow on checked_add failure. Run the full contract test suite and the frontend drift test after changes.

Changes

  • Add new error variants to the ErrorCode enum: InvalidToken (for token mismatch in place_bet/withdraw_refund), AlreadyVotedOnRemoval, RemovalNotPending, and RemovalExpired (for guardian-removal voting). BetNotFound (142) and NoWinnings (156) already exist and will be reused. Assign new codes after the current highest (161+), keeping the enum contiguous and documented with doc comments so the docs generator picks them up. (contracts/predict-iq/src/errors.rs)
  • In place_bet, return ErrorCode::InvalidToken instead of InvalidBetAmount when token_address != market.token_address. In withdraw_refund, restructure so the creator-deposit refund path runs independently of bet existence: first check whether the caller is the market creator and the market is Cancelled (or Resolved) with a non-zero creation_deposit, refund it, then attempt to load the bet; if no bet exists return Ok(0) (or BetNotFound only when the caller is not the creator and has no bet) rather than MarketNotFound. Use BetNotFound/NoWinnings where appropriate for missing bet/winnings. Ensure the deposit is zeroed before transfer (checks-effects-interactions) and that a creator who never bet can still reclaim the deposit on a cancelled market. (contracts/predict-iq/src/modules/bets.rs)
  • Extend release_creation_deposit to accept MarketStatus::Cancelled in addition to MarketStatus::Resolved (return MarketNotActive only for other statuses), so a creator can reclaim the creation deposit on a cancelled market independently of any bet. Keep the creator auth check and the zero-before-transfer ordering. (contracts/predict-iq/src/modules/markets.rs)
  • In vote_on_guardian_removal, replace the GuardianNotSet returned when no PendingGuardianRemoval exists with RemovalNotPending; replace the GuardianNotSet returned when the proposal has expired (now - initiated_at > GUARDIAN_REMOVAL_VOTE_WINDOW) with RemovalExpired (still clearing the stale proposal); and replace both AlreadyVotedOnUpgrade returns for duplicate votes with AlreadyVotedOnRemoval. Leave execute_guardian_removal's GuardianNotSet for a genuinely missing guardian set. (contracts/predict-iq/src/modules/governance.rs)
  • In cancel_market_vote, require the voting window to have closed before cancelling: compare e.ledger().timestamp() against the market's dispute/voting start plus the same 72h rule used by finalize_resolution (return VotingNotStarted/VotingEnded or a suitable error if the window is still open), and enforce a quorum on total votes cast (return InsufficientVotingWeight when below quorum). Replace total_votes += ... with checked_add returning ErrorCode::ArithmeticOverflow (or Overflow) on overflow. Keep the existing checked_mul/checked_div threshold math. (contracts/predict-iq/src/modules/cancellation.rs)
  • Add regression tests: (a) a creator who never placed a bet can reclaim the creation deposit on a cancelled market via withdraw_refund/release_creation_deposit; (b) place_bet with a mismatched token returns InvalidToken; (c) withdraw_refund with no bet returns BetNotFound/Ok(0) rather than MarketNotFound. Reuse the existing setup_test_with_token/create_simple_market helpers. (contracts/predict-iq/src/modules/bets_test.rs)
  • Add regression tests for cancel_market_vote: an early vote before the voting window closes is rejected, a tally below quorum is rejected, and the tally sum uses checked arithmetic (no panic on overflow). Also add a test that release_creation_deposit succeeds for a Cancelled market and still rejects non-Resolved/non-Cancelled statuses. (contracts/predict-iq/src/test_cancellation.rs)
  • Add a regression test that release_creation_deposit succeeds for a Cancelled market (creator reclaims deposit) and returns MarketNotActive for Active/PendingResolution/Disputed markets, complementing the existing prune tests. (contracts/predict-iq/src/modules/markets_test.rs)
  • Regenerate the error table by running node scripts/check-contract-errors.js --write after updating errors.rs, so the new variants (InvalidToken, AlreadyVotedOnRemoval, RemovalNotPending, RemovalExpired) appear with correct codes and descriptions, and update the Error Groups section to place them under Betting and Voting & Governance respectively. (docs/CONTRACT_ERRORS.md)
  • Add short labels for the new error codes to CONTRACT_ERROR_LABELS (e.g. InvalidToken -> 'Invalid token', AlreadyVotedOnRemoval -> 'Already voted on removal', RemovalNotPending -> 'Removal not pending', RemovalExpired -> 'Removal expired') so the drift test against docs/CONTRACT_ERRORS.md stays in lockstep and the frontend surfaces the correct remedy. (frontend/src/lib/api/contractErrors.ts)

Co-authored-by: Simple Agent <agent@simple.dev>
@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@AMV-AUTOS 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 and others added 2 commits October 19, 2026 21:41
…e agent)

- contracts/predict-iq/src/errors.rs: merged [markers] — model resolved the conflict markers

Co-authored-by: Simple Agent <agent@simple.dev>
…e agent)

- contracts/predict-iq/src/errors.rs: merged [markers] — model resolved the conflict markers

Co-authored-by: Simple Agent <agent@simple.dev>
@hman38705
hman38705 merged commit 45a61af into solutions-plug:main Oct 19, 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