diff --git a/parachains/runtimes/assets/common/src/lib.rs b/parachains/runtimes/assets/common/src/lib.rs index fbf19b89914..999b0ae990a 100644 --- a/parachains/runtimes/assets/common/src/lib.rs +++ b/parachains/runtimes/assets/common/src/lib.rs @@ -79,6 +79,7 @@ pub type ForeignAssetsConvertedConcreteId, u128>; + type Convert = ForeignAssetsConvertedConcreteId< + ( + StartsWith, + StartsWithExplicitGlobalConsensus, + ), + u128, + >; let test_data = vec![ // excluded as local @@ -212,13 +220,33 @@ mod tests { ), // excluded as parent (ma_1000(1, Here), Err(MatchError::AssetNotHandled)), - // excluded as additional filter + // excluded as additional filter - Parachain100Pattern (ma_1000(1, X1(Parachain(100))), Err(MatchError::AssetNotHandled)), (ma_1000(1, X2(Parachain(100), GeneralIndex(1234))), Err(MatchError::AssetNotHandled)), ( ma_1000(1, X3(Parachain(100), PalletInstance(13), GeneralIndex(1234))), Err(MatchError::AssetNotHandled), ), + // excluded as additional filter - StartsWithExplicitGlobalConsensus + ( + ma_1000(1, X1(GlobalConsensus(NetworkId::ByGenesis([9; 32])))), + Err(MatchError::AssetNotHandled), + ), + ( + ma_1000(2, X1(GlobalConsensus(NetworkId::ByGenesis([9; 32])))), + Err(MatchError::AssetNotHandled), + ), + ( + ma_1000( + 2, + X3( + GlobalConsensus(NetworkId::ByGenesis([9; 32])), + Parachain(200), + GeneralIndex(1234), + ), + ), + Err(MatchError::AssetNotHandled), + ), // ok (ma_1000(1, X1(Parachain(200))), Ok((MultiLocation::new(1, X1(Parachain(200))), 1000))), (ma_1000(2, X1(Parachain(200))), Ok((MultiLocation::new(2, X1(Parachain(200))), 1000))), @@ -230,6 +258,34 @@ mod tests { ma_1000(2, X2(Parachain(200), GeneralIndex(1234))), Ok((MultiLocation::new(2, X2(Parachain(200), GeneralIndex(1234))), 1000)), ), + ( + ma_1000(2, X1(GlobalConsensus(NetworkId::ByGenesis([7; 32])))), + Ok(( + MultiLocation::new(2, X1(GlobalConsensus(NetworkId::ByGenesis([7; 32])))), + 1000, + )), + ), + ( + ma_1000( + 2, + X3( + GlobalConsensus(NetworkId::ByGenesis([7; 32])), + Parachain(200), + GeneralIndex(1234), + ), + ), + Ok(( + MultiLocation::new( + 2, + X3( + GlobalConsensus(NetworkId::ByGenesis([7; 32])), + Parachain(200), + GeneralIndex(1234), + ), + ), + 1000, + )), + ), ]; for (multi_asset, expected_result) in test_data { diff --git a/parachains/runtimes/assets/common/src/matching.rs b/parachains/runtimes/assets/common/src/matching.rs index 05acaff3990..5a60b18b8c9 100644 --- a/parachains/runtimes/assets/common/src/matching.rs +++ b/parachains/runtimes/assets/common/src/matching.rs @@ -37,6 +37,18 @@ impl> Contains for Equals } } +pub struct StartsWithExplicitGlobalConsensus(sp_std::marker::PhantomData); +impl> Contains + for StartsWithExplicitGlobalConsensus +{ + fn contains(t: &MultiLocation) -> bool { + match t.interior.global_consensus() { + Ok(requested_network) if requested_network.eq(&Network::get()) => true, + _ => false, + } + } +} + frame_support::parameter_types! { pub LocalMultiLocationPattern: MultiLocation = MultiLocation::new(0, Here); pub ParentLocation: MultiLocation = MultiLocation::parent(); diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index 3476da44a47..bb591d5bcab 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -18,7 +18,9 @@ use super::{ ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; -use assets_common::matching::{FromSiblingParachain, IsForeignConcreteAsset, StartsWith}; +use assets_common::matching::{ + FromSiblingParachain, IsForeignConcreteAsset, StartsWith, StartsWithExplicitGlobalConsensus, +}; use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, @@ -49,6 +51,7 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); + pub UniversalLocationNetworkId: NetworkId = UniversalLocation::get().global_consensus().unwrap(); pub TrustBackedAssetsPalletLocation: MultiLocation = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); @@ -103,7 +106,14 @@ pub type FungiblesTransactor = FungiblesAdapter< /// `AssetId/Balance` converter for `TrustBackedAssets` pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConvertedConcreteId< - StartsWith, + ( + // Ignore `TrustBackedAssets` explicitly + StartsWith, + // Ignore asset which starts explicitly with our `GlobalConsensus(NetworkId)`, means: + // - foreign assets from our consensus should be: `MultiLocation {parent: 1, X*(Parachain(xyz))} + // - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` wont be accepted here + StartsWithExplicitGlobalConsensus, + ), Balance, >; diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index b6587c7dc97..b13e88b2b06 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -19,7 +19,9 @@ use super::{ TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use crate::ForeignAssets; -use assets_common::matching::{FromSiblingParachain, IsForeignConcreteAsset, StartsWith}; +use assets_common::matching::{ + FromSiblingParachain, IsForeignConcreteAsset, StartsWith, StartsWithExplicitGlobalConsensus, +}; use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, @@ -50,6 +52,7 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); + pub UniversalLocationNetworkId: NetworkId = UniversalLocation::get().global_consensus().unwrap(); pub TrustBackedAssetsPalletLocation: MultiLocation = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); @@ -104,7 +107,14 @@ pub type FungiblesTransactor = FungiblesAdapter< /// `AssetId/Balance` converter for `TrustBackedAssets` pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConvertedConcreteId< - StartsWith, + ( + // Ignore `TrustBackedAssets` explicitly + StartsWith, + // Ignore asset which starts explicitly with our `GlobalConsensus(NetworkId)`, means: + // - foreign assets from our consensus should be: `MultiLocation {parent: 1, X*(Parachain(xyz))} + // - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` wont be accepted here + StartsWithExplicitGlobalConsensus, + ), Balance, >;