mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 00:47:55 +00:00
Added AllSiblingSystemParachains matcher to be used at a parachain level (#2422)
As suggested in this thread: https://github.com/polkadot-fellows/runtimes/pull/87#discussion_r1400237122 We already have the `IsChildSystemParachain`, which may be used at relay chain, but it can't be used at a parachain level. So let's use `AllSiblingSystemParachains` for that. I was thinking about `AllSystemParachains`, but it may cause wrong impression that it can be used at a relay chain level. --------- Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4df313fbc7
commit
0b3d0677f8
Generated
+2
@@ -14544,6 +14544,7 @@ dependencies = [
|
||||
"sp-runtime",
|
||||
"sp-weights",
|
||||
"staging-xcm",
|
||||
"staging-xcm-builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -20982,6 +20983,7 @@ dependencies = [
|
||||
"sp-runtime",
|
||||
"sp-weights",
|
||||
"staging-xcm",
|
||||
"staging-xcm-builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -100,6 +100,25 @@ impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::C
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains all sibling system parachains, including the one where this matcher is used.
|
||||
///
|
||||
/// This structure can only be used at a parachain level. In the Relay Chain, please use
|
||||
/// the `xcm_builder::IsChildSystemParachain` matcher.
|
||||
pub struct AllSiblingSystemParachains;
|
||||
|
||||
impl Contains<MultiLocation> for AllSiblingSystemParachains {
|
||||
fn contains(l: &MultiLocation) -> bool {
|
||||
log::trace!(target: "xcm::contains", "AllSiblingSystemParachains location: {:?}", l);
|
||||
match *l {
|
||||
// System parachain
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
|
||||
ParaId::from(id).is_system(),
|
||||
// Everything else
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
|
||||
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
|
||||
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
@@ -122,12 +141,14 @@ impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use frame_support::parameter_types;
|
||||
use frame_support::{parameter_types, traits::Contains};
|
||||
|
||||
use super::{
|
||||
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
|
||||
PalletInstance, Parachain, Parent,
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here,
|
||||
MultiAsset, MultiLocation, PalletInstance, Parachain, Parent,
|
||||
};
|
||||
use polkadot_primitives::LOWEST_PUBLIC_ID;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
@@ -180,4 +201,19 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_sibling_system_parachains_works() {
|
||||
// system parachain
|
||||
assert!(AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(Parachain(1)))));
|
||||
// non-system parachain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(
|
||||
1,
|
||||
X1(Parachain(LOWEST_PUBLIC_ID.into()))
|
||||
)));
|
||||
// when used at relay chain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(0, X1(Parachain(1)))));
|
||||
// when used with non-parachain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(OnlyChild))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,13 @@ use pallet_xcm::XcmPassthrough;
|
||||
use parachains_common::{
|
||||
impls::ToStakingPot,
|
||||
xcm_config::{
|
||||
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
|
||||
RelayOrOtherSystemParachains,
|
||||
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
|
||||
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
TREASURY_PALLET_ID,
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use rococo_runtime_constants::system_parachain;
|
||||
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
@@ -513,25 +512,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
|
||||
ForeignAssetsInstance,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::BRIDGE_HUB_ID |
|
||||
system_parachain::CONTRACTS_ID |
|
||||
system_parachain::ENCOINTER_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
|
||||
///
|
||||
|
||||
@@ -32,15 +32,14 @@ use pallet_xcm::XcmPassthrough;
|
||||
use parachains_common::{
|
||||
impls::ToStakingPot,
|
||||
xcm_config::{
|
||||
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
|
||||
RelayOrOtherSystemParachains,
|
||||
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
|
||||
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
TREASURY_PALLET_ID,
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
|
||||
use westend_runtime_constants::system_parachain;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
|
||||
@@ -520,24 +519,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
|
||||
ForeignAssetsInstance,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::COLLECTIVES_ID |
|
||||
system_parachain::BRIDGE_HUB_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
|
||||
///
|
||||
|
||||
@@ -33,12 +33,13 @@ use frame_system::EnsureRoot;
|
||||
use pallet_xcm::XcmPassthrough;
|
||||
use parachains_common::{
|
||||
impls::ToStakingPot,
|
||||
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
|
||||
xcm_config::{
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
TREASURY_PALLET_ID,
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use rococo_runtime_constants::system_parachain;
|
||||
use sp_core::Get;
|
||||
use sp_runtime::traits::AccountIdConversion;
|
||||
use sp_std::marker::PhantomData;
|
||||
@@ -220,25 +221,13 @@ pub type Barrier = TrailingSetTopicAsId<
|
||||
>,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::BRIDGE_HUB_ID |
|
||||
system_parachain::CONTRACTS_ID |
|
||||
system_parachain::ENCOINTER_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
|
||||
/// - NativeToken with the parent Relay Chain and sibling parachains.
|
||||
|
||||
@@ -28,13 +28,14 @@ use frame_system::EnsureRoot;
|
||||
use pallet_xcm::XcmPassthrough;
|
||||
use parachains_common::{
|
||||
impls::ToStakingPot,
|
||||
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
|
||||
xcm_config::{
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
TREASURY_PALLET_ID,
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use sp_runtime::traits::AccountIdConversion;
|
||||
use westend_runtime_constants::system_parachain;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
|
||||
@@ -209,24 +210,13 @@ pub type Barrier = TrailingSetTopicAsId<
|
||||
>,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::BRIDGE_HUB_ID |
|
||||
system_parachain::COLLECTIVES_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
|
||||
/// - NativeToken with the parent Relay Chain and sibling parachains.
|
||||
|
||||
@@ -27,11 +27,12 @@ use frame_system::EnsureRoot;
|
||||
use pallet_xcm::XcmPassthrough;
|
||||
use parachains_common::{
|
||||
impls::ToStakingPot,
|
||||
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
|
||||
xcm_config::{
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use westend_runtime_constants::system_parachain;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
|
||||
@@ -250,24 +251,13 @@ pub type Barrier = TrailingSetTopicAsId<
|
||||
>,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::BRIDGE_HUB_ID |
|
||||
system_parachain::COLLECTIVES_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
|
||||
/// - DOT with the parent Relay Chain and sibling parachains.
|
||||
|
||||
@@ -27,12 +27,13 @@ use frame_support::{
|
||||
use frame_system::EnsureRoot;
|
||||
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
|
||||
use parachains_common::{
|
||||
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
|
||||
xcm_config::{
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
|
||||
},
|
||||
TREASURY_PALLET_ID,
|
||||
};
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
|
||||
use rococo_runtime_constants::system_parachain;
|
||||
use sp_runtime::traits::AccountIdConversion;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
@@ -158,25 +159,13 @@ pub type Barrier = TrailingSetTopicAsId<
|
||||
>,
|
||||
>;
|
||||
|
||||
match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(
|
||||
system_parachain::ASSET_HUB_ID |
|
||||
system_parachain::BRIDGE_HUB_ID |
|
||||
system_parachain::CONTRACTS_ID |
|
||||
system_parachain::ENCOINTER_ID
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Locations that will not be charged fees in the executor,
|
||||
/// either execution or delivery.
|
||||
/// We only waive fees for system functions, which these locations represent.
|
||||
pub type WaivedLocations =
|
||||
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
|
||||
pub type WaivedLocations = (
|
||||
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
|
||||
Equals<RelayTreasuryLocation>,
|
||||
);
|
||||
|
||||
pub type TrustedTeleporter = ConcreteAssetFromSystem<RelayLocation>;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ sp-weights = { path = "../../../../substrate/primitives/weights", default-featur
|
||||
sp-core = { path = "../../../../substrate/primitives/core", default-features = false }
|
||||
|
||||
xcm = { package = "staging-xcm", path = "../../../xcm", default-features = false }
|
||||
xcm-builder = { package = "staging-xcm-builder", path = "../../../xcm/xcm-builder", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
@@ -27,6 +28,7 @@ std = [
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
"sp-weights/std",
|
||||
"xcm-builder/std",
|
||||
"xcm/std",
|
||||
]
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ pub mod fee {
|
||||
|
||||
/// System Parachains.
|
||||
pub mod system_parachain {
|
||||
use xcm::latest::prelude::*;
|
||||
use primitives::Id;
|
||||
use xcm_builder::IsChildSystemParachain;
|
||||
|
||||
/// Network's Asset Hub parachain ID.
|
||||
pub const ASSET_HUB_ID: u32 = 1000;
|
||||
@@ -114,11 +115,8 @@ pub mod system_parachain {
|
||||
/// BridgeHub parachain ID.
|
||||
pub const BRIDGE_HUB_ID: u32 = 1013;
|
||||
|
||||
frame_support::match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) }
|
||||
};
|
||||
}
|
||||
/// All system parachains of Rococo.
|
||||
pub type SystemParachains = IsChildSystemParachain<Id>;
|
||||
}
|
||||
|
||||
/// Rococo Treasury pallet instance.
|
||||
|
||||
@@ -17,6 +17,7 @@ sp-weights = { path = "../../../../substrate/primitives/weights", default-featur
|
||||
sp-core = { path = "../../../../substrate/primitives/core", default-features = false }
|
||||
|
||||
xcm = { package = "staging-xcm", path = "../../../xcm", default-features = false }
|
||||
xcm-builder = { package = "staging-xcm-builder", path = "../../../xcm/xcm-builder", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
@@ -27,5 +28,6 @@ std = [
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
"sp-weights/std",
|
||||
"xcm-builder/std",
|
||||
"xcm/std",
|
||||
]
|
||||
|
||||
@@ -98,7 +98,8 @@ pub mod fee {
|
||||
|
||||
/// System Parachains.
|
||||
pub mod system_parachain {
|
||||
use xcm::latest::prelude::*;
|
||||
use primitives::Id;
|
||||
use xcm_builder::IsChildSystemParachain;
|
||||
|
||||
/// Network's Asset Hub parachain ID.
|
||||
pub const ASSET_HUB_ID: u32 = 1000;
|
||||
@@ -107,11 +108,8 @@ pub mod system_parachain {
|
||||
/// BridgeHub parachain ID.
|
||||
pub const BRIDGE_HUB_ID: u32 = 1002;
|
||||
|
||||
frame_support::match_types! {
|
||||
pub type SystemParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))}
|
||||
};
|
||||
}
|
||||
/// All system parachains of Westend.
|
||||
pub type SystemParachains = IsChildSystemParachain<Id>;
|
||||
}
|
||||
|
||||
/// Westend Treasury pallet instance.
|
||||
|
||||
Reference in New Issue
Block a user