Problem
A trade's outcome can be set by five independent paths, none of which are coordinated:
- User input — form submit in edit modal
- Rysk oracle —
resolveRyskOutcomes() (~line 116)
- Hypersurface redeemActions —
resolveHsfcOutcomes() (~line 284)
- CoinGecko historical price —
autoDetectOutcomes() (~line 413)
- 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
Problem
A trade's outcome can be set by five independent paths, none of which are coordinated:
resolveRyskOutcomes()(~line 116)resolveHsfcOutcomes()(~line 284)autoDetectOutcomes()(~line 413)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.jssrc/js/18b-chain-apply.jsProposed solution
A single pure
resolveOutcome(trade, signals) → outcomefunction. Each sync source becomes a producer of signals (oracle price, redeemAction, CoinGecko price, "expired by time").resolveOutcomeowns the priority logic.Benefits
Category
Deepening opportunity — architecture review