Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
fix: smol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Jun 20, 2024
1 parent b7d7955 commit f76dea1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
35 changes: 7 additions & 28 deletions crates/client/eth-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand Down
8 changes: 6 additions & 2 deletions crates/client/l1-gas-price/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -103,10 +103,14 @@ async fn update_gas_price(
.send()
.await?;

let res_json = response.json::<ApiResponse>().await;
let res_json = response.json::<OracleApiResponse>().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");
Expand Down

0 comments on commit f76dea1

Please sign in to comment.