Replace CoinGecko outcome inference with on-chain oracle resolution#63
Merged
Conversation
Rysk outcomes now resolved via /api/expiry-prices (Chainlink settlement price); Hypersurface outcomes via redeemActions on the Goldsky positions subgraph. Fixes two bugs: HSFC trades stuck as OPEN after expiry, and CoinGecko daily-close price misclassifying ITM vs OTM options. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Problem
Two bugs prevented expired PUT/CALL positions from resolving to ASSIGNED or CALLED:
Bug 1 — HSFC correction loop missing. When a Hypersurface trade was synced as OPEN and later expired, subsequent syncs skipped it entirely (already in the
syncedset).autoDetectOutcomeswas never called again, so the trade stayed OPEN indefinitely.Bug 2 — CoinGecko as settlement oracle.
autoDetectOutcomesfetched the CoinGecko historical daily-close price for the expiry date and compared it to the strike. Three failure modes:autoDetectOutcomeswas not wired into any periodic retry; a single failure was finalSolution
Replace CoinGecko inference with authoritative on-chain data, separately for each platform.
Rysk — expiry-prices endpoint (
resolveRyskOutcomes)GET /api/expiry-prices/999/{underlyingAddress}returns{ expiryTimestamp: rawPriceAt1e8 }— the exact Chainlink oracle price the Rysk protocol used at settlement. One call per unique underlying token covers all strikes and expiries for that asset.Resolution:
PUT: settlementPrice ≤ strikePrice → ASSIGNED, elseEXPIREDCALL: settlementPrice ≥ strikePrice → CALLED, elseEXPIREDtxHash(authoritative). Runs every sync — self-correcting over prior CoinGecko misclassifications.Hypersurface — positions + redeemActions (
resolveHsfcOutcomes)A second Goldsky GQL query fetches short positions (
amount_lt:"0") and checksredeemActions. Non-empty = option buyer exercised =ASSIGNED(PUT) orCALLED(CALL). Empty = expired worthless. No price comparison needed.Matched by
platform=HSFC+asset+expiry+strike(within $0.01) +type. Only updatesOPEN/EXPIREDoutcomes —CLOSEDtrades are never touched.autoDetectOutcomes (CoinGecko) — retained for stale-detection only
Still called from
autoLoadChain's boot-time stale-detection loop for locally-known OPEN trades whose expiry passed while the app was closed. For Rysk and HSFC, the oracle resolvers will correct anything CoinGecko guessed once the sync runs. Forplatform='SPOT'(manual entries), CoinGecko remains the only path.Changes
src/js/18-chain-sync.jsfetchRyskExpiryPrices,resolveRyskOutcomes,resolveHsfcOutcomes. RefactoredfetchHsfcGoldsky(url, address)→fetchHsfcGoldsky(url, gqlBody)to share transport between trades and positions GQL calls. Added HSFC OPEN→EXPIRED correction loop (mirroring Rysk's existing one). RemovedautoDetectOutcomescalls fromsyncRyskandsyncHypersurface.api/chain-sync.jstype=expiry-priceshandler for Rysk source, with Ethereum address validation (/^0x[0-9a-fA-F]{40}$/).test/integration/chain-sync-outcomes.test.jsdocs/adr/0005-authoritative-outcome-resolution.mddocs/architecture.mdCLAUDE.md18-chain-sync.jsfile map entry; rewrote chain sync section.Test plan
npm testpasses (99/99, +14 new tests)python3 build.py --checkpasses0xe94a312B9e8B4B5117aEB485dd749c3547aC06C2— verify known cases after deploy:🤖 Generated with Claude Code