Skip to content

oracle support#438

Open
rouzwelt wants to merge 18 commits into2026-03-27-v6-calldata-fixfrom
2026-04-03-oracle-support
Open

oracle support#438
rouzwelt wants to merge 18 commits into2026-03-27-v6-calldata-fixfrom
2026-04-03-oracle-support

Conversation

@rouzwelt
Copy link
Copy Markdown
Collaborator

@rouzwelt rouzwelt commented Apr 3, 2026

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Josh Hardy and others added 13 commits February 23, 2026 20:21
1. Add meta field to subgraph queries for order discovery
2. Create oracle module with:
   - extractOracleUrl() placeholder for meta parsing
   - fetchSignedContext() for batch oracle requests
   - Support for batch format (array of contexts)
3. Wire oracle into quoting logic:
   - Extract oracle URL from order meta before quote2
   - Fetch signed context and inject into takeOrder struct
   - Graceful fallback on oracle failures
4. Ensure signed context flows through to takeOrdersConfig

The solver now automatically fetches oracle data for orders that
specify an oracle-url, enabling external data integration.
- Fix ethers v6 → v5 APIs (defaultAbiCoder, arrayify)
- Use ABI.Orderbook.V5.OrderV4 constant instead of hardcoded tuple string
- Add 5s timeout on oracle fetch via AbortController
- Validate SignedContextV1 shape on each response entry
- Extract fetchOracleContext helper to deduplicate quote logic
- Remove noisy console.warn from stub extractOracleUrl
- Type OracleOrderRequest.order properly instead of any
Replace ethers.utils.defaultAbiCoder/arrayify with viem's
encodeAbiParameters/hexToBytes. Use proper viem ABI parameter
definitions instead of string-based encoding.
- Up to 2 retries with exponential backoff (500ms, 1s)
- After 3 consecutive failures, oracle URL enters 5min cooloff
- During cooloff, requests to that URL are skipped immediately
- Cooloff resets on first successful response
- Invalid responses (bad shape, wrong length) also count as failures
- All configurable via module constants
No retries, no delays in the loop. Single attempt with 5s timeout —
if it fails, record the failure and move on. After 3 consecutive
failures the URL enters a 5min cooloff where it's skipped immediately
(no network call at all). This way one bad oracle can't block the
processing of other orders.
…ager

Extract oracle cooloff tracking from module-level singleton into an
OracleManager class. Instance lives on OrderManager, threaded through
to quote functions. This makes it properly scoped to the solver
instance lifecycle and testable.

- OracleManager class in src/oracle/manager.ts
- fetchSignedContext takes OracleManager as parameter
- OrderManager creates and owns the OracleManager instance
- OracleManager is optional in quote functions for backward compat
Follow codebase conventions:
- Oracle health map lives on SharedState.oracleHealth
- fetchOracleContext is a standalone fn with this: SharedState,
  called via .call(state) like processOrder/findBestTrade
- Health helpers (isInCooloff, recordOracleSuccess/Failure) are
  plain exported functions operating on the health map
- No new classes, no module-level singletons
- quoteSingleOrder receives SharedState to thread through
- fetchSignedContext returns Result<SignedContextV1[], string>
- fetchOracleContext returns Result<void, string>
- Callers check .isErr() instead of try/catch
- Follows codebase convention for error handling
…terface

- OracleOrderRequest.order uses Order.V3 | Order.V4 from order/types
- OracleOrderRequest.counterparty typed as 0x
- Drop custom SignedContextV1 interface — signed context is already
  typed as any[] on TakeOrderV3/V4, and the response validation
  ensures the right shape at runtime
- fetchSignedContext returns Result<any[], string> matching the
  existing signedContext field type
- extractOracleUrl: implement CBOR meta parsing (was a stub returning null)
- Add oracleUrl field to PairBase, thread through V3/V4 fromArgs
- Add meta field to SgOrder type (already in subgraph query)
- fetchOracleContext: use pair.oracleUrl instead of dead (pair as any).meta
- Switch from batch to single request encoding to match oracle server spec
- Restrict oracle requests to V4 orders only
- Strip internal type discriminant before ABI encoding
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5658f5f-d767-4e5d-ad1c-988ca92a4994

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-04-03-oracle-support

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant