avoid capped 1 in a Perbill struct

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-08-08 00:39:04 +03:00
parent 9afda5a701
commit ef81076f71
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
4 changed files with 11 additions and 26 deletions

View File

@ -2,7 +2,7 @@
name = "ghost-eye"
authors = ["str3tch <stretch@ghostchain.io>"]
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"

View File

@ -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<u8> {
let mut key = SLOW_CLAP_DB_PREFIX.to_vec();
key.extend(first);

View File

@ -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},

View File

@ -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))?;