diff --git a/src/constants.rs b/src/constants.rs index 89e7da3..c3fe4f7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -15,6 +15,7 @@ pub(crate) static COINGECKO_IDS: phf::Map<&'static str, &'static str> = phf_map! "LORDS/USD" => "lords", "STRK/USD" => "starknet", "ZEND/USD" => "zklend-2", + "NSTR/USD" => "nostra", }; lazy_static! { @@ -119,7 +120,7 @@ lazy_static! { } #[allow(unused)] -pub const FEE_TOKEN_DECIMALS: i32 = 18; +pub const FEE_TOKEN_DECIMALS: u32 = 18; #[allow(unused)] pub const FEE_TOKEN_ADDRESS: &str = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"; diff --git a/src/monitoring/on_off_deviation.rs b/src/monitoring/on_off_deviation.rs index 2158a4f..c4a78a3 100644 --- a/src/monitoring/on_off_deviation.rs +++ b/src/monitoring/on_off_deviation.rs @@ -56,6 +56,15 @@ pub async fn on_off_price_deviation( .await .map_err(|e| MonitoringError::OnChain(e.to_string()))?; + let decimals = + config + .decimals(data_type.clone()) + .get(&pair_id) + .ok_or(MonitoringError::OnChain(format!( + "Failed to get decimals for pair {:?}", + pair_id + )))?; + let on_chain_price = data .first() .ok_or(MonitoringError::OnChain("No data".to_string()))? @@ -63,7 +72,8 @@ pub async fn on_off_price_deviation( .to_f64() .ok_or(MonitoringError::Conversion( "Failed to convert to f64".to_string(), - ))?; + ))? + / 10u64.pow(*decimals as u32) as f64; let (deviation, num_sources_aggregated) = match data_type { DataType::Spot => { diff --git a/src/monitoring/publisher_balance.rs b/src/monitoring/publisher_balance.rs index 2e75afe..0aefed2 100644 --- a/src/monitoring/publisher_balance.rs +++ b/src/monitoring/publisher_balance.rs @@ -5,7 +5,7 @@ use starknet::{ providers::Provider, }; -use crate::constants::FEE_TOKEN_ADDRESS; +use crate::constants::{FEE_TOKEN_ADDRESS, FEE_TOKEN_DECIMALS}; use crate::{config::get_config, error::MonitoringError}; /// Returns the balance of a given publisher address @@ -33,7 +33,8 @@ pub async fn publisher_balance(publisher_address: Felt) -> Result( .await .map_err(|e| MonitoringError::OnChain(e.to_string()))?; + let decimals = config + .decimals(query.data_type()) + .get(query.pair_id()) + .ok_or(MonitoringError::OnChain(format!( + "Failed to get decimals for pair {:?}", + query.pair_id() + )))?; + let on_chain_price = data .first() .ok_or(MonitoringError::OnChain("No data".to_string()))? @@ -41,7 +49,8 @@ pub async fn source_deviation( .to_f64() .ok_or(MonitoringError::Conversion( "Failed to convert to f64".to_string(), - ))?; + ))? + / 10u32.pow(*decimals as u32) as f64; let deviation = (normalized_price - on_chain_price) / on_chain_price; let num_sources_aggregated = try_felt_to_u32(data.get(3).unwrap()).map_err(|e| {