mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 23:37:56 +00:00
Migrate fee payment from Currency to fungible (#2292)
Part of https://github.com/paritytech/polkadot-sdk/issues/226 Related https://github.com/paritytech/polkadot-sdk/issues/1833 - Deprecate `CurrencyAdapter` and introduce `FungibleAdapter` - Deprecate `ToStakingPot` and replace usage with `ResolveTo` - Required creating a new `StakingPotAccountId` struct that implements `TypedGet` for the staking pot account ID - Update parachain common utils `DealWithFees`, `ToAuthor` and `AssetsToBlockAuthor` implementations to use `fungible` - Update runtime XCM Weight Traders to use `ResolveTo` instead of `ToStakingPot` - Update runtime Transaction Payment pallets to use `FungibleAdapter` instead of `CurrencyAdapter` - [x] Blocked by https://github.com/paritytech/polkadot-sdk/pull/1296, needs the `Unbalanced::decrease_balance` fix
This commit is contained in:
@@ -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>;
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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 = ();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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`
|
||||
/// trait (eg. the pallet_balances) using an unbalance handler (implementing
|
||||
/// `OnUnbalanced`).
|
||||
/// 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.
|
||||
/// 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`]).
|
||||
///
|
||||
/// 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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user