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
// KILT Blockchain – https://botlabs.org
// Copyright (C) 2019-2024 BOTLabs GmbH

// The KILT Blockchain 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.

// The KILT Blockchain 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/>.

// If you feel like getting in touch with us, you can do so at info@botlabs.org

use frame_support::{
	parameter_types,
	traits::WithdrawReasons,
	weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use sp_runtime::{Perbill, Percent, Perquintill};

use parachain_staking::InflationInfo;

use crate::{Balance, BlockNumber};

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet
/// included into the relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent.
/// Limits the number of blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

/// This determines the average expected block time that we are targetting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 12_000;

pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

// Time is measured by 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;
// Julian year as Substrate handles it
pub const BLOCKS_PER_YEAR: BlockNumber = DAYS * 36525 / 100;

pub const MAX_COLLATOR_STAKE: Balance = 200_000 * KILT;

/// One KILT
pub const KILT: Balance = 10u128.pow(15);

/// 0.001 KILT
pub const MILLI_KILT: Balance = 10u128.pow(12);

/// 0.000_001 KILT
pub const MICRO_KILT: Balance = 10u128.pow(9);

pub const EXISTENTIAL_DEPOSIT: Balance = 10 * MILLI_KILT;

/// Deposit that must be provided for each occupied storage item.
pub const DEPOSIT_STORAGE_ITEM: Balance = 56 * MILLI_KILT;

/// Deposit that must be provided for each occupied storage byte.
pub const DEPOSIT_STORAGE_BYTE: Balance = 50 * MICRO_KILT;
// 1 in 4 blocks (on average, not counting collisions) will be primary babe
// blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

/// We assume that ~10% of the block weight is consumed by `on_initalize`
/// handlers. This is used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// 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);
/// We allow for 0.5 seconds of compute with a 12 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
	WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
	cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

pub const INFLATION_CONFIG: (Perquintill, Perquintill, Perquintill, Perquintill) = (
	// max collator staking rate
	Perquintill::from_percent(40),
	// collator reward rate
	Perquintill::from_percent(10),
	// max delegator staking rate
	Perquintill::from_percent(10),
	// delegator reward rate
	Perquintill::from_percent(8),
);

/// Inflation configuration which is used at genesis
pub fn kilt_inflation_config() -> InflationInfo {
	InflationInfo::new(
		BLOCKS_PER_YEAR,
		// max collator staking rate
		Perquintill::from_percent(40),
		// collator reward rate
		Perquintill::from_percent(10),
		// max delegator staking rate
		Perquintill::from_percent(10),
		// delegator reward rate
		Perquintill::from_percent(8),
	)
}

/// Calculate the storage deposit based on the number of storage items and the
/// combined byte size of those items.
pub const fn deposit(items: u32, bytes: u32) -> Balance {
	items as Balance * DEPOSIT_STORAGE_ITEM + (bytes as Balance) * DEPOSIT_STORAGE_BYTE
}

/// The size of an index in the index pallet.
/// The size is checked in the runtime by a test.
pub const MAX_INDICES_BYTE_LENGTH: u32 = 49;

/// Copied from Kusama & Polkadot runtime
pub const MAX_VESTING_SCHEDULES: u32 = 28;

parameter_types! {
	/// Vesting Pallet. Copied from Kusama & Polkadot runtime
	pub const MinVestedTransfer: Balance = 100 * MILLI_KILT;
	pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
		WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
	/// Deposits per byte
	pub const ByteDeposit: Balance = deposit(0, 1);
	/// Index Pallet. Deposit taken for an account index
	pub const IndicesDeposit: Balance = deposit(1, MAX_INDICES_BYTE_LENGTH);
	/// CType Pallet. Per byte fee for a ctype.
	pub const CtypeFee: Balance = MILLI_KILT;
}

pub mod attestation {
	use super::*;

	/// The size is checked in the runtime by a test.
	pub const MAX_ATTESTATION_BYTE_LENGTH: u32 = 179;
	pub const ATTESTATION_DEPOSIT: Balance = deposit(2, MAX_ATTESTATION_BYTE_LENGTH);

	parameter_types! {
		pub const MaxDelegatedAttestations: u32 = 1000;
		pub const AttestationDeposit: Balance = ATTESTATION_DEPOSIT;
	}
}

pub mod assets {
	use super::*;

	pub const APPROVAL_DEPOSIT: u128 = 0;
	pub const ASSET_ACCOUNT_DEPOSIT: u128 = 0;
	pub const ASSET_DEPOSIT: u128 = 0;
	pub const META_DEPOSIT_BASE: u128 = 0;
	pub const META_DEPOSIT_PER_BYTE: u128 = 0;
	pub const REMOVE_ITEMS_LIMIT: u32 = 1000;
	pub const STRING_LIMIT: u32 = 4;

	parameter_types! {
		pub const ApprovalDeposit: u128 = APPROVAL_DEPOSIT;
		pub const AssetAccountDeposit: u128 = ASSET_ACCOUNT_DEPOSIT;
		pub const AssetDeposit: u128 = ASSET_DEPOSIT;
		pub const MetaDepositBase: u128 = META_DEPOSIT_BASE;
		pub const MetaDepositPerByte: u128 = META_DEPOSIT_PER_BYTE;
		pub const RemoveItemsLimit: u32 = REMOVE_ITEMS_LIMIT;
		pub const StringLimit: u32 = STRING_LIMIT;
	}
}

pub mod delegation {
	use scale_info::TypeInfo;

	use super::*;

	pub const DELEGATION_DEPOSIT: Balance = KILT;
	pub const MAX_SIGNATURE_BYTE_LENGTH: u16 = 64;
	pub const MAX_PARENT_CHECKS: u32 = 5;
	pub const MAX_REVOCATIONS: u32 = 5;
	pub const MAX_REMOVALS: u32 = MAX_REVOCATIONS;
	pub const MAX_CHILDREN: u32 = 1000;

	parameter_types! {
		pub const MaxSignatureByteLength: u16 = MAX_SIGNATURE_BYTE_LENGTH;
		pub const MaxParentChecks: u32 = MAX_PARENT_CHECKS;
		pub const MaxRevocations: u32 = MAX_REVOCATIONS;
		pub const MaxRemovals: u32 = MAX_REMOVALS;
		#[derive(Clone, TypeInfo)]
		pub const MaxChildren: u32 = MAX_CHILDREN;
		pub const DelegationDeposit: Balance = DELEGATION_DEPOSIT;
	}
}

pub mod deposit_storage {
	// Keys is an enum with a single variant (DidIdentifier,
	// IdentityCommitmentVersion) which is 32 + 2 = 34 bytes. Adding the
	// discriminant byte, it totals to 35 bytes.
	pub const MAX_DEPOSIT_PALLET_KEY_LENGTH: u32 = 35;
}

pub mod dip_provider {
	use super::*;

	pub const MAX_LINKED_ACCOUNTS: u32 = 10;
	// Commitment are 32-byte hashes.
	pub const MAX_COMMITMENT_BYTE_LENGTH: u32 = 32;
	pub const COMMITMENT_DEPOSIT: Balance = deposit(1, MAX_COMMITMENT_BYTE_LENGTH);
}

pub mod staking {
	use super::*;

	/// Minimum round length is 1 hour (300 * 12 second block times)
	#[cfg(feature = "fast-gov")]
	pub const MIN_BLOCKS_PER_ROUND: BlockNumber = 10;
	#[cfg(not(feature = "fast-gov"))]
	pub const MIN_BLOCKS_PER_ROUND: BlockNumber = HOURS;

	#[cfg(feature = "fast-gov")]
	pub const DEFAULT_BLOCKS_PER_ROUND: BlockNumber = 20;
	#[cfg(not(feature = "fast-gov"))]
	pub const DEFAULT_BLOCKS_PER_ROUND: BlockNumber = 2 * HOURS;

	#[cfg(feature = "fast-gov")]
	pub const STAKE_DURATION: BlockNumber = 30;
	#[cfg(not(feature = "fast-gov"))]
	pub const STAKE_DURATION: BlockNumber = 7 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const MIN_COLLATORS: u32 = 4;
	#[cfg(not(feature = "fast-gov"))]
	pub const MIN_COLLATORS: u32 = 16;

	#[cfg(feature = "fast-gov")]
	pub const MAX_CANDIDATES: u32 = 16;
	#[cfg(not(feature = "fast-gov"))]
	pub const MAX_CANDIDATES: u32 = 75;

	pub const MAX_DELEGATORS_PER_COLLATOR: u32 = 35;
	pub const MIN_DELEGATOR_STAKE: Balance = 20 * KILT;

	pub const NETWORK_REWARD_RATE: Perquintill = Perquintill::from_percent(10);

	parameter_types! {
		/// Minimum round length is 1 hour
		pub const MinBlocksPerRound: BlockNumber = MIN_BLOCKS_PER_ROUND;
		/// Default length of a round/session is 2 hours
		pub const DefaultBlocksPerRound: BlockNumber = DEFAULT_BLOCKS_PER_ROUND;
		/// Unstaked balance can be unlocked after 7 days
		pub const StakeDuration: BlockNumber = STAKE_DURATION;
		/// Collator exit requests are delayed by 4 hours (2 rounds/sessions)
		pub const ExitQueueDelay: u32 = 2;
		/// Minimum 16 collators selected per round, default at genesis and minimum forever after
		pub const MinCollators: u32 = MIN_COLLATORS;
		/// At least 4 candidates which cannot leave the network if there are no other candidates.
		pub const MinRequiredCollators: u32 = 4;
		/// We only allow one delegation per round.
		pub const MaxDelegationsPerRound: u32 = 1;
		/// Maximum 25 delegators per collator at launch, might be increased later
		#[derive(Debug, Eq, PartialEq)]
		pub const MaxDelegatorsPerCollator: u32 = MAX_DELEGATORS_PER_COLLATOR;
		/// Minimum stake required to be reserved to be a collator is 10_000
		pub const MinCollatorStake: Balance = 10_000 * KILT;
		/// Minimum stake required to be reserved to be a delegator is 1000
		pub const MinDelegatorStake: Balance = MIN_DELEGATOR_STAKE;
		/// Maximum number of collator candidates
		#[derive(Debug, Eq, PartialEq)]
		pub const MaxCollatorCandidates: u32 = MAX_CANDIDATES;
		/// Maximum number of concurrent requests to unlock unstaked balance
		pub const MaxUnstakeRequests: u32 = 10;
		/// The starting block number for the network rewards
		pub const NetworkRewardStart: BlockNumber = super::treasury::INITIAL_PERIOD_LENGTH;
		/// The rate in percent for the network rewards
		pub const NetworkRewardRate: Perquintill = NETWORK_REWARD_RATE;
	}
}

pub mod governance {
	use super::*;

	pub const MIN_DEPOSIT: Balance = KILT;

	#[cfg(feature = "fast-gov")]
	pub const LAUNCH_PERIOD: BlockNumber = 7 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const LAUNCH_PERIOD: BlockNumber = 7 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const VOTING_PERIOD: BlockNumber = 7 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const VOTING_PERIOD: BlockNumber = 7 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const FAST_TRACK_VOTING_PERIOD: BlockNumber = 3 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const FAST_TRACK_VOTING_PERIOD: BlockNumber = 3 * HOURS;

	#[cfg(feature = "fast-gov")]
	pub const ENACTMENT_PERIOD: BlockNumber = 8 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const ENACTMENT_PERIOD: BlockNumber = DAYS;

	#[cfg(feature = "fast-gov")]
	pub const COOLOFF_PERIOD: BlockNumber = 7 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const COOLOFF_PERIOD: BlockNumber = 7 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const SPEND_PERIOD: BlockNumber = 6 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const SPEND_PERIOD: BlockNumber = 6 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const ROTATION_PERIOD: BlockNumber = 80 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const ROTATION_PERIOD: BlockNumber = 80 * HOURS;

	#[cfg(feature = "fast-gov")]
	pub const TERM_DURATION: BlockNumber = 15 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const TERM_DURATION: BlockNumber = DAYS;

	#[cfg(feature = "fast-gov")]
	pub const COUNCIL_MOTION_DURATION: BlockNumber = 4 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const COUNCIL_MOTION_DURATION: BlockNumber = 7 * DAYS;

	#[cfg(feature = "fast-gov")]
	pub const TECHNICAL_MOTION_DURATION: BlockNumber = 4 * MINUTES;
	#[cfg(not(feature = "fast-gov"))]
	pub const TECHNICAL_MOTION_DURATION: BlockNumber = 7 * DAYS;

	parameter_types! {
		// Democracy Pallet
		pub const LaunchPeriod: BlockNumber = LAUNCH_PERIOD;
		pub const VotingPeriod: BlockNumber = VOTING_PERIOD;
		pub const FastTrackVotingPeriod: BlockNumber = FAST_TRACK_VOTING_PERIOD;
		pub const MinimumDeposit: Balance = MIN_DEPOSIT;
		pub const EnactmentPeriod: BlockNumber = ENACTMENT_PERIOD;
		pub const CooloffPeriod: BlockNumber = COOLOFF_PERIOD;
		// Council Pallet
		pub const CouncilMotionDuration: BlockNumber = COUNCIL_MOTION_DURATION;
		pub const CouncilMaxProposals: u32 = 100;
		pub const CouncilMaxMembers: u32 = 100;
		// Technical Committee
		pub const TechnicalMotionDuration: BlockNumber = TECHNICAL_MOTION_DURATION;
		pub const TechnicalMaxProposals: u32 = 100;
		pub const TechnicalMaxMembers: u32 = 100;
		// Tipper Group
		pub const TipperMaxMembers: u32 = 21;
	}
}

pub mod multisig {
	use super::*;

	parameter_types! {
		pub const MaxSignitors: u32 = 64;
		pub const DepositBase: Balance = DEPOSIT_STORAGE_ITEM;
		pub const DepositFactor: Balance = DEPOSIT_STORAGE_BYTE;
	}
}

pub mod pallet_migration {
	use super::*;

	parameter_types! {
		pub const  MaxMigrationsPerPallet: u32 = 100;
	}
}

pub mod did {
	use parity_scale_codec::{Decode, Encode};
	use scale_info::TypeInfo;

	use super::*;

	///  Max length of a key (including its enum discriminants).
	pub const MAX_KEY_LENGTH: u32 = 35;

	///  Max length of a single service entry.
	/// It is the sum of:
	/// - the maximum service ID length
	/// - the maximum service type length * the maximum number of service types
	///   for a single service
	/// - the maximum service URL length * the maximum number of URLs for a
	///   single service
	/// - Additional padding bytes to make up for the different encoding size of
	///   the different const values (each BoundedVec has additional bytes
	///   encoded in compact form indicating the max length of the vec)
	pub const MAX_SERVICE_ENDPOINT_BYTE_LENGTH: u32 = MAX_SERVICE_ID_LENGTH
		+ MAX_NUMBER_OF_TYPES_PER_SERVICE * MAX_SERVICE_TYPE_LENGTH
		+ MAX_NUMBER_OF_URLS_PER_SERVICE * MAX_SERVICE_URL_LENGTH
		+ 8;

	pub const DID_BASE_DEPOSIT: Balance = 2 * KILT;
	pub const KEY_DEPOSIT: Balance = deposit(0, MAX_KEY_LENGTH);
	pub const SERVICE_ENDPOINT_DEPOSIT: Balance = deposit(1, MAX_SERVICE_ENDPOINT_BYTE_LENGTH);

	pub const DID_FEE: Balance = 50 * MILLI_KILT;
	pub const MAX_KEY_AGREEMENT_KEYS: u32 = 10;
	// This has been reduced from the previous 100, but it might still need
	// fine-tuning depending on our needs.
	pub const MAX_PUBLIC_KEYS_PER_DID: u32 = 20;
	// At most the max number of keys - 1 for authentication
	pub const MAX_TOTAL_KEY_AGREEMENT_KEYS: u32 = MAX_PUBLIC_KEYS_PER_DID - 1;
	pub const MAX_BLOCKS_TX_VALIDITY: BlockNumber = HOURS;

	pub const MAX_NUMBER_OF_SERVICES_PER_DID: u32 = 25;
	pub const MAX_SERVICE_ID_LENGTH: u32 = 50;
	pub const MAX_SERVICE_TYPE_LENGTH: u32 = 50;
	pub const MAX_NUMBER_OF_TYPES_PER_SERVICE: u32 = 1;
	pub const MAX_SERVICE_URL_LENGTH: u32 = 2_000;
	pub const MAX_NUMBER_OF_URLS_PER_SERVICE: u32 = 2;

	parameter_types! {
		#[derive(Debug, Clone, Eq, PartialEq, TypeInfo, Decode, Encode)]
		pub const MaxNewKeyAgreementKeys: u32 = MAX_KEY_AGREEMENT_KEYS;
		#[derive(Clone)]
		pub const MaxPublicKeysPerDid: u32 = MAX_PUBLIC_KEYS_PER_DID;
		#[derive(Debug, Clone, Eq, PartialEq)]
		pub const MaxTotalKeyAgreementKeys: u32 = MAX_TOTAL_KEY_AGREEMENT_KEYS;
		// Standalone block time is half the duration of a parachain block.
		pub const MaxBlocksTxValidity: BlockNumber = MAX_BLOCKS_TX_VALIDITY;
		pub const DidBaseDeposit: Balance = DID_BASE_DEPOSIT;
		pub const KeyDeposit: Balance = KEY_DEPOSIT;
		pub const ServiceEndpointDeposit: Balance = SERVICE_ENDPOINT_DEPOSIT;
		pub const DidFee: Balance = DID_FEE;
		pub const MaxNumberOfServicesPerDid: u32 = MAX_NUMBER_OF_SERVICES_PER_DID;
		pub const MaxServiceIdLength: u32 = MAX_SERVICE_ID_LENGTH;
		pub const MaxServiceTypeLength: u32 = MAX_SERVICE_TYPE_LENGTH;
		pub const MaxServiceUrlLength: u32 = MAX_SERVICE_URL_LENGTH;
		pub const MaxNumberOfTypesPerService: u32 = MAX_NUMBER_OF_TYPES_PER_SERVICE;
		pub const MaxNumberOfUrlsPerService: u32 = MAX_NUMBER_OF_URLS_PER_SERVICE;
	}
}

pub mod did_lookup {
	use super::*;

	/// The size is checked in the runtime by a test.
	pub const MAX_CONNECTION_BYTE_LENGTH: u32 = 80;
	pub const DID_CONNECTION_DEPOSIT: Balance = deposit(1, MAX_CONNECTION_BYTE_LENGTH);

	parameter_types! {
		pub const DidLookupDeposit: Balance = DID_CONNECTION_DEPOSIT;
	}
}

pub mod treasury {
	use super::*;

	pub const INITIAL_PERIOD_LENGTH: BlockNumber = BLOCKS_PER_YEAR.saturating_mul(5);
	const YEARLY_REWARD: Balance = 2_000_000u128 * KILT;
	pub const INITIAL_PERIOD_REWARD_PER_BLOCK: Balance = YEARLY_REWARD / (BLOCKS_PER_YEAR as Balance);

	parameter_types! {
		pub const InitialPeriodLength: BlockNumber = INITIAL_PERIOD_LENGTH;
		pub const InitialPeriodReward: Balance = INITIAL_PERIOD_REWARD_PER_BLOCK;
		pub const PayoutPeriod: BlockNumber = DAYS * 30;
	}
}

pub mod proxy {
	use super::*;

	parameter_types! {
		// One storage item; key size 32, value size 8; .
		pub const ProxyDepositBase: Balance = deposit(1, 8);
		// Additional storage item size of 33 bytes.
		pub const ProxyDepositFactor: Balance = deposit(0, 33);
		pub const MaxProxies: u16 = 10;
		pub const AnnouncementDepositBase: Balance = deposit(1, 8);
		pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
		pub const MaxPending: u16 = 10;
	}
}

pub mod web3_names {
	use super::*;

	pub const MIN_LENGTH: u32 = 3;
	pub const MAX_LENGTH: u32 = 32;

	/// The size is checked in the runtime by a test.
	pub const MAX_NAME_BYTE_LENGTH: u32 = 121;
	pub const DEPOSIT: Balance = deposit(2, MAX_NAME_BYTE_LENGTH);

	parameter_types! {
		pub const Web3NameDeposit: Balance = DEPOSIT;
		pub const MinNameLength: u32 = MIN_LENGTH;
		pub const MaxNameLength: u32 = MAX_LENGTH;
	}
}

pub mod preimage {
	use super::*;
	parameter_types! {
		pub const PreimageBaseDeposit: Balance = deposit(2, 64);
	}
}

pub mod tips {
	use super::*;

	parameter_types! {
		pub const MaximumReasonLength: u32 = 16384;
		pub const TipCountdown: BlockNumber = DAYS;
		pub const TipFindersFee: Percent = Percent::from_percent(0);
		pub const TipReportDepositBase: Balance = deposit(1, 1);
		pub const MaxTipAmount: Balance = 100_000 * KILT;
	}
}

pub mod fee {
	use super::*;

	parameter_types! {
		/// This value increases the priority of `Operational` transactions by adding
		/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
		pub const OperationalFeeMultiplier: u8 = 5;
		pub const TransactionByteFee: Balance = MICRO_KILT;
	}
}

pub mod public_credentials {
	use super::*;

	/// The size is checked in the runtime by a test.
	pub const MAX_PUBLIC_CREDENTIAL_STORAGE_LENGTH: u32 = 419;
	// Each credential would have a different deposit, so no multiplier here
	pub const PUBLIC_CREDENTIAL_DEPOSIT: Balance = deposit(1, MAX_PUBLIC_CREDENTIAL_STORAGE_LENGTH);

	parameter_types! {
		pub const Deposit: Balance = PUBLIC_CREDENTIAL_DEPOSIT;
		pub const MaxEncodedClaimsLength: u32 = 100_000;	// 100 Kb
		pub const MaxSubjectIdLength: u32 = kilt_asset_dids::MAXIMUM_ASSET_DID_LENGTH as u32;
	}
}

#[cfg(test)]
mod tests {
	use super::*;
	// TODO: static assert
	#[allow(clippy::assertions_on_constants)]
	#[test]
	fn blocks_per_year_saturation() {
		assert!(BLOCKS_PER_YEAR < u64::MAX);
	}
}