make inflation and apy to represent correct values based on bridged amounts

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-08-07 15:10:19 +03:00
parent a6ebb90ede
commit 29622e6ec3
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
4 changed files with 57 additions and 6 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.62"
version = "0.3.63"
edition = "2021"
homepage = "https://git.ghostchain.io/ghostchain"
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"

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

View File

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

View File

@ -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<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<BridgeAdjustment<u128>>> {
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<CasperConfig>,
at_hash: Option<&H256>,
) -> Result<Option<u128>> {
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)
}