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
use crate::prod_or_testnet_or_local;
use common_primitives::node::{Balance, BlockNumber};
use parity_scale_codec::{Encode, MaxEncodedLen};

use frame_support::{
	parameter_types,
	sp_runtime::{Perbill, Permill},
	traits::{ConstU128, ConstU16, ConstU32, ConstU64, ConstU8},
	weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
	PalletId,
};

// Duplicated in runtime/frequency/build.rs to keep build dependencies low
pub const FREQUENCY_TESTNET_TOKEN: &str = "XRQCY";
pub const FREQUENCY_LOCAL_TOKEN: &str = "UNIT";
pub const FREQUENCY_TOKEN: &str = "FRQCY";
pub const TOKEN_DECIMALS: u8 = 8;

/// The maximum number of schema grants allowed per delegation
pub type MaxSchemaGrants = ConstU32<30>;

/// This determines the average expected block time that we are targeting.
/// 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 = 6_000;

// NOTE: Currently it is not possible to change the slot duration after the chain has started.
//       Attempting to do so will brick block production.
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;

// Unit = the base number of indivisible units for balances
pub mod currency {
	use common_primitives::node::Balance;

	/// The existential deposit. Set to be 1/100th of a token.
	pub const EXISTENTIAL_DEPOSIT: Balance = CENTS;

	pub const UNITS: Balance = 10u128.saturating_pow(super::TOKEN_DECIMALS as u32);
	pub const DOLLARS: Balance = UNITS; // 100_000_000
	pub const CENTS: Balance = DOLLARS / 100; // 1_000_000
	pub const MILLICENTS: Balance = CENTS / 1_000; // 1_000

	/// Generates a balance based on amount of items and bytes
	/// Items are each worth 20 Dollars
	/// Bytes each cost 1/1_000 of a Dollar
	pub const fn deposit(items: u32, bytes: u32) -> Balance {
		items as Balance * 20 * DOLLARS + (bytes as Balance) * 100 * MILLICENTS
	}
}

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);

/// 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 2 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
	WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
	cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

pub type ZERO = ConstU32<0>;
pub type TWO = ConstU32<2>;
pub type FIFTY = ConstU32<50>;
pub type HUNDRED = ConstU32<100>;

// --- Frame System Pallet ---
pub type FrameSystemMaxConsumers = ConstU32<16>;
// -end- Frame System Pallet ---

// --- MSA Pallet ---
/// The maximum number of public keys per MSA
pub type MsaMaxPublicKeysPerMsa = ConstU8<25>;
/// The maximum size of the provider name (in bytes)
pub type MsaMaxProviderNameSize = ConstU32<16>;
/// The number of blocks per virtual bucket
pub type MSAMortalityWindowSize = ConstU32<{ 20 * MINUTES }>;
/// The upper limit on total stored signatures.
/// Set to an average of 50 signatures per block
pub type MSAMaxSignaturesStored = ConstU32<50_000>;
// -end- MSA Pallet ---

// --- Schemas Pallet ---
parameter_types! {
	/// The maximum length of a schema model (in bytes)
	pub const SchemasMaxBytesBoundedVecLimit :u32 = 65_500;
}
/// The maximum number of schema registrations
pub type SchemasMaxRegistrations = ConstU16<65_000>;
/// The minimum schema model size (in bytes)
pub type SchemasMinModelSizeBytes = ConstU32<8>;
/// The maximum number of grants allowed per schema
pub type MaxSchemaSettingsPerSchema = ConstU32<2>;

impl Encode for SchemasMaxBytesBoundedVecLimit {}

impl MaxEncodedLen for SchemasMaxBytesBoundedVecLimit {
	fn max_encoded_len() -> usize {
		u32::max_encoded_len()
	}
}
// -end- Schemas Pallet ---

