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:
parent
a6ebb90ede
commit
29622e6ec3
@ -2,7 +2,7 @@
|
|||||||
name = "ghost-eye"
|
name = "ghost-eye"
|
||||||
authors = ["str3tch <stretch@ghostchain.io>"]
|
authors = ["str3tch <stretch@ghostchain.io>"]
|
||||||
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
|
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"
|
edition = "2021"
|
||||||
homepage = "https://git.ghostchain.io/ghostchain"
|
homepage = "https://git.ghostchain.io/ghostchain"
|
||||||
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
||||||
|
@ -4,9 +4,9 @@ use subxt::{
|
|||||||
backend::rpc::RpcClient,
|
backend::rpc::RpcClient,
|
||||||
client::OnlineClient,
|
client::OnlineClient,
|
||||||
config::substrate::DigestItem,
|
config::substrate::DigestItem,
|
||||||
ext::sp_core::crypto::{
|
ext::{sp_core::crypto::{
|
||||||
AccountId32, Ss58AddressFormat, Ss58Codec,
|
AccountId32, Ss58AddressFormat, Ss58Codec,
|
||||||
},
|
}, sp_runtime::{traits::Saturating, Perbill}},
|
||||||
rpc_params,
|
rpc_params,
|
||||||
utils::H256,
|
utils::H256,
|
||||||
};
|
};
|
||||||
@ -183,9 +183,28 @@ pub async fn get_inflation(
|
|||||||
.await?
|
.await?
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let (inflation, fraction) = super::calculate_for_fraction(total_staked, total_issuance);
|
let adjusted_issuance = super::raw_calls::networks::bridged_imbalance(api, None)
|
||||||
let inflation_str = super::prepare_perbill_fraction_string(inflation);
|
.await?
|
||||||
let fraction_str = super::prepare_perbill_fraction_string(fraction);
|
.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::Inflation(inflation_str))?;
|
||||||
action_tx.send(Action::Apy(fraction_str))?;
|
action_tx.send(Action::Apy(fraction_str))?;
|
||||||
|
@ -12,6 +12,7 @@ pub mod staking;
|
|||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod babe;
|
pub mod babe;
|
||||||
pub mod balances;
|
pub mod balances;
|
||||||
|
pub mod networks;
|
||||||
|
|
||||||
pub async fn do_storage_call<'address, Addr>(
|
pub async fn do_storage_call<'address, Addr>(
|
||||||
online_client: &OnlineClient<CasperConfig>,
|
online_client: &OnlineClient<CasperConfig>,
|
||||||
|
31
src/network/raw_calls/networks.rs
Normal file
31
src/network/raw_calls/networks.rs
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user