xcm_simulator_example/parachain/
mod.rs1mod xcm_config;
20pub use xcm_config::*;
21
22use core::marker::PhantomData;
23use frame_support::{
24 construct_runtime, derive_impl, parameter_types,
25 traits::{
26 ConstU128, ContainsPair, Disabled, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing,
27 },
28 weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
29};
30use frame_system::EnsureRoot;
31use sp_core::ConstU32;
32use sp_runtime::{
33 traits::{Get, IdentityLookup},
34 AccountId32,
35};
36use xcm::latest::prelude::*;
37use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32};
38use xcm_executor::{traits::ConvertLocation, XcmExecutor};
39use xcm_simulator::mock_message_queue;
40
41pub type AccountId = AccountId32;
42pub type Balance = u128;
43
44parameter_types! {
45 pub const BlockHashCount: u64 = 250;
46}
47
48#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
49impl frame_system::Config for Runtime {
50 type AccountId = AccountId;
51 type Lookup = IdentityLookup<Self::AccountId>;
52 type Block = Block;
53 type AccountData = pallet_balances::AccountData<Balance>;
54}
55
56#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
57impl pallet_balances::Config for Runtime {
58 type Balance = Balance;
59 type ExistentialDeposit = ConstU128<1>;
60 type AccountStore = System;
61}
62
63#[cfg(feature = "runtime-benchmarks")]
64pub struct UniquesHelper;
65#[cfg(feature = "runtime-benchmarks")]
66impl pallet_uniques::BenchmarkHelper<Location, AssetInstance> for UniquesHelper {
67 fn collection(i: u16) -> Location {
68 GeneralIndex(i as u128).into()
69 }
70 fn item(i: u16) -> AssetInstance {
71 AssetInstance::Index(i as u128)
72 }
73}
74
75impl pallet_uniques::Config for Runtime {
76 type RuntimeEvent = RuntimeEvent;
77 type CollectionId = Location;
78 type ItemId = AssetInstance;
79 type Currency = Balances;
80 type CreateOrigin = ForeignCreators;
81 type ForceOrigin = frame_system::EnsureRoot<AccountId>;
82 type CollectionDeposit = frame_support::traits::ConstU128<1_000>;
83 type ItemDeposit = frame_support::traits::ConstU128<1_000>;
84 type MetadataDepositBase = frame_support::traits::ConstU128<1_000>;
85 type AttributeDepositBase = frame_support::traits::ConstU128<1_000>;
86 type DepositPerByte = frame_support::traits::ConstU128<1>;
87 type StringLimit = ConstU32<64>;
88 type KeyLimit = ConstU32<64>;
89 type ValueLimit = ConstU32<128>;
90 type Locker = ();
91 type WeightInfo = ();
92 #[cfg(feature = "runtime-benchmarks")]
93 type Helper = UniquesHelper;
94}
95
96pub struct ForeignCreators;
99impl EnsureOriginWithArg<RuntimeOrigin, Location> for ForeignCreators {
100 type Success = AccountId;
101
102 fn try_origin(
103 o: RuntimeOrigin,
104 a: &Location,
105 ) -> core::result::Result<Self::Success, RuntimeOrigin> {
106 let origin_location = pallet_xcm::EnsureXcm::<Everything>::try_origin(o.clone())?;
107 if !a.starts_with(&origin_location) {
108 return Err(o);
109 }
110 xcm_config::location_converter::LocationConverter::convert_location(&origin_location)
111 .ok_or(o)
112 }
113
114 #[cfg(feature = "runtime-benchmarks")]
115 fn try_successful_origin(a: &Location) -> Result<RuntimeOrigin, ()> {
116 Ok(pallet_xcm::Origin::Xcm(a.clone()).into())
117 }
118}
119
120parameter_types! {
121 pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0);
122 pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0);
123}
124
125impl mock_message_queue::Config for Runtime {
126 type RuntimeEvent = RuntimeEvent;
127 type XcmExecutor = XcmExecutor<XcmConfig>;
128}
129
130pub type LocalOriginToLocation =
131 SignedToAccountId32<RuntimeOrigin, AccountId, constants::RelayNetwork>;
132
133pub struct TrustedLockerCase<T>(PhantomData<T>);
134impl<T: Get<(Location, AssetFilter)>> ContainsPair<Location, Asset> for TrustedLockerCase<T> {
135 fn contains(origin: &Location, asset: &Asset) -> bool {
136 let (o, a) = T::get();
137 a.matches(asset) && &o == origin
138 }
139}
140
141parameter_types! {
142 pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible }));
143}
144
145pub type TrustedLockers = TrustedLockerCase<RelayTokenForRelay>;
146
147impl pallet_xcm::Config for Runtime {
148 type RuntimeEvent = RuntimeEvent;
149 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
150 type XcmRouter = XcmRouter;
151 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
152 type XcmExecuteFilter = Everything;
153 type XcmExecutor = XcmExecutor<XcmConfig>;
154 type XcmTeleportFilter = Nothing;
155 type XcmReserveTransferFilter = Everything;
156 type Weigher = weigher::Weigher;
157 type UniversalLocation = constants::UniversalLocation;
158 type RuntimeOrigin = RuntimeOrigin;
159 type RuntimeCall = RuntimeCall;
160 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
161 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
162 type Currency = Balances;
163 type CurrencyMatcher = ();
164 type TrustedLockers = TrustedLockers;
165 type SovereignAccountOf = location_converter::LocationConverter;
166 type MaxLockers = ConstU32<8>;
167 type MaxRemoteLockConsumers = ConstU32<0>;
168 type RemoteLockConsumerIdentifier = ();
169 type WeightInfo = pallet_xcm::TestWeightInfo;
170 type AdminOrigin = EnsureRoot<AccountId>;
171 type AuthorizedAliasConsideration = Disabled;
172}
173
174type Block = frame_system::mocking::MockBlock<Runtime>;
175
176construct_runtime!(
177 pub struct Runtime {
178 System: frame_system,
179 Balances: pallet_balances,
180 MsgQueue: mock_message_queue,
181 PolkadotXcm: pallet_xcm,
182 ForeignUniques: pallet_uniques,
183 }
184);