// --- Handles Pallet ---
// IMPORTANT: These values should only increase and never overlap with a previous set!
/// The minimum suffix value
pub type HandleSuffixMin = ConstU16<10>;
/// The maximum suffix value
pub type HandleSuffixMax = ConstU16<99>;
// -end- Handles Pallet

// --- TimeRelease Pallet ---
// Update
pub type MinReleaseTransfer = ConstU128<0>;

/// Update
pub const MAX_RELEASE_SCHEDULES: u32 = 50;
// -end- TimeRelease Pallet ---

// --- Timestamp Pallet ---
pub type MinimumPeriod = ConstU64<0>;
// -end- Timestamp Pallet ---

// --- Authorship Pallet ---
pub type AuthorshipUncleGenerations = ZERO;
// -end- Authorship Pallet ---

// --- Balances Pallet ---
pub type BalancesMaxLocks = FIFTY;
pub type BalancesMaxReserves = FIFTY;
pub type BalancesMaxFreezes = TWO; // capacity + time-release
								   // -end- Balances Pallet ---

// --- Scheduler Pallet ---
pub type SchedulerMaxScheduledPerBlock = FIFTY;
// -end- Scheduler Pallet ---

// --- Preimage Pallet ---
/// Preimage maximum size set to 4 MB
/// Expected to be removed in Polkadot v0.9.31
pub type PreimageMaxSize = ConstU32<{ 4096 * 1024 }>;

pub type PreimageBaseDeposit = ConstU128<{ currency::deposit(10, 64) }>;
pub type PreimageByteDeposit = ConstU128<{ currency::deposit(0, 1) }>;
// -end- Preimage Pallet ---

// --- Council ---
// The maximum number of council proposals
pub type CouncilMaxProposals = ConstU32<25>;
// The maximum number of council members
pub type CouncilMaxMembers = ConstU32<10>;

pub type CouncilMotionDuration = ConstU32<{ 5 * DAYS }>;
// -end- Council ---

// --- Technical Committee ---
// The maximum number of technical committee proposals
pub type TCMaxProposals = ConstU32<25>;
// The maximum number of technical committee members
pub type TCMaxMembers = ConstU32<10>;

pub type TCMotionDuration = ConstU32<{ 5 * DAYS }>;
// -end- Technical Committee ---

// --- Democracy Pallet ---
// Config from
// https://github.com/paritytech/substrate/blob/367dab0d4bd7fd7b6c222dd15c753169c057dd42/bin/node/runtime/src/lib.rs#L880
pub type LaunchPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
pub type VotingPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
pub type FastTrackVotingPeriod =
	ConstU32<{ prod_or_testnet_or_local!(3 * HOURS, 30 * MINUTES, 5 * MINUTES) }>;
pub type EnactmentPeriod =
	ConstU32<{ prod_or_testnet_or_local!(8 * DAYS, 30 * HOURS, 10 * MINUTES) }>;
pub type CooloffPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
pub type MinimumDeposit = ConstU128<
	{
		prod_or_testnet_or_local!(
			currency::deposit(5, 0),
			100 * currency::deposit(5, 0),
			100 * currency::deposit(5, 0)
		)
	},
>;
pub type SpendPeriod =
	ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 10 * MINUTES, 10 * MINUTES) }>;
pub type DemocracyMaxVotes = ConstU32<100>;
pub type DemocracyMaxProposals = HUNDRED;
// -end- Democracy Pallet ---

// --- Treasury Pallet ---
/// Generates the pallet "account"
/// 5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z
pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");

// https://wiki.polkadot.network/docs/learn-treasury
// https://paritytech.github.io/substrate/master/pallet_treasury/pallet/trait.Config.html
// Needs parameter_types! for the Permill and PalletId
parameter_types! {

	/// Keyless account that holds the money for the treasury
	pub const TreasuryPalletId: PalletId = TREASURY_PALLET_ID;

	/// Bond amount a treasury request must put up to make the proposal
	/// This will be transferred to OnSlash if the proposal is rejected
	pub const ProposalBondPercent: Permill = Permill::from_percent(5);

	/// How much of the treasury to burn, if funds remain at the end of the SpendPeriod
	/// Set to zero until the economic system is setup and stabilized
	pub const Burn: Permill = Permill::zero();
}

