Skip to content

fix: infer hardcoded oracle assumptions in path warnings#499

Merged
antoncoding merged 7 commits intomasterfrom
fix/oracle-assumption-warnings
Apr 20, 2026
Merged

fix: infer hardcoded oracle assumptions in path warnings#499
antoncoding merged 7 commits intomasterfrom
fix/oracle-assumption-warnings

Conversation

@starksama
Copy link
Copy Markdown
Collaborator

@starksama starksama commented Apr 19, 2026

Summary

  • treat DAI and USDS as the same UI-resolution group so sUSDS/USDT paths no longer warn just because the route uses DAI/USD
  • keep exact path cancellation for warning text, then infer likely hardcoded assumptions from peg metadata when a route still mismatches the market
  • upgrade the mismatch message to show the actual resolved path plus inferred assumptions like cbBTC <> BTC peg and USDC <> USD peg

Validation

  • custom tsx path-check script covering:
    • cbBTC / USDC with BTC / USD only -> infers cbBTC <> BTC and USDC <> USD
    • sUSDS / USDT with sUSDS/USDS + DAI/USD + USDT/USD -> resolves cleanly
    • WETH / USDC with ETH/USD + USDC/USD -> still resolves cleanly
  • pnpm lint:check
  • pnpm typecheck

Summary by CodeRabbit

  • Bug Fixes

    • Improved feed-path validation with more flexible symbol matching, clearer mismatch messages, and inferred assumptions to aid diagnosis.
  • New Features

    • Added two new peg categories and updated token metadata to recognize additional pegged assets.
    • Refined price estimation to handle different peg types explicitly and better fill missing prices.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
monarch Ready Ready Preview, Comment Apr 20, 2026 6:30am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Warning

Rate limit exceeded

@antoncoding has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 40 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 12 minutes and 40 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5abcac90-cf0d-4126-b539-9d66b541c66b

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf763e and ed14c90.

📒 Files selected for processing (1)
  • src/utils/oracle.ts
📝 Walkthrough

Walkthrough

validateFeedPaths (src/utils/oracle.ts) was reworked to cancel numerator/denominator legs by exact symbol matching, produce actualPath from strict leftovers, and infer inferredAssumptions via peg-anchor aliases; CheckFeedsPathResult now includes actualPath? and inferredAssumptions?. TokenPeg adds XRP and HYPE. Market price fallback logic was simplified to use a peg-based estimator and a fillMissingPrice helper.

Changes

Cohort / File(s) Summary
Oracle feed-path logic
src/utils/oracle.ts
Rewrote validateFeedPaths to track numerator/denominator arrays and perform exact cancellation, compute actualPath from strict leftovers, infer inferredAssumptions via peg-anchor aliasing and supportedTokens, adjust mismatch message formatting, and extend CheckFeedsPathResult with optional actualPath and inferredAssumptions.
Token metadata
src/utils/tokens.ts
Added TokenPeg.XRP and TokenPeg.HYPE enum members and set peg for WHYPE and cbXRP in supportedTokens.
Subgraph market transform
src/data-sources/subgraph/market.ts
Refactored getEstimateValue to switch on token.peg (USD→1, ETH/BTCmajorPrices[...], others→undefined) and added fillMissingPrice to populate missing loan/collateral prices unconditionally.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the core objective: inferring hardcoded oracle assumptions in path warnings to improve mismatch messages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/oracle-assumption-warnings

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils/oracle.ts`:
- Around line 332-340: getPegAnchor currently resolves a token peg by
symbol-only which can return incorrect pegs for duplicate/cross-chain symbols;
change getPegAnchor(symbol: string) to accept chain-scoped identity (e.g.,
getPegAnchor(chainId: number, address?: string, symbol?: string) or
getPegAnchor(tokenMeta: TokenMetadata)) and use chainId + lowercase address (or
tokenMeta.uniqueKey) to find the exact supportedTokens entry instead of
normalizeSymbol(symbol); update the lookup in supportedTokens.find(...) to
compare chainId and canonical address/uniqueKey (and fall back to symbol only as
last resort), and update all callers to pass the chain-scoped token info (or
token metadata) so identity checks follow the required chain-scoped canonical
identifier rule.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c8f81e03-0dc2-41ea-b93b-0d18fe7579d3

📥 Commits

Reviewing files that changed from the base of the PR and between 176adfc and 98406d7.

📒 Files selected for processing (1)
  • src/utils/oracle.ts

Comment thread src/utils/oracle.ts Outdated
@starksama
Copy link
Copy Markdown
Collaborator Author

Addressed the follow-up issues:\n- cbXRP / XRP now infers both hardcoded assumptions ( and )\n- warning copy now uses a newline plus instead of stacking everything into one sentence\n- tightened so symbol-based peg inference only returns a peg when all supported-token matches agree, which avoids ambiguous symbol collisions\n\nRe-validated with the local path-check script plus

monarch@1.0.0 lint:check /Users/anton/projects/monarch
biome check

Checked 635 files in 1417ms. No fixes applied. and

monarch@1.0.0 typecheck /Users/anton/projects/monarch
tsc --noEmit.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Apr 19, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/data-sources/subgraph/market.ts`:
- Around line 52-59: The current logic re-computes both token sides when
!hasUSDPrice and may overwrite an existing direct price with 0 if
getEstimateValue(token.peg) returns undefined (e.g., new XRP/HYPE pegs); change
the flow so you only call getEstimateValue() for the side that is missing
lastPriceUSD and only assign the estimated value if it is not undefined, leaving
the existing direct price unchanged otherwise. Locate the code paths around
token.peg / TokenPeg and majorPrices (and the second similar block at lines
referenced 115-122) and modify them so you check lastPriceUSD per-asset, call
getEstimateValue(token.peg) only for the missing side, and guard assignments
with a !== undefined check before replacing any current price.

