From 29622e6ec3ee8ae671d94ed0ccb14bd4d160f0da Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Thu, 7 Aug 2025 15:10:19 +0300 Subject: [PATCH] make inflation and apy to represent correct values based on bridged amounts Signed-off-by: Uncle Stretch --- Cargo.toml | 2 +- src/network/predefined_calls.rs | 29 ++++++++++++++++++++++++----- src/network/raw_calls/mod.rs | 1 + src/network/raw_calls/networks.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/network/raw_calls/networks.rs diff --git a/Cargo.toml b/Cargo.toml index 8efc9e8..17614b9 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.62" +version = "0.3.63" edition = "2021" homepage = "https://git.ghostchain.io/ghostchain" repository = "https://git.ghostchain.io/ghostchain/ghost-eye" diff --git a/src/network/predefined_calls.rs b/src/network/predefined_calls.rs index 3e7082c..9f39172 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, }; @@ -183,9 +183,28 @@ pub async fn get_inflation( .await? .unwrap_or_default(); - let (inflation, fraction) = super::calculate_for_fraction(total_staked, total_issuance); - let inflation_str = super::prepare_perbill_fraction_string(inflation); - let fraction_str = super::prepare_perbill_fraction_string(fraction); + let adjusted_issuance = super::raw_calls::networks::bridged_imbalance(api, None) + .await? + .map(|imbalance| total_issuance + .saturating_add(imbalance.bridged_out) + .saturating_sub(imbalance.bridged_in) + ) + .unwrap_or_default(); + + let accumulated_commission = super::raw_calls::networks::accumulated_commission(api, None) + .await? + .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 inflation_str = super::prepare_perbill_fraction_string(expected_inflation); + let fraction_str = super::prepare_perbill_fraction_string(expected_fraction); action_tx.send(Action::Inflation(inflation_str))?; action_tx.send(Action::Apy(fraction_str))?; diff --git a/src/network/raw_calls/mod.rs b/src/network/raw_calls/mod.rs index 49c9e74..b829178 100644 --- a/src/network/raw_calls/mod.rs +++ b/src/network/raw_calls/mod.rs @@ -12,6 +12,7 @@ pub mod staking; pub mod system; pub mod babe; pub mod balances; +pub mod networks; pub async fn do_storage_call<'address, Addr>( online_client: &OnlineClient, diff --git a/src/network/raw_calls/networks.rs b/src/network/raw_calls/networks.rs new file mode 100644 index 0000000..c4c05ca --- /dev/null +++ b/src/network/raw_calls/networks.rs @@ -0,0 +1,31 @@ +use color_eyre::Result; +use subxt::{ + utils::H256, + client::OnlineClient, +}; + +use crate::{ + casper_network::{ + self, + runtime_types::ghost_networks::BridgeAdjustment, + }, + CasperConfig, +}; + +pub async fn bridged_imbalance( + online_client: &OnlineClient, + at_hash: Option<&H256>, +) -> Result>> { + let storage_key = casper_network::storage().ghost_networks().bridged_imbalance(); + let maybe_bridged_imbalance = super::do_storage_call(online_client, &storage_key, at_hash).await?; + Ok(maybe_bridged_imbalance) +} + +pub async fn accumulated_commission( + online_client: &OnlineClient, + at_hash: Option<&H256>, +) -> Result> { + let storage_key = casper_network::storage().ghost_networks().accumulated_commission(); + let maybe_accumulated_commission = super::do_storage_call(online_client, &storage_key, at_hash).await?; + Ok(maybe_accumulated_commission) +}