Outcome token reconciliation jhayniffy - #674
Merged
Mimah97 merged 2 commits intoJul 30, 2026
Merged
Conversation
Position (market storage) and OutcomeToken balances can diverge from a historical bug, a partial upgrade, or a manual admin mint/burn issued directly on the outcome-token contract. Trading and settlement previously assumed the two ledgers always matched. - get_position_token_parity(market_id, user): read-only view comparing Position shares against OutcomeToken balances. - Guard on update_position and settle_position (plus batch/page settlement): reject with ContractError::PositionTokenMismatch on divergence, emitting PositionTokenMismatchDetected. No silent re-sync. - Admin-gated reconcile_position_tokens(admin, market_id, user): mints/burns OutcomeToken balances to match Position (Position is the source of truth), emitting PositionTokensReconciled. No-op when already matched. - Tests in contracts/market/src/reconciliation.rs force divergence via an out-of-band mint on the outcome-token contract and assert trading/ settlement are blocked until repaired. - Docs: contracts/outcome-token/README.md (new), cross-contract-call-graph.md, events-reference.md. Also fixes two small pre-existing compile breaks uncovered while wiring this up: a missing ContractError::InvalidThresholdQuorum variant referenced by set_threshold_signers, and a Result-vs-Vec return type mismatch in TreasuryContract::market_contract/list_markets.
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #660
This PR introduces position-to-token reconciliation to ensure market position shares always remain consistent with YES/NO outcome token balances. It adds parity validation, blocks trading and settlement when inconsistencies are detected, and provides an admin-only repair mechanism with full auditability.
Changes
Added get_position_token_parity(market_id, user) view to compare stored position shares with outcome token balances.
Added reconciliation guards to update_position and settle_position that reject operations when a mismatch is detected.
Implemented admin-gated reconcile_position_tokens to restore ledger consistency using a documented reconciliation policy.
Emitted events for mismatch detection and successful reconciliation.
Added tests covering ledger divergence, blocked trading/settlement, authorized repair, and successful recovery.
Updated outcome-token documentation and cross-contract call graph with the reconciliation flow.
Why
This prevents inconsistencies between market storage and outcome token balances from creating exploitable states or preventing users from settling positions. The reconciliation flow ensures dual ledgers remain consistent, making settlement deterministic, auditable, and production-ready.