pub fn compute_inflation<P: PerThing>(stake: P, ideal_stake: P, falloff: P) -> P {
	if stake < ideal_stake {
		// ideal_stake is more than 0 because it is strictly more than stake
		return stake / ideal_stake
	}

	if falloff < P::from_percent(1.into()) {
		log::error!("Invalid inflation computation: falloff less than 1% is not supported");
		return PerThing::zero()
	}

	let accuracy = {
		let mut a = BigUint::from(Into::<u128>::into(P::ACCURACY));
		a.lstrip();
		a
	};

	let mut falloff = BigUint::from(falloff.deconstruct().into());
	falloff.lstrip();

	let ln2 = {
		/// `ln(2)` expressed in as perquintillionth.
		const LN2: u64 = 0_693_147_180_559_945_309;
		let ln2 = P::from_rational(LN2.into(), Perquintill::ACCURACY.into());
		BigUint::from(ln2.deconstruct().into())
	};

	// falloff is stripped above.
	let ln2_div_d = div_by_stripped(ln2.mul(&accuracy), &falloff);

	let inpos_param = INPoSParam {
		x_ideal: BigUint::from(ideal_stake.deconstruct().into()),
		x: BigUint::from(stake.deconstruct().into()),
		accuracy,
		ln2_div_d,
	};

	let res = compute_taylor_serie_part(&inpos_param);

	match u128::try_from(res.clone()) {
		Ok(res) if res <= Into::<u128>::into(P::ACCURACY) => P::from_parts(res.saturated_into()),
		// If result is beyond bounds there is nothing we can do
		_ => {
			log::error!("Invalid inflation computation: unexpected result {:?}", res);
			P::zero()
		},
	}
}
/// Compute yearly inflation using function
///
/// ```ignore
/// I(x) = for x between 0 and x_ideal: x / x_ideal,
/// for x between x_ideal and 1: 2^((x_ideal - x) / d)
/// ```
///
/// where:
/// * x is the stake rate, i.e. fraction of total issued tokens that actively staked behind
///   validators.
/// * d is the falloff or `decay_rate`
/// * x_ideal: the ideal stake rate.
///
/// The result is meant to be scaled with minimum inflation and maximum inflation.
///
/// (as detailed
/// [here](https://research.web3.foundation/en/latest/polkadot/economics/1-token-economics.html#inflation-model-with-parachains))
///
/// Arguments are:
/// * `stake`:
///   The fraction of total issued tokens that actively staked behind
///   validators. Known as `x` in the literature.
///   Must be between 0 and 1.
/// * `ideal_stake`:
///   The fraction of total issued tokens that should be actively staked behind
///   validators. Known as `x_ideal` in the literature.
///   Must be between 0 and 1.
/// * `falloff`:
///   Known as `decay_rate` in the literature. A co-efficient dictating the strength of
///   the global incentivization to get the `ideal_stake`. A higher number results in less typical
///   inflation at the cost of greater volatility for validators.
///   Must be more than 0.01.


x is the stake rate, i.e. fraction of total issued tokens that actively staked behind
validators.
d is the falloff or `decay_rate`
x_ideal: the ideal stake rate.

The result is meant to be scaled with minimum inflation and maximum inflation.

(as detailed
[here])

