-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlib.rs
1011 lines (882 loc) · 32.9 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
#![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"]
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
use codec::Encode;
pub use dia_oracle::dia::*;
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, ConstU8, Contains},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, IdentityFee, Weight},
PalletId,
};
pub use frame_system::Call as SystemCall;
use orml_currencies::BasicCurrencyAdapter;
use orml_traits::{currency::MutationHooks, parameter_type_with_key};
pub use pallet_balances::Call as BalancesCall;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
pub use pallet_timestamp::Call as TimestampCall;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{OpaqueMetadata, H256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, NumberFor,
Zero,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchError, FixedPointNumber, Perbill, Perquintill,
SaturatedConversion,
};
use sp_std::{marker::PhantomData, prelude::*};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use currency::Amount;
pub use issue::{Event as IssueEvent, IssueRequest};
pub use module_oracle_rpc_runtime_api::BalanceWrapper;
pub use nomination::Event as NominationEvent;
use oracle::dia::{DiaOracleAdapter, NativeCurrencyKey, XCMCurrencyConversion};
pub use primitives::{
self, AccountId, Balance, BlockNumber, CurrencyId, Hash, Moment, Nonce, Signature,
SignedFixedPoint, SignedInner, UnsignedFixedPoint, UnsignedInner,
};
pub use redeem::{Event as RedeemEvent, RedeemRequest};
pub use replace::{Event as ReplaceEvent, ReplaceRequest};
pub use security::StatusCode;
pub use stellar_relay::traits::{FieldLength, Organization, Validator};
type VaultId = primitives::VaultId<AccountId, CurrencyId>;
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
pub grandpa: Grandpa,
}
}
pub const UNITS: Balance = 10_000_000_000;
pub const CENTS: Balance = UNITS / 100; // 100_000_000
pub const MILLICENTS: Balance = CENTS / 1_000; // 100_000
// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
pub const WEEKS: BlockNumber = DAYS * 7;
pub const YEARS: BlockNumber = DAYS * 365;
/// This runtime version.
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("spacewalk-standalone"),
impl_name: create_runtime_str!("spacewalk-standalone"),
authoring_version: 1,
spec_version: 1,
impl_version: 1,
transaction_version: 1,
apis: RUNTIME_API_VERSIONS,
state_version: 0,
};
pub const MILLISECS_PER_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
pub struct BlockNumberToBalance;
impl Convert<BlockNumber, Balance> for BlockNumberToBalance {
fn convert(a: BlockNumber) -> Balance {
a.into()
}
}
/// The version information 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() }
}
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 250;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::with_sensible_defaults(
(2u64 * Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND,0)).set_proof_size(u64::MAX),
NORMAL_DISPATCH_RATIO,
);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
}
pub type Index = u32;
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
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;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// 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 = AccountIdLookup<AccountId, ()>;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
type DbWeight = ();
/// Runtime version.
type Version = Version;
/// Converts a module to an index of this module in the runtime.
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
pub const MaxAuthorities: u32 = 32;
}
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = MaxAuthorities;
}
impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type KeyOwnerProof = sp_core::Void;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxSetIdSessionEntries = ConstU64<0>;
type EquivocationReportSystem = ();
}
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 = ();
}
const NATIVE_CURRENCY_ID: CurrencyId = CurrencyId::Native;
const PARENT_CURRENCY_ID: CurrencyId = CurrencyId::XCM(0);
parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = NATIVE_CURRENCY_ID;
pub const GetRelayChainCurrencyId: CurrencyId = PARENT_CURRENCY_ID;
pub const TransactionByteFee: Balance = MILLICENTS;
}
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = ();
}
impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
}
// Pallet accounts
parameter_types! {
pub const FeePalletId: PalletId = PalletId(*b"mod/fees");
pub const VaultRegistryPalletId: PalletId = PalletId(*b"mod/vreg");
}
parameter_types! {
// 5EYCAe5i8QbRr5WN1PvaAVqPbfXsqazk9ocaxuzcTjgXPM1e
pub FeeAccount: AccountId = FeePalletId::get().into_account_truncating();
// 5EYCAe5i8QbRra1jndPz1WAuf1q1KHQNfu2cW1EXJ231emTd
pub VaultRegistryAccount: AccountId = VaultRegistryPalletId::get().into_account_truncating();
}
pub fn get_all_module_accounts() -> Vec<AccountId> {
vec![FeeAccount::get(), VaultRegistryAccount::get()]
}
parameter_types! {
pub const MaxLocks: u32 = 50;
}
parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance {
Zero::zero()
};
}
pub struct CurrencyHooks<T>(PhantomData<T>);
impl<T: orml_tokens::Config> MutationHooks<T::AccountId, T::CurrencyId, T::Balance>
for CurrencyHooks<T>
{
type OnDust = orml_tokens::BurnDust<T>;
type OnSlash = ();
type PreDeposit = ();
type PostDeposit = ();
type PreTransfer = ();
type PostTransfer = ();
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}
impl orml_tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type Amount = primitives::Amount;
type CurrencyId = CurrencyId;
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = CurrencyHooks<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type DustRemovalWhitelist = DustRemovalWhitelist;
}
pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
vec![].contains(a)
}
}
impl orml_currencies::Config for Runtime {
type MultiCurrency = Tokens;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances, primitives::Amount, BlockNumber>;
type GetNativeCurrencyId = GetNativeCurrencyId;
type WeightInfo = ();
}
/// Existential deposit.
pub const EXISTENTIAL_DEPOSIT: u128 = 500;
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
}
impl security::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = security::SubstrateWeight<Runtime>;
}
pub struct CurrencyConvert;
impl currency::CurrencyConversion<currency::Amount<Runtime>, CurrencyId> for CurrencyConvert {
fn convert(
amount: ¤cy::Amount<Runtime>,
to: CurrencyId,
) -> Result<currency::Amount<Runtime>, DispatchError> {
Oracle::convert(amount, to)
}
}
impl currency::Config for Runtime {
type SignedInner = SignedInner;
type SignedFixedPoint = SignedFixedPoint;
type UnsignedFixedPoint = UnsignedFixedPoint;
type Balance = Balance;
type GetRelayChainCurrencyId = GetRelayChainCurrencyId;
type AssetConversion = primitives::AssetConversion;
type BalanceConversion = primitives::BalanceConversion;
type CurrencyConversion = CurrencyConvert;
type AmountCompatibility = primitives::StellarCompatibility;
}
impl staking::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SignedFixedPoint = SignedFixedPoint;
type SignedInner = SignedInner;
type CurrencyId = CurrencyId;
type GetNativeCurrencyId = GetNativeCurrencyId;
type MaxRewardCurrencies = MaxRewardCurrencies;
}
pub type OrganizationId = u128;
parameter_types! {
pub const OrganizationLimit: u32 = 255;
pub const ValidatorLimit: u32 = 255;
pub const IsPublicNetwork: bool = false;
}
impl stellar_relay::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OrganizationId = OrganizationId;
type OrganizationLimit = OrganizationLimit;
type ValidatorLimit = ValidatorLimit;
type IsPublicNetwork = IsPublicNetwork;
type WeightInfo = stellar_relay::SubstrateWeight<Runtime>;
}
impl vault_registry::Config for Runtime {
type PalletId = VaultRegistryPalletId;
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type WeightInfo = vault_registry::SubstrateWeight<Runtime>;
type GetGriefingCollateralCurrencyId = GetRelayChainCurrencyId;
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
RuntimeCall: From<C>,
{
type OverarchingCall = RuntimeCall;
type Extrinsic = UncheckedExtrinsic;
}
impl dia_oracle::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type AuthorityId = dia_oracle::crypto::DiaAuthId;
type WeightInfo = dia_oracle::weights::DiaWeightInfo<Runtime>;
}
impl frame_system::offchain::SigningTypes for Runtime {
type Public = <Signature as sp_runtime::traits::Verify>::Signer;
type Signature = Signature;
}
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: RuntimeCall,
public: <Signature as sp_runtime::traits::Verify>::Signer,
account: AccountId,
index: Index,
) -> Option<(
RuntimeCall,
<UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
)> {
let period = BlockHashCount::get() as u64;
let current_block = System::block_number().saturated_into::<u64>().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(index),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
);
let raw_payload = SignedPayload::new(call, extra).ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
let address = account;
let (call, extra, _) = raw_payload.deconstruct();
Some((call, (sp_runtime::MultiAddress::Id(address), signature, extra)))
}
}
pub struct ConvertPrice;
impl Convert<u128, Option<UnsignedFixedPoint>> for ConvertPrice {
fn convert(price: u128) -> Option<UnsignedFixedPoint> {
Some(UnsignedFixedPoint::from_inner(price))
}
}
pub struct ConvertMoment;
impl Convert<u64, Option<Moment>> for ConvertMoment {
fn convert(moment: u64) -> Option<Moment> {
// The provided moment is in seconds, but we need milliseconds
Some(moment.saturating_mul(1000))
}
}
pub struct SpacewalkNativeCurrencyKey;
impl NativeCurrencyKey for SpacewalkNativeCurrencyKey {
fn native_symbol() -> Vec<u8> {
"LOCAL".as_bytes().to_vec()
}
fn native_chain() -> Vec<u8> {
"LOCAL".as_bytes().to_vec()
}
}
// It's important that this is implemented the same way as the MockOracleKeyConvertor
// because this is used in the benchmark_utils::DataCollector when feeding prices
impl XCMCurrencyConversion for SpacewalkNativeCurrencyKey {
fn convert_to_dia_currency_id(token_symbol: u8) -> Option<(Vec<u8>, Vec<u8>)> {
// todo: this code results in Execution error:
// todo: \"Unable to get required collateral for amount\":
// todo: Module(ModuleError { index: 19, error: [0, 0, 0, 0], message: None })", data: None
// } cfg_if::cfg_if! {
// if #[cfg(not(feature = "testing-utils"))] {
// if token_symbol == 0 {
// return Some((b"Kusama".to_vec(), b"KSM".to_vec()))
// }
// }
// }
// We assume that the blockchain is always 0 and the symbol represents the token symbol
let blockchain = vec![0u8];
let symbol = vec![token_symbol];
Some((blockchain, symbol))
}
fn convert_from_dia_currency_id(blockchain: Vec<u8>, symbol: Vec<u8>) -> Option<u8> {
// We assume that the blockchain is always 0 and the symbol represents the token symbol
if blockchain.len() != 1 && blockchain[0] != 0 || symbol.len() != 1 {
return None
}
return Some(symbol[0])
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "testing-utils")] {
type DataProviderImpl = DiaOracleAdapter<
DiaOracleModule,
UnsignedFixedPoint,
Moment,
oracle::dia::DiaOracleKeyConvertor<SpacewalkNativeCurrencyKey>,
ConvertPrice,
ConvertMoment,
>;
} else if #[cfg(feature = "runtime-benchmarks")] {
use oracle::testing_utils::{
MockConvertMoment, MockConvertPrice, MockDiaOracle, MockOracleKeyConvertor,
};
type DataProviderImpl = DiaOracleAdapter<
MockDiaOracle,
UnsignedFixedPoint,
Moment,
MockOracleKeyConvertor,
MockConvertPrice,
MockConvertMoment<Moment>,
>;
} else {
// This implementation will be used when running the testchain locally
// as well as for the **vault integration tests**
type DataProviderImpl = DiaOracleAdapter<
DiaOracleModule,
UnsignedFixedPoint,
Moment,
oracle::dia::DiaOracleKeyConvertor<SpacewalkNativeCurrencyKey>,
ConvertPrice,
ConvertMoment,
>;
}
}
#[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))]
use oracle::testing_utils::MockDataFeeder;
impl oracle::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = oracle::SubstrateWeight<Runtime>;
type DataProvider = DataProviderImpl;
#[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))]
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}
impl issue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BlockNumberToBalance = BlockNumberToBalance;
type WeightInfo = issue::SubstrateWeight<Runtime>;
}
impl redeem::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = redeem::SubstrateWeight<Runtime>;
}
impl replace::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = replace::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const MaxExpectedValue: UnsignedFixedPoint = UnsignedFixedPoint::from_inner(<UnsignedFixedPoint as FixedPointNumber>::DIV);
}
impl fee::Config for Runtime {
type FeePalletId = FeePalletId;
type WeightInfo = fee::SubstrateWeight<Runtime>;
type SignedFixedPoint = SignedFixedPoint;
type SignedInner = SignedInner;
type UnsignedFixedPoint = UnsignedFixedPoint;
type UnsignedInner = UnsignedInner;
type VaultRewards = VaultRewards;
type VaultStaking = VaultStaking;
type OnSweep = currency::SweepFunds<Runtime, FeeAccount>;
type MaxExpectedValue = MaxExpectedValue;
type RewardDistribution = RewardDistribution;
}
impl nomination::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = nomination::SubstrateWeight<Runtime>;
}
impl clients_info::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = clients_info::SubstrateWeight<Runtime>;
type MaxNameLength = ConstU32<255>;
type MaxUriLength = ConstU32<255>;
}
parameter_types! {
pub const DecayRate: Perquintill = Perquintill::from_percent(5);
pub const MaxCurrencies: u32 = 10;
}
impl reward_distribution::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = reward_distribution::SubstrateWeight<Runtime>;
type Balance = Balance;
type DecayInterval = ConstU32<100>;
type DecayRate = DecayRate;
type VaultRewards = VaultRewards;
type MaxCurrencies = MaxCurrencies;
type OracleApi = Oracle;
type Balances = Balances;
type VaultStaking = VaultStaking;
type FeePalletId = FeePalletId;
}
parameter_types! {
pub const MaxRewardCurrencies: u32= 10;
}
impl pooled_rewards::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SignedFixedPoint = SignedFixedPoint;
type PoolId = CurrencyId;
type PoolRewardsCurrencyId = CurrencyId;
type StakeId = VaultId;
type MaxRewardCurrencies = MaxRewardCurrencies;
}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 0,
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 1,
Aura: pallet_aura::{Pallet, Config<T>} = 2,
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event} = 3,
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 4,
Tokens: orml_tokens::{Pallet, Call, Storage, Config<T>, Event<T>} = 5,
Currencies: orml_currencies::{Pallet, Call, Storage} = 7,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 8,
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 9,
StellarRelay: stellar_relay::{Pallet, Call, Config<T>, Storage, Event<T>} = 10,
VaultRewards: pooled_rewards::{Pallet, Storage, Event<T>} = 15,
VaultStaking: staking::{Pallet, Storage, Event<T>} = 16,
Currency: currency::{Pallet} = 17,
Security: security::{Pallet, Call, Config, Storage, Event<T>} = 19,
VaultRegistry: vault_registry::{Pallet, Call, Config<T>, Storage, Event<T>, ValidateUnsigned} = 21,
Oracle: oracle::{Pallet, Call, Config, Storage, Event<T>} = 22,
Issue: issue::{Pallet, Call, Config<T>, Storage, Event<T>} = 23,
Redeem: redeem::{Pallet, Call, Config<T>, Storage, Event<T>} = 24,
Replace: replace::{Pallet, Call, Config<T>, Storage, Event<T>} = 25,
Fee: fee::{Pallet, Call, Config<T>, Storage} = 26,
Nomination: nomination::{Pallet, Call, Config, Storage, Event<T>} = 28,
DiaOracleModule: dia_oracle::{Pallet, Call, Config<T>, Storage, Event<T>} = 29,
ClientsInfo: clients_info::{Pallet, Call, Storage, Event<T>} = 30,
RewardDistribution: reward_distribution::{Pallet, Call, Storage, Event<T>} = 31,
}
}
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
>;
#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[clients_info, ClientsInfo]
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>]
[stellar_relay, StellarRelay]
[issue, Issue]
[fee, Fee]
[oracle, Oracle]
[redeem, Redeem]
[replace, Replace]
[vault_registry, VaultRegistry]
[nomination, Nomination]
[reward_distribution, RewardDistribution]
);
}
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(Runtime::metadata().into())
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::finalize_block()
}
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
data.create_extrinsics()
}
fn check_inherents(
block: Block,
data: sp_inherents::InherentData,
) -> sp_inherents::CheckInherentsResult {
data.check_extrinsics(&block)
}
}
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
Executive::offchain_worker(header)
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
SessionKeys::decode_into_raw_public_keys(&encoded)
}
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
}
}
impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> GrandpaAuthorityList {
Grandpa::grandpa_authorities()
}
fn current_set_id() -> fg_primitives::SetId {
Grandpa::current_set_id()
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
>,
_key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}
fn generate_key_ownership_proof(
_set_id: fg_primitives::SetId,
_authority_id: GrandpaId,
) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
// NOTE: this is the only implementation possible since we've
// defined our key owner proof type as a bottom type (i.e. a type
// with no values).
None
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
}
fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
}
}
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
fn query_info(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
fn query_fee_details(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment_rpc_runtime_api::FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
fn query_weight_to_fee(weight: Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
let storage_info = AllPalletsWithSystem::storage_info();
(list, storage_info)
}
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
impl frame_system_benchmarking::Config for Runtime {}
impl baseline::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
// Execution Phase
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
// Event Count
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
];
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmarks!(params, batches);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
impl module_issue_rpc_runtime_api::IssueApi<
Block,
AccountId,
H256,
IssueRequest<AccountId, BlockNumber, Balance, CurrencyId>
> for Runtime {
fn get_issue_requests(account_id: AccountId) -> Vec<H256> {
Issue::get_issue_requests_for_account(account_id)
}
fn get_vault_issue_requests(vault_id: AccountId) -> Vec<H256> {
Issue::get_issue_requests_for_vault(vault_id)
}
}
impl module_vault_registry_rpc_runtime_api::VaultRegistryApi<
Block,
VaultId,
Balance,
UnsignedFixedPoint,
CurrencyId,
AccountId,
> for Runtime {
fn get_vault_collateral(vault_id: VaultId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let result = VaultRegistry::compute_collateral(&vault_id)?;
Ok(BalanceWrapper{amount:result.amount()})
}
fn get_vaults_by_account_id(account_id: AccountId) -> Result<Vec<VaultId>, DispatchError> {
VaultRegistry::get_vaults_by_account_id(account_id)
}
fn get_vault_total_collateral(vault_id: VaultId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let result = VaultRegistry::get_backing_collateral(&vault_id)?;
Ok(BalanceWrapper{amount:result.amount()})
}
fn get_premium_redeem_vaults() -> Result<Vec<(VaultId, BalanceWrapper<Balance>)>, DispatchError> {
let result = VaultRegistry::get_premium_redeem_vaults()?;
Ok(result.iter().map(|v| (v.0.clone(), BalanceWrapper{amount:v.1.amount()})).collect())
}
fn get_vaults_with_issuable_tokens() -> Result<Vec<(VaultId, BalanceWrapper<Balance>)>, DispatchError> {
let result = VaultRegistry::get_vaults_with_issuable_tokens()?;
Ok(result.into_iter().map(|v| (v.0, BalanceWrapper{amount:v.1.amount()})).collect())
}
fn get_vaults_with_redeemable_tokens() -> Result<Vec<(VaultId, BalanceWrapper<Balance>)>, DispatchError> {
let result = VaultRegistry::get_vaults_with_redeemable_tokens()?;
Ok(result.into_iter().map(|v| (v.0, BalanceWrapper{amount:v.1.amount()})).collect())
}
fn get_issuable_tokens_from_vault(vault: VaultId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let result = VaultRegistry::get_issuable_tokens_from_vault(&vault)?;
Ok(BalanceWrapper{amount:result.amount()})
}
fn get_collateralization_from_vault(vault: VaultId, only_issued: bool) -> Result<UnsignedFixedPoint, DispatchError> {
VaultRegistry::get_collateralization_from_vault(vault, only_issued)
}
fn get_collateralization_from_vault_and_collateral(vault: VaultId, collateral: BalanceWrapper<Balance>, only_issued: bool) -> Result<UnsignedFixedPoint, DispatchError> {
let amount = Amount::new(collateral.amount, vault.collateral_currency());
VaultRegistry::get_collateralization_from_vault_and_collateral(vault, &amount, only_issued)
}
fn get_required_collateral_for_wrapped(amount_wrapped: BalanceWrapper<Balance>, wrapped_currency_id: CurrencyId, collateral_currency_id: CurrencyId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let amount_wrapped = Amount::new(amount_wrapped.amount, wrapped_currency_id);
let result = VaultRegistry::get_required_collateral_for_wrapped(&amount_wrapped, collateral_currency_id)?;
Ok(BalanceWrapper{amount:result.amount()})
}
fn get_required_collateral_for_vault(vault_id: VaultId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let result = VaultRegistry::get_required_collateral_for_vault(vault_id)?;
Ok(BalanceWrapper{amount:result.amount()})
}
}
impl module_redeem_rpc_runtime_api::RedeemApi<
Block,
AccountId,
H256,
RedeemRequest<AccountId, BlockNumber, Balance, CurrencyId>
> for Runtime {
fn get_redeem_requests(account_id: AccountId) -> Vec<H256> {
Redeem::get_redeem_requests_for_account(account_id)
}
fn get_vault_redeem_requests(vault_account_id: AccountId) -> Vec<H256> {
Redeem::get_redeem_requests_for_vault(vault_account_id)
}
}
impl module_replace_rpc_runtime_api::ReplaceApi<
Block,
AccountId,
H256,
ReplaceRequest<AccountId, BlockNumber, Balance, CurrencyId>
> for Runtime {
fn get_old_vault_replace_requests(vault_id: AccountId) -> Vec<H256> {
Replace::get_replace_requests_for_old_vault(vault_id)
}
fn get_new_vault_replace_requests(vault_id: AccountId) -> Vec<H256> {
Replace::get_replace_requests_for_new_vault(vault_id)
}
}
impl module_oracle_rpc_runtime_api::OracleApi<
Block,
Balance,
CurrencyId
> for Runtime {
fn currency_to_usd(amount: BalanceWrapper<Balance>, currency_id: CurrencyId) -> Result<BalanceWrapper<Balance>, DispatchError> {
let result = Oracle::currency_to_usd(amount.amount, currency_id)?;
Ok(BalanceWrapper{amount:result})
}
fn usd_to_currency(amount: BalanceWrapper<Balance>, currency_id: CurrencyId) -> Result<BalanceWrapper<Balance>, DispatchError> {