Skip to content

Comments

Feat/cancel market#143

Closed
aji70 wants to merge 10 commits intoNetwalls:mainfrom
aji70:feat/cancel-market
Closed

Feat/cancel market#143
aji70 wants to merge 10 commits intoNetwalls:mainfrom
aji70:feat/cancel-market

Conversation

@aji70
Copy link
Contributor

@aji70 aji70 commented Feb 19, 2026

Implement cancel_market() for creator/admin

Summary

Implements the cancel_market() function so creators or admins can cancel markets before resolution and refund all committed USDC to participants. Closes #64

Changes

contracts/contracts/boxmeout/src/market.rs

  • State & storage

    • Added STATE_CANCELLED = 3
    • Added PARTICIPANTS_KEY and ADMIN_KEY
    • Added MarketError::Unauthorized
  • Initialization

    • Added admin: Address to initialize() (breaking change)
  • Participants tracking

    • Append user to participants list in commit_prediction() for refunds on cancel
  • cancel_market()

    • Requires caller to be creator or admin
    • Rejects cancel when market is RESOLVED or already CANCELLED
    • Refunds USDC to all participants (both commitments and revealed predictions)
    • Sets market state to CANCELLED
    • Emits MarketCancelled event

contracts/contracts/boxmeout/src/factory.rs

  • Added get_admin() for future use

contracts/BUILD.md

  • Updated initialize() example to include admin_address

Acceptance criteria

  • Only creator or admin can cancel
  • Refund all committed USDC to participants
  • Transition status to CANCELLED
  • Emit MarketCancelled event
  • Block cancel on resolved markets
  • Unit tests

Tests added

  • test_cancel_market_creator_refunds_participants – creator cancels and refunds
  • test_cancel_market_admin_refunds_participants – admin can cancel
  • test_cancel_market_unauthorized – non-creator/non-admin fails
  • test_cancel_market_resolved_fails – cannot cancel resolved market
  • test_cancel_market_refunds_predictions – refunds revealed predictions

Breaking change

initialize() now takes admin as the 4th parameter:

// Before
initialize(market_id, creator, factory, usdc_token, oracle, closing_time, resolution_time)

// After
initialize(market_id, creator, factory, admin, usdc_token, oracle, closing_time, resolution_time)

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 21, 2026

@aji70 resolve conflict

@aji70 aji70 closed this Feb 21, 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.

[Contract] Implement cancel_market in Market Contract

2 participants