-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathsystem.rs
More file actions
775 lines (701 loc) · 28.6 KB
/
Copy pathsystem.rs
File metadata and controls
775 lines (701 loc) · 28.6 KB
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
// This file is part of HydraDX-node.
// Copyright (C) 2020-2023 Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::*;
use crate::origins::GeneralAdmin;
use pallet_transaction_multi_payment::{DepositAll, TransferFees, WeightInfo};
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use primitives::constants::{
chain::{
BLOCK_PROCESSING_VELOCITY, CORE_ASSET_ID, DEFAULT_RELAY_PARENT_OFFSET, MAXIMUM_BLOCK_WEIGHT,
RELAY_CHAIN_SLOT_DURATION_MILLIS, UNINCLUDED_SEGMENT_CAPACITY,
},
currency::{deposit, CENTS, DOLLARS, MILLICENTS},
time::{DAYS, HOURS, SLOT_DURATION},
};
use crate::circuit_breaker::IgnoreWithdrawFuse;
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::cmp::Ordering;
use frame_support::migrations::FailedMigrationHandling;
use frame_support::{
dispatch::DispatchClass,
parameter_types,
sp_runtime::{
traits::{ConstU32, ConstU64, IdentityLookup},
FixedPointNumber, Perbill, Perquintill, RuntimeDebug,
},
traits::{
fungible::HoldConsideration, ConstBool, Contains, EitherOf, InstanceFilter, LinearStoragePrice, PrivilegeCmp,
SortedMembers,
},
weights::{
constants::{BlockExecutionWeight, RocksDbWeight},
ConstantMultiplier, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
},
PalletId,
};
use frame_system::EnsureRoot;
use hydradx_adapters::{OraclePriceProvider, RelayChainBlockNumberProvider};
use pallet_broadcast::types::ExecutionType;
use pallet_utility::BatchHook;
use scale_info::TypeInfo;
use sp_runtime::DispatchResult;
pub struct CallFilter;
impl Contains<RuntimeCall> for CallFilter {
fn contains(call: &RuntimeCall) -> bool {
if matches!(
call,
RuntimeCall::System(_)
| RuntimeCall::ConvictionVoting(_)
| RuntimeCall::Timestamp(_)
| RuntimeCall::ParachainSystem(_)
| RuntimeCall::Preimage(_)
| RuntimeCall::Referenda(_)
| RuntimeCall::TransactionPause(_)
| RuntimeCall::Whitelist(_)
) {
// always allow
// Note: this is done to avoid unnecessary check of paused storage, and to
// ensure that critical functions cannot be paused by TechnicalCommittee
return true;
}
if pallet_transaction_pause::PausedTransactionFilter::<Runtime>::contains(call) {
// if paused, dont allow!
return false;
}
let hub_asset_id = <Runtime as pallet_omnipool::Config>::HubAssetId::get();
// filter transfers of LRNA and omnipool assets to the omnipool account
if let RuntimeCall::Tokens(orml_tokens::Call::transfer { dest, currency_id, .. })
| RuntimeCall::Tokens(orml_tokens::Call::transfer_keep_alive { dest, currency_id, .. })
| RuntimeCall::Tokens(orml_tokens::Call::transfer_all { dest, currency_id, .. })
| RuntimeCall::Currencies(pallet_currencies::Call::transfer { dest, currency_id, .. }) = call
{
// Lookup::lookup() is not necessary thanks to IdentityLookup
if dest == &Omnipool::protocol_account() && (*currency_id == hub_asset_id || Omnipool::exists(*currency_id))
{
return false;
}
}
// filter transfers of HDX to the omnipool account
if let RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { dest, .. })
| RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { dest, .. })
| RuntimeCall::Balances(pallet_balances::Call::transfer_all { dest, .. })
| RuntimeCall::Currencies(pallet_currencies::Call::transfer_native_currency { dest, .. }) = call
{
// Lookup::lookup() is not necessary thanks to IdentityLookup
if dest == &Omnipool::protocol_account() {
return false;
}
}
// XYK pools with LRNA are not allowed
if let RuntimeCall::XYK(pallet_xyk::Call::create_pool { asset_a, asset_b, .. }) = call {
if *asset_a == hub_asset_id || *asset_b == hub_asset_id {
return false;
}
}
match call {
// create and create2 are only allowed through RPC or Runtime API
RuntimeCall::EVM(pallet_evm::Call::create { .. }) => false,
RuntimeCall::EVM(pallet_evm::Call::create2 { .. }) => false,
RuntimeCall::OrmlXcm(_) => false,
//NOTE: this prevents creation of thombstone positions if nft was burned outside
//of pallet that created it.
RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) => false,
RuntimeCall::Router(pallet_route_executor::Call::set_route { .. }) => false,
_ => true,
}
}
}
/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic
/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_perthousand(25);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
/// Block weights base values and limits.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have an extra reserved space, so that they
// are included even if block reachd `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
pub ExtrinsicBaseWeight: Weight = get_extrinsic_base_weight();
pub const BlockHashCount: BlockNumber = 2400;
/// Maximum length of block. Up to 5MB.
pub BlockLength: frame_system::limits::BlockLength =
frame_system::limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 0;
}
//We get the base and add the multi payment overhead until we have proper solution for calculating ExtrinsicBaseWeight by using the benchmark overhead command.
pub fn get_extrinsic_base_weight() -> Weight {
let mut base_weight = frame_support::weights::constants::ExtrinsicBaseWeight::get();
let multi_payment_overhead =
crate::weights::pallet_transaction_multi_payment::HydraWeight::<Runtime>::withdraw_fee();
base_weight.saturating_accrue(multi_payment_overhead);
base_weight
}
impl frame_system::Config for Runtime {
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// The basic call filter to use in dispatchable.
type BaseCallFilter = CallFilter;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
/// The ubiquitous origin type.
type RuntimeOrigin = RuntimeOrigin;
/// The aggregated dispatch type that is available for extrinsics.
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
/// The index type for storing how many extrinsics an account has signed.
type Nonce = Index;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = IdentityLookup<AccountId>;
/// The index type for blocks.
type Block = Block;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// The weight of the overhead invoked on the block import process, independent of the
/// extrinsics included in that block.
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = weights::frame_system::HydraWeight<Runtime>;
type SS58Prefix = SS58Prefix;
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type SingleBlockMigrations = migrations::SingleBlockMigrationsList;
type MultiBlockMigrator = MultiBlockMigrations;
type PreInherents = ();
type PostInherents = ();
type PostTransactions = ();
type ExtensionsWeightInfo = weights::frame_system_extensions::HydraWeight<Runtime>;
}
parameter_types! {
pub MaxServiceWeight: Weight = NORMAL_DISPATCH_RATIO * BlockWeights::get().max_block;
}
impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
#[cfg(not(feature = "runtime-benchmarks"))]
type Migrations = migrations::MultiBlockMigrationsList;
#[cfg(feature = "runtime-benchmarks")]
type Migrations = pallet_migrations::mock_helpers::MockedMigrations;
type CursorMaxLen = ConstU32<65_536>;
type IdentifierMaxLen = ConstU32<256>;
type MigrationStatusHandler = ();
type FailedMigrationHandler = LogErrorAndForceUnstuck;
type MaxServiceWeight = MaxServiceWeight;
type WeightInfo = weights::pallet_migrations::HydraWeight<Runtime>;
}
pub struct LogErrorAndForceUnstuck;
impl frame_support::migrations::FailedMigrationHandler for LogErrorAndForceUnstuck {
fn failed(migration: Option<u32>) -> FailedMigrationHandling {
log::error!(
target: "runtime::migrations",
"Migration {migration:?} failed - halting all migrations and resuming chain"
);
// Clear the migration cursor entirely. Transactions resume, remaining migrations are
// skipped. State may be inconsistent.
FailedMigrationHandling::ForceUnstuck
}
}
parameter_types! {
pub const NativeAssetId : AssetId = CORE_ASSET_ID;
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::HydraWeight<Runtime>;
}
parameter_types! {
pub ReservedXcmpWeight: Weight = BlockWeights::get().max_block / 4;
pub ReservedDmpWeight: Weight = BlockWeights::get().max_block / 4;
}
pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
pub struct RelayParentOffset;
impl Get<u32> for RelayParentOffset {
fn get() -> u32 {
if Parameters::relay_parent_offset_override() {
0
} else {
DEFAULT_RELAY_PARENT_OFFSET
}
}
}
impl cumulus_pallet_parachain_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnSystemEvent = pallet_relaychain_info::OnValidationDataHandler<Runtime>;
type SelfParaId = ParachainInfo;
type OutboundXcmpMessageSource = XcmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
type WeightInfo = weights::cumulus_pallet_parachain_system::HydraWeight<Runtime>;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type RelayParentOffset = RelayParentOffset;
}
parameter_types! {
pub const MaxAuthorities: u32 = 50;
}
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type MaxAuthorities = MaxAuthorities;
type DisabledValidators = ();
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type SlotDuration = ConstU64<SLOT_DURATION>;
}
impl staging_parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type EventHandler = (CollatorSelection,);
}
parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 0;
pub const MaxInvulnerables: u32 = 50;
}
impl pallet_collator_selection::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type UpdateOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type PotId = PotId;
#[cfg(not(feature = "runtime-benchmarks"))]
type MaxCandidates = MaxCandidates;
#[cfg(feature = "runtime-benchmarks")]
type MaxCandidates = ConstU32<20>;
type MaxInvulnerables = MaxInvulnerables;
// should be a multiple of session or things will get inconsistent
type KickThreshold = Period;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = weights::pallet_collator_selection::HydraWeight<Runtime>;
type MinEligibleCollators = ConstU32<4>;
}
parameter_types! {
pub PreimageBaseDeposit: Balance = deposit(2, 64);
pub PreimageByteDeposit: Balance = deposit(0, 1);
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}
impl pallet_preimage::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_preimage::HydraWeight<Runtime>;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<AccountId>;
type Consideration = HoldConsideration<
AccountId,
Balances,
PreimageHoldReason,
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
>;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
impl pallet_scheduler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type OriginPrivilegeCmp = OriginPrivilegeCmp;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = weights::pallet_scheduler::HydraWeight<Runtime>;
type Preimages = Preimage;
type BlockNumberProvider = System;
}
/// Used the compare the privilege of an origin inside the scheduler.
pub struct OriginPrivilegeCmp;
impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
if left == right {
return Some(Ordering::Equal);
}
match (left, right) {
// Root is greater than anything.
(OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater),
// For every other origin we don't care, as they are not used for `ScheduleOrigin`.
_ => None,
}
}
}
parameter_types! {
pub const Period: u32 = 4 * HOURS;
pub const Offset: u32 = 0;
}
impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = <Self as frame_system::Config>::AccountId;
// we don't have stash and controller, thus we don't need the convert as well.
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
// We wrap the session manager to give out rewards.
type SessionManager = CollatorRewards;
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <opaque::SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::SessionKeys;
type WeightInfo = ();
type DisablingStrategy = ();
}
impl pallet_utility::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type BatchHook = ManageExecutionTypeForUnifiedEvent;
type WeightInfo = weights::pallet_utility::HydraWeight<Runtime>;
}
pub struct ManageExecutionTypeForUnifiedEvent;
impl BatchHook for ManageExecutionTypeForUnifiedEvent {
fn on_batch_start() -> DispatchResult {
Broadcast::add_to_context(ExecutionType::Batch)?;
Ok(())
}
fn on_batch_end() -> DispatchResult {
Broadcast::remove_from_context()?;
Ok(())
}
}
parameter_types! {
pub const BasicDeposit: Balance = 5 * DOLLARS;
pub const ByteDeposit: Balance = DOLLARS / 10;
pub const SubAccountDeposit: Balance = 5 * DOLLARS;
pub const MaxSubAccounts: u32 = 100;
pub const MaxAdditionalFields: u32 = 100;
pub const MaxRegistrars: u32 = 20;
pub const PendingUserNameExpiration: u32 = 7 * DAYS;
pub const MaxSuffixLength: u32 = 7;
pub const MaxUsernameLength: u32 = 32;
pub const UsernameDeposit: Balance = 5 * DOLLARS;
}
impl pallet_identity::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
type ByteDeposit = ByteDeposit;
type SubAccountDeposit = SubAccountDeposit;
type MaxSubAccounts = MaxSubAccounts;
type IdentityInformation = pallet_identity::legacy::IdentityInfo<MaxAdditionalFields>;
type MaxRegistrars = MaxRegistrars;
type Slashed = Treasury;
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type RegistrarOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type OffchainSignature = Signature;
type SigningPublicKey = <Signature as sp_runtime::traits::Verify>::Signer;
type UsernameAuthorityOrigin = EnsureRoot<AccountId>;
type PendingUsernameExpiration = PendingUserNameExpiration;
type MaxSuffixLength = MaxSuffixLength;
type MaxUsernameLength = MaxUsernameLength;
type WeightInfo = weights::pallet_identity::HydraWeight<Runtime>;
type UsernameDeposit = UsernameDeposit;
type UsernameGracePeriod = ConstU32<{ 30 * DAYS }>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum ProxyType {
Any,
CancelProxy,
Governance,
Transfer,
Liquidity,
LiquidityMining,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::CancelProxy => matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::Treasury(..)
| RuntimeCall::Utility(..)
| RuntimeCall::Preimage(..)
| RuntimeCall::Referenda(..)
| RuntimeCall::ConvictionVoting(..)
),
// Transfer group doesn't include cross-chain transfers
ProxyType::Transfer => matches!(
c,
RuntimeCall::Balances(..) | RuntimeCall::Currencies(..) | RuntimeCall::Tokens(..)
),
ProxyType::Liquidity => matches!(
c,
RuntimeCall::Omnipool(pallet_omnipool::Call::add_liquidity { .. })
| RuntimeCall::Omnipool(pallet_omnipool::Call::remove_liquidity { .. })
),
ProxyType::LiquidityMining => matches!(
c,
RuntimeCall::OmnipoolLiquidityMining(pallet_omnipool_liquidity_mining::Call::deposit_shares { .. })
| RuntimeCall::OmnipoolLiquidityMining(
pallet_omnipool_liquidity_mining::Call::redeposit_shares { .. }
) | RuntimeCall::OmnipoolLiquidityMining(pallet_omnipool_liquidity_mining::Call::claim_rewards { .. })
| RuntimeCall::OmnipoolLiquidityMining(
pallet_omnipool_liquidity_mining::Call::withdraw_shares { .. }
)
),
}
}
fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
_ => false,
}
}
}
parameter_types! {
pub ProxyDepositBase: Balance = deposit(1, 8);
pub ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
pub AnnouncementDepositBase: Balance = deposit(1, 8);
pub AnnouncementDepositFactor: Balance = deposit(0, 66);
pub const MaxPending: u16 = 32;
}
impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
type WeightInfo = weights::pallet_proxy::HydraWeight<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = System;
}
parameter_types! {
pub DepositBase: Balance = deposit(1, 88);
pub DepositFactor: Balance = deposit(0, 32);
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = weights::pallet_multisig::HydraWeight<Runtime>;
type BlockNumberProvider = System;
}
impl pallet_genesis_history::Config for Runtime {}
impl pallet_parameters::Config for Runtime {}
/// Parameterized slow adjusting fee updated based on
/// https://w3f-research.readthedocs.io/en/latest/polkadot/overview/2-token-economics.html?highlight=token%20economics#-2.-slow-adjusting-mechanism
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier, MaximumMultiplier>;
pub struct WeightToFee;
pub const SUBSTRATE_FEE_DIVIDER: u128 = 6; // To scale down the fee (based on manually evaluating market price data)
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, MAXIMUM_BLOCK_WEIGHT]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT
let p = CENTS / SUBSTRATE_FEE_DIVIDER; // 1_000_000_000_000 / SUBSTRATE_FEE_DIVIDER
let q = 10 * Balance::from(frame_support::weights::constants::ExtrinsicBaseWeight::get().ref_time());
smallvec::smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q, // 124
}]
}
}
parameter_types! {
pub const TransactionByteFee: Balance = 10 * MILLICENTS / SUBSTRATE_FEE_DIVIDER;
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
/// change the fees more rapidly.
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(10, 113);
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1000u128);
/// The maximum amount of the multiplier.
pub MaximumMultiplier: Multiplier = Multiplier::saturating_from_integer(320);
}
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction =
TransferFees<Runtime, Currencies, DepositAll<Runtime>, TreasuryAccount, IgnoreWithdrawFuse<Runtime>>;
type OperationalFeeMultiplier = ();
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
type WeightInfo = weights::pallet_transaction_payment::HydraWeight<Runtime>;
}
impl pallet_transaction_multi_payment::Config for Runtime {
type AcceptedCurrencyOrigin = EitherOf<EnsureRoot<Self::AccountId>, EitherOf<TechCommitteeMajority, GeneralAdmin>>;
type Currencies = Currencies;
type RouteProvider = Router;
type OraclePriceProvider = OraclePriceProvider<AssetId, EmaOracle, LRNA>;
type WeightInfo = weights::pallet_transaction_multi_payment::HydraWeight<Runtime>;
type NativeAssetId = NativeAssetId;
type PolkadotNativeAssetId = DotAssetId;
type EvmAssetId = evm::WethAssetId;
type InspectEvmAccounts = EVMAccounts;
type WeightToFee = WeightToFee;
type EvmPermit = evm::permit::EvmPermitHandler<Runtime>;
type TryCallCurrency<'a> = TryCallCurrency;
type SwappablePaymentAssetSupport = assets::XykPaymentAssetSupport;
type EvmFeePayer = evm::EvmFeePayerImpl;
}
impl pallet_relaychain_info::Config for Runtime {
type RelaychainBlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}
parameter_types! {
pub const RewardPerCollator: Balance = 455_371_584_699_000; // 83333 HDX / 183 sessions
//GalacticCouncil collators
pub ExcludedCollators: Vec<AccountId> = vec![
// 5G3t6yhAonQHGUEqrByWQPgP9R8fcSSL6Vujphc89ysdTpKF
hex!["b0502e92d738d528922e8963b8a58a3c7c3b693db51b0972a6981836d67b8835"].into(),
// 5CVBHPAjhcVVAvL3AYpa9MB6kWDwoJbBwu7q4MqbhKwNnrV4
hex!["12aa36d6c1b055b9a7ab5d39f4fd9a9fe42912163c90e122fb7997e890a53d7e"].into(),
// 5DFGmHjpxS6Xveg4YDw2hSp62JJ9h8oLCkeZUAoVR7hVtQ3k
hex!["344b7693389189ad0be0c83630b02830a568f7cb0f2d4b3483bcea323cc85f70"].into(),
// 5H178NL4DLM9DGgAgZz1kbrX2TReP3uPk7svPtsg1VcYnuXH
hex!["da6e859211b1140369a73af533ecea4e4c0e985ad122ac4c663cc8b81d4fcd12"].into(),
// 5Ca1iV2RNV253FzYJo12XtKJMPWCjv5CsPK9HdmwgJarD1sJ
hex!["165a3c2eb21341bf170fd1fa728bd9a7d02b7dc3b4968a46f2b1d494ee8c2b5d"].into(),
];
}
impl pallet_collator_rewards::Config for Runtime {
type Balance = Balance;
type CurrencyId = AssetId;
type Currency = Currencies;
type RewardPerCollator = RewardPerCollator;
type RewardCurrencyId = NativeAssetId;
type RewardsBag = TreasuryAccount;
type ExcludedCollators = ExcludedCollators;
// We wrap the `SessionManager` implementation of `CollatorRotation` to get the collators that
// we hand out rewards to.
type SessionManager = CollatorRotation;
type MaxCandidates = MaxInvulnerables;
}
impl pallet_collator_rotation::Config for Runtime {
type Inner = CollatorSelection;
}
impl pallet_transaction_pause::Config for Runtime {
type UpdateOrigin = EitherOf<EnsureRoot<Self::AccountId>, EitherOf<TechCommitteeMajority, GeneralAdmin>>;
type WeightInfo = weights::pallet_transaction_pause::HydraWeight<Runtime>;
}
pub struct TechCommAccounts;
impl SortedMembers<AccountId> for TechCommAccounts {
fn sorted_members() -> Vec<AccountId> {
pallet_collective::Members::<Runtime, TechnicalCollective>::get()
}
}
parameter_types! {
// The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high)
pub const MigrationSignedDepositPerItem: Balance = CENTS;
pub const MigrationSignedDepositBase: Balance = 20 * DOLLARS;
pub const MaxKeyLen: u32 = 512; // 144, but use the default value
}
impl pallet_state_trie_migration::Config for Runtime {
type ControlOrigin = EnsureRoot<Self::AccountId>;
#[cfg(not(feature = "runtime-benchmarks"))]
type SignedFilter = frame_system::EnsureSignedBy<TechCommAccounts, AccountId>;
#[cfg(feature = "runtime-benchmarks")]
type SignedFilter = frame_system::EnsureSigned<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;
type MaxKeyLen = MaxKeyLen;
type SignedDepositPerItem = MigrationSignedDepositPerItem;
type SignedDepositBase = MigrationSignedDepositBase;
type WeightInfo = weights::pallet_state_trie_migration::HydraWeight<Runtime>;
}
impl cumulus_pallet_weight_reclaim::Config for Runtime {
type WeightInfo = weights::cumulus_pallet_weight_reclaim::HydraWeight<Runtime>;
}