1
// Copyright 2021 Parity Technologies (UK) Ltd.
2
// This file is part of Polkadot.
3

            
4
// Polkadot is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Polkadot is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! Parachain runtime mock.
18

            
19
use frame_support::{
20
	construct_runtime,
21
	dispatch::GetDispatchInfo,
22
	ensure, parameter_types,
23
	traits::{
24
		fungible::NativeOrWithId, AsEnsureOriginWithArg, ConstU32, EitherOf, Everything, Get,
25
		InstanceFilter, Nothing, PalletInfoAccess,
26
	},
27
	weights::Weight,
28
	PalletId,
29
};
30

            
31
use frame_system::{pallet_prelude::BlockNumberFor, EnsureNever, EnsureRoot};
32
use moonbeam_runtime_common::{
33
	impl_asset_conversion::AssetRateConverter, impl_multiasset_paymaster::MultiAssetPaymaster,
34
	xcm_origins::AllowSiblingParachains,
35
};
36
use pallet_moonbeam_foreign_assets::{MapSuccessToGovernance, MapSuccessToXcm};
37
use pallet_xcm::{migration::v1::VersionUncheckedMigrateToV1, EnsureXcm};
38
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
39
use sp_core::{H160, H256};
40
use sp_runtime::{
41
	traits::{BlakeTwo256, Hash, IdentityLookup, MaybeEquivalence, Zero},
42
	Permill,
43
};
44
use sp_std::{convert::TryFrom, prelude::*};
45
use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm};
46

            
47
use cumulus_primitives_core::relay_chain::HrmpChannelId;
48
use pallet_ethereum::PostLogContent;
49
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
50
use polkadot_parachain::primitives::{Id as ParaId, Sibling};
51
use xcm::latest::{
52
	Error as XcmError, ExecuteXcm,
53
	Junction::{PalletInstance, Parachain},
54
	Location, NetworkId, Outcome, Xcm,
55
};
56
use xcm_builder::{
57
	AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
58
	AllowTopLevelPaidExecutionFrom, Case, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds,
59
	FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, IsConcrete, NoChecking,
60
	ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
61
	SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
62
	TakeWeightCredit, WithComputedOrigin,
63
};
64
use xcm_executor::{traits::JustTry, Config, XcmExecutor};
65

            
66
pub use moonbase_runtime::xcm_config::AssetType;
67
#[cfg(feature = "runtime-benchmarks")]
68
use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper;
69
use scale_info::TypeInfo;
70
use xcm_simulator::{
71
	DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
72
	XcmpMessageHandlerT as XcmpMessageHandler,
73
};
74

            
75
pub type AccountId = moonbeam_core_primitives::AccountId;
76
pub type Balance = u128;
77
pub type AssetId = u128;
78
pub type BlockNumber = BlockNumberFor<Runtime>;
79

            
80
parameter_types! {
81
	pub const BlockHashCount: u32 = 250;
82
}
83

            
84
impl frame_system::Config for Runtime {
85
	type RuntimeOrigin = RuntimeOrigin;
86
	type RuntimeCall = RuntimeCall;
87
	type RuntimeTask = RuntimeTask;
88
	type Nonce = u64;
89
	type Block = Block;
90
	type Hash = H256;
91
	type Hashing = ::sp_runtime::traits::BlakeTwo256;
92
	type AccountId = AccountId;
93
	type Lookup = IdentityLookup<AccountId>;
94
	type RuntimeEvent = RuntimeEvent;
95
	type BlockHashCount = BlockHashCount;
96
	type BlockWeights = ();
97
	type BlockLength = ();
98
	type Version = ();
99
	type PalletInfo = PalletInfo;
100
	type AccountData = pallet_balances::AccountData<Balance>;
101
	type OnNewAccount = ();
102
	type OnKilledAccount = ();
103
	type DbWeight = ();
104
	type BaseCallFilter = Everything;
105
	type SystemWeightInfo = ();
106
	type SS58Prefix = ();
107
	type OnSetCode = ();
108
	type MaxConsumers = frame_support::traits::ConstU32<16>;
109
	type SingleBlockMigrations = ();
110
	type MultiBlockMigrator = ();
111
	type PreInherents = ();
112
	type PostInherents = ();
113
	type PostTransactions = ();
114
	type ExtensionsWeightInfo = ();
115
}
116

            
117
parameter_types! {
118
	pub ExistentialDeposit: Balance = 0;
119
	pub const MaxLocks: u32 = 50;
120
	pub const MaxReserves: u32 = 50;
121
}
122

            
123
impl pallet_balances::Config for Runtime {
124
	type MaxLocks = MaxLocks;
125
	type Balance = Balance;
126
	type RuntimeEvent = RuntimeEvent;
127
	type DustRemoval = ();
128
	type ExistentialDeposit = ExistentialDeposit;
129
	type AccountStore = System;
130
	type WeightInfo = ();
131
	type MaxReserves = MaxReserves;
132
	type ReserveIdentifier = [u8; 8];
133
	type RuntimeHoldReason = ();
134
	type FreezeIdentifier = ();
135
	type MaxFreezes = ();
136
	type RuntimeFreezeReason = ();
137
	type DoneSlashHandler = ();
138
}
139

            
140
pub type ForeignAssetInstance = ();
141

            
142
// Required for runtime benchmarks
143
pallet_assets::runtime_benchmarks_enabled! {
144
	pub struct BenchmarkHelper;
145
	impl<AssetIdParameter> pallet_assets::BenchmarkHelper<AssetIdParameter> for BenchmarkHelper
146
	where
147
		AssetIdParameter: From<u128>,
148
	{
149
		fn create_asset_id_parameter(id: u32) -> AssetIdParameter {
150
			(id as u128).into()
151
		}
152
	}
153
}
154

            
155
parameter_types! {
156
	pub const AssetDeposit: Balance = 10; // Does not really matter as this will be only called by root
157
	pub const ApprovalDeposit: Balance = 0;
158
	pub const AssetsStringLimit: u32 = 50;
159
	pub const MetadataDepositBase: Balance = 0;
160
	pub const MetadataDepositPerByte: Balance = 0;
161
	pub const AssetAccountDeposit: Balance = 0;
162
}
163

            
164
impl pallet_assets::Config<ForeignAssetInstance> for Runtime {
165
	type RuntimeEvent = RuntimeEvent;
166
	type Balance = Balance;
167
	type AssetId = AssetId;
168
	type Currency = Balances;
169
	type ForceOrigin = EnsureRoot<AccountId>;
170
	type AssetDeposit = AssetDeposit;
171
	type MetadataDepositBase = MetadataDepositBase;
172
	type MetadataDepositPerByte = MetadataDepositPerByte;
173
	type ApprovalDeposit = ApprovalDeposit;
174
	type StringLimit = AssetsStringLimit;
175
	type Freezer = ();
176
	type Extra = ();
177
	type AssetAccountDeposit = AssetAccountDeposit;
178
	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
179
	type RemoveItemsLimit = ConstU32<656>;
180
	type AssetIdParameter = AssetId;
181
	type CreateOrigin = AsEnsureOriginWithArg<EnsureNever<AccountId>>;
182
	type CallbackHandle = ();
183
	pallet_assets::runtime_benchmarks_enabled! {
184
		type BenchmarkHelper = BenchmarkHelper;
185
	}
186
}
187

            
188
/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
189
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
190
/// `Transact` in order to determine the dispatch Origin.
191
pub type LocationToAccountId = (
192
	// The parent (Relay-chain) origin converts to the default `AccountId`.
193
	ParentIsPreset<AccountId>,
194
	// Sibling parachain origins convert to AccountId via the `ParaId::into`.
195
	SiblingParachainConvertsVia<Sibling, AccountId>,
196
	AccountKey20Aliases<RelayNetwork, AccountId>,
197
	// The rest of multilocations convert via hashing it
198
	xcm_builder::HashedDescription<
199
		AccountId,
200
		xcm_builder::DescribeFamily<xcm_builder::DescribeAllTerminal>,
201
	>,
202
);
203

            
204
/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
205
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
206
/// biases the kind of local `Origin` it will become.
207
pub type XcmOriginToTransactDispatchOrigin = (
208
	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
209
	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
210
	// foreign chains who want to have a local sovereign account on this chain which they control.
211
	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
212
	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
213
	// recognised.
214
	RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
215
	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
216
	// recognised.
217
	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
218
	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
219
	// transaction from the Root origin.
220
	ParentAsSuperuser<RuntimeOrigin>,
221
	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
222
	pallet_xcm::XcmPassthrough<RuntimeOrigin>,
223
	SignedAccountKey20AsNative<RelayNetwork, RuntimeOrigin>,
224
);
225

            
226
parameter_types! {
227
	pub const UnitWeightCost: Weight = Weight::from_parts(1u64, 1u64);
228
	pub MaxInstructions: u32 = 100;
229
}
230

            
231
// Instructing how incoming xcm assets will be handled
232
pub type ForeignFungiblesTransactor = FungiblesAdapter<
233
	// Use this fungibles implementation:
