Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/apollo_integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions crates/apollo_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -574,8 +573,7 @@ async fn get_rate(Query(query): Query<EthToStrkOracleQuery>) -> Json<serde_json:
// TODO(Asmaa): Retrun timestamp as price once we start mocking out time in the
// tests.
let price = format!("0x{DEFAULT_ETH_TO_FRI_RATE:x}");
let response =
json!({ "timestamp": query.timestamp ,"price": price, "decimals": EXCHANGE_RATE_DECIMALS });
let response = json!({ "timestamp": query.timestamp ,"price": price, "decimals": 18 });
Comment thread
cursor[bot] marked this conversation as resolved.
Json(response)
}

Expand Down
16 changes: 9 additions & 7 deletions crates/apollo_l1_gas_price/src/exchange_rate_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use crate::metrics::{
#[path = "exchange_rate_oracle_test.rs"]
pub mod exchange_rate_oracle_test;

pub const EXCHANGE_RATE_DECIMALS: u64 = 18;

fn btreemap_to_headermap(hash_map: BTreeMap<String, String>) -> HeaderMap {
let mut header_map = HeaderMap::new();
for (key, value) in hash_map {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -157,7 +156,10 @@ impl ExchangeRateOracleClient {
}
}

fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
fn resolve_query(
body: String,
expected_decimals: u64,
) -> Result<u128, ExchangeRateOracleClientError> {
let Ok(json): Result<serde_json::Value, _> = serde_json::from_str(&body) else {
return Err(ExchangeRateOracleClientError::ParseError(format!(
"Failed to parse JSON: {body}"
Expand Down Expand Up @@ -186,9 +188,9 @@ fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
));
}
};
if decimals != EXCHANGE_RATE_DECIMALS {
if decimals != expected_decimals {
return Err(ExchangeRateOracleClientError::InvalidDecimalsError(
EXCHANGE_RATE_DECIMALS,
expected_decimals,
decimals,
));
}
Expand All @@ -202,7 +204,7 @@ fn resolve_query(body: String) -> Result<u128, ExchangeRateOracleClientError> {
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<u128, ExchangeRateOracleClientError> {
const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1;
Expand Down
9 changes: 9 additions & 0 deletions crates/apollo_l1_gas_price_config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
),
])
}
}
Expand All @@ -86,6 +94,7 @@ impl Default for ExchangeRateOracleConfig {
lag_interval_seconds: 1,
max_cache_size: 100,
query_timeout_sec: 10,
exchange_rate_decimals: 18,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/apollo_node/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading