mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Treasury burning can be directed (#6671)
* Treasury burning can be directed Also, Society is a imbalance handler * Build * Introduce from_permill in perthings. * Rename to from_perthousand to avoid confusion with Permill * Fixes
This commit is contained in:
@@ -264,11 +264,12 @@ use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, d
|
||||
use frame_support::weights::Weight;
|
||||
use frame_support::traits::{
|
||||
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
|
||||
ExistenceRequirement::AllowDeath, EnsureOrigin
|
||||
ExistenceRequirement::AllowDeath, EnsureOrigin, OnUnbalanced, Imbalance
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
|
||||
type BalanceOf<T, I> = <<T as Trait<I>>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
|
||||
|
||||
/// The module's configuration trait.
|
||||
pub trait Trait<I=DefaultInstance>: system::Trait {
|
||||
@@ -1143,6 +1144,8 @@ decl_event! {
|
||||
NewMaxMembers(u32),
|
||||
/// Society is unfounded.
|
||||
Unfounded(AccountId),
|
||||
/// Some funds were deposited into the society account.
|
||||
Deposit(Balance),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1665,3 +1668,14 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> OnUnbalanced<NegativeImbalanceOf<T>> for Module<T> {
|
||||
fn on_nonzero_unbalanced(amount: NegativeImbalanceOf<T>) {
|
||||
let numeric_amount = amount.peek();
|
||||
|
||||
// Must resolve into existing but better to be safe.
|
||||
let _ = T::Currency::resolve_creating(&Self::account_id(), amount);
|
||||
|
||||
Self::deposit_event(RawEvent::Deposit(numeric_amount));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -897,6 +897,14 @@ pub trait Currency<AccountId> {
|
||||
/// in the case of overflow.
|
||||
fn issue(amount: Self::Balance) -> Self::NegativeImbalance;
|
||||
|
||||
/// Produce a pair of imbalances that cancel each other out exactly.
|
||||
///
|
||||
/// This is just the same as burning and issuing the same amount and has no effect on the
|
||||
/// total issuance.
|
||||
fn pair(amount: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) {
|
||||
(Self::burn(amount.clone()), Self::issue(amount))
|
||||
}
|
||||
|
||||
/// The 'free' balance of a given account.
|
||||
///
|
||||
/// This is the only balance that matters in terms of most operations on tokens. It alone
|
||||
|
||||
@@ -184,6 +184,9 @@ pub trait Trait: frame_system::Trait {
|
||||
/// Percentage of spare funds (if any) that are burnt per spend period.
|
||||
type Burn: Get<Permill>;
|
||||
|
||||
/// Handler for the unbalanced decrease when treasury funds are burned.
|
||||
type BurnDestination: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
@@ -771,7 +774,10 @@ impl<T: Trait> Module<T> {
|
||||
// burn some proportion of the remaining budget if we run a surplus.
|
||||
let burn = (T::Burn::get() * budget_remaining).min(budget_remaining);
|
||||
budget_remaining -= burn;
|
||||
imbalance.subsume(T::Currency::burn(burn));
|
||||
|
||||
let (debit, credit) = T::Currency::pair(burn);
|
||||
imbalance.subsume(debit);
|
||||
T::BurnDestination::on_unbalanced(credit);
|
||||
Self::deposit_event(RawEvent::Burnt(burn))
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ impl Trait for Test {
|
||||
type ProposalBondMinimum = ProposalBondMinimum;
|
||||
type SpendPeriod = SpendPeriod;
|
||||
type Burn = Burn;
|
||||
type BurnDestination = (); // Just gets burned.
|
||||
type WeightInfo = ();
|
||||
}
|
||||
type System = frame_system::Module<Test>;
|
||||
|
||||
Reference in New Issue
Block a user