234
	Assets,
235
	// Use this currency when it is a fungible asset matching any of the locations in
236
	// SelfReserveRepresentations
237
	(
238
		ConvertedConcreteId<
239
			AssetId,
240
			Balance,
241
			xcm_primitives::AsAssetType<AssetId, AssetType, AssetManager>,
242
			JustTry,
243
		>,
244
	),
245
	// Do a simple punn to convert an AccountId32 Location into a native chain account ID:
246
	LocationToAccountId,
247
	// Our chain's account ID type (we can't get away without mentioning it explicitly):
248
	AccountId,
249
	// We dont allow teleports.
250
	NoChecking,
251
	// We dont track any teleports
252
	(),
253
>;
254

            
255
/// The transactor for our own chain currency.
256
pub type LocalAssetTransactor = XcmCurrencyAdapter<
257
	// Use this currency:
258
	Balances,
259
	// Use this currency when it is a fungible asset matching any of the locations in
260
	// SelfReserveRepresentations
261
	IsConcrete<SelfReserve>,
262
	// We can convert the Locations with our converter above:
263
	LocationToAccountId,
264
	// Our chain's account ID type (we can't get away without mentioning it explicitly):
265
	AccountId,
266
	// We dont allow teleport
267
	(),
268
>;
269

            
270
// These will be our transactors
271
// We use both transactors
272
pub type AssetTransactors = (LocalAssetTransactor, ForeignFungiblesTransactor);
273

            
274
pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
275

            
276
pub type XcmBarrier = (
277
	// Weight that is paid for may be consumed.
278
	TakeWeightCredit,
279
	// Expected responses are OK.
280
	AllowKnownQueryResponses<PolkadotXcm>,
281
	WithComputedOrigin<
282
		(
283
			// If the message is one that immediately attemps to pay for execution, then allow it.
284
			AllowTopLevelPaidExecutionFrom<Everything>,
285
			// Subscriptions for version tracking are OK.
286
			AllowSubscriptionsFrom<Everything>,
287
		),
288
		UniversalLocation,
289
		ConstU32<8>,
290
	>,
291
);
292

            
293
parameter_types! {
294
	/// Xcm fees will go to the treasury account
295
	pub XcmFeesAccount: AccountId = Treasury::account_id();
296
	/// Parachain token units per second of execution
297
	pub ParaTokensPerSecond: u128 = 1000000000000;
298
}
299

            
300
pub struct WeightToFee;
301
impl sp_weights::WeightToFee for WeightToFee {
302
	type Balance = Balance;
303

            
304
49
	fn weight_to_fee(weight: &Weight) -> Self::Balance {
305
		use sp_runtime::SaturatedConversion as _;
306
49
		Self::Balance::saturated_from(weight.ref_time())
307
49
			.saturating_mul(ParaTokensPerSecond::get())
308
49
			.saturating_div(frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND as u128)
309
49
	}
310
}
311

            
312
parameter_types! {
313
	pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
314
	pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
315
	pub UniversalLocation: InteriorLocation =
316
		[GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
317

            
318
	// New Self Reserve location, defines the multilocation identifiying the self-reserve currency
319
	// This is used to match it also against our Balances pallet when we receive such
320
	// a Location: (Self Balances pallet index)
321
	pub SelfReserve: Location = Location {
322
		parents:0,
323
		interior: [
324
			PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
325
		].into()
326
	};
327
	pub const MaxAssetsIntoHolding: u32 = 64;
328

            
329
	pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
330
	pub RelayLocationFilter: AssetFilter = Wild(AllOf {
331
		fun: WildFungible,
332
		id: xcm::prelude::AssetId(Location::parent()),
333
	});
334

            
335
	pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
336
		RelayLocationFilter::get(),
337
		AssetHubLocation::get()
338
	);
339
}
340

            
341
use frame_system::RawOrigin;
342
use sp_runtime::traits::PostDispatchInfoOf;
343
use sp_runtime::DispatchErrorWithPostInfo;
344
use xcm_executor::traits::CallDispatcher;
345
moonbeam_runtime_common::impl_moonbeam_xcm_call!();
346

            
347
type Reserves = (
348
	// Relaychain (DOT) from Asset Hub
349
	Case<RelayChainNativeAssetFromAssetHub>,
350
	// Assets which the reserve is the same as the origin.
351
	xcm_primitives::MultiNativeAsset<
352
		xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>,
353
	>,
354
);
355

            
356
pub struct XcmConfig;
357
impl Config for XcmConfig {
358
	type RuntimeCall = RuntimeCall;
359
	type XcmSender = XcmRouter;
360
	type AssetTransactor = AssetTransactors;
361
	type OriginConverter = XcmOriginToTransactDispatchOrigin;
362
	type IsReserve = Reserves;
363
	type IsTeleporter = ();
364
	type UniversalLocation = UniversalLocation;
365
	type Barrier = XcmBarrier;
366
	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
367
	type Trader = pallet_xcm_weight_trader::Trader<Runtime>;
368

            
369
	type ResponseHandler = PolkadotXcm;
370
	type SubscriptionService = PolkadotXcm;
371
	type AssetTrap = PolkadotXcm;
372
	type AssetClaims = PolkadotXcm;
373
	type CallDispatcher = MoonbeamCall;
374
	type AssetLocker = ();
375
	type AssetExchanger = ();
376
	type PalletInstancesInfo = ();
377
	type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
378
	type FeeManager = ();
379
	type MessageExporter = ();
380
	type UniversalAliases = Nothing;
381
	type SafeCallFilter = Everything;
382
	type Aliasers = Nothing;
383
	type TransactionalProcessor = ();
384
	type HrmpNewChannelOpenRequestHandler = ();
385
	type HrmpChannelAcceptedHandler = ();
386
	type HrmpChannelClosingHandler = ();
387
	type XcmRecorder = PolkadotXcm;
388
}
389

            
390
impl cumulus_pallet_xcm::Config for Runtime {
391
	type RuntimeEvent = RuntimeEvent;
392
	type XcmExecutor = XcmExecutor<XcmConfig>;
393
}
394

            
395
// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id.
396
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
397
pub enum CurrencyId {
398
	SelfReserve,
399
	ForeignAsset(AssetId),
400
}
401

            
402
// How to convert from CurrencyId to Location
403
pub struct CurrencyIdToLocation<AssetXConverter>(sp_std::marker::PhantomData<AssetXConverter>);
404
impl<AssetXConverter> sp_runtime::traits::Convert<CurrencyId, Option<Location>>
405
	for CurrencyIdToLocation<AssetXConverter>
