diff --git a/bridges/bin/runtime-common/src/mock.rs b/bridges/bin/runtime-common/src/mock.rs index 8c4cb2233e17c7ff0f6aa05f45483db07ef2b707..ad71cd0d456d827d3757433d214f7ea794406fca 100644 --- a/bridges/bin/runtime-common/src/mock.rs +++ b/bridges/bin/runtime-common/src/mock.rs @@ -166,7 +166,7 @@ impl pallet_balances::Config for TestRuntime { #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)] impl pallet_transaction_payment::Config for TestRuntime { - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee<ThisChainBalance>; type LengthToFee = ConstantMultiplier<ThisChainBalance, TransactionByteFee>; diff --git a/cumulus/pallets/collator-selection/src/lib.rs b/cumulus/pallets/collator-selection/src/lib.rs index 84bde5c9fac9f640692458f02b37f0ee108a734f..82cce385b4d4625e704e0356a761f946629b5547 100644 --- a/cumulus/pallets/collator-selection/src/lib.rs +++ b/cumulus/pallets/collator-selection/src/lib.rs @@ -81,6 +81,8 @@ #![cfg_attr(not(feature = "std"), no_std)] +use core::marker::PhantomData; +use frame_support::traits::TypedGet; pub use pallet::*; #[cfg(test)] @@ -981,3 +983,15 @@ pub mod pallet { } } } + +/// [`TypedGet`] implementaion to get the AccountId of the StakingPot. +pub struct StakingPotAccountId<R>(PhantomData<R>); +impl<R> TypedGet for StakingPotAccountId<R> +where + R: crate::Config, +{ + type Type = <R as frame_system::Config>::AccountId; + fn get() -> Self::Type { + <crate::Pallet<R>>::account_id() + } +} diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index 6a990740f0f1930fc259726fd85e966ae48887a2..d70fdfeb7095a2dbd6f5fd9a53caeb1272476743 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -17,10 +17,11 @@ //! Taken from polkadot/runtime/common (at a21cd64) and adapted for parachains. use frame_support::traits::{ - fungibles::{self, Balanced, Credit}, - Contains, ContainsPair, Currency, Get, Imbalance, OnUnbalanced, OriginTrait, + fungible, fungibles, tokens::imbalance::ResolveTo, Contains, ContainsPair, Currency, Defensive, + Get, Imbalance, OnUnbalanced, OriginTrait, }; use pallet_asset_tx_payment::HandleCredit; +use pallet_collator_selection::StakingPotAccountId; use sp_runtime::traits::Zero; use sp_std::{marker::PhantomData, prelude::*}; use xcm::latest::{ @@ -29,16 +30,20 @@ use xcm::latest::{ }; use xcm_executor::traits::ConvertLocation; +/// Type alias to conveniently refer to `frame_system`'s `Config::AccountId`. +pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId; + /// Type alias to conveniently refer to the `Currency::NegativeImbalance` associated type. pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency< <T as frame_system::Config>::AccountId, >>::NegativeImbalance; -/// Type alias to conveniently refer to `frame_system`'s `Config::AccountId`. -pub type AccountIdOf<R> = <R as frame_system::Config>::AccountId; - /// Implementation of `OnUnbalanced` that deposits the fees into a staking pot for later payout. +#[deprecated( + note = "ToStakingPot is deprecated and will be removed after March 2024. Please use frame_support::traits::tokens::imbalance::ResolveTo instead." +)] pub struct ToStakingPot<R>(PhantomData<R>); +#[allow(deprecated)] impl<R> OnUnbalanced<NegativeImbalance<R>> for ToStakingPot<R> where R: pallet_balances::Config + pallet_collator_selection::Config, @@ -47,25 +52,30 @@ where { fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) { let staking_pot = <pallet_collator_selection::Pallet<R>>::account_id(); + // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. <pallet_balances::Pallet<R>>::resolve_creating(&staking_pot, amount); } } -/// Implementation of `OnUnbalanced` that deals with the fees by combining tip and fee and passing -/// the result on to `ToStakingPot`. +/// Fungible implementation of `OnUnbalanced` that deals with the fees by combining tip and fee and +/// passing the result on to `ToStakingPot`. pub struct DealWithFees<R>(PhantomData<R>); -impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R> +impl<R> OnUnbalanced<fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R> where R: pallet_balances::Config + pallet_collator_selection::Config, AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>, <R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>, { - fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) { + fn on_unbalanceds<B>( + mut fees_then_tips: impl Iterator< + Item = fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>, + >, + ) { if let Some(mut fees) = fees_then_tips.next() { if let Some(tips) = fees_then_tips.next() { tips.merge_into(&mut fees); } - <ToStakingPot<R> as OnUnbalanced<_>>::on_unbalanced(fees); + ResolveTo::<StakingPotAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(fees) } } } @@ -79,10 +89,11 @@ where R: pallet_authorship::Config + pallet_assets::Config<I>, AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>, { - fn handle_credit(credit: Credit<AccountIdOf<R>, pallet_assets::Pallet<R, I>>) { + fn handle_credit(credit: fungibles::Credit<AccountIdOf<R>, pallet_assets::Pallet<R, I>>) { + use frame_support::traits::fungibles::Balanced; if let Some(author) = pallet_authorship::Pallet::<R>::author() { // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. - let _ = pallet_assets::Pallet::<R, I>::resolve(&author, credit); + let _ = pallet_assets::Pallet::<R, I>::resolve(&author, credit).defensive(); } } } @@ -313,8 +324,14 @@ mod tests { #[test] fn test_fees_and_tip_split() { new_test_ext().execute_with(|| { - let fee = Balances::issue(10); - let tip = Balances::issue(20); + let fee = + <pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(10); + let tip = + <pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(20); assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 7edec45abfbb2ee42d9e532498b887ea2b3c0e11..547d465802efb011e8ff2b70b25086a5eb975713 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -226,7 +226,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index f4ff985e2773f02c17c75dbf3fcf78dd6aa0ada2..f71b5e9c5e88bdd560f7fab2ecbd31ff96f4cd0c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -27,14 +27,13 @@ use assets_common::{ use frame_support::{ parameter_types, traits::{ - tokens::imbalance::ResolveAssetTo, ConstU32, Contains, Equals, Everything, Nothing, - PalletInfoAccess, + tokens::imbalance::{ResolveAssetTo, ResolveTo}, + ConstU32, Contains, Equals, Everything, Nothing, PalletInfoAccess, }, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -569,7 +568,13 @@ impl xcm_executor::Config for XcmConfig { MaxInstructions, >; type Trader = ( - UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToStakingPot<Runtime>>, + UsingComponents< + WeightToFee, + TokenLocation, + AccountId, + Balances, + ResolveTo<StakingPot, Balances>, + >, cumulus_primitives_utility::SwapFirstAssetTrader< TokenLocationV3, crate::AssetConversion, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index d17d5a707579d6df527adb0f625b225d95c5d385..97928d0548436da379097d72f3fcdd26d70c348b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -210,7 +210,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 7d3ed650e6bfcd10e91bfe19fb9463b6c8a4714f..360b1a7055b70ab7448c6ca180207fc499fff9f8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -27,14 +27,13 @@ use assets_common::{ use frame_support::{ parameter_types, traits::{ - tokens::imbalance::ResolveAssetTo, ConstU32, Contains, Equals, Everything, Nothing, - PalletInfoAccess, + tokens::imbalance::{ResolveAssetTo, ResolveTo}, + ConstU32, Contains, Equals, Everything, Nothing, PalletInfoAccess, }, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, RelayOrOtherSystemParachains, @@ -591,7 +590,13 @@ impl xcm_executor::Config for XcmConfig { MaxInstructions, >; type Trader = ( - UsingComponents<WeightToFee, WestendLocation, AccountId, Balances, ToStakingPot<Runtime>>, + UsingComponents< + WeightToFee, + WestendLocation, + AccountId, + Balances, + ResolveTo<StakingPot, Balances>, + >, cumulus_primitives_utility::SwapFirstAssetTrader< WestendLocationV3, crate::AssetConversion, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 9796a77f994e47d4e52fe75e8ab74434b97307d7..6ffb7eb3c948e8020213841fd02bc5c9eae90d53 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -317,7 +317,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 8934ff9b22729da0ea322792837d2a08d5829763..8de7aa742fc6887b37b19d9844455c3c3632dd7d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -33,13 +33,13 @@ use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParam use bp_runtime::ChainId; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, StoragePrefixedMap, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -295,8 +295,13 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = - UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + TokenLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetLocker = (); diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 4318df8f15edb5fbe1ad14d04e95e9821d82ccb6..9571cc68a18735d916e29455dd8585e46ab449e4 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -291,7 +291,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs index 840d0c9af0e5886eef81ea9bbc542279ff7a106f..dcefeeaef7095bd92f7595ac0c3b374874b1f0a1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs @@ -22,12 +22,12 @@ use super::{ use crate::bridge_common_config::{DeliveryRewardInBalance, RequiredStakeForStakeAndSlash}; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -244,8 +244,13 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = - UsingComponents<WeightToFee, WestendLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + WestendLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetLocker = (); diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 170b0a3960006cd2fbfbe0fb391ae4731a113b6c..b7410071f128c6148c6094a7ef92016388124aff 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -223,7 +223,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs index b83106a5828402390d1bd237ceb510d78b020b6d..34c0deef534e10c67d7cfaa16f6c93c501e834f9 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs @@ -20,17 +20,15 @@ use super::{ }; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, weights::Weight, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::{ - AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, - RelayOrOtherSystemParachains, - }, +use parachains_common::xcm_config::{ + AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, + RelayOrOtherSystemParachains, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; @@ -268,8 +266,13 @@ impl xcm_executor::Config for XcmConfig { type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds<TempFixedXcmWeight, RuntimeCall, MaxInstructions>; - type Trader = - UsingComponents<WeightToFee, WndLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + WndLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 936d87a23caa03e124d1a4fb1e3c3f86849d55cf..1d2da68067523ff8f22e9f896d0b6c88c7d7d70c 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -232,7 +232,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type WeightToFee = WeightToFee; /// Relay Chain `TransactionByteFee` / 10 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 27965aa204f98579fdc0735c0ae278b4e7a0852a..7e489cdd06fea373e28c1f4f0e8b763ec55dc486 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -244,7 +244,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs index 955f2eeba339c0e99a8364377dfc27ccc7557e80..afb68749f3b9b5872b53459ae00a79902b437aae 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs @@ -22,12 +22,12 @@ use super::{ use frame_support::{ pallet_prelude::PalletInfoAccess, parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -237,8 +237,13 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = - UsingComponents<WeightToFee, RocRelayLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + RocRelayLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 8075ffb4f1c2200f520131c9eb9d3dc4861db55b..d54e1be44fc759e29c841a82431cbb49351e124b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -244,7 +244,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs index fc7d36a8ba1854f1a52b7630d98b545a28868c74..eac07c97c01797896b43fa588825011fafeb4b29 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs @@ -22,12 +22,12 @@ use super::{ use frame_support::{ pallet_prelude::PalletInfoAccess, parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -249,7 +249,7 @@ impl xcm_executor::Config for XcmConfig { TokenRelayLocation, AccountId, Balances, - ToStakingPot<Runtime>, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 1b6499f5d6178ef16fdf1cb024cfd638e1331e45..4232d9e41dd48487dad13a3898325870e12b912e 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -225,7 +225,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index a10333fdb62651df1d8500f28379710da318d279..048728d271aa0462a1f58d1317923efd397ec585 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -20,12 +20,12 @@ use super::{ use crate::{TransactionByteFee, CENTS}; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -249,8 +249,13 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = - UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + RelayLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 6ae53d641b0c7cd812d405039d59bc93c5749597..25b17fd502e1f534ee96a289bf41bba65e7022c9 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -225,7 +225,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = - pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>; + pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index fee2f5684ac309c623a3914835e0d755953ca52f..368b20e1c9e05c93b1855467babda23882ffbc12 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -20,12 +20,12 @@ use super::{ use crate::{TransactionByteFee, CENTS}; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Equals, Everything, Nothing}, + traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing}, }; use frame_system::EnsureRoot; +use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; use parachains_common::{ - impls::ToStakingPot, xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -257,8 +257,13 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = - UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToStakingPot<Runtime>>; + type Trader = UsingComponents< + WeightToFee, + RelayLocation, + AccountId, + Balances, + ResolveTo<StakingPotAccountId<Runtime>, Balances>, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 0a55d2dcfe53ee5ba7bf98a223a300f02e97d05f..c8c469b76fed3531846d2beb8f1e93d333714e8b 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -416,7 +416,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 034d16267d450a03a395b6b9f7401231c5cfea69..d896d7492b5a32cca3017d9f2591686c9540916b 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -259,7 +259,7 @@ impl pallet_balances::Config for Runtime { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type WeightToFee = IdentityFee<Balance>; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = (); diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 5127b63f27155835f9f8bcd4ec50a4b47f9cc332..350c945765b4ad4f62cbfadf02f6a4b16bbea97b 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -241,7 +241,7 @@ impl pallet_balances::Config for Runtime { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type WeightToFee = IdentityFee<Balance>; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = (); diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index d405278411b7e4aa1f1133fb7356bf6929a370e6..a2143212d8c59ffac9b40dc9f4009c1b87c2e343 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -83,10 +83,6 @@ type CurrencyOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>> type LeasePeriodOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>>>::LeasePeriod; type BalanceOf<T> = <CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::Balance; -#[allow(dead_code)] -type NegativeImbalanceOf<T> = - <CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance; - type FundIndex = u32; pub trait WeightInfo { diff --git a/polkadot/runtime/common/src/impls.rs b/polkadot/runtime/common/src/impls.rs index acf5a701a62d0e7a5b60eee00d85528f5d9214b5..cc1243790c2e58b23c169de918f28d75397420ba 100644 --- a/polkadot/runtime/common/src/impls.rs +++ b/polkadot/runtime/common/src/impls.rs @@ -16,8 +16,12 @@ //! Auxiliary `struct`/`enum`s for polkadot runtime. -use crate::NegativeImbalance; -use frame_support::traits::{Currency, Imbalance, OnUnbalanced}; +use frame_support::traits::{ + fungible::{Balanced, Credit}, + tokens::imbalance::ResolveTo, + Imbalance, OnUnbalanced, +}; +use pallet_treasury::TreasuryAccountId; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::Balance; use sp_runtime::{traits::TryConvert, Perquintill, RuntimeDebug}; @@ -25,28 +29,31 @@ use xcm::VersionedLocation; /// Logic for the author to get a portion of fees. pub struct ToAuthor<R>(sp_std::marker::PhantomData<R>); -impl<R> OnUnbalanced<NegativeImbalance<R>> for ToAuthor<R> +impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for ToAuthor<R> where R: pallet_balances::Config + pallet_authorship::Config, <R as frame_system::Config>::AccountId: From<primitives::AccountId>, <R as frame_system::Config>::AccountId: Into<primitives::AccountId>, { - fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) { + fn on_nonzero_unbalanced( + amount: Credit<<R as frame_system::Config>::AccountId, pallet_balances::Pallet<R>>, + ) { if let Some(author) = <pallet_authorship::Pallet<R>>::author() { - <pallet_balances::Pallet<R>>::resolve_creating(&author, amount); + let _ = <pallet_balances::Pallet<R>>::resolve(&author, amount); } } } pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>); -impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R> +impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R> where - R: pallet_balances::Config + pallet_treasury::Config + pallet_authorship::Config, - pallet_treasury::Pallet<R>: OnUnbalanced<NegativeImbalance<R>>, + R: pallet_balances::Config + pallet_authorship::Config + pallet_treasury::Config, <R as frame_system::Config>::AccountId: From<primitives::AccountId>, <R as frame_system::Config>::AccountId: Into<primitives::AccountId>, { - fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) { + fn on_unbalanceds<B>( + mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>, + ) { if let Some(fees) = fees_then_tips.next() { // for fees, 80% to treasury, 20% to author let mut split = fees.ration(80, 20); @@ -54,8 +61,7 @@ where // for tips, if any, 100% to author tips.merge_into(&mut split.1); } - use pallet_treasury::Pallet as Treasury; - <Treasury<R> as OnUnbalanced<_>>::on_unbalanced(split.0); + ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(split.0); <ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(split.1); } } @@ -366,8 +372,14 @@ mod tests { #[test] fn test_fees_and_tip_split() { new_test_ext().execute_with(|| { - let fee = Balances::issue(10); - let tip = Balances::issue(20); + let fee = + <pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(10); + let tip = + <pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(20); assert_eq!(Balances::free_balance(Treasury::account_id()), 0); assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0); diff --git a/polkadot/runtime/common/src/lib.rs b/polkadot/runtime/common/src/lib.rs index bd49d3cccc9cac99f3a11b698629dfd51b847816..65161764ccd7bf363a85238fbf7a708421561743 100644 --- a/polkadot/runtime/common/src/lib.rs +++ b/polkadot/runtime/common/src/lib.rs @@ -63,6 +63,9 @@ pub use sp_runtime::BuildStorage; /// Implementations of some helper traits passed into runtime modules as associated types. pub use impls::ToAuthor; +#[deprecated( + note = "Please use fungible::Credit instead. This type will be removed some time after March 2024." +)] pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency< <T as frame_system::Config>::AccountId, >>::NegativeImbalance; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 7d16d2dbf1655d2c9563c247896afc42ca7714f7..471bb891e00ed5726468d85b22c1701c0d15961d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -79,7 +79,7 @@ use frame_system::{EnsureRoot, EnsureSigned}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; use pallet_session::historical as session_historical; -use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; +use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo}; use sp_core::{ConstU128, OpaqueMetadata, H256}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -324,7 +324,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ToAuthor<Runtime>>; + type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 446cd101efffb81c60fc44fa96130777ed027203..40aa4a1d499747888028f65f290cfc6208e3110d 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -20,7 +20,7 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::FungibleAdapter; use parity_scale_codec::Encode; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -233,7 +233,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = FungibleAdapter<Balances, ()>; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; type LengthToFee = frame_support::weights::ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9445e27f0e51c016ed2744ebc930bb8dd046d875..4de1dbc16e095aa8140f0f95004bde39f174feca 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -42,7 +42,7 @@ use frame_system::{EnsureRoot, EnsureSigned}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; use pallet_session::historical as session_historical; -use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; +use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ slashing, AccountId, AccountIndex, ApprovalVotingParams, Balance, BlockNumber, CandidateEvent, @@ -377,7 +377,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ToAuthor<Runtime>>; + type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/polkadot/xcm/xcm-builder/src/weight.rs b/polkadot/xcm/xcm-builder/src/weight.rs index 6026218f55316ea950ae5482bb72bfda86c8f511..6141b0142eed00fa8fb3a3e834b71fae51cffe86 100644 --- a/polkadot/xcm/xcm-builder/src/weight.rs +++ b/polkadot/xcm/xcm-builder/src/weight.rs @@ -16,7 +16,10 @@ use frame_support::{ dispatch::GetDispatchInfo, - traits::{tokens::currency::Currency as CurrencyT, Get, OnUnbalanced as OnUnbalancedT}, + traits::{ + fungible::{Balanced, Credit, Inspect}, + Get, OnUnbalanced as OnUnbalancedT, + }, weights::{ constants::{WEIGHT_PROOF_SIZE_PER_MB, WEIGHT_REF_TIME_PER_SECOND}, WeightToFee as WeightToFeeT, @@ -193,23 +196,23 @@ impl<T: Get<(AssetId, u128, u128)>, R: TakeRevenue> Drop for FixedRateOfFungible /// Weight trader which uses the configured `WeightToFee` to set the right price for weight and then /// places any weight bought into the right account. pub struct UsingComponents< - WeightToFee: WeightToFeeT<Balance = Currency::Balance>, + WeightToFee: WeightToFeeT<Balance = <Fungible as Inspect<AccountId>>::Balance>, AssetIdValue: Get<Location>, AccountId, - Currency: CurrencyT<AccountId>, - OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>, + Fungible: Balanced<AccountId> + Inspect<AccountId>, + OnUnbalanced: OnUnbalancedT<Credit<AccountId, Fungible>>, >( Weight, - Currency::Balance, - PhantomData<(WeightToFee, AssetIdValue, AccountId, Currency, OnUnbalanced)>, + Fungible::Balance, + PhantomData<(WeightToFee, AssetIdValue, AccountId, Fungible, OnUnbalanced)>, ); impl< - WeightToFee: WeightToFeeT<Balance = Currency::Balance>, + WeightToFee: WeightToFeeT<Balance = <Fungible as Inspect<AccountId>>::Balance>, AssetIdValue: Get<Location>, AccountId, - Currency: CurrencyT<AccountId>, - OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>, - > WeightTrader for UsingComponents<WeightToFee, AssetIdValue, AccountId, Currency, OnUnbalanced> + Fungible: Balanced<AccountId> + Inspect<AccountId>, + OnUnbalanced: OnUnbalancedT<Credit<AccountId, Fungible>>, + > WeightTrader for UsingComponents<WeightToFee, AssetIdValue, AccountId, Fungible, OnUnbalanced> { fn new() -> Self { Self(Weight::zero(), Zero::zero(), PhantomData) @@ -247,14 +250,14 @@ impl< } } impl< - WeightToFee: WeightToFeeT<Balance = Currency::Balance>, + WeightToFee: WeightToFeeT<Balance = <Fungible as Inspect<AccountId>>::Balance>, AssetId: Get<Location>, AccountId, - Currency: CurrencyT<AccountId>, - OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>, - > Drop for UsingComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced> + Fungible: Balanced<AccountId> + Inspect<AccountId>, + OnUnbalanced: OnUnbalancedT<Credit<AccountId, Fungible>>, + > Drop for UsingComponents<WeightToFee, AssetId, AccountId, Fungible, OnUnbalanced> { fn drop(&mut self) { - OnUnbalanced::on_unbalanced(Currency::issue(self.1)); + OnUnbalanced::on_unbalanced(Fungible::issue(self.1)); } } diff --git a/prdoc/pr_2292.prdoc b/prdoc/pr_2292.prdoc new file mode 100644 index 0000000000000000000000000000000000000000..e4c50f7806baea41aa27d2ba0da647e514e7ba4d --- /dev/null +++ b/prdoc/pr_2292.prdoc @@ -0,0 +1,59 @@ +title: Migrate Fee Payment from Currency to fungible traits + +doc: + - audience: Runtime Dev + description: | + Deprecates the `CurrencyAdapter` and introduces `FungibleAdapter` + Deprecates `ToStakingPot` and replaces usage with `ResolveTo` + Updated `DealWithFees`, `ToAuthor`, `AssetsToBlockAuthor` to all use `fungible` traits + Updated runtime XCM Weight Traders to use `ResolveTo` + Updated runtime TransactionPayment pallets to use `FungibleAdapter` instead of `CurrencyAdapter` + + Runtime Migration Guide: + - Replace usage of `CurrencyAdapter` with `FungibleAdapter` + - Replace usage of `ToStakingPot<Runtime>` with `ResolveTo<pallet_collator_selection::StakingPotAccountId<Runtime>, Balances>` + +crates: + - name: pallet-collator-selection + bump: minor + - name: parachains-common + bump: major + - name: asset-hub-rococo-runtime + bump: major + - name: asset-hub-westend-runtime + bump: major + - name: bridge-hub-westend-runtime + bump: major + - name: bridge-hub-rococo-runtime + bump: major + - name: collectives-westend-runtime + bump: major + - name: contracts-rococo-runtime + bump: major + - name: coretime-rococo-runtime + bump: major + - name: coretime-westend-runtime + bump: major + - name: people-westend-runtime + bump: major + - name: people-rococo-runtime + bump: major + - name: polkadot-runtime-common + bump: major + - name: westend-runtime + bump: major + - name: rococo-runtime + bump: major + - name: staging-xcm-builder + bump: major + - name: kitchensink-runtime + bump: major + - name: pallet-transaction-payment + bump: minor + - name: minimal-template-runtime + bump: major + - name: parachain-template-runtime + bump: major + - name: solochain-template-runtime + bump: major + diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 191244c3bb060cec264995f760d43abc7bd2613a..5ed5e7943f696bb21501ee7bf8500e693870ee05 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -71,6 +71,9 @@ use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_nfts::PalletFeatures; use pallet_nis::WithMaximumOf; use pallet_session::historical as pallet_session_historical; +// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles +// <https://github.com/paritytech/polkadot-sdk/issues/226> +#[allow(deprecated)] pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use pallet_tx_pause::RuntimeCallNameOf; @@ -549,6 +552,9 @@ parameter_types! { pub MaximumMultiplier: Multiplier = Bounded::max_value(); } +// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles +// <https://github.com/paritytech/polkadot-sdk/issues/226> +#[allow(deprecated)] impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>; diff --git a/substrate/frame/balances/src/tests/mod.rs b/substrate/frame/balances/src/tests/mod.rs index f2f107d8bd64ea4115b45fc29a84abfaff34ba92..234fe6eaf2c3298183d55d646a8af6bad14153c1 100644 --- a/substrate/frame/balances/src/tests/mod.rs +++ b/substrate/frame/balances/src/tests/mod.rs @@ -32,7 +32,7 @@ use frame_support::{ weights::{IdentityFee, Weight}, }; use frame_system::{self as system, RawOrigin}; -use pallet_transaction_payment::{ChargeTransactionPayment, CurrencyAdapter, Multiplier}; +use pallet_transaction_payment::{ChargeTransactionPayment, FungibleAdapter, Multiplier}; use scale_info::TypeInfo; use sp_core::hexdisplay::HexDisplay; use sp_io; @@ -99,7 +99,7 @@ impl frame_system::Config for Test { #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)] impl pallet_transaction_payment::Config for Test { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>; + type OnChargeTransaction = FungibleAdapter<Pallet<Test>, ()>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee<u64>; type LengthToFee = IdentityFee<u64>; diff --git a/substrate/frame/executive/src/tests.rs b/substrate/frame/executive/src/tests.rs index 204889a292fd720aa89cb343435849be0ca8e442..e3721f7b6dcbac24be073515d78fbf0f1d2658b8 100644 --- a/substrate/frame/executive/src/tests.rs +++ b/substrate/frame/executive/src/tests.rs @@ -19,6 +19,7 @@ use super::*; +use pallet_transaction_payment::FungibleAdapter; use sp_core::H256; use sp_runtime::{ generic::{DigestItem, Era}, @@ -40,7 +41,6 @@ use frame_support::{ }; use frame_system::{pallet_prelude::*, ChainContext, LastRuntimeUpgrade, LastRuntimeUpgradeInfo}; use pallet_balances::Call as BalancesCall; -use pallet_transaction_payment::CurrencyAdapter; const TEST_KEY: &[u8] = b":test:key:"; @@ -338,7 +338,7 @@ parameter_types! { } impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = FungibleAdapter<Balances, ()>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee<Balance>; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs index bd9565fe1887c3b1a117c62fae25a2744586318a..d61558cf536362bbaa5abd4a451fa5f4589a85bd 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs @@ -24,6 +24,7 @@ use frame_support::{ pallet_prelude::*, parameter_types, traits::{ + fungible, tokens::{ fungible::{NativeFromLeft, NativeOrWithId, UnionOf}, imbalance::ResolveAssetTo, @@ -36,7 +37,7 @@ use frame_support::{ use frame_system as system; use frame_system::{EnsureRoot, EnsureSignedBy}; use pallet_asset_conversion::{Ascending, Chain, WithFirstAsset}; -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::FungibleAdapter; use sp_core::H256; use sp_runtime::{ traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, SaturatedConversion}, @@ -155,9 +156,13 @@ parameter_types! { } pub struct DealWithFees; -impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees { +impl OnUnbalanced<fungible::Credit<<Runtime as frame_system::Config>::AccountId, Balances>> + for DealWithFees +{ fn on_unbalanceds<B>( - mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<Runtime>>, + mut fees_then_tips: impl Iterator< + Item = fungible::Credit<<Runtime as frame_system::Config>::AccountId, Balances>, + >, ) { if let Some(fees) = fees_then_tips.next() { FeeUnbalancedAmount::mutate(|a| *a += fees.peek()); @@ -171,7 +176,7 @@ impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)] impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>; + type OnChargeTransaction = FungibleAdapter<Balances, DealWithFees>; type WeightToFee = WeightToFee; type LengthToFee = TransactionByteFee; type FeeMultiplierUpdate = (); diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs index 4387f319c3b542a84902d24faabd4fc955b9b031..b04d4ffd9e0b794f56fd7be0219f8150f45e7078 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -28,7 +28,7 @@ use frame_support::{ }; use frame_system as system; use frame_system::EnsureRoot; -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::FungibleAdapter; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, ConvertInto, IdentityLookup, SaturatedConversion}; @@ -139,7 +139,7 @@ impl WeightToFeeT for TransactionByteFee { #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)] impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = FungibleAdapter<Balances, ()>; type WeightToFee = WeightToFee; type LengthToFee = TransactionByteFee; type FeeMultiplierUpdate = (); diff --git a/substrate/frame/transaction-payment/src/mock.rs b/substrate/frame/transaction-payment/src/mock.rs index 67ad1caa02ff8d05acd4a33d671aa7e26daae253..c1bb05ab5c7eb8e03c49e5f8d789276de296bba9 100644 --- a/substrate/frame/transaction-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/src/mock.rs @@ -25,7 +25,7 @@ use frame_support::{ derive_impl, dispatch::DispatchClass, parameter_types, - traits::{ConstU32, ConstU64, Imbalance, OnUnbalanced}, + traits::{fungible, ConstU32, ConstU64, Imbalance, OnUnbalanced}, weights::{Weight, WeightToFee as WeightToFeeT}, }; use frame_system as system; @@ -137,9 +137,13 @@ parameter_types! { } pub struct DealWithFees; -impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees { +impl OnUnbalanced<fungible::Credit<<Runtime as frame_system::Config>::AccountId, Balances>> + for DealWithFees +{ fn on_unbalanceds<B>( - mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<Runtime>>, + mut fees_then_tips: impl Iterator< + Item = fungible::Credit<<Runtime as frame_system::Config>::AccountId, Balances>, + >, ) { if let Some(fees) = fees_then_tips.next() { FeeUnbalancedAmount::mutate(|a| *a += fees.peek()); @@ -152,7 +156,7 @@ impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees impl Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>; + type OnChargeTransaction = FungibleAdapter<Balances, DealWithFees>; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; type LengthToFee = TransactionByteFee; diff --git a/substrate/frame/transaction-payment/src/payment.rs b/substrate/frame/transaction-payment/src/payment.rs index 886683f2e0b883aea0ccd4e769c902ee45bdf99a..0fe616782903c822eb1f1af19323af75f442adb2 100644 --- a/substrate/frame/transaction-payment/src/payment.rs +++ b/substrate/frame/transaction-payment/src/payment.rs @@ -25,7 +25,11 @@ use sp_runtime::{ }; use frame_support::{ - traits::{Currency, ExistenceRequirement, Imbalance, OnUnbalanced, WithdrawReasons}, + traits::{ + fungible::{Balanced, Credit, Debt, Inspect}, + tokens::Precision, + Currency, ExistenceRequirement, Imbalance, OnUnbalanced, WithdrawReasons, + }, unsigned::TransactionValidityError, }; @@ -66,18 +70,95 @@ pub trait OnChargeTransaction<T: Config> { ) -> Result<(), TransactionValidityError>; } -/// Implements the transaction payment for a pallet implementing the `Currency` +/// Implements transaction payment for a pallet implementing the [`frame_support::traits::fungible`] +/// trait (eg. pallet_balances) using an unbalance handler (implementing +/// [`OnUnbalanced`]). +/// +/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: `fee` and +/// then `tip`. +pub struct FungibleAdapter<F, OU>(PhantomData<(F, OU)>); + +impl<T, F, OU> OnChargeTransaction<T> for FungibleAdapter<F, OU> +where + T: Config, + F: Balanced<T::AccountId>, + OU: OnUnbalanced<Credit<T::AccountId, F>>, +{ + type LiquidityInfo = Option<Credit<T::AccountId, F>>; + type Balance = <F as Inspect<<T as frame_system::Config>::AccountId>>::Balance; + + fn withdraw_fee( + who: &<T>::AccountId, + _call: &<T>::RuntimeCall, + _dispatch_info: &DispatchInfoOf<<T>::RuntimeCall>, + fee: Self::Balance, + _tip: Self::Balance, + ) -> Result<Self::LiquidityInfo, TransactionValidityError> { + if fee.is_zero() { + return Ok(None) + } + + match F::withdraw( + who, + fee, + Precision::Exact, + frame_support::traits::tokens::Preservation::Preserve, + frame_support::traits::tokens::Fortitude::Polite, + ) { + Ok(imbalance) => Ok(Some(imbalance)), + Err(_) => Err(InvalidTransaction::Payment.into()), + } + } + + fn correct_and_deposit_fee( + who: &<T>::AccountId, + _dispatch_info: &DispatchInfoOf<<T>::RuntimeCall>, + _post_info: &PostDispatchInfoOf<<T>::RuntimeCall>, + corrected_fee: Self::Balance, + tip: Self::Balance, + already_withdrawn: Self::LiquidityInfo, + ) -> Result<(), TransactionValidityError> { + if let Some(paid) = already_withdrawn { + // Calculate how much refund we should return + let refund_amount = paid.peek().saturating_sub(corrected_fee); + // refund to the the account that paid the fees if it exists. otherwise, don't refind + // anything. + let refund_imbalance = if F::total_balance(who) > F::Balance::zero() { + F::deposit(who, refund_amount, Precision::BestEffort) + .unwrap_or_else(|_| Debt::<T::AccountId, F>::zero()) + } else { + Debt::<T::AccountId, F>::zero() + }; + // merge the imbalance caused by paying the fees and refunding parts of it again. + let adjusted_paid: Credit<T::AccountId, F> = paid + .offset(refund_imbalance) + .same() + .map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Payment))?; + // Call someone else to handle the imbalance (fee and tip separately) + let (tip, fee) = adjusted_paid.split(tip); + OU::on_unbalanceds(Some(fee).into_iter().chain(Some(tip))); + } + + Ok(()) + } +} + +/// Implements the transaction payment for a pallet implementing the [`Currency`] /// trait (eg. the pallet_balances) using an unbalance handler (implementing -/// `OnUnbalanced`). +/// [`OnUnbalanced`]). /// -/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: fee and -/// then tip. +/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: `fee` and +/// then `tip`. +#[deprecated( + note = "Please use the fungible trait and FungibleAdapter. This struct will be removed some time after March 2024." +)] pub struct CurrencyAdapter<C, OU>(PhantomData<(C, OU)>); /// Default implementation for a Currency and an OnUnbalanced handler. /// -/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: fee and -/// then tip. +/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: `fee` and +/// then `tip`. +#[allow(deprecated)] impl<T, C, OU> OnChargeTransaction<T> for CurrencyAdapter<C, OU> where T: Config, diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index d569ae406ea39aa9734d145968924ba1309e2f60..2723c4289d928aaaec58f64e8b82bf45c1bda5b2 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -76,6 +76,8 @@ mod benchmarking; #[cfg(test)] mod tests; pub mod weights; +use core::marker::PhantomData; + #[cfg(feature = "runtime-benchmarks")] pub use benchmarking::ArgumentsFactory; @@ -1120,3 +1122,15 @@ impl<T: Config<I>, I: 'static> OnUnbalanced<NegativeImbalanceOf<T, I>> for Palle Self::deposit_event(Event::Deposit { value: numeric_amount }); } } + +/// TypedGet implementaion to get the AccountId of the Treasury. +pub struct TreasuryAccountId<R>(PhantomData<R>); +impl<R> sp_runtime::traits::TypedGet for TreasuryAccountId<R> +where + R: crate::Config, +{ + type Type = <R as frame_system::Config>::AccountId; + fn get() -> Self::Type { + <crate::Pallet<R>>::account_id() + } +} diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 00fcaf1cec76a3aecefa64bc7da3a0a74df2f06e..f386169130cec4de41894564beb86fc7de9b64fa 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -104,7 +104,7 @@ impl pallet_timestamp::Config for Runtime {} #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)] impl pallet_transaction_payment::Config for Runtime { - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type WeightToFee = NoFee<<Self as pallet_balances::Config>::Balance>; type LengthToFee = FixedFee<1, <Self as pallet_balances::Config>::Balance>; } diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index e2c51e07d37b9fc453865f161f37aa2365d07ed5..f1aea481ee277c5b753452bab315175cb4afb741 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -166,7 +166,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 5a97bd2f39120b1bdf119b0638464e6eceb45047..f3353d19be6ac2d029c79ea5cf7498f6eb3c073f 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -36,7 +36,7 @@ pub use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::{ConstFeeMultiplier, CurrencyAdapter, Multiplier}; +use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; @@ -230,7 +230,7 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = FungibleAdapter<Balances, ()>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee<Balance>; type LengthToFee = IdentityFee<Balance>;