1use super::{
18 AccountId, AllPalletsWithSystem, Balance, Balances, BaseDeliveryFee, FeeAssetId, ParachainInfo,
19 ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason,
20 RuntimeOrigin, TransactionByteFee, WeightToFee, XcmOverBridgeHubWestend, XcmOverRococoBulletin,
21 XcmpQueue,
22};
23
24use core::marker::PhantomData;
25use frame_support::{
26 parameter_types,
27 traits::{
28 fungible::HoldConsideration, tokens::imbalance::ResolveTo, ConstU32, Contains, Equals,
29 Everything, LinearStoragePrice, Nothing,
30 },
31};
32use frame_system::EnsureRoot;
33use pallet_collator_selection::StakingPotAccountId;
34use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
35use parachains_common::{
36 xcm_config::{
37 AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains,
38 RelayOrOtherSystemParachains,
39 },
40 TREASURY_PALLET_ID,
41};
42use polkadot_parachain_primitives::primitives::Sibling;
43use polkadot_runtime_common::xcm_sender::ExponentialPrice;
44use sp_runtime::traits::AccountIdConversion;
45use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;
46use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH};
47use xcm_builder::{
48 AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
49 AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom,
50 AllowTopLevelPaidExecutionFrom, DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry,
51 DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, ExternalConsensusLocationsConverterFor,
52 FrameTransactionalProcessor, FungibleAdapter, HandleFee, HashedDescription, IsConcrete,
53 ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
54 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
55 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
56 UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
57 XcmFeeManagerFromComponents,
58};
59use xcm_executor::{
60 traits::{FeeManager, FeeReason, FeeReason::Export},
61 XcmExecutor,
62};
63
64parameter_types! {
65 pub const RootLocation: Location = Location::here();
66 pub const TokenLocation: Location = Location::parent();
67 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
68 pub RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
69 pub UniversalLocation: InteriorLocation =
70 [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
71 pub const MaxInstructions: u32 = 100;
72 pub const MaxAssetsIntoHolding: u32 = 64;
73 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
74 pub RelayTreasuryLocation: Location = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
75 pub SiblingPeople: Location = (Parent, Parachain(rococo_runtime_constants::system_parachain::PEOPLE_ID)).into();
76 pub AssetHubRococoLocation: Location = Location::new(1, [Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)]);
77}
78
79pub type LocationToAccountId = (
83 ParentIsPreset<AccountId>,
85 SiblingParachainConvertsVia<Sibling, AccountId>,
87 AccountId32Aliases<RelayNetwork, AccountId>,
89 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
91 ExternalConsensusLocationsConverterFor<UniversalLocation, AccountId>,
93);
94
95pub type FungibleTransactor = FungibleAdapter<
97 Balances,
99 IsConcrete<TokenLocation>,
101 LocationToAccountId,
103 AccountId,
105 (),
107>;
108
109pub type XcmOriginToTransactDispatchOrigin = (
113 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
117 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
120 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
123 ParentAsSuperuser<RuntimeOrigin>,
126 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
129 XcmPassthrough<RuntimeOrigin>,
131);
132
133pub struct ParentOrParentsPlurality;
134impl Contains<Location> for ParentOrParentsPlurality {
135 fn contains(location: &Location) -> bool {
136 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
137 }
138}
139
140pub type Barrier = TrailingSetTopicAsId<
141 DenyThenTry<
142 DenyRecursively<DenyReserveTransferToRelayChain>,
143 (
144 TakeWeightCredit,
146 AllowKnownQueryResponses<PolkadotXcm>,
148 WithComputedOrigin<
149 (
150 AllowTopLevelPaidExecutionFrom<Everything>,
153 AllowExplicitUnpaidExecutionFrom<(
156 ParentOrParentsPlurality,
157 Equals<RelayTreasuryLocation>,
158 Equals<SiblingPeople>,
159 Equals<AssetHubRococoLocation>,
160 )>,
161 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
163 AllowHrmpNotificationsFromRelayChain,
165 ),
166 UniversalLocation,
167 ConstU32<8>,
168 >,
169 ),
170 >,
171>;
172
173pub type WaivedLocations = (
177 Equals<RootLocation>,
178 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
179 Equals<RelayTreasuryLocation>,
180);
181
182pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenLocation>;
185
186pub type TrustedAliasers = (AliasChildLocation, AuthorizedAliasers<Runtime>);
191
192pub struct XcmConfig;
193impl xcm_executor::Config for XcmConfig {
194 type RuntimeCall = RuntimeCall;
195 type XcmSender = XcmRouter;
196 type XcmEventEmitter = PolkadotXcm;
197 type AssetTransactor = FungibleTransactor;
198 type OriginConverter = XcmOriginToTransactDispatchOrigin;
199 type IsReserve = ();
202 type IsTeleporter = TrustedTeleporters;
203 type UniversalLocation = UniversalLocation;
204 type Barrier = Barrier;
205 type Weigher = WeightInfoBounds<
206 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
207 RuntimeCall,
208 MaxInstructions,
209 >;
210 type Trader = UsingComponents<
211 WeightToFee,
212 TokenLocation,
213 AccountId,
214 Balances,
215 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
216 >;
217 type ResponseHandler = PolkadotXcm;
218 type AssetTrap = PolkadotXcm;
219 type AssetLocker = ();
220 type AssetExchanger = ();
221 type AssetClaims = PolkadotXcm;
222 type SubscriptionService = PolkadotXcm;
223 type PalletInstancesInfo = AllPalletsWithSystem;
224 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
225 type FeeManager = XcmFeeManagerFromComponents<
226 WaivedLocations,
227 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
228 >;
229 type MessageExporter = (
230 XcmOverBridgeHubWestend,
231 XcmOverRococoBulletin,
232 crate::bridge_to_ethereum_config::SnowbridgeExporter,
233 );
234 type UniversalAliases = Nothing;
235 type CallDispatcher = RuntimeCall;
236 type SafeCallFilter = Everything;
237 type Aliasers = TrustedAliasers;
238 type TransactionalProcessor = FrameTransactionalProcessor;
239 type HrmpNewChannelOpenRequestHandler = ();
240 type HrmpChannelAcceptedHandler = ();
241 type HrmpChannelClosingHandler = ();
242 type XcmRecorder = PolkadotXcm;
243}
244
245pub type PriceForParentDelivery =
246 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
247
248pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
251
252pub type XcmRouter = WithUniqueTopic<(
255 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
257 XcmpQueue,
259)>;
260
261parameter_types! {
262 pub const DepositPerItem: Balance = crate::deposit(1, 0);
263 pub const DepositPerByte: Balance = crate::deposit(0, 1);
264 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
265}
266
267impl pallet_xcm::Config for Runtime {
268 type RuntimeEvent = RuntimeEvent;
269 type XcmRouter = XcmRouter;
270 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
272 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
274 type XcmExecuteFilter = Everything;
275 type XcmExecutor = XcmExecutor<XcmConfig>;
276 type XcmTeleportFilter = Everything;
277 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
279 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
280 RuntimeCall,
281 MaxInstructions,
282 >;
283 type UniversalLocation = UniversalLocation;
284 type RuntimeOrigin = RuntimeOrigin;
285 type RuntimeCall = RuntimeCall;
286 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
287 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
288 type Currency = Balances;
289 type CurrencyMatcher = ();
290 type TrustedLockers = ();
291 type SovereignAccountOf = LocationToAccountId;
292 type MaxLockers = ConstU32<8>;
293 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
294 type AdminOrigin = EnsureRoot<AccountId>;
295 type MaxRemoteLockConsumers = ConstU32<0>;
296 type RemoteLockConsumerIdentifier = ();
297 type AuthorizedAliasConsideration = HoldConsideration<
299 AccountId,
300 Balances,
301 AuthorizeAliasHoldReason,
302 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
303 >;
304}
305
306impl cumulus_pallet_xcm::Config for Runtime {
307 type RuntimeEvent = RuntimeEvent;
308 type XcmExecutor = XcmExecutor<XcmConfig>;
309}
310
311pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
312 PhantomData<(WaivedLocations, HandleFee)>,
313);
314impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
315 for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
316{
317 fn is_waived(origin: Option<&Location>, fee_reason: FeeReason) -> bool {
318 let Some(loc) = origin else { return false };
319 if let Export { network, destination: Here } = fee_reason {
320 if network == EthereumNetwork::get().into() {
321 return false
322 }
323 }
324 WaivedLocations::contains(loc)
325 }
326
327 fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
328 FeeHandler::handle_fee(fee, context, reason);
329 }
330}