From f76dea180052e31d50d06a050888a3cdd475d279 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Thu, 20 Jun 2024 12:54:38 +0100 Subject: [PATCH] fix: smol fixes --- crates/client/eth-client/src/config.rs | 35 +++++------------------- crates/client/l1-gas-price/src/worker.rs | 8 ++++-- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/crates/client/eth-client/src/config.rs b/crates/client/eth-client/src/config.rs index e932169b0c..395f6e69fc 100644 --- a/crates/client/eth-client/src/config.rs +++ b/crates/client/eth-client/src/config.rs @@ -100,6 +100,9 @@ impl OracleConfig { } } +/// Price bounds for the oracle +/// If the price is outside of these bounds, it will not be used +/// The bounds are denominated in the quote currency so in FRI here. #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct PriceBounds { pub low: u128, @@ -123,16 +126,13 @@ pub struct PragmaOracle { impl PragmaOracle { fn get_fetch_url(&self, base: String, quote: String) -> String { format!( - "{}{}/{}?interval={}&aggregation={}", - self.api_url, - base, - quote, - self.interval.as_str(), - self.aggregation_method.as_str() + "{}{}/{}?interval={:?}&aggregation={:?}", + self.api_url, base, quote, self.interval, self.aggregation_method ) } } +/// Supported Aggregation Methods #[derive(Default, Debug, Serialize, Deserialize, Clone)] pub enum AggregationMethod { #[serde(rename = "median")] @@ -144,17 +144,7 @@ pub enum AggregationMethod { Twap, } -impl AggregationMethod { - pub fn as_str(&self) -> &str { - match self { - AggregationMethod::Median => "median", - AggregationMethod::Mean => "mean", - AggregationMethod::Twap => "twap", - } - } -} - -// Supported Aggregation Intervals +/// Supported Aggregation Intervals #[derive(Default, Debug, Serialize, Deserialize, Clone)] pub enum Interval { #[serde(rename = "1min")] @@ -168,17 +158,6 @@ pub enum Interval { TwoHours, } -impl Interval { - pub fn as_str(&self) -> &str { - match self { - Interval::OneMinute => "1min", - Interval::FifteenMinutes => "15min", - Interval::OneHour => "1h", - Interval::TwoHours => "2h", - } - } -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LocalWalletConfig { #[serde(default = "default_chain_id")] diff --git a/crates/client/l1-gas-price/src/worker.rs b/crates/client/l1-gas-price/src/worker.rs index 115773e914..c9d4057989 100644 --- a/crates/client/l1-gas-price/src/worker.rs +++ b/crates/client/l1-gas-price/src/worker.rs @@ -16,7 +16,7 @@ use crate::types::{EthRpcResponse, FeeHistory}; const DEFAULT_GAS_PRICE_POLL_MS: u64 = 10_000; #[derive(Deserialize, Debug)] -struct ApiResponse { +struct OracleApiResponse { price: String, decimals: u32, } @@ -103,10 +103,14 @@ async fn update_gas_price( .send() .await?; - let res_json = response.json::().await; + let res_json = response.json::().await; let mut gas_price = gas_price.lock().await; + // We query the Oracle API for the ETH/STRK price feed + // If the api response is successful AND the price is within the bounds + // Then we update the strk_l1_gas_price and strk_l1_data_gas_price fields + // Otherwise we log an error and we keep the previous values match res_json { Ok(api_response) => { log::trace!("Retrieved ETH/STRK price from Oracle");