From 619a47da3ce45190b122042edc3177dcc79ef5b4 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 15 Aug 2023 09:55:39 +0800 Subject: [PATCH] Update xcm config for template --- parachain-template/runtime/src/xcm_config.rs | 56 ++++++++------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/parachain-template/runtime/src/xcm_config.rs b/parachain-template/runtime/src/xcm_config.rs index e08cf9fc6a84..1935c6bfa7fc 100644 --- a/parachain-template/runtime/src/xcm_config.rs +++ b/parachain-template/runtime/src/xcm_config.rs @@ -5,21 +5,28 @@ use super::{ use frame_support::{ match_types, parameter_types, traits::{ConstU32, Everything, Nothing}, - weights::Weight, BoundedBTreeMap + weights::Weight, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; use xcm::latest::prelude::*; -use xcm_builder::{AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic}; +use xcm_builder::{ + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, + FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, +}; use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: Option = None; + pub const RelayNetwork: Option = Some(NetworkId::Kusama); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -188,41 +195,24 @@ impl cumulus_pallet_xcm::Config for Runtime { /// All configuration related to bridging pub mod bridging { use pallet_bridge_transfer_primitives::{ - AssetFilter, BridgeConfig, BridgesConfig, BridgesConfigAdapter, BridgesConfigBuilder, - MaybePaidLocation, MultiLocationFilter, ReserveLocation, + BridgeConfig, BridgesConfig, BridgesConfigAdapter, BridgesConfigBuilder, MaybePaidLocation, }; - use frame_support::{parameter_types}; - use frame_support::traits::ConstU32; + use crate::xcm_config::{ + Junction::{GlobalConsensus, Parachain}, + Junctions::X1, + MultiLocation, SovereignPaidRemoteExporter, UniversalLocation, XcmRouter, + }; + use frame_support::parameter_types; use xcm::v3::NetworkId; - use xcm_builder::SovereignPaidRemoteExporter; - use crate::xcm_config::{UniversalLocation, XcmRouter}; parameter_types! { - pub const PolkadotNetwork: NetworkId = NetworkId::Polkadot; + pub BridgeHubKusamaParaId: u32 = 1013; + pub BridgeHubKusama: MultiLocation = MultiLocation::new(1, X1(Parachain(BridgeHubKusamaParaId::get()))); + // Network and location for the local Ethereum testnet. pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; + pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); pub Bridges: BridgesConfig = BridgesConfigBuilder::default() - .add_or_panic( - PolkadotNetwork::get(), - BridgeConfig::new( - MaybePaidLocation { - location: BridgeHubKusama::get(), - // No fees needed because we use `UnpaidRemoteExporter` and BridgeHubKusama allows unpaid execution for local system parachains - maybe_fee: None, - } - ).add_target_location( - // add target location as AssetHubPolkadot - MaybePaidLocation { - location: AssetHubPolkadot::get(), - maybe_fee: AssetHubPolkadotMaxFee::get(), - }, - Some(AssetFilter::ByMultiLocation( - MultiLocationFilter::default() - // allow transfer KSM - .add_equals(KsmLocation::get()) - )) - ) - ) .add_or_panic( EthereumNetwork::get(), BridgeConfig::new( @@ -241,5 +231,5 @@ pub mod bridging { } pub type BridgeXcmSender = - SovereignPaidRemoteExporter; + SovereignPaidRemoteExporter, XcmRouter, UniversalLocation>; }