referrerpolicy=no-referrer-when-downgrade

testnet_parachains_constants/
westend.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16/// Universally recognized accounts.
17pub mod account {
18	use frame_support::PalletId;
19
20	/// Westend treasury pallet id, used to convert into AccountId - in Westend as a destination for
21	/// slashed funds.
22	pub const WESTEND_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
23	/// Alliance pallet ID - used as a temporary place to deposit a slashed imbalance before the
24	/// teleport to the Treasury.
25	pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia");
26	/// Referenda pallet ID - used as a temporary place to deposit a slashed imbalance before the
27	/// teleport to the Treasury.
28	pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer");
29	/// Ambassador Referenda pallet ID - used as a temporary place to deposit a slashed imbalance
30	/// before the teleport to the Treasury.
31	pub const AMBASSADOR_REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/amref");
32	/// Fellowship treasury pallet ID.
33	pub const FELLOWSHIP_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/feltr");
34}
35
36pub mod currency {
37	use polkadot_core_primitives::Balance;
38	use westend_runtime_constants as constants;
39
40	/// The existential deposit. Set to 1/10 of its parent Relay Chain.
41	pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
42
43	pub const UNITS: Balance = constants::currency::UNITS;
44	pub const DOLLARS: Balance = UNITS; // 1_000_000_000_000
45	pub const CENTS: Balance = constants::currency::CENTS;
46	pub const MILLICENTS: Balance = constants::currency::MILLICENTS;
47	pub const GRAND: Balance = constants::currency::GRAND;
48
49	pub const fn deposit(items: u32, bytes: u32) -> Balance {
50		// 1/100 of Westend testnet
51		constants::currency::deposit(items, bytes) / 100
52	}
53}
54
55/// Fee-related.
56pub mod fee {
57	use frame_support::{
58		pallet_prelude::Weight,
59		weights::{
60			constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient,
61			WeightToFeeCoefficients, WeightToFeePolynomial,
62		},
63	};
64	use polkadot_core_primitives::Balance;
65	use smallvec::smallvec;
66	pub use sp_runtime::Perbill;
67
68	/// The block saturation level. Fees will be updated based on this value.
69	pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
70
71	/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
72	/// node's balance type.
73	///
74	/// This should typically create a mapping between the following ranges:
75	///   - [0, MAXIMUM_BLOCK_WEIGHT]
76	///   - [Balance::min, Balance::max]
77	///
78	/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
79	///   - Setting it to `0` will essentially disable the weight fee.
80	///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
81	pub struct WeightToFee;
82	impl frame_support::weights::WeightToFee for WeightToFee {
83		type Balance = Balance;
84
85		fn weight_to_fee(weight: &Weight) -> Self::Balance {
86			let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
87			let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
88
89			// Take the maximum instead of the sum to charge by the more scarce resource.
90			time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
91		}
92	}
93
94	/// Maps the reference time component of `Weight` to a fee.
95	pub struct RefTimeToFee;
96	impl WeightToFeePolynomial for RefTimeToFee {
97		type Balance = Balance;
98		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
99			// In Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
100			// The standard system parachain configuration is 1/10 of that, as in 1/100 CENT.
101			let p = super::currency::CENTS;
102			let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
103
104			smallvec![WeightToFeeCoefficient {
105				degree: 1,
106				negative: false,
107				coeff_frac: Perbill::from_rational(p % q, q),
108				coeff_integer: p / q,
109			}]
110		}
111	}
112
113	/// Maps the proof size component of `Weight` to a fee.
114	pub struct ProofSizeToFee;
115	impl WeightToFeePolynomial for ProofSizeToFee {
116		type Balance = Balance;
117		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
118			// Map 10kb proof to 1 CENT.
119			let p = super::currency::CENTS;
120			let q = 10_000;
121
122			smallvec![WeightToFeeCoefficient {
123				degree: 1,
124				negative: false,
125				coeff_frac: Perbill::from_rational(p % q, q),
126				coeff_integer: p / q,
127			}]
128		}
129	}
130}
131
132/// Consensus-related.
133pub mod consensus {
134	use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight};
135
136	/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
137	/// relay chain.
138	pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
139	/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
140	/// blocks authored per slot.
141	pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
142	/// Relay chain slot duration, in milliseconds.
143	pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
144
145	/// We allow for 2 seconds of compute with a 6 second average block.
146	pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
147		WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
148		cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
149	);
150
151	/// This determines the average expected block time that we are targeting.
152	/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
153	/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
154	/// up by `pallet_aura` to implement `fn slot_duration()`.
155	///
156	/// Change this to adjust the block time.
157	pub const MILLISECS_PER_BLOCK: u64 = 6000;
158	pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
159}
160
161/// Time-related
162pub mod time {
163	use polkadot_core_primitives::BlockNumber;
164
165	// Time is measured by number of blocks.
166	pub const MINUTES: BlockNumber =
167		60_000 / (super::consensus::MILLISECS_PER_BLOCK as BlockNumber);
168	pub const HOURS: BlockNumber = MINUTES * 60;
169	pub const DAYS: BlockNumber = HOURS * 24;
170}
171
172pub mod snowbridge {
173	use cumulus_primitives_core::ParaId;
174	use frame_support::parameter_types;
175	use xcm::prelude::{Location, NetworkId};
176
177	/// The pallet index of the Ethereum inbound queue pallet in the bridge hub runtime.
178	pub const INBOUND_QUEUE_PALLET_INDEX_V1: u8 = 80;
179	pub const INBOUND_QUEUE_PALLET_INDEX_V2: u8 = 91;
180
181	pub const FRONTEND_PALLET_INDEX: u8 = 36;
182
183	parameter_types! {
184		/// Network and location for the Ethereum chain. On Westend, the Ethereum chain bridged
185		/// to is the Sepolia Ethereum testnet, with chain ID 11155111.
186		/// <https://chainlist.org/chain/11155111>
187		/// <https://ethereum.org/en/developers/docs/apis/json-rpc/#net_version>
188		pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 11155111 };
189		pub EthereumLocation: Location = Location::new(2, EthereumNetwork::get());
190		pub AssetHubParaId: ParaId = ParaId::from(westend_runtime_constants::system_parachain::ASSET_HUB_ID);
191	}
192}
193
194pub mod xcm_version {
195	/// The default XCM version to set in genesis config.
196	pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
197}
198
199pub mod locations {
200	use frame_support::parameter_types;
201	pub use westend_runtime_constants::system_parachain::{AssetHubParaId, PeopleParaId};
202	use xcm::latest::prelude::{Location, Parachain};
203
204	parameter_types! {
205		pub AssetHubLocation: Location = Location::new(1, Parachain(westend_runtime_constants::system_parachain::ASSET_HUB_ID));
206		pub PeopleLocation: Location = Location::new(1, Parachain(westend_runtime_constants::system_parachain::PEOPLE_ID));
207	}
208
209	/// The governance on the AssetHub.
210	pub type GovernanceLocation = AssetHubLocation;
211}