406
where
407
	AssetXConverter: MaybeEquivalence<Location, AssetId>,
408
{
409
25
	fn convert(currency: CurrencyId) -> Option<Location> {
410
25
		match currency {
411
			CurrencyId::SelfReserve => {
412
				// For now and until Xtokens is adapted to handle 0.9.16 version we use
413
				// the old anchoring here
414
				// This is not a problem in either cases, since the view of the destination
415
				// chain does not change
416
				// TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it
417
8
				let multi: Location = SelfReserve::get();
418
8
				Some(multi)
419
			}
420
17
			CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset),
421
		}
422
25
	}
423
}
424

            
425
parameter_types! {
426
	pub const BaseXcmWeight: Weight = Weight::from_parts(100u64, 100u64);
427
	pub const MaxAssetsForTransfer: usize = 2;
428
	pub SelfLocation: Location = Location::here();
429
	pub SelfLocationAbsolute: Location = Location {
430
		parents:1,
431
		interior: [
432
			Parachain(MsgQueue::parachain_id().into())
433
		].into()
434
	};
435
}
436

            
437
parameter_types! {
438
	pub const ProposalBond: Permill = Permill::from_percent(5);
439
	pub const ProposalBondMinimum: Balance = 0;
440
	pub const SpendPeriod: u32 = 0;
441
	pub const TreasuryId: PalletId = PalletId(*b"pc/trsry");
442
	pub const MaxApprovals: u32 = 100;
443
	pub TreasuryAccount: AccountId = Treasury::account_id();
444
}
445

            
446
impl pallet_treasury::Config for Runtime {
447
	type PalletId = TreasuryId;
448
	type Currency = Balances;
449
	type RejectOrigin = EnsureRoot<AccountId>;
450
	type RuntimeEvent = RuntimeEvent;
451
	type SpendPeriod = SpendPeriod;
452
	type Burn = ();
453
	type BurnDestination = ();
454
	type MaxApprovals = MaxApprovals;
455
	type WeightInfo = ();
456
	type SpendFunds = ();
457
	type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>; // Same as Polkadot
458
	type AssetKind = NativeOrWithId<AssetId>;
459
	type Beneficiary = AccountId;
460
	type BeneficiaryLookup = IdentityLookup<AccountId>;
461
	type Paymaster = MultiAssetPaymaster<Runtime, TreasuryAccount, Balances>;
462
	type BalanceConverter = AssetRateConverter<Runtime, Balances>;
463
	type PayoutPeriod = ConstU32<0>;
464
	#[cfg(feature = "runtime-benchmarks")]
465
	type BenchmarkHelper = ArgumentsBenchmarkHelper;
466
	type BlockNumberProvider = System;
467
}
468

            
469
#[frame_support::pallet]
470
pub mod mock_msg_queue {
471
	use super::*;
472
	use frame_support::pallet_prelude::*;
473

            
474
	#[pallet::config]
475
	pub trait Config: frame_system::Config {
476
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
477
		type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
478
	}
479

            
480
	#[pallet::call]
481
	impl<T: Config> Pallet<T> {}
482

            
483
1
	#[pallet::pallet]
484
	pub struct Pallet<T>(_);
485

            
486
1158
	#[pallet::storage]
487
	#[pallet::getter(fn parachain_id)]
488
	pub(super) type ParachainId<T: Config> = StorageValue<_, ParaId, ValueQuery>;
489

            
490
	impl<T: Config> Get<ParaId> for Pallet<T> {
491
49
		fn get() -> ParaId {
492
49
			Self::parachain_id()
493
49
		}
494
	}
495

            
496
	pub type MessageId = [u8; 32];
497

            
498
	#[pallet::event]
499
53
	#[pallet::generate_deposit(pub(super) fn deposit_event)]
500
	pub enum Event<T: Config> {
501
		// XCMP
502
5
		/// Some XCM was executed OK.
503
		Success(Option<T::Hash>),
504
		/// Some XCM failed.
505
		Fail(Option<T::Hash>, XcmError),
506
		/// Bad XCM version used.
507
		BadVersion(Option<T::Hash>),
508
		/// Bad XCM format used.
509
		BadFormat(Option<T::Hash>),
510

            
511
		// DMP
512
		/// Downward message is invalid XCM.
513
		InvalidFormat(MessageId),
514
		/// Downward message is unsupported version of XCM.
515
		UnsupportedVersion(MessageId),
516
5
		/// Downward message executed with the given outcome.
517
		ExecutedDownward(MessageId, Outcome),
518
	}
519

            
520
	impl<T: Config> Pallet<T> {
521
246
		pub fn set_para_id(para_id: ParaId) {
522
246
			ParachainId::<T>::put(para_id);
523
246
		}
524

            
525
33
		fn handle_xcmp_message(
526
33
			sender: ParaId,
527
33
			_sent_at: RelayBlockNumber,
528
33
			xcm: VersionedXcm<T::RuntimeCall>,
529
33
			max_weight: Weight,
530
33
		) -> Result<Weight, XcmError> {
531
33
			let hash = Encode::using_encoded(&xcm, T::Hashing::hash);
532
33
			let (result, event) = match Xcm::<T::RuntimeCall>::try_from(xcm) {
533
33
				Ok(xcm) => {
534
33
					let location = Location::new(1, [Parachain(sender.into())]);
535
33
					let mut id = [0u8; 32];
536
33
					id.copy_from_slice(hash.as_ref());
537
33
					match T::XcmExecutor::prepare_and_execute(
538
33
						location,
539
33
						xcm,
540
33
						&mut id,
541
33
						max_weight,
542
33
						Weight::zero(),
543
33
					) {
544
						Outcome::Error { error } => {
545
							(Err(error.clone()), Event::Fail(Some(hash), error))
546
						}
547
33
						Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))),
548
						// As far as the caller is concerned, this was dispatched without error, so
549
						// we just report the weight used.
550
						Outcome::Incomplete { used, error } => {
551
							(Ok(used), Event::Fail(Some(hash), error))
552
						}
553
					}
554
				}
555
				Err(()) => (
556
					Err(XcmError::UnhandledXcmVersion),
557
					Event::BadVersion(Some(hash)),
558
				),
559
			};
