From 6b330a476de043ecd9a1dd1497c1ecf76a759192 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Wed, 31 Jul 2024 16:25:40 +0200 Subject: [PATCH] tmp: remove randomness in base token price --- .../src/forced_price_client.rs | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/core/lib/external_price_api/src/forced_price_client.rs b/core/lib/external_price_api/src/forced_price_client.rs index 10b633db039..da5f1c4ec32 100644 --- a/core/lib/external_price_api/src/forced_price_client.rs +++ b/core/lib/external_price_api/src/forced_price_client.rs @@ -46,30 +46,35 @@ impl PriceAPIClient for ForcedPriceClient { /// Returns a ratio which is 10% higher or lower than the configured forced ratio, /// but not different more than 3% than the last value async fn fetch_ratio(&self, _token_address: Address) -> anyhow::Result { - let mut previous_numerator = self.previous_numerator.write().await; - let mut rng = rand::thread_rng(); - let numerator_range = ( - max( - (self.ratio.numerator.get() as f64 * (1.0 - VARIATION_RANGE)).round() as u64, - (previous_numerator.get() as f64 * (1.0 - NEXT_VALUE_VARIATION_RANGE)).round() - as u64, - ), - min( - (self.ratio.numerator.get() as f64 * (1.0 + VARIATION_RANGE)).round() as u64, - (previous_numerator.get() as f64 * (1.0 + NEXT_VALUE_VARIATION_RANGE)).round() - as u64, - ), - ); - - let new_numerator = NonZeroU64::new(rng.gen_range(numerator_range.0..=numerator_range.1)) - .unwrap_or(self.ratio.numerator); - let adjusted_ratio = BaseTokenAPIRatio { - numerator: new_numerator, + Ok(BaseTokenAPIRatio { + numerator: self.ratio.numerator, denominator: self.ratio.denominator, ratio_timestamp: chrono::Utc::now(), - }; - *previous_numerator = new_numerator; + }) + // let mut previous_numerator = self.previous_numerator.write().await; + // let mut rng = rand::thread_rng(); + // let numerator_range = ( + // max( + // (self.ratio.numerator.get() as f64 * (1.0 - VARIATION_RANGE)).round() as u64, + // (previous_numerator.get() as f64 * (1.0 - NEXT_VALUE_VARIATION_RANGE)).round() + // as u64, + // ), + // min( + // (self.ratio.numerator.get() as f64 * (1.0 + VARIATION_RANGE)).round() as u64, + // (previous_numerator.get() as f64 * (1.0 + NEXT_VALUE_VARIATION_RANGE)).round() + // as u64, + // ), + // ); + // + // let new_numerator = NonZeroU64::new(rng.gen_range(numerator_range.0..=numerator_range.1)) + // .unwrap_or(self.ratio.numerator); + // let adjusted_ratio = BaseTokenAPIRatio { + // numerator: new_numerator, + // denominator: self.ratio.denominator, + // ratio_timestamp: chrono::Utc::now(), + // }; + // *previous_numerator = new_numerator; - Ok(adjusted_ratio) + // Ok(adjusted_ratio) } }