Skip to content

Architecture: outcome resolution scattered across three independent paths with no coordinating module #75

@heyitsStylez

Description

@heyitsStylez

Problem

A trade's outcome can be set by five independent paths, none of which are coordinated:

  1. User input — form submit in edit modal
  2. Rysk oracleresolveRyskOutcomes() (~line 116)
  3. Hypersurface redeemActionsresolveHsfcOutcomes() (~line 284)
  4. CoinGecko historical priceautoDetectOutcomes() (~line 413)
  5. Time-based stale detection — inline in autoLoadChain (~line 475)

There is no module whose interface is "given a trade and resolution signals, what is its outcome?" The precedence rules (oracle beats CoinGecko, etc.) are implicit in execution order, not written anywhere. A reader who wants to understand outcome resolution must trace all five paths.

Files involved

  • src/js/18-chain-sync.js
  • src/js/18b-chain-apply.js

Proposed solution

A single pure resolveOutcome(trade, signals) → outcome function. Each sync source becomes a producer of signals (oracle price, redeemAction, CoinGecko price, "expired by time"). resolveOutcome owns the priority logic.

Benefits

  • Precedence rules are written in one place — readable and auditable
  • Adding a new resolution source is one new signal type, not a new mutation path
  • Fully unit-testable: pass a trade + signals, assert the returned outcome
  • Eliminates duplicate expiry-detection logic currently spread across multiple call sites

Category

Deepening opportunity — architecture review

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageMaintainer needs to evaluate this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions