1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
use super::{AssetId, *};
use cumulus_primitives_core::ParaId;
use frame_support::{
traits::{Everything, Nothing},
PalletId,
};
use hydradx_adapters::{MultiCurrencyTrader, ToFeeReceiver};
use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use polkadot_xcm::latest::prelude::*;
use polkadot_xcm::latest::Error;
use primitives::Price;
use sp_runtime::traits::Convert;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
EnsureXcmOrigin, FixedWeightBounds, LocationInverter, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit,
};
use xcm_executor::{traits::WeightTrader, Assets, Config, XcmExecutor};
use polkadot_xcm::latest::Weight;
pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNetwork>;
pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowKnownQueryResponses<PolkadotXcm>,
AllowSubscriptionsFrom<Everything>,
invarch_xcm_builder::AllowPaidTinkernetMultisig,
);
parameter_types! {
pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
}
parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
pub type XcmOriginToCallOrigin = (
SovereignSignedViaLocation<LocationToAccountId, Origin>,
RelayChainAsNative<RelayChainOrigin, Origin>,
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,
SignedAccountId32AsNative<RelayNetwork, Origin>,
XcmPassthrough<Origin>,
invarch_xcm_builder::DeriveOriginFromTinkernetMultisig<Origin>,
);
parameter_types! {
pub const BaseXcmWeight: Weight = 100_000_000;
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsForTransfer: usize = 2;
}
pub struct TradePassthrough();
impl WeightTrader for TradePassthrough {
fn new() -> Self {
Self()
}
fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, Error> {
Ok(payment)
}
}
pub struct XcmConfig;
impl Config for XcmConfig {
type Call = Call;
type XcmSender = XcmRouter;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToCallOrigin;
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
type IsTeleporter = (); type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Trader = MultiCurrencyTrader<
AssetId,
Balance,
Price,
WeightToFee,
MultiTransactionPayment,
CurrencyIdConvert,
ToFeeReceiver<
AccountId,
AssetId,
Balance,
Price,
CurrencyIdConvert,
DepositAll<Runtime>,
MultiTransactionPayment,
>,
>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
}
impl cumulus_pallet_xcm::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = PolkadotXcm;
type ExecuteOverweightOrigin = MajorityTechCommitteeOrRoot;
type ControllerOrigin = MajorityTechCommitteeOrRoot;
type ControllerOriginConverter = XcmOriginToCallOrigin;
type WeightInfo = weights::xcmp_queue::BasiliskWeight<Runtime>;
}
impl cumulus_pallet_dmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ExecuteOverweightOrigin = MajorityTechCommitteeOrRoot;
}
parameter_type_with_key! {
pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
None
};
}
impl orml_xtokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
type CurrencyId = AssetId;
type CurrencyIdConvert = CurrencyIdConvert;
type AccountIdToMultiLocation = AccountIdToMultiLocation;
type SelfLocation = SelfLocation;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type BaseXcmWeight = BaseXcmWeight;
type LocationInverter = LocationInverter<Ancestry>;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MultiLocationsFilter = Everything;
type ReserveProvider = AbsoluteReserveProvider;
type MinXcmFee = ParachainMinFee;
}
impl orml_unknown_tokens::Config for Runtime {
type Event = Event;
}
impl orml_xcm::Config for Runtime {
type Event = Event;
type SovereignOrigin = SuperMajorityCouncilOrRoot;
}
impl pallet_xcm::Config for Runtime {
type Event = Event;
type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type LocationInverter = LocationInverter<Ancestry>;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
}
pub struct CurrencyIdConvert;
use primitives::constants::chain::CORE_ASSET_ID;
impl Convert<AssetId, Option<MultiLocation>> for CurrencyIdConvert {
fn convert(id: AssetId) -> Option<MultiLocation> {
match id {
CORE_ASSET_ID => Some(MultiLocation::new(
1,
X2(Parachain(ParachainInfo::get().into()), GeneralIndex(id.into())),
)),
_ => {
if let Some(loc) = AssetRegistry::asset_to_location(id) {
Some(loc.0)
} else {
None
}
}
}
}
}
impl Convert<MultiLocation, Option<AssetId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<AssetId> {
match location {
MultiLocation {
parents,
interior: X2(Parachain(id), GeneralIndex(index)),
} if parents == 1 && ParaId::from(id) == ParachainInfo::get() && (index as u32) == CORE_ASSET_ID => {
Some(CORE_ASSET_ID)
}
MultiLocation {
parents: 0,
interior: X1(GeneralIndex(index)),
} if (index as u32) == CORE_ASSET_ID => Some(CORE_ASSET_ID),
_ => AssetRegistry::location_to_asset(AssetLocation(location)),
}
}
}
impl Convert<MultiAsset, Option<AssetId>> for CurrencyIdConvert {
fn convert(asset: MultiAsset) -> Option<AssetId> {
if let MultiAsset {
id: Concrete(location), ..
} = asset
{
Self::convert(location)
} else {
None
}
}
}
pub struct AccountIdToMultiLocation;
impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
fn convert(account: AccountId) -> MultiLocation {
X1(AccountId32 {
network: NetworkId::Any,
id: account.into(),
})
.into()
}
}
pub type XcmRouter = (
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
XcmpQueue,
);
pub type LocationToAccountId = (
ParentIsPreset<AccountId>,
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountId32Aliases<RelayNetwork, AccountId>,
invarch_xcm_builder::TinkernetMultisigAsAccountId<AccountId>,
);
parameter_types! {
pub Alternative: AccountId = PalletId(*b"xcm/alte").into_account_truncating();
}
pub type LocalAssetTransactor = MultiCurrencyAdapter<
Currencies,
UnknownTokens,
IsNativeConcrete<AssetId, CurrencyIdConvert>,
AccountId,
LocationToAccountId,
AssetId,
CurrencyIdConvert,
DepositToAlternative<Alternative, Currencies, AssetId, AccountId, Balance>,
>;