diff --git a/prdoc/pr_10587.prdoc b/prdoc/pr_10587.prdoc new file mode 100644 index 0000000000000..e89a28e58c0be --- /dev/null +++ b/prdoc/pr_10587.prdoc @@ -0,0 +1,10 @@ +title: Derive extra traits for fungibles::Imbalance +doc: +- audience: Runtime Dev + description: |- + This PR adds the same derived traits to `fungibles::Imbalance` that are already derived for `fungible::Imbalance`. + + This is required so that the `OnChargeTransaction` configuration of `pallet_transaction_payment` can work for the `fungibles` version of types/traits (it already works for `fungible`). +crates: +- name: frame-support + bump: patch diff --git a/substrate/frame/support/src/traits/tokens/fungibles/imbalance.rs b/substrate/frame/support/src/traits/tokens/fungibles/imbalance.rs index 349d9d7c65e89..3c4bd149d5472 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/imbalance.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/imbalance.rs @@ -21,12 +21,15 @@ //! See the [`crate::traits::fungibles`] doc for more information about fungibles traits. use super::*; -use crate::traits::{ - fungible, - misc::{SameOrOther, TryDrop}, - tokens::{ - imbalance::{Imbalance as ImbalanceT, TryMerge}, - AssetId, Balance, +use crate::{ + pallet_prelude::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen, TypeInfo}, + traits::{ + fungible, + misc::{SameOrOther, TryDrop}, + tokens::{ + imbalance::{Imbalance as ImbalanceT, TryMerge}, + AssetId, Balance, + }, }, }; use core::marker::PhantomData; @@ -45,7 +48,16 @@ pub trait HandleImbalanceDrop { /// /// Importantly, it has a special `Drop` impl, and cannot be created outside of this module. #[must_use] -#[derive(EqNoBound, PartialEqNoBound, RuntimeDebugNoBound)] +#[derive( + EqNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + Encode, + Decode, + DecodeWithMemTracking, + MaxEncodedLen, + TypeInfo, +)] pub struct Imbalance< A: AssetId, B: Balance, @@ -84,6 +96,18 @@ impl< } } +impl< + A: AssetId + Default, + B: Balance, + OnDrop: HandleImbalanceDrop, + OppositeOnDrop: HandleImbalanceDrop, + > Default for Imbalance +{ + fn default() -> Self { + Self::zero(Default::default()) + } +} + impl< A: AssetId, B: Balance,