/// Maximum number of approved proposals per Spending Period
/// Set to 64 or 16 per week
pub type MaxApprovals = ConstU32<64>;

/// Minimum bond for a treasury proposal
pub type ProposalBondMinimum = ConstU128<{ 100 * currency::DOLLARS }>;

/// Minimum bond for a treasury proposal
pub type ProposalBondMaximum = ConstU128<{ 1_000 * currency::DOLLARS }>;

// -end- Treasury Pallet ---

// --- Transaction Payment Pallet ---
// The fee multiplier
pub type TransactionPaymentOperationalFeeMultiplier = ConstU8<5>;

/// Relay Chain `TransactionByteFee` / 10
pub type TransactionByteFee = ConstU128<{ 10 * currency::MILLICENTS }>;
// -end- Transaction Payment Pallet ---

// --- Frequency Transaction Payment Pallet ---
pub type MaximumCapacityBatchLength = ConstU8<10>;
// -end- Frequency Transaction Payment Pallet ---

// --- Session Pallet ---
pub type SessionPeriod = ConstU32<{ 6 * HOURS }>;
pub type SessionOffset = ZERO;
// -end- Session Pallet ---

// --- Aura Pallet ---
/// The maximum number of authorities
pub type AuraMaxAuthorities = ConstU32<100_000>;
// -end- Aura Pallet ---

// --- Collator Selection Pallet ---
// Values for each runtime environment are independently configurable.
// Example CollatorMaxInvulnerables are 16 in production(mainnet),
// 5 in testnet and 5 in local

pub type CollatorMaxCandidates = ConstU32<50>;
pub type CollatorMinCandidates = ConstU32<{ prod_or_testnet_or_local!(1, 0, 0) }>;
pub type CollatorMaxInvulnerables = ConstU32<{ prod_or_testnet_or_local!(16, 5, 5) }>;
pub type CollatorKickThreshold =
	ConstU32<{ prod_or_testnet_or_local!(6 * HOURS, 6 * HOURS, 6 * HOURS) }>;

// Needs parameter_types! for the PalletId and impls below
parameter_types! {
	pub const NeverDepositIntoId: PalletId = PalletId(*b"NeverDep");
	pub const MessagesMaxPayloadSizeBytes: u32 = 1024 * 3; // 3K
}
// -end- Collator Selection Pallet ---

// --- Proxy Pallet ---
// Copied from Polkadot Runtime v1.2.0
parameter_types! {
	// One storage item; key size 32, value size 8; .
	pub const ProxyDepositBase: Balance = currency::deposit(1, 8);
	// Additional storage item size of 33 bytes.
	pub const ProxyDepositFactor: Balance = currency::deposit(0, 33);
	pub const MaxProxies: u16 = 32;
	pub const AnnouncementDepositBase: Balance = currency::deposit(1, 8);
	pub const AnnouncementDepositFactor: Balance = currency::deposit(0, 66);
	pub const MaxPending: u16 = 32;
}
// -end- Proxy Pallet ---

// --- Messages Pallet ---
impl Clone for MessagesMaxPayloadSizeBytes {
	fn clone(&self) -> Self {
		MessagesMaxPayloadSizeBytes {}
	}
}

impl sp_std::fmt::Debug for MessagesMaxPayloadSizeBytes {
	#[cfg(feature = "std")]
	fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		write!(f, "MessagesMaxPayloadSizeBytes<{:?}>", Self::get())
	}

	#[cfg(not(feature = "std"))]
	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		Ok(())
	}
}

impl Encode for MessagesMaxPayloadSizeBytes {}

impl MaxEncodedLen for MessagesMaxPayloadSizeBytes {
	fn max_encoded_len() -> usize {
		u32::max_encoded_len()
	}
}
// -end- Messages Pallet ---

