Skip to content

Commit

Permalink
Add AdditionalIssuance config for inflation calcs (moonbeam-foundation#9
Browse files Browse the repository at this point in the history
)

Allows injecting any additional planned issuance 
that isn't part of the currency pallet for calculating inflation
  • Loading branch information
nvengal authored May 27, 2022
1 parent 38eee70 commit e7e38b4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pallets/parachain-staking/src/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

//! Helper methods for computing issuance based on inflation
use crate::pallet::{BalanceOf, Config, Pallet};
use crate::traits::AdditionalIssuance;
use frame_support::traits::Currency;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::traits::Saturating;
use sp_runtime::PerThing;
use sp_runtime::{Perbill, RuntimeDebug};
use substrate_fixed::transcendental::pow as floatpow;
Expand Down Expand Up @@ -91,7 +93,8 @@ pub fn annual_to_round<T: Config>(annual: Range<Perbill>) -> Range<Perbill> {

/// Compute round issuance range from round inflation range and current total issuance
pub fn round_issuance_range<T: Config>(round: Range<Perbill>) -> Range<BalanceOf<T>> {
let circulating = T::Currency::total_issuance();
let circulating =
T::Currency::total_issuance().saturating_add(T::AdditionalIssuance::additional_issuance());
Range {
min: round.min * circulating,
ideal: round.ideal * circulating,
Expand Down
3 changes: 3 additions & 0 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ pub mod pallet {
type OnNewRound: OnNewRound;
/// Whether a given collator has completed required registration to be selected as block author
type CollatorRegistration: ValidatorRegistration<Self::AccountId>;
/// Any additional issuance that should be used for inflation calcs
/// If you don't need it, you can specify the type `()`.
type AdditionalIssuance: AdditionalIssuance<BalanceOf<Self>>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
Expand Down
1 change: 1 addition & 0 deletions pallets/parachain-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl Config for Test {
type OnCollatorPayout = ();
type OnNewRound = ();
type CollatorRegistration = ValidatorRegistrationMock<Self>;
type AdditionalIssuance = ();
type WeightInfo = ();
}

Expand Down
10 changes: 10 additions & 0 deletions pallets/parachain-staking/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ impl OnNewRound for () {
0
}
}

use sp_runtime::traits::Zero;
pub trait AdditionalIssuance<Balance> {
fn additional_issuance() -> Balance;
}
impl<Balance: Zero> AdditionalIssuance<Balance> for () {
fn additional_issuance() -> Balance {
Zero::zero()
}
}

0 comments on commit e7e38b4

Please sign in to comment.