bridge_hub_rococo_runtime/
xcm_config.rs1use super::{
18 AccountId, AllPalletsWithSystem, Balances, BaseDeliveryFee, FeeAssetId, ParachainInfo,
19 ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
20 TransactionByteFee, WeightToFee, XcmOverBridgeHubWestend, XcmOverRococoBulletin, XcmpQueue,
21};
22
23use core::marker::PhantomData;
24use frame_support::{
25 parameter_types,
26 traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing},
27};
28use frame_system::EnsureRoot;
29use pallet_collator_selection::StakingPotAccountId;
30use pallet_xcm::XcmPassthrough;
31use parachains_common::{
32 xcm_config::{
33 AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains,
34 RelayOrOtherSystemParachains,
35 },
36 TREASURY_PALLET_ID,
37};
38use polkadot_parachain_primitives::primitives::Sibling;
39use polkadot_runtime_common::xcm_sender::ExponentialPrice;
40use snowbridge_runtime_common::XcmExportFeeToSibling;
41use sp_runtime::traits::AccountIdConversion;
42use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;
43use xcm::latest::prelude::*;
44use xcm_builder::{
45 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
46 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
47 DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FrameTransactionalProcessor,
48 FungibleAdapter, HandleFee, IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
49 SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
50 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
51 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
52};
53use xcm_executor::{
54 traits::{FeeManager, FeeReason, FeeReason::Export},
55 XcmExecutor,
56};
57
58parameter_types! {
59 pub const TokenLocation: Location = Location::parent();
60 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
61 pub RelayNetwork: NetworkId = NetworkId::Rococo;
62 pub UniversalLocation: InteriorLocation =
63 [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
64 pub const MaxInstructions: u32 = 100;
65 pub const MaxAssetsIntoHolding: u32 = 64;
66 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
67 pub RelayTreasuryLocation: Location = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
68 pub SiblingPeople: Location = (Parent, Parachain(rococo_runtime_constants::system_parachain::PEOPLE_ID)).into();
69}
70
71pub type LocationToAccountId = (
75 ParentIsPreset<AccountId>,
77 SiblingParachainConvertsVia<Sibling, AccountId>,
79 AccountId32Aliases<RelayNetwork, AccountId>,
81);
82
83pub type FungibleTransactor = FungibleAdapter<
85 Balances,
87 IsConcrete<TokenLocation>,
89 LocationToAccountId,
91 AccountId,
93 (),
95>;
96
97pub type XcmOriginToTransactDispatchOrigin = (
101 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
105 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
108 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
111 ParentAsSuperuser<RuntimeOrigin>,
114 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
117 XcmPassthrough<RuntimeOrigin>,
119);
120
121pub struct ParentOrParentsPlurality;
122impl Contains<Location> for ParentOrParentsPlurality {
123 fn contains(location: &Location) -> bool {
124 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
125 }
126}
127
128pub type Barrier = TrailingSetTopicAsId<
129 DenyThenTry<
130 DenyReserveTransferToRelayChain,
131 (
132 TakeWeightCredit,
134 AllowKnownQueryResponses<PolkadotXcm>,
136 WithComputedOrigin<
137 (
138 AllowTopLevelPaidExecutionFrom<Everything>,
141 AllowExplicitUnpaidExecutionFrom<(
144 ParentOrParentsPlurality,
145 Equals<RelayTreasuryLocation>,
146 Equals<SiblingPeople>,
147 )>,
148 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
150 AllowHrmpNotificationsFromRelayChain,
152 ),
153 UniversalLocation,
154 ConstU32<8>,
155 >,
156 ),
157 >,
158>;
159
160pub type WaivedLocations = (
164 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
165 Equals<RelayTreasuryLocation>,
166);
167
168pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenLocation>;
171
172pub struct XcmConfig;
173impl xcm_executor::Config for XcmConfig {
174 type RuntimeCall = RuntimeCall;
175 type XcmSender = XcmRouter;
176 type AssetTransactor = FungibleTransactor;
177 type OriginConverter = XcmOriginToTransactDispatchOrigin;
178 type IsReserve = ();
181 type IsTeleporter = TrustedTeleporters;
182 type UniversalLocation = UniversalLocation;
183 type Barrier = Barrier;
184 type Weigher = WeightInfoBounds<
185 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
186 RuntimeCall,
187 MaxInstructions,
188 >;
189 type Trader = UsingComponents<
190 WeightToFee,
191 TokenLocation,
192 AccountId,
193 Balances,
194 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
195 >;
196 type ResponseHandler = PolkadotXcm;
197 type AssetTrap = PolkadotXcm;
198 type AssetLocker = ();
199 type AssetExchanger = ();
200 type AssetClaims = PolkadotXcm;
201 type SubscriptionService = PolkadotXcm;
202 type PalletInstancesInfo = AllPalletsWithSystem;
203 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
204 type FeeManager = XcmFeeManagerFromComponentsBridgeHub<
205 WaivedLocations,
206 (
207 XcmExportFeeToSibling<
208 bp_rococo::Balance,
209 AccountId,
210 TokenLocation,
211 EthereumNetwork,
212 Self::AssetTransactor,
213 crate::EthereumOutboundQueue,
214 >,
215 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
216 ),
217 >;
218 type MessageExporter = (
219 XcmOverBridgeHubWestend,
220 XcmOverRococoBulletin,
221 crate::bridge_to_ethereum_config::SnowbridgeExporter,
222 );
223 type UniversalAliases = Nothing;
224 type CallDispatcher = RuntimeCall;
225 type SafeCallFilter = Everything;
226 type Aliasers = Nothing;
227 type TransactionalProcessor = FrameTransactionalProcessor;
228 type HrmpNewChannelOpenRequestHandler = ();
229 type HrmpChannelAcceptedHandler = ();
230 type HrmpChannelClosingHandler = ();
231 type XcmRecorder = PolkadotXcm;
232}
233
234pub type PriceForParentDelivery =
235 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
236
237pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
240
241pub type XcmRouter = WithUniqueTopic<(
244 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
246 XcmpQueue,
248)>;
249
250impl pallet_xcm::Config for Runtime {
251 type RuntimeEvent = RuntimeEvent;
252 type XcmRouter = XcmRouter;
253 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
255 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
257 type XcmExecuteFilter = Everything;
258 type XcmExecutor = XcmExecutor<XcmConfig>;
259 type XcmTeleportFilter = Everything;
260 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
262 crate::weights::xcm::BridgeHubRococoXcmWeight<RuntimeCall>,
263 RuntimeCall,
264 MaxInstructions,
265 >;
266 type UniversalLocation = UniversalLocation;
267 type RuntimeOrigin = RuntimeOrigin;
268 type RuntimeCall = RuntimeCall;
269 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
270 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
271 type Currency = Balances;
272 type CurrencyMatcher = ();
273 type TrustedLockers = ();
274 type SovereignAccountOf = LocationToAccountId;
275 type MaxLockers = ConstU32<8>;
276 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
277 type AdminOrigin = EnsureRoot<AccountId>;
278 type MaxRemoteLockConsumers = ConstU32<0>;
279 type RemoteLockConsumerIdentifier = ();
280}
281
282impl cumulus_pallet_xcm::Config for Runtime {
283 type RuntimeEvent = RuntimeEvent;
284 type XcmExecutor = XcmExecutor<XcmConfig>;
285}
286
287pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
288 PhantomData<(WaivedLocations, HandleFee)>,
289);
290impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
291 for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
292{
293 fn is_waived(origin: Option<&Location>, fee_reason: FeeReason) -> bool {
294 let Some(loc) = origin else { return false };
295 if let Export { network, destination: Here } = fee_reason {
296 if network == EthereumNetwork::get() {
297 return false
298 }
299 }
300 WaivedLocations::contains(loc)
301 }
302
303 fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
304 FeeHandler::handle_fee(fee, context, reason);
305 }
306}