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 AssetsInHolding, 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 SubscriptionService = PolkadotXcm;
222 type PalletInstancesInfo = AllPalletsWithSystem;
223 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
224 type FeeManager = XcmFeeManagerFromComponents<
225 WaivedLocations,
226 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
227 >;
228 type MessageExporter = (
229 XcmOverBridgeHubWestend,
230 XcmOverRococoBulletin,
231 crate::bridge_to_ethereum_config::SnowbridgeExporter,
232 );
233 type UniversalAliases = Nothing;
234 type CallDispatcher = RuntimeCall;
235 type SafeCallFilter = Everything;
236 type Aliasers = TrustedAliasers;
237 type TransactionalProcessor = FrameTransactionalProcessor;
238 type HrmpNewChannelOpenRequestHandler = ();
239 type HrmpChannelAcceptedHandler = ();
240 type HrmpChannelClosingHandler = ();
241 type XcmRecorder = PolkadotXcm;
242}
243
244pub type PriceForParentDelivery =
245 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
246
247pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
250
251pub type XcmRouter = WithUniqueTopic<(
254 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
256 XcmpQueue,
258)>;
259
260parameter_types! {
261 pub const DepositPerItem: Balance = crate::deposit(1, 0);
262 pub const DepositPerByte: Balance = crate::deposit(0, 1);
263 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
264}
265
266impl pallet_xcm::Config for Runtime {
267 type RuntimeEvent = RuntimeEvent;
268 type XcmRouter = XcmRouter;
269 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
271 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
273 type XcmExecuteFilter = Everything;
274 type XcmExecutor = XcmExecutor<XcmConfig>;
275 type XcmTeleportFilter = Everything;
276 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
278 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
279 RuntimeCall,
280 MaxInstructions,
281 >;
282 type UniversalLocation = UniversalLocation;
283 type RuntimeOrigin = RuntimeOrigin;
284 type RuntimeCall = RuntimeCall;
285 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
286 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
287 type Currency = Balances;
288 type CurrencyMatcher = ();
289 type TrustedLockers = ();
290 type SovereignAccountOf = LocationToAccountId;
291 type MaxLockers = ConstU32<8>;
292 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
293 type AdminOrigin = EnsureRoot<AccountId>;
294 type MaxRemoteLockConsumers = ConstU32<0>;
295 type RemoteLockConsumerIdentifier = ();
296 type AuthorizedAliasConsideration = HoldConsideration<
298 AccountId,
299 Balances,
300 AuthorizeAliasHoldReason,
301 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
302 >;
303}
304
305impl cumulus_pallet_xcm::Config for Runtime {
306 type RuntimeEvent = RuntimeEvent;
307 type XcmExecutor = XcmExecutor<XcmConfig>;
308}
309
310pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
311 PhantomData<(WaivedLocations, HandleFee)>,
312);
313impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
314 for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
315{
316 fn is_waived(origin: Option<&Location>, fee_reason: FeeReason) -> bool {
317 let Some(loc) = origin else { return false };
318 if let Export { network, destination: Here } = fee_reason {
319 if network == EthereumNetwork::get().into() {
320 return false;
321 }
322 }
323 WaivedLocations::contains(loc)
324 }
325
326 fn handle_fee(fee: AssetsInHolding, context: Option<&XcmContext>, reason: FeeReason) {
327 FeeHandler::handle_fee(fee, context, reason);
328 }
329}