From f32d9dd395a5839fa20977585e0f27c618e7eff0 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 9 Apr 2024 10:29:33 +0200 Subject: [PATCH 01/11] Remove `xcm::v3` from `assets-common` (AssetIdForTrustBackedAssetsConvert) --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-rococo/tests/tests.rs | 8 +++--- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../assets/asset-hub-westend/tests/tests.rs | 8 +++--- .../runtimes/assets/common/src/lib.rs | 27 ++++++++++--------- 5 files changed, 26 insertions(+), 21 deletions(-) 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 9e21d1133237..e815d3a3c467 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -316,7 +316,7 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, xcm::v3::Location, >, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 5fa7455ad2a0..a261ef0abe8e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -59,11 +59,13 @@ use xcm_executor::traits::{JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; -type AssetIdForTrustBackedAssetsConvert = - assets_common::AssetIdForTrustBackedAssetsConvert; +type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert< + TrustBackedAssetsPalletLocationV3, + xcm::v3::Location, +>; type AssetIdForTrustBackedAssetsConvertLatest = - assets_common::AssetIdForTrustBackedAssetsConvertLatest; + assets_common::AssetIdForTrustBackedAssetsConvert; type RuntimeHelper = asset_test_utils::RuntimeHelper; 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 f3499a8d2921..eb4c18a411dc 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -298,7 +298,7 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, xcm::v3::Location, >, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 6696cb232239..d2391a707c0b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -59,11 +59,13 @@ use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; -type AssetIdForTrustBackedAssetsConvert = - assets_common::AssetIdForTrustBackedAssetsConvert; +type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert< + TrustBackedAssetsPalletLocationV3, + xcm::v3::Location, +>; type AssetIdForTrustBackedAssetsConvertLatest = - assets_common::AssetIdForTrustBackedAssetsConvertLatest; + assets_common::AssetIdForTrustBackedAssetsConvert; type RuntimeHelper = asset_test_utils::RuntimeHelper; diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index fa2752179eb6..f64a01bb2b5d 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -26,36 +26,37 @@ pub mod runtime_api; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; +use xcm::latest::Location; use xcm_builder::{ AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, }; use xcm_executor::traits::JustTry; /// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets` -pub type AssetIdForTrustBackedAssetsConvert = +pub type AssetIdForTrustBackedAssetsConvert = AsPrefixedGeneralIndex< TrustBackedAssetsPalletLocation, AssetIdForTrustBackedAssets, JustTry, - xcm::v3::Location, + L, >; -pub type AssetIdForTrustBackedAssetsConvertLatest = - AsPrefixedGeneralIndex; - /// `Location` vs `CollectionId` converter for `Uniques` pub type CollectionIdForUniquesConvert = AsPrefixedGeneralIndex; /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets` -pub type TrustBackedAssetsConvertedConcreteId = - MatchedConvertedConcreteId< - AssetIdForTrustBackedAssets, - Balance, - StartsWith, - AssetIdForTrustBackedAssetsConvertLatest, - JustTry, - >; +pub type TrustBackedAssetsConvertedConcreteId< + TrustBackedAssetsPalletLocation, + Balance, + L = Location, +> = MatchedConvertedConcreteId< + AssetIdForTrustBackedAssets, + Balance, + StartsWith, + AssetIdForTrustBackedAssetsConvert, + JustTry, +>; /// [`MatchedConvertedConcreteId`] converter dedicated for `Uniques` pub type UniquesConvertedConcreteId = MatchedConvertedConcreteId< From 9ce86913ff9c59887e0ac4ecb2cb954bdc28a678 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 9 Apr 2024 10:48:14 +0200 Subject: [PATCH 02/11] Compile test --- cumulus/parachains/runtimes/assets/common/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index f64a01bb2b5d..e8a9c402dd2f 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -144,14 +144,14 @@ mod tests { Location::new(5, [PalletInstance(13), GeneralIndex(local_asset_id.into())]); assert_eq!( - AssetIdForTrustBackedAssetsConvertLatest::::convert_back( + AssetIdForTrustBackedAssetsConvert::::convert_back( &local_asset_id ) .unwrap(), expected_reverse_ref ); assert_eq!( - AssetIdForTrustBackedAssetsConvertLatest::::convert( + AssetIdForTrustBackedAssetsConvert::::convert( &expected_reverse_ref ) .unwrap(), From cb90bcf5cd2d8e5f01d42446017ce1a8f8d02641 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 9 Apr 2024 15:33:04 +0200 Subject: [PATCH 03/11] Replace `V4V3LocationConverter` with `WithLatestLocationConverter` --- .../xcm/xcm-builder/src/asset_conversion.rs | 11 ----------- polkadot/xcm/xcm-builder/src/lib.rs | 6 ++++-- .../xcm/xcm-builder/src/matches_location.rs | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/asset_conversion.rs b/polkadot/xcm/xcm-builder/src/asset_conversion.rs index e38af149be54..520ce87448ea 100644 --- a/polkadot/xcm/xcm-builder/src/asset_conversion.rs +++ b/polkadot/xcm/xcm-builder/src/asset_conversion.rs @@ -107,17 +107,6 @@ impl< #[deprecated = "Use `ConvertedConcreteId` instead"] pub type ConvertedConcreteAssetId = ConvertedConcreteId; -pub struct V4V3LocationConverter; -impl MaybeEquivalence for V4V3LocationConverter { - fn convert(old: &xcm::v4::Location) -> Option { - (*old).clone().try_into().ok() - } - - fn convert_back(new: &xcm::v3::Location) -> Option { - (*new).try_into().ok() - } -} - pub struct MatchedConvertedConcreteId( PhantomData<(AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertOther)>, ); diff --git a/polkadot/xcm/xcm-builder/src/lib.rs b/polkadot/xcm/xcm-builder/src/lib.rs index 46d0ad227bfd..c3400cc72b48 100644 --- a/polkadot/xcm/xcm-builder/src/lib.rs +++ b/polkadot/xcm/xcm-builder/src/lib.rs @@ -30,7 +30,7 @@ mod asset_conversion; #[allow(deprecated)] pub use asset_conversion::ConvertedConcreteAssetId; pub use asset_conversion::{ - AsPrefixedGeneralIndex, ConvertedConcreteId, MatchedConvertedConcreteId, V4V3LocationConverter, + AsPrefixedGeneralIndex, ConvertedConcreteId, MatchedConvertedConcreteId, }; mod barriers; @@ -81,7 +81,9 @@ pub use location_conversion::{ }; mod matches_location; -pub use matches_location::{StartsWith, StartsWithExplicitGlobalConsensus}; +pub use matches_location::{ + StartsWith, StartsWithExplicitGlobalConsensus, WithLatestLocationConverter, +}; mod matches_token; pub use matches_token::IsConcrete; diff --git a/polkadot/xcm/xcm-builder/src/matches_location.rs b/polkadot/xcm/xcm-builder/src/matches_location.rs index 1664c2477290..b6c2807e6b29 100644 --- a/polkadot/xcm/xcm-builder/src/matches_location.rs +++ b/polkadot/xcm/xcm-builder/src/matches_location.rs @@ -18,6 +18,8 @@ //! `InteriorLocation` types. use frame_support::traits::{Contains, Get}; +use sp_runtime::traits::MaybeEquivalence; +use sp_std::marker::PhantomData; use xcm::latest::{InteriorLocation, Location, NetworkId}; /// An implementation of `Contains` that checks for `Location` or @@ -51,3 +53,18 @@ impl> Contains for StartsWithExplicitGlobalC matches!(location.global_consensus(), Ok(requested_network) if requested_network.eq(&T::get())) } } + +/// An adapter implementation of `MaybeEquivalence` which can convert between the latest `Location` +/// and other versions that implement `TryInto` and `TryFrom`. +pub struct WithLatestLocationConverter(PhantomData); +impl + TryFrom + Clone> MaybeEquivalence + for WithLatestLocationConverter +{ + fn convert(old: &Location) -> Option { + (*old).clone().try_into().ok() + } + + fn convert_back(new: &Target) -> Option { + new.clone().try_into().ok() + } +} From cdc42cff7c9304c83f99148aa6e9e9e72e30173a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 10:19:22 +0200 Subject: [PATCH 04/11] Remove `xcm::v3::Location` from `ForeignAssetsConvertedConcreteId` --- .../assets/asset-hub-rococo/src/xcm_config.rs | 6 +- .../assets/asset-hub-rococo/tests/tests.rs | 9 ++- .../asset-hub-westend/src/xcm_config.rs | 6 +- .../assets/asset-hub-westend/tests/tests.rs | 9 ++- .../runtimes/assets/common/src/lib.rs | 81 +++++++++++-------- 5 files changed, 66 insertions(+), 45 deletions(-) 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 f71b5e9c5e88..e3fadaaf269d 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 @@ -58,8 +58,8 @@ use xcm_builder::{ SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, - XcmFeeToAccount, + WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, + XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -179,6 +179,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, + xcm::v3::Location, + WithLatestLocationConverter, >; /// Means for transacting foreign assets from different global consensus. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index a261ef0abe8e..df7ba04c8d4c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -53,7 +53,7 @@ use sp_std::ops::Mul; use std::convert::Into; use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee}; use xcm::latest::prelude::{Assets as XcmAssets, *}; -use xcm_builder::V4V3LocationConverter; +use xcm_builder::WithLatestLocationConverter; use xcm_executor::traits::{JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; @@ -933,7 +933,10 @@ fn test_assets_balances_api_works() { .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(), + WithLatestLocationConverter::::convert_back( + &foreign_asset_id_location + ) + .unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); @@ -1046,7 +1049,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, xcm::v3::Location, - V4V3LocationConverter, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), 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 360b1a7055b7..adcbf0894eca 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 @@ -54,8 +54,8 @@ use xcm_builder::{ RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, - XcmFeeToAccount, + WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, + XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -172,6 +172,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, + xcm::v3::Location, + WithLatestLocationConverter, >; /// Means for transacting foreign assets from different global consensus. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index d2391a707c0b..8b0467963408 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -53,7 +53,7 @@ use sp_runtime::traits::MaybeEquivalence; use std::{convert::Into, ops::Mul}; use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee}; use xcm::latest::prelude::{Assets as XcmAssets, *}; -use xcm_builder::V4V3LocationConverter; +use xcm_builder::WithLatestLocationConverter; use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; @@ -931,7 +931,10 @@ fn test_assets_balances_api_works() { .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(), + WithLatestLocationConverter::::convert_back( + &foreign_asset_id_location + ) + .unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); @@ -1045,7 +1048,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, xcm::v3::Location, - V4V3LocationConverter, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index e8a9c402dd2f..31151ae871f1 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -26,24 +26,22 @@ pub mod runtime_api; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; +use sp_runtime::traits::TryConvertInto; use xcm::latest::Location; -use xcm_builder::{ - AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, -}; -use xcm_executor::traits::JustTry; +use xcm_builder::{AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith}; /// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets` pub type AssetIdForTrustBackedAssetsConvert = AsPrefixedGeneralIndex< TrustBackedAssetsPalletLocation, AssetIdForTrustBackedAssets, - JustTry, + TryConvertInto, L, >; /// `Location` vs `CollectionId` converter for `Uniques` pub type CollectionIdForUniquesConvert = - AsPrefixedGeneralIndex; + AsPrefixedGeneralIndex; /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets` pub type TrustBackedAssetsConvertedConcreteId< @@ -55,7 +53,7 @@ pub type TrustBackedAssetsConvertedConcreteId< Balance, StartsWith, AssetIdForTrustBackedAssetsConvert, - JustTry, + TryConvertInto, >; /// [`MatchedConvertedConcreteId`] converter dedicated for `Uniques` @@ -66,16 +64,21 @@ pub type UniquesConvertedConcreteId = MatchedConvertedCon // junction within the pallet itself. StartsWith, CollectionIdForUniquesConvert, - JustTry, + TryConvertInto, >; -/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `Location`. -pub type LocationConvertedConcreteId = MatchedConvertedConcreteId< - xcm::v3::Location, +/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `xcm::v*::Location`. +pub type LocationConvertedConcreteId< + AssetLocationFilter, Balance, - LocationFilter, - V4V3LocationConverter, - JustTry, + AssetId, + LocationToAssetIdConverter, +> = MatchedConvertedConcreteId< + AssetId, + Balance, + AssetLocationFilter, + LocationToAssetIdConverter, + TryConvertInto, >; /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets` @@ -85,7 +88,7 @@ pub type TrustBackedAssetsAsLocation = Balance, StartsWith, V4V3LocationConverter, - JustTry, + TryConvertInto, >; /// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as @@ -96,26 +99,32 @@ pub type TrustBackedAssetsAsLocation = /// - all local Locations /// /// `AdditionalLocationExclusionFilter` can customize additional excluded Locations -pub type ForeignAssetsConvertedConcreteId = - LocationConvertedConcreteId< - EverythingBut<( - // Excludes relay/parent chain currency - Equals, - // Here we rely on fact that something like this works: - // assert!(Location::new(1, - // [Parachain(100)]).starts_with(&Location::parent())); - // assert!([Parachain(100)].into().starts_with(&Here)); - StartsWith, - // Here we can exclude more stuff or leave it as `()` - AdditionalLocationExclusionFilter, - )>, - Balance, - >; +pub type ForeignAssetsConvertedConcreteId< + AdditionalLocationExclusionFilter, + Balance, + AssetId, + LocationToAssetIdConverter, +> = LocationConvertedConcreteId< + EverythingBut<( + // Excludes relay/parent chain currency + Equals, + // Here we rely on fact that something like this works: + // assert!(Location::new(1, + // [Parachain(100)]).starts_with(&Location::parent())); + // assert!([Parachain(100)].into().starts_with(&Here)); + StartsWith, + // Here we can exclude more stuff or leave it as `()` + AdditionalLocationExclusionFilter, + )>, + Balance, + AssetId, + LocationToAssetIdConverter, +>; type AssetIdForPoolAssets = u32; /// `Location` vs `AssetIdForPoolAssets` converter for `PoolAssets`. pub type AssetIdForPoolAssetsConvert = - AsPrefixedGeneralIndex; + AsPrefixedGeneralIndex; /// [`MatchedConvertedConcreteId`] converter dedicated for `PoolAssets` pub type PoolAssetsConvertedConcreteId = MatchedConvertedConcreteId< @@ -123,7 +132,7 @@ pub type PoolAssetsConvertedConcreteId = Balance, StartsWith, AssetIdForPoolAssetsConvert, - JustTry, + TryConvertInto, >; #[cfg(test)] @@ -131,7 +140,7 @@ mod tests { use super::*; use sp_runtime::traits::MaybeEquivalence; use xcm::prelude::*; - use xcm_builder::StartsWithExplicitGlobalConsensus; + use xcm_builder::{StartsWithExplicitGlobalConsensus, WithLatestLocationConverter}; use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; #[test] @@ -164,7 +173,7 @@ mod tests { frame_support::parameter_types! { pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]); } - // setup convert + // setup a converter type TrustBackedAssetsConvert = TrustBackedAssetsConvertedConcreteId; @@ -253,13 +262,15 @@ mod tests { pub UniversalLocationNetworkId: NetworkId = NetworkId::ByGenesis([9; 32]); } - // setup convert + // setup a converter which uses `xcm::v3::Location` under the hood type Convert = ForeignAssetsConvertedConcreteId< ( StartsWith, StartsWithExplicitGlobalConsensus, ), u128, + xcm::v3::Location, + WithLatestLocationConverter, >; let test_data = vec![ From 2a9cf4c795ca5c48a7924469cd9006a0d791cabb Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 11:04:14 +0200 Subject: [PATCH 05/11] Remove `xcm::v3::Location` from `assets-common` --- .../assets/asset-hub-rococo/src/xcm_config.rs | 6 +++- .../asset-hub-westend/src/xcm_config.rs | 6 +++- .../runtimes/assets/common/src/lib.rs | 35 ++++++++++++------- 3 files changed, 32 insertions(+), 15 deletions(-) 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 e3fadaaf269d..68e715aa2833 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 @@ -583,7 +583,11 @@ impl xcm_executor::Config for XcmConfig { WeightToFee, crate::NativeAndAssets, ( - TrustBackedAssetsAsLocation, + TrustBackedAssetsAsLocation< + TrustBackedAssetsPalletLocation, + Balance, + xcm::v3::Location, + >, ForeignAssetsConvertedConcreteId, ), ResolveAssetTo, 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 adcbf0894eca..f93ee2cd76d1 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 @@ -605,7 +605,11 @@ impl xcm_executor::Config for XcmConfig { WeightToFee, crate::NativeAndAssets, ( - TrustBackedAssetsAsLocation, + TrustBackedAssetsAsLocation< + TrustBackedAssetsPalletLocation, + Balance, + xcm::v3::Location, + >, ForeignAssetsConvertedConcreteId, ), ResolveAssetTo, diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index 31151ae871f1..2687928a8c8e 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -28,7 +28,9 @@ use frame_support::traits::{Equals, EverythingBut}; use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; use sp_runtime::traits::TryConvertInto; use xcm::latest::Location; -use xcm_builder::{AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith}; +use xcm_builder::{ + AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, WithLatestLocationConverter, +}; /// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets` pub type AssetIdForTrustBackedAssetsConvert = @@ -81,15 +83,22 @@ pub type LocationConvertedConcreteId< TryConvertInto, >; -/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets` -pub type TrustBackedAssetsAsLocation = - MatchedConvertedConcreteId< - xcm::v3::Location, - Balance, - StartsWith, - V4V3LocationConverter, - TryConvertInto, - >; +/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`, +/// it is a similar implementation to `TrustBackedAssetsConvertedConcreteId`, +/// but it converts `AssetId` to `xcm::v*::Location` type instead of `AssetIdForTrustBackedAssets = +/// u32` +pub type TrustBackedAssetsAsLocation< + TrustBackedAssetsPalletLocation, + Balance, + L, + LocationConverter = WithLatestLocationConverter, +> = MatchedConvertedConcreteId< + L, + Balance, + StartsWith, + LocationConverter, + TryConvertInto, +>; /// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as /// `Location`. @@ -173,7 +182,7 @@ mod tests { frame_support::parameter_types! { pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]); } - // setup a converter + // set up a converter type TrustBackedAssetsConvert = TrustBackedAssetsConvertedConcreteId; @@ -256,13 +265,13 @@ mod tests { } #[test] - fn location_converted_concrete_id_converter_works() { + fn foreign_assets_converted_concrete_id_converter_works() { frame_support::parameter_types! { pub Parachain100Pattern: Location = Location::new(1, [Parachain(100)]); pub UniversalLocationNetworkId: NetworkId = NetworkId::ByGenesis([9; 32]); } - // setup a converter which uses `xcm::v3::Location` under the hood + // set up a converter which uses `xcm::v3::Location` under the hood type Convert = ForeignAssetsConvertedConcreteId< ( StartsWith, From 8d98da193abe5069b7c6718b890e7bf92c2d75eb Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 11:31:26 +0200 Subject: [PATCH 06/11] Simplify - added default types, removed unused --- .../assets/asset-hub-rococo/src/xcm_config.rs | 5 ++-- .../asset-hub-westend/src/xcm_config.rs | 5 ++-- .../runtimes/assets/common/src/lib.rs | 24 +++++-------------- 3 files changed, 10 insertions(+), 24 deletions(-) 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 68e715aa2833..180257035bf3 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 @@ -58,8 +58,8 @@ use xcm_builder::{ SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, - XcmFeeManagerFromComponents, XcmFeeToAccount, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + XcmFeeToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -180,7 +180,6 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte ), Balance, xcm::v3::Location, - WithLatestLocationConverter, >; /// Means for transacting foreign assets from different global consensus. 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 f93ee2cd76d1..d940f5d995ee 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 @@ -54,8 +54,8 @@ use xcm_builder::{ RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, - XcmFeeManagerFromComponents, XcmFeeToAccount, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + XcmFeeToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -173,7 +173,6 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte ), Balance, xcm::v3::Location, - WithLatestLocationConverter, >; /// Means for transacting foreign assets from different global consensus. diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index 2687928a8c8e..431b5766147a 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -69,20 +69,6 @@ pub type UniquesConvertedConcreteId = MatchedConvertedCon TryConvertInto, >; -/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `xcm::v*::Location`. -pub type LocationConvertedConcreteId< - AssetLocationFilter, - Balance, - AssetId, - LocationToAssetIdConverter, -> = MatchedConvertedConcreteId< - AssetId, - Balance, - AssetLocationFilter, - LocationToAssetIdConverter, - TryConvertInto, ->; - /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`, /// it is a similar implementation to `TrustBackedAssetsConvertedConcreteId`, /// but it converts `AssetId` to `xcm::v*::Location` type instead of `AssetIdForTrustBackedAssets = @@ -112,8 +98,11 @@ pub type ForeignAssetsConvertedConcreteId< AdditionalLocationExclusionFilter, Balance, AssetId, - LocationToAssetIdConverter, -> = LocationConvertedConcreteId< + LocationToAssetIdConverter = WithLatestLocationConverter, + BalanceConverter = TryConvertInto, +> = MatchedConvertedConcreteId< + AssetId, + Balance, EverythingBut<( // Excludes relay/parent chain currency Equals, @@ -125,9 +114,8 @@ pub type ForeignAssetsConvertedConcreteId< // Here we can exclude more stuff or leave it as `()` AdditionalLocationExclusionFilter, )>, - Balance, - AssetId, LocationToAssetIdConverter, + BalanceConverter, >; type AssetIdForPoolAssets = u32; From b9e6ed582ee41b8b916f7628b97e34f24c77e2d4 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 11:55:04 +0200 Subject: [PATCH 07/11] Clean up penpal and foreign assets --- .../runtimes/testing/penpal/src/lib.rs | 12 ++++------- .../runtimes/testing/penpal/src/xcm_config.rs | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 919bfe83e7d7..89885d77378b 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -72,18 +72,14 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm_config::XcmOriginToTransactDispatchOrigin; +use xcm_config::{ForeignAssetsAssetId, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -// Polkadot imports +use parachains_common::{AccountId, Signature}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; - use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; - -// XCM Imports -use parachains_common::{AccountId, Signature}; use xcm::latest::prelude::{AssetId as AssetLocationId, BodyId}; /// Balance of an account. @@ -474,8 +470,8 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; - type AssetIdParameter = xcm::v3::Location; + type AssetId = ForeignAssetsAssetId; + type AssetIdParameter = ForeignAssetsAssetId; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = EnsureRoot; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 7b8e40e04288..6a860c01eacc 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -40,7 +40,7 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{xcm_config::AssetFeeAsExistentialDepositMultiplier, TREASURY_PALLET_ID}; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::{impls::ToAuthor, xcm_sender::ExponentialPrice}; -use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, @@ -77,7 +77,7 @@ pub type LocationToAccountId = ( ); /// Means for transacting assets on this chain. -pub type CurrencyTransactor = FungibleAdapter< +pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -124,7 +124,11 @@ pub type FungiblesTransactor = FungiblesAdapter< CheckingAccount, >; -pub type ForeignAssetsConvertedConcreteId = assets_common::LocationConvertedConcreteId< +// Using the latest `Location`, we don't need to worry about migrations for Penpal. +pub type ForeignAssetsAssetId = Location; +pub type ForeignAssetsConvertedConcreteId = xcm_builder::MatchedConvertedConcreteId< + Location, + Balance, EverythingBut<( // Here we rely on fact that something like this works: // assert!(Location::new(1, @@ -132,7 +136,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::LocationConvertedConc // assert!([Parachain(100)].into().starts_with(&Here)); StartsWith, )>, - Balance, + Identity, + TryConvertInto, >; /// Means for transacting foreign assets from different global consensus. @@ -152,7 +157,7 @@ pub type ForeignFungiblesTransactor = FungiblesAdapter< >; /// Means for transacting assets on this chain. -pub type AssetTransactors = (CurrencyTransactor, ForeignFungiblesTransactor, FungiblesTransactor); +pub type AssetTransactors = (FungibleTransactor, ForeignFungiblesTransactor, FungiblesTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can @@ -411,8 +416,8 @@ impl cumulus_pallet_xcm::Config for Runtime { /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { - xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(id)]) +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> ForeignAssetsAssetId { + Location::new(1, [Parachain(id)]) } } From b3259696b805898d00aea6db610239848598d038 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 11:55:24 +0200 Subject: [PATCH 08/11] More renaming --- .../runtimes/contracts/contracts-rococo/src/xcm_config.rs | 4 ++-- .../runtimes/coretime/coretime-rococo/src/xcm_config.rs | 4 ++-- .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index ac6fe634662f..2ae59a93b1bc 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -78,7 +78,7 @@ pub type LocationToAccountId = ( ); /// Means for transacting the native currency on this chain. -pub type CurrencyTransactor = FungibleAdapter< +pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -171,7 +171,7 @@ pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; - type AssetTransactor = CurrencyTransactor; + type AssetTransactor = FungibleTransactor; type OriginConverter = XcmOriginToTransactDispatchOrigin; type IsReserve = NativeAsset; type IsTeleporter = TrustedTeleporter; 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 afb68749f3b9..4e1c6919ec93 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs @@ -77,7 +77,7 @@ pub type LocationToAccountId = ( ); /// Means for transacting the native currency on this chain. -pub type CurrencyTransactor = FungibleAdapter< +pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -106,7 +106,7 @@ pub type RegionTransactor = NonFungibleAdapter< >; /// Means for transacting assets on this chain. -pub type AssetTransactors = (CurrencyTransactor, RegionTransactor); +pub type AssetTransactors = (FungibleTransactor, RegionTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with XCM's `Transact`. There is an `OriginKind` that can diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 5695c54f054c..941ba265679b 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -346,7 +346,7 @@ pub type LocationToAccountId = ( ); /// Means for transacting assets on this chain. -pub type CurrencyTransactor = FungibleAdapter< +pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -385,7 +385,7 @@ pub type FungiblesTransactor = FungiblesAdapter< CheckingAccount, >; /// Means for transacting assets on this chain. -pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); +pub type AssetTransactors = (FungibleTransactor, FungiblesTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can From de33fa6b2e482421ee80223e55a7066d24057ac7 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 13:16:30 +0200 Subject: [PATCH 09/11] Use `xcm::lastest::Location` for penpal and clean up xcm-emulated integration tests --- Cargo.lock | 2 + .../assets/asset-hub-rococo/Cargo.toml | 3 + .../assets/asset-hub-rococo/src/lib.rs | 4 +- .../assets/asset-hub-westend/Cargo.toml | 3 + .../assets/asset-hub-westend/src/lib.rs | 4 +- .../parachains/testing/penpal/src/genesis.rs | 17 +-- .../parachains/testing/penpal/src/lib.rs | 5 +- .../emulated/common/src/impls.rs | 110 ++++++++++-------- .../src/tests/reserve_transfer.rs | 101 +++++++--------- .../assets/asset-hub-rococo/src/tests/swap.rs | 21 ++-- .../asset-hub-rococo/src/tests/teleport.rs | 17 ++- .../src/tests/reserve_transfer.rs | 97 +++++++-------- .../asset-hub-westend/src/tests/swap.rs | 21 ++-- .../asset-hub-westend/src/tests/teleport.rs | 17 ++- .../bridge-hub-rococo/src/tests/snowbridge.rs | 6 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 2 - .../asset-hub-westend/src/xcm_config.rs | 2 - 17 files changed, 203 insertions(+), 229 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2145a870e75c..4e074e410d6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -821,6 +821,7 @@ dependencies = [ "parachains-common", "rococo-emulated-chain", "sp-core", + "staging-xcm", "testnet-parachains-constants", ] @@ -941,6 +942,7 @@ dependencies = [ "frame-support", "parachains-common", "sp-core", + "staging-xcm", "testnet-parachains-constants", "westend-emulated-chain", ] diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/Cargo.toml index 98762beb0cb2..8100e6813488 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/Cargo.toml @@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu asset-hub-rococo-runtime = { path = "../../../../../../runtimes/assets/asset-hub-rococo" } rococo-emulated-chain = { path = "../../../relays/rococo" } testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["rococo"] } + +# Polkadot +xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index f1e972e869dc..202d02b250bb 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize; use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, - impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, + impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, + xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; @@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo); impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo); impl_assets_helpers_for_parachain!(AssetHubRococo); +impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, xcm::v3::Location); impl_xcm_helpers_for_parachain!(AssetHubRococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/Cargo.toml index a42a9abf618d..e0abaa66c5ca 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/Cargo.toml @@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu asset-hub-westend-runtime = { path = "../../../../../../runtimes/assets/asset-hub-westend" } westend-emulated-chain = { path = "../../../relays/westend" } testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["westend"] } + +# Polkadot +xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 7f05eefb4c20..6043a6aeda48 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize; use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, - impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, + impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, + xcm_emulator::decl_test_parachains, }; use westend_emulated_chain::Westend; @@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend); impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend); impl_assets_helpers_for_parachain!(AssetHubWestend); +impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, xcm::v3::Location); impl_xcm_helpers_for_parachain!(AssetHubWestend); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index d81ab8143ddb..450439f5ea30 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -17,8 +17,6 @@ use frame_support::parameter_types; use sp_core::{sr25519, storage::Storage}; -// Polkadot -use xcm::v3::Location; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, @@ -79,20 +77,9 @@ pub fn genesis(para_id: u32) -> Storage { foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ // Relay Native asset representation - ( - Location::try_from(RelayLocation::get()).expect("conversion works"), - PenpalAssetOwner::get(), - true, - ED, - ), + (RelayLocation::get(), PenpalAssetOwner::get(), true, ED), // Sufficient AssetHub asset representation - ( - Location::try_from(LocalReservableFromAssetHub::get()) - .expect("conversion works"), - PenpalAssetOwner::get(), - true, - ED, - ), + (LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED), ], ..Default::default() }, diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index 0b49c7a3e091..e12e2eaa2c0b 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -25,7 +25,8 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain, + xcm_emulator::decl_test_parachains, }; // Penpal Parachain declaration @@ -76,4 +77,6 @@ impl_accounts_helpers_for_parachain!(PenpalB); impl_assert_events_helpers_for_parachain!(PenpalA); impl_assert_events_helpers_for_parachain!(PenpalB); impl_assets_helpers_for_parachain!(PenpalA); +impl_foreign_assets_helpers_for_parachain!(PenpalA, xcm::latest::Location); impl_assets_helpers_for_parachain!(PenpalB); +impl_foreign_assets_helpers_for_parachain!(PenpalB, xcm::latest::Location); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 618c3addc5d0..c8a2f097abe9 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -38,9 +38,7 @@ pub use polkadot_runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, }; pub use xcm::{ - prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmVersion}, - v3, - v4::Error as XcmError, + prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmError, XcmVersion}, DoubleEncoded, }; @@ -696,12 +694,12 @@ macro_rules! impl_assets_helpers_for_system_parachain { #[macro_export] macro_rules! impl_assets_helpers_for_parachain { - ( $chain:ident) => { + ($chain:ident) => { $crate::impls::paste::paste! { impl $chain { - /// Create foreign assets using sudo `ForeignAssets::force_create()` - pub fn force_create_foreign_asset( - id: $crate::impls::v3::Location, + /// Create assets using sudo `Assets::force_create()` + pub fn force_create_asset( + id: u32, owner: $crate::impls::AccountId, is_sufficient: bool, min_balance: u128, @@ -711,20 +709,20 @@ macro_rules! impl_assets_helpers_for_parachain { let sudo_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::root(); ::execute_with(|| { $crate::impls::assert_ok!( - ]>::ForeignAssets::force_create( + ]>::Assets::force_create( sudo_origin, - id.clone(), + id.clone().into(), owner.clone().into(), is_sufficient, min_balance, ) ); - assert!(]>::ForeignAssets::asset_exists(id.clone())); + assert!(]>::Assets::asset_exists(id.clone())); type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::ForeignAssets( + RuntimeEvent::::Assets( $crate::impls::pallet_assets::Event::ForceCreated { asset_id, .. @@ -736,19 +734,19 @@ macro_rules! impl_assets_helpers_for_parachain { for (beneficiary, amount) in prefund_accounts.into_iter() { let signed_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone()); - Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount); + Self::mint_asset(signed_origin, id.clone(), beneficiary, amount); } } - /// Mint assets making use of the ForeignAssets pallet-assets instance - pub fn mint_foreign_asset( + /// Mint assets making use of the assets pallet + pub fn mint_asset( signed_origin: ::RuntimeOrigin, - id: $crate::impls::v3::Location, + id: u32, beneficiary: $crate::impls::AccountId, amount_to_mint: u128, ) { ::execute_with(|| { - $crate::impls::assert_ok!(]>::ForeignAssets::mint( + $crate::impls::assert_ok!(]>::Assets::mint( signed_origin, id.clone().into(), beneficiary.clone().into(), @@ -760,7 +758,7 @@ macro_rules! impl_assets_helpers_for_parachain { $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::ForeignAssets( + RuntimeEvent::::Assets( $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } ) => { asset_id: *asset_id == id, @@ -771,9 +769,39 @@ macro_rules! impl_assets_helpers_for_parachain { ); }); } - /// Create assets using sudo `Assets::force_create()` - pub fn force_create_asset( - id: u32, + + /// Returns the encoded call for `create` from the assets pallet + pub fn create_asset_call( + asset_id: u32, + min_balance: $crate::impls::Balance, + admin: $crate::impls::AccountId, + ) -> $crate::impls::DoubleEncoded<()> { + use $crate::impls::{Chain, Encode}; + + ::RuntimeCall::Assets($crate::impls::pallet_assets::Call::< + ::Runtime, + $crate::impls::pallet_assets::Instance1, + >::create { + id: asset_id.into(), + min_balance, + admin: admin.into(), + }) + .encode() + .into() + } + } + } + }; +} + +#[macro_export] +macro_rules! impl_foreign_assets_helpers_for_parachain { + ($chain:ident, $asset_id_type:ty) => { + $crate::impls::paste::paste! { + impl $chain { + /// Create foreign assets using sudo `ForeignAssets::force_create()` + pub fn force_create_foreign_asset( + id: $asset_id_type, owner: $crate::impls::AccountId, is_sufficient: bool, min_balance: u128, @@ -783,20 +811,20 @@ macro_rules! impl_assets_helpers_for_parachain { let sudo_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::root(); ::execute_with(|| { $crate::impls::assert_ok!( - ]>::Assets::force_create( + ]>::ForeignAssets::force_create( sudo_origin, - id.clone().into(), + id.clone(), owner.clone().into(), is_sufficient, min_balance, ) ); - assert!(]>::Assets::asset_exists(id.clone())); + assert!(]>::ForeignAssets::asset_exists(id.clone())); type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::Assets( + RuntimeEvent::::ForeignAssets( $crate::impls::pallet_assets::Event::ForceCreated { asset_id, .. @@ -808,19 +836,19 @@ macro_rules! impl_assets_helpers_for_parachain { for (beneficiary, amount) in prefund_accounts.into_iter() { let signed_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone()); - Self::mint_asset(signed_origin, id.clone(), beneficiary, amount); + Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount); } } - /// Mint assets making use of the assets pallet - pub fn mint_asset( + /// Mint assets making use of the ForeignAssets pallet-assets instance + pub fn mint_foreign_asset( signed_origin: ::RuntimeOrigin, - id: u32, + id: $asset_id_type, beneficiary: $crate::impls::AccountId, amount_to_mint: u128, ) { ::execute_with(|| { - $crate::impls::assert_ok!(]>::Assets::mint( + $crate::impls::assert_ok!(]>::ForeignAssets::mint( signed_origin, id.clone().into(), beneficiary.clone().into(), @@ -832,7 +860,7 @@ macro_rules! impl_assets_helpers_for_parachain { $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::Assets( + RuntimeEvent::::ForeignAssets( $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } ) => { asset_id: *asset_id == id, @@ -844,29 +872,9 @@ macro_rules! impl_assets_helpers_for_parachain { }); } - /// Returns the encoded call for `create` from the assets pallet - pub fn create_asset_call( - asset_id: u32, - min_balance: $crate::impls::Balance, - admin: $crate::impls::AccountId, - ) -> $crate::impls::DoubleEncoded<()> { - use $crate::impls::{Chain, Encode}; - - ::RuntimeCall::Assets($crate::impls::pallet_assets::Call::< - ::Runtime, - $crate::impls::pallet_assets::Instance1, - >::create { - id: asset_id.into(), - min_balance, - admin: admin.into(), - }) - .encode() - .into() - } - /// Returns the encoded call for `create` from the foreign assets pallet pub fn create_foreign_asset_call( - asset_id: $crate::impls::v3::Location, + asset_id: $asset_id_type, min_balance: $crate::impls::Balance, admin: $crate::impls::AccountId, ) -> $crate::impls::DoubleEncoded<()> { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index a0738839087a..547556fc5096 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -87,8 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); PenpalA::assert_xcmp_queue_success(None); @@ -113,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -212,10 +211,8 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let reservable_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let reservable_asset_location = PenpalLocalReservableFromAssetHub::get(); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -245,14 +242,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_asset_location = PenpalLocalReservableFromAssetHub::get(); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -304,7 +300,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::MessageQueue( @@ -317,8 +313,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = RelayLocation::get(); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -371,8 +366,7 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = RelayLocation::get(); PenpalB::assert_xcmp_queue_success(None); @@ -526,8 +520,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let amount_to_send: Balance = ROCOCO_ED * 1000; // Init values fot Parachain - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -542,7 +535,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &receiver) + >::balance(relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -555,7 +548,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -577,13 +570,12 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = ROCOCO_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - relay_native_asset_location, + relay_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -614,7 +606,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -627,7 +619,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -654,8 +646,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -677,7 +668,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.into(), &receiver) + >::balance(system_para_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -711,14 +702,13 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - system_para_native_asset_location, + system_para_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -749,7 +739,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(system_para_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -817,10 +807,8 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get(); // Init Test let para_test_args = TestContext { @@ -845,11 +833,14 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(system_para_native_asset_location.clone(), &receiver) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -866,7 +857,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(system_para_native_asset_location.clone(), &receiver) }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -904,14 +895,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); - let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let asset_location_on_penpal = PenpalLocalReservableFromAssetHub::get(); + let system_asset_location_on_penpal = RelayLocation::get(); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - (asset_location_on_penpal_latest, asset_amount_to_send).into(), + (asset_location_on_penpal.clone(), asset_amount_to_send).into(), ] .into(); let fee_asset_index = assets @@ -938,10 +926,8 @@ fn reserve_transfer_assets_from_para_to_system_para() { let receiver = AssetHubRococoReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get(); let ah_asset_owner = AssetHubRococoAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -976,11 +962,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &sender) + >::balance(system_para_foreign_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubRococo::execute_with(|| { @@ -997,7 +983,7 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query final balances let sender_system_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -1036,15 +1022,14 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = ROCOCO_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - relay_native_asset_location, + relay_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -1066,11 +1051,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -1083,7 +1068,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index e13300b7c114..a0a3c4d2e74a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -17,7 +17,10 @@ use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { - let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get()); + let asset_native = Box::new( + v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get()) + .expect("conversion works"), + ); let asset_one = Box::new(v3::Location::new( 0, [ @@ -228,11 +231,9 @@ fn swap_locally_on_chain_using_foreign_assets() { #[test] fn cannot_create_pool_from_pool_assets() { - let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get()); - let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocationV3::get(); - asset_one - .append_with(v3::Junction::GeneralIndex(ASSET_ID.into())) - .expect("pool assets"); + let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get(); + let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocation::get(); + asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets"); AssetHubRococo::execute_with(|| { let pool_owner_account_id = asset_hub_rococo_runtime::AssetConversionOrigin::get(); @@ -255,8 +256,8 @@ fn cannot_create_pool_from_pool_assets() { assert_matches::assert_matches!( ::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), - asset_native, - Box::new(asset_one), + Box::new(v3::Location::try_from(asset_native).expect("conversion works")), + Box::new(v3::Location::try_from(asset_one).expect("conversion works")), ), Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) ); @@ -265,7 +266,9 @@ fn cannot_create_pool_from_pool_assets() { #[test] fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get(); + let asset_native = + v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get()) + .expect("conversion works"); let asset_one = xcm::v3::Location { parents: 0, interior: [ diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 1cbb7fb8c193..5ca39a939594 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -110,8 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -204,8 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); PenpalA::assert_xcmp_queue_success(None); @@ -428,8 +426,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { }; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); @@ -448,7 +445,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner.clone()), - system_para_native_asset_location, + system_para_native_asset_location.clone(), sender.clone(), fee_amount_to_send * 2, ); @@ -494,7 +491,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -521,7 +518,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -603,7 +600,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalAReceiver::get(), ) }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index a26dfef8e8e7..1026c1c496ab 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -87,8 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); PenpalA::assert_xcmp_queue_success(None); @@ -113,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -212,10 +211,8 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let reservable_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let reservable_asset_location = PenpalLocalReservableFromAssetHub::get(); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -245,14 +242,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_asset_location = PenpalLocalReservableFromAssetHub::get(); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -304,7 +300,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), + asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::MessageQueue( @@ -317,8 +313,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = RelayLocation::get(); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -371,8 +366,7 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = RelayLocation::get(); PenpalB::assert_xcmp_queue_success(None); @@ -526,8 +520,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let amount_to_send: Balance = WESTEND_ED * 1000; // Init values fot Parachain - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -542,7 +535,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &receiver) + >::balance(relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -555,7 +548,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -577,13 +570,12 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - relay_native_asset_location, + relay_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -614,7 +606,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -627,7 +619,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.into(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -654,8 +646,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -677,7 +668,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.into(), &receiver) + >::balance(system_para_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -711,14 +702,13 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - system_para_native_asset_location, + system_para_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -750,7 +740,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(system_para_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -818,10 +808,8 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get(); // Init Test let para_test_args = TestContext { @@ -846,11 +834,14 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(system_para_native_asset_location.clone(), &receiver) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -905,14 +896,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); - let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let asset_location_on_penpal = PenpalLocalReservableFromAssetHub::get(); + let system_asset_location_on_penpal = RelayLocation::get(); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - (asset_location_on_penpal_latest, asset_amount_to_send).into(), + (asset_location_on_penpal.clone(), asset_amount_to_send).into(), ] .into(); let fee_asset_index = assets @@ -940,10 +928,8 @@ fn reserve_transfer_assets_from_para_to_system_para() { let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location = - v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get(); let ah_asset_owner = AssetHubWestendAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -978,11 +964,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &sender) + >::balance(system_para_foreign_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubWestend::execute_with(|| { @@ -1038,15 +1024,14 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = WESTEND_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = RelayLocation::get(); let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner), - relay_native_asset_location, + relay_native_asset_location.clone(), sender.clone(), amount_to_send * 2, ); @@ -1068,11 +1053,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -1085,7 +1070,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(relay_native_asset_location.clone(), &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index aa673c03483a..363c09d682d8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -17,7 +17,10 @@ use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { - let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get()); + let asset_native = Box::new( + v3::Location::try_from(asset_hub_westend_runtime::xcm_config::WestendLocation::get()) + .expect("conversion works"), + ); let asset_one = Box::new(v3::Location { parents: 0, interior: [ @@ -227,11 +230,9 @@ fn swap_locally_on_chain_using_foreign_assets() { #[test] fn cannot_create_pool_from_pool_assets() { - let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get()); - let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocationV3::get(); - asset_one - .append_with(v3::Junction::GeneralIndex(ASSET_ID.into())) - .expect("pool assets"); + let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get(); + let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocation::get(); + asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets"); AssetHubWestend::execute_with(|| { let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get(); @@ -254,8 +255,8 @@ fn cannot_create_pool_from_pool_assets() { assert_matches::assert_matches!( ::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), - asset_native, - Box::new(asset_one), + Box::new(v3::Location::try_from(asset_native).expect("conversion works")), + Box::new(v3::Location::try_from(asset_one).expect("conversion works")), ), Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) ); @@ -264,7 +265,9 @@ fn cannot_create_pool_from_pool_assets() { #[test] fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocationV3::get(); + let asset_native = + v3::Location::try_from(asset_hub_westend_runtime::xcm_config::WestendLocation::get()) + .expect("conversion works"); let asset_one = xcm::v3::Location { parents: 0, interior: [ diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index ac518d2ed4a4..06d88b4f7f76 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -110,8 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -204,8 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); PenpalA::assert_xcmp_queue_success(None); @@ -428,8 +426,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { }; let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = - v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = RelayLocation::get(); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); @@ -448,7 +445,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner.clone()), - system_para_native_asset_location, + system_para_native_asset_location.clone(), sender.clone(), fee_amount_to_send * 2, ); @@ -497,7 +494,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -524,7 +521,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -606,7 +603,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + system_para_native_asset_location.clone(), &PenpalAReceiver::get(), ) }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 780ba57f78a1..750427833d48 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -306,8 +306,6 @@ fn send_token_from_ethereum_to_penpal() { // The Weth asset location, identified by the contract address on Ethereum let weth_asset_location: Location = (Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into(); - // Converts the Weth asset location into an asset ID - let weth_asset_id: v3::Location = weth_asset_location.try_into().unwrap(); let origin_location = (Parent, Parent, EthereumNetwork::get()).into(); @@ -321,12 +319,12 @@ fn send_token_from_ethereum_to_penpal() { PenpalA::execute_with(|| { assert_ok!(::ForeignAssets::create( ::RuntimeOrigin::signed(PenpalASender::get()), - weth_asset_id, + weth_asset_location.clone(), asset_hub_sovereign.into(), 1000, )); - assert!(::ForeignAssets::asset_exists(weth_asset_id)); + assert!(::ForeignAssets::asset_exists(weth_asset_location)); }); BridgeHubRococo::execute_with(|| { 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 180257035bf3..d1ed7a2a44f6 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 @@ -82,8 +82,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub UniquesPalletLocation: Location = PalletInstance(::index() as u8).into(); - pub PoolAssetsPalletLocationV3: xcm::v3::Location = - xcm::v3::Junction::PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: Location = Location::parent(); pub StakingPot: AccountId = CollatorSelection::account_id(); 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 d940f5d995ee..41e941ee9a2b 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 @@ -78,8 +78,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub UniquesPalletLocation: Location = PalletInstance(::index() as u8).into(); - pub PoolAssetsPalletLocationV3: xcm::v3::Location = - xcm::v3::Junction::PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub StakingPot: AccountId = CollatorSelection::account_id(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); From 1c4636ceca15e1cf3d6d9237aea52e98eaf869f4 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 10 Apr 2024 14:28:29 +0200 Subject: [PATCH 10/11] Removed duplicated AssetIdForTrustBackedAssetsConvert/AssetIdForTrustBackedAssetsConvertLatest from tests --- .../assets/asset-hub-rococo/tests/tests.rs | 73 +++++++++---------- .../assets/asset-hub-westend/tests/tests.rs | 71 +++++++++--------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index df7ba04c8d4c..f670c5f424ef 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -22,8 +22,7 @@ use asset_hub_rococo_runtime::{ xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, - LocationToAccountId, StakingPot, TokenLocation, TokenLocationV3, - TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig, + LocationToAccountId, StakingPot, TokenLocation, TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, @@ -59,12 +58,7 @@ use xcm_executor::traits::{JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; -type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert< - TrustBackedAssetsPalletLocationV3, - xcm::v3::Location, ->; - -type AssetIdForTrustBackedAssetsConvertLatest = +type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert; type RuntimeHelper = asset_test_utils::RuntimeHelper; @@ -206,7 +200,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); let asset_1: u32 = 1; - let native_location = TokenLocationV3::get(); + let native_location = TokenLocation::get(); let asset_1_location = AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap(); // bob's initial balance for native and `asset1` assets. @@ -223,14 +217,24 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location) + Box::new( + xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + ), + Box::new( + xcm::v3::Location::try_from(asset_1_location.clone()) + .expect("conversion works") + ) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location), + Box::new( + xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + ), + Box::new( + xcm::v3::Location::try_from(asset_1_location.clone()) + .expect("conversion works") + ), pool_liquidity, pool_liquidity, 1, @@ -242,8 +246,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let asset_total_issuance = Assets::total_issuance(asset_1); let native_total_issuance = Balances::total_issuance(); - let asset_1_location_latest: Location = asset_1_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -251,7 +253,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (asset_1_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -259,24 +261,25 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&asset_1_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); // prepare input to refund weight. let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); - let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); + let (reserve1, reserve2) = AssetConversion::get_reserves( + xcm::v3::Location::try_from(native_location).expect("conversion works"), + xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + ) + .unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (asset_1_location, asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -305,7 +308,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .execute_with(|| { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); - let native_location = TokenLocationV3::get(); + let native_location = + xcm::v3::Location::try_from(TokenLocation::get()).expect("conversion works"); let foreign_location = xcm::v3::Location { parents: 1, interior: ( @@ -437,7 +441,7 @@ fn test_asset_xcm_take_first_trader() { // get asset id as location let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); @@ -605,9 +609,7 @@ fn test_asset_xcm_take_first_trader_with_refund() { // We are going to buy 4e9 weight let bought = Weight::from_parts(4_000_000_000u64, 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -625,7 +627,7 @@ fn test_asset_xcm_take_first_trader_with_refund() { // We actually use half of the weight let weight_used = bought / 2; - // Make sure refurnd works. + // Make sure refund works. let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used)); assert_eq!( @@ -679,8 +681,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e // We are going to buy small amount let bought = Weight::from_parts(500_000_000u64, 0); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -732,8 +733,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { // We are gonna buy ED let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -809,8 +809,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let asset: Asset = (asset_location, asset_amount_needed).into(); @@ -927,7 +926,7 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); @@ -1009,7 +1008,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ XcmConfig, TrustBackedAssetsInstance, AssetIdForTrustBackedAssets, - AssetIdForTrustBackedAssetsConvertLatest, + AssetIdForTrustBackedAssetsConvert, collator_session_keys(), ExistentialDeposit::get(), 12345, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 8b0467963408..b5957dd5df92 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -22,8 +22,8 @@ use asset_hub_westend_runtime::{ xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, - LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, - TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, XcmConfig, + LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, WestendLocation, + XcmConfig, }, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, @@ -59,12 +59,7 @@ use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; -type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert< - TrustBackedAssetsPalletLocationV3, - xcm::v3::Location, ->; - -type AssetIdForTrustBackedAssetsConvertLatest = +type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert; type RuntimeHelper = asset_test_utils::RuntimeHelper; @@ -206,7 +201,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); let asset_1: u32 = 1; - let native_location = WestendLocationV3::get(); + let native_location = WestendLocation::get(); let asset_1_location = AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap(); // bob's initial balance for native and `asset1` assets. @@ -223,14 +218,24 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location) + Box::new( + xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + ), + Box::new( + xcm::v3::Location::try_from(asset_1_location.clone()) + .expect("conversion works") + ) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location), + Box::new( + xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + ), + Box::new( + xcm::v3::Location::try_from(asset_1_location.clone()) + .expect("conversion works") + ), pool_liquidity, pool_liquidity, 1, @@ -242,8 +247,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let asset_total_issuance = Assets::total_issuance(asset_1); let native_total_issuance = Balances::total_issuance(); - let asset_1_location_latest: Location = asset_1_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -251,7 +254,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (asset_1_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -259,24 +262,25 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&asset_1_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); // prepare input to refund weight. let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); - let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); + let (reserve1, reserve2) = AssetConversion::get_reserves( + xcm::v3::Location::try_from(native_location).expect("conversion works"), + xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + ) + .unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (asset_1_location, asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -305,7 +309,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .execute_with(|| { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); - let native_location = WestendLocationV3::get(); + let native_location = + xcm::v3::Location::try_from(WestendLocation::get()).expect("conversion works"); let foreign_location = xcm::v3::Location { parents: 1, interior: ( @@ -437,7 +442,7 @@ fn test_asset_xcm_take_first_trader() { // get asset id as location let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); @@ -601,8 +606,7 @@ fn test_asset_xcm_take_first_trader_with_refund() { // We are going to buy 4e9 weight let bought = Weight::from_parts(4_000_000_000u64, 0); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -674,8 +678,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e // We are going to buy small amount let bought = Weight::from_parts(500_000_000u64, 0); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -726,8 +729,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { let bought = Weight::from_parts(500_000_000u64, 0); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -803,8 +805,7 @@ fn test_asset_xcm_take_first_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); + let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let asset: Asset = (asset_location, asset_amount_needed).into(); @@ -925,7 +926,7 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); @@ -1007,7 +1008,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ XcmConfig, TrustBackedAssetsInstance, AssetIdForTrustBackedAssets, - AssetIdForTrustBackedAssetsConvertLatest, + AssetIdForTrustBackedAssetsConvert, collator_session_keys(), ExistentialDeposit::get(), 12345, From 9925ae12fb56750b2d4d8a9b37e03134a53847e0 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 12 Apr 2024 15:53:24 +0200 Subject: [PATCH 11/11] add prdoc --- prdoc/pr_4037.prdoc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 prdoc/pr_4037.prdoc diff --git a/prdoc/pr_4037.prdoc b/prdoc/pr_4037.prdoc new file mode 100644 index 000000000000..7071875a7e37 --- /dev/null +++ b/prdoc/pr_4037.prdoc @@ -0,0 +1,26 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "Remove `xcm::v3` from `assets-common` nits" + +doc: + - audience: Runtime Dev + description: | + Remove `xcm::v3` imports from `assets-common` to make it more generic and facilitate the transition to newer XCM versions. + The implementations `AssetIdForTrustBackedAssetsConvert`, `ForeignAssetsConvertedConcreteId`, or `TrustBackedAssetsAsLocation` + used hard-coded `xcm::v3::Location`, which has been changed to use `xcm::latest::Location` by default. + Alternatively, the providing runtime can configure them according to its needs, such as with a lower XCM version. + + Example: + ```patch + - AssetIdForTrustBackedAssetsConvert, + + AssetIdForTrustBackedAssetsConvert, + ``` + + Another change is that the removed `xcm_builder::V4V3LocationConverter` can be replaced with `WithLatestLocationConverter`. + +crates: +- name: assets-common + bump: patch +- name: staging-xcm-builder + bump: patch