diff --git a/runtime/common/src/impl_on_charge_evm_transaction.rs b/runtime/common/src/impl_on_charge_evm_transaction.rs index 0fe3b9c026..1cb816c73c 100644 --- a/runtime/common/src/impl_on_charge_evm_transaction.rs +++ b/runtime/common/src/impl_on_charge_evm_transaction.rs @@ -22,13 +22,17 @@ macro_rules! impl_on_charge_evm_transaction { type BalanceFor = <::Currency as Inspect>>::Balance; - pub struct OnChargeEVMTransaction(sp_std::marker::PhantomData); + pub struct OnChargeEVMTransaction( + sp_std::marker::PhantomData<(BaseFeesOU, PriorityFeesOU)> + ); - impl OnChargeEVMTransactionT for OnChargeEVMTransaction + impl OnChargeEVMTransactionT + for OnChargeEVMTransaction where T: pallet_evm::Config, T::Currency: Balanced>, - OU: OnUnbalanced, T::Currency>>, + BaseFeesOU: OnUnbalanced, T::Currency>>, + PriorityFeesOU: OnUnbalanced, T::Currency>>, U256: UniqueSaturatedInto<>>::Balance>, T::AddressMapping: pallet_evm::AddressMapping, { @@ -48,14 +52,14 @@ macro_rules! impl_on_charge_evm_transaction { base_fee: U256, already_withdrawn: Self::LiquidityInfo, ) -> Self::LiquidityInfo { - ::Currency, OU> as OnChargeEVMTransactionT< + ::Currency, BaseFeesOU> as OnChargeEVMTransactionT< T, >>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn) } fn pay_priority_fee(tip: Self::LiquidityInfo) { if let Some(tip) = tip { - OU::on_unbalanced(tip); + PriorityFeesOU::on_unbalanced(tip); } } } diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 073da4d764..cf87b19903 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -60,7 +60,7 @@ use frame_support::{ construct_runtime, dispatch::{DispatchClass, GetDispatchInfo, PostDispatchInfo}, ensure, - pallet_prelude::DispatchResult, + pallet_prelude::{DispatchResult, PhantomData}, parameter_types, traits::{ fungible::{Balanced, Credit, HoldConsideration, Inspect}, @@ -125,6 +125,7 @@ use xcm_runtime_apis::{ use smallvec::smallvec; use sp_runtime::serde::{Deserialize, Serialize}; +use sp_runtime::traits::TypedGet; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -338,40 +339,32 @@ impl pallet_balances::Config for Runtime { type WeightInfo = moonbase_weights::pallet_balances::WeightInfo; } -pub struct DealWithFees(sp_std::marker::PhantomData); -impl OnUnbalanced>> for DealWithFees +/// Deal with substrate based fees and tip. This should be used with pallet_transaction_payment. +pub struct DealWithSubstrateFeesAndTip(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithSubstrateFeesAndTip where R: pallet_balances::Config + pallet_treasury::Config, { - // this seems to be called for substrate-based transactions - fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, - ) { - if let Some(fees) = fees_then_tips.next() { - let treasury_proportion = - runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_proportion.deconstruct(); - let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); - // Balances pallet automatically burns dropped Credits by decreasing - // total_supply accordingly - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - - // handle tip if there is one - if let Some(tip) = fees_then_tips.next() { - // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - } - } + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } +} - // this is called from pallet_evm for Ethereum-based transactions - // (technically, it calls on_unbalanced, which calls this when non-zero) +/// Deal with ethereum based fees. To handle tips/priority fees, use DealWithEthereumPriorityFees. +pub struct DealWithEthereumBaseFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumBaseFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly @@ -384,6 +377,31 @@ where } } +pub struct BlockAuthorAccountId(PhantomData); +impl TypedGet for BlockAuthorAccountId +where + R: frame_system::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + type Type = R::AccountId; + fn get() -> Self::Type { + as Get>::get() + } +} + +/// Deal with ethereum based priority fees/tips. See DealWithEthereumBaseFees for base fees. +pub struct DealWithEthereumPriorityFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumPriorityFees +where + R: pallet_balances::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + fn on_nonzero_unbalanced(amount: Credit>) { + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(amount); + } +} + pub struct LengthToFee; impl WeightToFeePolynomial for LengthToFee { type Balance = Balance; @@ -408,7 +426,7 @@ impl WeightToFeePolynomial for LengthToFee { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = FungibleAdapter>; + type OnChargeTransaction = FungibleAdapter>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = ConstantMultiplier>; type LengthToFee = LengthToFee; @@ -542,7 +560,10 @@ impl pallet_evm::Config for Runtime { type PrecompilesType = MoonbasePrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = EthereumChainId; - type OnChargeTransaction = OnChargeEVMTransaction>; + type OnChargeTransaction = OnChargeEVMTransaction< + DealWithEthereumBaseFees, + DealWithEthereumPriorityFees, + >; type BlockGasLimit = BlockGasLimit; type FindAuthor = FindAuthorAdapter; type OnCreate = (); diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index b5816bede2..b331efc5b1 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -37,6 +37,7 @@ use fp_rpc::TransactionStatus; use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin}; #[cfg(feature = "std")] pub use fp_evm::GenesisAccount; +use frame_support::pallet_prelude::{TypedGet, PhantomData}; pub use frame_support::traits::Get; use frame_support::{ construct_runtime, @@ -332,40 +333,32 @@ impl pallet_balances::Config for Runtime { type WeightInfo = moonbeam_weights::pallet_balances::WeightInfo; } -pub struct DealWithFees(sp_std::marker::PhantomData); -impl OnUnbalanced>> for DealWithFees +/// Deal with substrate based fees and tip. This should be used with pallet_transaction_payment. +pub struct DealWithSubstrateFeesAndTip(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithSubstrateFeesAndTip where R: pallet_balances::Config + pallet_treasury::Config, { - // this seems to be called for substrate-based transactions - fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, - ) { - if let Some(fees) = fees_then_tips.next() { - let treasury_proportion = - runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_proportion.deconstruct(); - let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); - // Balances pallet automatically burns dropped Credits by decreasing - // total_supply accordingly - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - - // handle tip if there is one - if let Some(tip) = fees_then_tips.next() { - // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - } - } + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } +} - // this is called from pallet_evm for Ethereum-based transactions - // (technically, it calls on_unbalanced, which calls this when non-zero) +/// Deal with ethereum based fees. To handle tips/priority fees, use DealWithEthereumPriorityFees. +pub struct DealWithEthereumBaseFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumBaseFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly @@ -378,6 +371,31 @@ where } } +pub struct BlockAuthorAccountId(PhantomData); +impl TypedGet for BlockAuthorAccountId +where + R: frame_system::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + type Type = R::AccountId; + fn get() -> Self::Type { + as Get>::get() + } +} + +/// Deal with ethereum based priority fees/tips. See DealWithEthereumBaseFees for base fees. +pub struct DealWithEthereumPriorityFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumPriorityFees +where + R: pallet_balances::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + fn on_nonzero_unbalanced(amount: Credit>) { + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(amount); + } +} + pub struct LengthToFee; impl WeightToFeePolynomial for LengthToFee { type Balance = Balance; @@ -402,7 +420,7 @@ impl WeightToFeePolynomial for LengthToFee { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = FungibleAdapter>; + type OnChargeTransaction = FungibleAdapter>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = ConstantMultiplier>; type LengthToFee = LengthToFee; @@ -533,7 +551,10 @@ impl pallet_evm::Config for Runtime { type PrecompilesType = MoonbeamPrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = EthereumChainId; - type OnChargeTransaction = OnChargeEVMTransaction>; + type OnChargeTransaction = OnChargeEVMTransaction< + DealWithEthereumBaseFees, + DealWithEthereumPriorityFees, + >; type BlockGasLimit = BlockGasLimit; type FindAuthor = FindAuthorAdapter; type OnCreate = (); diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 47e564ea5a..19291d64af 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -38,6 +38,7 @@ use fp_rpc::TransactionStatus; use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin}; #[cfg(feature = "std")] pub use fp_evm::GenesisAccount; +use frame_support::pallet_prelude::{PhantomData, TypedGet}; pub use frame_support::traits::Get; use frame_support::{ construct_runtime, @@ -334,40 +335,32 @@ impl pallet_balances::Config for Runtime { type WeightInfo = moonriver_weights::pallet_balances::WeightInfo; } -pub struct DealWithFees(sp_std::marker::PhantomData); -impl OnUnbalanced>> for DealWithFees +/// Deal with substrate based fees and tip. This should be used with pallet_transaction_payment. +pub struct DealWithSubstrateFeesAndTip(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithSubstrateFeesAndTip where R: pallet_balances::Config + pallet_treasury::Config, { - // this seems to be called for substrate-based transactions - fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, - ) { - if let Some(fees) = fees_then_tips.next() { - let treasury_proportion = - runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_proportion.deconstruct(); - let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); - // Balances pallet automatically burns dropped Credits by decreasing - // total_supply accordingly - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - - // handle tip if there is one - if let Some(tip) = fees_then_tips.next() { - // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); - ResolveTo::, pallet_balances::Pallet>::on_unbalanced( - to_treasury, - ); - } - } + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } +} - // this is called from pallet_evm for Ethereum-based transactions - // (technically, it calls on_unbalanced, which calls this when non-zero) +/// Deal with ethereum based fees. To handle tips/priority fees, use DealWithEthereumPriorityFees. +pub struct DealWithEthereumBaseFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumBaseFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly @@ -380,6 +373,31 @@ where } } +pub struct BlockAuthorAccountId(PhantomData); +impl TypedGet for BlockAuthorAccountId +where + R: frame_system::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + type Type = R::AccountId; + fn get() -> Self::Type { + as Get>::get() + } +} + +/// Deal with ethereum based priority fees/tips. See DealWithEthereumBaseFees for base fees. +pub struct DealWithEthereumPriorityFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> + for DealWithEthereumPriorityFees +where + R: pallet_balances::Config + pallet_author_inherent::Config, + pallet_author_inherent::Pallet: Get, +{ + fn on_nonzero_unbalanced(amount: Credit>) { + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(amount); + } +} + pub struct LengthToFee; impl WeightToFeePolynomial for LengthToFee { type Balance = Balance; @@ -404,7 +422,7 @@ impl WeightToFeePolynomial for LengthToFee { impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = FungibleAdapter>; + type OnChargeTransaction = FungibleAdapter>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = ConstantMultiplier>; type LengthToFee = LengthToFee; @@ -535,7 +553,10 @@ impl pallet_evm::Config for Runtime { type PrecompilesType = MoonriverPrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = EthereumChainId; - type OnChargeTransaction = OnChargeEVMTransaction>; + type OnChargeTransaction = OnChargeEVMTransaction< + DealWithEthereumBaseFees, + DealWithEthereumPriorityFees, + >; type BlockGasLimit = BlockGasLimit; type FindAuthor = FindAuthorAdapter; type OnCreate = ();