// Needs parameter_types! to reduce pallet dependencies
parameter_types! {
	/// SS58 Prefix for the for Frequency Network
	/// 90 is the prefix for the Frequency Network on Polkadot
	/// 42 is the default prefix elsewhere
	pub const Ss58Prefix: u16 = prod_or_testnet_or_local!(90, 42, 42);
}

// --- Stateful Storage Pallet ---
// Needs parameter_types! for the impls below
parameter_types! {
	/// The maximum size of a single item in an itemized storage model (in bytes)
	pub const MaxItemizedBlobSizeBytes: u32 = 1024;
	/// The maximum size of a page (in bytes) for an Itemized storage model ~ (10KiB)
	/// extra 2 bytes is for ItemHeader which enables us to simulate max PoV in benchmarks
	pub const MaxItemizedPageSizeBytes: u32 = 10 * (1024 + 2);
	/// The maximum size of a page (in bytes) for a Paginated storage model (1KiB)
	pub const MaxPaginatedPageSizeBytes: u32 = 1 * 1024;
}
/// The maximum number of pages in a Paginated storage model
pub type MaxPaginatedPageId = ConstU16<32>;
/// The maximum number of actions in itemized actions
pub type MaxItemizedActionsCount = ConstU32<5>;
/// The number of blocks for Stateful mortality is 48 hours
pub type StatefulMortalityWindowSize = ConstU32<{ 2 * DAYS }>;
// -end- Stateful Storage Pallet

impl Default for MaxItemizedPageSizeBytes {
	fn default() -> Self {
		Self
	}
}

impl Default for MaxPaginatedPageSizeBytes {
	fn default() -> Self {
		Self
	}
}

impl Clone for MaxItemizedBlobSizeBytes {
	fn clone(&self) -> Self {
		MaxItemizedBlobSizeBytes {}
	}
}

impl Eq for MaxItemizedBlobSizeBytes {
	fn assert_receiver_is_total_eq(&self) {}
}

impl PartialEq for MaxItemizedBlobSizeBytes {
	fn eq(&self, other: &Self) -> bool {
		self == other
	}
}

impl sp_std::fmt::Debug for MaxItemizedBlobSizeBytes {
	#[cfg(feature = "std")]
	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		Ok(())
	}

	#[cfg(not(feature = "std"))]
	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		Ok(())
	}
}

// --- Capacity Pallet ---
pub type CapacityMinimumStakingAmount = ConstU128<{ currency::EXISTENTIAL_DEPOSIT }>;
pub type CapacityMinimumTokenBalance = ConstU128<{ currency::DOLLARS }>;
pub type CapacityMaxUnlockingChunks = ConstU32<4>;
pub type CapacityMaxEpochLength = ConstU32<{ 2 * DAYS }>; // Two days, assuming 6 second blocks.

#[cfg(not(any(feature = "frequency-local", feature = "frequency-no-relay")))]
pub type CapacityUnstakingThawPeriod = ConstU16<30>; // 30 Epochs, or 30 days given the above

#[cfg(any(feature = "frequency-local", feature = "frequency-no-relay"))]
pub type CapacityUnstakingThawPeriod = ConstU16<2>; // 2 Epochs

// Needs parameter_types! for the Perbil
parameter_types! {
	// 1:50 Capacity:Token, must be declared this way instead of using `from_rational` because of
	//  ```error[E0015]: cannot call non-const fn `Perbill::from_rational::<u32>` in constant functions```
	pub const CapacityPerToken: Perbill = Perbill::from_percent(2);
	pub const CapacityRewardCap: Permill = Permill::from_parts(5_750);  // 0.575% or 0.00575 per RewardEra
}
pub type CapacityRewardEraLength =
	ConstU32<{ prod_or_testnet_or_local!(14 * DAYS, 1 * HOURS, 50) }>;

// -end- Capacity Pallet ---