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