560
33
			Self::deposit_event(event);
561
33
			result
562
33
		}
563
	}
564

            
565
	impl<T: Config> XcmpMessageHandler for Pallet<T> {
566
33
		fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
567
33
			iter: I,
568
33
			max_weight: Weight,
569
33
		) -> Weight {
570
66
			for (sender, sent_at, data) in iter {
571
33
				let mut data_ref = data;
572
33
				let _ = XcmpMessageFormat::decode(&mut data_ref)
573
33
					.expect("Simulator encodes with versioned xcm format; qed");
574
33

            
575
33
				let mut remaining_fragments = &data_ref[..];
576
66
				while !remaining_fragments.is_empty() {
577
33
					if let Ok(xcm) =
578
33
						VersionedXcm::<T::RuntimeCall>::decode(&mut remaining_fragments)
579
33
					{
580
33
						let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight);
581
33
					} else {
582
						debug_assert!(false, "Invalid incoming XCMP message data");
583
					}
584
				}
585
			}
586
33
			max_weight
587
33
		}
588
	}
589

            
590
	impl<T: Config> DmpMessageHandler for Pallet<T> {
591
20
		fn handle_dmp_messages(
592
20
			iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
593
20
			limit: Weight,
594
20
		) -> Weight {
595
20
			for (_i, (_sent_at, data)) in iter.enumerate() {
596
20
				let mut id = sp_io::hashing::blake2_256(&data[..]);
597
20
				let maybe_msg = VersionedXcm::<T::RuntimeCall>::decode(&mut &data[..])
598
20
					.map(Xcm::<T::RuntimeCall>::try_from);
599
20
				match maybe_msg {
600
					Err(_) => {
601
						Self::deposit_event(Event::InvalidFormat(id));
602
					}
603
					Ok(Err(())) => {
604
						Self::deposit_event(Event::UnsupportedVersion(id));
605
					}
606
20
					Ok(Ok(x)) => {
607
20
						let outcome = T::XcmExecutor::prepare_and_execute(
608
20
							Parent,
609
20
							x,
610
20
							&mut id,
611
20
							limit,
612
20
							Weight::zero(),
613
20
						);
614
20

            
615
20
						Self::deposit_event(Event::ExecutedDownward(id, outcome));
616
20
					}
617
				}
618
			}
619
20
			limit
620
20
		}
621
	}
