Skip to content

feat(market): implement close_market with time validation, access control, and MarketClosed event#144

Merged
Olowodarey merged 2 commits into
Arena1X:mainfrom
ussyalfaks:feature/close-market-permissioned-transition
Mar 24, 2026
Merged

feat(market): implement close_market with time validation, access control, and MarketClosed event#144
Olowodarey merged 2 commits into
Arena1X:mainfrom
ussyalfaks:feature/close-market-permissioned-transition

Conversation

@ussyalfaks

@ussyalfaks ussyalfaks commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Closes #51


Summary

Implements close_market in market.rs to transition a market into a closed state
awaiting oracle resolution — with end time validation, duplicate close protection,
oracle/admin access control, event emission, and full unit test coverage across
all three key scenarios.

Changes

  • close_market(env, caller, market_id) — full implementation in market.rs
  • Time guard — returns MarketStillOpen if current_time < market.end_time
  • Resolution guard — returns MarketAlreadyResolved if market.is_resolved == true
  • Access control — validates caller is either admin or config.oracle_address,
    rejects all other callers before any state mutation
  • Market status updated and re-persisted to Soroban storage after all validations pass
  • MarketClosed event emitted post-save with market_id and closing timestamp
  • Unit tests for all 3 scenarios: early close attempt, successful close,
    and double-close attempt

Implementation Notes

  • Validation order: time check → resolution check → access control → state write
    → event emit; keeps cheap checks before storage reads
  • Market re-saved atomically after status update to avoid partial state on failure
  • MarketClosed event emitted only after successful storage write to ensure
    event reflects actual on-chain state
  • Keeper bot compatibility — no special caller type needed; oracle or admin
    address can be held by an automated keeper

Testing Checklist

  • Returns MarketStillOpen when called before market.end_time
  • Returns MarketAlreadyResolved when market.is_resolved == true
  • Unauthorized caller is rejected without mutating market state
  • Market status transitions correctly to closed on valid call
  • Updated market is correctly re-persisted to storage
  • MarketClosed event is emitted with correct market_id and timestamp
  • Double-close attempt returns MarketAlreadyResolved after first close
  • Oracle address can successfully close a market
  • Admin address can successfully close a market

@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview, Comment Mar 24, 2026 10:37pm

@drips-wave

drips-wave Bot commented Mar 24, 2026

Copy link
Copy Markdown

@ussyalfaks 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

@Olowodarey Olowodarey merged commit 87a711e into Arena1X:main Mar 24, 2026
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

Development

Successfully merging this pull request may close these issues.

[Contract] Implement close_market and Market Status Transitions

2 participants