Skip to content

Commit

Permalink
ED consistent between tokens and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Oct 18, 2023
1 parent 06f3bc8 commit 7dd7071
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
15 changes: 3 additions & 12 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -1107,15 +1107,6 @@ impl pallet_restricted_tokens::Config for Runtime {
type WeightInfo = weights::pallet_restricted_tokens::WeightInfo<Self>;
}

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();
}
Expand All @@ -1138,7 +1129,7 @@ impl orml_tokens::Config for Runtime {
type CurrencyHooks = CurrencyHooks<Runtime>;
type CurrencyId = CurrencyId;
type DustRemovalWhitelist = frame_support::traits::Nothing;
type ExistentialDeposits = ExistentialDeposits;
type ExistentialDeposits = CurrencyEDs<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
Expand Down
17 changes: 5 additions & 12 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down Expand Up @@ -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<R>(sp_std::marker::PhantomData<R>);
impl<C: orml_tokens::Config> MutationHooks<AccountId, CurrencyId, Balance> for CurrencyHooks<C> {
type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccount>;
Expand All @@ -405,7 +398,7 @@ impl orml_tokens::Config for Runtime {
type CurrencyHooks = CurrencyHooks<Runtime>;
type CurrencyId = CurrencyId;
type DustRemovalWhitelist = frame_support::traits::Nothing;
type ExistentialDeposits = ExistentialDeposits;
type ExistentialDeposits = CurrencyEDs<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
Expand Down
22 changes: 22 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {{
Expand All @@ -37,6 +43,22 @@ macro_rules! production_or_benchmark {
}};
}

pub struct CurrencyEDs<T>(PhantomData<T>);
impl<T> GetByKey<CurrencyId, Balance> for CurrencyEDs<T>
where
T: pallet_balances::Config<Balance = Balance>
+ orml_asset_registry::Config<AssetId = CurrencyId, Balance = Balance>,
{
fn get(currency_id: &CurrencyId) -> Balance {
match currency_id {
CurrencyId::Native => T::ExistentialDeposit::get(),
currency_id => orml_asset_registry::Pallet::<T>::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};
Expand Down
12 changes: 3 additions & 9 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -1498,13 +1499,6 @@ impl pallet_restricted_tokens::Config for Runtime {
type WeightInfo = weights::pallet_restricted_tokens::WeightInfo<Self>;
}

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();
}
Expand All @@ -1527,7 +1521,7 @@ impl orml_tokens::Config for Runtime {
type CurrencyHooks = CurrencyHooks<Runtime>;
type CurrencyId = CurrencyId;
type DustRemovalWhitelist = frame_support::traits::Nothing;
type ExistentialDeposits = ExistentialDeposits;
type ExistentialDeposits = CurrencyEDs<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
Expand Down

0 comments on commit 7dd7071

Please sign in to comment.