-
Notifications
You must be signed in to change notification settings - Fork 83
/
xcm_config.rs
749 lines (691 loc) · 27.1 KB
/
xcm_config.rs
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// This file is part of Bifrost.
// Copyright (C) Liebi Technologies PTE. LTD.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{
AccountId, CurrencyId, CurrencyIdMapping, TokenSymbol, DOT_TOKEN_ID, GLMR_TOKEN_ID,
};
pub use bifrost_xcm_interface::traits::{parachains, XcmBaseWeight};
use cumulus_primitives_core::AggregateMessageOrigin;
pub use cumulus_primitives_core::ParaId;
use frame_support::{
ensure,
sp_runtime::traits::{CheckedConversion, Convert},
traits::{ContainsPair, Get, ProcessMessageError, TransformOrigin},
};
use orml_traits::location::Reserve;
pub use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key, MultiCurrency};
use pallet_xcm::XcmPassthrough;
use parity_scale_codec::{Decode, Encode};
pub use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use sp_core::bounded::BoundedVec;
use sp_std::{convert::TryFrom, marker::PhantomData};
pub use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
use xcm_builder::{
DescribeAllTerminal, DescribeFamily, FrameTransactionalProcessor, HashedDescription,
TrailingSetTopicAsId,
};
use xcm_executor::traits::{MatchesFungible, ShouldExecute};
// orml imports
use bifrost_currencies::BasicCurrencyAdapter;
use bifrost_runtime_common::currency_adapter::{
BifrostDropAssets, DepositToAlternative, MultiCurrencyAdapter,
};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
use xcm::v4::{prelude::*, Asset, AssetId, InteriorLocation, Location};
/// Bifrost Asset Matcher
pub struct BifrostAssetMatcher<CurrencyId, CurrencyIdConvert>(
PhantomData<(CurrencyId, CurrencyIdConvert)>,
);
impl<CurrencyId, CurrencyIdConvert, Amount> MatchesFungible<Amount>
for BifrostAssetMatcher<CurrencyId, CurrencyIdConvert>
where
CurrencyIdConvert: Convert<Location, Option<CurrencyId>>,
Amount: TryFrom<u128>,
{
fn matches_fungible(a: &Asset) -> Option<Amount> {
if let (Fungible(ref amount), AssetId(ref location)) = (&a.fun, &a.id) {
if CurrencyIdConvert::convert(location.clone()).is_some() {
return CheckedConversion::checked_from(*amount);
}
}
None
}
}
/// A `FilterAssetLocation` implementation. Filters multi native assets whose
/// reserve is same with `origin`.
pub struct MultiNativeAsset<ReserveProvider>(PhantomData<ReserveProvider>);
impl<ReserveProvider> ContainsPair<Asset, Location> for MultiNativeAsset<ReserveProvider>
where
ReserveProvider: Reserve,
{
fn contains(asset: &Asset, origin: &Location) -> bool {
if let Some(ref reserve) = ReserveProvider::reserve(asset) {
if reserve == origin {
return true;
}
}
false
}
}
fn native_currency_location(id: CurrencyId) -> Location {
Location::new(0, [Junction::from(BoundedVec::try_from(id.encode()).unwrap())])
}
impl<T: Get<ParaId>> Convert<Asset, Option<CurrencyId>> for BifrostCurrencyIdConvert<T> {
fn convert(asset: Asset) -> Option<CurrencyId> {
if let Asset { id: AssetId(id), fun: xcm::v4::Fungibility::Fungible(_) } = asset {
Self::convert(id)
} else {
None
}
}
}
pub struct BifrostAccountIdToLocation;
impl Convert<AccountId, Location> for BifrostAccountIdToLocation {
fn convert(account: AccountId) -> Location {
[AccountId32 { network: None, id: account.into() }].into()
}
}
pub struct BifrostCurrencyIdConvert<T>(PhantomData<T>);
impl<T: Get<ParaId>> Convert<CurrencyId, Option<Location>> for BifrostCurrencyIdConvert<T> {
fn convert(id: CurrencyId) -> Option<Location> {
use CurrencyId::*;
use TokenSymbol::*;
if let Some(id) = AssetIdMaps::<Runtime>::get_location(id) {
return Some(id);
}
match id {
Token2(DOT_TOKEN_ID) => Some(Location::parent()),
Native(BNC) => Some(native_currency_location(id)),
// Moonbeam Native token
Token2(GLMR_TOKEN_ID) => Some(Location::new(
1,
[
Parachain(parachains::moonbeam::ID),
PalletInstance(parachains::moonbeam::PALLET_ID.into()),
],
)),
_ => None,
}
}
}
impl<T: Get<ParaId>> Convert<Location, Option<CurrencyId>> for BifrostCurrencyIdConvert<T> {
fn convert(location: Location) -> Option<CurrencyId> {
use CurrencyId::*;
use TokenSymbol::*;
if location == Location::parent() {
return Some(Token2(DOT_TOKEN_ID));
}
if let Some(currency_id) = AssetIdMaps::<Runtime>::get_currency_id(location.clone()) {
return Some(currency_id);
}
match &location.unpack() {
(0, [Parachain(id), PalletInstance(index)])
if (*id == parachains::moonbeam::ID) &&
(*index == parachains::moonbeam::PALLET_ID) =>
Some(Token2(GLMR_TOKEN_ID)),
(0, [Parachain(id), GeneralKey { data, length }])
if *id == u32::from(ParachainInfo::parachain_id()) =>
{
let key = &data[..*length as usize];
if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) {
match currency_id {
Native(BNC) => Some(currency_id),
_ => None,
}
} else {
None
}
},
(0, [GeneralKey { data, length }]) => {
// decode the general key
let key = &data[..*length as usize];
if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) {
match currency_id {
Native(BNC) => Some(currency_id),
_ => None,
}
} else {
None
}
},
_ => None,
}
}
}
parameter_types! {
pub const DotLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = Polkadot;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub SelfParaChainId: CumulusParaId = ParachainInfo::parachain_id();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
}
/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
/// `Transact` in order to determine the dispatch RuntimeOrigin.
pub type LocationToAccountId = (
// The parent (Relay-chain) origin converts to the parent `AccountId`.
ParentIsPreset<AccountId>,
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign locations alias into accounts according to a hash of their standard description.
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
);
/// This is the type we use to convert an (incoming) XCM origin into a local `RuntimeOrigin`
/// instance, ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind`
/// which can biases the kind of local `RuntimeOrigin` it will become.
pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// recognized.
RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
// recognized.
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
// transaction from the Root origin.
ParentAsSuperuser<RuntimeOrigin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `RuntimeOrigin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<RuntimeOrigin>,
);
parameter_types! {
// One XCM operation is 200_000_000 weight, cross-chain transfer ~= 2x of transfer = 3_000_000_000
pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0);
pub const MaxInstructions: u32 = 100;
}
/// Barrier allowing a top level paid message with DescendOrigin instruction
pub const DEFAULT_PROOF_SIZE: u64 = 64 * 1024;
pub const DEFAULT_REF_TIMR: u64 = 10_000_000_000;
pub struct AllowTopLevelPaidExecutionDescendOriginFirst<T>(PhantomData<T>);
impl<T: Contains<Location>> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst<T> {
fn should_execute<Call>(
origin: &Location,
message: &mut [Instruction<Call>],
max_weight: Weight,
_weight_credit: &mut Properties,
) -> Result<(), ProcessMessageError> {
log::trace!(
target: "xcm::barriers",
"AllowTopLevelPaidExecutionDescendOriginFirst origin:
{:?}, message: {:?}, max_weight: {:?}, weight_credit: {:?}",
origin, message, max_weight, _weight_credit,
);
ensure!(T::contains(origin), ProcessMessageError::Unsupported);
let mut iter = message.iter_mut();
// Make sure the first instruction is DescendOrigin
iter.next()
.filter(|instruction| matches!(instruction, DescendOrigin(_)))
.ok_or(ProcessMessageError::Unsupported)?;
// Then WithdrawAsset
iter.next()
.filter(|instruction| matches!(instruction, WithdrawAsset(_)))
.ok_or(ProcessMessageError::Unsupported)?;
// Then BuyExecution
let i = iter.next().ok_or(ProcessMessageError::Unsupported)?;
match i {
BuyExecution { weight_limit: Limited(ref mut weight), .. } => {
if weight.all_gte(max_weight) {
weight.set_ref_time(max_weight.ref_time());
weight.set_proof_size(max_weight.proof_size());
};
},
BuyExecution { ref mut weight_limit, .. } if weight_limit == &Unlimited => {
*weight_limit = Limited(max_weight);
},
_ => {},
};
// Then Transact
let i = iter.next().ok_or(ProcessMessageError::Unsupported)?;
match i {
Transact { ref mut require_weight_at_most, .. } => {
let weight = Weight::from_parts(DEFAULT_REF_TIMR, DEFAULT_PROOF_SIZE);
*require_weight_at_most = weight;
Ok(())
},
_ => Err(ProcessMessageError::Unsupported),
}
}
}
pub type Barrier = TrailingSetTopicAsId<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
// Barrier allowing a top level paid message with DescendOrigin instruction
AllowTopLevelPaidExecutionDescendOriginFirst<Everything>,
)>;
pub type BifrostAssetTransactor = MultiCurrencyAdapter<
Currencies,
UnknownTokens,
BifrostAssetMatcher<CurrencyId, BifrostCurrencyIdConvert<SelfParaChainId>>,
AccountId,
LocationToAccountId,
CurrencyId,
BifrostCurrencyIdConvert<SelfParaChainId>,
DepositToAlternative<BifrostTreasuryAccount, Currencies, CurrencyId, AccountId, Balance>,
>;
parameter_types! {
pub DotPerSecond: (AssetId,u128, u128) = (Location::parent().into(), dot_per_second::<Runtime>(),0);
pub BncPerSecond: (AssetId,u128, u128) = (
Location::new(
1,
[xcm::v4::Junction::Parachain(SelfParaId::get()), xcm::v4::Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())],
).into(),
// BNC:DOT = 80:1
dot_per_second::<Runtime>() * 80,
0
);
pub BncNewPerSecond: (AssetId,u128, u128) = (
Location::new(
0,
[xcm::v4::Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())]
).into(),
// BNC:DOT = 80:1
dot_per_second::<Runtime>() * 80,
0
);
pub ZlkPerSecond: (AssetId, u128,u128) = (
Location::new(
1,
[xcm::v4::Junction::Parachain(SelfParaId::get()), xcm::v4::Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())]
).into(),
// ZLK:KSM = 150:1
dot_per_second::<Runtime>() * 150 * 1_000_000,
0
);
pub ZlkNewPerSecond: (AssetId, u128,u128) = (
Location::new(
0,
[xcm::v4::Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())]
).into(),
// ZLK:KSM = 150:1
dot_per_second::<Runtime>() * 150 * 1_000_000,
0
);
pub BasePerSecond: u128 = dot_per_second::<Runtime>();
}
pub struct ToTreasury;
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: Asset) {
if let Asset { id: AssetId(location), fun: xcm::v4::Fungibility::Fungible(amount) } =
revenue
{
if let Some(currency_id) =
BifrostCurrencyIdConvert::<SelfParaChainId>::convert(location)
{
let _ = Currencies::deposit(currency_id, &BifrostTreasuryAccount::get(), amount);
}
}
}
}
pub type Trader = (
FixedRateOfFungible<BncPerSecond, ToTreasury>,
FixedRateOfFungible<BncNewPerSecond, ToTreasury>,
FixedRateOfFungible<DotPerSecond, ToTreasury>,
FixedRateOfAsset<Runtime, BasePerSecond, ToTreasury>,
);
/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
/// account for proof size weights.
///
/// Calls that are allowed through this filter must:
/// 1. Have a fixed weight;
/// 2. Cannot lead to another call being made;
/// 3. Have a defined proof size weight, e.g. no unbounded vecs in call parameters.
pub struct SafeCallFilter;
impl Contains<RuntimeCall> for SafeCallFilter {
fn contains(call: &RuntimeCall) -> bool {
#[cfg(feature = "runtime-benchmarks")]
{
if matches!(call, RuntimeCall::System(frame_system::Call::remark_with_event { .. })) {
return true;
}
}
match call {
RuntimeCall::System(
frame_system::Call::kill_prefix { .. } | frame_system::Call::set_heap_pages { .. },
) |
RuntimeCall::Timestamp(..) |
RuntimeCall::Indices(..) |
RuntimeCall::Balances(..) |
RuntimeCall::Session(pallet_session::Call::purge_keys { .. }) |
RuntimeCall::Treasury(..) |
RuntimeCall::Utility(pallet_utility::Call::as_derivative { .. }) |
RuntimeCall::Identity(
pallet_identity::Call::add_registrar { .. } |
pallet_identity::Call::set_identity { .. } |
pallet_identity::Call::clear_identity { .. } |
pallet_identity::Call::request_judgement { .. } |
pallet_identity::Call::cancel_request { .. } |
pallet_identity::Call::set_fee { .. } |
pallet_identity::Call::set_account_id { .. } |
pallet_identity::Call::set_fields { .. } |
pallet_identity::Call::provide_judgement { .. } |
pallet_identity::Call::kill_identity { .. } |
pallet_identity::Call::add_sub { .. } |
pallet_identity::Call::rename_sub { .. } |
pallet_identity::Call::remove_sub { .. } |
pallet_identity::Call::quit_sub { .. },
) |
RuntimeCall::Vesting(..) |
RuntimeCall::PolkadotXcm(pallet_xcm::Call::limited_reserve_transfer_assets { .. }) |
RuntimeCall::Proxy(..) |
RuntimeCall::Tokens(
orml_tokens::Call::transfer { .. } |
orml_tokens::Call::transfer_all { .. } |
orml_tokens::Call::transfer_keep_alive { .. }
) |
// Bifrost moudule
RuntimeCall::Farming(
bifrost_farming::Call::claim { .. } |
bifrost_farming::Call::deposit { .. } |
bifrost_farming::Call::withdraw { .. } |
bifrost_farming::Call::withdraw_claim { .. }
) |
RuntimeCall::Salp(
bifrost_salp::Call::contribute { .. } |
bifrost_salp::Call::batch_unlock { .. } |
bifrost_salp::Call::redeem { .. } |
bifrost_salp::Call::unlock { .. } |
bifrost_salp::Call::unlock_by_vsbond { .. } |
bifrost_salp::Call::unlock_vstoken { .. }
) |
RuntimeCall::TokenConversion(
bifrost_vstoken_conversion::Call::vsbond_convert_to_vstoken { .. } |
bifrost_vstoken_conversion::Call::vstoken_convert_to_vsbond { .. }
) |
RuntimeCall::VeMinting(
bifrost_ve_minting::Call::increase_amount { .. } |
bifrost_ve_minting::Call::increase_unlock_time { .. } |
bifrost_ve_minting::Call::withdraw { .. } |
bifrost_ve_minting::Call::get_rewards { .. }
) |
RuntimeCall::VtokenMinting(
bifrost_vtoken_minting::Call::mint { .. } |
bifrost_vtoken_minting::Call::rebond { .. } |
bifrost_vtoken_minting::Call::rebond_by_unlock_id { .. } |
bifrost_vtoken_minting::Call::redeem { .. }
) |
RuntimeCall::XcmInterface(
bifrost_xcm_interface::Call::transfer_statemine_assets { .. }
) |
RuntimeCall::Slpx(..) |
RuntimeCall::ZenlinkProtocol(
zenlink_protocol::Call::add_liquidity { .. } |
zenlink_protocol::Call::remove_liquidity { .. } |
zenlink_protocol::Call::transfer { .. }
) => true,
_ => false,
}
}
}
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type AssetClaims = PolkadotXcm;
type AssetTransactor = BifrostAssetTransactor;
type AssetTrap = BifrostDropAssets<ToTreasury>;
type Barrier = Barrier;
type RuntimeCall = RuntimeCall;
type IsReserve = MultiNativeAsset<RelativeReserveProvider>;
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type ResponseHandler = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
type Trader = Trader;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmSender = XcmRouter;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = ConstU32<8>;
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = SafeCallFilter;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type MessageExporter = ();
type Aliasers = Nothing;
type TransactionalProcessor = FrameTransactionalProcessor;
}
/// Local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<Location> = Some(Parent.into());
}
impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type UniversalLocation = UniversalLocation;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmReserveTransferFilter = Everything;
#[cfg(feature = "runtime-benchmarks")]
type XcmRouter = bifrost_primitives::DoNothingRouter;
#[cfg(not(feature = "runtime-benchmarks"))]
type XcmRouter = XcmRouter;
type XcmTeleportFilter = Nothing;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = weights::pallet_xcm::WeightInfo<Runtime>;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
}
impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
parameter_types! {
pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
}
impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ChannelInfo = ParachainSystem;
type RuntimeEvent = RuntimeEvent;
type VersionWrapper = PolkadotXcm;
type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
type MaxInboundSuspended = ConstU32<1_000>;
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
}
parameter_types! {
pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
}
impl pallet_message_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_message_queue::weights::SubstrateWeight<Self>;
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = xcm_builder::ProcessXcmMessage<
AggregateMessageOrigin,
xcm_executor::XcmExecutor<XcmConfig>,
RuntimeCall,
>;
type Size = u32;
type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
type HeapSize = ConstU32<{ 64 * 1024 }>;
type MaxStale = ConstU32<8>;
type ServiceWeight = MessageQueueServiceWeight;
}
// orml runtime start
impl bifrost_currencies::Config for Runtime {
type GetNativeCurrencyId = NativeCurrencyId;
type MultiCurrency = Tokens;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances, Amount, BlockNumber>;
type WeightInfo = weights::bifrost_currencies::WeightInfo<Runtime>;
}
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
&CurrencyId::Native(TokenSymbol::BNC) => 10 * milli::<Runtime>(NativeCurrencyId::get()), // 0.01 BNC
&CurrencyId::Token2(DOT_TOKEN_ID) => 1_000_000, // DOT
&CurrencyId::LPToken(..) => 1 * micro::<Runtime>(NativeCurrencyId::get()),
CurrencyId::ForeignAsset(foreign_asset_id) => {
AssetIdMaps::<Runtime>::get_asset_metadata(AssetIds::ForeignAssetId(*foreign_asset_id)).
map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
},
_ => AssetIdMaps::<Runtime>::get_currency_metadata(*currency_id)
.map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
}
};
}
pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
AccountIdConversion::<AccountId>::into_account_truncating(&TreasuryPalletId::get()).eq(a) ||
AccountIdConversion::<AccountId>::into_account_truncating(&BifrostCrowdloanId::get())
.eq(a) || AccountIdConversion::<AccountId>::into_account_truncating(
&BifrostVsbondPalletId::get(),
)
.eq(a) || AccountIdConversion::<AccountId>::into_account_truncating(
&SlpEntrancePalletId::get(),
)
.eq(a) || AccountIdConversion::<AccountId>::into_account_truncating(&SlpExitPalletId::get())
.eq(a) || FarmingKeeperPalletId::get().check_sub_account::<PoolId>(a) ||
FarmingRewardIssuerPalletId::get().check_sub_account::<PoolId>(a) ||
AccountIdConversion::<AccountId>::into_account_truncating(&BuybackPalletId::get())
.eq(a) || AccountIdConversion::<AccountId>::into_account_truncating(
&SystemMakerPalletId::get(),
)
.eq(a) || FeeSharePalletId::get().check_sub_account::<DistributionId>(a) ||
a.eq(&ZenklinkFeeAccount::get()) ||
AccountIdConversion::<AccountId>::into_account_truncating(&CommissionPalletId::get())
.eq(a) || AccountIdConversion::<AccountId>::into_account_truncating(&BuyBackAccount::get())
.eq(a) ||
AccountIdConversion::<AccountId>::into_account_truncating(&LiquidityAccount::get())
.eq(a)
}
}
parameter_types! {
pub BifrostTreasuryAccount: AccountId = TreasuryPalletId::get().into_account_truncating();
// gVLo8SqxQsm11cXpkFJnaqXhAd6qtxwi2DhxfUFE7pSiyoi
pub ZenklinkFeeAccount: AccountId = hex!["d2ca9ceb400cc68dcf58de4871bd261406958fd17338d2d82ad2592db62e6a2a"].into();
}
pub struct CurrencyHooks;
impl MutationHooks<AccountId, CurrencyId, Balance> for CurrencyHooks {
type OnDust = orml_tokens::TransferDust<Runtime, BifrostTreasuryAccount>;
type OnSlash = ();
type PreDeposit = ();
type PostDeposit = ();
type PreTransfer = ();
type PostTransfer = ();
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}
impl orml_tokens::Config for Runtime {
type Amount = Amount;
type Balance = Balance;
type CurrencyId = CurrencyId;
type DustRemovalWhitelist = DustRemovalWhitelist;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposits = ExistentialDeposits;
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
type WeightInfo = weights::orml_tokens::WeightInfo<Runtime>;
type CurrencyHooks = CurrencyHooks;
}
parameter_types! {
pub SelfLocation: Location = Location::new(1, [Parachain(ParachainInfo::get().into())]);
pub SelfRelativeLocation: Location = Location::here();
pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0);
pub const MaxAssetsForTransfer: usize = 2;
}
parameter_type_with_key! {
pub ParachainMinFee: |_location: Location| -> Option<u128> {
Some(u128::MAX)
};
}
impl orml_xtokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = BifrostCurrencyIdConvert<ParachainInfo>;
type AccountIdToLocation = BifrostAccountIdToLocation;
type UniversalLocation = UniversalLocation;
type SelfLocation = SelfRelativeLocation;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type BaseXcmWeight = BaseXcmWeight;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MinXcmFee = ParachainMinFee;
type LocationsFilter = Everything;
type ReserveProvider = RelativeReserveProvider;
type RateLimiter = ();
type RateLimiterId = ();
}
impl orml_unknown_tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl orml_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SovereignOrigin = MoreThanHalfCouncil;
}
parameter_types! {
pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating();
}
impl bifrost_xcm_interface::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type UpdateOrigin = TechAdminOrCouncil;
type MultiCurrency = Currencies;
type RelayNetwork = RelayNetwork;
type RelaychainCurrencyId = RelayCurrencyId;
type ParachainSovereignAccount = ParachainAccount;
type XcmExecutor = XcmExecutor<XcmConfig>;
type AccountIdToLocation = BifrostAccountIdToLocation;
type SalpHelper = Salp;
type ParachainId = SelfParaChainId;
type CallBackTimeOut = ConstU32<10>;
type CurrencyIdConvert = AssetIdMaps<Runtime>;
}