622
}
623

            
624
// Pallet to provide the version, used to test runtime upgrade version changes
625
#[frame_support::pallet]
626
pub mod mock_version_changer {
627
	use super::*;
628
	use frame_support::pallet_prelude::*;
629

            
630
	#[pallet::config]
631
	pub trait Config: frame_system::Config {
632
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
633
	}
634

            
635
	#[pallet::call]
636
	impl<T: Config> Pallet<T> {}
637

            
638
1
	#[pallet::pallet]
639
	pub struct Pallet<T>(_);
640

            
641
22
	#[pallet::storage]
642
	#[pallet::getter(fn current_version)]
643
	pub(super) type CurrentVersion<T: Config> = StorageValue<_, XcmVersion, ValueQuery>;
644

            
645
	impl<T: Config> Get<XcmVersion> for Pallet<T> {
646
4
		fn get() -> XcmVersion {
647
4
			Self::current_version()
648
4
		}
649
	}
650

            
651
	#[pallet::event]
652
5
	#[pallet::generate_deposit(pub(super) fn deposit_event)]
653
	pub enum Event<T: Config> {
654
		// XCMP
655
6
		/// Some XCM was executed OK.
656
		VersionChanged(XcmVersion),
657
	}
658

            
659
	impl<T: Config> Pallet<T> {
660
5
		pub fn set_version(version: XcmVersion) {
661
5
			CurrentVersion::<T>::put(version);
662
5
			Self::deposit_event(Event::VersionChanged(version));
663
5
		}
664
	}
665
}
666

            
667
impl mock_msg_queue::Config for Runtime {
668
	type RuntimeEvent = RuntimeEvent;
669
	type XcmExecutor = XcmExecutor<XcmConfig>;
670
}
671

            
672
impl mock_version_changer::Config for Runtime {
673
	type RuntimeEvent = RuntimeEvent;
674
}
675

            
676
pub type LocalOriginToLocation =
677
	xcm_primitives::SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;
