diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs index 1a4054839d..c5e175a8ea 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs @@ -98,6 +98,8 @@ pub fn genesis() -> Storage { ) }) .collect(), + // TODO: Any keys to add here? + non_authority_keys: vec![], }, polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs index 4d60c808d8..0093c10f33 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs @@ -72,6 +72,8 @@ fn asset_hub_polkadot_genesis( ) }) .collect(), + // TODO: Any keys to add here? + non_authority_keys: vec![], }, "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION), diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/impls.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/impls.rs index 68a3bfb318..151ae0c0dd 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/impls.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/impls.rs @@ -23,13 +23,10 @@ pub mod tx_payment { ensure, pallet_prelude::{InvalidTransaction, TransactionValidityError}, traits::{ - fungibles::{Balanced as FungiblesBalanced, Inspect as FungiblesInspect}, tokens::{Fortitude, Precision, Preservation}, Defensive, OnUnbalanced, SameOrOther, }, }; - use pallet_asset_conversion::{Pallet as AssetConversion, SwapCredit}; - use pallet_asset_conversion_tx_payment::OnChargeAssetTransaction; use pallet_transaction_payment::OnChargeTransaction; use sp_core::Get; use sp_runtime::{ @@ -124,180 +121,4 @@ pub mod tx_payment { Ok(()) } } - - type LiquidityInfoOf = - <::OnChargeTransaction as OnChargeTransaction< - T, - >>::LiquidityInfo; - - /// Implements [`OnChargeAssetTransaction`] for [`pallet_asset_conversion_tx_payment`], where - /// the asset class used to pay the fee is defined with the `A` type parameter (eg. DOT - /// location) and accessed via the type implementing the [`frame_support::traits::fungibles`] - /// trait. - pub struct SwapCreditAdapter(PhantomData<(A, S)>); - impl OnChargeAssetTransaction for SwapCreditAdapter - where - A: Get, - S: SwapCredit< - T::AccountId, - Balance = T::Balance, - AssetKind = T::AssetKind, - Credit = fungibles::Credit, - >, - - T: pallet_asset_conversion_tx_payment::Config, - T::Fungibles: - fungibles::Inspect, - T::OnChargeTransaction: - OnChargeTransaction>, - { - type AssetId = T::AssetKind; - type Balance = T::Balance; - type LiquidityInfo = T::Balance; - - fn withdraw_fee( - who: &::AccountId, - _call: &::RuntimeCall, - _dispatch_info: &DispatchInfoOf<::RuntimeCall>, - asset_id: Self::AssetId, - fee: Self::Balance, - _tip: Self::Balance, - ) -> Result<(LiquidityInfoOf, Self::LiquidityInfo, T::Balance), TransactionValidityError> - { - let asset_fee = AssetConversion::::quote_price_tokens_for_exact_tokens( - asset_id.clone(), - A::get(), - fee, - true, - ) - .ok_or(InvalidTransaction::Payment)?; - - let asset_fee_credit = T::Assets::withdraw( - asset_id.clone(), - who, - asset_fee, - Precision::Exact, - Preservation::Preserve, - Fortitude::Polite, - ) - .map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?; - - let (fee_credit, change) = match S::swap_tokens_for_exact_tokens( - vec![asset_id, A::get()], - asset_fee_credit, - fee, - ) { - Ok((fee_credit, change)) => (fee_credit, change), - Err((credit_in, _)) => { - // The swap should not error since the price quote was successful. - let _ = T::Assets::resolve(who, credit_in).defensive(); - return Err(InvalidTransaction::Payment.into()) - }, - }; - - // Should be always zero since the exact price was quoted before. - ensure!(change.peek().is_zero(), InvalidTransaction::Payment); - - Ok((Some(fee_credit), fee, asset_fee)) - } - fn correct_and_deposit_fee( - who: &::AccountId, - dispatch_info: &DispatchInfoOf<::RuntimeCall>, - post_info: &PostDispatchInfoOf<::RuntimeCall>, - corrected_fee: Self::Balance, - tip: Self::Balance, - fee_paid: LiquidityInfoOf, - _received_exchanged: Self::LiquidityInfo, - asset_id: Self::AssetId, - initial_asset_consumed: T::Balance, - ) -> Result { - let Some(fee_paid) = fee_paid else { - return Ok(Zero::zero()); - }; - // Try to refund if the fee paid is more than the corrected fee and the account was not - // removed by the dispatched function. - let (fee, fee_in_asset) = if fee_paid.peek() > corrected_fee && - !T::Assets::total_balance(asset_id.clone(), who).is_zero() - { - let refund_amount = fee_paid.peek().saturating_sub(corrected_fee); - // Check if the refund amount can be swapped back into the asset used by `who` for - // fee payment. - let refund_asset_amount = - AssetConversion::::quote_price_exact_tokens_for_tokens( - A::get(), - asset_id.clone(), - refund_amount, - true, - ) - // No refund given if it cannot be swapped back. - .unwrap_or(Zero::zero()); - - // Deposit the refund before the swap to ensure it can be processed. - let debt = match T::Assets::deposit( - asset_id.clone(), - who, - refund_asset_amount, - Precision::BestEffort, - ) { - Ok(debt) => debt, - // No refund given since it cannot be deposited. - Err(_) => fungibles::Debt::::zero(asset_id.clone()), - }; - - if debt.peek().is_zero() { - // No refund given. - (fee_paid, initial_asset_consumed) - } else { - let (refund, fee_paid) = fee_paid.split(refund_amount); - match S::swap_exact_tokens_for_tokens( - vec![A::get(), asset_id], - refund, - Some(refund_asset_amount), - ) { - Ok(refund_asset) => { - match refund_asset.offset(debt) { - Ok(SameOrOther::None) => {}, - // This arm should never be reached, as the amount of `debt` is - // expected to be exactly equal to the amount of `refund_asset` - // credit. - _ => return Err(InvalidTransaction::Payment.into()), - }; - (fee_paid, initial_asset_consumed.saturating_sub(refund_asset_amount)) - }, - // The error should not occur since swap was quoted before. - Err((refund, _)) => { - match T::Assets::settle(who, debt, Preservation::Expendable) { - Ok(dust) => - ensure!(dust.peek().is_zero(), InvalidTransaction::Payment), - // The error should not occur as the `debt` was just withdrawn - // above. - Err(_) => return Err(InvalidTransaction::Payment.into()), - }; - let fee_paid = fee_paid.merge(refund).map_err(|_| { - // The error should never occur since `fee_paid` and `refund` are - // credits of the same asset. - TransactionValidityError::from(InvalidTransaction::Payment) - })?; - (fee_paid, initial_asset_consumed) - }, - } - } - } else { - (fee_paid, initial_asset_consumed) - }; - - // Refund is already processed. - let corrected_fee = fee.peek(); - // Deposit fee. - T::OnChargeTransaction::correct_and_deposit_fee( - who, - dispatch_info, - post_info, - corrected_fee, - tip, - Some(fee), - ) - .map(|_| fee_in_asset) - } - } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 2a8764ee48..e939d818e3 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -100,7 +100,7 @@ use frame_support::{ parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, NeverEnsureOrigin, + ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, NeverEnsureOrigin, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -764,9 +764,13 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = LocalAndForeignAssets; - type OnChargeAssetTransaction = - impls::tx_payment::SwapCreditAdapter; + type AssetId = xcm::v3::Location; + type OnChargeAssetTransaction = pallet_asset_conversion_tx_payment::SwapAssetAdapter< + DotLocationV3, + NativeAndAssets, + AssetConversion, + ResolveAssetTo, + >; } parameter_types! { @@ -842,6 +846,7 @@ impl pallet_nfts::Config for Runtime { /// consensus with dynamic fees and back-pressure. pub type ToKusamaXcmRouterInstance = pallet_xcm_bridge_hub_router::Instance1; impl pallet_xcm_bridge_hub_router::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_xcm_bridge_hub_router::WeightInfo; type UniversalLocation = xcm_config::UniversalLocation; @@ -849,25 +854,14 @@ impl pallet_xcm_bridge_hub_router::Config for Runtime type Bridges = xcm_config::bridging::NetworkExportTable; type DestinationVersion = PolkadotXcm; - #[cfg(not(feature = "runtime-benchmarks"))] - type BridgeHubOrigin = EnsureXcm>; - #[cfg(feature = "runtime-benchmarks")] - type BridgeHubOrigin = frame_support::traits::EitherOfDiverse< - // for running benchmarks - EnsureRoot, - // for running tests with `--feature runtime-benchmarks` - EnsureXcm>, - >; + type SiblingBridgeHubLocation = xcm_config::bridging::SiblingBridgeHub; type ToBridgeHubSender = XcmpQueue; - type WithBridgeHubChannel = - cumulus_pallet_xcmp_queue::bridging::InAndOutXcmpChannelStatusProvider< - xcm_config::bridging::SiblingBridgeHubParaId, - Runtime, - >; type ByteFee = xcm_config::bridging::XcmBridgeHubRouterByteFee; type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId; + type LocalXcmChannelManager = + cumulus_pallet_xcmp_queue::bridging::InAndOutXcmpChannelStatusProvider; } pub type PoolAssetsInstance = pallet_assets::Instance3; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_foreign.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_foreign.rs index 89dec61252..61ce70ecdb 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_foreign.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_foreign.rs @@ -539,4 +539,11 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + Weight::from_parts(0, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_local.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_local.rs index fb7936a26d..4711b0f436 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_local.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_local.rs @@ -537,4 +537,11 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + Weight::from_parts(0, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_pool.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_pool.rs index 9865f43ce4..9c7859b6da 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_pool.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_assets_pool.rs @@ -529,4 +529,11 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + Weight::from_parts(0, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_xcm_bridge_hub_router.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_xcm_bridge_hub_router.rs index 0c6ec990df..3f458272a9 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_xcm_bridge_hub_router.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_xcm_bridge_hub_router.rs @@ -76,50 +76,4 @@ impl pallet_xcm_bridge_hub_router::WeightInfo for Weigh .saturating_add(Weight::from_parts(0, 5487)) .saturating_add(T::DbWeight::get().reads(2)) } - /// Storage: `ToKusamaXcmRouter::Bridge` (r:1 w:1) - /// Proof: `ToKusamaXcmRouter::Bridge` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) - fn report_bridge_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `150` - // Estimated: `1502` - // Minimum execution time: 12_570_000 picoseconds. - Weight::from_parts(12_960_000, 0) - .saturating_add(Weight::from_parts(0, 1502)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) - /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: UNKNOWN KEY `0x3302afcb67e838a3f960251b417b9a4f` (r:1 w:0) - /// Proof: UNKNOWN KEY `0x3302afcb67e838a3f960251b417b9a4f` (r:1 w:0) - /// Storage: UNKNOWN KEY `0x0973fe64c85043ba1c965cbc38eb63c7` (r:1 w:0) - /// Proof: UNKNOWN KEY `0x0973fe64c85043ba1c965cbc38eb63c7` (r:1 w:0) - /// Storage: `ToKusamaXcmRouter::Bridge` (r:1 w:1) - /// Proof: `ToKusamaXcmRouter::Bridge` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) - /// Storage: `XcmpQueue::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `XcmpQueue::DeliveryFeeFactor` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `PolkadotXcm::SupportedVersion` (r:2 w:0) - /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) - /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) - /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `ParachainSystem::RelevantMessagingState` (r:1 w:0) - /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) - /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) - /// Storage: `XcmpQueue::InboundXcmpSuspended` (r:1 w:0) - /// Proof: `XcmpQueue::InboundXcmpSuspended` (`max_values`: Some(1), `max_size`: Some(4002), added: 4497, mode: `MaxEncodedLen`) - /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) - /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: Some(105506), added: 107981, mode: `MaxEncodedLen`) - fn send_message() -> Weight { - // Proof Size summary in bytes: - // Measured: `486` - // Estimated: `6426` - // Minimum execution time: 59_481_000 picoseconds. - Weight::from_parts(60_690_000, 0) - .saturating_add(Weight::from_parts(0, 6426)) - .saturating_add(T::DbWeight::get().reads(12)) - .saturating_add(T::DbWeight::get().writes(4)) - } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 2873ac3d12..1ded2df676 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -50,11 +50,11 @@ use xcm_builder::{ DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith, - StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, - XcmFeeToAccount, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignPaidRemoteExporter, + SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; @@ -449,7 +449,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + SendXcmFeeToAccount, >; type MessageExporter = (); type UniversalAliases =