From 7dd70717ba7145aca9347ec03659421f1d3b7c24 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 18 Oct 2023 11:54:20 +0200 Subject: [PATCH] ED consistent between tokens and assets --- runtime/altair/src/lib.rs | 15 +++------------ runtime/centrifuge/src/lib.rs | 17 +++++------------ runtime/common/src/lib.rs | 22 ++++++++++++++++++++++ runtime/development/src/lib.rs | 12 +++--------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 56f7f23c7c..05162d3192 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -58,7 +58,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use orml_traits::{currency::MutationHooks, parameter_type_with_key}; +use orml_traits::currency::MutationHooks; use pallet_anchors::AnchorData; pub use pallet_balances::Call as BalancesCall; use pallet_collective::{EnsureMember, EnsureProportionMoreThan}; @@ -74,11 +74,11 @@ pub use pallet_timestamp::Call as TimestampCall; pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, RuntimeDispatchInfo}; use polkadot_runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate}; -pub use runtime_common::*; use runtime_common::{ account_conversion::AccountConverter, fees::{DealWithFees, WeightToFee}, xcm::AccountIdToMultiLocation, + CurrencyEDs, }; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; @@ -1107,15 +1107,6 @@ impl pallet_restricted_tokens::Config for Runtime { type WeightInfo = weights::pallet_restricted_tokens::WeightInfo; } -parameter_type_with_key! { - pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { - match currency_id { - CurrencyId::Native => ExistentialDeposit::get(), - _ => 0, - } - }; -} - parameter_types! { pub TreasuryAccount: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -1138,7 +1129,7 @@ impl orml_tokens::Config for Runtime { type CurrencyHooks = CurrencyHooks; type CurrencyId = CurrencyId; type DustRemovalWhitelist = frame_support::traits::Nothing; - type ExistentialDeposits = ExistentialDeposits; + type ExistentialDeposits = CurrencyEDs; type MaxLocks = MaxLocks; type MaxReserves = MaxReserves; type ReserveIdentifier = [u8; 8]; diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index d094fc5fcc..9fabb89ea6 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -59,7 +59,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use orml_traits::{currency::MutationHooks, parameter_type_with_key}; +use orml_traits::currency::MutationHooks; use pallet_anchors::AnchorData; pub use pallet_balances::Call as BalancesCall; use pallet_collective::{EnsureMember, EnsureProportionAtLeast, EnsureProportionMoreThan}; @@ -78,7 +78,9 @@ pub use pallet_timestamp::Call as TimestampCall; pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, RuntimeDispatchInfo}; use polkadot_runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate}; -use runtime_common::{account_conversion::AccountConverter, xcm::AccountIdToMultiLocation}; +use runtime_common::{ + account_conversion::AccountConverter, xcm::AccountIdToMultiLocation, CurrencyEDs, +}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; use sp_core::{OpaqueMetadata, H160, H256, U256}; @@ -378,15 +380,6 @@ parameter_types! { pub TreasuryAccount: AccountId = TreasuryPalletId::get().into_account_truncating(); } -parameter_type_with_key! { - pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { - match currency_id { - CurrencyId::Native => ExistentialDeposit::get(), - _ => 0, - } - }; -} - pub struct CurrencyHooks(sp_std::marker::PhantomData); impl MutationHooks for CurrencyHooks { type OnDust = orml_tokens::TransferDust; @@ -405,7 +398,7 @@ impl orml_tokens::Config for Runtime { type CurrencyHooks = CurrencyHooks; type CurrencyId = CurrencyId; type DustRemovalWhitelist = frame_support::traits::Nothing; - type ExistentialDeposits = ExistentialDeposits; + type ExistentialDeposits = CurrencyEDs; type MaxLocks = MaxLocks; type MaxReserves = MaxReserves; type ReserveIdentifier = [u8; 8]; diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index a931aea44b..8512aebfdb 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -26,6 +26,12 @@ pub mod migrations; pub mod oracle; pub mod xcm; +use cfg_primitives::Balance; +use cfg_types::tokens::CurrencyId; +use orml_traits::GetByKey; +use sp_runtime::traits::Get; +use sp_std::marker::PhantomData; + #[macro_export] macro_rules! production_or_benchmark { ($production:expr, $benchmark:expr) => {{ @@ -37,6 +43,22 @@ macro_rules! production_or_benchmark { }}; } +pub struct CurrencyEDs(PhantomData); +impl GetByKey for CurrencyEDs +where + T: pallet_balances::Config + + orml_asset_registry::Config, +{ + fn get(currency_id: &CurrencyId) -> Balance { + match currency_id { + CurrencyId::Native => T::ExistentialDeposit::get(), + currency_id => orml_asset_registry::Pallet::::metadata(currency_id) + .map(|metadata| metadata.existential_deposit) + .unwrap_or_default(), + } + } +} + pub mod xcm_fees { use cfg_primitives::{constants::currency_decimals, types::Balance}; use frame_support::weights::constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}; diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 0e8d618170..7a15989a02 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -68,7 +68,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use orml_traits::{currency::MutationHooks, parameter_type_with_key}; +use orml_traits::{currency::MutationHooks}; use pallet_anchors::AnchorData; pub use pallet_balances::Call as BalancesCall; use pallet_collective::EnsureMember; @@ -89,6 +89,7 @@ use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, RuntimeDispatchInfo use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; pub use runtime_common::*; use runtime_common::{ + CurrencyEDs account_conversion::AccountConverter, fees::{DealWithFees, WeightToFee}, xcm::AccountIdToMultiLocation, @@ -1498,13 +1499,6 @@ impl pallet_restricted_tokens::Config for Runtime { type WeightInfo = weights::pallet_restricted_tokens::WeightInfo; } -parameter_type_with_key! { - pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { - // every currency has a zero existential deposit - 0 - }; -} - parameter_types! { pub TreasuryAccount: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -1527,7 +1521,7 @@ impl orml_tokens::Config for Runtime { type CurrencyHooks = CurrencyHooks; type CurrencyId = CurrencyId; type DustRemovalWhitelist = frame_support::traits::Nothing; - type ExistentialDeposits = ExistentialDeposits; + type ExistentialDeposits = CurrencyEDs; type MaxLocks = MaxLocks; type MaxReserves = MaxReserves; type ReserveIdentifier = [u8; 8];