Arguments are:
`stake`:
The fraction of total issued tokens that actively staked behind
validators. Known as `x` in the literature.
Must be between 0 and 1.
`ideal_stake`:
The fraction of total issued tokens that should be actively staked behind
validators. Known as `x_ideal` in the literature.
Must be between 0 and 1.
`falloff`:
Known as `decay_rate` in the literature. A co-efficient dictating the strength of
the global incentivization to get the `ideal_stake`. A higher number results in less typical
inflation at the cost of greater volatility for validators.
Must be more than 0.01.
x is the stake rate i . e . fraction of total issued tokens that actively staked behind validators . d is the falloff or ` decay_rate ` x_ideal : the ideal stake rate . The result is meant to be scaled with minimum inflation and maximum inflation . ( as detailed [ here ] ) Arguments are : ` stake ` : The fraction of total issued tokens that actively staked behind validators . Known as ` x ` in the literature . Must be between 0 and 1 . ` ideal_stake ` : The fraction of total issued tokens that should be actively staked behind validators . Known as ` x_ideal ` in the literature . Must be between 0 and 1 . ` falloff ` : Known as ` decay_rate ` in the literature . A co - efficient dictating the strength of the global incentivization to get the ` ideal_stake ` . A higher number results in less typical inflation at the cost of greater volatility for validators . Must be more than 0 . 01 .
pub fn compute_inflation<P: PerThing>(stake: P, ideal_stake: P, falloff: P) -> P {
	if stake < ideal_stake {
		// ideal_stake is more than 0 because it is strictly more than stake
		return stake / ideal_stake
	}
	if falloff < P::from_percent(1.into()) {
		log::error!("Invalid inflation computation: falloff less than 1% is not supported");
		return PerThing::zero()
	}
	let accuracy = {
		let mut a = BigUint::from(Into::<u128>::into(P::ACCURACY));
		a.lstrip();
		a
	};
	let mut falloff = BigUint::from(falloff.deconstruct().into());
	falloff.lstrip();
	let ln2 = {
		/// `ln(2)` expressed in as perquintillionth.
		const LN2: u64 = 0_693_147_180_559_945_309;
		let ln2 = P::from_rational(LN2.into(), Perquintill::ACCURACY.into());
		BigUint::from(ln2.deconstruct().into())
	};
	// falloff is stripped above.
	let ln2_div_d = div_by_stripped(ln2.mul(&accuracy), &falloff);
	let inpos_param = INPoSParam {
		x_ideal: BigUint::from(ideal_stake.deconstruct().into()),
		x: BigUint::from(stake.deconstruct().into()),
		accuracy,
		ln2_div_d,
	};
	let res = compute_taylor_serie_part(&inpos_param);
	match u128::try_from(res.clone()) {
		Ok(res) if res <= Into::<u128>::into(P::ACCURACY) => P::from_parts(res.saturated_into()),
		// If result is beyond bounds there is nothing we can do
		_ => {
			log::error!("Invalid inflation computation: unexpected result {:?}", res);
			P::zero()
		},
	}
}
pub fn compute_inflation < P : PerThing > ( stake : P , ideal_stake : P , falloff : P ) -> P { if stake < ideal_stake { // ideal_stake is more than 0 because it is strictly more than stake return stake / ideal_stake } if falloff < P :: from_percent ( 1 . into ( ) ) { log :: error ! ( " " ) ; return PerThing :: zero ( ) } let accuracy = { let mut a = BigUint :: from ( Into :: < u128 > :: into ( P :: ACCURACY ) ) ; a . lstrip ( ) ; a } ; let mut falloff = BigUint :: from ( falloff . deconstruct ( ) . into ( ) ) ; falloff . lstrip ( ) ; let ln2 = { /// `ln(2)` expressed in as perquintillionth. const LN2 : u64 = 0_693_147_180_559_945_309 ; let ln2 = P :: from_rational ( LN2 . into ( ) , Perquintill :: ACCURACY . into ( ) ) ; BigUint :: from ( ln2 . deconstruct ( ) . into ( ) ) } ; // falloff is stripped above. let ln2_div_d = div_by_stripped ( ln2 . mul ( & accuracy ) , & falloff ) ; let inpos_param = INPoSParam { x_ideal : BigUint :: from ( ideal_stake . deconstruct ( ) . into ( ) ) , x : BigUint :: from ( stake . deconstruct ( ) . into ( ) ) , accuracy , ln2_div_d , } ; let res = compute_taylor_serie_part ( & inpos_param ) ; match u128 :: try_from ( res . clone ( ) ) { Ok ( res ) if res <= Into :: < u128 > :: into ( P :: ACCURACY ) => P :: from_parts ( res . saturated_into ( ) ) , // If result is beyond bounds there is nothing we can do _ => { log :: error ! ( " " res ) ; P :: zero ( ) } , } }
Compute yearly inflation using function
```ignore
I(x) = for x between 0 and x_ideal: x / x_ideal,
for x between x_ideal and 1: 2^((x_ideal - x) / d)
```
Compute yearly inflation using function ` ` ` ignore I ( x ) = for x between 0 and x_ideal : x / x_ideal for x between x_ideal and 1 : 2^ (( x_ideal - x ) / d ) ` ` `
stake
P
ideal_stake
P
falloff
P
stake
P
ideal_stake
P
falloff
P