-
Notifications
You must be signed in to change notification settings - Fork 515
/
lib.rs
2376 lines (2134 loc) · 84 KB
/
lib.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
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of Acala.
// Copyright (C) 2020-2021 Acala Foundation.
// 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/>.
//! The Dev runtime. This can be compiled with `#[no_std]`, ready for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
#![allow(clippy::unnecessary_mut_passed)]
#![allow(clippy::or_fun_call)]
#![allow(clippy::from_over_into)]
#![allow(clippy::upper_case_acronyms)]
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BadOrigin, BlakeTwo256, Block as BlockT, Convert, SaturatedConversion,
StaticLookup,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use frame_system::{EnsureRoot, RawOrigin};
use module_asset_registry::{EvmErc20InfoMapping, FixedRateOfForeignAsset, XcmForeignAssetIdMapping};
use module_currencies::BasicCurrencyAdapter;
use module_evm::{CallInfo, CreateInfo, EvmTask, Runner};
use module_evm_accounts::EvmAddressMapping;
use module_relaychain::RelayChainCallBuilder;
use module_support::{DispatchableTask, ForeignAssetIdMapping};
use module_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use orml_traits::{
create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, MultiCurrency,
};
use pallet_transaction_payment::RuntimeDispatchInfo;
pub use cumulus_primitives_core::ParaId;
pub use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
pub use polkadot_parachain::primitives::Sibling;
pub use xcm::latest::prelude::*;
pub use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete, LocationInverter,
NativeAsset, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeRevenue, TakeWeightCredit,
};
pub use xcm_executor::{traits::WeightTrader, Assets, Config, XcmExecutor};
/// Weights for pallets used in the runtime.
mod weights;
pub use frame_support::{
construct_runtime, log, parameter_types,
traits::{
Contains, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Everything, Get, Imbalance,
InstanceFilter, IsSubType, IsType, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, Randomness,
SortedMembers, U128CurrencyToVote,
},
weights::{constants::RocksDbWeight, IdentityFee, Weight},
PalletId, RuntimeDebug, StorageValue,
};
pub use pallet_staking::StakerStatus;
pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use authority::AuthorityConfigImpl;
pub use constants::{fee::*, parachains, time::*};
pub use primitives::{
define_combined_task, evm::EstimateResourcesRequest, task::TaskResult, AccountId, AccountIndex, Address, Amount,
AuctionId, AuthoritysOriginId, Balance, BlockNumber, CurrencyId, DataProviderId, EraIndex, Hash, Moment, Nonce,
ReserveIdentifier, Share, Signature, TokenSymbol, TradingPair,
};
pub use runtime_common::{
cent, dollar, microcent, millicent, EnsureRootOrAllGeneralCouncil, EnsureRootOrAllTechnicalCommittee,
EnsureRootOrHalfFinancialCouncil, EnsureRootOrHalfGeneralCouncil, EnsureRootOrHalfHomaCouncil,
EnsureRootOrOneGeneralCouncil, EnsureRootOrOneThirdsTechnicalCommittee, EnsureRootOrThreeFourthsGeneralCouncil,
EnsureRootOrTwoThirdsGeneralCouncil, EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate,
FinancialCouncilInstance, FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance,
GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance,
OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RelayChainBlockNumberProvider,
RelayChainSubAccountId, RuntimeBlockLength, RuntimeBlockWeights, SystemContractsFilter, TechnicalCommitteeInstance,
TechnicalCommitteeMembershipInstance, TimeStampedPrice, BNC, KAR, KSM, KUSD, LKSM, PHA, RENBTC, VSKSM,
};
mod authority;
mod benchmarking;
pub mod constants;
/// This runtime version.
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("karura"),
impl_name: create_runtime_str!("karura"),
authoring_version: 1,
spec_version: 2001,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
};
/// The version infromation used to identify this runtime when compiled
/// natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
}
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
}
}
// Pallet accounts of runtime
parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trsy");
pub const LoansPalletId: PalletId = PalletId(*b"aca/loan");
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const CDPTreasuryPalletId: PalletId = PalletId(*b"aca/cdpt");
pub const HonzonTreasuryPalletId: PalletId = PalletId(*b"aca/hztr");
pub const HomaTreasuryPalletId: PalletId = PalletId(*b"aca/hmtr");
pub const IncentivesPalletId: PalletId = PalletId(*b"aca/inct");
pub const CollatorPotId: PalletId = PalletId(*b"aca/cpot");
// Treasury reserve
pub const TreasuryReservePalletId: PalletId = PalletId(*b"aca/reve");
pub const NftPalletId: PalletId = PalletId(*b"aca/aNFT");
// Vault all unrleased native token.
pub UnreleasedNativeVaultAccountId: AccountId = PalletId(*b"aca/urls").into_account();
}
pub fn get_all_module_accounts() -> Vec<AccountId> {
vec![
LoansPalletId::get().into_account(),
CDPTreasuryPalletId::get().into_account(),
CollatorPotId::get().into_account(),
DEXPalletId::get().into_account(),
HomaTreasuryPalletId::get().into_account(),
HonzonTreasuryPalletId::get().into_account(),
IncentivesPalletId::get().into_account(),
TreasuryPalletId::get().into_account(),
TreasuryReservePalletId::get().into_account(),
ZeroAccountId::get(),
UnreleasedNativeVaultAccountId::get(),
]
}
parameter_types! {
pub const BlockHashCount: BlockNumber = 1200; // mortal tx can be valid up to 4 hour after signing
pub const Version: RuntimeVersion = VERSION;
pub const SS58Prefix: u8 = 8; // Ss58AddressFormat::KaruraAccount
}
pub struct BaseCallFilter;
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
let is_core_call = matches!(call, Call::System(_) | Call::Timestamp(_) | Call::ParachainSystem(_));
if is_core_call {
// always allow core call
return true;
}
let is_paused = module_transaction_pause::PausedTransactionFilter::<Runtime>::contains(call);
if is_paused {
// no paused call
return false;
}
let is_evm = matches!(
call,
Call::EVM(_) | Call::EvmAccounts(_) // EvmBridge / EvmManager does not have call
);
if is_evm {
// no evm call
return false;
}
if let Call::PolkadotXcm(xcm_method) = call {
match xcm_method {
pallet_xcm::Call::send { .. }
| pallet_xcm::Call::execute { .. }
| pallet_xcm::Call::teleport_assets { .. }
| pallet_xcm::Call::reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_reserve_transfer_assets { .. }
| pallet_xcm::Call::limited_teleport_assets { .. } => {
return false;
}
pallet_xcm::Call::force_xcm_version { .. }
| pallet_xcm::Call::force_default_xcm_version { .. }
| pallet_xcm::Call::force_subscribe_version_notify { .. }
| pallet_xcm::Call::force_unsubscribe_version_notify { .. } => {
return true;
}
pallet_xcm::Call::__Ignore { .. } => {
unimplemented!()
}
}
}
true
}
}
impl frame_system::Config for Runtime {
type AccountId = AccountId;
type Call = Call;
type Lookup = (AccountIdLookup<AccountId, AccountIndex>, EvmAccounts);
type Index = Nonce;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type Origin = Origin;
type BlockHashCount = BlockHashCount;
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type Version = Version;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = (
module_evm::CallKillAccount<Runtime>,
module_evm_accounts::CallKillAccount<Runtime>,
);
type DbWeight = RocksDbWeight;
type BaseCallFilter = BaseCallFilter;
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
}
parameter_types! {
pub const MaxAuthorities: u32 = 32;
}
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = MaxAuthorities;
}
parameter_types! {
pub const UncleGenerations: u32 = 0;
}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = CollatorSelection;
}
parameter_types! {
pub const SessionDuration: BlockNumber = 6 * HOURS; // used in SessionManagerConfig of genesis
}
impl pallet_session::Config for Runtime {
type Event = Event;
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 = module_collator_selection::IdentityCollator;
type ShouldEndSession = SessionManager;
type NextSessionRotation = SessionManager;
type SessionManager = CollatorSelection;
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = ();
}
parameter_types! {
pub const MinCandidates: u32 = 4;
pub const MaxCandidates: u32 = 50;
pub const MaxInvulnerables: u32 = 10;
pub const KickPenaltySessionLength: u32 = 8;
pub const CollatorKickThreshold: Permill = Permill::from_percent(85);
}
impl module_collator_selection::Config for Runtime {
type Event = Event;
type Currency = Balances;
type ValidatorSet = Session;
type UpdateOrigin = EnsureRootOrHalfGeneralCouncil;
type PotId = CollatorPotId;
type MinCandidates = MinCandidates;
type MaxCandidates = MaxCandidates;
type MaxInvulnerables = MaxInvulnerables;
type KickPenaltySessionLength = KickPenaltySessionLength;
type CollatorKickThreshold = CollatorKickThreshold;
type WeightInfo = weights::module_collator_selection::WeightInfo<Runtime>;
}
parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = Moment;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
parameter_types! {
pub NativeTokenExistentialDeposit: Balance = 10 * cent(KAR); // 0.1 KAR
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = ReserveIdentifier::Count as u32;
}
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type DustRemoval = Treasury;
type Event = Event;
type ExistentialDeposit = NativeTokenExistentialDeposit;
type AccountStore = frame_system::Pallet<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = ReserveIdentifier;
type WeightInfo = ();
}
parameter_types! {
pub TransactionByteFee: Balance = millicent(KAR);
/// 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(3, 100_000);
/// 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.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
}
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>;
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
parameter_types! {
pub const GeneralCouncilMotionDuration: BlockNumber = 3 * DAYS;
pub const GeneralCouncilMaxProposals: u32 = 20;
pub const GeneralCouncilMaxMembers: u32 = 30;
}
impl pallet_collective::Config<GeneralCouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = GeneralCouncilMotionDuration;
type MaxProposals = GeneralCouncilMaxProposals;
type MaxMembers = GeneralCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
impl pallet_membership::Config<GeneralCouncilMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrThreeFourthsGeneralCouncil;
type RemoveOrigin = EnsureRootOrThreeFourthsGeneralCouncil;
type SwapOrigin = EnsureRootOrThreeFourthsGeneralCouncil;
type ResetOrigin = EnsureRootOrThreeFourthsGeneralCouncil;
type PrimeOrigin = EnsureRootOrThreeFourthsGeneralCouncil;
type MembershipInitialized = GeneralCouncil;
type MembershipChanged = GeneralCouncil;
type MaxMembers = GeneralCouncilMaxMembers;
type WeightInfo = ();
}
parameter_types! {
pub const FinancialCouncilMotionDuration: BlockNumber = 3 * DAYS;
pub const FinancialCouncilMaxProposals: u32 = 20;
pub const FinancialCouncilMaxMembers: u32 = 30;
}
impl pallet_collective::Config<FinancialCouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = FinancialCouncilMotionDuration;
type MaxProposals = FinancialCouncilMaxProposals;
type MaxMembers = FinancialCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
impl pallet_membership::Config<FinancialCouncilMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type MembershipInitialized = FinancialCouncil;
type MembershipChanged = FinancialCouncil;
type MaxMembers = FinancialCouncilMaxMembers;
type WeightInfo = ();
}
parameter_types! {
pub const HomaCouncilMotionDuration: BlockNumber = 3 * DAYS;
pub const HomaCouncilMaxProposals: u32 = 20;
pub const HomaCouncilMaxMembers: u32 = 30;
}
impl pallet_collective::Config<HomaCouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = HomaCouncilMotionDuration;
type MaxProposals = HomaCouncilMaxProposals;
type MaxMembers = HomaCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
impl pallet_membership::Config<HomaCouncilMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type MembershipInitialized = HomaCouncil;
type MembershipChanged = HomaCouncil;
type MaxMembers = HomaCouncilMaxMembers;
type WeightInfo = ();
}
parameter_types! {
pub const TechnicalCommitteeMotionDuration: BlockNumber = 3 * DAYS;
pub const TechnicalCommitteeMaxProposals: u32 = 20;
pub const TechnicalCouncilMaxMembers: u32 = 30;
}
impl pallet_collective::Config<TechnicalCommitteeInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = TechnicalCommitteeMotionDuration;
type MaxProposals = TechnicalCommitteeMaxProposals;
type MaxMembers = TechnicalCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
impl pallet_membership::Config<TechnicalCommitteeMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
type MaxMembers = TechnicalCouncilMaxMembers;
type WeightInfo = ();
}
parameter_types! {
pub const OracleMaxMembers: u32 = 50;
}
impl pallet_membership::Config<OperatorMembershipInstanceAcala> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type MembershipInitialized = ();
type MembershipChanged = AcalaOracle;
type MaxMembers = OracleMaxMembers;
type WeightInfo = ();
}
impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = ();
}
parameter_types! {
pub MultisigDepositBase: Balance = deposit(1, 88);
pub MultisigDepositFactor: Balance = deposit(0, 32);
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type DepositBase = MultisigDepositBase;
type DepositFactor = MultisigDepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = ();
}
pub struct GeneralCouncilProvider;
impl SortedMembers<AccountId> for GeneralCouncilProvider {
fn contains(who: &AccountId) -> bool {
GeneralCouncil::is_member(who)
}
fn sorted_members() -> Vec<AccountId> {
GeneralCouncil::members()
}
#[cfg(feature = "runtime-benchmarks")]
fn add(_: &AccountId) {
unimplemented!()
}
}
impl ContainsLengthBound for GeneralCouncilProvider {
fn max_len() -> usize {
GeneralCouncilMaxMembers::get() as usize
}
fn min_len() -> usize {
0
}
}
parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub ProposalBondMinimum: Balance = 5 * dollar(KAR);
pub const SpendPeriod: BlockNumber = 7 * DAYS;
pub const Burn: Permill = Permill::from_percent(0);
pub const TipCountdown: BlockNumber = DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(5);
pub TipReportDepositBase: Balance = deposit(1, 0);
pub BountyDepositBase: Balance = deposit(1, 0);
pub const BountyDepositPayoutDelay: BlockNumber = 4 * DAYS;
pub const BountyUpdatePeriod: BlockNumber = 35 * DAYS;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
pub BountyValueMinimum: Balance = 5 * dollar(KAR);
pub DataDepositPerByte: Balance = deposit(0, 1);
pub const MaximumReasonLength: u32 = 8192;
pub const MaxApprovals: u32 = 30;
pub const SevenDays: BlockNumber = 7 * DAYS;
pub const OneDay: BlockNumber = DAYS;
}
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureRootOrHalfGeneralCouncil;
type RejectOrigin = EnsureRootOrHalfGeneralCouncil;
type Event = Event;
type OnSlash = Treasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
type SpendFunds = Bounties;
type WeightInfo = ();
type MaxApprovals = MaxApprovals;
}
impl pallet_bounties::Config for Runtime {
type Event = Event;
type BountyDepositBase = BountyDepositBase;
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
type BountyUpdatePeriod = BountyUpdatePeriod;
type BountyCuratorDeposit = BountyCuratorDeposit;
type BountyValueMinimum = BountyValueMinimum;
type DataDepositPerByte = DataDepositPerByte;
type MaximumReasonLength = MaximumReasonLength;
type WeightInfo = ();
}
impl pallet_tips::Config for Runtime {
type Event = Event;
type DataDepositPerByte = DataDepositPerByte;
type MaximumReasonLength = MaximumReasonLength;
type Tippers = GeneralCouncilProvider;
type TipCountdown = TipCountdown;
type TipFindersFee = TipFindersFee;
type TipReportDepositBase = TipReportDepositBase;
type WeightInfo = ();
}
parameter_types! {
pub const LaunchPeriod: BlockNumber = 5 * DAYS;
pub const VotingPeriod: BlockNumber = 5 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub MinimumDeposit: Balance = 100 * dollar(KAR);
pub const EnactmentPeriod: BlockNumber = 2 * DAYS;
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub PreimageByteDeposit: Balance = deposit(0, 1);
pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
}
impl pallet_democracy::Config for Runtime {
type Proposal = Call;
type Event = Event;
type Currency = Balances;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type VoteLockingPeriod = VoteLockingPeriod;
type MinimumDeposit = MinimumDeposit;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin = EnsureRootOrHalfGeneralCouncil;
/// A majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin = EnsureRootOrHalfGeneralCouncil;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin = EnsureRootOrAllGeneralCouncil;
/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
/// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin = EnsureRootOrTwoThirdsTechnicalCommittee;
type InstantOrigin = EnsureRootOrAllTechnicalCommittee;
type InstantAllowed = InstantAllowed;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type BlacklistOrigin = EnsureRoot<AccountId>;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EnsureRootOrAllTechnicalCommittee;
// Any single technical committee member may veto a coming council proposal, however they can
// only do it once and it lasts only for the cooloff period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCommitteeInstance>;
type CooloffPeriod = CooloffPeriod;
type PreimageByteDeposit = PreimageByteDeposit;
type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, GeneralCouncilInstance>;
type Slash = Treasury;
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
//TODO: might need to weight for Karura
type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
type MaxProposals = MaxProposals;
}
impl orml_auction::Config for Runtime {
type Event = Event;
type Balance = Balance;
type AuctionId = AuctionId;
type Handler = AuctionManager;
type WeightInfo = weights::orml_auction::WeightInfo<Runtime>;
}
impl orml_authority::Config for Runtime {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type Scheduler = Scheduler;
type AsOriginId = AuthoritysOriginId;
type AuthorityConfig = AuthorityConfigImpl;
type WeightInfo = weights::orml_authority::WeightInfo<Runtime>;
}
parameter_types! {
pub const MinimumCount: u32 = 5;
pub const ExpiresIn: Moment = 1000 * 60 * 60; // 1 hours
pub ZeroAccountId: AccountId = AccountId::from([0u8; 32]);
pub const MaxHasDispatchedSize: u32 = 20;
}
type AcalaDataProvider = orml_oracle::Instance1;
impl orml_oracle::Config<AcalaDataProvider> for Runtime {
type Event = Event;
type OnNewData = ();
type CombineData = orml_oracle::DefaultCombineData<Runtime, MinimumCount, ExpiresIn, AcalaDataProvider>;
type Time = Timestamp;
type OracleKey = CurrencyId;
type OracleValue = Price;
type RootOperatorAccountId = ZeroAccountId;
type Members = OperatorMembershipAcala;
type MaxHasDispatchedSize = MaxHasDispatchedSize;
type WeightInfo = ();
}
create_median_value_data_provider!(
AggregatedDataProvider,
CurrencyId,
Price,
TimeStampedPrice,
[AcalaOracle]
);
// Aggregated data provider cannot feed.
impl DataFeeder<CurrencyId, Price, AccountId> for AggregatedDataProvider {
fn feed_value(_: AccountId, _: CurrencyId, _: Price) -> DispatchResult {
Err("Not supported".into())
}
}
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
CurrencyId::Token(symbol) => match symbol {
TokenSymbol::KUSD => cent(*currency_id),
TokenSymbol::KSM => 10 * millicent(*currency_id),
TokenSymbol::LKSM => 50 * millicent(*currency_id),
TokenSymbol::BNC => 800 * millicent(*currency_id), // 80BNC = 1KSM
TokenSymbol::VSKSM => 10 * millicent(*currency_id), // 1VSKSM = 1KSM
TokenSymbol::PHA => 4000 * millicent(*currency_id), // 400PHA = 1KSM
TokenSymbol::ACA |
TokenSymbol::AUSD |
TokenSymbol::DOT |
TokenSymbol::LDOT |
TokenSymbol::RENBTC |
TokenSymbol::KAR |
TokenSymbol::CASH => Balance::max_value() // unsupported
},
CurrencyId::DexShare(dex_share_0, _) => {
let currency_id_0: CurrencyId = (*dex_share_0).into();
// initial dex share amount is calculated based on currency_id_0,
// use the ED of currency_id_0 as the ED of lp token.
if currency_id_0 == GetNativeCurrencyId::get() {
NativeTokenExistentialDeposit::get()
} else if let CurrencyId::Erc20(_) = currency_id_0 {
// LP token with erc20
1
} else {
Self::get(¤cy_id_0)
}
},
CurrencyId::Erc20(_) => Balance::max_value(), // not handled by orml-tokens
CurrencyId::StableAssetPoolToken(_) => Balance::max_value(), // TODO: update this before we enable StableAsset
CurrencyId::LiquidCroadloan(_) => Balance::max_value(), // TODO: unsupported
CurrencyId::ForeignAsset(foreign_asset_id) => {
XcmForeignAssetIdMapping::<Runtime>::get_asset_metadata(*foreign_asset_id).
map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
},
}
};
}
pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
get_all_module_accounts().contains(a)
}
}
parameter_types! {
pub KaruraTreasuryAccount: AccountId = TreasuryPalletId::get().into_account();
}
impl orml_tokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
type Amount = Amount;
type CurrencyId = CurrencyId;
type WeightInfo = weights::orml_tokens::WeightInfo<Runtime>;
type ExistentialDeposits = ExistentialDeposits;
type OnDust = orml_tokens::TransferDust<Runtime, KaruraTreasuryAccount>;
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = DustRemovalWhitelist;
}
parameter_types! {
pub StableCurrencyFixedPrice: Price = Price::saturating_from_rational(1, 1);
}
impl module_prices::Config for Runtime {
type Event = Event;
type Source = AggregatedDataProvider;
type GetStableCurrencyId = GetStableCurrencyId;
type StableCurrencyFixedPrice = StableCurrencyFixedPrice;
type GetStakingCurrencyId = GetStakingCurrencyId;
type GetLiquidCurrencyId = GetLiquidCurrencyId;
type LockOrigin = EnsureRootOrTwoThirdsGeneralCouncil;
type LiquidStakingExchangeRateProvider = HomaLite;
type DEX = Dex;
type Currency = Currencies;
type Erc20InfoMapping = EvmErc20InfoMapping<Runtime>;
type WeightInfo = weights::module_prices::WeightInfo<Runtime>;
}
parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = KAR;
pub const GetStableCurrencyId: CurrencyId = KUSD;
pub const GetLiquidCurrencyId: CurrencyId = LKSM;
pub const GetStakingCurrencyId: CurrencyId = KSM;
}
impl module_currencies::Config for Runtime {
type Event = Event;
type MultiCurrency = Tokens;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances, Amount, BlockNumber>;
type GetNativeCurrencyId = GetNativeCurrencyId;
type WeightInfo = weights::module_currencies::WeightInfo<Runtime>;
type AddressMapping = EvmAddressMapping<Runtime>;
type EVMBridge = EVMBridge;
type SweepOrigin = EnsureRootOrOneGeneralCouncil;
type OnDust = module_currencies::TransferDust<Runtime, KaruraTreasuryAccount>;
}
parameter_types! {
pub KaruraFoundationAccounts: Vec<AccountId> = vec![
hex_literal::hex!["efd29d0d6e63911ae3727fc71506bc3365c5d3b39e3a1680c857b4457cf8afad"].into(), // tij5W2NzmtxxAbwudwiZpif9ScmZfgFYdzrJWKYq6oNbSNH
hex_literal::hex!["41dd2515ea11692c02306b68a2c6ff69b6606ebddaac40682789cfab300971c4"].into(), // pndshZqDAC9GutDvv7LzhGhgWeGv5YX9puFA8xDidHXCyjd
hex_literal::hex!["dad0a28c620ba73b51234b1b2ae35064d90ee847e2c37f9268294646c5af65eb"].into(), // tFBV65Ts7wpQPxGM6PET9euNzp4pXdi9DVtgLZDJoFveR9F
TreasuryPalletId::get().into_account(),
TreasuryReservePalletId::get().into_account(),
];
}
pub struct EnsureKaruraFoundation;
impl EnsureOrigin<Origin> for EnsureKaruraFoundation {
type Success = AccountId;
fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
Into::<Result<RawOrigin<AccountId>, Origin>>::into(o).and_then(|o| match o {
RawOrigin::Signed(caller) => {
if KaruraFoundationAccounts::get().contains(&caller) {
Ok(caller)
} else {
Err(Origin::from(Some(caller)))
}
}
r => Err(Origin::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> Origin {
Origin::from(RawOrigin::Signed(Default::default()))
}
}
parameter_types! {
pub MinVestedTransfer: Balance = 0;
pub const MaxVestingSchedules: u32 = 100;
}
impl orml_vesting::Config for Runtime {
type Event = Event;
type Currency = pallet_balances::Pallet<Runtime>;
type MinVestedTransfer = MinVestedTransfer;
type VestedTransferOrigin = EnsureKaruraFoundation;
type WeightInfo = weights::orml_vesting::WeightInfo<Runtime>;
type MaxVestingSchedules = MaxVestingSchedules;
type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(10) * RuntimeBlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 10;
}
impl pallet_scheduler::Config for Runtime {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
}
parameter_types! {
pub MinimumIncrementSize: Rate = Rate::saturating_from_rational(2, 100);
pub const AuctionTimeToClose: BlockNumber = 15 * MINUTES;
pub const AuctionDurationSoftCap: BlockNumber = 2 * HOURS;
pub DefaultSwapParitalPathList: Vec<Vec<CurrencyId>> = vec![
vec![KUSD],
vec![KSM, KUSD],
];
}
impl module_auction_manager::Config for Runtime {
type Event = Event;
type Currency = Currencies;
type Auction = Auction;
type MinimumIncrementSize = MinimumIncrementSize;
type AuctionTimeToClose = AuctionTimeToClose;
type AuctionDurationSoftCap = AuctionDurationSoftCap;
type GetStableCurrencyId = GetStableCurrencyId;
type CDPTreasury = CdpTreasury;
type DEX = Dex;
type PriceSource = module_prices::PriorityLockedPriceProvider<Runtime>;
type UnsignedPriority = runtime_common::AuctionManagerUnsignedPriority;
type EmergencyShutdown = EmergencyShutdown;
type DefaultSwapParitalPathList = DefaultSwapParitalPathList;
type WeightInfo = weights::module_auction_manager::WeightInfo<Runtime>;
}
impl module_loans::Config for Runtime {
type Event = Event;
type Convert = module_cdp_engine::DebitExchangeRateConvertor<Runtime>;
type Currency = Currencies;
type RiskManager = CdpEngine;
type CDPTreasury = CdpTreasury;
type PalletId = LoansPalletId;
type OnUpdateLoan = module_incentives::OnUpdateLoan<Runtime>;
}
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
Call: From<LocalCall>,
{
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as sp_runtime::traits::Verify>::Signer,
account: AccountId,
nonce: Nonce,
) -> Option<(
Call,
<UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
)> {
// take the biggest period possible.
let period = BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let current_block = System::block_number()
.saturated_into::<u64>()
// The `System::block_number` is initialized with `n+1`,
// so the actual block number is `n`.
.saturating_sub(1);
let tip = 0;
let extra: SignedExtra = (
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
module_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
module_evm::SetEvmOrigin::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
log::warn!("Unable to create signed payload: {:?}", e);
})
.ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
let address = AccountIdLookup::unlookup(account);
let (call, extra, _) = raw_payload.deconstruct();
Some((call, (address, signature, extra)))
}
}
impl frame_system::offchain::SigningTypes for Runtime {
type Public = <Signature as sp_runtime::traits::Verify>::Signer;
type Signature = Signature;
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,