In `@src/utils/oracle.ts`:
- Around line 341-350: The current logic builds matchingPegs by filtering out
null pegs which causes collisions with unpegged tokens to be treated as a match;
change the logic in the block that uses supportedTokens, normalizeSymbol and
matchingPegs so you first collect the peg values for all supportedTokens where
normalizeSymbol(supportedToken.symbol) === normalized (including nulls), return
null immediately if any collected peg is null, otherwise dedupe the non-null
pegs (TokenPeg) and return the single peg only if the deduped list length === 1,
else return null; update references to matchingPegs and TokenPeg accordingly.

In `@src/utils/tokens.ts`:
- Around line 17-18: The ERC20Token.peg field is being used both for USD price
fallbacks and for oracle-warning anchors, causing XRP/HYPE (and WHYPE/cbXRP) to
resolve to 0/undefined when market/token-price paths don't provide USD;
introduce a separate field (e.g., oracleAnchor) on the ERC20Token definition and
move XRP and HYPE values to that field for oracle-only use, then update all code
paths that currently read ERC20Token.peg for warnings to use
ERC20Token.oracleAnchor instead; alternatively, if you intend XRP/HYPE to be
used for price fallbacks, add proper price sources for XRP and HYPE to the
market/token-price resolution logic (update token price registry and resolver
functions) so they are resolved instead of falling back to zero. Ensure
references to ERC20Token.peg remain for USD fallbacks and search for uses in
warning/anchor code (e.g., where WHYPE/cbXRP are handled) and replace with the
new oracleAnchor symbol.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c01eb45e-7a2f-492f-8061-c614649f9b24

📥 Commits

Reviewing files that changed from the base of the PR and between 98406d7 and 30c771d.

📒 Files selected for processing (3)
  • src/data-sources/subgraph/market.ts
  • src/utils/oracle.ts
  • src/utils/tokens.ts

Comment thread src/data-sources/subgraph/market.ts
Comment thread src/utils/oracle.ts
Comment thread src/utils/tokens.ts
Comment on lines +17 to +18
XRP = 'XRP',
HYPE = 'HYPE',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Separate oracle anchors from price-estimation pegs.

ERC20Token.peg is used by USD price fallbacks, but XRP/HYPE are not resolved by the market or token-price paths, so WHYPE/cbXRP still fall to 0/undefined when direct USD pricing is missing. If these are only for oracle warnings, use a separate oracle-anchor field; otherwise add XRP/HYPE price sources.

Also applies to: 786-786, 829-829

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/tokens.ts` around lines 17 - 18, The ERC20Token.peg field is being
used both for USD price fallbacks and for oracle-warning anchors, causing
XRP/HYPE (and WHYPE/cbXRP) to resolve to 0/undefined when market/token-price
paths don't provide USD; introduce a separate field (e.g., oracleAnchor) on the
ERC20Token definition and move XRP and HYPE values to that field for oracle-only
use, then update all code paths that currently read ERC20Token.peg for warnings
to use ERC20Token.oracleAnchor instead; alternatively, if you intend XRP/HYPE to
be used for price fallbacks, add proper price sources for XRP and HYPE to the
market/token-price resolution logic (update token price registry and resolver
functions) so they are resolved instead of falling back to zero. Ensure
references to ERC20Token.peg remain for USD fallbacks and search for uses in
warning/anchor code (e.g., where WHYPE/cbXRP are handled) and replace with the
new oracleAnchor symbol.

@antoncoding antoncoding added feature request Specific feature ready to be implemented and removed bug Something isn't working labels Apr 19, 2026
@coderabbitai coderabbitai Bot added bug Something isn't working ui User interface labels Apr 20, 2026
@antoncoding antoncoding merged commit ecba111 into master Apr 20, 2026
4 checks passed
@antoncoding antoncoding deleted the fix/oracle-assumption-warnings branch April 20, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature request Specific feature ready to be implemented ui User interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants