Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jun 25, 2024
1 parent 5aabe52 commit b1d1ca6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
29 changes: 22 additions & 7 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use dc_primitives::GWEI;
// polkadot-sdk
use frame_support::{
pallet_prelude::*,
traits::{tokens::currency::Currency as CurrencyT, ConstU128, OnUnbalanced as OnUnbalancedT},
traits::{
tokens::currency::Currency as CurrencyT, ConstU128, Contains, OnUnbalanced as OnUnbalancedT,
},
weights::{Weight, WeightToFee as WeightToFeeT},
};
use sp_core::Get;
Expand All @@ -40,13 +42,11 @@ use xcm_executor::traits::{ConvertLocation, WeightTrader};
pub type XcmBaseWeightFee = ConstU128<GWEI>;

frame_support::match_types! {
pub type ParentOrParentsExecutivePlurality: impl Contains<Location> = {
pub type ParentOrParentsPlurality: impl Contains<Location> = {
Location { parents: 1, interior: Here } |
Location { parents: 1, interior: Junctions::X1(Plurality { id: BodyId::Executive, .. }) }
};
pub type ParentOrSiblings: impl Contains<Location> = {
Location { parents: 1, interior: Here } |
Location { parents: 1, interior: Junctions::X1(_) }
Location { parents: 1, interior: Junctions::X1(Plurality { id: BodyId::Administration, .. }) }|
Location { parents: 1, interior: Junctions::X1(Plurality { id: BodyId::Executive, .. }) }|
Location { parents: 1, interior: Junctions::X1(Plurality { id: BodyId::Technical, .. }) }
};
}

Expand Down Expand Up @@ -140,6 +140,21 @@ impl<
}
}

/// Filter to check if a given location is the parent Relay Chain or a sibling parachain.
///
/// This type should only be used within the context of a parachain, since it does not verify that
/// the parent is indeed a Relay Chain.
pub struct ParentRelayOrSiblingParachains;
impl Contains<Location> for ParentRelayOrSiblingParachains {
fn contains(location: &Location) -> bool {
matches!(
location,
Location { parents: 1, interior: Here }
| Location { parents: 1, interior: Junctions::X1(Parachain(_)) }
)
}
}

// TODO: move to other place.
#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub struct AssetRegistrarMetadata {
Expand Down
6 changes: 2 additions & 4 deletions runtime/crab/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ pub type Barrier = xcm_builder::TrailingSetTopicAsId<
// Parent, its pluralities (i.e. governance bodies), and the Fellows plurality
// get free execution.
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
darwinia_common_runtime::xcm_configs::ParentOrParentsPlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
xcm_builder::AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
),
UniversalLocation,
ConstU32<8>,
Expand Down
6 changes: 2 additions & 4 deletions runtime/darwinia/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ pub type Barrier = xcm_builder::TrailingSetTopicAsId<
// Parent, its pluralities (i.e. governance bodies), and the Fellows plurality
// get free execution.
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
darwinia_common_runtime::xcm_configs::ParentOrParentsPlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
xcm_builder::AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
),
UniversalLocation,
ConstU32<8>,
Expand Down
8 changes: 3 additions & 5 deletions runtime/koi/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// darwinia
use crate::*;
// substrate
use xcm::latest::prelude::*;
use frame_support::traits::Currency;
use xcm::latest::prelude::*;

/// Means for transacting assets on this chain.
pub type LocalAssetTransactor = xcm_builder::CurrencyAdapter<
Expand Down Expand Up @@ -121,12 +121,10 @@ pub type Barrier = xcm_builder::TrailingSetTopicAsId<
// Parent, its pluralities (i.e. governance bodies), and the Fellows plurality
// get free execution.
xcm_builder::AllowExplicitUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
darwinia_common_runtime::xcm_configs::ParentOrParentsPlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
xcm_builder::AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
),
UniversalLocation,
ConstU32<8>,
Expand Down

0 comments on commit b1d1ca6

Please sign in to comment.