Quote signed-context oracles server-side, expose parsedMeta#97
Open
alastairong1 wants to merge 2 commits intoalastair/comprehensive-health-endpointfrom
Open
Quote signed-context oracles server-side, expose parsedMeta#97alastairong1 wants to merge 2 commits intoalastair/comprehensive-health-endpointfrom
alastairong1 wants to merge 2 commits intoalastair/comprehensive-health-endpointfrom
Conversation
Two changes that together let signed-context oracle orders (e.g. SPYM)
return real `ioRatio` values from `/v1/orders/token/*` and
`/v1/orders/owner/*` instead of the `"-"` sentinel:
1. **`fetch_oracle_context` now sends the right body.** The previous
implementation POSTed `abi.encode(empty bytes)` (just `0x20` || `0x00`)
to the maker's oracle URL, which the server (st0x-oracle-server) 400'd
with `Invalid ABI-encoded body`. As a result every signed-context
`quote()` call fell through with empty `signedContext` and the order's
Rainlang reverted with `signed-context out of bounds` — the API then
reported `ioRatio: "-"`, which the frontend would helpfully synthesise
from oracle price plus phantom liquidity.
The fix matches what the oracle server's own smoke test does: it
ABI-encodes the tuple `(OrderV4, U256 inputIOIndex, U256 outputIOIndex,
address counterparty)` via `SolValue::abi_encode`, with `(0, 0,
address(0))` for the IO indices and counterparty. The orderbook
contract then runs the order's full Rainlang including `× baseline-
multiplier`, so the returned `io_ratio` is the exact ratio the order
would fill at right now.
Stale-oracle reverts (`Oracle data stale`) still surface as `"-"` —
that's correct, the order legitimately can't fill outside market hours.
Old orders with deprecated URLs (`/context` instead of `/context/v1`)
404 and also surface as `"-"` — also correct, they can't fill.
Function signature changed from `(oracle_url: &str)` to
`(order: &RaindexOrder, oracle_url: &str)` so we can build the request
body. Success path now logs at INFO so deploys can verify the wiring
without bumping `RUST_LOG`.
2. **`OrderSummary` exposes `parsed_meta: Vec<ParsedMeta>`.** Since the
server now does the oracle plumbing internally, frontends don't need
this field to *quote* — but exposing it lets clients tag oracle-driven
orders in the UI, read `DotrainSourceV1` for strategy configuration,
etc. Mirrors the Rain SDK's `ParsedMeta` enum shape; schema declared
as `Vec<serde_json::Value>` because `ParsedMeta` lives outside this
crate.
Verified on api.preview.st0x.io — INFO logs show
`fetched oracle signed context oracle_url=...context/v1 count=1` for
SPYM orders. `ioRatio` populates when markets are open / oracle data is
fresh; `"-"` only appears for orders that genuinely can't fill.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Two changes that together let signed-context oracle orders (SPYM and
similar) return real
ioRatiovalues from the/v1/orders/*listendpoints instead of the
"-"sentinel:fetch_oracle_contextsends. The existingimplementation POSTed
abi.encode(empty bytes)to the maker's oracleURL — every request 400'd with
Invalid ABI-encoded body. The fixmatches the oracle server's own smoke-test format: it ABI-encodes the
tuple
(OrderV4, U256 inputIOIndex, U256 outputIOIndex, address counterparty)(using0/0/address(0)for the indices andcounterparty). The orderbook then runs the order's full Rainlang —
including
× baseline-multiplier— so the returnedioRatiois theexact ratio the order would fill at right now, not an approximation.
parsed_meta: Vec<ParsedMeta>onOrderSummary. Sincethe server handles oracle plumbing internally, consumers don't need
this to quote. It's exposed for clients that want to surface extra
detail (tagging oracle-driven orders in the UI, reading
DotrainSourceV1for strategy configuration, etc.).Why it was broken
For Pyth-oracle orders (NVDA, MSTR, etc.) the order's Rainlang reads
Pyth's on-chain contract directly —
quote()works without any signedcontext,
ioRatiowas always populated.For signed-context oracle orders (SPYM, where the maker runs their own
off-chain signer), the order's Rainlang reads the price out of
signed-context<col row>()opcodes.quote()without a signed contextreverts (
Oracle data stale,signed-context out of bounds), so theAPI has to POST to the maker's URL first to get the signed payload, then
hand that into
quote()as the 4th arg. The plumbing was wired up butthe request body was wrong.
Verification
Deployed to
api.preview.st0x.io(rest-api-17-link). Server logs show:— SPYM signed-context orders now successfully fetch their signed payload.
ioRatiopopulates when markets are open / oracle data is fresh."-"still appears for orders that genuinely can't fill right now:Oracle data stale(markets closed, last Alpaca quote > 30s old)/contextURLs (now 404)All 208 tests pass.
Notes for review
fetch_oracle_context(oracle_url)→fetch_oracle_context(order, oracle_url)so we can deriveOrderV4from the order to build the request body.debug!toinfo!so deploys canverify the wiring without manually bumping
RUST_LOG.parsed_metafield's utoipa schema isVec<serde_json::Value>because
ParsedMetais defined inrain_orderbook_commonand wedon't want to ToSchema-ify a foreign type. Serialization shape is
unchanged — matches the SDK's TypeScript
ParsedMetaenum.Targeting
alastair/comprehensive-health-endpointbecause that branchholds the rest of the in-flight oracle infrastructure (oracle URL
extraction on
RaindexOrder, the 4-argfetch_order_quotes_batchsignature, etc.). Will rebase once the snapshot is split into per-topic
PRs against main.
🤖 Generated with Claude Code