1use super::{
18 AccountId, AllPalletsWithSystem, Balance, Balances, BaseDeliveryFee, FeeAssetId, ParachainInfo,
19 ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason,
20 RuntimeOrigin, TransactionByteFee, WeightToFee, XcmOverBridgeHubRococo, XcmpQueue,
21};
22use crate::bridge_to_ethereum_config::SnowbridgeFrontendLocation;
23use bridge_hub_common::DenyExportMessageFrom;
24use frame_support::{
25 parameter_types,
26 traits::{
27 fungible::HoldConsideration, tokens::imbalance::ResolveTo, ConstU32, Contains, Equals,
28 Everything, EverythingBut, LinearStoragePrice, Nothing,
29 },
30};
31use frame_system::EnsureRoot;
32use pallet_collator_selection::StakingPotAccountId;
33use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
34use parachains_common::{
35 xcm_config::{
36 AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains,
37 RelayOrOtherSystemParachains,
38 },
39 TREASURY_PALLET_ID,
40};
41use polkadot_parachain_primitives::primitives::Sibling;
42use polkadot_runtime_common::xcm_sender::ExponentialPrice;
43use sp_runtime::traits::AccountIdConversion;
44use testnet_parachains_constants::westend::{
45 locations::AssetHubLocation, snowbridge::EthereumNetwork,
46};
47use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
48use xcm_builder::{
49 AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
50 AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom,
51 AllowTopLevelPaidExecutionFrom, DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry,
52 DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, ExternalConsensusLocationsConverterFor,
53 FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete,
54 LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
55 SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
56 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
57 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
58 XcmFeeManagerFromComponents,
59};
60use xcm_executor::XcmExecutor;
61
62pub use testnet_parachains_constants::westend::locations::GovernanceLocation;
64
65parameter_types! {
66 pub const RootLocation: Location = Location::here();
67 pub const WestendLocation: Location = Location::parent();
68 pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH);
69 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
70 pub UniversalLocation: InteriorLocation =
71 [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
72 pub const MaxInstructions: u32 = 100;
73 pub const MaxAssetsIntoHolding: u32 = 64;
74 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
75 pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
76}
77
78pub type LocationToAccountId = (
82 ParentIsPreset<AccountId>,
84 SiblingParachainConvertsVia<Sibling, AccountId>,
86 AccountId32Aliases<RelayNetwork, AccountId>,
88 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
90 ExternalConsensusLocationsConverterFor<UniversalLocation, AccountId>,
92);
93
94pub type FungibleTransactor = FungibleAdapter<
96 Balances,
98 IsConcrete<WestendLocation>,
100 LocationToAccountId,
102 AccountId,
104 (),
106>;
107
108pub type XcmOriginToTransactDispatchOrigin = (
112 LocationAsSuperuser<Equals<GovernanceLocation>, RuntimeOrigin>,
114 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
118 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
121 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
124 ParentAsSuperuser<RuntimeOrigin>,
127 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
130 XcmPassthrough<RuntimeOrigin>,
132);
133
134pub struct ParentOrParentsPlurality;
135impl Contains<Location> for ParentOrParentsPlurality {
136 fn contains(location: &Location) -> bool {
137 let result = matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]));
138 tracing::trace!(target: "xcm::contains", ?location, ?result, "ParentOrParentsPlurality matches");
139 result
140 }
141}
142
143pub type Barrier = TrailingSetTopicAsId<
144 DenyThenTry<
145 (
146 DenyRecursively<DenyReserveTransferToRelayChain>,
147 DenyRecursively<
148 DenyExportMessageFrom<
149 EverythingBut<Equals<AssetHubLocation>>,
150 Equals<EthereumNetwork>,
151 >,
152 >,
153 ),
154 (
155 TakeWeightCredit,
157 AllowKnownQueryResponses<PolkadotXcm>,
159 WithComputedOrigin<
160 (
161 AllowTopLevelPaidExecutionFrom<Everything>,
164 AllowExplicitUnpaidExecutionFrom<(
167 ParentOrParentsPlurality,
168 Equals<RelayTreasuryLocation>,
169 Equals<SnowbridgeFrontendLocation>,
170 Equals<GovernanceLocation>,
171 )>,
172 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
174 AllowHrmpNotificationsFromRelayChain,
176 ),
177 UniversalLocation,
178 ConstU32<8>,
179 >,
180 ),
181 >,
182>;
183
184pub type WaivedLocations = (
188 Equals<RootLocation>,
189 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
190 Equals<RelayTreasuryLocation>,
191);
192
193pub type TrustedTeleporters = ConcreteAssetFromSystem<WestendLocation>;
196
197pub type TrustedAliasers = (AliasChildLocation, AuthorizedAliasers<Runtime>);
202
203pub struct XcmConfig;
204impl xcm_executor::Config for XcmConfig {
205 type RuntimeCall = RuntimeCall;
206 type XcmSender = XcmRouter;
207 type XcmEventEmitter = PolkadotXcm;
208 type AssetTransactor = FungibleTransactor;
209 type OriginConverter = XcmOriginToTransactDispatchOrigin;
210 type IsReserve = ();
213 type IsTeleporter = TrustedTeleporters;
214 type UniversalLocation = UniversalLocation;
215 type Barrier = Barrier;
216 type Weigher = WeightInfoBounds<
217 crate::weights::xcm::BridgeHubWestendXcmWeight<RuntimeCall>,
218 RuntimeCall,
219 MaxInstructions,
220 >;
221 type Trader = UsingComponents<
222 WeightToFee,
223 WestendLocation,
224 AccountId,
225 Balances,
226 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
227 >;
228 type ResponseHandler = PolkadotXcm;
229 type AssetTrap = PolkadotXcm;
230 type AssetLocker = ();
231 type AssetExchanger = ();
232 type AssetClaims = PolkadotXcm;
233 type SubscriptionService = PolkadotXcm;
234 type PalletInstancesInfo = AllPalletsWithSystem;
235 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
236 type FeeManager = XcmFeeManagerFromComponents<
237 WaivedLocations,
238 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
239 >;
240 type MessageExporter = (
241 XcmOverBridgeHubRococo,
242 crate::bridge_to_ethereum_config::SnowbridgeExporterV2,
243 crate::bridge_to_ethereum_config::SnowbridgeExporter,
244 );
245 type UniversalAliases = Nothing;
246 type CallDispatcher = RuntimeCall;
247 type SafeCallFilter = Everything;
248 type Aliasers = TrustedAliasers;
249 type TransactionalProcessor = FrameTransactionalProcessor;
250 type HrmpNewChannelOpenRequestHandler = ();
251 type HrmpChannelAcceptedHandler = ();
252 type HrmpChannelClosingHandler = ();
253 type XcmRecorder = PolkadotXcm;
254}
255
256pub type PriceForParentDelivery =
257 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
258
259pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
262
263pub type XcmRouter = WithUniqueTopic<(
266 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
268 XcmpQueue,
270)>;
271
272parameter_types! {
273 pub const DepositPerItem: Balance = crate::deposit(1, 0);
274 pub const DepositPerByte: Balance = crate::deposit(0, 1);
275 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
276}
277
278impl pallet_xcm::Config for Runtime {
279 type RuntimeEvent = RuntimeEvent;
280 type XcmRouter = XcmRouter;
281 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
283 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
285 type XcmExecuteFilter = Everything;
286 type XcmExecutor = XcmExecutor<XcmConfig>;
287 type XcmTeleportFilter = Everything;
288 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
290 crate::weights::xcm::BridgeHubWestendXcmWeight<RuntimeCall>,
291 RuntimeCall,
292 MaxInstructions,
293 >;
294 type UniversalLocation = UniversalLocation;
295 type RuntimeOrigin = RuntimeOrigin;
296 type RuntimeCall = RuntimeCall;
297 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
298 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
299 type Currency = Balances;
300 type CurrencyMatcher = ();
301 type TrustedLockers = ();
302 type SovereignAccountOf = LocationToAccountId;
303 type MaxLockers = ConstU32<8>;
304 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
305 type AdminOrigin = EnsureRoot<AccountId>;
306 type MaxRemoteLockConsumers = ConstU32<0>;
307 type RemoteLockConsumerIdentifier = ();
308 type AuthorizedAliasConsideration = HoldConsideration<
310 AccountId,
311 Balances,
312 AuthorizeAliasHoldReason,
313 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
314 >;
315}
316
317impl cumulus_pallet_xcm::Config for Runtime {
318 type RuntimeEvent = RuntimeEvent;
319 type XcmExecutor = XcmExecutor<XcmConfig>;
320}