From 048d4b6ff0c7d501660b8bce4f28f6c90c3377a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Fri, 8 May 2026 14:22:00 +0100 Subject: [PATCH 1/3] Pre-cache BUY_ETH_ADDRESS as non-vault --- crates/price-estimation/src/native/eip4626.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/price-estimation/src/native/eip4626.rs b/crates/price-estimation/src/native/eip4626.rs index 802380c45e..904d3e121a 100644 --- a/crates/price-estimation/src/native/eip4626.rs +++ b/crates/price-estimation/src/native/eip4626.rs @@ -7,6 +7,7 @@ use { dashmap::DashSet, ethrpc::{AlloyProvider, alloy::errors::ContractErrorExt}, futures::{FutureExt, future::BoxFuture}, + model::order::BUY_ETH_ADDRESS, num::{BigInt, BigRational, ToPrimitive}, number::conversions::u256_to_big_rational, std::time::{Duration, Instant}, @@ -37,7 +38,7 @@ impl Eip4626 { Self { inner, provider, - non_vault_tokens: DashSet::new(), + non_vault_tokens: DashSet::from_iter([BUY_ETH_ADDRESS]), } } From b8e1b8035acf3957977786f16b5858269e49883a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Fri, 8 May 2026 16:25:08 +0100 Subject: [PATCH 2/3] Add tests for the BUY_ETH_ADDRESS --- crates/e2e/tests/e2e/eip4626.rs | 19 +++++++--- crates/price-estimation/Cargo.toml | 1 + crates/price-estimation/src/native/eip4626.rs | 37 +++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/crates/e2e/tests/e2e/eip4626.rs b/crates/e2e/tests/e2e/eip4626.rs index cfcb2c5607..3d2975c28c 100644 --- a/crates/e2e/tests/e2e/eip4626.rs +++ b/crates/e2e/tests/e2e/eip4626.rs @@ -12,7 +12,10 @@ use { e2e::setup::*, ethrpc::alloy::CallBuilderExt, futures::{FutureExt, future::BoxFuture}, - model::quote::{OrderQuoteRequest, OrderQuoteSide, SellAmount}, + model::{ + order::BUY_ETH_ADDRESS, + quote::{OrderQuoteRequest, OrderQuoteSide, SellAmount}, + }, number::units::EthUnit, price_estimation::{ HEALTHY_PRICE_ESTIMATION_TIME, @@ -20,6 +23,7 @@ use { }, shared::web3::Web3, std::time::Duration, + testlib::tokens::GNO, }; /// The block number from which we will fetch state for the forked test. @@ -265,11 +269,14 @@ async fn eip4626_empty_revert_terminal_token_test(web3: Web3) { let expected_price = 0.0001; let inner = FixedPrice(expected_price); let estimator = Eip4626::new(Box::new(inner), web3.provider); - let price = estimator - .estimate_native_price(USDC, HEALTHY_PRICE_ESTIMATION_TIME) - .await - .expect("empty-revert on terminal token must not abort the unwrap"); - assert_eq!(price, expected_price); + + for token in [BUY_ETH_ADDRESS, USDC, GNO] { + let price = estimator + .estimate_native_price(token, HEALTHY_PRICE_ESTIMATION_TIME) + .await + .expect("empty-revert on terminal token must not abort the unwrap"); + assert_eq!(price, expected_price); + } } struct FixedPrice(f64); diff --git a/crates/price-estimation/Cargo.toml b/crates/price-estimation/Cargo.toml index 42f08ca145..e9024e06f1 100644 --- a/crates/price-estimation/Cargo.toml +++ b/crates/price-estimation/Cargo.toml @@ -61,6 +61,7 @@ mockall = { workspace = true } testlib = { workspace = true } token-info = { workspace = true, features = ["test-util"] } toml = { workspace = true } +ethrpc = {workspace = true, features = ["test-util"]} [features] test-util = ["dep:mockall"] diff --git a/crates/price-estimation/src/native/eip4626.rs b/crates/price-estimation/src/native/eip4626.rs index 904d3e121a..46d3f787da 100644 --- a/crates/price-estimation/src/native/eip4626.rs +++ b/crates/price-estimation/src/native/eip4626.rs @@ -38,6 +38,8 @@ impl Eip4626 { Self { inner, provider, + // BUY_ETH_ADDRESS is not ERC-20, but it is a valid estimation address + // so we need to make sure it bypasses the EIP-4626 estimator non_vault_tokens: DashSet::from_iter([BUY_ETH_ADDRESS]), } } @@ -225,6 +227,8 @@ mod tests { use { super::*, crate::{HEALTHY_PRICE_ESTIMATION_TIME, native::MockNativePriceEstimating}, + alloy::providers::mock::Asserter, + std::borrow::Cow, }; #[test] @@ -254,6 +258,39 @@ mod tests { assert!((rate - 2.0).abs() < 1e-9, "rate={rate}"); } + /// Tests two (related) things: + /// * Cached tokens bypass the EIP-4626 provider calls — i.e. calling decimals, assets, etc + /// * That the BUY_ETH_ADDRESS is cached by default (and the previous applies to it) + #[tokio::test] + async fn buy_eth_address_bypasses_eth_calls() { + let mut inner = MockNativePriceEstimating::new(); + let token = BUY_ETH_ADDRESS; + let expected_price = 1.5; + inner + .expect_estimate_native_price() + .withf(move |t, _| *t == token) + .returning(move |_, _| Box::pin(async move { Ok(expected_price) })); + + let asserter = Asserter::new(); + asserter.push_failure_msg(Cow::from("calls are not being bypassed")); + let web3 = ethrpc::Web3::with_asserter(asserter); + + let estimator = Eip4626::new(Box::new(inner), web3.provider); + + let result = estimator + .estimate(token, HEALTHY_PRICE_ESTIMATION_TIME) + .await; + assert_eq!(result.unwrap(), expected_price); + + let result = estimator + .estimate(Address::random(), HEALTHY_PRICE_ESTIMATION_TIME) + .await; + assert!( + matches!(result, Err(PriceEstimationError::EstimatorInternal(_))), + "{result:?}" + ); + } + #[tokio::test] async fn non_vault_tokens_delegate_to_inner() { let mut inner = MockNativePriceEstimating::new(); From 959449836b0c16d38b19c871779d4194aae6e594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Fri, 8 May 2026 18:49:33 +0100 Subject: [PATCH 3/3] fmt --- crates/price-estimation/Cargo.toml | 2 +- crates/price-estimation/src/native/eip4626.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/price-estimation/Cargo.toml b/crates/price-estimation/Cargo.toml index e9024e06f1..98ea29733c 100644 --- a/crates/price-estimation/Cargo.toml +++ b/crates/price-estimation/Cargo.toml @@ -55,13 +55,13 @@ tracing = { workspace = true } url = { workspace = true } [dev-dependencies] +ethrpc = { workspace = true, features = ["test-util"] } hex-literal = { workspace = true } maplit = { workspace = true } mockall = { workspace = true } testlib = { workspace = true } token-info = { workspace = true, features = ["test-util"] } toml = { workspace = true } -ethrpc = {workspace = true, features = ["test-util"]} [features] test-util = ["dep:mockall"] diff --git a/crates/price-estimation/src/native/eip4626.rs b/crates/price-estimation/src/native/eip4626.rs index 46d3f787da..f3191fa382 100644 --- a/crates/price-estimation/src/native/eip4626.rs +++ b/crates/price-estimation/src/native/eip4626.rs @@ -259,8 +259,10 @@ mod tests { } /// Tests two (related) things: - /// * Cached tokens bypass the EIP-4626 provider calls — i.e. calling decimals, assets, etc - /// * That the BUY_ETH_ADDRESS is cached by default (and the previous applies to it) + /// * Cached tokens bypass the EIP-4626 provider calls — i.e. calling + /// decimals, assets, etc + /// * That the BUY_ETH_ADDRESS is cached by default (and the previous + /// applies to it) #[tokio::test] async fn buy_eth_address_bypasses_eth_calls() { let mut inner = MockNativePriceEstimating::new();