1use super::{
20 parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, Fellows, ParaId, Runtime,
21 RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasurer, Treasury, WeightToFee,
22 XcmPallet,
23};
24
25use crate::governance::StakingAdmin;
26
27use frame_support::{
28 parameter_types,
29 traits::{Contains, Disabled, Equals, Everything, Nothing},
30 weights::Weight,
31};
32use frame_system::EnsureRoot;
33use polkadot_runtime_common::{
34 xcm_sender::{ChildParachainRouter, ExponentialPrice},
35 ToAuthor,
36};
37use rococo_runtime_constants::{currency::CENTS, system_parachain::*};
38use sp_core::ConstU32;
39use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH};
40use xcm_builder::{
41 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
42 AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
43 ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FixedWeightBounds,
44 FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
45 IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount,
46 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
47 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
48 XcmFeeManagerFromComponents,
49};
50use xcm_executor::XcmExecutor;
51
52parameter_types! {
53 pub TokenLocation: Location = Here.into_location();
54 pub RootLocation: Location = Location::here();
55 pub const ThisNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
56 pub UniversalLocation: InteriorLocation = ThisNetwork::get().into();
57 pub CheckAccount: AccountId = XcmPallet::check_account();
58 pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
59 pub TreasuryAccount: AccountId = Treasury::account_id();
60}
61
62pub type LocationConverter = (
63 ChildParachainConvertsVia<ParaId, AccountId>,
65 AccountId32Aliases<ThisNetwork, AccountId>,
67 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
69);
70
71pub type LocalAssetTransactor = FungibleAdapter<
76 Balances,
78 IsConcrete<TokenLocation>,
80 LocationConverter,
82 AccountId,
84 LocalCheckAccount,
86>;
87
88type LocalOriginConverter = (
90 SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
92 ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
94 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
96);
97
98parameter_types! {
99 pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
101 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
103 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
105}
106
107pub type PriceForChildParachainDelivery =
108 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
109
110pub type XcmRouter = WithUniqueTopic<
113 ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
115>;
116
117parameter_types! {
118 pub Roc: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
119 pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
120 pub Contracts: Location = Parachain(CONTRACTS_ID).into_location();
121 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
122 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
123 pub People: Location = Parachain(PEOPLE_ID).into_location();
124 pub Broker: Location = Parachain(BROKER_ID).into_location();
125 pub Tick: Location = Parachain(100).into_location();
126 pub Trick: Location = Parachain(110).into_location();
127 pub Track: Location = Parachain(120).into_location();
128 pub RocForTick: (AssetFilter, Location) = (Roc::get(), Tick::get());
129 pub RocForTrick: (AssetFilter, Location) = (Roc::get(), Trick::get());
130 pub RocForTrack: (AssetFilter, Location) = (Roc::get(), Track::get());
131 pub RocForAssetHub: (AssetFilter, Location) = (Roc::get(), AssetHub::get());
132 pub RocForContracts: (AssetFilter, Location) = (Roc::get(), Contracts::get());
133 pub RocForEncointer: (AssetFilter, Location) = (Roc::get(), Encointer::get());
134 pub RocForBridgeHub: (AssetFilter, Location) = (Roc::get(), BridgeHub::get());
135 pub RocForPeople: (AssetFilter, Location) = (Roc::get(), People::get());
136 pub RocForBroker: (AssetFilter, Location) = (Roc::get(), Broker::get());
137 pub const MaxInstructions: u32 = 100;
138 pub const MaxAssetsIntoHolding: u32 = 64;
139}
140pub type TrustedTeleporters = (
141 xcm_builder::Case<RocForTick>,
142 xcm_builder::Case<RocForTrick>,
143 xcm_builder::Case<RocForTrack>,
144 xcm_builder::Case<RocForAssetHub>,
145 xcm_builder::Case<RocForContracts>,
146 xcm_builder::Case<RocForEncointer>,
147 xcm_builder::Case<RocForBridgeHub>,
148 xcm_builder::Case<RocForPeople>,
149 xcm_builder::Case<RocForBroker>,
150);
151
152pub struct OnlyParachains;
153impl Contains<Location> for OnlyParachains {
154 fn contains(loc: &Location) -> bool {
155 matches!(loc.unpack(), (0, [Parachain(_)]))
156 }
157}
158
159pub struct LocalPlurality;
160impl Contains<Location> for LocalPlurality {
161 fn contains(loc: &Location) -> bool {
162 matches!(loc.unpack(), (0, [Plurality { .. }]))
163 }
164}
165
166pub type Barrier = TrailingSetTopicAsId<(
168 TakeWeightCredit,
170 AllowKnownQueryResponses<XcmPallet>,
172 WithComputedOrigin<
173 (
174 AllowTopLevelPaidExecutionFrom<Everything>,
176 AllowExplicitUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
178 AllowSubscriptionsFrom<OnlyParachains>,
180 ),
181 UniversalLocation,
182 ConstU32<8>,
183 >,
184)>;
185
186pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
189
190pub struct XcmConfig;
191impl xcm_executor::Config for XcmConfig {
192 type RuntimeCall = RuntimeCall;
193 type XcmSender = XcmRouter;
194 type XcmEventEmitter = XcmPallet;
195 type AssetTransactor = LocalAssetTransactor;
196 type OriginConverter = LocalOriginConverter;
197 type IsReserve = ();
198 type IsTeleporter = TrustedTeleporters;
199 type UniversalLocation = UniversalLocation;
200 type Barrier = Barrier;
201 type Weigher = WeightInfoBounds<
202 crate::weights::xcm::RococoXcmWeight<RuntimeCall>,
203 RuntimeCall,
204 MaxInstructions,
205 >;
206 type Trader =
207 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
208 type ResponseHandler = XcmPallet;
209 type AssetTrap = XcmPallet;
210 type AssetLocker = ();
211 type AssetExchanger = ();
212 type AssetClaims = XcmPallet;
213 type SubscriptionService = XcmPallet;
214 type PalletInstancesInfo = AllPalletsWithSystem;
215 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
216 type FeeManager = XcmFeeManagerFromComponents<
217 WaivedLocations,
218 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
219 >;
220 type MessageExporter = ();
221 type UniversalAliases = Nothing;
222 type CallDispatcher = RuntimeCall;
223 type SafeCallFilter = Everything;
224 type Aliasers = Nothing;
225 type TransactionalProcessor = FrameTransactionalProcessor;
226 type HrmpNewChannelOpenRequestHandler = ();
227 type HrmpChannelAcceptedHandler = ();
228 type HrmpChannelClosingHandler = ();
229 type XcmRecorder = XcmPallet;
230}
231
232parameter_types! {
233 pub const CollectiveBodyId: BodyId = BodyId::Unit;
235 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
237 pub const FellowsBodyId: BodyId = BodyId::Technical;
239 pub const TreasuryBodyId: BodyId = BodyId::Treasury;
241}
242
243pub type LocalOriginToLocation = (
246 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
248);
249
250pub type StakingAdminToPlurality =
252 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
253
254pub type FellowsToPlurality = OriginToPluralityVoice<RuntimeOrigin, Fellows, FellowsBodyId>;
256
257pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasuryBodyId>;
259
260pub type LocalPalletOriginToLocation = (
263 StakingAdminToPlurality,
265 FellowsToPlurality,
267 TreasurerToPlurality,
269);
270
271impl pallet_xcm::Config for Runtime {
272 type RuntimeEvent = RuntimeEvent;
273 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<
276 RuntimeOrigin,
277 (LocalPalletOriginToLocation, LocalOriginToLocation),
278 >;
279 type XcmRouter = XcmRouter;
280 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
282 type XcmExecuteFilter = Everything;
283 type XcmExecutor = XcmExecutor<XcmConfig>;
284 type XcmTeleportFilter = Everything;
285 type XcmReserveTransferFilter = Everything;
288 type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
289 type UniversalLocation = UniversalLocation;
290 type RuntimeOrigin = RuntimeOrigin;
291 type RuntimeCall = RuntimeCall;
292 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
293 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
294 type Currency = Balances;
295 type CurrencyMatcher = IsConcrete<TokenLocation>;
296 type TrustedLockers = ();
297 type SovereignAccountOf = LocationConverter;
298 type MaxLockers = ConstU32<8>;
299 type MaxRemoteLockConsumers = ConstU32<0>;
300 type RemoteLockConsumerIdentifier = ();
301 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
302 type AdminOrigin = EnsureRoot<AccountId>;
303 type AuthorizedAliasConsideration = Disabled;
305}