mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Remove xcm::v3 from assets-common nits (#4037)
This PR mainly removes `xcm::v3` stuff from `assets-common` to make it
more generic and facilitate the transition to newer XCM versions. Some
of the implementations here used hard-coded `xcm::v3::Location`, but now
it's up to the runtime to configure according to its needs.
Additional/consequent changes:
- `penpal` runtime uses now `xcm::latest::Location` for `pallet_assets`
as `AssetId`, because we don't care about migrations here
- it pretty much simplify xcm-emulator integration tests, where we don't
need now a lots of boilerplate conversions:
```
v3::Location::try_from(...).expect("conversion works")`
```
- xcm-emulator tests
- split macro `impl_assets_helpers_for_parachain` to the
`impl_assets_helpers_for_parachain` and
`impl_foreign_assets_helpers_for_parachain` (avoids using hard-coded
`xcm::v3::Location`)
This commit is contained in:
@@ -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 sp_runtime::traits::TryConvertInto;
|
||||
use xcm::latest::Location;
|
||||
use xcm_builder::{
|
||||
AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter,
|
||||
AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, WithLatestLocationConverter,
|
||||
};
|
||||
use xcm_executor::traits::JustTry;
|
||||
|
||||
/// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets`
|
||||
pub type AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation> =
|
||||
pub type AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation, L = Location> =
|
||||
AsPrefixedGeneralIndex<
|
||||
TrustBackedAssetsPalletLocation,
|
||||
AssetIdForTrustBackedAssets,
|
||||
JustTry,
|
||||
xcm::v3::Location,
|
||||
TryConvertInto,
|
||||
L,
|
||||
>;
|
||||
|
||||
pub type AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation> =
|
||||
AsPrefixedGeneralIndex<TrustBackedAssetsPalletLocation, AssetIdForTrustBackedAssets, JustTry>;
|
||||
|
||||
/// `Location` vs `CollectionId` converter for `Uniques`
|
||||
pub type CollectionIdForUniquesConvert<UniquesPalletLocation> =
|
||||
AsPrefixedGeneralIndex<UniquesPalletLocation, CollectionId, JustTry>;
|
||||
AsPrefixedGeneralIndex<UniquesPalletLocation, CollectionId, TryConvertInto>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
|
||||
pub type TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, Balance> =
|
||||
MatchedConvertedConcreteId<
|
||||
AssetIdForTrustBackedAssets,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>,
|
||||
JustTry,
|
||||
>;
|
||||
pub type TrustBackedAssetsConvertedConcreteId<
|
||||
TrustBackedAssetsPalletLocation,
|
||||
Balance,
|
||||
L = Location,
|
||||
> = MatchedConvertedConcreteId<
|
||||
AssetIdForTrustBackedAssets,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation, L>,
|
||||
TryConvertInto,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `Uniques`
|
||||
pub type UniquesConvertedConcreteId<UniquesPalletLocation> = MatchedConvertedConcreteId<
|
||||
@@ -65,28 +66,26 @@ pub type UniquesConvertedConcreteId<UniquesPalletLocation> = MatchedConvertedCon
|
||||
// junction within the pallet itself.
|
||||
StartsWith<UniquesPalletLocation>,
|
||||
CollectionIdForUniquesConvert<UniquesPalletLocation>,
|
||||
JustTry,
|
||||
TryConvertInto,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `Location`.
|
||||
pub type LocationConvertedConcreteId<LocationFilter, Balance> = MatchedConvertedConcreteId<
|
||||
xcm::v3::Location,
|
||||
/// [`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,
|
||||
LocationFilter,
|
||||
V4V3LocationConverter,
|
||||
JustTry,
|
||||
L,
|
||||
LocationConverter = WithLatestLocationConverter<L>,
|
||||
> = MatchedConvertedConcreteId<
|
||||
L,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
LocationConverter,
|
||||
TryConvertInto,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
|
||||
pub type TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance> =
|
||||
MatchedConvertedConcreteId<
|
||||
xcm::v3::Location,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
V4V3LocationConverter,
|
||||
JustTry,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as
|
||||
/// `Location`.
|
||||
///
|
||||
@@ -95,26 +94,34 @@ pub type TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance> =
|
||||
/// - all local Locations
|
||||
///
|
||||
/// `AdditionalLocationExclusionFilter` can customize additional excluded Locations
|
||||
pub type ForeignAssetsConvertedConcreteId<AdditionalLocationExclusionFilter, Balance> =
|
||||
LocationConvertedConcreteId<
|
||||
EverythingBut<(
|
||||
// Excludes relay/parent chain currency
|
||||
Equals<ParentLocation>,
|
||||
// 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<LocalLocationPattern>,
|
||||
// Here we can exclude more stuff or leave it as `()`
|
||||
AdditionalLocationExclusionFilter,
|
||||
)>,
|
||||
Balance,
|
||||
>;
|
||||
pub type ForeignAssetsConvertedConcreteId<
|
||||
AdditionalLocationExclusionFilter,
|
||||
Balance,
|
||||
AssetId,
|
||||
LocationToAssetIdConverter = WithLatestLocationConverter<AssetId>,
|
||||
BalanceConverter = TryConvertInto,
|
||||
> = MatchedConvertedConcreteId<
|
||||
AssetId,
|
||||
Balance,
|
||||
EverythingBut<(
|
||||
// Excludes relay/parent chain currency
|
||||
Equals<ParentLocation>,
|
||||
// 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<LocalLocationPattern>,
|
||||
// Here we can exclude more stuff or leave it as `()`
|
||||
AdditionalLocationExclusionFilter,
|
||||
)>,
|
||||
LocationToAssetIdConverter,
|
||||
BalanceConverter,
|
||||
>;
|
||||
|
||||
type AssetIdForPoolAssets = u32;
|
||||
/// `Location` vs `AssetIdForPoolAssets` converter for `PoolAssets`.
|
||||
pub type AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation> =
|
||||
AsPrefixedGeneralIndex<PoolAssetsPalletLocation, AssetIdForPoolAssets, JustTry>;
|
||||
AsPrefixedGeneralIndex<PoolAssetsPalletLocation, AssetIdForPoolAssets, TryConvertInto>;
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `PoolAssets`
|
||||
pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> =
|
||||
MatchedConvertedConcreteId<
|
||||
@@ -122,7 +129,7 @@ pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> =
|
||||
Balance,
|
||||
StartsWith<PoolAssetsPalletLocation>,
|
||||
AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation>,
|
||||
JustTry,
|
||||
TryConvertInto,
|
||||
>;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -130,7 +137,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]
|
||||
@@ -143,14 +150,14 @@ mod tests {
|
||||
Location::new(5, [PalletInstance(13), GeneralIndex(local_asset_id.into())]);
|
||||
|
||||
assert_eq!(
|
||||
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert_back(
|
||||
AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert_back(
|
||||
&local_asset_id
|
||||
)
|
||||
.unwrap(),
|
||||
expected_reverse_ref
|
||||
);
|
||||
assert_eq!(
|
||||
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert(
|
||||
AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert(
|
||||
&expected_reverse_ref
|
||||
)
|
||||
.unwrap(),
|
||||
@@ -163,7 +170,7 @@ mod tests {
|
||||
frame_support::parameter_types! {
|
||||
pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]);
|
||||
}
|
||||
// setup convert
|
||||
// set up a converter
|
||||
type TrustBackedAssetsConvert =
|
||||
TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, u128>;
|
||||
|
||||
@@ -246,19 +253,21 @@ 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 convert
|
||||
// set up a converter which uses `xcm::v3::Location` under the hood
|
||||
type Convert = ForeignAssetsConvertedConcreteId<
|
||||
(
|
||||
StartsWith<Parachain100Pattern>,
|
||||
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
|
||||
),
|
||||
u128,
|
||||
xcm::v3::Location,
|
||||
WithLatestLocationConverter<xcm::v3::Location>,
|
||||
>;
|
||||
|
||||
let test_data = vec![
|
||||
|
||||
Reference in New Issue
Block a user