diff --git a/Cargo.lock b/Cargo.lock index 27a2048815d..e3251169d6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1748,7 +1748,6 @@ dependencies = [ "apollo_l1_events", "apollo_l1_events_config", "apollo_l1_events_types", - "apollo_l1_gas_price", "apollo_l1_gas_price_config", "apollo_l1_gas_price_types", "apollo_mempool_config", diff --git a/crates/apollo_integration_tests/Cargo.toml b/crates/apollo_integration_tests/Cargo.toml index b0c6cf1516a..bd3bb0ffef8 100644 --- a/crates/apollo_integration_tests/Cargo.toml +++ b/crates/apollo_integration_tests/Cargo.toml @@ -35,7 +35,6 @@ apollo_infra = { workspace = true, features = ["testing"] } apollo_infra_utils = { workspace = true, features = ["testing"] } apollo_l1_events.workspace = true apollo_l1_events_config.workspace = true -apollo_l1_gas_price.workspace = true apollo_l1_gas_price_config.workspace = true apollo_l1_gas_price_types.workspace = true apollo_mempool_config.workspace = true diff --git a/crates/apollo_integration_tests/src/utils.rs b/crates/apollo_integration_tests/src/utils.rs index 345a6d21609..5a95229c7c3 100644 --- a/crates/apollo_integration_tests/src/utils.rs +++ b/crates/apollo_integration_tests/src/utils.rs @@ -52,7 +52,6 @@ use apollo_http_server::test_utils::create_http_server_config; use apollo_infra::trace_util::configure_tracing; use apollo_infra_utils::test_utils::{AvailablePorts, TestIdentifier}; use apollo_l1_events_config::config::{L1EventsProviderConfig, L1EventsScraperConfig}; -use apollo_l1_gas_price::exchange_rate_oracle::EXCHANGE_RATE_DECIMALS; use apollo_l1_gas_price_config::config::{ ExchangeRateOracleConfig, L1GasPriceProviderConfig, @@ -574,8 +573,7 @@ async fn get_rate(Query(query): Query) -> Json) -> HeaderMap { let mut header_map = HeaderMap::new(); for (key, value) in hash_map { @@ -108,6 +106,7 @@ impl ExchangeRateOracleClient { ); let adjusted_timestamp = quantized_timestamp * self.config.lag_interval_seconds; let query_timeout_sec = self.config.query_timeout_sec; + let expected_decimals = self.config.exchange_rate_decimals; let client = self.client.clone(); let index_clone = self.index.clone(); let url_header_list = self.url_header_list.clone(); @@ -126,7 +125,7 @@ impl ExchangeRateOracleClient { .send() .await?; let body = response.text().await?; - let rate = resolve_query(body)?; + let rate = resolve_query(body, expected_decimals)?; Ok::<_, ExchangeRateOracleClientError>(rate) }) .await; @@ -157,7 +156,10 @@ impl ExchangeRateOracleClient { } } -fn resolve_query(body: String) -> Result { +fn resolve_query( + body: String, + expected_decimals: u64, +) -> Result { let Ok(json): Result = serde_json::from_str(&body) else { return Err(ExchangeRateOracleClientError::ParseError(format!( "Failed to parse JSON: {body}" @@ -186,9 +188,9 @@ fn resolve_query(body: String) -> Result { )); } }; - if decimals != EXCHANGE_RATE_DECIMALS { + if decimals != expected_decimals { return Err(ExchangeRateOracleClientError::InvalidDecimalsError( - EXCHANGE_RATE_DECIMALS, + expected_decimals, decimals, )); } @@ -202,7 +204,7 @@ fn resolve_query(body: String) -> Result { impl ExchangeRateOracleClientTrait for ExchangeRateOracleClient { /// The HTTP response must include the following fields: /// - `price`: a hexadecimal string representing the price. - /// - `decimals`: a `u64` value, must be equal to `EXCHANGE_RATE_DECIMALS`. + /// - `decimals`: a `u64` value, must be equal to `config.exchange_rate_decimals`. #[instrument(skip(self))] async fn fetch_rate(&self, timestamp: u64) -> Result { const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1; diff --git a/crates/apollo_l1_gas_price_config/src/config.rs b/crates/apollo_l1_gas_price_config/src/config.rs index 53a4f530eab..207f3e2b043 100644 --- a/crates/apollo_l1_gas_price_config/src/config.rs +++ b/crates/apollo_l1_gas_price_config/src/config.rs @@ -28,6 +28,7 @@ pub struct ExchangeRateOracleConfig { pub lag_interval_seconds: u64, pub max_cache_size: usize, pub query_timeout_sec: u64, + pub exchange_rate_decimals: u64, } impl SerializeConfig for ExchangeRateOracleConfig { @@ -69,6 +70,13 @@ impl SerializeConfig for ExchangeRateOracleConfig { "The timeout (seconds) for the query to the eth to strk oracle.", ParamPrivacyInput::Public, ), + ser_param( + "exchange_rate_decimals", + &self.exchange_rate_decimals, + "The expected `decimals` value returned in oracle API responses. Responses with a \ + different `decimals` value are rejected as invalid. ETH/STRK feeds use 18.", + ParamPrivacyInput::Public, + ), ]) } } @@ -86,6 +94,7 @@ impl Default for ExchangeRateOracleConfig { lag_interval_seconds: 1, max_cache_size: 100, query_timeout_sec: 10, + exchange_rate_decimals: 18, } } } diff --git a/crates/apollo_node/resources/config_schema.json b/crates/apollo_node/resources/config_schema.json index 8d48e0f2d65..a0c166fea59 100644 --- a/crates/apollo_node/resources/config_schema.json +++ b/crates/apollo_node/resources/config_schema.json @@ -3274,6 +3274,11 @@ "privacy": "TemporaryValue", "value": false }, + "l1_gas_price_provider_config.eth_to_strk_oracle_config.exchange_rate_decimals": { + "description": "The expected `decimals` value returned in oracle API responses. Responses with a different `decimals` value are rejected as invalid. ETH/STRK feeds use 18.", + "privacy": "Public", + "value": 18 + }, "l1_gas_price_provider_config.eth_to_strk_oracle_config.lag_interval_seconds": { "description": "The size of the interval (seconds) that the eth to strk rate is taken on. The lag refers to the fact that the interval `[T, T+k)` contains the conversion rate for queries in the interval `[T+k, T+2k)`. Should be configured in alignment with relevant query parameters in `url_header_list`, if required.", "privacy": "Public",