contracts_parachain_runtime/
xcm_config.rs1use super::{
2 AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
3 Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
4};
5use frame_support::{
6 parameter_types,
7 traits::{ConstU32, Contains, Everything, Nothing},
8 weights::Weight,
9};
10use frame_system::EnsureRoot;
11use pallet_xcm::XcmPassthrough;
12use polkadot_runtime_common::impls::ToAuthor;
13use xcm::latest::prelude::*;
14#[allow(deprecated)]
15use xcm_builder::CurrencyAdapter;
16use xcm_builder::{
17 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
18 DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
19 FrameTransactionalProcessor, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative,
20 SiblingParachainAsNative, SignedAccountId32AsNative, SignedToAccountId32,
21 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
22 WithComputedOrigin, WithUniqueTopic,
23};
24use xcm_executor::XcmExecutor;
25
26parameter_types! {
27 pub const TokenLocation: Location = Here.into_location();
28 pub const RelayLocation: Location = Location::parent();
29 pub const RelayNetwork: Option<NetworkId> = None;
30 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
31 pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
32}
33
34pub type LocationToAccountId = (
38 AccountId32Aliases<RelayNetwork, AccountId>,
40 ParentIsPreset<AccountId>,
42);
43
44#[allow(deprecated)]
46pub type LocalAssetTransactor = CurrencyAdapter<
47 Balances,
49 IsConcrete<RelayLocation>,
51 LocationToAccountId,
53 AccountId,
55 (),
57>;
58
59#[allow(deprecated)]
60pub type LocalBalancesTransactor =
61 CurrencyAdapter<Balances, IsConcrete<TokenLocation>, LocationToAccountId, AccountId, ()>;
62
63pub type AssetTransactors = (LocalBalancesTransactor, LocalAssetTransactor);
64
65pub type XcmOriginToTransactDispatchOrigin = (
69 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
73 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
76 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
79 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
82 XcmPassthrough<RuntimeOrigin>,
84);
85
86parameter_types! {
87 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
89 pub const MaxInstructions: u32 = 100;
90 pub const MaxAssetsIntoHolding: u32 = 64;
91}
92
93pub struct ParentOrParentsPlurality;
94impl Contains<Location> for ParentOrParentsPlurality {
95 fn contains(location: &Location) -> bool {
96 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
97 }
98}
99
100pub type Barrier = TrailingSetTopicAsId<
101 DenyThenTry<
102 DenyReserveTransferToRelayChain,
103 (
104 TakeWeightCredit,
105 WithComputedOrigin<
106 (
107 AllowTopLevelPaidExecutionFrom<Everything>,
108 AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
109 ),
111 UniversalLocation,
112 ConstU32<8>,
113 >,
114 ),
115 >,
116>;
117
118pub struct XcmConfig;
119impl xcm_executor::Config for XcmConfig {
120 type RuntimeCall = RuntimeCall;
121 type XcmSender = XcmRouter;
122 type AssetTransactor = AssetTransactors;
123 type OriginConverter = XcmOriginToTransactDispatchOrigin;
124 type IsReserve = NativeAsset;
125 type IsTeleporter = (); type UniversalLocation = UniversalLocation;
127 type Barrier = Barrier;
128 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
129 type Trader =
130 UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
131 type ResponseHandler = PolkadotXcm;
132 type AssetTrap = PolkadotXcm;
133 type AssetClaims = PolkadotXcm;
134 type SubscriptionService = PolkadotXcm;
135 type PalletInstancesInfo = AllPalletsWithSystem;
136 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
137 type AssetLocker = ();
138 type AssetExchanger = ();
139 type FeeManager = ();
140 type MessageExporter = ();
141 type UniversalAliases = Nothing;
142 type CallDispatcher = RuntimeCall;
143 type SafeCallFilter = Everything;
144 type Aliasers = Nothing;
145 type TransactionalProcessor = FrameTransactionalProcessor;
146 type HrmpNewChannelOpenRequestHandler = ();
147 type HrmpChannelAcceptedHandler = ();
148 type HrmpChannelClosingHandler = ();
149 type XcmRecorder = PolkadotXcm;
150}
151
152pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
154
155pub type XcmRouter = WithUniqueTopic<(
158 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
160 XcmpQueue,
162)>;
163
164#[cfg(feature = "runtime-benchmarks")]
165parameter_types! {
166 pub ReachableDest: Option<Location> = Some(Parent.into());
167}
168
169impl pallet_xcm::Config for Runtime {
170 type RuntimeEvent = RuntimeEvent;
171 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
172 type XcmRouter = XcmRouter;
173 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
174 type XcmExecuteFilter = Everything;
175 type XcmExecutor = XcmExecutor<XcmConfig>;
176 type XcmTeleportFilter = Everything;
177 type XcmReserveTransferFilter = Nothing;
178 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
179 type UniversalLocation = UniversalLocation;
180 type RuntimeOrigin = RuntimeOrigin;
181 type RuntimeCall = RuntimeCall;
182
183 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
184 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
186 type Currency = Balances;
187 type CurrencyMatcher = ();
188 type TrustedLockers = ();
189 type SovereignAccountOf = LocationToAccountId;
190 type MaxLockers = ConstU32<8>;
191 type WeightInfo = pallet_xcm::TestWeightInfo;
192 type AdminOrigin = EnsureRoot<AccountId>;
193 type MaxRemoteLockConsumers = ConstU32<0>;
194 type RemoteLockConsumerIdentifier = ();
195}
196
197impl cumulus_pallet_xcm::Config for Runtime {
198 type RuntimeEvent = RuntimeEvent;
199 type XcmExecutor = XcmExecutor<XcmConfig>;
200}