diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cfde97db..d672fa934b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Upgrade parachains runtime API from v7 to v8 in Kusama ([polkadot-fellows/runtimes#148](https://github.com/polkadot-fellows/runtimes/pull/148)). Context: https://paritytech.github.io/polkadot-sdk/book/protocol-validator-disabling.html +- Fixed the lowering of Asset Hub existential deposits. ## [1.1.0] 10.01.2024 diff --git a/Cargo.lock b/Cargo.lock index 794b45dc8a..f557b0006a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,7 +606,6 @@ dependencies = [ "polkadot-runtime-constants", "primitive-types", "scale-info", - "smallvec", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -706,7 +705,6 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-constants", "scale-info", - "smallvec", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -1466,7 +1464,6 @@ dependencies = [ "polkadot-runtime-common", "scale-info", "serde", - "smallvec", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -1550,7 +1547,6 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", - "smallvec", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -2092,7 +2088,6 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-constants", "scale-info", - "smallvec", "sp-api", "sp-arithmetic", "sp-block-builder", @@ -3389,6 +3384,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "kusama-runtime-constants", "log", "pallet-asset-tx-payment", "pallet-aura", @@ -3436,6 +3432,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-constants", ] [[package]] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index e2cdc68b85..b3f819a0ee 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -13,7 +13,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = hex-literal = { version = "0.4.1" } log = { version = "0.4.20", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } -smallvec = "1.11.0" # Local bp-asset-hub-kusama = { path = "./primitives", default-features = false} diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/constants.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/constants.rs deleted file mode 100644 index a5c24f58de..0000000000 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/constants.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod currency { - use kusama_runtime_constants as constants; - use polkadot_core_primitives::Balance; - - /// The existential deposit. Set to 1/100 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 100; - - pub const UNITS: Balance = constants::currency::UNITS; - pub const CENTS: Balance = constants::currency::CENTS; - pub const GRAND: Balance = constants::currency::GRAND; - pub const MILLICENTS: Balance = constants::currency::MILLICENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - // map to 1/100 of what the kusama relay chain charges (v9020) - constants::currency::deposit(items, bytes) / 100 - } -} - -/// Fee-related. -pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, Weight, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - - /// The block saturation level. Fees will be updates based on this value. - pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); - - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the - /// node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Asset Hub, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } -} diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 22ae002c53..8934ac8efa 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -208,7 +208,9 @@ impl pallet_authorship::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + // This comes from system_parachains_constants::kusama::currency and is the ED for all system + // parachains. For Asset Hub in particular, we set it to 1/10th of the amount. + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT / 10; } impl pallet_balances::Config for Runtime { @@ -249,13 +251,12 @@ impl pallet_transaction_payment::Config for Runtime { parameter_types! { pub const AssetDeposit: Balance = UNITS / 10; // 1 / 10 UNITS deposit to create asset - pub const AssetAccountDeposit: Balance = deposit(1, 16); - pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const AssetAccountDeposit: Balance = system_para_deposit(1, 16); pub const AssetsStringLimit: u32 = 50; /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 - pub const MetadataDepositBase: Balance = deposit(1, 68); - pub const MetadataDepositPerByte: Balance = deposit(0, 1); + pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); + pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); } /// We allow root to execute privileged asset operations. @@ -277,7 +278,7 @@ impl pallet_assets::Config for Runtime { type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; type MetadataDepositPerByte = MetadataDepositPerByte; - type ApprovalDeposit = ApprovalDeposit; + type ApprovalDeposit = ExistentialDeposit; type StringLimit = AssetsStringLimit; type Freezer = (); type Extra = (); @@ -317,7 +318,7 @@ impl pallet_assets::Config for Runtime { type AssetAccountDeposit = ConstU128<0>; type MetadataDepositBase = ConstU128<0>; type MetadataDepositPerByte = ConstU128<0>; - type ApprovalDeposit = ApprovalDeposit; + type ApprovalDeposit = ExistentialDeposit; type StringLimit = ConstU32<50>; type Freezer = (); type Extra = (); @@ -363,7 +364,6 @@ parameter_types! { // we just reuse the same deposits pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get(); pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get(); - pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get(); pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get(); pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get(); pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get(); @@ -389,7 +389,7 @@ impl pallet_assets::Config for Runtime { type AssetDeposit = ForeignAssetsAssetDeposit; type MetadataDepositBase = ForeignAssetsMetadataDepositBase; type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte; - type ApprovalDeposit = ForeignAssetsApprovalDeposit; + type ApprovalDeposit = ExistentialDeposit; type StringLimit = ForeignAssetsAssetsStringLimit; type Freezer = (); type Extra = (); @@ -403,9 +403,9 @@ impl pallet_assets::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + pub const DepositBase: Balance = system_para_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); + pub const DepositFactor: Balance = system_para_deposit(0, 32); pub const MaxSignatories: u32 = 100; } @@ -428,13 +428,13 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . - pub const ProxyDepositBase: Balance = deposit(1, 40); + pub const ProxyDepositBase: Balance = system_para_deposit(1, 40); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositFactor: Balance = system_para_deposit(0, 33); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 - pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositBase: Balance = system_para_deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = system_para_deposit(0, 66); pub const MaxPending: u16 = 32; } @@ -744,9 +744,9 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime { parameter_types! { pub const UniquesCollectionDeposit: Balance = UNITS / 10; // 1 / 10 UNIT deposit to create a collection pub const UniquesItemDeposit: Balance = UNITS / 1_000; // 1 / 1000 UNIT deposit to mint an item - pub const UniquesMetadataDepositBase: Balance = deposit(1, 129); - pub const UniquesAttributeDepositBase: Balance = deposit(1, 0); - pub const UniquesDepositPerByte: Balance = deposit(0, 1); + pub const UniquesMetadataDepositBase: Balance = system_para_deposit(1, 129); + pub const UniquesAttributeDepositBase: Balance = system_para_deposit(1, 0); + pub const UniquesDepositPerByte: Balance = system_para_deposit(0, 1); } impl pallet_uniques::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index a70901b5b4..95d2b7e8e5 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -69,6 +69,23 @@ fn collator_session_keys() -> CollatorSessionKeys { ) } +#[test] +fn test_ed_is_one_hundredth_of_relay() { + ExtBuilder::::default() + .with_collators(vec![AccountId::from(ALICE)]) + .with_session_keys(vec![( + AccountId::from(ALICE), + AccountId::from(ALICE), + SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, + )]) + .build() + .execute_with(|| { + let relay_ed = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let asset_hub_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 100, asset_hub_ed); + }); +} + #[test] fn test_asset_xcm_trader() { ExtBuilder::::default() @@ -257,7 +274,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); // We are going to buy small amount - let bought = Weight::from_parts(500_000_000u64, 0); + let bought = Weight::from_parts(50_000_000u64, 0); let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 2af6758a65..b133129e25 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -13,7 +13,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.20", default-features = false } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } -smallvec = "1.11.1" # Local bp-asset-hub-kusama = { path = "../asset-hub-kusama/primitives", default-features = false} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/constants.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/constants.rs deleted file mode 100644 index 03dd41319e..0000000000 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/constants.rs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod currency { - use polkadot_core_primitives::Balance; - use polkadot_runtime_constants as constants; - - /// The existential deposit. Set to 1/100 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 100; - - pub const UNITS: Balance = constants::currency::UNITS; - pub const DOLLARS: Balance = constants::currency::DOLLARS; - pub const CENTS: Balance = constants::currency::CENTS; - pub const MILLICENTS: Balance = constants::currency::MILLICENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - // 1/100 of Polkadot - constants::currency::deposit(items, bytes) / 100 - } -} - -/// Fee-related. -pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - use sp_weights::Weight; - - /// The block saturation level. Fees will be updates based on this value. - pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); - - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the - /// node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Asset Hub, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } -} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 4638d8e6b0..a7455f46d1 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -220,7 +220,9 @@ impl pallet_authorship::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + // This comes from system_parachains_constants::polkadot::currency and is the ED for all system + // parachains. For Asset Hub in particular, we set it to 1/10th of the amount. + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT / 10; } impl pallet_balances::Config for Runtime { @@ -259,13 +261,12 @@ impl pallet_transaction_payment::Config for Runtime { parameter_types! { pub const AssetDeposit: Balance = 10 * UNITS; // 10 UNITS deposit to create fungible asset class - pub const AssetAccountDeposit: Balance = deposit(1, 16); - pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const AssetAccountDeposit: Balance = system_para_deposit(1, 16); pub const AssetsStringLimit: u32 = 50; /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 - pub const MetadataDepositBase: Balance = deposit(1, 68); - pub const MetadataDepositPerByte: Balance = deposit(0, 1); + pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); + pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); } /// We allow root to execute privileged asset operations. @@ -287,7 +288,7 @@ impl pallet_assets::Config for Runtime { type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; type MetadataDepositPerByte = MetadataDepositPerByte; - type ApprovalDeposit = ApprovalDeposit; + type ApprovalDeposit = ExistentialDeposit; type StringLimit = AssetsStringLimit; type Freezer = (); type Extra = (); @@ -303,7 +304,6 @@ parameter_types! { // we just reuse the same deposits pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get(); pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get(); - pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get(); pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get(); pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get(); pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get(); @@ -329,7 +329,7 @@ impl pallet_assets::Config for Runtime { type AssetDeposit = ForeignAssetsAssetDeposit; type MetadataDepositBase = ForeignAssetsMetadataDepositBase; type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte; - type ApprovalDeposit = ForeignAssetsApprovalDeposit; + type ApprovalDeposit = ExistentialDeposit; type StringLimit = ForeignAssetsAssetsStringLimit; type Freezer = (); type Extra = (); @@ -343,9 +343,9 @@ impl pallet_assets::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + pub const DepositBase: Balance = system_para_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); + pub const DepositFactor: Balance = system_para_deposit(0, 32); pub const MaxSignatories: u32 = 100; } @@ -368,13 +368,13 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . - pub const ProxyDepositBase: Balance = deposit(1, 40); + pub const ProxyDepositBase: Balance = system_para_deposit(1, 40); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositFactor: Balance = system_para_deposit(0, 33); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 - pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositBase: Balance = system_para_deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = system_para_deposit(0, 66); pub const MaxPending: u16 = 32; } @@ -686,9 +686,9 @@ impl pallet_asset_tx_payment::Config for Runtime { parameter_types! { pub const UniquesCollectionDeposit: Balance = 10 * UNITS; // 10 UNIT deposit to create uniques class pub const UniquesItemDeposit: Balance = UNITS / 100; // 1 / 100 UNIT deposit to create uniques instance - pub const UniquesMetadataDepositBase: Balance = deposit(1, 129); - pub const UniquesAttributeDepositBase: Balance = deposit(1, 0); - pub const UniquesDepositPerByte: Balance = deposit(0, 1); + pub const UniquesMetadataDepositBase: Balance = system_para_deposit(1, 129); + pub const UniquesAttributeDepositBase: Balance = system_para_deposit(1, 0); + pub const UniquesDepositPerByte: Balance = system_para_deposit(0, 1); } impl pallet_uniques::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index e5c53f39b2..46354fec17 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -71,6 +71,23 @@ fn collator_session_keys() -> CollatorSessionKeys { ) } +#[test] +fn test_ed_is_one_hundredth_of_relay() { + ExtBuilder::::default() + .with_collators(vec![AccountId::from(ALICE)]) + .with_session_keys(vec![( + AccountId::from(ALICE), + AccountId::from(ALICE), + SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, + )]) + .build() + .execute_with(|| { + let relay_ed = polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let asset_hub_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 100, asset_hub_ed); + }); +} + #[test] fn test_asset_xcm_trader() { ExtBuilder::::default() @@ -268,7 +285,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { // Because of the ED being higher in kusama's asset hub // and not to complicate things, we use a little // bit more of weight - let bought = Weight::from_parts(50_000_000_000u64, 0); + let bought = Weight::from_parts(5_000_000_000u64, 0); let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 38b43df99c..12bbb33722 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -17,7 +17,6 @@ hex-literal = { version = "0.4.1" } log = { version = "0.4.20", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } serde = { version = "1.0.188", optional = true, features = ["derive"] } -smallvec = "1.11.0" # Local bp-asset-hub-kusama = { path = "../../asset-hubs/asset-hub-kusama/primitives", default-features = false} diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/constants.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/constants.rs deleted file mode 100644 index 257d0da755..0000000000 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/constants.rs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod currency { - use kusama_runtime_constants as constants; - use polkadot_core_primitives::Balance; - - /// The existential deposit. Set to 1/10 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; - - pub const UNITS: Balance = constants::currency::UNITS; - pub const CENTS: Balance = constants::currency::CENTS; - pub const MILLICENTS: Balance = constants::currency::MILLICENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - // map to 1/100 of what the kusama relay chain charges (v9020) - constants::currency::deposit(items, bytes) / 100 - } -} - -/// Fee-related. -pub mod fee { - use frame_support::{ - pallet_prelude::Weight, - weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the - /// node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Bridge Hub, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } -} diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index ce74c1bd35..16f9badaa6 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -245,7 +245,7 @@ impl pallet_authorship::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -413,9 +413,9 @@ impl pallet_collator_selection::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + pub const DepositBase: Balance = system_para_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); + pub const DepositFactor: Balance = system_para_deposit(0, 32); } impl pallet_multisig::Config for Runtime { diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 54a4192851..c51154b5a7 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -123,6 +123,13 @@ bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!( 1002 ); +#[test] +fn test_ed_is_one_tenth_of_relay() { + let relay_ed = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let bridge_hub_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 10, bridge_hub_ed); +} + #[test] fn initialize_bridge_by_governance_works() { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index ab0af45c83..575d554f57 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -17,7 +17,6 @@ hex-literal = { version = "0.4.1" } log = { version = "0.4.20", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } serde = { version = "1.0.188", optional = true, features = ["derive"] } -smallvec = "1.11.0" # Local bp-asset-hub-kusama = { path = "../../asset-hubs/asset-hub-kusama/primitives", default-features = false} diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/constants.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/constants.rs deleted file mode 100644 index 388d23e644..0000000000 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/constants.rs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2023 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod currency { - use polkadot_core_primitives::Balance; - use polkadot_runtime_constants as constants; - - /// The existential deposit. Set to 1/10 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; - - pub const UNITS: Balance = constants::currency::UNITS; - pub const CENTS: Balance = constants::currency::CENTS; - pub const MILLICENTS: Balance = constants::currency::MILLICENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - // 1/100 of Polkadot - constants::currency::deposit(items, bytes) / 100 - } -} - -/// Fee-related. -pub mod fee { - use frame_support::{ - pallet_prelude::Weight, - weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the - /// node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Bridge Hub, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } -} diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 08d5d2706e..5bc7a10472 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -245,7 +245,7 @@ impl pallet_authorship::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -413,9 +413,9 @@ impl pallet_collator_selection::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + pub const DepositBase: Balance = system_para_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); + pub const DepositFactor: Balance = system_para_deposit(0, 32); } impl pallet_multisig::Config for Runtime { diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index b5682ec790..7a94db6041 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -123,6 +123,13 @@ bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!( 1002 ); +#[test] +fn test_ed_is_one_tenth_of_relay() { + let relay_ed = polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let bridge_hub_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 10, bridge_hub_ed); +} + #[test] fn initialize_bridge_by_governance_works() { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index bd53424767..7507e965bd 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -13,7 +13,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = hex-literal = { version = "0.4.1" } log = { version = "0.4.20", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } -smallvec = "1.11.0" # Substrate frame-benchmarking = { default-features = false, optional = true, version = "25.0.0" } diff --git a/system-parachains/collectives/collectives-polkadot/src/constants.rs b/system-parachains/collectives/collectives-polkadot/src/constants.rs deleted file mode 100644 index 8d0325844c..0000000000 --- a/system-parachains/collectives/collectives-polkadot/src/constants.rs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod account { - use frame_support::PalletId; - - /// Polkadot treasury pallet id, used to convert into AccountId - pub const POLKADOT_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); - /// Alliance pallet ID. - /// It is used as a temporarily place to deposit a slashed imbalance - /// before the teleport to the Treasury. - pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia"); - /// Referenda pallet ID. - /// It is used as a temporarily place to deposit a slashed imbalance - /// before the teleport to the Treasury. - pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer"); -} - -pub mod currency { - use polkadot_core_primitives::Balance; - use polkadot_runtime_constants as constants; - - /// The existential deposit. Set to 1/10 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; - - pub const UNITS: Balance = constants::currency::UNITS; - pub const DOLLARS: Balance = constants::currency::DOLLARS; - pub const CENTS: Balance = constants::currency::CENTS; - pub const MILLICENTS: Balance = constants::currency::MILLICENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - // 1/100 of Polkadot. - constants::currency::deposit(items, bytes) / 100 - } -} - -/// Fee-related. -pub mod fee { - use frame_support::{ - pallet_prelude::Weight, - weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - - /// The block saturation level. Fees will be updates based on this value. - pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); - - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the - /// node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in a parachain, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } -} diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index b75545c4fd..40e9f22a46 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -197,7 +197,7 @@ impl pallet_authorship::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -236,9 +236,9 @@ impl pallet_transaction_payment::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + pub const DepositBase: Balance = system_para_deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); + pub const DepositFactor: Balance = system_para_deposit(0, 32); } impl pallet_multisig::Config for Runtime { @@ -260,12 +260,12 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . - pub const ProxyDepositBase: Balance = deposit(1, 40); + pub const ProxyDepositBase: Balance = system_para_deposit(1, 40); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositFactor: Balance = system_para_deposit(0, 33); // One storage item; key size 32, value size 16 - pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositBase: Balance = system_para_deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = system_para_deposit(0, 66); } /// The type used to represent the kinds of proxying allowed. @@ -568,8 +568,8 @@ impl pallet_scheduler::Config for Runtime { } parameter_types! { - pub const PreimageBaseDeposit: Balance = deposit(2, 64); - pub const PreimageByteDeposit: Balance = deposit(0, 1); + pub const PreimageBaseDeposit: Balance = system_para_deposit(2, 64); + pub const PreimageByteDeposit: Balance = system_para_deposit(0, 1); pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); } @@ -978,3 +978,10 @@ fn fellowship_treasury_pallet_index() { // Remote accounts with funds depend on this pallet staying in the same index. assert_eq!(::index() as u8, 65u8); } + +#[test] +fn test_ed_is_one_tenth_of_relay() { + let relay_ed = polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let collectives_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 10, collectives_ed); +} diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index 3ae72f6514..04ecbf3e20 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -29,18 +29,21 @@ pub mod consensus { pub mod currency { use polkadot_core_primitives::Balance; - /// The existential deposit. 1/10th of the relay deposit. - pub const EXISTENTIAL_DEPOSIT: Balance = + /// The default existential deposit for system chains. 1/10th of the Relay Chain's existential + /// deposit. Individual system parachains may modify this in special cases. + pub const SYSTEM_PARA_EXISTENTIAL_DEPOSIT: Balance = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; + /// One "KSM" that a UI would show a user. pub const UNITS: Balance = 1_000_000_000_000; pub const QUID: Balance = UNITS / 30; pub const CENTS: Balance = QUID / 100; pub const GRAND: Balance = QUID * 1_000; pub const MILLICENTS: Balance = CENTS / 1_000; - /// Deposit for stored data. 1/100th of the relay deposit. - pub const fn deposit(items: u32, bytes: u32) -> Balance { + /// Deposit rate for stored data. 1/100th of the Relay Chain's deposit rate. `items` is the + /// number of keys in storage and `bytes` is the size of the value. + pub const fn system_para_deposit(items: u32, bytes: u32) -> Balance { kusama_runtime_constants::currency::deposit(items, bytes) / 100 } } diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index dfca992715..932cf2c341 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -51,17 +51,21 @@ pub mod consensus { pub mod currency { use polkadot_core_primitives::Balance; - /// The existential deposit. - pub const EXISTENTIAL_DEPOSIT: Balance = + /// The default existential deposit for system chains. 1/10th of the Relay Chain's existential + /// deposit. Individual system parachains may modify this in special cases. + pub const SYSTEM_PARA_EXISTENTIAL_DEPOSIT: Balance = polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; + /// One "DOT" that a UI would show a user. pub const UNITS: Balance = 10_000_000_000; pub const DOLLARS: Balance = UNITS; // 10_000_000_000 pub const GRAND: Balance = DOLLARS * 1_000; // 10_000_000_000_000 pub const CENTS: Balance = DOLLARS / 100; // 100_000_000 pub const MILLICENTS: Balance = CENTS / 1_000; // 100_000 - pub const fn deposit(items: u32, bytes: u32) -> Balance { + /// Deposit rate for stored data. 1/100th of the Relay Chain's deposit rate. `items` is the + /// number of keys in storage and `bytes` is the size of the value. + pub const fn system_para_deposit(items: u32, bytes: u32) -> Balance { polkadot_runtime_constants::currency::deposit(items, bytes) / 100 } } diff --git a/system-parachains/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index 93e10f2581..279f0f53c9 100644 --- a/system-parachains/encointer/Cargo.toml +++ b/system-parachains/encointer/Cargo.toml @@ -88,6 +88,7 @@ cumulus-primitives-timestamp = { default-features = false, version = "0.4.0" } cumulus-primitives-utility = { default-features = false, version = "0.4.0" } parachain-info = { package = "staging-parachain-info", default-features = false, version = "0.4.0" } parachains-common = { default-features = false, version = "4.0.0" } +system-parachains-constants = { path = "../constants", default-features = false } # Used for runtime benchmarking @@ -95,6 +96,9 @@ parachains-common = { default-features = false, version = "4.0.0" } [build-dependencies] substrate-wasm-builder = { optional = true, version = "14.0.0" } +[dev-dependencies] +kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false} + [features] default = ["std"] runtime-benchmarks = [ diff --git a/system-parachains/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index 0861b4adc4..36a7f58ede 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -71,9 +71,9 @@ pub use pallet_encointer_faucet::Call as EncointerFaucetCall; pub use pallet_encointer_reputation_commitments::Call as EncointerReputationCommitmentsCall; pub use pallet_encointer_scheduler::Call as EncointerSchedulerCall; use pallet_xcm::{EnsureXcm, IsMajorityOfBody}; -use parachains_common::{ - kusama::{consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::*, fee::WeightToFee}, - AuraId, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, +pub use parachains_common::{ + impls::DealWithFees, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, + Hash, Header, Nonce, Signature, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use sp_api::impl_runtime_apis; @@ -90,6 +90,10 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use system_parachains_constants::{ + kusama::{consensus::*, currency::*, fee::WeightToFee}, + AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, +}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::{ latest::{BodyId, InteriorMultiLocation, Junction::PalletInstance}, @@ -148,13 +152,13 @@ pub fn native_version() -> NativeVersion { parameter_types! { // One storage item; key size 32, value size 8; . - pub const ProxyDepositBase: Balance = deposit(1, 40); + pub const ProxyDepositBase: Balance = system_para_deposit(1, 40); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositFactor: Balance = system_para_deposit(0, 33); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 - pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositBase: Balance = system_para_deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = system_para_deposit(0, 66); pub const MaxPending: u16 = 32; } @@ -297,7 +301,7 @@ impl pallet_timestamp::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const ExistentialDeposit: Balance = SYSTEM_PARA_EXISTENTIAL_DEPOSIT; pub const MaxLocks: u32 = 50; pub const MaxReserves: u32 = 50; } @@ -663,11 +667,6 @@ construct_runtime! { } } -/// `parachains_common` is an upstream crate, where they are started to define common types. -/// -/// The re-export is added by encointer. -pub use parachains_common::{AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature}; - /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block type as expected by this runtime. @@ -1018,3 +1017,10 @@ mod multiplier_tests { assert_eq!(ENCOINTER_TREASURY_PALLET_ID, ::index() as u8); } } + +#[test] +fn test_ed_is_one_tenth_of_relay() { + let relay_ed = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT; + let encointer_ed = ExistentialDeposit::get(); + assert_eq!(relay_ed / 10, encointer_ed); +}