678

            
679
parameter_types! {
680
	pub MatcherLocation: Location = Location::here();
681
}
682

            
683
impl pallet_xcm::Config for Runtime {
684
	type RuntimeEvent = RuntimeEvent;
685
	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
686
	type XcmRouter = XcmRouter;
687
	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
688
	type XcmExecuteFilter = frame_support::traits::Nothing;
689
	type XcmExecutor = XcmExecutor<XcmConfig>;
690
	// Do not allow teleports
691
	type XcmTeleportFilter = Nothing;
692
	type XcmReserveTransferFilter = Everything;
693
	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
694
	type UniversalLocation = UniversalLocation;
695
	type RuntimeOrigin = RuntimeOrigin;
696
	type RuntimeCall = RuntimeCall;
697
	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
698
	// We use a custom one to test runtime ugprades
699
	type AdvertisedXcmVersion = XcmVersioner;
700
	type Currency = Balances;
701
	type CurrencyMatcher = IsConcrete<MatcherLocation>;
702
	type TrustedLockers = ();
703
	type SovereignAccountOf = ();
704
	type MaxLockers = ConstU32<8>;
705
	type WeightInfo = pallet_xcm::TestWeightInfo;
706
	type MaxRemoteLockConsumers = ConstU32<0>;
707
	type RemoteLockConsumerIdentifier = ();
708
	type AdminOrigin = frame_system::EnsureRoot<AccountId>;
709
}
710

            
711
// We instruct how to register the Assets
712
// In this case, we tell it to Create an Asset in pallet-assets
713
pub struct AssetRegistrar;
714
use frame_support::pallet_prelude::DispatchResult;
715
impl pallet_asset_manager::AssetRegistrar<Runtime> for AssetRegistrar {
716
35
	fn create_foreign_asset(
717
35
		asset: AssetId,
718
35
		min_balance: Balance,
719
35
		metadata: AssetMetadata,
720
35
		is_sufficient: bool,
721
35
	) -> DispatchResult {
722
35
		Assets::force_create(
723
35
			RuntimeOrigin::root(),
724
35
			asset,
725
35
			AssetManager::account_id(),
726
35
			is_sufficient,
727
35
			min_balance,
728
35
		)?;
729

            
730
35
		Assets::force_set_metadata(
731
35
			RuntimeOrigin::root(),
732
35
			asset,
733
35
			metadata.name,
734
35
			metadata.symbol,
735
35
			metadata.decimals,
736
35
			false,
737
35
		)
738
35
	}
739

            
740
	fn destroy_foreign_asset(asset: AssetId) -> DispatchResult {
741
		// Mark the asset as destroying
742
		Assets::start_destroy(RuntimeOrigin::root(), asset.into())?;
743

            
744
		Ok(())
745
	}
746

            
747
	fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight {
748
		RuntimeCall::Assets(
749
			pallet_assets::Call::<Runtime, ForeignAssetInstance>::start_destroy {
750
				id: asset.into(),
751
			},
752
		)
753
		.get_dispatch_info()
754
		.total_weight()
755
	}
756
}
757

            
758
#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
759
pub struct AssetMetadata {
760
	pub name: Vec<u8>,
761
	pub symbol: Vec<u8>,
762
	pub decimals: u8,
763
}
764

            
765
impl pallet_asset_manager::Config for Runtime {
766
	type RuntimeEvent = RuntimeEvent;
767
	type Balance = Balance;
768
	type AssetId = AssetId;
769
	type AssetRegistrarMetadata = AssetMetadata;
770
	type ForeignAssetType = AssetType;
771
	type AssetRegistrar = AssetRegistrar;
772
	type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
773
	type WeightInfo = ();
774
}
775

            
776
pub struct AccountIdToH160;
777
impl sp_runtime::traits::Convert<AccountId, H160> for AccountIdToH160 {
778
	fn convert(account_id: AccountId) -> H160 {
779
		account_id.into()
780
	}
781
}
782

            
783
pub struct EvmForeignAssetIdFilter;
784
impl frame_support::traits::Contains<AssetId> for EvmForeignAssetIdFilter {
785
	fn contains(asset_id: &AssetId) -> bool {
786
		use xcm_primitives::AssetTypeGetter as _;
787
		// We should return true only if the AssetId doesn't exist in AssetManager
788
		AssetManager::get_asset_type(*asset_id).is_none()
789
	}
790
}
791

            
792
pub type ForeignAssetManagerOrigin = EitherOf<
793
	MapSuccessToXcm<EnsureXcm<AllowSiblingParachains>>,
794
	MapSuccessToGovernance<EnsureRoot<AccountId>>,
795
>;
796

            
797
moonbeam_runtime_common::impl_evm_runner_precompile_or_eth_xcm!();
798

            
799
parameter_types! {
800
	pub ForeignAssetCreationDeposit: u128 = 100 * currency::UNIT;
801
}
802

            
803
impl pallet_moonbeam_foreign_assets::Config for Runtime {
804
	type AccountIdToH160 = AccountIdToH160;
805
	type AssetIdFilter = EvmForeignAssetIdFilter;
806
	type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
807
	type ConvertLocation =
808
		SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>;
809
	type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin;
810
	type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin;
811
	type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin;
812
	type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;
813
	type OnForeignAssetCreated = ();
814
	type MaxForeignAssets = ConstU32<256>;
815
	type RuntimeEvent = RuntimeEvent;
816
	type WeightInfo = ();
817
	type XcmLocationToH160 = LocationToH160;
818
	type ForeignAssetCreationDeposit = ForeignAssetCreationDeposit;
819
	type Balance = Balance;
820
	type Currency = Balances;
821
}
822

            
823
// 1 ROC/WND should be enough
824
parameter_types! {
825
	pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into();
826
}
827

            
828
impl pallet_xcm_transactor::Config for Runtime {
829
	type RuntimeEvent = RuntimeEvent;
830
	type Balance = Balance;
831
	type Transactor = MockTransactors;
832
	type DerivativeAddressRegistrationOrigin = EnsureRoot<AccountId>;
833
	type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot<AccountId>;
834
	type CurrencyId = CurrencyId;
835
	type AccountIdToLocation = xcm_primitives::AccountIdToLocation<AccountId>;
836
	type CurrencyIdToLocation = CurrencyIdToLocation<(
837
		EvmForeignAssets,
838
		AsAssetType<moonbeam_core_primitives::AssetId, AssetType, AssetManager>,
839
	)>;
840
	type SelfLocation = SelfLocation;
841
	type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
842
	type UniversalLocation = UniversalLocation;
843
	type XcmSender = XcmRouter;
844
	type BaseXcmWeight = BaseXcmWeight;
845
	type AssetTransactor = AssetTransactors;
846
	type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
847
	type WeightInfo = ();
848
	type HrmpManipulatorOrigin = EnsureRoot<AccountId>;
849
	type HrmpOpenOrigin = EnsureRoot<AccountId>;
850
	type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
851
}
852

            
853
parameter_types! {
854
	pub RelayLocation: Location = Location::parent();
855
}
856

            
857
impl pallet_xcm_weight_trader::Config for Runtime {
858
	type AccountIdToLocation = xcm_primitives::AccountIdToLocation<AccountId>;
859
	type AddSupportedAssetOrigin = EnsureRoot<AccountId>;
860
	type AssetLocationFilter = Everything;
861
	type AssetTransactor = AssetTransactors;
862
	type Balance = Balance;
863
	type EditSupportedAssetOrigin = EnsureRoot<AccountId>;
864
	type NativeLocation = SelfReserve;
865
	type PauseSupportedAssetOrigin = EnsureRoot<AccountId>;
866
	type RemoveSupportedAssetOrigin = EnsureRoot<AccountId>;
867
	type RuntimeEvent = RuntimeEvent;
868
	type ResumeSupportedAssetOrigin = EnsureRoot<AccountId>;
869
	type WeightInfo = ();
870
	type WeightToFee = WeightToFee;
871
	type XcmFeesAccount = XcmFeesAccount;
872
	#[cfg(feature = "runtime-benchmarks")]
873
	type NotFilteredLocation = RelayLocation;
874
}
875

            
876
parameter_types! {
877
	pub const MinimumPeriod: u64 = 1000;
878
}
879
impl pallet_timestamp::Config for Runtime {
880
	type Moment = u64;
881
	type OnTimestampSet = ();
882
	type MinimumPeriod = MinimumPeriod;
883
	type WeightInfo = ();
884
}
885

            
886
parameter_types! {
887
	pub BlockGasLimit: U256 = U256::from(u64::MAX);
888
	pub WeightPerGas: Weight = Weight::from_parts(1, 0);
889
	pub GasLimitPovSizeRatio: u64 = {
890
		let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
891
		block_gas_limit.saturating_div(MAX_POV_SIZE as u64)
892
	};
893
	pub GasLimitStorageGrowthRatio: u64 =
894
		BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT);
