1use super::moonbase_weights;
21use super::{
22 governance, AccountId, AssetId, Balance, Balances, EmergencyParaXcm, Erc20XcmBridge,
23 EvmForeignAssets, MaintenanceMode, MessageQueue, ParachainInfo, ParachainSystem, Perbill,
24 PolkadotXcm, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury,
25 XcmpQueue,
26};
27use crate::OpenTechCommitteeInstance;
28use moonkit_xcm_primitives::AccountIdAssetIdConversion;
29use sp_runtime::{
30 traits::{Hash as THash, MaybeEquivalence, PostDispatchInfoOf},
31 DispatchErrorWithPostInfo,
32};
33
34use frame_support::{
35 parameter_types,
36 traits::{EitherOf, EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin},
37};
38
39use frame_system::{EnsureRoot, RawOrigin};
40use sp_core::{ConstU32, H160, H256};
41use sp_weights::Weight;
42use xcm_builder::{
43 AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
44 AllowTopLevelPaidExecutionFrom, Case, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
45 ExternalConsensusLocationsConverterFor, FungibleAdapter as XcmCurrencyAdapter,
46 HashedDescription, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
47 SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
48 TakeWeightCredit, TrailingSetTopicAsId, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
49};
50
51use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
52
53use xcm::{
54 latest::prelude::{
55 AllOf, Asset, AssetFilter, GlobalConsensus, InteriorLocation, Junction, Location,
56 NetworkId, PalletInstance, Parachain, Wild, WildFungible,
57 },
58 IntoVersion,
59};
60
61use xcm_executor::traits::{CallDispatcher, ConvertLocation};
62
63use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
64use frame_support::traits::Disabled;
65use pallet_xcm::EnsureXcm;
66use xcm_primitives::{
67 AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation,
68 IsBridgedConcreteAssetFrom, MultiNativeAsset, SignedToAccountId20, XcmTransact,
69};
70
71use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot};
72use crate::runtime_params::dynamic_params;
73use moonbeam_runtime_common::xcm_origins::AllowSiblingParachains;
74use pallet_moonbeam_foreign_assets::{MapSuccessToGovernance, MapSuccessToXcm};
75use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode};
76use scale_info::TypeInfo;
77use sp_core::Get;
78use sp_std::{
79 convert::{From, Into, TryFrom},
80 prelude::*,
81};
82
83parameter_types! {
84 pub RelayNetwork: NetworkId = NetworkId::ByGenesis(xcm::v5::WESTEND_GENESIS_HASH);
86}
87
88parameter_types! {
89 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
91 pub UniversalLocation: InteriorLocation =
93 [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
94 pub SelfReserve: Location = Location {
99 parents: 0,
100 interior: [
101 PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
102 ].into()
103 };
104}
105
106pub type LocationToAccountId = (
111 ParentIsPreset<AccountId>,
113 SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>,
115 AccountKey20Aliases<RelayNetwork, AccountId>,
117 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
119 ExternalConsensusLocationsConverterFor<UniversalLocation, AccountId>,
122);
123
124pub struct LocationToH160;
126impl ConvertLocation<H160> for LocationToH160 {
127 fn convert_location(location: &Location) -> Option<H160> {
128 <LocationToAccountId as ConvertLocation<AccountId>>::convert_location(location)
129 .map(Into::into)
130 }
131}
132
133pub type LocalAssetTransactor = XcmCurrencyAdapter<
135 Balances,
137 xcm_builder::IsConcrete<SelfReserve>,
140 LocationToAccountId,
142 AccountId,
144 (),
146>;
147
148pub type AssetTransactors = (LocalAssetTransactor, EvmForeignAssets, Erc20XcmBridge);
155
156pub type XcmOriginToTransactDispatchOrigin = (
160 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
164 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
167 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
170 pallet_xcm::XcmPassthrough<RuntimeOrigin>,
172 SignedAccountKey20AsNative<RelayNetwork, RuntimeOrigin>,
175);
176
177parameter_types! {
178 pub MaxInstructions: u32 = 100;
181}
182
183pub type XcmWeigher = WeightInfoBounds<
185 crate::weights::xcm::XcmWeight<Runtime, RuntimeCall>,
186 RuntimeCall,
187 MaxInstructions,
188>;
189
190pub type XcmBarrier = TrailingSetTopicAsId<(
191 TakeWeightCredit,
193 AllowKnownQueryResponses<PolkadotXcm>,
195 WithComputedOrigin<
196 (
197 AllowTopLevelPaidExecutionFrom<Everything>,
199 AllowSubscriptionsFrom<Everything>,
201 ),
202 UniversalLocation,
203 ConstU32<8>,
204 >,
205)>;
206
207parameter_types! {
208 pub XcmFeesAccount: AccountId = Treasury::account_id();
210}
211
212#[cfg(not(feature = "evm-tracing"))]
215moonbeam_runtime_common::impl_moonbeam_xcm_call!();
216#[cfg(feature = "evm-tracing")]
217moonbeam_runtime_common::impl_moonbeam_xcm_call_tracing!();
218
219moonbeam_runtime_common::impl_evm_runner_precompile_or_eth_xcm!();
220
221pub struct SafeCallFilter;
222impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
223 fn contains(_call: &RuntimeCall) -> bool {
224 true
227 }
228}
229
230parameter_types! {
231 pub AssetHubLocation: Location = Location::new(1, [Parachain(1001)]);
233 pub const RelayLocation: Location = Location::parent();
234 pub RelayLocationFilter: AssetFilter = Wild(AllOf {
235 fun: WildFungible,
236 id: xcm::prelude::AssetId(RelayLocation::get()),
237 });
238 pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
239 RelayLocationFilter::get(),
240 AssetHubLocation::get()
241 );
242 pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS;
243}
244
245type BridgedReserves = (
246 IsBridgedConcreteAssetFrom<AssetHubLocation>,
248);
249
250type Reserves = (
251 BridgedReserves,
253 Case<RelayChainNativeAssetFromAssetHub>,
255 MultiNativeAsset<AbsoluteAndRelativeReserve<SelfLocationAbsolute>>,
257);
258
259pub struct XcmExecutorConfig;
260impl xcm_executor::Config for XcmExecutorConfig {
261 type RuntimeCall = RuntimeCall;
262 type XcmSender = XcmRouter;
263 type AssetTransactor = AssetTransactors;
265 type OriginConverter = XcmOriginToTransactDispatchOrigin;
266 type IsReserve = Reserves;
270 type IsTeleporter = (); type UniversalLocation = UniversalLocation;
272 type Barrier = XcmBarrier;
273 type Weigher = XcmWeigher;
274 type Trader = pallet_xcm_weight_trader::Trader<Runtime>;
279 type ResponseHandler = PolkadotXcm;
280 type SubscriptionService = PolkadotXcm;
281 type AssetTrap = pallet_erc20_xcm_bridge::AssetTrapWrapper<PolkadotXcm, Runtime>;
282 type AssetClaims = PolkadotXcm;
283 type CallDispatcher = MoonbeamCall;
284 type PalletInstancesInfo = crate::AllPalletsWithSystem;
285 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
286 type AssetLocker = ();
287 type AssetExchanger = ();
288 type FeeManager = ();
289
290 type MessageExporter = ();
291 type UniversalAliases = Nothing;
292 type SafeCallFilter = SafeCallFilter;
293 type Aliasers = Nothing;
294 type TransactionalProcessor = xcm_builder::FrameTransactionalProcessor;
295 type HrmpNewChannelOpenRequestHandler = ();
296 type HrmpChannelAcceptedHandler = ();
297 type HrmpChannelClosingHandler = ();
298 type XcmRecorder = PolkadotXcm;
299 type XcmEventEmitter = PolkadotXcm;
300}
301
302pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;
304
305pub type LocalXcmRouter = (
307 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
309 XcmpQueue,
311);
312
313pub type XcmRouter = WithUniqueTopic<LocalXcmRouter>;
316
317pub type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper<
318 XcmExecutorConfig,
319 xcm_executor::XcmExecutor<XcmExecutorConfig>,
320>;
321
322impl pallet_xcm::Config for Runtime {
323 type RuntimeEvent = RuntimeEvent;
324 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
325 type XcmRouter = XcmRouter;
326 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
327 type XcmExecuteFilter = Everything;
328 type XcmExecutor = XcmExecutor;
329 type XcmTeleportFilter = Nothing;
330 type XcmReserveTransferFilter = Everything;
331 type Weigher = XcmWeigher;
332 type UniversalLocation = UniversalLocation;
333 type RuntimeOrigin = RuntimeOrigin;
334 type RuntimeCall = RuntimeCall;
335 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
336 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
337 type Currency = Balances;
338 type CurrencyMatcher = ();
339 type TrustedLockers = ();
340 type SovereignAccountOf = LocationToAccountId;
341 type MaxLockers = ConstU32<8>;
342 type MaxRemoteLockConsumers = ConstU32<0>;
343 type RemoteLockConsumerIdentifier = ();
344 type WeightInfo = moonbase_weights::pallet_xcm::WeightInfo<Runtime>;
345 type AdminOrigin = EnsureRoot<AccountId>;
346 type AuthorizedAliasConsideration = Disabled;
347}
348
349impl cumulus_pallet_xcm::Config for Runtime {
350 type RuntimeEvent = RuntimeEvent;
351 type XcmExecutor = XcmExecutor;
352}
353
354impl cumulus_pallet_xcmp_queue::Config for Runtime {
355 type RuntimeEvent = RuntimeEvent;
356 type ChannelInfo = ParachainSystem;
357 type VersionWrapper = PolkadotXcm;
358 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
359 type MaxInboundSuspended = sp_core::ConstU32<1_000>;
360 type ControllerOrigin = EnsureRoot<AccountId>;
361 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
362 type WeightInfo = moonbase_weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
363 type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery<
364 cumulus_primitives_core::ParaId,
365 >;
366 type MaxActiveOutboundChannels = ConstU32<128>;
367 type MaxPageSize = MessageQueueHeapSize;
370}
371
372parameter_types! {
373 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
374}
375
376parameter_types! {
377 pub MessageQueueServiceWeight: Weight =
383 Perbill::from_percent(25) * RuntimeBlockWeights::get().max_block;
384 pub const MessageQueueMaxStale: u32 = 8;
388 pub const MessageQueueHeapSize: u32 = 103 * 1024;
394}
395
396impl pallet_message_queue::Config for Runtime {
397 type RuntimeEvent = RuntimeEvent;
398 #[cfg(feature = "runtime-benchmarks")]
399 type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
400 cumulus_primitives_core::AggregateMessageOrigin,
401 >;
402 #[cfg(not(feature = "runtime-benchmarks"))]
403 type MessageProcessor = pallet_ethereum_xcm::MessageProcessorWrapper<
404 xcm_builder::ProcessXcmMessage<AggregateMessageOrigin, XcmExecutor, RuntimeCall>,
405 >;
406 type Size = u32;
407 type HeapSize = MessageQueueHeapSize;
408 type MaxStale = MessageQueueMaxStale;
409 type ServiceWeight = MessageQueueServiceWeight;
410 type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
412 type QueuePausedQuery = EmergencyParaXcm;
414 type WeightInfo = moonbase_weights::pallet_message_queue::WeightInfo<Runtime>;
415 type IdleMaxServiceWeight = MessageQueueServiceWeight;
416}
417
418pub type FastAuthorizeUpgradeOrigin = EitherOfDiverse<
419 EnsureRoot<AccountId>,
420 pallet_collective::EnsureProportionAtLeast<AccountId, OpenTechCommitteeInstance, 5, 9>,
421>;
422
423pub type ResumeXcmOrigin = EitherOfDiverse<
424 EnsureRoot<AccountId>,
425 pallet_collective::EnsureProportionAtLeast<AccountId, OpenTechCommitteeInstance, 5, 9>,
426>;
427
428impl pallet_emergency_para_xcm::Config for Runtime {
429 type CheckAssociatedRelayNumber =
430 cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
431 type QueuePausedQuery = (MaintenanceMode, NarrowOriginToSibling<XcmpQueue>);
432 type PausedThreshold = ConstU32<300>;
433 type FastAuthorizeUpgradeOrigin = FastAuthorizeUpgradeOrigin;
434 type PausedToNormalOrigin = ResumeXcmOrigin;
435}
436
437#[derive(
439 Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo, DecodeWithMemTracking,
440)]
441pub enum AssetType {
442 Xcm(xcm::v3::Location),
443}
444impl Default for AssetType {
445 fn default() -> Self {
446 Self::Xcm(xcm::v3::Location::here())
447 }
448}
449
450impl From<xcm::v3::Location> for AssetType {
451 fn from(location: xcm::v3::Location) -> Self {
452 Self::Xcm(location)
453 }
454}
455
456impl TryFrom<Location> for AssetType {
458 type Error = ();
459
460 fn try_from(location: Location) -> Result<Self, Self::Error> {
461 match xcm::VersionedLocation::V5(location).into_version(xcm::v3::VERSION) {
463 Ok(xcm::VersionedLocation::V3(loc)) => Ok(AssetType::Xcm(loc.into())),
464 _ => Err(()),
466 }
467 }
468}
469
470impl Into<Option<xcm::v3::Location>> for AssetType {
471 fn into(self) -> Option<xcm::v3::Location> {
472 match self {
473 Self::Xcm(location) => Some(location),
474 }
475 }
476}
477
478impl Into<Option<Location>> for AssetType {
479 fn into(self) -> Option<Location> {
480 match self {
481 Self::Xcm(location) => {
482 let versioned = xcm::VersionedLocation::V3(location);
483 match versioned.into_version(xcm::latest::VERSION) {
484 Ok(xcm::VersionedLocation::V5(loc)) => Some(loc),
485 _ => None,
486 }
487 }
488 }
489 }
490}
491
492impl From<AssetType> for AssetId {
495 fn from(asset: AssetType) -> AssetId {
496 match asset {
497 AssetType::Xcm(id) => {
498 let mut result: [u8; 16] = [0u8; 16];
499 let hash: H256 = id.using_encoded(<Runtime as frame_system::Config>::Hashing::hash);
500 result.copy_from_slice(&hash.as_fixed_bytes()[0..16]);
501 u128::from_le_bytes(result)
502 }
503 }
504 }
505}
506
507#[derive(
509 Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo, DecodeWithMemTracking,
510)]
511pub enum CurrencyId {
512 SelfReserve,
514 ForeignAsset(AssetId),
516 Erc20 { contract_address: H160 },
518}
519
520impl AccountIdToCurrencyId<AccountId, CurrencyId> for Runtime {
521 fn account_to_currency_id(account: AccountId) -> Option<CurrencyId> {
522 Some(match account {
523 a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve,
525 _ => match Runtime::account_to_asset_id(account) {
527 Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id),
529 None => CurrencyId::Erc20 {
532 contract_address: account.into(),
533 },
534 },
535 })
536 }
537}
538
539pub struct CurrencyIdToLocation<AssetXConverter>(sp_std::marker::PhantomData<AssetXConverter>);
541impl<AssetXConverter> sp_runtime::traits::Convert<CurrencyId, Option<Location>>
542 for CurrencyIdToLocation<AssetXConverter>
543where
544 AssetXConverter: MaybeEquivalence<Location, AssetId>,
545{
546 fn convert(currency: CurrencyId) -> Option<Location> {
547 match currency {
548 CurrencyId::SelfReserve => {
549 let multi: Location = SelfReserve::get();
550 Some(multi)
551 }
552 CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset),
553 CurrencyId::Erc20 { contract_address } => {
554 let mut location = Erc20XcmBridgePalletLocation::get();
555 location
556 .push_interior(Junction::AccountKey20 {
557 key: contract_address.0,
558 network: None,
559 })
560 .ok();
561 Some(location)
562 }
563 }
564 }
565}
566
567parameter_types! {
568 pub const BaseXcmWeight: Weight
569 = Weight::from_parts(200_000_000u64, 0);
570 pub const MaxAssetsForTransfer: usize = 2;
571 pub SelfLocation: Location = Location::here();
574 pub SelfLocationAbsolute: Location = Location {
577 parents:1,
578 interior: [
579 Parachain(ParachainInfo::parachain_id().into())
580 ].into()
581 };
582
583}
584
585parameter_types! {
587 pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into();
588}
589
590#[derive(
594 Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo, DecodeWithMemTracking,
595)]
596pub enum Transactors {
597 Relay,
598 AssetHub,
599}
600
601#[cfg(feature = "runtime-benchmarks")]
603impl Default for Transactors {
604 fn default() -> Self {
605 Transactors::Relay
606 }
607}
608
609impl TryFrom<u8> for Transactors {
610 type Error = ();
611 fn try_from(value: u8) -> Result<Self, Self::Error> {
612 match value {
613 0u8 => Ok(Transactors::Relay),
614 1u8 => Ok(Transactors::AssetHub),
615 _ => Err(()),
616 }
617 }
618}
619
620impl XcmTransact for Transactors {
621 fn destination(self) -> Location {
622 match self {
623 Transactors::Relay => RelayLocation::get(),
624 Transactors::AssetHub => AssetHubLocation::get(),
625 }
626 }
627
628 fn utility_pallet_index(&self) -> u8 {
629 match self {
630 Transactors::Relay => pallet_xcm_transactor::RelayIndices::<Runtime>::get().utility,
631 Transactors::AssetHub => pallet_xcm_transactor::ASSET_HUB_UTILITY_PALLET_INDEX,
632 }
633 }
634
635 fn staking_pallet_index(&self) -> u8 {
636 match self {
637 Transactors::Relay => pallet_xcm_transactor::RelayIndices::<Runtime>::get().staking,
638 Transactors::AssetHub => pallet_xcm_transactor::ASSET_HUB_STAKING_PALLET_INDEX,
639 }
640 }
641}
642
643pub type DerivativeAddressRegistrationOrigin =
644 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
645
646impl pallet_xcm_transactor::Config for Runtime {
647 type Balance = Balance;
648 type Transactor = Transactors;
649 type DerivativeAddressRegistrationOrigin = DerivativeAddressRegistrationOrigin;
650 type SovereignAccountDispatcherOrigin = EnsureRoot<AccountId>;
651 type CurrencyId = CurrencyId;
652 type AccountIdToLocation = AccountIdToLocation<AccountId>;
653 type CurrencyIdToLocation = CurrencyIdToLocation<(EvmForeignAssets,)>;
654 type XcmSender = XcmRouter;
655 type SelfLocation = SelfLocation;
656 type Weigher = XcmWeigher;
657 type UniversalLocation = UniversalLocation;
658 type BaseXcmWeight = BaseXcmWeight;
659 type AssetTransactor = AssetTransactors;
660 type ReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
661 type WeightInfo = moonbase_weights::pallet_xcm_transactor::WeightInfo<Runtime>;
662 type HrmpManipulatorOrigin = GeneralAdminOrRoot;
663 type HrmpOpenOrigin = FastGeneralAdminOrRoot;
664 type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
665}
666
667parameter_types! {
668 pub Erc20XcmBridgePalletLocation: Location = Location {
672 parents:0,
673 interior: [
674 PalletInstance(<Erc20XcmBridge as PalletInfoAccess>::index() as u8)
675 ].into()
676 };
677
678 pub Erc20XcmBridgeTransferGasLimit: u64 = 400_000;
681}
682
683impl pallet_erc20_xcm_bridge::Config for Runtime {
684 type AccountIdConverter = LocationToH160;
685 type Erc20MultilocationPrefix = Erc20XcmBridgePalletLocation;
686 type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit;
687 type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
688}
689
690pub struct AccountIdToH160;
691impl sp_runtime::traits::Convert<AccountId, H160> for AccountIdToH160 {
692 fn convert(account_id: AccountId) -> H160 {
693 account_id.into()
694 }
695}
696
697pub type ForeignAssetManagerOrigin = EitherOf<
698 MapSuccessToXcm<EnsureXcm<AllowSiblingParachains>>,
699 MapSuccessToGovernance<
700 EitherOf<
701 EnsureRoot<AccountId>,
702 EitherOf<
703 pallet_collective::EnsureProportionMoreThan<
704 AccountId,
705 OpenTechCommitteeInstance,
706 5,
707 9,
708 >,
709 EitherOf<
710 governance::custom_origins::FastGeneralAdmin,
711 governance::custom_origins::GeneralAdmin,
712 >,
713 >,
714 >,
715 >,
716>;
717
718impl pallet_moonbeam_foreign_assets::Config for Runtime {
719 type AccountIdToH160 = AccountIdToH160;
720 type AssetIdFilter = Everything;
721 type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
722 type ConvertLocation =
723 SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>;
724 type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin;
725 type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin;
726 type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin;
727 type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;
728 type OnForeignAssetCreated = ();
729 type MaxForeignAssets = ConstU32<256>;
730 type WeightInfo = moonbase_weights::pallet_moonbeam_foreign_assets::WeightInfo<Runtime>;
731 type XcmLocationToH160 = LocationToH160;
732 type ForeignAssetCreationDeposit = dynamic_params::xcm_config::ForeignAssetCreationDeposit;
733 type Balance = Balance;
734 type Currency = Balances;
735}
736
737pub struct AssetFeesFilter;
738impl frame_support::traits::Contains<Location> for AssetFeesFilter {
739 fn contains(location: &Location) -> bool {
740 location.parent_count() > 0
741 && location.first_interior() != Erc20XcmBridgePalletLocation::get().first_interior()
742 }
743}
744
745pub type AddAndEditSupportedAssetOrigin = EitherOfDiverse<
746 EnsureRoot<AccountId>,
747 EitherOfDiverse<
748 pallet_collective::EnsureProportionMoreThan<AccountId, OpenTechCommitteeInstance, 5, 9>,
749 EitherOf<
750 governance::custom_origins::GeneralAdmin,
751 governance::custom_origins::FastGeneralAdmin,
752 >,
753 >,
754>;
755
756pub type RemoveSupportedAssetOrigin = EitherOfDiverse<
757 EnsureRoot<AccountId>,
758 pallet_collective::EnsureProportionMoreThan<AccountId, OpenTechCommitteeInstance, 5, 9>,
759>;
760
761impl pallet_xcm_weight_trader::Config for Runtime {
762 type AccountIdToLocation = AccountIdToLocation<AccountId>;
763 type AddSupportedAssetOrigin = AddAndEditSupportedAssetOrigin;
764 type AssetLocationFilter = AssetFeesFilter;
765 type AssetTransactor = AssetTransactors;
766 type Balance = Balance;
767 type EditSupportedAssetOrigin = AddAndEditSupportedAssetOrigin;
768 type NativeLocation = SelfReserve;
769 type PauseSupportedAssetOrigin = AddAndEditSupportedAssetOrigin;
770 type ResumeSupportedAssetOrigin = AddAndEditSupportedAssetOrigin;
771 type RemoveSupportedAssetOrigin = RemoveSupportedAssetOrigin;
772 type WeightInfo = moonbase_weights::pallet_xcm_weight_trader::WeightInfo<Runtime>;
773 type WeightToFee = <Runtime as pallet_transaction_payment::Config>::WeightToFee;
774 type XcmFeesAccount = XcmFeesAccount;
775 #[cfg(feature = "runtime-benchmarks")]
776 type NotFilteredLocation = RelayLocation;
777}
778
779#[cfg(feature = "runtime-benchmarks")]
780mod testing {
781 use super::*;
782
783 impl From<Location> for CurrencyId {
786 fn from(location: Location) -> CurrencyId {
787 use sp_runtime::traits::MaybeEquivalence;
788
789 let asset_id = if let Some(asset_id) = EvmForeignAssets::convert(&location) {
791 asset_id
792 } else {
793 let hash: H256 =
795 location.using_encoded(<Runtime as frame_system::Config>::Hashing::hash);
796 let mut result: [u8; 16] = [0u8; 16];
797 result.copy_from_slice(&hash.as_fixed_bytes()[0..16]);
798 let asset_id = u128::from_le_bytes(result);
799
800 EvmForeignAssets::set_asset(location, asset_id);
801 asset_id
802 };
803
804 CurrencyId::ForeignAsset(asset_id)
805 }
806 }
807}