@@ -490,6 +490,23 @@ parameter_types! {
490490
491491pub struct ExponentialEraPayout ;
492492
493+ impl ExponentialEraPayout {
494+ fn era_payout ( total_issuance : Balance , era_duration_millis : u64 ) -> ( Balance , Balance ) {
495+ const VALIDATOR_REWARD : Perbill = Perbill :: from_percent ( 90 ) ;
496+
497+ let azero_cap = pallet_aleph:: AzeroCap :: < Runtime > :: get ( ) ;
498+ let horizon = pallet_aleph:: ExponentialInflationHorizon :: < Runtime > :: get ( ) ;
499+
500+ let total_payout: Balance =
501+ exp_helper ( Perbill :: from_rational ( era_duration_millis, horizon) )
502+ * ( azero_cap. saturating_sub ( total_issuance) ) ;
503+ let validators_payout = VALIDATOR_REWARD * total_payout;
504+ let rest = total_payout - validators_payout;
505+
506+ ( validators_payout, rest)
507+ }
508+ }
509+
493510/// Calculates 1 - exp(-x) for small positive x
494511fn exp_helper ( x : Perbill ) -> Perbill {
495512 let x2 = x * x;
@@ -505,18 +522,7 @@ impl pallet_staking::EraPayout<Balance> for ExponentialEraPayout {
505522 total_issuance : Balance ,
506523 era_duration_millis : u64 ,
507524 ) -> ( Balance , Balance ) {
508- const VALIDATOR_REWARD : Perbill = Perbill :: from_percent ( 90 ) ;
509-
510- let azero_cap = pallet_aleph:: AzeroCap :: < Runtime > :: get ( ) ;
511- let horizon = pallet_aleph:: ExponentialInflationHorizon :: < Runtime > :: get ( ) ;
512-
513- let total_payout: Balance =
514- exp_helper ( Perbill :: from_rational ( era_duration_millis, horizon) )
515- * ( azero_cap. saturating_sub ( total_issuance) ) ;
516- let validators_payout = VALIDATOR_REWARD * total_payout;
517- let rest = total_payout - validators_payout;
518-
519- ( validators_payout, rest)
525+ ExponentialEraPayout :: era_payout ( total_issuance, era_duration_millis)
520526 }
521527}
522528
@@ -1222,6 +1228,24 @@ impl_runtime_apis! {
12221228 fn key_owner( key: AlephId ) -> Option <AccountId > {
12231229 Session :: key_owner( primitives:: KEY_TYPE , key. as_ref( ) )
12241230 }
1231+
1232+ fn yearly_inflation( ) -> Perbill {
1233+ // Milliseconds per year for the Julian year (365.25 days).
1234+ const MILLISECONDS_PER_YEAR : u64 = 1000 * 3600 * 24 * 36525 / 100 ;
1235+ let total_issuance = pallet_balances:: Pallet :: <Runtime >:: total_issuance( ) ;
1236+
1237+ let ( validator_payout, rest)
1238+ = ExponentialEraPayout :: era_payout( total_issuance, MILLISECONDS_PER_YEAR ) ;
1239+
1240+ Perbill :: from_rational( validator_payout + rest, total_issuance)
1241+ }
1242+
1243+ fn current_era_payout( ) -> ( Balance , Balance ) {
1244+ const MILLISECONDS_PER_ERA : u64 = 1000 * 3600 * 24 ;
1245+ let total_issuance = pallet_balances:: Pallet :: <Runtime >:: total_issuance( ) ;
1246+
1247+ ExponentialEraPayout :: era_payout( total_issuance, MILLISECONDS_PER_ERA )
1248+ }
12251249 }
12261250
12271251 impl pallet_nomination_pools_runtime_api:: NominationPoolsApi <Block , AccountId , Balance > for Runtime {
0 commit comments