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 snowbridge_runtime_common::XcmExportFeeToSibling;
45use sp_runtime::traits::AccountIdConversion;
46use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;
47use xcm::latest::{prelude::*, ROCOCO_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, HandleFee, HashedDescription, IsConcrete,
54 ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
55 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
56 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
57 UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
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}
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<TokenLocation>,
100 LocationToAccountId,
102 AccountId,
104 (),
106>;
107
108pub type XcmOriginToTransactDispatchOrigin = (
112 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
116 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
119 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
122 ParentAsSuperuser<RuntimeOrigin>,
125 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
128 XcmPassthrough<RuntimeOrigin>,
130);
131
132pub struct ParentOrParentsPlurality;
133impl Contains<Location> for ParentOrParentsPlurality {
134 fn contains(location: &Location) -> bool {
135 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
136 }
137}
138
139pub type Barrier = TrailingSetTopicAsId<
140 DenyThenTry<
141 DenyRecursively<DenyReserveTransferToRelayChain>,
142 (
143 TakeWeightCredit,
145 AllowKnownQueryResponses<PolkadotXcm>,
147 WithComputedOrigin<
148 (
149 AllowTopLevelPaidExecutionFrom<Everything>,
152 AllowExplicitUnpaidExecutionFrom<(
155 ParentOrParentsPlurality,
156 Equals<RelayTreasuryLocation>,
157 Equals<SiblingPeople>,
158 )>,
159 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
161 AllowHrmpNotificationsFromRelayChain,
163 ),
164 UniversalLocation,
165 ConstU32<8>,
166 >,
167 ),
168 >,
169>;
170
171pub type WaivedLocations = (
175 Equals<RootLocation>,
176 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
177 Equals<RelayTreasuryLocation>,
178);
179
180pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenLocation>;
183
184pub type TrustedAliasers = (AliasChildLocation, AuthorizedAliasers<Runtime>);
189
190pub struct XcmConfig;
191impl xcm_executor::Config for XcmConfig {
192 type RuntimeCall = RuntimeCall;
193 type XcmSender = XcmRouter;
194 type XcmEventEmitter = PolkadotXcm;
195 type AssetTransactor = FungibleTransactor;
196 type OriginConverter = XcmOriginToTransactDispatchOrigin;
197 type IsReserve = ();
200 type IsTeleporter = TrustedTeleporters;
201 type UniversalLocation = UniversalLocation;
202 type Barrier = Barrier;
203 type Weigher = WeightInfoBounds<
204 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
205 RuntimeCall,
206 MaxInstructions,
207 >;
208 type Trader = UsingComponents<
209 WeightToFee,
210 TokenLocation,
211 AccountId,
212 Balances,
213 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
214 >;
215 type ResponseHandler = PolkadotXcm;
216 type AssetTrap = PolkadotXcm;
217 type AssetLocker = ();
218 type AssetExchanger = ();
219 type AssetClaims = PolkadotXcm;
220 type SubscriptionService = PolkadotXcm;
221 type PalletInstancesInfo = AllPalletsWithSystem;
222 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
223 type FeeManager = XcmFeeManagerFromComponentsBridgeHub<
224 WaivedLocations,
225 (
226 XcmExportFeeToSibling<
227 bp_rococo::Balance,
228 AccountId,
229 TokenLocation,
230 EthereumNetwork,
231 Self::AssetTransactor,
232 crate::EthereumOutboundQueue,
233 >,
234 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
235 ),
236 >;
237 type MessageExporter = (
238 XcmOverBridgeHubWestend,
239 XcmOverRococoBulletin,
240 crate::bridge_to_ethereum_config::SnowbridgeExporter,
241 );
242 type UniversalAliases = Nothing;
243 type CallDispatcher = RuntimeCall;
244 type SafeCallFilter = Everything;
245 type Aliasers = TrustedAliasers;
246 type TransactionalProcessor = FrameTransactionalProcessor;
247 type HrmpNewChannelOpenRequestHandler = ();
248 type HrmpChannelAcceptedHandler = ();
249 type HrmpChannelClosingHandler = ();
250 type XcmRecorder = PolkadotXcm;
251}
252
253pub type PriceForParentDelivery =
254 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
255
256pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
259
260pub type XcmRouter = WithUniqueTopic<(
263 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
265 XcmpQueue,
267)>;
268
269parameter_types! {
270 pub const DepositPerItem: Balance = crate::deposit(1, 0);
271 pub const DepositPerByte: Balance = crate::deposit(0, 1);
272 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
273}
274
275impl pallet_xcm::Config for Runtime {
276 type RuntimeEvent = RuntimeEvent;
277 type XcmRouter = XcmRouter;
278 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
280 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
282 type XcmExecuteFilter = Everything;
283 type XcmExecutor = XcmExecutor<XcmConfig>;
284 type XcmTeleportFilter = Everything;
285 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
287 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
288 RuntimeCall,
289 MaxInstructions,
290 >;
291 type UniversalLocation = UniversalLocation;
292 type RuntimeOrigin = RuntimeOrigin;
293 type RuntimeCall = RuntimeCall;
294 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
295 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
296 type Currency = Balances;
297 type CurrencyMatcher = ();
298 type TrustedLockers = ();
299 type SovereignAccountOf = LocationToAccountId;
300 type MaxLockers = ConstU32<8>;
301 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
302 type AdminOrigin = EnsureRoot<AccountId>;
303 type MaxRemoteLockConsumers = ConstU32<0>;
304 type RemoteLockConsumerIdentifier = ();
305 type AuthorizedAliasConsideration = HoldConsideration<
307 AccountId,
308 Balances,
309 AuthorizeAliasHoldReason,
310 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
311 >;
312}
313
314impl cumulus_pallet_xcm::Config for Runtime {
315 type RuntimeEvent = RuntimeEvent;
316 type XcmExecutor = XcmExecutor<XcmConfig>;
317}
318
319pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
320 PhantomData<(WaivedLocations, HandleFee)>,
321);
322impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
323 for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
324{
325 fn is_waived(origin: Option<&Location>, fee_reason: FeeReason) -> bool {
326 let Some(loc) = origin else { return false };
327 if let Export { network, destination: Here } = fee_reason {
328 if network == EthereumNetwork::get().into() {
329 return false
330 }
331 }
332 WaivedLocations::contains(loc)
333 }
334
335 fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
336 FeeHandler::handle_fee(fee, context, reason);
337 }
338}