Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into loans/integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Oct 26, 2023
2 parents 83a5095 + c7e1704 commit 8fc7858
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 72 deletions.
17 changes: 5 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,13 @@ 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,
asset_registry,
fees::{DealWithFees, WeightToFee},
production_or_benchmark,
xcm::AccountIdToMultiLocation,
xcm_transactor, CurrencyED,
};
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
Expand Down Expand Up @@ -1107,15 +1109,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 +1131,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 = CurrencyED<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, CurrencyED,
};
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 = CurrencyED<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 CurrencyED<T>(PhantomData<T>);
impl<T> GetByKey<CurrencyId, Balance> for CurrencyED<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 @@ -92,6 +92,7 @@ use runtime_common::{
account_conversion::AccountConverter,
fees::{DealWithFees, WeightToFee},
xcm::AccountIdToMultiLocation,
CurrencyED,
};
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
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 = CurrencyED<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
Expand Down
9 changes: 7 additions & 2 deletions runtime/integration-tests/src/evm/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ use crate::{
},
};

const ED: Balance = 1_234;

#[tokio::test]
async fn axelar_precompile_execute() {
let mut env = env::test_env_default(Handle::current());
Expand Down Expand Up @@ -90,7 +92,7 @@ async fn axelar_precompile_execute() {
decimals: 18,
name: "Test".into(),
symbol: "TST".into(),
existential_deposit: 1_000_000,
existential_deposit: ED,
location: Some(VersionedMultiLocation::V3(MultiLocation::here())),
additional: CustomMetadata {
transferability: Default::default(),
Expand All @@ -114,6 +116,9 @@ async fn axelar_precompile_execute() {
1_000_000_000_000 * 10u128.saturating_pow(18),
)
.unwrap();

orml_tokens::Pallet::<Runtime>::deposit(currency_id, &derived_receiver_account, ED)
.unwrap();
})
.unwrap();

Expand Down Expand Up @@ -227,7 +232,7 @@ async fn axelar_precompile_execute() {
let derived_receiver_balance =
orml_tokens::Pallet::<Runtime>::free_balance(currency_id, &derived_receiver_account);

assert_eq!(derived_receiver_balance, transfer_amount)
assert_eq!(derived_receiver_balance, transfer_amount + ED)
})
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use sp_runtime::traits::AccountIdConversion;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};

use super::setup::{cfg, ExtBuilder, ALICE, BOB, PARA_ID_MOONBEAM};
use crate::utils::{
AUSD_CURRENCY_ID, AUSD_ED, GLMR_CURRENCY_ID, GLMR_ED, USDT_CURRENCY_ID, USDT_ED,
};

decl_test_relay_chain! {
pub struct RelayChain {
Expand Down Expand Up @@ -114,6 +117,12 @@ pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
.balances(vec![
(AccountId::from(ALICE), CurrencyId::Native, cfg(10_000)),
(AccountId::from(BOB), CurrencyId::Native, cfg(10_000)),
(AccountId::from(ALICE), AUSD_CURRENCY_ID, AUSD_ED),
(AccountId::from(BOB), AUSD_CURRENCY_ID, AUSD_ED),
(AccountId::from(ALICE), USDT_CURRENCY_ID, USDT_ED),
(AccountId::from(BOB), USDT_CURRENCY_ID, USDT_ED),
(AccountId::from(ALICE), GLMR_CURRENCY_ID, GLMR_ED),
(AccountId::from(BOB), GLMR_CURRENCY_ID, GLMR_ED),
])
.parachain_id(parachain_id)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ fn add_currency_should_fail() {
"TEST".into(),
12,
false,
1_000_000,
None,
CrossChainTransferability::LiquidityPools,
),
Expand Down Expand Up @@ -500,6 +501,7 @@ fn allow_pool_should_fail() {
"TEST".into(),
12,
true,
1_000_000,
None,
Default::default(),
),
Expand Down Expand Up @@ -629,6 +631,7 @@ fn allow_pool_should_fail() {
"AUSD".into(),
12,
true,
1_000_000,
None,
Default::default()
),
Expand Down
Loading

0 comments on commit 8fc7858

Please sign in to comment.