avoid capped 1 in a Perbill struct
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
9afda5a701
commit
ef81076f71
@ -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.64"
|
version = "0.3.65"
|
||||||
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"
|
||||||
|
@ -101,20 +101,6 @@ fn multiply_by_rational_saturating(value: u128, p: u32, q: u32) -> u128 {
|
|||||||
result_divisor_part.saturating_add(result_remainder_part)
|
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> {
|
pub fn get_slow_clap_storage_key(first: &[u8], second: &[u8]) -> Vec<u8> {
|
||||||
let mut key = SLOW_CLAP_DB_PREFIX.to_vec();
|
let mut key = SLOW_CLAP_DB_PREFIX.to_vec();
|
||||||
key.extend(first);
|
key.extend(first);
|
||||||
|
@ -11,7 +11,7 @@ mod subscriptions;
|
|||||||
mod miscellaneous;
|
mod miscellaneous;
|
||||||
mod raw_calls;
|
mod raw_calls;
|
||||||
|
|
||||||
pub use miscellaneous::{prepare_perbill_fraction_string, calculate_for_fraction};
|
pub use miscellaneous::calculate_for_fraction;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
types::{ActionLevel, ActionTarget},
|
types::{ActionLevel, ActionTarget},
|
||||||
|
@ -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,
|
||||||
};
|
};
|
||||||
@ -196,15 +196,14 @@ pub async fn get_inflation(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let (inflation, fraction) = super::calculate_for_fraction(total_staked, adjusted_issuance);
|
let (inflation, fraction) = super::calculate_for_fraction(total_staked, adjusted_issuance);
|
||||||
let current_ratio = Perbill::from_rational(accumulated_commission, adjusted_issuance);
|
let current_ratio: f64 = 1.0 + accumulated_commission as f64 / adjusted_issuance as f64;
|
||||||
let expected_inflation = inflation
|
let yearly_current_ratio = current_ratio.powf(365.0) + 1.0;
|
||||||
.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 expected_inflation = (inflation.deconstruct() as f64) * yearly_current_ratio / 1_000_000_000.0;
|
||||||
let fraction_str = super::prepare_perbill_fraction_string(expected_fraction);
|
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::Inflation(inflation_str))?;
|
||||||
action_tx.send(Action::Apy(fraction_str))?;
|
action_tx.send(Action::Apy(fraction_str))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user