895
}
896

            
897
impl pallet_evm::Config for Runtime {
898
	type FeeCalculator = ();
899
	type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
900
	type WeightPerGas = WeightPerGas;
901

            
902
	type CallOrigin = pallet_evm::EnsureAddressRoot<AccountId>;
903
	type WithdrawOrigin = pallet_evm::EnsureAddressNever<AccountId>;
904

            
905
	type AddressMapping = pallet_evm::IdentityAddressMapping;
906
	type Currency = Balances;
907
	type Runner = pallet_evm::runner::stack::Runner<Self>;
908

            
909
	type RuntimeEvent = RuntimeEvent;
910
	type PrecompilesType = ();
911
	type PrecompilesValue = ();
912
	type ChainId = ();
913
	type BlockGasLimit = BlockGasLimit;
914
	type OnChargeTransaction = ();
915
	type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping<Self>;
916
	type FindAuthor = ();
917
	type OnCreate = ();
918
	type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
919
	type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
920
	type Timestamp = Timestamp;
921
	type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
922
	type AccountProvider = FrameSystemAccountProvider<Runtime>;
923
}
924

            
925
#[allow(dead_code)]
926
pub struct NormalFilter;
927

            
928
impl frame_support::traits::Contains<RuntimeCall> for NormalFilter {
929
	fn contains(c: &RuntimeCall) -> bool {
930
		match c {
931
			_ => true,
932
		}
933
	}
934
}
935

            
936
// We need to use the encoding from the relay mock runtime
937
#[derive(Encode, Decode)]
938
pub enum RelayCall {
939
	#[codec(index = 5u8)]
940
	// the index should match the position of the module in `construct_runtime!`
941
	Utility(UtilityCall),
942
	#[codec(index = 6u8)]
943
	// the index should match the position of the module in `construct_runtime!`
944
	Hrmp(HrmpCall),
945
}
946

            
947
#[derive(Encode, Decode)]
948
pub enum UtilityCall {
949
	#[codec(index = 1u8)]
950
	AsDerivative(u16),
951
}
952

            
953
// HRMP call encoding, needed for xcm transactor pallet
954
#[derive(Encode, Decode)]
955
pub enum HrmpCall {
956
	#[codec(index = 0u8)]
957
	InitOpenChannel(ParaId, u32, u32),
958
	#[codec(index = 1u8)]
959
	AcceptOpenChannel(ParaId),
960
	#[codec(index = 2u8)]
961
	CloseChannel(HrmpChannelId),
962
	#[codec(index = 6u8)]
963
	CancelOpenRequest(HrmpChannelId, u32),
964
}
965

            
966
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
967
pub enum MockTransactors {
968
	Relay,
969
}
970

            
971
impl xcm_primitives::XcmTransact for MockTransactors {
972
3
	fn destination(self) -> Location {
973
3
		match self {
974
3
			MockTransactors::Relay => Location::parent(),
975
3
		}
976
3
	}
977
}
978

            
979
impl xcm_primitives::UtilityEncodeCall for MockTransactors {
980
7
	fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec<u8> {
981
7
		match self {
982
7
			MockTransactors::Relay => match call {
983
7
				xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => {
984
7
					let mut call =
985
7
						RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode();
986
7
					call.append(&mut b.clone());
987
7
					call
988
7
				}
989
7
			},
990
7
		}
991
7
	}
992
}
993

            
994
#[allow(dead_code)]
995
pub struct MockHrmpEncoder;
996

            
997
impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder {
998
	fn hrmp_encode_call(
999
		call: xcm_primitives::HrmpAvailableCalls,
	) -> Result<Vec<u8>, xcm::latest::Error> {
		match call {
			xcm_primitives::HrmpAvailableCalls::InitOpenChannel(a, b, c) => Ok(RelayCall::Hrmp(
				HrmpCall::InitOpenChannel(a.clone(), b.clone(), c.clone()),
			)
			.encode()),
			xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(a) => {
				Ok(RelayCall::Hrmp(HrmpCall::AcceptOpenChannel(a.clone())).encode())
			}
			xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => {
				Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode())
			}
			xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => {
				Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode())
			}
		}
	}
}
parameter_types! {
	pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
}
impl pallet_ethereum::Config for Runtime {
	type RuntimeEvent = RuntimeEvent;
	type StateRoot =
		pallet_ethereum::IntermediateStateRoot<<Runtime as frame_system::Config>::Version>;
	type PostLogContent = PostBlockAndTxnHashes;
	type ExtraDataLength = ConstU32<30>;
}
parameter_types! {
	pub ReservedXcmpWeight: Weight = Weight::from_parts(u64::max_value(), 0);
}
#[derive(
	Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo,
)]
pub enum ProxyType {
	NotAllowed = 0,
1
	Any = 1,
}
impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType {}
impl InstanceFilter<RuntimeCall> for ProxyType {
	fn filter(&self, _c: &RuntimeCall) -> bool {
		match self {
			ProxyType::NotAllowed => false,
			ProxyType::Any => true,
		}
	}
	fn is_superset(&self, _o: &Self) -> bool {
		false
	}
}
impl Default for ProxyType {
	fn default() -> Self {
		Self::NotAllowed
	}
}
parameter_types! {
	pub const ProxyCost: u64 = 1;
}
impl pallet_proxy::Config for Runtime {
	type RuntimeEvent = RuntimeEvent;
	type RuntimeCall = RuntimeCall;
	type Currency = Balances;
	type ProxyType = ProxyType;
	type ProxyDepositBase = ProxyCost;
	type ProxyDepositFactor = ProxyCost;
	type MaxProxies = ConstU32<32>;
	type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
	type MaxPending = ConstU32<32>;
	type CallHasher = BlakeTwo256;
	type AnnouncementDepositBase = ProxyCost;
	type AnnouncementDepositFactor = ProxyCost;
}
pub struct EthereumXcmEnsureProxy;
impl xcm_primitives::EnsureProxy<AccountId> for EthereumXcmEnsureProxy {
2
	fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> {
		// The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies
1
		let def: pallet_proxy::ProxyDefinition<AccountId, ProxyType, BlockNumber> =
2
			pallet_proxy::Pallet::<Runtime>::find_proxy(
2
				&delegator,
2
				&delegatee,
2
				Some(ProxyType::Any),
2
			)
2
			.map_err(|_| "proxy error: expected `ProxyType::Any`")?;
		// We only allow to use it for delay zero proxies, as the call will iMmediatly be executed
1
		ensure!(def.delay.is_zero(), "proxy delay is Non-zero`");
1
		Ok(())
2
	}
}
impl pallet_ethereum_xcm::Config for Runtime {
	type RuntimeEvent = RuntimeEvent;
	type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper;
	type ValidatedTransaction = pallet_ethereum::ValidatedTransaction<Self>;
	type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction;
	type ReservedXcmpWeight = ReservedXcmpWeight;
	type EnsureProxy = EthereumXcmEnsureProxy;
	type ControllerOrigin = EnsureRoot<AccountId>;
	type ForceOrigin = EnsureRoot<AccountId>;
}
type Block = frame_system::mocking::MockBlockU32<Runtime>;
10098
construct_runtime!(
1882
	pub enum Runtime	{
1882
		System: frame_system,
1882
		Balances: pallet_balances,
1882
		MsgQueue: mock_msg_queue,
1882
		XcmVersioner: mock_version_changer,
1882

            
1882
		PolkadotXcm: pallet_xcm,
1882
		Assets: pallet_assets,
1882
		CumulusXcm: cumulus_pallet_xcm,
1882
		AssetManager: pallet_asset_manager,
1882
		XcmTransactor: pallet_xcm_transactor,
1882
		XcmWeightTrader: pallet_xcm_weight_trader,
1882
		Treasury: pallet_treasury,
1882
		Proxy: pallet_proxy,
1882

            
1882
		Timestamp: pallet_timestamp,
1882
		EVM: pallet_evm,
1882
		Ethereum: pallet_ethereum,
1882
		EthereumXcm: pallet_ethereum_xcm,
1882
		EvmForeignAssets: pallet_moonbeam_foreign_assets,
1882
	}
10288
);
7
pub(crate) fn para_events() -> Vec<RuntimeEvent> {
7
	System::events()
7
		.into_iter()
76
		.map(|r| r.event)
76
		.filter_map(|e| Some(e))
7
		.collect::<Vec<_>>()
7
}
use frame_support::traits::{OnFinalize, OnInitialize, UncheckedOnRuntimeUpgrade};
use moonbase_runtime::{currency, xcm_config::LocationToH160, BLOCK_STORAGE_LIMIT, MAX_POV_SIZE};
use pallet_evm::FrameSystemAccountProvider;
use xcm_primitives::AsAssetType;
2
pub(crate) fn on_runtime_upgrade() {
2
	VersionUncheckedMigrateToV1::<Runtime>::on_runtime_upgrade();
2
}
3
pub(crate) fn para_roll_to(n: BlockNumber) {
6
	while System::block_number() < n {
3
		PolkadotXcm::on_finalize(System::block_number());
3
		Balances::on_finalize(System::block_number());
3
		System::on_finalize(System::block_number());
3
		System::set_block_number(System::block_number() + 1);
3
		System::on_initialize(System::block_number());
3
		Balances::on_initialize(System::block_number());
3
		PolkadotXcm::on_initialize(System::block_number());
3
	}
3
}