Skip to content

fix(price-estimation): short-circuit native price#4367

Open
tilacog wants to merge 4 commits intomainfrom
tiago/native-price-shortcircuit
Open

fix(price-estimation): short-circuit native price#4367
tilacog wants to merge 4 commits intomainfrom
tiago/native-price-shortcircuit

Conversation

@tilacog
Copy link
Copy Markdown
Contributor

@tilacog tilacog commented Apr 29, 2026

POST /api/v1/quote fails with "NativeBuy estimator failed: No liquidity" whenever buy_token = BUY_ETH_ADDRESS (0xeee…eee), most likely because Eip4626 tries to detect vault tokens by calling asset() and decimals() on a non-contract sentinel.

The native token and the ETH-flow sentinel both price at 1 native by definition, so there's no point dispatching them to any downstream estimator.

Two short-circuits:

  • CachingNativePriceEstimator (primary): return Ok(1.0) immediately for either token, bypassing cache, Eip4626 wrapper, and all underlying sources.
  • Eip4626::estimate_native_price (secodary, safeguard): pass BUY_ETH_ADDRESS through to the inner estimator without attempting vault detection RPC calls.

…d wrapped native token

POST /api/v1/quote on mainnet fails with "NativeBuy estimator failed: No
liquidity" whenever buy_token = BUY_ETH_ADDRESS (0xeee…eee), because
Eip4626 tries to detect vault tokens by calling asset() on a non-contract
sentinel.

The native token and the ETH-flow sentinel both price at 1 native by definition,
so there's no point dispatching them to any downstream estimator.

Two short-circuits:
- CachingNativePriceEstimator (primary): return Ok(1.0) immediately for
  either token, bypassing cache, Eip4626 wrapper, and all underlying sources.
- Eip4626::estimate_native_price (defence-in-depth): pass BUY_ETH_ADDRESS
  through to the inner estimator without attempting vault detection RPC calls.
@tilacog tilacog requested a review from a team as a code owner April 29, 2026 14:47
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces short-circuiting logic for the native token and the ETH-flow sentinel address in the price estimation service. By returning a fixed price of 1.0 for these addresses, the system avoids unnecessary RPC calls and potential failures in downstream estimators like Eip4626. A high-severity issue was identified where the Eip4626 estimator still delegates the sentinel address to an inner estimator instead of short-circuiting, which could lead to failures in external price sources.

Comment thread crates/price-estimation/src/native/eip4626.rs Outdated
@tilacog tilacog marked this pull request as draft April 29, 2026 15:31
@tilacog
Copy link
Copy Markdown
Contributor Author

tilacog commented Apr 29, 2026

Converting this to a draft for now.
We have turned EIP4626 off again here #4367

@tilacog tilacog marked this pull request as ready for review April 30, 2026 11:16
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements short-circuiting logic for the native token and the ETH-flow sentinel address within the price estimation components. By identifying these tokens in CachingNativePriceEstimator and the Eip4626 estimator, the system now returns a 1:1 price ratio immediately, which prevents unnecessary RPC calls, downstream estimator overhead, and cache pollution. Corresponding tests have been updated to include the required native token configuration and to verify the new short-circuiting behavior. I have no feedback to provide.

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.

2 participants