Skip to content

Commit 6afda0a

Browse files
apollo_l1_gas_price,apollo_l1_gas_price_config: move exchange_rate_decimals const to config
1 parent bf81ef7 commit 6afda0a

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_integration_tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ apollo_infra = { workspace = true, features = ["testing"] }
3535
apollo_infra_utils = { workspace = true, features = ["testing"] }
3636
apollo_l1_events.workspace = true
3737
apollo_l1_events_config.workspace = true
38-
apollo_l1_gas_price.workspace = true
3938
apollo_l1_gas_price_config.workspace = true
4039
apollo_l1_gas_price_types.workspace = true
4140
apollo_mempool_config.workspace = true

crates/apollo_integration_tests/src/utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use apollo_http_server::test_utils::create_http_server_config;
5252
use apollo_infra::trace_util::configure_tracing;
5353
use apollo_infra_utils::test_utils::{AvailablePorts, TestIdentifier};
5454
use apollo_l1_events_config::config::{L1EventsProviderConfig, L1EventsScraperConfig};
55-
use apollo_l1_gas_price::exchange_rate_oracle::EXCHANGE_RATE_DECIMALS;
5655
use apollo_l1_gas_price_config::config::{
5756
ExchangeRateOracleConfig,
5857
L1GasPriceProviderConfig,
@@ -574,8 +573,7 @@ async fn get_rate(Query(query): Query<EthToStrkOracleQuery>) -> Json<serde_json:
574573
// TODO(Asmaa): Retrun timestamp as price once we start mocking out time in the
575574
// tests.
576575
let price = format!("0x{DEFAULT_ETH_TO_FRI_RATE:x}");
577-
let response =
578-
json!({ "timestamp": query.timestamp ,"price": price, "decimals": EXCHANGE_RATE_DECIMALS });
576+
let response = json!({ "timestamp": query.timestamp ,"price": price, "decimals": 18 });
579577
Json(response)
580578
}
581579

crates/apollo_l1_gas_price/src/exchange_rate_oracle.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use crate::metrics::{
3030
#[path = "exchange_rate_oracle_test.rs"]
3131
pub mod exchange_rate_oracle_test;
3232

33-
pub const EXCHANGE_RATE_DECIMALS: u64 = 18;
34-
3533
fn btreemap_to_headermap(hash_map: BTreeMap<String, String>) -> HeaderMap {
3634
let mut header_map = HeaderMap::new();
3735
for (key, value) in hash_map {
@@ -108,6 +106,7 @@ impl ExchangeRateOracleClient {
108106
);
109107
let adjusted_timestamp = quantized_timestamp * self.config.lag_interval_seconds;
110108
let query_timeout_sec = self.config.query_timeout_sec;
109+
let expected_decimals = self.config.exchange_rate_decimals;
111110
let client = self.client.clone();
112111
let index_clone = self.index.clone();
113112
let url_header_list = self.url_header_list.clone();
@@ -126,7 +125,7 @@ impl ExchangeRateOracleClient {
126125
.send()
127126
.await?;
128127
let body = response.text().await?;
129-
let rate = resolve_query(body)?;
128+
let rate = resolve_query(body, expected_decimals)?;
130129
Ok::<_, ExchangeRateOracleClientError>(rate)
131130
})
132131
.await;
@@ -157,7 +156,10 @@ impl ExchangeRateOracleClient {
157156
}
158157
}
159158

160-
fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
159+
fn resolve_query(
160+
body: String,
161+
expected_decimals: u64,
162+
) -> Result<u128, ExchangeRateOracleClientError> {
161163
let Ok(json): Result<serde_json::Value, _> = serde_json::from_str(&body) else {
162164
return Err(ExchangeRateOracleClientError::ParseError(format!(
163165
"Failed to parse JSON: {body}"
@@ -186,9 +188,9 @@ fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
186188
));
187189
}
188190
};
189-
if decimals != EXCHANGE_RATE_DECIMALS {
191+
if decimals != expected_decimals {
190192
return Err(ExchangeRateOracleClientError::InvalidDecimalsError(
191-
EXCHANGE_RATE_DECIMALS,
193+
expected_decimals,
192194
decimals,
193195
));
194196
}
@@ -202,7 +204,7 @@ fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
202204
impl ExchangeRateOracleClientTrait for ExchangeRateOracleClient {
203205
/// The HTTP response must include the following fields:
204206
/// - `price`: a hexadecimal string representing the price.
205-
/// - `decimals`: a `u64` value, must be equal to `EXCHANGE_RATE_DECIMALS`.
207+
/// - `decimals`: a `u64` value, must be equal to `config.exchange_rate_decimals`.
206208
#[instrument(skip(self))]
207209
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, ExchangeRateOracleClientError> {
208210
const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1;

crates/apollo_l1_gas_price_config/src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct ExchangeRateOracleConfig {
2828
pub lag_interval_seconds: u64,
2929
pub max_cache_size: usize,
3030
pub query_timeout_sec: u64,
31+
pub exchange_rate_decimals: u64,
3132
}
3233

3334
impl SerializeConfig for ExchangeRateOracleConfig {
@@ -69,6 +70,13 @@ impl SerializeConfig for ExchangeRateOracleConfig {
6970
"The timeout (seconds) for the query to the eth to strk oracle.",
7071
ParamPrivacyInput::Public,
7172
),
73+
ser_param(
74+
"exchange_rate_decimals",
75+
&self.exchange_rate_decimals,
76+
"The expected `decimals` value returned in oracle API responses. Responses with a \
77+
different `decimals` value are rejected as invalid. ETH/STRK feeds use 18.",
78+
ParamPrivacyInput::Public,
79+
),
7280
])
7381
}
7482
}
@@ -86,6 +94,7 @@ impl Default for ExchangeRateOracleConfig {
8694
lag_interval_seconds: 1,
8795
max_cache_size: 100,
8896
query_timeout_sec: 10,
97+
exchange_rate_decimals: 18,
8998
}
9099
}
91100
}

crates/apollo_node/resources/config_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,11 @@
32743274
"privacy": "TemporaryValue",
32753275
"value": false
32763276
},
3277+
"l1_gas_price_provider_config.eth_to_strk_oracle_config.exchange_rate_decimals": {
3278+
"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.",
3279+
"privacy": "Public",
3280+
"value": 18
3281+
},
32773282
"l1_gas_price_provider_config.eth_to_strk_oracle_config.lag_interval_seconds": {
32783283
"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.",
32793284
"privacy": "Public",

0 commit comments

Comments
 (0)