mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 13:51:11 +00:00
Treasury rewards should pay the remainder of the 10% (#4026)
* Treasury rewards should pay the remainder of the 10%.. * Event for deposits coming into treasury * Fix tests * Remove OnDilution
This commit is contained in:
@@ -256,7 +256,7 @@ use codec::{HasCompact, Encode, Decode};
|
||||
use support::{
|
||||
decl_module, decl_event, decl_storage, ensure,
|
||||
traits::{
|
||||
Currency, OnFreeBalanceZero, OnDilution, LockIdentifier, LockableCurrency,
|
||||
Currency, OnFreeBalanceZero, LockIdentifier, LockableCurrency,
|
||||
WithdrawReasons, OnUnbalanced, Imbalance, Get, Time
|
||||
}
|
||||
};
|
||||
@@ -501,8 +501,8 @@ pub trait Trait: system::Trait {
|
||||
/// The post-processing needs it but will be moved to off-chain. TODO: #2908
|
||||
type CurrencyToVote: Convert<BalanceOf<Self>, u64> + Convert<u128, BalanceOf<Self>>;
|
||||
|
||||
/// Some tokens minted.
|
||||
type OnRewardMinted: OnDilution<BalanceOf<Self>>;
|
||||
/// Tokens have been minted and are unused for validator-reward.
|
||||
type RewardRemainder: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
@@ -524,6 +524,10 @@ pub trait Trait: system::Trait {
|
||||
|
||||
/// The NPoS reward curve to use.
|
||||
type RewardCurve: Get<&'static PiecewiseLinear<'static>>;
|
||||
|
||||
/// The maximum possible reward (in proportion of total issued tokens) that can be paid in one
|
||||
/// reward cycle.
|
||||
type MaxPossibleReward: Get<Perbill>;
|
||||
}
|
||||
|
||||
/// Mode of era-forcing.
|
||||
@@ -652,8 +656,9 @@ decl_storage! {
|
||||
|
||||
decl_event!(
|
||||
pub enum Event<T> where Balance = BalanceOf<T>, <T as system::Trait>::AccountId {
|
||||
/// All validators have been rewarded by the given balance.
|
||||
Reward(Balance),
|
||||
/// All validators have been rewarded by the first balance; the second is the remainder
|
||||
/// from the maximum amount of reward.
|
||||
Reward(Balance, Balance),
|
||||
/// One validator (and its nominators) has been slashed by the given amount.
|
||||
Slash(AccountId, Balance),
|
||||
/// An old slashing report from a prior era was discarded because it could
|
||||
@@ -1218,9 +1223,13 @@ impl<T: Trait> Module<T> {
|
||||
let total_reward = total_imbalance.peek();
|
||||
// assert!(total_reward <= total_payout)
|
||||
|
||||
Self::deposit_event(RawEvent::Reward(total_reward));
|
||||
let max_reward = T::MaxPossibleReward::get() * T::Currency::total_issuance();
|
||||
let rest_reward = max_reward.saturating_sub(total_reward);
|
||||
|
||||
Self::deposit_event(RawEvent::Reward(total_reward, rest_reward));
|
||||
|
||||
T::Reward::on_unbalanced(total_imbalance);
|
||||
T::OnRewardMinted::on_dilution(total_reward, total_rewarded_stake);
|
||||
T::RewardRemainder::on_unbalanced(T::Currency::issue(rest_reward));
|
||||
}
|
||||
|
||||
// Increment current era.
|
||||
|
||||
@@ -192,12 +192,13 @@ parameter_types! {
|
||||
pub const SessionsPerEra: SessionIndex = 3;
|
||||
pub const BondingDuration: EraIndex = 3;
|
||||
pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
|
||||
pub const MaxReward: Perbill = Perbill::from_percent(10);
|
||||
}
|
||||
impl Trait for Test {
|
||||
type Currency = balances::Module<Self>;
|
||||
type Time = timestamp::Module<Self>;
|
||||
type CurrencyToVote = CurrencyToVoteHandler;
|
||||
type OnRewardMinted = ();
|
||||
type RewardRemainder = ();
|
||||
type Event = ();
|
||||
type Slash = ();
|
||||
type Reward = ();
|
||||
@@ -205,6 +206,7 @@ impl Trait for Test {
|
||||
type BondingDuration = BondingDuration;
|
||||
type SessionInterface = Self;
|
||||
type RewardCurve = RewardCurve;
|
||||
type MaxPossibleReward = MaxReward;
|
||||
}
|
||||
|
||||
pub struct ExtBuilder {
|
||||
|
||||
Reference in New Issue
Block a user