From ef81076f71070dc21d46cee1a506d29c2410f26a Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Fri, 8 Aug 2025 00:39:04 +0300 Subject: [PATCH] avoid capped 1 in a Perbill struct Signed-off-by: Uncle Stretch --- Cargo.toml | 2 +- src/network/miscellaneous.rs | 14 -------------- src/network/mod.rs | 2 +- src/network/predefined_calls.rs | 19 +++++++++---------- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19f514e..1de0cfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "ghost-eye" authors = ["str3tch "] description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" -version = "0.3.64" +version = "0.3.65" edition = "2021" homepage = "https://git.ghostchain.io/ghostchain" repository = "https://git.ghostchain.io/ghostchain/ghost-eye" diff --git a/src/network/miscellaneous.rs b/src/network/miscellaneous.rs index fba1874..1636e46 100644 --- a/src/network/miscellaneous.rs +++ b/src/network/miscellaneous.rs @@ -101,20 +101,6 @@ fn multiply_by_rational_saturating(value: u128, p: u32, q: u32) -> u128 { result_divisor_part.saturating_add(result_remainder_part) } -pub fn prepare_perbill_fraction_string(value: Perbill) -> String { - let d = value.deconstruct(); - let mut m = 10_000_000; - - let units = d / m; - let rest = d % m; - - for _ in 0..2 { - m /= 10; - } - - format!("{}.{:02}%", units, rest / m) -} - pub fn get_slow_clap_storage_key(first: &[u8], second: &[u8]) -> Vec { let mut key = SLOW_CLAP_DB_PREFIX.to_vec(); key.extend(first); diff --git a/src/network/mod.rs b/src/network/mod.rs index a6e63c8..fce1f66 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -11,7 +11,7 @@ mod subscriptions; mod miscellaneous; mod raw_calls; -pub use miscellaneous::{prepare_perbill_fraction_string, calculate_for_fraction}; +pub use miscellaneous::calculate_for_fraction; use crate::{ types::{ActionLevel, ActionTarget}, diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index 542b7d4..3cd0369 100644 --- a/src/network/predefined_calls.rs +++ b/src/network/predefined_calls.rs @@ -4,9 +4,9 @@ use subxt::{ backend::rpc::RpcClient, client::OnlineClient, config::substrate::DigestItem, - ext::{sp_core::crypto::{ + ext::sp_core::crypto::{ AccountId32, Ss58AddressFormat, Ss58Codec, - }, sp_runtime::{traits::Saturating, Perbill}}, + }, rpc_params, utils::H256, }; @@ -196,15 +196,14 @@ pub async fn get_inflation( .unwrap_or_default(); let (inflation, fraction) = super::calculate_for_fraction(total_staked, adjusted_issuance); - let current_ratio = Perbill::from_rational(accumulated_commission, adjusted_issuance); - let expected_inflation = inflation - .saturating_mul(Perbill::one().saturating_add(current_ratio)) - .saturating_pow(365) - .saturating_sub(Perbill::one()); - let expected_fraction = expected_inflation.saturating_mul(fraction); + let current_ratio: f64 = 1.0 + accumulated_commission as f64 / adjusted_issuance as f64; + let yearly_current_ratio = current_ratio.powf(365.0) + 1.0; - let inflation_str = super::prepare_perbill_fraction_string(expected_inflation); - let fraction_str = super::prepare_perbill_fraction_string(expected_fraction); + let expected_inflation = (inflation.deconstruct() as f64) * yearly_current_ratio / 1_000_000_000.0; + let expected_fraction = expected_inflation - (fraction.deconstruct() as f64) / 1_000_000_000.0; + + let inflation_str = format!("{:.4}%", expected_inflation); + let fraction_str = format!("{:.4}%", expected_fraction); action_tx.send(Action::Inflation(inflation_str))?; action_tx.send(Action::Apy(fraction_str))?;