diff --git a/Cargo.lock b/Cargo.lock index d846f63b42bd..1b150a7fec99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13271,7 +13271,6 @@ dependencies = [ "sp-externalities 0.25.0", "sp-io", "sp-tracing 16.0.0", - "tempfile", "thiserror", "tracing-gum", ] diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index d70fdfeb7095..725a8d68d7e7 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -106,7 +106,7 @@ where Assets: fungibles::Inspect, { fn contains(id: &>::AssetId) -> bool { - !Assets::total_issuance(id.clone()).is_zero() + !Assets::total_issuance(id).is_zero() } } @@ -118,7 +118,7 @@ where Assets: fungibles::Inspect, { fn contains(id: &>::AssetId) -> bool { - Assets::asset_exists(id.clone()) + Assets::asset_exists(id) } } diff --git a/cumulus/parachains/common/src/xcm_config.rs b/cumulus/parachains/common/src/xcm_config.rs index a9756af7aed2..ba56e6b86b49 100644 --- a/cumulus/parachains/common/src/xcm_config.rs +++ b/cumulus/parachains/common/src/xcm_config.rs @@ -47,7 +47,7 @@ where >, { fn charge_weight_in_fungibles( - asset_id: as Inspect< + asset_id: & as Inspect< AccountIdOf, >>::AssetId, weight: Weight, @@ -58,7 +58,7 @@ where let amount = WeightToFee::weight_to_fee(&weight); // If the amount gotten is not at least the ED, then make it be the ED of the asset // This is to avoid burning assets and decreasing the supply - let asset_amount = BalanceConverter::to_asset_balance(amount, asset_id) + let asset_amount = BalanceConverter::to_asset_balance(amount, asset_id.clone()) .map_err(|_| XcmError::TooExpensive)?; Ok(asset_amount) } diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 8f2789eb2f3a..4efe992684c4 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -684,7 +684,7 @@ macro_rules! impl_assets_helpers_for_system_parachain { ] ); - assert!(]>::Assets::asset_exists(id.clone().into())); + assert!(]>::Assets::asset_exists(&id)); }); } } @@ -717,7 +717,7 @@ macro_rules! impl_assets_helpers_for_parachain { min_balance, ) ); - assert!(]>::Assets::asset_exists(id.clone())); + assert!(]>::Assets::asset_exists(&id)); type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; $crate::impls::assert_expected_events!( Self, @@ -819,7 +819,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { min_balance, ) ); - assert!(]>::ForeignAssets::asset_exists(id.clone())); + assert!(]>::ForeignAssets::asset_exists(&id)); type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; $crate::impls::assert_expected_events!( Self, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs index edaaa998a9ca..773df838cb75 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs @@ -224,17 +224,17 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_wnds_before = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sender, ) }); let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &receiver) + >::balance(&native_asset_location.clone(), &receiver) }); let receiver_wnds_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &receiver) + >::balance(&wnd_at_rococo_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -248,17 +248,17 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_wnds_after = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sender, ) }); let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &receiver) + >::balance(&native_asset_location, &receiver) }); let receiver_wnds_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains, &receiver) + >::balance(&wnd_at_rococo_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -377,17 +377,17 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Query initial balances let sender_native_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &sender) + >::balance(&native_asset_location.clone(), &sender) }); let sender_wnds_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &sender) + >::balance(&wnd_at_rococo_parachains.clone(), &sender) }); let receiver_native_before = test.receiver.balance; let receiver_wnds_before = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &receiver, ) }); @@ -401,17 +401,17 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Query final balances let sender_native_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &sender) + >::balance(&native_asset_location, &sender) }); let sender_wnds_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &sender) + >::balance(&wnd_at_rococo_parachains.clone(), &sender) }); let receiver_native_after = test.receiver.balance; let receiver_wnds_after = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.try_into().unwrap(), + &wnd_at_rococo_parachains.try_into().unwrap(), &receiver, ) }); @@ -536,18 +536,18 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query initial balances let sender_rocs_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_location.clone(), &sender) + >::balance(&roc_location.clone(), &sender) }); let sender_wnds_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &sender) + >::balance(&wnd_at_rococo_parachains.clone(), &sender) }); let rocs_in_sender_reserve_on_ahr_before = ::account_data_of(sov_of_sender_on_ah.clone()).free; let wnds_in_sender_reserve_on_ahr_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sov_of_sender_on_ah, ) }); @@ -556,17 +556,17 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { let wnds_in_receiver_reserve_on_ahr_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sov_of_receiver_on_ah, ) }); let receiver_rocs_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_location.clone(), &receiver) + >::balance(&roc_location.clone(), &receiver) }); let receiver_wnds_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &receiver) + >::balance(&wnd_at_rococo_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -579,16 +579,16 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query final balances let sender_rocs_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_location.clone(), &sender) + >::balance(&roc_location.clone(), &sender) }); let sender_wnds_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone(), &sender) + >::balance(&wnd_at_rococo_parachains.clone(), &sender) }); let wnds_in_sender_reserve_on_ahr_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sov_of_sender_on_ah, ) }); @@ -597,7 +597,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { let wnds_in_receiver_reserve_on_ahr_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_rococo_parachains.clone().try_into().unwrap(), + &wnd_at_rococo_parachains.clone().try_into().unwrap(), &sov_of_receiver_on_ah, ) }); @@ -605,11 +605,11 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { ::account_data_of(sov_of_receiver_on_ah).free; let receiver_rocs_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_location, &receiver) + >::balance(&roc_location, &receiver) }); let receiver_wnds_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains, &receiver) + >::balance(&wnd_at_rococo_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -682,7 +682,7 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() { }); let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location, &receiver) }); fn relay_assertions(t: RelayToParaThroughAHTest) { @@ -795,7 +795,7 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() { }); let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 8b9fedcd4947..7f8d28087cbf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -590,7 +590,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -603,7 +603,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -661,7 +661,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -674,7 +674,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(&relay_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -723,7 +723,10 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance( + &system_para_native_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -736,7 +739,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(&system_para_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -794,7 +797,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(&system_para_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -807,7 +810,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(&system_para_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -884,16 +887,19 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let sender_assets_before = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &sender) + >::balance(&RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance( + &system_para_native_asset_location.clone(), + &receiver, + ) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + &system_para_foreign_asset_location.clone(), &receiver, ) }); @@ -908,15 +914,18 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let sender_assets_after = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &sender) + >::balance(&RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance( + &system_para_native_asset_location.clone(), + &receiver, + ) }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &receiver) + >::balance(&system_para_foreign_asset_location, &receiver) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); @@ -1017,16 +1026,16 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(&system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(&system_para_foreign_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &receiver) + >::balance(&RESERVABLE_ASSET_ID, &receiver) }); // Set assertions and dispatchables @@ -1038,16 +1047,16 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query final balances let sender_system_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(&system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &sender) + >::balance(&system_para_foreign_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; let receiver_assets_after = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &receiver) + >::balance(&RESERVABLE_ASSET_ID, &receiver) }); // Sender's system asset balance is reduced assert!(sender_system_assets_after < sender_system_assets_before); @@ -1106,11 +1115,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -1123,11 +1132,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index 364fbd0d439f..78dac6e991d8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -110,7 +110,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); type ForeignAssets = ::ForeignAssets; - assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); + assert!(ForeignAssets::asset_exists(&foreign_asset_at_asset_hub)); }); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index ec48e400ff54..8f086972ad8a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -38,7 +38,7 @@ fn swap_locally_on_chain_using_local_assets() { AssetHubRococoSender::get().into(), 1000, )); - assert!(::Assets::asset_exists(ASSET_ID)); + assert!(::Assets::asset_exists(&ASSET_ID)); assert_ok!(::Assets::mint( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), @@ -243,7 +243,7 @@ fn cannot_create_pool_from_pool_assets() { pool_owner_account_id.clone().into(), 1000, )); - assert!(::PoolAssets::asset_exists(ASSET_ID)); + assert!(::PoolAssets::asset_exists(&ASSET_ID)); assert_ok!(::PoolAssets::mint( ::RuntimeOrigin::signed(pool_owner_account_id), @@ -290,7 +290,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { AssetHubRococoSender::get().into(), ASSET_MIN_BALANCE, )); - assert!(::Assets::asset_exists(ASSET_ID)); + assert!(::Assets::asset_exists(&ASSET_ID)); assert_ok!(::Assets::mint( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index f74378d7631a..4f0728dfca31 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -491,7 +491,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -500,12 +500,12 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_assets_before = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) + >::balance(&asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), &AssetHubRococoReceiver::get(), ) }); @@ -518,7 +518,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -527,12 +527,12 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_assets_after = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) + >::balance(&asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), &AssetHubRococoReceiver::get(), ) }); @@ -598,7 +598,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalAReceiver::get(), ) }); @@ -606,13 +606,13 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_before = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(), &AssetHubRococoSender::get(), ) }); let penpal_receiver_assets_before = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) + >::balance(&asset_id_on_penpal, &PenpalAReceiver::get()) }); ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_sender_assertions); @@ -624,7 +624,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_receiver_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + &system_para_native_asset_location, &PenpalAReceiver::get(), ) }); @@ -632,13 +632,13 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_after = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_rococo.try_into().unwrap(), + &foreign_asset_at_asset_hub_rococo.try_into().unwrap(), &AssetHubRococoSender::get(), ) }); let penpal_receiver_assets_after = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) + >::balance(&asset_id_on_penpal, &PenpalAReceiver::get()) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs index 01bf40ae8fdf..339f49db78c4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs @@ -39,7 +39,7 @@ fn spend_roc_on_asset_hub() { let init_alice_balance = AssetHubRococo::execute_with(|| { <::Balances as Inspect<_>>::balance( - &AssetHubRococo::account_id_of(ALICE), + &&AssetHubRococo::account_id_of(ALICE), ) }); @@ -197,9 +197,13 @@ fn create_and_claim_treasury_spend_in_usdt() { true, SPEND_AMOUNT / 2 )); - assert_ok!(>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); + assert_ok!(>::mint_into( + &ASSET_ID, + &treasury_account, + SPEND_AMOUNT * 4 + )); // beneficiary has zero balance. - assert_eq!(>::balance(ASSET_ID, &alice,), 0u128,); + assert_eq!(>::balance(&ASSET_ID, &alice,), 0u128,); }); Rococo::execute_with(|| { @@ -251,7 +255,7 @@ fn create_and_claim_treasury_spend_in_usdt() { ] ); // beneficiary received the assets from the treasury. - assert_eq!(>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); + assert_eq!(>::balance(&ASSET_ID, &alice,), SPEND_AMOUNT,); }); Rococo::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs index 2d02e90f47fb..67e18b680027 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs @@ -54,9 +54,13 @@ fn create_and_claim_treasury_spend() { true, SPEND_AMOUNT / 2 )); - assert_ok!(>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); + assert_ok!(>::mint_into( + &ASSET_ID, + &treasury_account, + SPEND_AMOUNT * 4 + )); // beneficiary has zero balance. - assert_eq!(>::balance(ASSET_ID, &alice,), 0u128,); + assert_eq!(>::balance(&ASSET_ID, &alice,), 0u128,); }); CollectivesWestend::execute_with(|| { @@ -109,7 +113,7 @@ fn create_and_claim_treasury_spend() { ] ); // beneficiary received the assets from the treasury. - assert_eq!(>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); + assert_eq!(>::balance(&ASSET_ID, &alice,), SPEND_AMOUNT,); }); CollectivesWestend::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs index d39c72c7c5f0..3497e3748675 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs @@ -224,17 +224,17 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_rocs_before = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sender, ) }); let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &receiver) + >::balance(&native_asset_location.clone(), &receiver) }); let receiver_rocs_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &receiver) + >::balance(&roc_at_westend_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -248,17 +248,17 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_rocs_after = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sender, ) }); let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &receiver) + >::balance(&native_asset_location, &receiver) }); let receiver_rocs_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains, &receiver) + >::balance(&roc_at_westend_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -378,17 +378,17 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Query initial balances let sender_native_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &sender) + >::balance(&native_asset_location.clone(), &sender) }); let sender_rocs_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + >::balance(&roc_at_westend_parachains.clone(), &sender) }); let receiver_native_before = test.receiver.balance; let receiver_rocs_before = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &receiver, ) }); @@ -402,17 +402,17 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Query final balances let sender_native_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &sender) + >::balance(&native_asset_location, &sender) }); let sender_rocs_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + >::balance(&roc_at_westend_parachains.clone(), &sender) }); let receiver_native_after = test.receiver.balance; let receiver_rocs_after = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.try_into().unwrap(), + &roc_at_westend_parachains.try_into().unwrap(), &receiver, ) }); @@ -537,18 +537,18 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query initial balances let sender_wnds_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &sender) + >::balance(&wnd_location.clone(), &sender) }); let sender_rocs_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + >::balance(&roc_at_westend_parachains.clone(), &sender) }); let wnds_in_sender_reserve_on_ah_before = ::account_data_of(sov_of_sender_on_ah.clone()).free; let rocs_in_sender_reserve_on_ah_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sov_of_sender_on_ah, ) }); @@ -557,17 +557,17 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { let rocs_in_receiver_reserve_on_ah_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sov_of_receiver_on_ah, ) }); let receiver_wnds_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &receiver) + >::balance(&wnd_location.clone(), &receiver) }); let receiver_rocs_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &receiver) + >::balance(&roc_at_westend_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -580,16 +580,16 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query final balances let sender_wnds_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &sender) + >::balance(&wnd_location.clone(), &sender) }); let sender_rocs_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + >::balance(&roc_at_westend_parachains.clone(), &sender) }); let rocs_in_sender_reserve_on_ah_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sov_of_sender_on_ah, ) }); @@ -598,7 +598,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { let rocs_in_receiver_reserve_on_ah_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_westend_parachains.clone().try_into().unwrap(), + &roc_at_westend_parachains.clone().try_into().unwrap(), &sov_of_receiver_on_ah, ) }); @@ -606,11 +606,11 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { ::account_data_of(sov_of_receiver_on_ah).free; let receiver_wnds_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location, &receiver) + >::balance(&wnd_location, &receiver) }); let receiver_rocs_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains, &receiver) + >::balance(&roc_at_westend_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -683,7 +683,7 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() { }); let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location, &receiver) }); fn relay_assertions(t: RelayToParaThroughAHTest) { @@ -796,7 +796,7 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() { }); let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 65d013a0eec4..e010a9d6b8bf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -590,7 +590,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -603,7 +603,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -661,7 +661,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -674,7 +674,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &sender) + >::balance(&relay_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -723,7 +723,10 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance( + &system_para_native_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -736,7 +739,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(&system_para_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -795,7 +798,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(&system_para_native_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; @@ -808,7 +811,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(&system_para_native_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; @@ -885,16 +888,19 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let sender_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &sender) + >::balance(&RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance( + &system_para_native_asset_location.clone(), + &receiver, + ) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + &system_para_foreign_asset_location.clone(), &receiver, ) }); @@ -909,15 +915,15 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let sender_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &sender) + >::balance(&RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &receiver) + >::balance(&system_para_native_asset_location, &receiver) }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &receiver) + >::balance(&system_para_foreign_asset_location, &receiver) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); @@ -1019,16 +1025,16 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(&system_para_native_asset_location.clone(), &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(&system_para_foreign_asset_location.clone(), &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &receiver) + >::balance(&RESERVABLE_ASSET_ID, &receiver) }); // Set assertions and dispatchables @@ -1040,16 +1046,16 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query final balances let sender_system_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &sender) + >::balance(&system_para_native_asset_location, &sender) }); let sender_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location, &sender) + >::balance(&system_para_foreign_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; let receiver_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(RESERVABLE_ASSET_ID, &receiver) + >::balance(&RESERVABLE_ASSET_ID, &receiver) }); // Sender's system asset balance is reduced assert!(sender_system_assets_after < sender_system_assets_before); @@ -1108,11 +1114,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(&relay_native_asset_location.clone(), &receiver) }); // Set assertions and dispatchables @@ -1125,11 +1131,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(&relay_native_asset_location.clone(), &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + >::balance(&relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index eb0e985cc0ce..f4810594e78a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -110,7 +110,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); type ForeignAssets = ::ForeignAssets; - assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); + assert!(ForeignAssets::asset_exists(&foreign_asset_at_asset_hub)); }); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index f6b658098865..eec54764ff43 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -39,7 +39,7 @@ fn swap_locally_on_chain_using_local_assets() { AssetHubWestendSender::get().into(), 1000, )); - assert!(::Assets::asset_exists(ASSET_ID)); + assert!(::Assets::asset_exists(&ASSET_ID)); assert_ok!(::Assets::mint( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), @@ -242,7 +242,7 @@ fn cannot_create_pool_from_pool_assets() { pool_owner_account_id.clone().into(), 1000, )); - assert!(::PoolAssets::asset_exists(ASSET_ID)); + assert!(::PoolAssets::asset_exists(&ASSET_ID)); assert_ok!(::PoolAssets::mint( ::RuntimeOrigin::signed(pool_owner_account_id), @@ -289,7 +289,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { AssetHubWestendSender::get().into(), ASSET_MIN_BALANCE, )); - assert!(::Assets::asset_exists(ASSET_ID)); + assert!(::Assets::asset_exists(&ASSET_ID)); assert_ok!(::Assets::mint( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index a524b87b2daf..1a3ab75f312d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -494,7 +494,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -503,12 +503,12 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_assets_before = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) + >::balance(&asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), &AssetHubWestendReceiver::get(), ) }); @@ -521,7 +521,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalASender::get(), ) }); @@ -530,12 +530,12 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_sender_assets_after = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) + >::balance(&asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), &AssetHubWestendReceiver::get(), ) }); @@ -601,7 +601,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location.clone(), + &system_para_native_asset_location.clone(), &PenpalAReceiver::get(), ) }); @@ -609,13 +609,13 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_before = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), &AssetHubWestendSender::get(), ) }); let penpal_receiver_assets_before = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) + >::balance(&asset_id_on_penpal, &PenpalAReceiver::get()) }); ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_sender_assertions); @@ -627,7 +627,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let penpal_receiver_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_native_asset_location, + &system_para_native_asset_location, &PenpalAReceiver::get(), ) }); @@ -635,13 +635,13 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_after = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), + &foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(), &AssetHubWestendSender::get(), ) }); let penpal_receiver_assets_after = PenpalA::execute_with(|| { type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) + >::balance(&asset_id_on_penpal, &PenpalAReceiver::get()) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs index 6d8c0f5e5de6..6e6960bfffda 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs @@ -53,9 +53,13 @@ fn create_and_claim_treasury_spend() { true, SPEND_AMOUNT / 2 )); - assert_ok!(>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); + assert_ok!(>::mint_into( + &ASSET_ID, + &treasury_account, + SPEND_AMOUNT * 4 + )); // beneficiary has zero balance. - assert_eq!(>::balance(ASSET_ID, &alice,), 0u128,); + assert_eq!(>::balance(&ASSET_ID, &alice,), 0u128,); }); Westend::execute_with(|| { @@ -107,7 +111,7 @@ fn create_and_claim_treasury_spend() { ] ); // beneficiary received the assets from the treasury. - assert_eq!(>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); + assert_eq!(>::balance(&ASSET_ID, &alice,), SPEND_AMOUNT,); }); Westend::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index 87fb70e4de23..f1ba6a89495b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -169,7 +169,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { ::account_data_of(AssetHubRococoSender::get()).free; let receiver_rocs_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) + >::balance(&roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) }); let amount = ASSET_HUB_ROCOCO_ED * 1_000_000; @@ -199,7 +199,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { ::account_data_of(AssetHubRococoSender::get()).free; let receiver_rocs_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) + >::balance(&roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) }); let rocs_in_reserve_on_ahr_after = ::account_data_of(sov_ahw_on_ahr.clone()).free; @@ -238,7 +238,7 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() { assert_eq!(wnds_in_reserve_on_ahw_before, prefund_amount); let sender_wnds_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) + >::balance(&wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) }); assert_eq!(sender_wnds_before, prefund_amount); let receiver_wnds_before = @@ -275,7 +275,7 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() { let sender_wnds_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) + >::balance(&wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) }); let receiver_wnds_after = ::account_data_of(AssetHubWestendReceiver::get()).free; @@ -325,14 +325,14 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() let sender_rocs_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - roc_at_rococo_parachains.clone(), + &roc_at_rococo_parachains.clone(), &PenpalASender::get(), ) }); let receiver_rocs_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_asset_hub_westend.clone().try_into().unwrap(), + &roc_at_asset_hub_westend.clone().try_into().unwrap(), &AssetHubWestendReceiver::get(), ) }); @@ -361,12 +361,12 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() let sender_rocs_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_rococo_parachains, &PenpalASender::get()) + >::balance(&roc_at_rococo_parachains, &PenpalASender::get()) }); let receiver_rocs_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - roc_at_asset_hub_westend.try_into().unwrap(), + &roc_at_asset_hub_westend.try_into().unwrap(), &AssetHubWestendReceiver::get(), ) }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 1c1c51404aa4..aa2e8fdead87 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -325,7 +325,7 @@ fn send_token_from_ethereum_to_penpal() { 1000, )); - assert!(::ForeignAssets::asset_exists(weth_asset_location)); + assert!(::ForeignAssets::asset_exists(&weth_asset_location)); }); BridgeHubRococo::execute_with(|| { @@ -583,7 +583,7 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12 )); assert!(::ForeignAssets::asset_exists( - weth_asset_location.clone().try_into().unwrap(), + &weth_asset_location.clone().try_into().unwrap(), )); }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index 597e77d9049c..1eb739fd5edf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -168,7 +168,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ::account_data_of(AssetHubWestendSender::get()).free; let receiver_wnds_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) + >::balance(&wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) }); let amount = ASSET_HUB_WESTEND_ED * 1_000; @@ -195,7 +195,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ::account_data_of(AssetHubWestendSender::get()).free; let receiver_wnds_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) + >::balance(&wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) }); let wnds_in_reserve_on_ahw_after = ::account_data_of(sov_ahr_on_ahw).free; @@ -234,7 +234,7 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() { assert_eq!(rocs_in_reserve_on_ahr_before, prefund_amount); let sender_rocs_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(roc_at_asset_hub_westend, &AssetHubWestendSender::get()) + >::balance(&roc_at_asset_hub_westend, &AssetHubWestendSender::get()) }); assert_eq!(sender_rocs_before, prefund_amount); let receiver_rocs_before = @@ -271,7 +271,7 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() { let sender_rocs_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; - >::balance(roc_at_asset_hub_westend, &AssetHubWestendSender::get()) + >::balance(&roc_at_asset_hub_westend, &AssetHubWestendSender::get()) }); let receiver_rocs_after = ::account_data_of(AssetHubRococoReceiver::get()).free; @@ -321,14 +321,14 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() let sender_wnds_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - wnd_at_westend_parachains.clone(), + &wnd_at_westend_parachains.clone(), &PenpalBSender::get(), ) }); let receiver_wnds_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_asset_hub_rococo.clone().try_into().unwrap(), + &wnd_at_asset_hub_rococo.clone().try_into().unwrap(), &AssetHubRococoReceiver::get(), ) }); @@ -357,12 +357,12 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() let sender_wnds_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_westend_parachains, &PenpalBSender::get()) + >::balance(&wnd_at_westend_parachains, &PenpalBSender::get()) }); let receiver_wnds_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - wnd_at_asset_hub_rococo.try_into().unwrap(), + &wnd_at_asset_hub_rococo.try_into().unwrap(), &AssetHubRococoReceiver::get(), ) }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/fellowship_treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/fellowship_treasury.rs index bde1220e2495..cbd53ea1b6a9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/fellowship_treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/fellowship_treasury.rs @@ -37,7 +37,7 @@ fn fellowship_treasury_spend() { let init_alice_balance = AssetHubWestend::execute_with(|| { <::Balances as Inspect<_>>::balance( - &AssetHubWestend::account_id_of(ALICE), + &&AssetHubWestend::account_id_of(ALICE), ) }); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 383751578e57..8a69b280e9b9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1186,13 +1186,13 @@ impl_runtime_apis! { xcm::v3::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index f670c5f424ef..8ec7a35ec0cd 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -211,7 +211,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create(asset_1, bob.clone(), true, 10)); - assert_ok!(Assets::mint_into(asset_1, &bob, initial_balance)); + assert_ok!(Assets::mint_into(&asset_1, &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); @@ -243,7 +243,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = Assets::total_issuance(asset_1); + let asset_total_issuance = Assets::total_issuance(&asset_1); let native_total_issuance = Balances::total_issuance(); // prepare input to buy weight. @@ -264,14 +264,14 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let unused_amount = unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); - assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); + assert_eq!(Assets::total_issuance(&asset_1), asset_total_issuance + asset_fee); // prepare input to refund weight. let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = AssetConversion::get_reserves( - xcm::v3::Location::try_from(native_location).expect("conversion works"), - xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + &xcm::v3::Location::try_from(native_location).expect("conversion works"), + &xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), ) .unwrap(); let asset_refund = @@ -288,7 +288,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { drop(trader); assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund); assert_eq!( - Assets::total_issuance(asset_1), + Assets::total_issuance(&asset_1), asset_total_issuance + asset_fee - asset_refund ); assert_eq!(Balances::total_issuance(), native_total_issuance); @@ -331,7 +331,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(&foreign_location, &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); @@ -353,7 +353,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(&foreign_location); let native_total_issuance = Balances::total_issuance(); let foreign_location_latest: Location = foreign_location.try_into().unwrap(); @@ -379,7 +379,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(&foreign_location), asset_total_issuance + asset_fee ); @@ -387,7 +387,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(&native_location, &foreign_location).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); @@ -402,7 +402,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { drop(trader); assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(&foreign_location), asset_total_issuance + asset_fee - asset_refund ); assert_eq!(Balances::total_issuance(), native_total_issuance); @@ -452,7 +452,7 @@ fn test_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = AssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - local_asset_id, + &local_asset_id, bought, ) .expect("failed to compute"); @@ -475,13 +475,13 @@ fn test_asset_xcm_take_first_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), + Assets::balance(&local_asset_id, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased assert_eq!( - Assets::total_supply(local_asset_id), + Assets::total_supply(&local_asset_id), minimum_asset_balance + asset_amount_needed ); }); @@ -535,7 +535,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - foreign_location, + &foreign_location, bought ) .expect("failed to compute"); @@ -560,13 +560,13 @@ fn test_foreign_asset_xcm_take_first_trader() { // Make sure author(Alice) has received the amount assert_eq!( - ForeignAssets::balance(foreign_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_location, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased assert_eq!( - ForeignAssets::total_supply(foreign_location), + ForeignAssets::total_supply(&foreign_location), minimum_asset_balance + asset_amount_needed ); }); @@ -642,12 +642,12 @@ fn test_asset_xcm_take_first_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&weight_used); assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + Assets::balance(&1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(Assets::total_supply(&1), ExistentialDeposit::get() + fees_paid); }); } @@ -696,10 +696,10 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); + assert_eq!(Assets::total_supply(&1), 0); }); } @@ -761,10 +761,10 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(Assets::total_supply(&1), ExistentialDeposit::get()); }); } @@ -820,10 +820,10 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); + assert_eq!(Assets::total_supply(&1), minimum_asset_balance); }); } @@ -847,9 +847,9 @@ fn test_assets_balances_api_works() { ); // check before - assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(&local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_asset_id_location, AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -902,11 +902,11 @@ fn test_assets_balances_api_works() { // check after assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), + Assets::balance(&local_asset_id, AccountId::from(ALICE)), minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_asset_id_location, AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -1180,7 +1180,7 @@ mod asset_hub_rococo_tests { assert_eq!(Balances::free_balance(&staking_pot), ExistentialDeposit::get()); // check now foreign asset for staking pot assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &staking_pot ), @@ -1194,7 +1194,7 @@ mod asset_hub_rococo_tests { ); // staking pot receives no foreign assets assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &staking_pot ), @@ -1244,7 +1244,7 @@ mod asset_hub_rococo_tests { || { // check block author before assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &block_author_account ), @@ -1254,7 +1254,7 @@ mod asset_hub_rococo_tests { || { // `TakeFirstAssetTrader` puts fees to the block author assert!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &block_author_account ) > 0 diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index e96ba3d962d8..e27d25d50886 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1277,15 +1277,15 @@ impl_runtime_apis! { xcm::v3::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: &xcm::v3::Location, asset2: &xcm::v3::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index b5957dd5df92..305ebd1a4f6c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -212,7 +212,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create(asset_1, bob.clone(), true, 10)); - assert_ok!(Assets::mint_into(asset_1, &bob, initial_balance)); + assert_ok!(Assets::mint_into(&asset_1, &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); @@ -244,7 +244,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = Assets::total_issuance(asset_1); + let asset_total_issuance = Assets::total_issuance(&asset_1); let native_total_issuance = Balances::total_issuance(); // prepare input to buy weight. @@ -265,14 +265,14 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let unused_amount = unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); - assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); + assert_eq!(Assets::total_issuance(&asset_1), asset_total_issuance + asset_fee); // prepare input to refund weight. let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = AssetConversion::get_reserves( - xcm::v3::Location::try_from(native_location).expect("conversion works"), - xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + &xcm::v3::Location::try_from(native_location).expect("conversion works"), + &xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), ) .unwrap(); let asset_refund = @@ -289,7 +289,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { drop(trader); assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund); assert_eq!( - Assets::total_issuance(asset_1), + Assets::total_issuance(&asset_1), asset_total_issuance + asset_fee - asset_refund ); assert_eq!(Balances::total_issuance(), native_total_issuance); @@ -332,7 +332,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(&foreign_location, &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); @@ -354,7 +354,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(&foreign_location); let native_total_issuance = Balances::total_issuance(); let foreign_location_latest: Location = foreign_location.try_into().unwrap(); @@ -380,7 +380,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(&foreign_location), asset_total_issuance + asset_fee ); @@ -388,7 +388,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(&native_location, &foreign_location).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); @@ -403,7 +403,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { drop(trader); assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(&foreign_location), asset_total_issuance + asset_fee - asset_refund ); assert_eq!(Balances::total_issuance(), native_total_issuance); @@ -453,7 +453,7 @@ fn test_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = AssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - local_asset_id, + &local_asset_id, bought, ) .expect("failed to compute"); @@ -476,13 +476,13 @@ fn test_asset_xcm_take_first_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), + Assets::balance(&local_asset_id, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased assert_eq!( - Assets::total_supply(local_asset_id), + Assets::total_supply(&local_asset_id), minimum_asset_balance + asset_amount_needed ); }); @@ -534,7 +534,7 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(foreign_location, bought) + let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(&foreign_location, bought) .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra @@ -557,13 +557,13 @@ fn test_foreign_asset_xcm_take_first_trader() { // Make sure author(Alice) has received the amount assert_eq!( - ForeignAssets::balance(foreign_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_location, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased assert_eq!( - ForeignAssets::total_supply(foreign_location), + ForeignAssets::total_supply(&foreign_location), minimum_asset_balance + asset_amount_needed ); }); @@ -639,12 +639,12 @@ fn test_asset_xcm_take_first_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&weight_used); assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + Assets::balance(&1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(Assets::total_supply(&1), ExistentialDeposit::get() + fees_paid); }); } @@ -693,10 +693,10 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); + assert_eq!(Assets::total_supply(&1), 0); }); } @@ -757,10 +757,10 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(Assets::total_supply(&1), ExistentialDeposit::get()); }); } @@ -816,10 +816,10 @@ fn test_asset_xcm_take_first_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!(Assets::balance(&1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); + assert_eq!(Assets::total_supply(&1), minimum_asset_balance); }); } @@ -847,9 +847,9 @@ fn test_assets_balances_api_works() { }; // check before - assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(&local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_asset_id_location, AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -902,11 +902,11 @@ fn test_assets_balances_api_works() { // check after assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), + Assets::balance(&local_asset_id, AccountId::from(ALICE)), minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(&foreign_asset_id_location, AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -1165,7 +1165,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_pool_s assert_eq!(Balances::free_balance(&staking_pot), ExistentialDeposit::get()); // check now foreign asset for staking pot assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &staking_pot ), @@ -1179,7 +1179,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_pool_s ); // staking pot receives no foreign assets assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &staking_pot ), @@ -1225,7 +1225,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_suffic || { // check block author before assert_eq!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &block_author_account ), @@ -1235,7 +1235,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_suffic || { // `TakeFirstAssetTrader` puts fees to the block author assert!( - ForeignAssets::balance( + ForeignAssets::balance(& foreign_asset_id_location.into(), &block_author_account ) > 0 diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 884b71369e79..652798e81967 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -438,14 +438,14 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account ), 0.into() ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &CheckingAccount::get() ), 0.into() @@ -526,7 +526,7 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account ), teleported_foreign_asset_amount.into() @@ -538,7 +538,7 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &CheckingAccount::get() ), 0.into() @@ -566,7 +566,7 @@ pub fn teleports_for_foreign_assets_works< let target_account_balance_before_teleport = >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account, ); let asset_to_teleport_away = asset_minimum_asset_balance * 3; @@ -606,14 +606,14 @@ pub fn teleports_for_foreign_assets_works< // check balances assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account ), (target_account_balance_before_teleport - asset_to_teleport_away.into()) ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &CheckingAccount::get() ), 0.into() @@ -881,28 +881,28 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works< // check Assets before assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &alice_account ), (6 * asset_minimum_asset_balance).into() ); assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &bob_account ), 0.into() ); assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &charlie_account ), 0.into() ); assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &asset_owner ), 0.into() @@ -970,28 +970,28 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works< // check Assets after assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &alice_account ), (5 * asset_minimum_asset_balance).into() ); assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &bob_account ), asset_minimum_asset_balance.into() ); assert_eq!( >::balance( - asset_id.clone().into(), + &asset_id.clone().into(), &charlie_account ), 0.into() ); assert_eq!( >::balance( - asset_id.into(), + &asset_id.into(), &asset_owner ), 0.into() @@ -1252,25 +1252,25 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor use frame_support::traits::fungibles::roles::Inspect as InspectRoles; assert_eq!( >::owner( - asset_id.clone().into() + &asset_id.clone().into() ), Some(foreign_creator_as_account_id.clone()) ); assert_eq!( >::admin( - asset_id.clone().into() + &asset_id.clone().into() ), Some(foreign_creator_as_account_id.clone()) ); assert_eq!( >::issuer( - asset_id.clone().into() + &asset_id.clone().into() ), Some(foreign_creator_as_account_id.clone()) ); assert_eq!( >::freezer( - asset_id.clone().into() + &asset_id.clone().into() ), Some(bob_account.clone()) ); diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs index 0b2364dbb8bd..f6923271cf33 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs @@ -409,7 +409,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< // ForeignAssets balances before assert_eq!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account ), 0.into() @@ -482,7 +482,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< // ForeignAssets balances after assert!( >::balance( - foreign_asset_id_location.into(), + &foreign_asset_id_location.into(), &target_account ) > 0.into() ); diff --git a/cumulus/parachains/runtimes/test-utils/src/lib.rs b/cumulus/parachains/runtimes/test-utils/src/lib.rs index 3c84243306fb..696fcddafb05 100644 --- a/cumulus/parachains/runtimes/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/test-utils/src/lib.rs @@ -534,9 +534,9 @@ pub fn assert_metadata( Fungibles: frame_support::traits::fungibles::metadata::Inspect + frame_support::traits::fungibles::Inspect, { - assert_eq!(Fungibles::name(asset_id.clone().into()), Vec::from(expected_name),); - assert_eq!(Fungibles::symbol(asset_id.clone().into()), Vec::from(expected_symbol),); - assert_eq!(Fungibles::decimals(asset_id.into()), expected_decimals); + assert_eq!(Fungibles::name(&asset_id.clone().into()), Vec::from(expected_name),); + assert_eq!(Fungibles::symbol(&asset_id.clone().into()), Vec::from(expected_symbol),); + assert_eq!(Fungibles::decimals(&asset_id.into()), expected_decimals); } pub fn assert_total( @@ -547,8 +547,8 @@ pub fn assert_total( Fungibles: frame_support::traits::fungibles::metadata::Inspect + frame_support::traits::fungibles::Inspect, { - assert_eq!(Fungibles::total_issuance(asset_id.clone().into()), expected_total_issuance.into()); - assert_eq!(Fungibles::active_issuance(asset_id.into()), expected_active_issuance.into()); + assert_eq!(Fungibles::total_issuance(&asset_id.clone().into()), expected_total_issuance.into()); + assert_eq!(Fungibles::active_issuance(&asset_id.into()), expected_active_issuance.into()); } /// Helper function which emulates opening HRMP channel which is needed for `XcmpQueue` to pass. diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 54f40bd01097..37e486c10f52 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -163,18 +163,17 @@ impl< // Calculate how much we should charge in the asset_id for such amount of weight // Require at least a payment of minimum_balance // Necessary for fully collateral-backed assets - let asset_balance: u128 = - FeeCharger::charge_weight_in_fungibles(local_asset_id.clone(), weight) - .map(|amount| { - let minimum_balance = ConcreteAssets::minimum_balance(local_asset_id); - if amount < minimum_balance { - minimum_balance - } else { - amount - } - })? - .try_into() - .map_err(|_| XcmError::Overflow)?; + let asset_balance: u128 = FeeCharger::charge_weight_in_fungibles(&local_asset_id, weight) + .map(|amount| { + let minimum_balance = ConcreteAssets::minimum_balance(&local_asset_id); + if amount < minimum_balance { + minimum_balance + } else { + amount + } + })? + .try_into() + .map_err(|_| XcmError::Overflow)?; // Convert to the same kind of asset, with the required fungible balance let required = first.id.clone().into_asset(asset_balance.into()); @@ -202,12 +201,12 @@ impl< let (local_asset_id, outstanding_balance) = Matcher::matches_fungibles(&(id.clone(), fun).into()).ok()?; - let minimum_balance = ConcreteAssets::minimum_balance(local_asset_id.clone()); + let minimum_balance = ConcreteAssets::minimum_balance(&local_asset_id); // Calculate asset_balance // This read should have already be cached in buy_weight let (asset_balance, outstanding_minus_subtracted) = - FeeCharger::charge_weight_in_fungibles(local_asset_id, weight).ok().map( + FeeCharger::charge_weight_in_fungibles(&local_asset_id, weight).ok().map( |asset_balance| { // Require at least a drop of minimum_balance // Necessary for fully collateral-backed assets @@ -297,7 +296,7 @@ impl< /// in such assetId for that amount of weight pub trait ChargeWeightInFungibles> { fn charge_weight_in_fungibles( - asset_id: >::AssetId, + asset_id: &>::AssetId, weight: Weight, ) -> Result<>::Balance, XcmError>; } @@ -404,7 +403,7 @@ impl< return Err(XcmError::FeesNotMet) } - let credit_in = Fungibles::issue(fungibles_asset, balance); + let credit_in = Fungibles::issue(&fungibles_asset, balance); let fee = WeightToFee::weight_to_fee(&weight); // swap the user's asset for the `Target` asset. @@ -683,24 +682,24 @@ mod test_trader { type AssetId = TestAssetId; type Balance = TestBalance; - fn total_issuance(_: Self::AssetId) -> Self::Balance { + fn total_issuance(_: &Self::AssetId) -> Self::Balance { todo!() } - fn minimum_balance(_: Self::AssetId) -> Self::Balance { + fn minimum_balance(_: &Self::AssetId) -> Self::Balance { 0 } - fn balance(_: Self::AssetId, _: &TestAccountId) -> Self::Balance { + fn balance(_: &Self::AssetId, _: &TestAccountId) -> Self::Balance { todo!() } - fn total_balance(_: Self::AssetId, _: &TestAccountId) -> Self::Balance { + fn total_balance(_: &Self::AssetId, _: &TestAccountId) -> Self::Balance { todo!() } fn reducible_balance( - _: Self::AssetId, + _: &Self::AssetId, _: &TestAccountId, _: Preservation, _: Fortitude, @@ -709,7 +708,7 @@ mod test_trader { } fn can_deposit( - _: Self::AssetId, + _: &Self::AssetId, _: &TestAccountId, _: Self::Balance, _: Provenance, @@ -718,14 +717,14 @@ mod test_trader { } fn can_withdraw( - _: Self::AssetId, + _: &Self::AssetId, _: &TestAccountId, _: Self::Balance, ) -> WithdrawConsequence { todo!() } - fn asset_exists(_: Self::AssetId) -> bool { + fn asset_exists(_: &Self::AssetId) -> bool { todo!() } } @@ -739,14 +738,14 @@ mod test_trader { todo!() } fn write_balance( - _: Self::AssetId, + _: &Self::AssetId, _: &TestAccountId, _: Self::Balance, ) -> Result, DispatchError> { todo!() } - fn set_total_issuance(_: Self::AssetId, _: Self::Balance) { + fn set_total_issuance(_: &Self::AssetId, _: Self::Balance) { todo!() } } @@ -754,7 +753,7 @@ mod test_trader { struct FeeChargerAssetsHandleRefund; impl ChargeWeightInFungibles for FeeChargerAssetsHandleRefund { fn charge_weight_in_fungibles( - _: >::AssetId, + _: &>::AssetId, _: Weight, ) -> Result<>::Balance, XcmError> { Ok(AMOUNT) diff --git a/cumulus/primitives/utility/src/tests/swap_first.rs b/cumulus/primitives/utility/src/tests/swap_first.rs index 2e19db498816..8075fb85305f 100644 --- a/cumulus/primitives/utility/src/tests/swap_first.rs +++ b/cumulus/primitives/utility/src/tests/swap_first.rs @@ -68,8 +68,8 @@ fn holding_asset_swap_for_target() { let holding_asset = create_holding_asset(CLIENT_ASSET, client_asset_total); let holding_change = create_holding_asset(CLIENT_ASSET, client_asset_total - fee); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -80,8 +80,8 @@ fn holding_asset_swap_for_target() { assert_eq!(trader.total_fee.peek(), fee); assert_eq!(trader.last_fee_asset, Some(create_asset_id(CLIENT_ASSET))); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee); } #[test] @@ -96,8 +96,8 @@ fn holding_asset_swap_for_target_twice() { let holding_change1 = create_holding_asset(CLIENT_ASSET, client_asset_total - fee1); let holding_change2 = create_holding_asset(CLIENT_ASSET, client_asset_total - fee1 - fee2); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -114,8 +114,8 @@ fn holding_asset_swap_for_target_twice() { assert_eq!(trader.total_fee.peek(), fee1 + fee2); assert_eq!(trader.last_fee_asset, Some(create_asset_id(CLIENT_ASSET))); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee1 + fee2); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee1 + fee2); } #[test] @@ -133,8 +133,8 @@ fn buy_and_refund_twice_for_target() { let holding_change = create_holding_asset(CLIENT_ASSET, client_asset_total - fee); let refund_asset = create_asset(CLIENT_ASSET, refund1); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -155,8 +155,8 @@ fn buy_and_refund_twice_for_target() { assert_eq!(trader.total_fee.peek(), fee - refund1); assert_eq!(trader.last_fee_asset, Some(create_asset_id(CLIENT_ASSET))); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee - refund1); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee - refund1); } #[test] @@ -181,9 +181,9 @@ fn buy_with_various_assets_and_refund_for_target() { let refund_asset = create_asset(CLIENT_ASSET_2, refund1); let refund_asset_2 = create_asset(CLIENT_ASSET_2, refund2); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); - let client_total_2 = Fungibles::total_issuance(CLIENT_ASSET_2); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); + let client_total_2 = Fungibles::total_issuance(&CLIENT_ASSET_2); let mut trader = Trader::new(); // first purchase with `CLIENT_ASSET`. @@ -221,10 +221,10 @@ fn buy_with_various_assets_and_refund_for_target() { assert_eq!(trader.total_fee.peek(), fee1 + fee2 - refund1 - refund2); assert_eq!(trader.last_fee_asset, Some(create_asset_id(CLIENT_ASSET_2))); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee1); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee1); assert_eq!( - Fungibles::total_issuance(CLIENT_ASSET_2), + Fungibles::total_issuance(&CLIENT_ASSET_2), client_total_2 + fee2 - refund1 - refund2 ); } @@ -240,8 +240,8 @@ fn not_enough_to_refund() { let holding_asset = create_holding_asset(CLIENT_ASSET, client_asset_total); let holding_change = create_holding_asset(CLIENT_ASSET, client_asset_total - fee); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -254,8 +254,8 @@ fn not_enough_to_refund() { assert_eq!(trader.refund_weight(weight_worth_of(refund), &xcm_context()), None); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee); } #[test] @@ -269,8 +269,8 @@ fn not_exchangeable_to_refund() { let holding_asset = create_holding_asset(CLIENT_ASSET, client_asset_total); let holding_change = create_holding_asset(CLIENT_ASSET, client_asset_total - fee); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -283,8 +283,8 @@ fn not_exchangeable_to_refund() { assert_eq!(trader.refund_weight(weight_worth_of(refund), &xcm_context()), None); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total + fee); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total + fee); } #[test] @@ -299,8 +299,8 @@ fn nothing_to_refund() { fn holding_asset_not_exchangeable_for_target() { let holding_asset = create_holding_asset(CLIENT_ASSET, 10); - let target_total = Fungibles::total_issuance(TARGET_ASSET); - let client_total = Fungibles::total_issuance(CLIENT_ASSET); + let target_total = Fungibles::total_issuance(&TARGET_ASSET); + let client_total = Fungibles::total_issuance(&CLIENT_ASSET); let mut trader = Trader::new(); assert_eq!( @@ -310,8 +310,8 @@ fn holding_asset_not_exchangeable_for_target() { XcmError::FeesNotMet ); - assert_eq!(Fungibles::total_issuance(TARGET_ASSET), target_total); - assert_eq!(Fungibles::total_issuance(CLIENT_ASSET), client_total); + assert_eq!(Fungibles::total_issuance(&TARGET_ASSET), target_total); + assert_eq!(Fungibles::total_issuance(&CLIENT_ASSET), client_total); } #[test] @@ -452,8 +452,8 @@ pub mod mock { pub fn setup_pool(asset1: AssetId, liquidity1: Balance, asset2: AssetId, liquidity2: Balance) { let account = pool_account(asset1, asset2); SWAP.with(|b| b.borrow_mut().insert((asset1, asset2), account)); - let debt1 = Fungibles::deposit(asset1, &account, liquidity1, Exact); - let debt2 = Fungibles::deposit(asset2, &account, liquidity2, Exact); + let debt1 = Fungibles::deposit(&asset1, &account, liquidity1, Exact); + let debt2 = Fungibles::deposit(&asset2, &account, liquidity2, Exact); drop(debt1); drop(debt2); } @@ -470,28 +470,28 @@ pub mod mock { impl Inspect for Fungibles { type AssetId = AssetId; type Balance = Balance; - fn total_issuance(asset: Self::AssetId) -> Self::Balance { + fn total_issuance(asset: &Self::AssetId) -> Self::Balance { TOTAL_ISSUANCE.with(|b| b.borrow().get(&asset).map_or(Self::Balance::zero(), |b| *b)) } - fn minimum_balance(_: Self::AssetId) -> Self::Balance { + fn minimum_balance(_: &Self::AssetId) -> Self::Balance { Self::Balance::one() } - fn total_balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - ACCOUNT.with(|b| b.borrow().get(&(asset, *who)).map_or(Self::Balance::zero(), |b| *b)) + fn total_balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + ACCOUNT.with(|b| b.borrow().get(&(*asset, *who)).map_or(Self::Balance::zero(), |b| *b)) } - fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - ACCOUNT.with(|b| b.borrow().get(&(asset, *who)).map_or(Self::Balance::zero(), |b| *b)) + fn balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + ACCOUNT.with(|b| b.borrow().get(&(*asset, *who)).map_or(Self::Balance::zero(), |b| *b)) } fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, _: Preservation, _: Fortitude, ) -> Self::Balance { - ACCOUNT.with(|b| b.borrow().get(&(asset, *who)).map_or(Self::Balance::zero(), |b| *b)) + ACCOUNT.with(|b| b.borrow().get(&(*asset, *who)).map_or(Self::Balance::zero(), |b| *b)) } fn can_deposit( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Self::Balance, _: Provenance, @@ -499,30 +499,30 @@ pub mod mock { unimplemented!() } fn can_withdraw( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Self::Balance, ) -> WithdrawConsequence { unimplemented!() } - fn asset_exists(_: Self::AssetId) -> bool { + fn asset_exists(_: &Self::AssetId) -> bool { unimplemented!() } } impl Unbalanced for Fungibles { - fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance) { - TOTAL_ISSUANCE.with(|b| b.borrow_mut().insert(asset, amount)); + fn set_total_issuance(asset: &Self::AssetId, amount: Self::Balance) { + TOTAL_ISSUANCE.with(|b| b.borrow_mut().insert(*asset, amount)); } fn handle_dust(_: Dust) { unimplemented!() } fn write_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError> { - let _ = ACCOUNT.with(|b| b.borrow_mut().insert((asset, *who), amount)); + let _ = ACCOUNT.with(|b| b.borrow_mut().insert((*asset, *who), amount)); Ok(None) } } diff --git a/polkadot/node/core/pvf/common/Cargo.toml b/polkadot/node/core/pvf/common/Cargo.toml index e1ce6e79cb99..bd405a4964b7 100644 --- a/polkadot/node/core/pvf/common/Cargo.toml +++ b/polkadot/node/core/pvf/common/Cargo.toml @@ -42,7 +42,6 @@ seccompiler = "0.4.0" [dev-dependencies] assert_matches = "1.4.0" -tempfile = "3.3.0" [features] # This feature is used to export test code to other crates without putting it in the production build. diff --git a/polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs b/polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs index f42e220d6932..687d008f092b 100644 --- a/polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs +++ b/polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs @@ -423,7 +423,7 @@ fn destination_asset_reserve_and_local_fee_reserve_call( // balances checks before assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); @@ -453,25 +453,19 @@ fn destination_asset_reserve_and_local_fee_reserve_call( // Alice spent (transferred) amount assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount - SEND_AMOUNT ); // Alice used native asset for fees assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - FEE_AMOUNT); // Destination account (parachain account) added native reserve used as fee to balances assert_eq!(Balances::free_balance(reserve_sovereign_account.clone()), FEE_AMOUNT); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), reserve_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, reserve_sovereign_account), 0); // Verify total and active issuance of foreign BLA have decreased (burned on // reserve-withdraw) let expected_issuance = foreign_initial_amount - SEND_AMOUNT; - assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), - expected_issuance - ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&foreign_asset_id_location), expected_issuance); // Verify sent XCM program assert_eq!( @@ -578,7 +572,7 @@ fn remote_asset_reserve_and_local_fee_reserve_call_disallowed( // balances checks before assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); @@ -596,7 +590,7 @@ fn remote_asset_reserve_and_local_fee_reserve_call_disallowed( // Alice transferred nothing assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); // Alice spent native asset for fees @@ -604,11 +598,8 @@ fn remote_asset_reserve_and_local_fee_reserve_call_disallowed( // Verify total and active issuance of foreign BLA asset have decreased (burned on // reserve-withdraw) let expected_issuance = foreign_initial_amount; - assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), - expected_issuance - ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&foreign_asset_id_location), expected_issuance); }); } @@ -697,10 +688,7 @@ fn local_asset_reserve_and_destination_fee_reserve_call( let expected_asset = xfer_asset.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -740,21 +728,18 @@ fn local_asset_reserve_and_destination_fee_reserve_call( // Alice spent (fees) amount assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), + AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount - FEE_AMOUNT ); // Alice used native asset for transfer assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT); // Sovereign account of dest parachain holds `SEND_AMOUNT` native asset in local reserve assert_eq!(Balances::free_balance(usdc_chain_sovereign_account.clone()), SEND_AMOUNT); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), usdc_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, usdc_chain_sovereign_account), 0); // Verify total and active issuance of USDC have decreased (burned on reserve-withdraw) let expected_issuance = usdc_initial_local_amount - FEE_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdc_id_location.clone()), expected_issuance); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location), expected_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), expected_issuance); // Verify sent XCM program assert_eq!( @@ -852,7 +837,7 @@ fn destination_asset_reserve_and_destination_fee_reserve_call( // balances checks before assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); @@ -894,25 +879,19 @@ fn destination_asset_reserve_and_destination_fee_reserve_call( // Alice spent (transferred) amount assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount - SEND_AMOUNT ); // Alice's native asset balance is untouched assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Reserve sovereign account has same balances assert_eq!(Balances::free_balance(reserve_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), reserve_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, reserve_sovereign_account), 0); // Verify total and active issuance of foreign BLA have decreased (burned on // reserve-withdraw) let expected_issuance = foreign_initial_amount - SEND_AMOUNT; - assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), - expected_issuance - ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&foreign_asset_id_location), expected_issuance); // Verify sent XCM program assert_eq!( @@ -1014,12 +993,9 @@ fn remote_asset_reserve_and_destination_fee_reserve_call_disallowed( ); // balances checks before + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); @@ -1037,23 +1013,20 @@ fn remote_asset_reserve_and_destination_fee_reserve_call_disallowed( // Alice native asset untouched assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); let expected_usdc_issuance = usdc_initial_local_amount; - assert_eq!(AssetsPallet::total_issuance(usdc_id_location.clone()), expected_usdc_issuance); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location.clone()), expected_usdc_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), expected_usdc_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), expected_usdc_issuance); let expected_bla_issuance = foreign_initial_amount; + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_bla_issuance); assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), + AssetsPallet::active_issuance(&foreign_asset_id_location), expected_bla_issuance ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_bla_issuance); }); } @@ -1131,10 +1104,7 @@ fn local_asset_reserve_and_remote_fee_reserve_call_disallowed( ); // balances checks before - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1147,21 +1117,15 @@ fn local_asset_reserve_and_remote_fee_reserve_call_disallowed( Unlimited, ); assert_eq!(result, expected_result); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Sovereign account of reserve parachain is unchanged assert_eq!(Balances::free_balance(usdc_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), usdc_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, usdc_chain_sovereign_account), 0); assert_eq!(Balances::free_balance(dest_sovereign_account), 0); let expected_usdc_issuance = usdc_initial_local_amount; - assert_eq!(AssetsPallet::total_issuance(usdc_id_location.clone()), expected_usdc_issuance); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location), expected_usdc_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), expected_usdc_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), expected_usdc_issuance); }); } @@ -1249,10 +1213,7 @@ fn destination_asset_reserve_and_remote_fee_reserve_call_disallowed( ); // balances checks before - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1267,33 +1228,24 @@ fn destination_asset_reserve_and_remote_fee_reserve_call_disallowed( assert_eq!(result, expected_result); // Alice native asset untouched assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(usdc_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), usdc_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, usdc_chain_sovereign_account), 0); assert_eq!(Balances::free_balance(dest_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), dest_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, dest_sovereign_account), 0); let expected_usdc_issuance = usdc_initial_local_amount; - assert_eq!(AssetsPallet::total_issuance(usdc_id_location.clone()), expected_usdc_issuance); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location.clone()), expected_usdc_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), expected_usdc_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), expected_usdc_issuance); let expected_bla_issuance = foreign_initial_amount; + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_bla_issuance); assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), + AssetsPallet::active_issuance(&foreign_asset_id_location), expected_bla_issuance ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_bla_issuance); }); } @@ -1389,10 +1341,7 @@ fn remote_asset_reserve_and_remote_fee_reserve_call( let expected_fee_on_dest = fees_half_2.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1417,21 +1366,18 @@ fn remote_asset_reserve_and_remote_fee_reserve_call( // Alice spent (transferred) amount assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), + AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount - SEND_AMOUNT ); // Alice's native asset balance is untouched assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Destination account (parachain account) has expected (same) balances assert_eq!(Balances::free_balance(usdc_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), usdc_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, usdc_chain_sovereign_account), 0); // Verify total and active issuance of USDC have decreased (burned on reserve-withdraw) let expected_usdc_issuance = usdc_initial_local_amount - SEND_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdc_id_location.clone()), expected_usdc_issuance); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location.clone()), expected_usdc_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), expected_usdc_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), expected_usdc_issuance); // Verify sent XCM program assert_eq!( @@ -1532,10 +1478,7 @@ fn local_asset_reserve_and_teleported_fee_call( let expected_asset = xfer_asset.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1574,21 +1517,18 @@ fn local_asset_reserve_and_teleported_fee_call( )); // Alice spent (fees) amount assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), + AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount - FEE_AMOUNT ); // Alice used native asset for transfer assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT); // Sovereign account of dest parachain holds `SEND_AMOUNT` native asset in local reserve assert_eq!(Balances::free_balance(usdt_chain_sovereign_account.clone()), SEND_AMOUNT); - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); // Verify total and active issuance have decreased (teleported) let expected_usdt_issuance = usdt_initial_local_amount - FEE_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdt_id_location.clone()), expected_usdt_issuance); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), expected_usdt_issuance); // Verify sent XCM program assert_eq!( @@ -1694,10 +1634,7 @@ fn destination_asset_reserve_and_teleported_fee_call( let expected_asset = xfer_asset.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1738,38 +1675,32 @@ fn destination_asset_reserve_and_teleported_fee_call( assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Alice spent USDT for fees assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), + AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount - FEE_AMOUNT ); // Alice transferred BLA assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount - SEND_AMOUNT ); // Verify balances of USDT reserve parachain assert_eq!(Balances::free_balance(usdt_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); // Verify balances of transferred-asset reserve parachain assert_eq!(Balances::free_balance(dest_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), dest_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, dest_sovereign_account), 0); // Verify total and active issuance of USDT have decreased (teleported) let expected_usdt_issuance = usdt_initial_local_amount - FEE_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdt_id_location.clone()), expected_usdt_issuance); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location.clone()), expected_usdt_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), expected_usdt_issuance); // Verify total and active issuance of foreign BLA asset have decreased (burned on // reserve-withdraw) let expected_bla_issuance = foreign_initial_amount - SEND_AMOUNT; + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_bla_issuance); assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), + AssetsPallet::active_issuance(&foreign_asset_id_location), expected_bla_issuance ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_bla_issuance); // Verify sent XCM program assert_eq!( @@ -1864,10 +1795,7 @@ fn remote_asset_reserve_and_teleported_fee_reserve_call_disallowed( ); // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // try the transfer @@ -1882,33 +1810,24 @@ fn remote_asset_reserve_and_teleported_fee_reserve_call_disallowed( assert_eq!(result, expected_result); // Alice native asset untouched assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount ); assert_eq!(Balances::free_balance(usdt_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); assert_eq!(Balances::free_balance(reserve_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), reserve_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, reserve_sovereign_account), 0); let expected_usdt_issuance = usdt_initial_local_amount; - assert_eq!(AssetsPallet::total_issuance(usdt_id_location.clone()), expected_usdt_issuance); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location.clone()), expected_usdt_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), expected_usdt_issuance); let expected_bla_issuance = foreign_initial_amount; + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_bla_issuance); assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), + AssetsPallet::active_issuance(&foreign_asset_id_location), expected_bla_issuance ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_bla_issuance); }); } @@ -1963,10 +1882,7 @@ fn reserve_transfer_assets_with_teleportable_asset_disallowed() { let fee_index = 0; // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -1982,21 +1898,12 @@ fn reserve_transfer_assets_with_teleportable_asset_disallowed() { // Alice native asset is still same assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Alice USDT balance is still same - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); // No USDT moved to sovereign account of reserve parachain - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); // Verify total and active issuance of USDT are still the same - assert_eq!( - AssetsPallet::total_issuance(usdt_id_location.clone()), - usdt_initial_local_amount - ); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location), usdt_initial_local_amount); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), usdt_initial_local_amount); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), usdt_initial_local_amount); }); } @@ -2050,10 +1957,7 @@ fn intermediary_error_reverts_side_effects() { let fee_index = 0; // balances checks before - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // introduce artificial error in sending outbound XCM @@ -2071,23 +1975,14 @@ fn intermediary_error_reverts_side_effects() { .is_err()); // Alice no changes - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), ALICE), - usdc_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, ALICE), usdc_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Destination account (parachain account) no changes assert_eq!(Balances::free_balance(usdc_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdc_id_location.clone(), usdc_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdc_id_location, usdc_chain_sovereign_account), 0); // Verify total and active issuance of USDC has not changed - assert_eq!( - AssetsPallet::total_issuance(usdc_id_location.clone()), - usdc_initial_local_amount - ); - assert_eq!(AssetsPallet::active_issuance(usdc_id_location), usdc_initial_local_amount); + assert_eq!(AssetsPallet::total_issuance(&usdc_id_location), usdc_initial_local_amount); + assert_eq!(AssetsPallet::active_issuance(&usdc_id_location), usdc_initial_local_amount); // Verify no XCM program sent assert_eq!(sent_xcm(), vec![]); }); @@ -2138,10 +2033,7 @@ fn teleport_asset_using_local_fee_reserve_call( let expected_asset = xfer_asset.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -2169,22 +2061,19 @@ fn teleport_asset_using_local_fee_reserve_call( // Alice spent (transferred) amount assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), + AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount - SEND_AMOUNT ); // Alice used native asset for fees assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - FEE_AMOUNT); // Destination account (parachain account) added native reserve to balances assert_eq!(Balances::free_balance(usdt_chain_sovereign_account.clone()), FEE_AMOUNT); - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); // Verify total and active issuance of foreign BLA have decreased (burned on // reserve-withdraw) let expected_issuance = usdt_initial_local_amount - SEND_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdt_id_location.clone()), expected_issuance); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location), expected_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), expected_issuance); // Verify sent XCM program assert_eq!( @@ -2299,10 +2188,7 @@ fn teleported_asset_using_destination_reserve_fee_call( let expected_asset = xfer_asset.reanchored(&dest, &context).unwrap(); // balances checks before - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), - usdt_initial_local_amount - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // do the transfer @@ -2343,38 +2229,32 @@ fn teleported_asset_using_destination_reserve_fee_call( assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); // Alice spent USDT for fees assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), ALICE), + AssetsPallet::balance(&usdt_id_location, ALICE), usdt_initial_local_amount - SEND_AMOUNT ); // Alice transferred BLA assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), ALICE), + AssetsPallet::balance(&foreign_asset_id_location, ALICE), foreign_initial_amount - FEE_AMOUNT ); // Verify balances of USDT reserve parachain assert_eq!(Balances::free_balance(usdt_chain_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(usdt_id_location.clone(), usdt_chain_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&usdt_id_location, usdt_chain_sovereign_account), 0); // Verify balances of transferred-asset reserve parachain assert_eq!(Balances::free_balance(dest_sovereign_account.clone()), 0); - assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), dest_sovereign_account), - 0 - ); + assert_eq!(AssetsPallet::balance(&foreign_asset_id_location, dest_sovereign_account), 0); // Verify total and active issuance of USDT have decreased (teleported) let expected_usdt_issuance = usdt_initial_local_amount - SEND_AMOUNT; - assert_eq!(AssetsPallet::total_issuance(usdt_id_location.clone()), expected_usdt_issuance); - assert_eq!(AssetsPallet::active_issuance(usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::total_issuance(&usdt_id_location), expected_usdt_issuance); + assert_eq!(AssetsPallet::active_issuance(&usdt_id_location), expected_usdt_issuance); // Verify total and active issuance of foreign BLA asset have decreased (burned on // reserve-withdraw) let expected_bla_issuance = foreign_initial_amount - FEE_AMOUNT; + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_bla_issuance); assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), + AssetsPallet::active_issuance(&foreign_asset_id_location), expected_bla_issuance ); - assert_eq!(AssetsPallet::active_issuance(foreign_asset_id_location), expected_bla_issuance); // Verify sent XCM program assert_eq!( @@ -2480,7 +2360,7 @@ fn remote_asset_reserve_and_remote_fee_reserve_paid_call( // balances checks before assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), user_account.clone()), + AssetsPallet::balance(&foreign_asset_id_location, user_account.clone()), foreign_initial_amount ); assert_eq!(Balances::free_balance(user_account.clone()), INITIAL_BALANCE); @@ -2522,7 +2402,7 @@ fn remote_asset_reserve_and_remote_fee_reserve_paid_call( // user account spent (transferred) amount assert_eq!( - AssetsPallet::balance(foreign_asset_id_location.clone(), user_account.clone()), + AssetsPallet::balance(&foreign_asset_id_location, user_account.clone()), foreign_initial_amount - SEND_AMOUNT ); @@ -2538,14 +2418,8 @@ fn remote_asset_reserve_and_remote_fee_reserve_paid_call( // Verify total and active issuance of foreign BLA have decreased (burned on // reserve-withdraw) let expected_issuance = foreign_initial_amount - SEND_AMOUNT; - assert_eq!( - AssetsPallet::total_issuance(foreign_asset_id_location.clone()), - expected_issuance - ); - assert_eq!( - AssetsPallet::active_issuance(foreign_asset_id_location.clone()), - expected_issuance - ); + assert_eq!(AssetsPallet::total_issuance(&foreign_asset_id_location), expected_issuance); + assert_eq!(AssetsPallet::active_issuance(&foreign_asset_id_location), expected_issuance); let context = UniversalLocation::get(); let foreign_id_location_reanchored = diff --git a/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs b/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs index b4c418ebf1c9..4a04e6228432 100644 --- a/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs @@ -54,7 +54,7 @@ impl< .ok_or(MatchError::AccountIdConversionFailed)?; let dest = AccountIdConverter::convert_location(to) .ok_or(MatchError::AccountIdConversionFailed)?; - Assets::transfer(asset_id, &source, &dest, amount, Preserve) + Assets::transfer(&asset_id, &source, &dest, amount, Preserve) .map_err(|e| XcmError::FailedToTransactAsset(e.into()))?; Ok(what.clone().into()) } @@ -156,25 +156,25 @@ impl< > FungiblesMutateAdapter { - fn can_accrue_checked(asset_id: Assets::AssetId, amount: Assets::Balance) -> XcmResult { + fn can_accrue_checked(asset_id: &Assets::AssetId, amount: Assets::Balance) -> XcmResult { let checking_account = CheckingAccount::get(); Assets::can_deposit(asset_id, &checking_account, amount, Minted) .into_result() .map_err(|_| XcmError::NotDepositable) } - fn can_reduce_checked(asset_id: Assets::AssetId, amount: Assets::Balance) -> XcmResult { + fn can_reduce_checked(asset_id: &Assets::AssetId, amount: Assets::Balance) -> XcmResult { let checking_account = CheckingAccount::get(); Assets::can_withdraw(asset_id, &checking_account, amount) .into_result(false) .map_err(|_| XcmError::NotWithdrawable) .map(|_| ()) } - fn accrue_checked(asset_id: Assets::AssetId, amount: Assets::Balance) { + fn accrue_checked(asset_id: &Assets::AssetId, amount: Assets::Balance) { let checking_account = CheckingAccount::get(); let ok = Assets::mint_into(asset_id, &checking_account, amount).is_ok(); debug_assert!(ok, "`can_accrue_checked` must have returned `true` immediately prior; qed"); } - fn reduce_checked(asset_id: Assets::AssetId, amount: Assets::Balance) { + fn reduce_checked(asset_id: &Assets::AssetId, amount: Assets::Balance) { let checking_account = CheckingAccount::get(); let ok = Assets::burn_from(asset_id, &checking_account, amount, Exact, Polite).is_ok(); debug_assert!(ok, "`can_reduce_checked` must have returned `true` immediately prior; qed"); @@ -208,9 +208,9 @@ impl< let (asset_id, amount) = Matcher::matches_fungibles(what)?; match CheckAsset::asset_checking(&asset_id) { // We track this asset's teleports to ensure no more come in than have gone out. - Some(MintLocation::Local) => Self::can_reduce_checked(asset_id, amount), + Some(MintLocation::Local) => Self::can_reduce_checked(&asset_id, amount), // We track this asset's teleports to ensure no more go out than have come in. - Some(MintLocation::NonLocal) => Self::can_accrue_checked(asset_id, amount), + Some(MintLocation::NonLocal) => Self::can_accrue_checked(&asset_id, amount), _ => Ok(()), } } @@ -224,9 +224,9 @@ impl< if let Ok((asset_id, amount)) = Matcher::matches_fungibles(what) { match CheckAsset::asset_checking(&asset_id) { // We track this asset's teleports to ensure no more come in than have gone out. - Some(MintLocation::Local) => Self::reduce_checked(asset_id, amount), + Some(MintLocation::Local) => Self::reduce_checked(&asset_id, amount), // We track this asset's teleports to ensure no more go out than have come in. - Some(MintLocation::NonLocal) => Self::accrue_checked(asset_id, amount), + Some(MintLocation::NonLocal) => Self::accrue_checked(&asset_id, amount), _ => (), } } @@ -242,9 +242,9 @@ impl< let (asset_id, amount) = Matcher::matches_fungibles(what)?; match CheckAsset::asset_checking(&asset_id) { // We track this asset's teleports to ensure no more come in than have gone out. - Some(MintLocation::Local) => Self::can_accrue_checked(asset_id, amount), + Some(MintLocation::Local) => Self::can_accrue_checked(&asset_id, amount), // We track this asset's teleports to ensure no more go out than have come in. - Some(MintLocation::NonLocal) => Self::can_reduce_checked(asset_id, amount), + Some(MintLocation::NonLocal) => Self::can_reduce_checked(&asset_id, amount), _ => Ok(()), } } @@ -258,9 +258,9 @@ impl< if let Ok((asset_id, amount)) = Matcher::matches_fungibles(what) { match CheckAsset::asset_checking(&asset_id) { // We track this asset's teleports to ensure no more come in than have gone out. - Some(MintLocation::Local) => Self::accrue_checked(asset_id, amount), + Some(MintLocation::Local) => Self::accrue_checked(&asset_id, amount), // We track this asset's teleports to ensure no more go out than have come in. - Some(MintLocation::NonLocal) => Self::reduce_checked(asset_id, amount), + Some(MintLocation::NonLocal) => Self::reduce_checked(&asset_id, amount), _ => (), } } @@ -276,7 +276,7 @@ impl< let (asset_id, amount) = Matcher::matches_fungibles(what)?; let who = AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; - Assets::mint_into(asset_id, &who, amount) + Assets::mint_into(&asset_id, &who, amount) .map_err(|e| XcmError::FailedToTransactAsset(e.into()))?; Ok(()) } @@ -295,7 +295,7 @@ impl< let (asset_id, amount) = Matcher::matches_fungibles(what)?; let who = AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; - Assets::burn_from(asset_id, &who, amount, Exact, Polite) + Assets::burn_from(&asset_id, &who, amount, Exact, Polite) .map_err(|e| XcmError::FailedToTransactAsset(e.into()))?; Ok(what.clone().into()) } diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs b/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs index 062faee2abd9..2937b69857db 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs @@ -55,7 +55,7 @@ fn pay_over_xcm_works() { new_test_ext().execute_with(|| { // Check starting balance - assert_eq!(mock::Assets::balance(0, &recipient), 0); + assert_eq!(mock::Assets::balance(&0, &recipient), 0); assert_ok!(PayOverXcm::< InteriorAccount, @@ -104,7 +104,7 @@ fn pay_over_xcm_works() { Weight::MAX, Weight::zero(), ); - assert_eq!(mock::Assets::balance(0, &recipient), amount); + assert_eq!(mock::Assets::balance(&0, &recipient), amount); }); } @@ -123,7 +123,7 @@ fn pay_over_xcm_governance_body() { new_test_ext().execute_with(|| { // Check starting balance - assert_eq!(mock::Assets::balance(relay_asset_index, &recipient), 0); + assert_eq!(mock::Assets::balance(&relay_asset_index, &recipient), 0); assert_ok!(PayOverXcm::< InteriorBody, @@ -171,6 +171,6 @@ fn pay_over_xcm_governance_body() { Weight::MAX, Weight::zero(), ); - assert_eq!(mock::Assets::balance(relay_asset_index, &recipient), amount); + assert_eq!(mock::Assets::balance(&relay_asset_index, &recipient), amount); }); } diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index 6a2945c6a9b9..2d9a5c9f4c99 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -128,7 +128,7 @@ fn salary_pay_over_xcm_works() { set_rank(recipient.clone(), 1); // Check starting balance - assert_eq!(mock::Assets::balance(AssetIdGeneralIndex::get(), &recipient.clone()), 0); + assert_eq!(mock::Assets::balance(&AssetIdGeneralIndex::get(), &recipient.clone()), 0); // Use salary pallet to call `PayOverXcm::pay` assert_ok!(Salary::init(RuntimeOrigin::signed(recipient.clone()))); @@ -174,7 +174,7 @@ fn salary_pay_over_xcm_works() { // Recipient receives the payment assert_eq!( - mock::Assets::balance(AssetIdGeneralIndex::get(), &recipient), + mock::Assets::balance(&AssetIdGeneralIndex::get(), &recipient), FixedSalaryAmount::get() ); }); diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 18b0d0c31a4d..f13b816c9fae 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2968,15 +2968,15 @@ impl_runtime_apis! { NativeOrWithId > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: NativeOrWithId, asset2: NativeOrWithId, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: &NativeOrWithId, asset2: &NativeOrWithId, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: NativeOrWithId, asset2: NativeOrWithId, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: &NativeOrWithId, asset2: &NativeOrWithId, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: NativeOrWithId, asset2: NativeOrWithId) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: &NativeOrWithId, asset2: &NativeOrWithId) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } diff --git a/substrate/frame/asset-conversion/ops/src/lib.rs b/substrate/frame/asset-conversion/ops/src/lib.rs index 6cc7bfa2e996..6fffe78c4b0c 100644 --- a/substrate/frame/asset-conversion/ops/src/lib.rs +++ b/substrate/frame/asset-conversion/ops/src/lib.rs @@ -163,9 +163,9 @@ pub mod pallet { let (asset1, asset2) = pool_id.clone(); // Assets that must be transferred to the new account id. - let balance1 = T::Assets::total_balance(asset1.clone(), &prior_account); - let balance2 = T::Assets::total_balance(asset2.clone(), &prior_account); - let lp_balance = T::PoolAssets::total_balance(info.lp_token.clone(), &prior_account); + let balance1 = T::Assets::total_balance(&asset1, &prior_account); + let balance2 = T::Assets::total_balance(&asset2, &prior_account); + let lp_balance = T::PoolAssets::total_balance(&info.lp_token, &prior_account); ensure!(!balance1.is_zero(), Error::::ZeroBalance); ensure!(!balance2.is_zero(), Error::::ZeroBalance); @@ -206,7 +206,7 @@ pub mod pallet { ensure!( balance1 == T::Assets::transfer( - asset1.clone(), + &asset1, &prior_account, &new_account, balance1, @@ -218,7 +218,7 @@ pub mod pallet { ensure!( balance2 == T::Assets::transfer( - asset2.clone(), + &asset2, &prior_account, &new_account, balance2, @@ -230,7 +230,7 @@ pub mod pallet { ensure!( lp_balance == T::PoolAssets::transfer( - info.lp_token.clone(), + &info.lp_token, &prior_account, &new_account, lp_balance, diff --git a/substrate/frame/asset-conversion/ops/src/tests.rs b/substrate/frame/asset-conversion/ops/src/tests.rs index 84bbe6336747..a72a763b7125 100644 --- a/substrate/frame/asset-conversion/ops/src/tests.rs +++ b/substrate/frame/asset-conversion/ops/src/tests.rs @@ -63,14 +63,14 @@ fn migrate_pool_account_id_with_native() { )); // assert user's balance. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000 + ed); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000 + ed); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // record total issuances before migration. - let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone()); - let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone()); - let total_issuance_lp_token = PoolAssets::total_issuance(lp_token); + let total_issuance_token1 = NativeAndAssets::total_issuance(&token_1); + let total_issuance_token2 = NativeAndAssets::total_issuance(&token_2); + let total_issuance_lp_token = PoolAssets::total_issuance(&lp_token); let pool_account = PoolLocator::address(&pool_id).unwrap(); let (prior_pool_account, new_pool_account) = @@ -78,9 +78,9 @@ fn migrate_pool_account_id_with_native() { assert_eq!(pool_account, prior_pool_account); // assert pool's balances before migration. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 100); // migrate. assert_ok!(AssetConversionOps::migrate_to_new_account( @@ -90,24 +90,24 @@ fn migrate_pool_account_id_with_native() { )); // assert user's balance has not changed. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000 + ed); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000 + ed); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // assert pool's balance on new account id is same as on prior account id. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &new_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &new_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &new_pool_account), 100); // assert pool's balance on prior account id is zero. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 0); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 0); // assert total issuance has not changed. - assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1)); - assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2)); - assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token)); + assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(&token_1)); + assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(&token_2)); + assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(&lp_token)); }); } @@ -147,14 +147,14 @@ fn migrate_pool_account_id_with_insufficient_assets() { )); // assert user's balance. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // record total issuances before migration. - let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone()); - let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone()); - let total_issuance_lp_token = PoolAssets::total_issuance(lp_token); + let total_issuance_token1 = NativeAndAssets::total_issuance(&token_1); + let total_issuance_token2 = NativeAndAssets::total_issuance(&token_2); + let total_issuance_lp_token = PoolAssets::total_issuance(&lp_token); let pool_account = PoolLocator::address(&pool_id).unwrap(); let (prior_pool_account, new_pool_account) = @@ -162,9 +162,9 @@ fn migrate_pool_account_id_with_insufficient_assets() { assert_eq!(pool_account, prior_pool_account); // assert pool's balances before migration. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 100); // migrate. assert_ok!(AssetConversionOps::migrate_to_new_account( @@ -174,24 +174,24 @@ fn migrate_pool_account_id_with_insufficient_assets() { )); // assert user's balance has not changed. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // assert pool's balance on new account id is same as on prior account id. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &new_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &new_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &new_pool_account), 100); // assert pool's balance on prior account id is zero. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 0); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 0); // assert total issuance has not changed. - assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1)); - assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2)); - assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token)); + assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(&token_1)); + assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(&token_2)); + assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(&lp_token)); }); } @@ -231,14 +231,14 @@ fn migrate_pool_account_id_with_sufficient_assets() { )); // assert user's balance. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // record total issuances before migration. - let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone()); - let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone()); - let total_issuance_lp_token = PoolAssets::total_issuance(lp_token); + let total_issuance_token1 = NativeAndAssets::total_issuance(&token_1); + let total_issuance_token2 = NativeAndAssets::total_issuance(&token_2); + let total_issuance_lp_token = PoolAssets::total_issuance(&lp_token); let pool_account = PoolLocator::address(&pool_id).unwrap(); let (prior_pool_account, new_pool_account) = @@ -246,9 +246,9 @@ fn migrate_pool_account_id_with_sufficient_assets() { assert_eq!(pool_account, prior_pool_account); // assert pool's balances before migration. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 100); // migrate. assert_ok!(AssetConversionOps::migrate_to_new_account( @@ -258,24 +258,24 @@ fn migrate_pool_account_id_with_sufficient_assets() { )); // assert user's balance has not changed. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10); - assert_eq!(PoolAssets::balance(lp_token, &user), 216); + assert_eq!(NativeAndAssets::balance(&token_1, &user), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &user), 1000 - 10); + assert_eq!(PoolAssets::balance(&lp_token, &user), 216); // assert pool's balance on new account id is same as on prior account id. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10); - assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100); + assert_eq!(NativeAndAssets::balance(&token_1, &new_pool_account), 10000); + assert_eq!(NativeAndAssets::balance(&token_2, &new_pool_account), 10); + assert_eq!(PoolAssets::balance(&lp_token, &new_pool_account), 100); // assert pool's balance on prior account id is zero. - assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0); - assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0); - assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_1, &prior_pool_account), 0); + assert_eq!(NativeAndAssets::balance(&token_2, &prior_pool_account), 0); + assert_eq!(PoolAssets::balance(&lp_token, &prior_pool_account), 0); // assert total issuance has not changed. - assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1)); - assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2)); - assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token)); + assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(&token_1)); + assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(&token_2)); + assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(&lp_token)); }); } diff --git a/substrate/frame/asset-conversion/src/lib.rs b/substrate/frame/asset-conversion/src/lib.rs index bb6e70a7fe93..81f0a932d94a 100644 --- a/substrate/frame/asset-conversion/src/lib.rs +++ b/substrate/frame/asset-conversion/src/lib.rs @@ -460,8 +460,8 @@ pub mod pallet { let pool_account = T::PoolLocator::address(&pool_id).map_err(|_| Error::::InvalidAssetPair)?; - let reserve1 = Self::get_balance(&pool_account, *asset1.clone()); - let reserve2 = Self::get_balance(&pool_account, *asset2.clone()); + let reserve1 = Self::get_balance(&pool_account, &asset1); + let reserve2 = Self::get_balance(&pool_account, &asset2); let amount1: T::Balance; let amount2: T::Balance; @@ -494,24 +494,24 @@ pub mod pallet { } ensure!( - amount1.saturating_add(reserve1) >= T::Assets::minimum_balance(*asset1.clone()), + amount1.saturating_add(reserve1) >= T::Assets::minimum_balance(&asset1), Error::::AmountOneLessThanMinimal ); ensure!( - amount2.saturating_add(reserve2) >= T::Assets::minimum_balance(*asset2.clone()), + amount2.saturating_add(reserve2) >= T::Assets::minimum_balance(&asset2), Error::::AmountTwoLessThanMinimal ); - T::Assets::transfer(*asset1, &sender, &pool_account, amount1, Preserve)?; - T::Assets::transfer(*asset2, &sender, &pool_account, amount2, Preserve)?; + T::Assets::transfer(&asset1, &sender, &pool_account, amount1, Preserve)?; + T::Assets::transfer(&asset2, &sender, &pool_account, amount2, Preserve)?; - let total_supply = T::PoolAssets::total_issuance(pool.lp_token.clone()); + let total_supply = T::PoolAssets::total_issuance(&pool.lp_token); let lp_token_amount: T::Balance; if total_supply.is_zero() { lp_token_amount = Self::calc_lp_amount_for_zero_supply(&amount1, &amount2)?; T::PoolAssets::mint_into( - pool.lp_token.clone(), + &pool.lp_token, &pool_account, T::MintMinLiquidity::get(), )?; @@ -526,7 +526,7 @@ pub mod pallet { Error::::InsufficientLiquidityMinted ); - T::PoolAssets::mint_into(pool.lp_token.clone(), &mint_to, lp_token_amount)?; + T::PoolAssets::mint_into(&pool.lp_token, &mint_to, lp_token_amount)?; Self::deposit_event(Event::LiquidityAdded { who: sender, @@ -566,10 +566,10 @@ pub mod pallet { let pool_account = T::PoolLocator::address(&pool_id).map_err(|_| Error::::InvalidAssetPair)?; - let reserve1 = Self::get_balance(&pool_account, *asset1.clone()); - let reserve2 = Self::get_balance(&pool_account, *asset2.clone()); + let reserve1 = Self::get_balance(&pool_account, &asset1); + let reserve2 = Self::get_balance(&pool_account, &asset2); - let total_supply = T::PoolAssets::total_issuance(pool.lp_token.clone()); + let total_supply = T::PoolAssets::total_issuance(&pool.lp_token); let withdrawal_fee_amount = T::LiquidityWithdrawalFee::get() * lp_token_burn; let lp_redeem_amount = lp_token_burn.saturating_sub(withdrawal_fee_amount); @@ -587,19 +587,19 @@ pub mod pallet { let reserve1_left = reserve1.saturating_sub(amount1); let reserve2_left = reserve2.saturating_sub(amount2); ensure!( - reserve1_left >= T::Assets::minimum_balance(*asset1.clone()), + reserve1_left >= T::Assets::minimum_balance(&asset1), Error::::ReserveLeftLessThanMinimal ); ensure!( - reserve2_left >= T::Assets::minimum_balance(*asset2.clone()), + reserve2_left >= T::Assets::minimum_balance(&asset2), Error::::ReserveLeftLessThanMinimal ); // burn the provided lp token amount that includes the fee - T::PoolAssets::burn_from(pool.lp_token.clone(), &sender, lp_token_burn, Exact, Polite)?; + T::PoolAssets::burn_from(&pool.lp_token, &sender, lp_token_burn, Exact, Polite)?; - T::Assets::transfer(*asset1, &pool_account, &withdraw_to, amount1, Expendable)?; - T::Assets::transfer(*asset2, &pool_account, &withdraw_to, amount2, Expendable)?; + T::Assets::transfer(&asset1, &pool_account, &withdraw_to, amount1, Expendable)?; + T::Assets::transfer(&asset2, &pool_account, &withdraw_to, amount2, Expendable)?; Self::deposit_event(Event::LiquidityRemoved { who: sender, @@ -957,7 +957,7 @@ pub mod pallet { .map_err(|_| Error::::InvalidAssetPair)?; T::Assets::transfer( - asset2.clone(), + asset2, &pool_from, &pool_to, *amount_out, @@ -1007,7 +1007,7 @@ pub mod pallet { if preservation == Preserve { // TODO drop the ensure! when this issue addressed // https://github.com/paritytech/polkadot-sdk/issues/1698 - let free = T::Assets::reducible_balance(asset.clone(), who, preservation, Polite); + let free = T::Assets::reducible_balance(&asset, who, preservation, Polite); ensure!(free >= value, TokenError::NotExpendable); } T::Assets::withdraw(asset, who, value, Exact, preservation, Polite) @@ -1015,17 +1015,17 @@ pub mod pallet { /// Get the `owner`'s balance of `asset`, which could be the chain's native asset or another /// fungible. Returns a value in the form of an `Balance`. - fn get_balance(owner: &T::AccountId, asset: T::AssetKind) -> T::Balance { + fn get_balance(owner: &T::AccountId, asset: &T::AssetKind) -> T::Balance { T::Assets::reducible_balance(asset, owner, Expendable, Polite) } /// Returns the balance of each asset in the pool. /// The tuple result is in the order requested (not necessarily the same as pool order). pub fn get_reserves( - asset1: T::AssetKind, - asset2: T::AssetKind, + asset1: &T::AssetKind, + asset2: &T::AssetKind, ) -> Result<(T::Balance, T::Balance), Error> { - let pool_account = T::PoolLocator::pool_address(&asset1, &asset2) + let pool_account = T::PoolLocator::pool_address(asset1, asset2) .map_err(|_| Error::::InvalidAssetPair)?; let balance1 = Self::get_balance(&pool_account, asset1); @@ -1055,7 +1055,7 @@ pub mod pallet { break }, }; - let (reserve_in, reserve_out) = Self::get_reserves(asset1.clone(), asset2.clone())?; + let (reserve_in, reserve_out) = Self::get_reserves(asset1, &asset2)?; balance_path.push((asset2, amount_in)); amount_in = Self::get_amount_in(&amount_in, &reserve_in, &reserve_out)?; } @@ -1081,7 +1081,7 @@ pub mod pallet { break }, }; - let (reserve_in, reserve_out) = Self::get_reserves(asset1.clone(), asset2.clone())?; + let (reserve_in, reserve_out) = Self::get_reserves(&asset1, asset2)?; balance_path.push((asset1, amount_out)); amount_out = Self::get_amount_out(&amount_out, &reserve_in, &reserve_out)?; } @@ -1090,12 +1090,12 @@ pub mod pallet { /// Used by the RPC service to provide current prices. pub fn quote_price_exact_tokens_for_tokens( - asset1: T::AssetKind, - asset2: T::AssetKind, + asset1: &T::AssetKind, + asset2: &T::AssetKind, amount: T::Balance, include_fee: bool, ) -> Option { - let pool_account = T::PoolLocator::pool_address(&asset1, &asset2).ok()?; + let pool_account = T::PoolLocator::pool_address(asset1, asset2).ok()?; let balance1 = Self::get_balance(&pool_account, asset1); let balance2 = Self::get_balance(&pool_account, asset2); @@ -1112,12 +1112,12 @@ pub mod pallet { /// Used by the RPC service to provide current prices. pub fn quote_price_tokens_for_exact_tokens( - asset1: T::AssetKind, - asset2: T::AssetKind, + asset1: &T::AssetKind, + asset2: &T::AssetKind, amount: T::Balance, include_fee: bool, ) -> Option { - let pool_account = T::PoolLocator::pool_address(&asset1, &asset2).ok()?; + let pool_account = T::PoolLocator::pool_address(asset1, asset2).ok()?; let balance1 = Self::get_balance(&pool_account, asset1); let balance2 = Self::get_balance(&pool_account, asset2); @@ -1294,8 +1294,8 @@ sp_api::decl_runtime_apis! { /// Note that the price may have changed by the time the transaction is executed. /// (Use `amount_in_max` to control slippage.) fn quote_price_tokens_for_exact_tokens( - asset1: AssetId, - asset2: AssetId, + asset1: &AssetId, + asset2: &AssetId, amount: Balance, include_fee: bool, ) -> Option; @@ -1305,14 +1305,14 @@ sp_api::decl_runtime_apis! { /// Note that the price may have changed by the time the transaction is executed. /// (Use `amount_out_min` to control slippage.) fn quote_price_exact_tokens_for_tokens( - asset1: AssetId, - asset2: AssetId, + asset1: &AssetId, + asset2: &AssetId, amount: Balance, include_fee: bool, ) -> Option; /// Returns the size of the liquidity pool for the given asset pair. - fn get_reserves(asset1: AssetId, asset2: AssetId) -> Option<(Balance, Balance)>; + fn get_reserves(asset1: &AssetId, asset2: &AssetId) -> Option<(Balance, Balance)>; } } diff --git a/substrate/frame/asset-conversion/src/tests.rs b/substrate/frame/asset-conversion/src/tests.rs index e69d14fcb3c4..e4cd5aa2a1d2 100644 --- a/substrate/frame/asset-conversion/src/tests.rs +++ b/substrate/frame/asset-conversion/src/tests.rs @@ -81,15 +81,15 @@ fn create_tokens_with_ed(owner: u128, tokens: Vec>, ed: u128 } fn balance(owner: u128, token_id: NativeOrWithId) -> u128 { - <::Assets>::balance(token_id, &owner) + <::Assets>::balance(&token_id, &owner) } fn pool_balance(owner: u128, token_id: u32) -> u128 { - <::PoolAssets>::balance(token_id, owner) + <::PoolAssets>::balance(&token_id, owner) } fn get_native_ed() -> u128 { - <::Assets>::minimum_balance(NativeOrWithId::Native) + <::Assets>::minimum_balance(&NativeOrWithId::Native) } macro_rules! bvec { @@ -535,7 +535,7 @@ fn can_remove_liquidity() { )); let ed_token_1 = >::minimum_balance(); - let ed_token_2 = >::minimum_balance(2); + let ed_token_2 = >::minimum_balance(&2); assert_ok!(Balances::force_set_balance( RuntimeOrigin::root(), user, @@ -673,8 +673,8 @@ fn can_quote_price() { assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 3000, false, ), @@ -683,8 +683,8 @@ fn can_quote_price() { // including fee so should get less out... assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 3000, true, ), @@ -694,8 +694,8 @@ fn can_quote_price() { // (if the above accidentally exchanged then it would not give same quote as before) assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 3000, false, ), @@ -704,8 +704,8 @@ fn can_quote_price() { // including fee so should get less out... assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 3000, true, ), @@ -715,8 +715,8 @@ fn can_quote_price() { // Check inverse: assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, 60, false, ), @@ -725,8 +725,8 @@ fn can_quote_price() { // including fee so should get less out... assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, 60, true, ), @@ -738,8 +738,8 @@ fn can_quote_price() { // assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 60, false, ), @@ -748,8 +748,8 @@ fn can_quote_price() { // including fee so should need to put more in... assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 60, true, ), @@ -759,8 +759,8 @@ fn can_quote_price() { // (if the above accidentally exchanged then it would not give same quote as before) assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 60, false, ), @@ -769,8 +769,8 @@ fn can_quote_price() { // including fee so should need to put more in... assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), 60, true, ), @@ -780,8 +780,8 @@ fn can_quote_price() { // Check inverse: assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, 3000, false, ), @@ -790,8 +790,8 @@ fn can_quote_price() { // including fee so should need to put more in... assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, 3000, true, ), @@ -805,14 +805,14 @@ fn can_quote_price() { assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, amount_in, false, ) .and_then(|amount| AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), amount, false, )), @@ -820,14 +820,14 @@ fn can_quote_price() { ); assert_eq!( AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), amount_in, false, ) .and_then(|amount| AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, amount, false, )), @@ -836,14 +836,14 @@ fn can_quote_price() { assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, amount_in, false, ) .and_then(|amount| AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), amount, false, )), @@ -851,14 +851,14 @@ fn can_quote_price() { ); assert_eq!( AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(2), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(2), amount_in, false, ) .and_then(|amount| AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(2), - NativeOrWithId::Native, + &NativeOrWithId::WithId(2), + &NativeOrWithId::Native, amount, false, )), @@ -899,12 +899,7 @@ fn quote_price_exact_tokens_for_tokens_matches_execution() { let amount = 1; let quoted_price = 49; assert_eq!( - AssetConversion::quote_price_exact_tokens_for_tokens( - token_2.clone(), - token_1.clone(), - amount, - true, - ), + AssetConversion::quote_price_exact_tokens_for_tokens(&token_2, &token_1, amount, true,), Some(quoted_price) ); @@ -956,12 +951,7 @@ fn quote_price_tokens_for_exact_tokens_matches_execution() { let amount = 49; let quoted_price = 1; assert_eq!( - AssetConversion::quote_price_tokens_for_exact_tokens( - token_2.clone(), - token_1.clone(), - amount, - true, - ), + AssetConversion::quote_price_tokens_for_exact_tokens(&token_2, &token_1, amount, true,), Some(quoted_price) ); @@ -2130,9 +2120,9 @@ fn swap_transactional() { ::PoolLocator::address(&(token_1.clone(), token_3.clone())).unwrap(); assert_eq!(Balances::balance(&pool_1), liquidity1); - assert_eq!(Assets::balance(2, pool_1), liquidity2); + assert_eq!(Assets::balance(&2, pool_1), liquidity2); assert_eq!(Balances::balance(&pool_2), liquidity1); - assert_eq!(Assets::balance(3, pool_2), liquidity2); + assert_eq!(Assets::balance(&3, pool_2), liquidity2); // the amount that would cause a transfer from the last pool in the path to fail let expected_out = liquidity2 - asset_ed + 1; @@ -2146,8 +2136,8 @@ fn swap_transactional() { .unwrap(); // swap credit with `swap_tokens_for_exact_tokens` transactional - let credit_in = NativeAndAssets::issue(token_2.clone(), amount_in); - let credit_in_err_expected = NativeAndAssets::issue(token_2.clone(), amount_in); + let credit_in = NativeAndAssets::issue(&token_2, amount_in); + let credit_in_err_expected = NativeAndAssets::issue(&token_2, amount_in); // avoiding drop of any credit, to assert any storage mutation from an actual call. let error; assert_storage_noop!( @@ -2161,8 +2151,8 @@ fn swap_transactional() { assert_eq!(error, (credit_in_err_expected, TokenError::NotExpendable.into())); // swap credit with `swap_exact_tokens_for_tokens` transactional - let credit_in = NativeAndAssets::issue(token_2.clone(), amount_in); - let credit_in_err_expected = NativeAndAssets::issue(token_2.clone(), amount_in); + let credit_in = NativeAndAssets::issue(&token_2, amount_in); + let credit_in_err_expected = NativeAndAssets::issue(&token_2, amount_in); // avoiding drop of any credit, to assert any storage mutation from an actual call. let error; assert_storage_noop!( @@ -2202,9 +2192,9 @@ fn swap_transactional() { ); assert_eq!(Balances::balance(&pool_1), liquidity1); - assert_eq!(Assets::balance(2, pool_1), liquidity2); + assert_eq!(Assets::balance(&2, pool_1), liquidity2); assert_eq!(Balances::balance(&pool_2), liquidity1); - assert_eq!(Assets::balance(3, pool_2), liquidity2); + assert_eq!(Assets::balance(&3, pool_2), liquidity2); }) } @@ -2240,15 +2230,14 @@ fn swap_credit_returns_change() { user, )); - let expected_change = NativeAndAssets::issue(token_1.clone(), 100); - let expected_credit_out = NativeAndAssets::issue(token_2.clone(), 20); + let expected_change = NativeAndAssets::issue(&token_1, 100); + let expected_credit_out = NativeAndAssets::issue(&token_2, 20); let amount_in_max = AssetConversion::get_amount_in(&expected_credit_out.peek(), &liquidity1, &liquidity2) .unwrap(); - let credit_in = - NativeAndAssets::issue(token_1.clone(), amount_in_max + expected_change.peek()); + let credit_in = NativeAndAssets::issue(&token_1, amount_in_max + expected_change.peek()); assert_ok!( >::swap_tokens_for_exact_tokens( vec![token_1.clone(), token_2.clone()], @@ -2301,8 +2290,8 @@ fn swap_credit_insufficient_amount_bounds() { let amount_in = AssetConversion::get_amount_in(&(amount_out_min - 1), &liquidity2, &liquidity1) .unwrap(); - let credit_in = NativeAndAssets::issue(token_1.clone(), amount_in); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), amount_in); + let credit_in = NativeAndAssets::issue(&token_1, amount_in); + let expected_credit_in = NativeAndAssets::issue(&token_1, amount_in); let error = >::swap_exact_tokens_for_tokens( vec![token_1.clone(), token_2.clone()], credit_in, @@ -2318,8 +2307,8 @@ fn swap_credit_insufficient_amount_bounds() { let amount_out = 20; let amount_in_max = AssetConversion::get_amount_in(&(amount_out - 1), &liquidity2, &liquidity1).unwrap(); - let credit_in = NativeAndAssets::issue(token_1.clone(), amount_in_max); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), amount_in_max); + let credit_in = NativeAndAssets::issue(&token_1, amount_in_max); + let expected_credit_in = NativeAndAssets::issue(&token_1, amount_in_max); let error = >::swap_tokens_for_exact_tokens( vec![token_1.clone(), token_2.clone()], credit_in, @@ -2392,8 +2381,8 @@ fn swap_credit_zero_amount() { assert_eq!(error, (expected_credit_in, Error::::ZeroAmount.into())); // swap with zero amount_out_min fails for `swap_exact_tokens_for_tokens` - let credit_in = NativeAndAssets::issue(token_1.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_1, 10); + let expected_credit_in = NativeAndAssets::issue(&token_1, 10); let error = >::swap_exact_tokens_for_tokens( vec![token_1.clone(), token_2.clone()], credit_in, @@ -2403,8 +2392,8 @@ fn swap_credit_zero_amount() { assert_eq!(error, (expected_credit_in, Error::::ZeroAmount.into())); // swap with zero amount_out fails with `swap_tokens_for_exact_tokens` fails - let credit_in = NativeAndAssets::issue(token_1.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_1, 10); + let expected_credit_in = NativeAndAssets::issue(&token_1, 10); let error = >::swap_tokens_for_exact_tokens( vec![token_1.clone(), token_2.clone()], credit_in, @@ -2452,8 +2441,8 @@ fn swap_credit_invalid_path() { )); // swap with credit_in.asset different from path[0] asset fails - let credit_in = NativeAndAssets::issue(token_1.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_1, 10); + let expected_credit_in = NativeAndAssets::issue(&token_1, 10); let error = >::swap_exact_tokens_for_tokens( vec![token_2.clone(), token_1.clone()], credit_in, @@ -2463,8 +2452,8 @@ fn swap_credit_invalid_path() { assert_eq!(error, (expected_credit_in, Error::::InvalidPath.into())); // swap with credit_in.asset different from path[0] asset fails - let credit_in = NativeAndAssets::issue(token_2.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_2.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_2, 10); + let expected_credit_in = NativeAndAssets::issue(&token_2, 10); let error = >::swap_tokens_for_exact_tokens( vec![token_1.clone(), token_2.clone()], credit_in, @@ -2474,8 +2463,8 @@ fn swap_credit_invalid_path() { assert_eq!(error, (expected_credit_in, Error::::InvalidPath.into())); // swap with path.len < 2 fails - let credit_in = NativeAndAssets::issue(token_1.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_1.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_1, 10); + let expected_credit_in = NativeAndAssets::issue(&token_1, 10); let error = >::swap_exact_tokens_for_tokens( vec![token_2.clone()], credit_in, @@ -2485,8 +2474,8 @@ fn swap_credit_invalid_path() { assert_eq!(error, (expected_credit_in, Error::::InvalidPath.into())); // swap with path.len < 2 fails - let credit_in = NativeAndAssets::issue(token_2.clone(), 10); - let expected_credit_in = NativeAndAssets::issue(token_2.clone(), 10); + let credit_in = NativeAndAssets::issue(&token_2, 10); + let expected_credit_in = NativeAndAssets::issue(&token_2, 10); let error = >::swap_tokens_for_exact_tokens(vec![], credit_in, 10) .unwrap_err(); diff --git a/substrate/frame/assets/src/extra_mutator.rs b/substrate/frame/assets/src/extra_mutator.rs index e2f7742c694a..925e8e0c5fdf 100644 --- a/substrate/frame/assets/src/extra_mutator.rs +++ b/substrate/frame/assets/src/extra_mutator.rs @@ -59,12 +59,12 @@ impl, I: 'static> core::ops::DerefMut for ExtraMutator { impl, I: 'static> ExtraMutator { pub(super) fn maybe_new( - id: T::AssetId, + id: &T::AssetId, who: impl core::borrow::Borrow, ) -> Option> { - if let Some(a) = Account::::get(&id, who.borrow()) { + if let Some(a) = Account::::get(id, who.borrow()) { Some(ExtraMutator:: { - id, + id: id.clone(), who: who.borrow().clone(), original: a.extra, pending: None, diff --git a/substrate/frame/assets/src/functions.rs b/substrate/frame/assets/src/functions.rs index 9309d0101175..2160a5e6e966 100644 --- a/substrate/frame/assets/src/functions.rs +++ b/substrate/frame/assets/src/functions.rs @@ -34,32 +34,32 @@ impl, I: 'static> Pallet { /// Return the extra "sid-car" data for `id`/`who`, or `None` if the account doesn't exist. pub fn adjust_extra( - id: T::AssetId, + id: &T::AssetId, who: impl sp_std::borrow::Borrow, ) -> Option> { ExtraMutator::maybe_new(id, who) } /// Get the asset `id` balance of `who`, or zero if the asset-account doesn't exist. - pub fn balance(id: T::AssetId, who: impl sp_std::borrow::Borrow) -> T::Balance { + pub fn balance(id: &T::AssetId, who: impl sp_std::borrow::Borrow) -> T::Balance { Self::maybe_balance(id, who).unwrap_or_default() } /// Get the asset `id` balance of `who` if the asset-account exists. pub fn maybe_balance( - id: T::AssetId, + id: &T::AssetId, who: impl sp_std::borrow::Borrow, ) -> Option { Account::::get(id, who.borrow()).map(|a| a.balance) } /// Get the total supply of an asset `id`. - pub fn total_supply(id: T::AssetId) -> T::Balance { + pub fn total_supply(id: &T::AssetId) -> T::Balance { Self::maybe_total_supply(id).unwrap_or_default() } /// Get the total supply of an asset `id` if the asset exists. - pub fn maybe_total_supply(id: T::AssetId) -> Option { + pub fn maybe_total_supply(id: &T::AssetId) -> Option { Asset::::get(id).map(|x| x.supply) } @@ -123,12 +123,12 @@ impl, I: 'static> Pallet { /// - `increase_supply`: Will the supply of the asset be increased by `amount` at the same time /// as crediting the `account`. pub(super) fn can_increase( - id: T::AssetId, + id: &T::AssetId, who: &T::AccountId, amount: T::Balance, increase_supply: bool, ) -> DepositConsequence { - let details = match Asset::::get(&id) { + let details = match Asset::::get(id) { Some(details) => details, None => return DepositConsequence::UnknownAsset, }; @@ -159,13 +159,13 @@ impl, I: 'static> Pallet { /// Return the consequence of a withdraw. pub(super) fn can_decrease( - id: T::AssetId, + id: &T::AssetId, who: &T::AccountId, amount: T::Balance, keep_alive: bool, ) -> WithdrawConsequence { use WithdrawConsequence::*; - let details = match Asset::::get(&id) { + let details = match Asset::::get(id) { Some(details) => details, None => return UnknownAsset, }; @@ -178,7 +178,7 @@ impl, I: 'static> Pallet { if amount.is_zero() { return Success } - let account = match Account::::get(&id, who) { + let account = match Account::::get(id, who) { Some(a) => a, None => return BalanceLow, }; @@ -186,7 +186,7 @@ impl, I: 'static> Pallet { return Frozen } if let Some(rest) = account.balance.checked_sub(&amount) { - if let Some(frozen) = T::Freezer::frozen_balance(id.clone(), who) { + if let Some(frozen) = T::Freezer::frozen_balance(id, who) { match frozen.checked_add(&details.min_balance) { Some(required) if rest < required => return Frozen, None => return Overflow, @@ -211,14 +211,14 @@ impl, I: 'static> Pallet { // Maximum `amount` that can be passed into `can_withdraw` to result in a `WithdrawConsequence` // of `Success`. pub(super) fn reducible_balance( - id: T::AssetId, + id: &T::AssetId, who: &T::AccountId, keep_alive: bool, ) -> Result { - let details = Asset::::get(&id).ok_or(Error::::Unknown)?; + let details = Asset::::get(id).ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); - let account = Account::::get(&id, who).ok_or(Error::::NoAccount)?; + let account = Account::::get(id, who).ok_or(Error::::NoAccount)?; ensure!(!account.status.is_frozen(), Error::::Frozen); let amount = if let Some(frozen) = T::Freezer::frozen_balance(id, who) { @@ -254,12 +254,12 @@ impl, I: 'static> Pallet { /// /// If no valid debit can be made then return an `Err`. pub(super) fn prep_debit( - id: T::AssetId, + id: &T::AssetId, target: &T::AccountId, amount: T::Balance, f: DebitFlags, ) -> Result { - let actual = Self::reducible_balance(id.clone(), target, f.keep_alive)?.min(amount); + let actual = Self::reducible_balance(id, target, f.keep_alive)?.min(amount); ensure!(f.best_effort || actual >= amount, Error::::BalanceLow); let conseq = Self::can_decrease(id, target, actual, f.keep_alive); @@ -290,7 +290,7 @@ impl, I: 'static> Pallet { /// /// If no valid credit can be made then return an `Err`. pub(super) fn prep_credit( - id: T::AssetId, + id: &T::AssetId, dest: &T::AccountId, amount: T::Balance, debit: T::Balance, @@ -341,12 +341,16 @@ impl, I: 'static> Pallet { /// Returns a deposit or a consumer reference, destroying an asset-account. /// Non-zero balance accounts refunded and destroyed only if `allow_burn` is true. - pub(super) fn do_refund(id: T::AssetId, who: T::AccountId, allow_burn: bool) -> DispatchResult { + pub(super) fn do_refund( + id: &T::AssetId, + who: T::AccountId, + allow_burn: bool, + ) -> DispatchResult { use AssetStatus::*; use ExistenceReason::*; - let mut account = Account::::get(&id, &who).ok_or(Error::::NoDeposit)?; + let mut account = Account::::get(id, &who).ok_or(Error::::NoDeposit)?; ensure!(matches!(account.reason, Consumer | DepositHeld(..)), Error::::NoDeposit); - let mut details = Asset::::get(&id).ok_or(Error::::Unknown)?; + let mut details = Asset::::get(id).ok_or(Error::::Unknown)?; ensure!(matches!(details.status, Live | Frozen), Error::::IncorrectStatus); ensure!(account.balance.is_zero() || allow_burn, Error::::WouldBurn); @@ -355,14 +359,14 @@ impl, I: 'static> Pallet { } if let Remove = Self::dead_account(&who, &mut details, &account.reason, false) { - Account::::remove(&id, &who); + Account::::remove(id, &who); } else { debug_assert!(false, "refund did not result in dead account?!"); // deposit may have been refunded, need to update `Account` Account::::insert(id, &who, account); return Ok(()) } - Asset::::insert(&id, details); + Asset::::insert(id, details); // Executing a hook here is safe, since it is not in a `mutate`. T::Freezer::died(id, &who); Ok(()) @@ -373,14 +377,14 @@ impl, I: 'static> Pallet { /// If the `maybe_check_caller` parameter is specified, it must match the account that provided /// the deposit or must be the admin of the asset. pub(super) fn do_refund_other( - id: T::AssetId, + id: &T::AssetId, who: &T::AccountId, maybe_check_caller: Option, ) -> DispatchResult { - let mut account = Account::::get(&id, &who).ok_or(Error::::NoDeposit)?; + let mut account = Account::::get(id, &who).ok_or(Error::::NoDeposit)?; let (depositor, deposit) = account.reason.take_deposit_from().ok_or(Error::::NoDeposit)?; - let mut details = Asset::::get(&id).ok_or(Error::::Unknown)?; + let mut details = Asset::::get(id).ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); ensure!(!account.status.is_frozen(), Error::::Frozen); if let Some(caller) = maybe_check_caller { @@ -391,14 +395,14 @@ impl, I: 'static> Pallet { T::Currency::unreserve(&depositor, deposit); if let Remove = Self::dead_account(&who, &mut details, &account.reason, false) { - Account::::remove(&id, &who); + Account::::remove(id, &who); } else { debug_assert!(false, "refund did not result in dead account?!"); // deposit may have been refunded, need to update `Account` - Account::::insert(&id, &who, account); + Account::::insert(id, &who, account); return Ok(()) } - Asset::::insert(&id, details); + Asset::::insert(id, details); // Executing a hook here is safe, since it is not in a `mutate`. T::Freezer::died(id, &who); return Ok(()) @@ -415,7 +419,7 @@ impl, I: 'static> Pallet { amount: T::Balance, maybe_check_issuer: Option, ) -> DispatchResult { - Self::increase_balance(id.clone(), beneficiary, amount, |details| -> DispatchResult { + Self::increase_balance(&id, beneficiary, amount, |details| -> DispatchResult { if let Some(check_issuer) = maybe_check_issuer { ensure!(check_issuer == details.issuer, Error::::NoPermission); } @@ -438,7 +442,7 @@ impl, I: 'static> Pallet { /// /// Will return an error or will increase the amount by exactly `amount`. pub(super) fn increase_balance( - id: T::AssetId, + id: &T::AssetId, beneficiary: &T::AccountId, amount: T::Balance, check: impl FnOnce( @@ -449,13 +453,13 @@ impl, I: 'static> Pallet { return Ok(()) } - Self::can_increase(id.clone(), beneficiary, amount, true).into_result()?; - Asset::::try_mutate(&id, |maybe_details| -> DispatchResult { + Self::can_increase(id, beneficiary, amount, true).into_result()?; + Asset::::try_mutate(id, |maybe_details| -> DispatchResult { let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); check(details)?; - Account::::try_mutate(&id, beneficiary, |maybe_account| -> DispatchResult { + Account::::try_mutate(id, beneficiary, |maybe_account| -> DispatchResult { match maybe_account { Some(ref mut account) => { account.balance.saturating_accrue(amount); @@ -499,7 +503,7 @@ impl, I: 'static> Pallet { Error::::IncorrectStatus ); - let actual = Self::decrease_balance(id.clone(), target, amount, f, |actual, details| { + let actual = Self::decrease_balance(&id, target, amount, f, |actual, details| { // Check admin rights. if let Some(check_admin) = maybe_check_admin { ensure!(check_admin == details.admin, Error::::NoPermission); @@ -523,7 +527,7 @@ impl, I: 'static> Pallet { /// Will return an error and do nothing or will decrease the amount and return the amount /// reduced by. pub(super) fn decrease_balance( - id: T::AssetId, + id: &T::AssetId, target: &T::AccountId, amount: T::Balance, f: DebitFlags, @@ -536,17 +540,17 @@ impl, I: 'static> Pallet { return Ok(amount) } - let details = Asset::::get(&id).ok_or(Error::::Unknown)?; + let details = Asset::::get(id).ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); - let actual = Self::prep_debit(id.clone(), target, amount, f)?; + let actual = Self::prep_debit(id, target, amount, f)?; let mut target_died: Option = None; - Asset::::try_mutate(&id, |maybe_details| -> DispatchResult { + Asset::::try_mutate(id, |maybe_details| -> DispatchResult { let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; check(actual, details)?; - Account::::try_mutate(&id, target, |maybe_account| -> DispatchResult { + Account::::try_mutate(id, target, |maybe_account| -> DispatchResult { let mut account = maybe_account.take().ok_or(Error::::NoAccount)?; debug_assert!(account.balance >= actual, "checked in prep; qed"); @@ -590,9 +594,9 @@ impl, I: 'static> Pallet { f: TransferFlags, ) -> Result { let (balance, died) = - Self::transfer_and_die(id.clone(), source, dest, amount, maybe_need_admin, f)?; + Self::transfer_and_die(&id, source, dest, amount, maybe_need_admin, f)?; if let Some(Remove) = died { - T::Freezer::died(id, source); + T::Freezer::died(&id, source); } Ok(balance) } @@ -600,7 +604,7 @@ impl, I: 'static> Pallet { /// Same as `do_transfer` but it does not execute the `FrozenBalance::died` hook and /// instead returns whether and how the `source` account died in this operation. fn transfer_and_die( - id: T::AssetId, + id: &T::AssetId, source: &T::AccountId, dest: &T::AccountId, amount: T::Balance, @@ -611,18 +615,18 @@ impl, I: 'static> Pallet { if amount.is_zero() { return Ok((amount, None)) } - let details = Asset::::get(&id).ok_or(Error::::Unknown)?; + let details = Asset::::get(id).ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); // Figure out the debit and credit, together with side-effects. - let debit = Self::prep_debit(id.clone(), source, amount, f.into())?; - let (credit, maybe_burn) = Self::prep_credit(id.clone(), dest, amount, debit, f.burn_dust)?; + let debit = Self::prep_debit(id, source, amount, f.into())?; + let (credit, maybe_burn) = Self::prep_credit(id, dest, amount, debit, f.burn_dust)?; let mut source_account = - Account::::get(&id, &source).ok_or(Error::::NoAccount)?; + Account::::get(id, &source).ok_or(Error::::NoAccount)?; let mut source_died: Option = None; - Asset::::try_mutate(&id, |maybe_details| -> DispatchResult { + Asset::::try_mutate(id, |maybe_details| -> DispatchResult { let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; // Check admin rights. @@ -647,7 +651,7 @@ impl, I: 'static> Pallet { debug_assert!(source_account.balance >= debit, "checked in prep; qed"); source_account.balance = source_account.balance.saturating_sub(debit); - Account::::try_mutate(&id, &dest, |maybe_account| -> DispatchResult { + Account::::try_mutate(id, &dest, |maybe_account| -> DispatchResult { match maybe_account { Some(ref mut account) => { // Calculate new balance; this will not saturate since it's already checked @@ -676,16 +680,16 @@ impl, I: 'static> Pallet { source_died = Some(Self::dead_account(source, details, &source_account.reason, false)); if let Some(Remove) = source_died { - Account::::remove(&id, &source); + Account::::remove(id, &source); return Ok(()) } } - Account::::insert(&id, &source, &source_account); + Account::::insert(id, &source, &source_account); Ok(()) })?; Self::deposit_event(Event::Transferred { - asset_id: id, + asset_id: id.clone(), from: source.clone(), to: dest.clone(), amount: credit, @@ -789,7 +793,7 @@ impl, I: 'static> Pallet { })?; for who in &dead_accounts { - T::Freezer::died(id.clone(), &who); + T::Freezer::died(&id, &who); } Self::deposit_event(Event::AccountsDestroyed { @@ -930,8 +934,7 @@ impl, I: 'static> Pallet { approved.amount.checked_sub(&amount).ok_or(Error::::Unapproved)?; let f = TransferFlags { keep_alive: false, best_effort: false, burn_dust: false }; - owner_died = - Self::transfer_and_die(id.clone(), owner, destination, amount, None, f)?.1; + owner_died = Self::transfer_and_die(&id, owner, destination, amount, None, f)?.1; if remaining.is_zero() { T::Currency::unreserve(owner, approved.deposit); @@ -950,7 +953,7 @@ impl, I: 'static> Pallet { // Execute hook outside of `mutate`. if let Some(Remove) = owner_died { - T::Freezer::died(id, owner); + T::Freezer::died(&id, owner); } Ok(()) } @@ -1013,9 +1016,7 @@ impl, I: 'static> Pallet { /// Returns all the non-zero balances for all assets of the given `account`. pub fn account_balances(account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { Asset::::iter_keys() - .filter_map(|id| { - Self::maybe_balance(id.clone(), account.clone()).map(|balance| (id, balance)) - }) + .filter_map(|id| Self::maybe_balance(&id, account.clone()).map(|balance| (id, balance))) .collect::>() } diff --git a/substrate/frame/assets/src/impl_fungibles.rs b/substrate/frame/assets/src/impl_fungibles.rs index 30122f6d788f..f9774ce4eebe 100644 --- a/substrate/frame/assets/src/impl_fungibles.rs +++ b/substrate/frame/assets/src/impl_fungibles.rs @@ -33,24 +33,24 @@ impl, I: 'static> fungibles::Inspect<::AccountId type AssetId = T::AssetId; type Balance = T::Balance; - fn total_issuance(asset: Self::AssetId) -> Self::Balance { + fn total_issuance(asset: &Self::AssetId) -> Self::Balance { Asset::::get(asset).map(|x| x.supply).unwrap_or_else(Zero::zero) } - fn minimum_balance(asset: Self::AssetId) -> Self::Balance { + fn minimum_balance(asset: &Self::AssetId) -> Self::Balance { Asset::::get(asset).map(|x| x.min_balance).unwrap_or_else(Zero::zero) } - fn balance(asset: Self::AssetId, who: &::AccountId) -> Self::Balance { + fn balance(asset: &Self::AssetId, who: &::AccountId) -> Self::Balance { Pallet::::balance(asset, who) } - fn total_balance(asset: Self::AssetId, who: &::AccountId) -> Self::Balance { + fn total_balance(asset: &Self::AssetId, who: &::AccountId) -> Self::Balance { Pallet::::balance(asset, who) } fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &::AccountId, preservation: Preservation, _: Fortitude, @@ -60,7 +60,7 @@ impl, I: 'static> fungibles::Inspect<::AccountId } fn can_deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &::AccountId, amount: Self::Balance, provenance: Provenance, @@ -69,43 +69,51 @@ impl, I: 'static> fungibles::Inspect<::AccountId } fn can_withdraw( - asset: Self::AssetId, + asset: &Self::AssetId, who: &::AccountId, amount: Self::Balance, ) -> WithdrawConsequence { Pallet::::can_decrease(asset, who, amount, false) } - fn asset_exists(asset: Self::AssetId) -> bool { + fn asset_exists(asset: &Self::AssetId) -> bool { Asset::::contains_key(asset) } } impl, I: 'static> fungibles::Mutate<::AccountId> for Pallet { fn done_mint_into( - asset_id: Self::AssetId, + asset_id: &Self::AssetId, beneficiary: &::AccountId, amount: Self::Balance, ) { - Self::deposit_event(Event::Issued { asset_id, owner: beneficiary.clone(), amount }) + Self::deposit_event(Event::Issued { + asset_id: asset_id.clone(), + owner: beneficiary.clone(), + amount, + }) } fn done_burn_from( - asset_id: Self::AssetId, + asset_id: &Self::AssetId, target: &::AccountId, balance: Self::Balance, ) { - Self::deposit_event(Event::Burned { asset_id, owner: target.clone(), balance }); + Self::deposit_event(Event::Burned { + asset_id: asset_id.clone(), + owner: target.clone(), + balance, + }); } fn done_transfer( - asset_id: Self::AssetId, + asset_id: &Self::AssetId, source: &::AccountId, dest: &::AccountId, amount: Self::Balance, ) { Self::deposit_event(Event::Transferred { - asset_id, + asset_id: asset_id.clone(), from: source.clone(), to: dest.clone(), amount, @@ -142,14 +150,14 @@ impl, I: 'static> fungibles::Unbalanced for Pallet Result, DispatchError> { defensive!("write_balance is not used if other functions are impl'd"); Err(DispatchError::Unavailable) } - fn set_total_issuance(id: T::AssetId, amount: Self::Balance) { + fn set_total_issuance(id: &T::AssetId, amount: Self::Balance) { Asset::::mutate_exists(id, |maybe_asset| { if let Some(ref mut asset) = maybe_asset { asset.supply = amount @@ -157,7 +165,7 @@ impl, I: 'static> fungibles::Unbalanced for Pallet, I: 'static> fungibles::Unbalanced for Pallet, I: 'static> fungibles::Destroy for Pallet impl, I: 'static> fungibles::metadata::Inspect<::AccountId> for Pallet { - fn name(asset: T::AssetId) -> Vec { + fn name(asset: &T::AssetId) -> Vec { Metadata::::get(asset).name.to_vec() } - fn symbol(asset: T::AssetId) -> Vec { + fn symbol(asset: &T::AssetId) -> Vec { Metadata::::get(asset).symbol.to_vec() } - fn decimals(asset: T::AssetId) -> u8 { + fn decimals(asset: &T::AssetId) -> u8 { Metadata::::get(asset).decimals } } @@ -260,7 +268,7 @@ impl, I: 'static> fungibles::approvals::Inspect< { // Check the amount approved to be spent by an owner to a delegate fn allowance( - asset: T::AssetId, + asset: &T::AssetId, owner: &::AccountId, delegate: &::AccountId, ) -> T::Balance { @@ -297,19 +305,19 @@ impl, I: 'static> fungibles::approvals::Mutate<: impl, I: 'static> fungibles::roles::Inspect<::AccountId> for Pallet { - fn owner(asset: T::AssetId) -> Option<::AccountId> { + fn owner(asset: &T::AssetId) -> Option<::AccountId> { Asset::::get(asset).map(|x| x.owner) } - fn issuer(asset: T::AssetId) -> Option<::AccountId> { + fn issuer(asset: &T::AssetId) -> Option<::AccountId> { Asset::::get(asset).map(|x| x.issuer) } - fn admin(asset: T::AssetId) -> Option<::AccountId> { + fn admin(asset: &T::AssetId) -> Option<::AccountId> { Asset::::get(asset).map(|x| x.admin) } - fn freezer(asset: T::AssetId) -> Option<::AccountId> { + fn freezer(asset: &T::AssetId) -> Option<::AccountId> { Asset::::get(asset).map(|x| x.freezer) } } @@ -350,8 +358,8 @@ impl, I: 'static> fungibles::Refund for Pallet } fn refund(id: Self::AssetId, who: T::AccountId) -> DispatchResult { match Self::deposit_held(id.clone(), who.clone()) { - Some((d, _)) if d == who => Self::do_refund(id, who, false), - Some(..) => Self::do_refund_other(id, &who, None), + Some((d, _)) if d == who => Self::do_refund(&id, who, false), + Some(..) => Self::do_refund_other(&id, &who, None), None => Err(Error::::NoDeposit.into()), } } diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index d52149225558..0da063536046 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -471,7 +471,7 @@ pub mod pallet { for (id, account_id, amount) in &self.accounts { let result = >::increase_balance( - id.clone(), + id, account_id, *amount, |details| -> DispatchResult { @@ -1556,7 +1556,7 @@ pub mod pallet { allow_burn: bool, ) -> DispatchResult { let id: T::AssetId = id.into(); - Self::do_refund(id, ensure_signed(origin)?, allow_burn) + Self::do_refund(&id, ensure_signed(origin)?, allow_burn) } /// Sets the minimum balance of an asset. @@ -1648,7 +1648,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let who = T::Lookup::lookup(who)?; let id: T::AssetId = id.into(); - Self::do_refund_other(id, &who, Some(origin)) + Self::do_refund_other(&id, &who, Some(origin)) } /// Disallow further unprivileged transfers of an asset `id` to and from an account `who`. diff --git a/substrate/frame/assets/src/mock.rs b/substrate/frame/assets/src/mock.rs index f6173a451fff..1487b26456f6 100644 --- a/substrate/frame/assets/src/mock.rs +++ b/substrate/frame/assets/src/mock.rs @@ -130,12 +130,12 @@ parameter_types! { pub struct TestFreezer; impl FrozenBalance for TestFreezer { - fn frozen_balance(asset: u32, who: &u64) -> Option { - Frozen::get().get(&(asset, *who)).cloned() + fn frozen_balance(asset: &u32, who: &u64) -> Option { + Frozen::get().get(&(*asset, *who)).cloned() } - fn died(asset: u32, who: &u64) { - Hooks::mutate(|v| v.push(Hook::Died(asset, *who))); + fn died(asset: &u32, who: &u64) { + Hooks::mutate(|v| v.push(Hook::Died(*asset, *who))); // Sanity check: dead accounts have no balance. assert!(Assets::balance(asset, *who).is_zero()); diff --git a/substrate/frame/assets/src/tests.rs b/substrate/frame/assets/src/tests.rs index c7021bcad531..e20164b977d3 100644 --- a/substrate/frame/assets/src/tests.rs +++ b/substrate/frame/assets/src/tests.rs @@ -50,7 +50,7 @@ fn transfer_should_never_burn() { Balances::make_free_balance_be(&2, 100); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); while System::inc_consumers(&2).is_ok() {} let _ = System::dec_consumers(&2); @@ -58,15 +58,15 @@ fn transfer_should_never_burn() { // Exactly one consumer ref remaining. assert_eq!(System::consumers(&2), 1); - let _ = >::transfer(0, &1, &2, 50, Protect); + let _ = >::transfer(&0, &1, &2, 50, Protect); System::assert_has_event(RuntimeEvent::Assets(crate::Event::Transferred { asset_id: 0, from: 1, to: 2, amount: 50, })); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 1) + Assets::balance(0, 2), 100); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 1) + Assets::balance(&0, 2), 100); }); } @@ -81,14 +81,14 @@ fn basic_minting_should_work() { owner: 1, amount: 100, })); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 2, 100)); System::assert_last_event(RuntimeEvent::Assets(crate::Event::Issued { asset_id: 0, owner: 2, amount: 100, })); - assert_eq!(Assets::balance(0, 2), 100); + assert_eq!(Assets::balance(&0, 2), 100); assert_eq!(asset_ids(), vec![0, 1, 999]); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 1, 1, 100)); System::assert_last_event(RuntimeEvent::Assets(crate::Event::Issued { @@ -158,7 +158,7 @@ fn refunding_asset_deposit_with_burn_should_work() { assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); assert_ok!(Assets::refund(RuntimeOrigin::signed(1), 0, true)); assert_eq!(Balances::reserved_balance(&1), 0); - assert_eq!(Assets::balance(1, 0), 0); + assert_eq!(Assets::balance(&1, 0), 0); }); } @@ -183,13 +183,13 @@ fn refunding_asset_deposit_without_burn_should_work() { assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); Balances::make_free_balance_be(&2, 100); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 100)); - assert_eq!(Assets::balance(0, 2), 100); - assert_eq!(Assets::balance(0, 1), 0); + assert_eq!(Assets::balance(&0, 2), 100); + assert_eq!(Assets::balance(&0, 1), 0); assert_eq!(Balances::reserved_balance(&1), 10); assert_eq!(asset_account_counts(0), (2, 0)); assert_ok!(Assets::refund(RuntimeOrigin::signed(1), 0, false)); assert_eq!(Balances::reserved_balance(&1), 0); - assert_eq!(Assets::balance(1, 0), 0); + assert_eq!(Assets::balance(&1, 0), 0); assert_eq!(asset_account_counts(0), (1, 0)); }); } @@ -219,8 +219,8 @@ fn refunding_with_sufficient_existence_reason_should_fail() { // create an asset account with sufficient existence reason // by transferring some sufficient assets assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); assert_eq!(asset_account_counts(0), (2, 2)); // fails to refund assert_noop!(Assets::refund(RuntimeOrigin::signed(2), 0, true), Error::::NoDeposit); @@ -256,8 +256,8 @@ fn refunding_frozen_with_consumer_ref_works() { // non-sufficient funds into assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); assert_eq!(System::consumers(&2), 1); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); assert_eq!(asset_account_counts(0), (2, 0)); // freeze asset account `2` and asset `0` assert_ok!(Assets::freeze(RuntimeOrigin::signed(1), 0, 2)); @@ -288,8 +288,8 @@ fn refunding_frozen_with_deposit_works() { // transfer some assets to `2` assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); assert_eq!(System::consumers(&2), 1); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); assert_eq!(asset_account_counts(0), (2, 0)); // ensure refundable even if asset account and asset is frozen assert_ok!(Assets::freeze(RuntimeOrigin::signed(1), 0, 2)); @@ -322,8 +322,8 @@ fn approval_lifecycle_works() { assert_eq!(Asset::::get(0).unwrap().approvals, 1); assert_ok!(Assets::cancel_approval(RuntimeOrigin::signed(1), 0, 2)); assert_eq!(Asset::::get(0).unwrap().approvals, 0); - assert_eq!(Assets::balance(0, 1), 60); - assert_eq!(Assets::balance(0, 3), 40); + assert_eq!(Assets::balance(&0, 1), 60); + assert_eq!(Assets::balance(&0, 3), 40); assert_eq!(Balances::reserved_balance(&1), 0); assert_eq!(asset_ids(), vec![0, 999]); }); @@ -348,8 +348,8 @@ fn transfer_approved_all_funds() { // transfer the full amount, which should trigger auto-cleanup assert_ok!(Assets::transfer_approved(RuntimeOrigin::signed(2), 0, 1, 3, 50)); assert_eq!(Asset::::get(0).unwrap().approvals, 0); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 3), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 3), 50); assert_eq!(Balances::reserved_balance(&1), 0); }); } @@ -643,21 +643,21 @@ fn min_balance_should_work() { // When deducting from an account to below minimum, it should be reaped. // Death by `transfer`. assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 91)); - assert!(Assets::maybe_balance(0, 1).is_none()); - assert_eq!(Assets::balance(0, 2), 100); + assert!(Assets::maybe_balance(&0, 1).is_none()); + assert_eq!(Assets::balance(&0, 2), 100); assert_eq!(Asset::::get(0).unwrap().accounts, 1); assert_eq!(take_hooks(), vec![Hook::Died(0, 1)]); // Death by `force_transfer`. assert_ok!(Assets::force_transfer(RuntimeOrigin::signed(1), 0, 2, 1, 91)); - assert!(Assets::maybe_balance(0, 2).is_none()); - assert_eq!(Assets::balance(0, 1), 100); + assert!(Assets::maybe_balance(&0, 2).is_none()); + assert_eq!(Assets::balance(&0, 1), 100); assert_eq!(Asset::::get(0).unwrap().accounts, 1); assert_eq!(take_hooks(), vec![Hook::Died(0, 2)]); // Death by `burn`. assert_ok!(Assets::burn(RuntimeOrigin::signed(1), 0, 1, 91)); - assert!(Assets::maybe_balance(0, 1).is_none()); + assert!(Assets::maybe_balance(&0, 1).is_none()); assert_eq!(Asset::::get(0).unwrap().accounts, 0); assert_eq!(take_hooks(), vec![Hook::Died(0, 1)]); @@ -675,16 +675,16 @@ fn querying_total_supply_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); assert_ok!(Assets::transfer(RuntimeOrigin::signed(2), 0, 3, 31)); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 19); - assert_eq!(Assets::balance(0, 3), 31); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 19); + assert_eq!(Assets::balance(&0, 3), 31); assert_ok!(Assets::burn(RuntimeOrigin::signed(1), 0, 3, u64::MAX)); - assert_eq!(Assets::total_supply(0), 69); + assert_eq!(Assets::total_supply(&0), 69); }); } @@ -693,10 +693,10 @@ fn transferring_amount_below_available_balance_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); }); } @@ -705,14 +705,14 @@ fn transferring_enough_to_kill_source_when_keep_alive_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 10)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_noop!( Assets::transfer_keep_alive(RuntimeOrigin::signed(1), 0, 2, 91), Error::::BalanceLow ); assert_ok!(Assets::transfer_keep_alive(RuntimeOrigin::signed(1), 0, 2, 90)); - assert_eq!(Assets::balance(0, 1), 10); - assert_eq!(Assets::balance(0, 2), 90); + assert_eq!(Assets::balance(&0, 1), 10); + assert_eq!(Assets::balance(&0, 2), 90); assert!(hooks().is_empty()); assert_eq!(asset_ids(), vec![0, 999]); }); @@ -723,7 +723,7 @@ fn transferring_frozen_user_should_not_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::freeze(RuntimeOrigin::signed(1), 0, 1)); assert_noop!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50), Error::::Frozen); assert_ok!(Assets::thaw(RuntimeOrigin::signed(1), 0, 1)); @@ -736,7 +736,7 @@ fn transferring_frozen_asset_should_not_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::freeze_asset(RuntimeOrigin::signed(1), 0)); assert_noop!( Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50), @@ -753,7 +753,7 @@ fn approve_transfer_frozen_asset_should_not_work() { Balances::make_free_balance_be(&1, 100); assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::freeze_asset(RuntimeOrigin::signed(1), 0)); assert_noop!( Assets::approve_transfer(RuntimeOrigin::signed(1), 0, 2, 50), @@ -769,7 +769,7 @@ fn transferring_from_blocked_account_should_not_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::block(RuntimeOrigin::signed(1), 0, 1)); // behaves as frozen when transferring from blocked assert_noop!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50), Error::::Frozen); @@ -785,8 +785,8 @@ fn transferring_to_blocked_account_should_not_work() { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 2, 100)); - assert_eq!(Assets::balance(0, 1), 100); - assert_eq!(Assets::balance(0, 2), 100); + assert_eq!(Assets::balance(&0, 1), 100); + assert_eq!(Assets::balance(&0, 2), 100); assert_ok!(Assets::block(RuntimeOrigin::signed(1), 0, 1)); assert_noop!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 50), TokenError::Blocked); assert_ok!(Assets::thaw(RuntimeOrigin::signed(1), 0, 1)); @@ -882,15 +882,15 @@ fn transferring_from_frozen_account_should_not_work() { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 2, 100)); - assert_eq!(Assets::balance(0, 1), 100); - assert_eq!(Assets::balance(0, 2), 100); + assert_eq!(Assets::balance(&0, 1), 100); + assert_eq!(Assets::balance(&0, 2), 100); assert_ok!(Assets::freeze(RuntimeOrigin::signed(1), 0, 2)); // can transfer to `2` assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); // cannot transfer from `2` assert_noop!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 25), Error::::Frozen); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 150); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 150); }); } @@ -901,8 +901,8 @@ fn touching_and_freezing_account_with_zero_asset_balance_should_work() { Balances::make_free_balance_be(&2, 100); assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); - assert_eq!(Assets::balance(0, 2), 0); + assert_eq!(Assets::balance(&0, 1), 100); + assert_eq!(Assets::balance(&0, 2), 0); // cannot freeze an account that doesn't have an `Assets` entry assert_noop!(Assets::freeze(RuntimeOrigin::signed(1), 0, 2), Error::::NoAccount); assert_ok!(Assets::touch(RuntimeOrigin::signed(2), 0)); @@ -912,8 +912,8 @@ fn touching_and_freezing_account_with_zero_asset_balance_should_work() { assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); // cannot transfer from `2` assert_noop!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 25), Error::::Frozen); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); }); } @@ -929,7 +929,7 @@ fn touch_other_works() { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, false, 1)); assert_ok!(Assets::set_team(RuntimeOrigin::signed(1), 0, 1, 1, 2)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); // account `3` does not exist assert!(!Account::::contains_key(0, &3)); // creation of asset account `3` by account `4` fails @@ -954,7 +954,7 @@ fn touch_other_and_freeze_works() { Balances::make_free_balance_be(&1, 100); assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); // account `2` does not exist assert!(!Account::::contains_key(0, &2)); // create account `2` with touch_other @@ -966,8 +966,8 @@ fn touch_other_and_freeze_works() { assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); // cannot transfer from `2` assert_noop!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 25), Error::::Frozen); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); }); } @@ -980,15 +980,15 @@ fn account_with_deposit_not_destroyed() { Balances::make_free_balance_be(&2, 100); assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, false, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); - assert_eq!(Assets::balance(0, 2), 0); + assert_eq!(Assets::balance(&0, 1), 100); + assert_eq!(Assets::balance(&0, 2), 0); // case 1; account `2` not destroyed with a holder's deposit assert_ok!(Assets::touch(RuntimeOrigin::signed(2), 0)); assert_eq!(Balances::reserved_balance(&2), 10); assert!(Account::::contains_key(0, &2)); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); assert_ok!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 50)); - assert_eq!(Assets::balance(0, 2), 0); + assert_eq!(Assets::balance(&0, 2), 0); assert!(Account::::contains_key(0, &2)); // destroy account `2` @@ -1110,12 +1110,12 @@ fn transferring_amount_more_than_available_balance_should_not_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 50)); - assert_eq!(Assets::balance(0, 1), 50); - assert_eq!(Assets::balance(0, 2), 50); + assert_eq!(Assets::balance(&0, 1), 50); + assert_eq!(Assets::balance(&0, 2), 50); assert_ok!(Assets::burn(RuntimeOrigin::signed(1), 0, 1, u64::MAX)); - assert_eq!(Assets::balance(0, 1), 0); + assert_eq!(Assets::balance(&0, 1), 0); assert_noop!( Assets::transfer(RuntimeOrigin::signed(1), 0, 1, 50), Error::::NoAccount @@ -1132,7 +1132,7 @@ fn transferring_less_than_one_unit_is_fine() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 0)); // `ForceCreated` and `Issued` but no `Transferred` event. assert_eq!(System::events().len(), 2); @@ -1144,7 +1144,7 @@ fn transferring_more_units_than_total_supply_should_not_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_noop!( Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 101), Error::::BalanceLow @@ -1157,14 +1157,14 @@ fn burning_asset_balance_with_positive_balance_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); assert_ok!(Assets::burn(RuntimeOrigin::signed(1), 0, 1, u64::MAX)); System::assert_last_event(RuntimeEvent::Assets(crate::Event::Burned { asset_id: 0, owner: 1, balance: 100, })); - assert_eq!(Assets::balance(0, 1), 0); + assert_eq!(Assets::balance(&0, 1), 0); }); } @@ -1173,13 +1173,13 @@ fn burning_asset_balance_with_zero_balance_does_nothing() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 2), 0); + assert_eq!(Assets::balance(&0, 2), 0); assert_noop!( Assets::burn(RuntimeOrigin::signed(1), 0, 2, u64::MAX), Error::::NoAccount ); - assert_eq!(Assets::balance(0, 2), 0); - assert_eq!(Assets::total_supply(0), 100); + assert_eq!(Assets::balance(&0, 2), 0); + assert_eq!(Assets::total_supply(&0), 100); }); } @@ -1293,7 +1293,7 @@ fn freezer_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 10)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); - assert_eq!(Assets::balance(0, 1), 100); + assert_eq!(Assets::balance(&0, 1), 100); // freeze 50 of it. set_frozen_balance(0, 1, 50); @@ -1335,8 +1335,8 @@ fn imbalances_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); - let imb = Assets::issue(0, 100); - assert_eq!(Assets::total_supply(0), 100); + let imb = Assets::issue(&0, 100); + assert_eq!(Assets::total_supply(&0), 100); assert_eq!(imb.peek(), 100); let (imb1, imb2) = imb.split(30); @@ -1344,11 +1344,11 @@ fn imbalances_should_work() { assert_eq!(imb2.peek(), 70); drop(imb2); - assert_eq!(Assets::total_supply(0), 30); + assert_eq!(Assets::total_supply(&0), 30); assert!(Assets::resolve(&1, imb1).is_ok()); - assert_eq!(Assets::balance(0, 1), 30); - assert_eq!(Assets::total_supply(0), 30); + assert_eq!(Assets::balance(&0, 1), 30); + assert_eq!(Assets::total_supply(&0), 30); }); } @@ -1451,15 +1451,15 @@ fn force_asset_status_should_work() { true, false )); - assert_eq!(Assets::balance(0, 1), 50); + assert_eq!(Assets::balance(&0, 1), 50); // account can receive assets for balance < min_balance assert_ok!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 1)); - assert_eq!(Assets::balance(0, 1), 51); + assert_eq!(Assets::balance(&0, 1), 51); // account on outbound transfer will cleanup for balance < min_balance assert_ok!(Assets::transfer(RuntimeOrigin::signed(1), 0, 2, 1)); - assert_eq!(Assets::balance(0, 1), 0); + assert_eq!(Assets::balance(&0, 1), 0); // won't create new account with balance below min_balance assert_noop!( @@ -1486,9 +1486,9 @@ fn force_asset_status_should_work() { false )); assert_ok!(Assets::transfer(RuntimeOrigin::signed(2), 0, 1, 110)); - assert_eq!(Assets::balance(0, 1), 200); - assert_eq!(Assets::balance(0, 2), 0); - assert_eq!(Assets::total_supply(0), 200); + assert_eq!(Assets::balance(&0, 1), 200); + assert_eq!(Assets::balance(&0, 2), 0); + assert_eq!(Assets::total_supply(&0), 200); }); } @@ -1585,8 +1585,8 @@ fn assets_from_genesis_should_exist() { new_test_ext().execute_with(|| { assert_eq!(asset_ids(), vec![999]); assert!(Metadata::::contains_key(999)); - assert_eq!(Assets::balance(999, 1), 100); - assert_eq!(Assets::total_supply(999), 100); + assert_eq!(Assets::balance(&999, 1), 100); + assert_eq!(Assets::total_supply(&999), 100); }); } @@ -1603,9 +1603,9 @@ fn querying_name_symbol_and_decimals_should_work() { 12, false )); - assert_eq!(Assets::name(0), vec![0u8; 10]); - assert_eq!(Assets::symbol(0), vec![1u8; 10]); - assert_eq!(Assets::decimals(0), 12); + assert_eq!(Assets::name(&0), vec![0u8; 10]); + assert_eq!(Assets::symbol(&0), vec![1u8; 10]); + assert_eq!(Assets::decimals(&0), 12); }); } @@ -1617,10 +1617,10 @@ fn querying_allowance_should_work() { assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); Balances::make_free_balance_be(&1, 2); assert_ok!(Assets::approve(0, &1, &2, 50)); - assert_eq!(Assets::allowance(0, &1, &2), 50); + assert_eq!(Assets::allowance(&0, &1, &2), 50); // Transfer asset 0, from owner 1 and delegate 2 to destination 3 assert_ok!(Assets::transfer_from(0, &1, &2, &3, 50)); - assert_eq!(Assets::allowance(0, &1, &2), 0); + assert_eq!(Assets::allowance(&0, &1, &2), 0); }); } @@ -1649,10 +1649,10 @@ fn querying_roles_should_work() { // Freezer 4, )); - assert_eq!(Assets::owner(0), Some(1)); - assert_eq!(Assets::issuer(0), Some(2)); - assert_eq!(Assets::admin(0), Some(3)); - assert_eq!(Assets::freezer(0), Some(4)); + assert_eq!(Assets::owner(&0), Some(1)); + assert_eq!(Assets::issuer(&0), Some(2)); + assert_eq!(Assets::admin(&0), Some(3)); + assert_eq!(Assets::freezer(&0), Some(4)); }); } diff --git a/substrate/frame/assets/src/tests/sets.rs b/substrate/frame/assets/src/tests/sets.rs index 4d75b8aeab2c..9cda9a5a2946 100644 --- a/substrate/frame/assets/src/tests/sets.rs +++ b/substrate/frame/assets/src/tests/sets.rs @@ -81,14 +81,14 @@ fn deposit_from_set_types_works() { let account2 = 2; assert_ok!(>::create(asset1, account1, true, 1)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); - assert_eq!(First::::total_issuance(()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), 100); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let imb = First::::deposit((), &account2, 50, Precision::Exact).unwrap(); - assert_eq!(First::::balance((), &account2), 50); - assert_eq!(First::::total_issuance(()), 100); + let imb = First::::deposit(&(), &account2, 50, Precision::Exact).unwrap(); + assert_eq!(First::::balance(&(), &account2), 50); + assert_eq!(First::::total_issuance(&()), 100); System::assert_has_event(RuntimeEvent::Assets(crate::Event::Deposited { asset_id: asset1, @@ -103,14 +103,14 @@ fn deposit_from_set_types_works() { assert_eq!(imb2.peek(), 20); drop(imb2); - assert_eq!(First::::total_issuance(()), 120); + assert_eq!(First::::total_issuance(&()), 120); assert!(First::::settle(&account1, imb1, Preservation::Preserve).is_ok()); - assert_eq!(First::::balance((), &account1), 70); - assert_eq!(First::::balance((), &account2), 50); - assert_eq!(First::::total_issuance(()), 120); + assert_eq!(First::::balance(&(), &account1), 70); + assert_eq!(First::::balance(&(), &account2), 50); + assert_eq!(First::::total_issuance(&()), 120); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -121,14 +121,14 @@ fn issue_from_set_types_works() { let account1: u64 = 1; assert_ok!(>::create(asset1, account1, true, 1)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); - assert_eq!(First::::balance((), &account1), 100); - assert_eq!(First::::total_issuance(()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::balance(&(), &account1), 100); + assert_eq!(First::::total_issuance(&()), 100); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let imb = First::::issue((), 100); - assert_eq!(First::::total_issuance(()), 200); + let imb = First::::issue(&(), 100); + assert_eq!(First::::total_issuance(&()), 200); assert_eq!(imb.peek(), 100); let (imb1, imb2) = imb.split(30); @@ -136,13 +136,13 @@ fn issue_from_set_types_works() { assert_eq!(imb2.peek(), 70); drop(imb2); - assert_eq!(First::::total_issuance(()), 130); + assert_eq!(First::::total_issuance(&()), 130); assert!(First::::resolve(&account1, imb1).is_ok()); - assert_eq!(First::::balance((), &account1), 130); - assert_eq!(First::::total_issuance(()), 130); + assert_eq!(First::::balance(&(), &account1), 130); + assert_eq!(First::::total_issuance(&()), 130); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -153,14 +153,14 @@ fn pair_from_set_types_works() { let account1: u64 = 1; assert_ok!(>::create(asset1, account1, true, 1)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); - assert_eq!(First::::balance((), &account1), 100); - assert_eq!(First::::total_issuance(()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::balance(&(), &account1), 100); + assert_eq!(First::::total_issuance(&()), 100); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let (debt, credit) = First::::pair((), 100).unwrap(); - assert_eq!(First::::total_issuance(()), 100); + let (debt, credit) = First::::pair(&(), 100).unwrap(); + assert_eq!(First::::total_issuance(&()), 100); assert_eq!(debt.peek(), 100); assert_eq!(credit.peek(), 100); @@ -169,24 +169,24 @@ fn pair_from_set_types_works() { assert_eq!(debt2.peek(), 70); drop(debt2); - assert_eq!(First::::total_issuance(()), 170); + assert_eq!(First::::total_issuance(&()), 170); assert!(First::::settle(&account1, debt1, Preservation::Preserve).is_ok()); - assert_eq!(First::::balance((), &account1), 70); - assert_eq!(First::::total_issuance(()), 170); + assert_eq!(First::::balance(&(), &account1), 70); + assert_eq!(First::::total_issuance(&()), 170); let (credit1, credit2) = credit.split(40); assert_eq!(credit1.peek(), 40); assert_eq!(credit2.peek(), 60); drop(credit2); - assert_eq!(First::::total_issuance(()), 110); + assert_eq!(First::::total_issuance(&()), 110); assert!(First::::resolve(&account1, credit1).is_ok()); - assert_eq!(First::::balance((), &account1), 110); - assert_eq!(First::::total_issuance(()), 110); + assert_eq!(First::::balance(&(), &account1), 110); + assert_eq!(First::::total_issuance(&()), 110); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -197,13 +197,13 @@ fn rescind_from_set_types_works() { let account1: u64 = 1; assert_ok!(>::create(asset1, account1, true, 1)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); - assert_eq!(First::::total_issuance(()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), 100); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let imb = First::::rescind((), 20); - assert_eq!(First::::total_issuance(()), 80); + let imb = First::::rescind(&(), 20); + assert_eq!(First::::total_issuance(&()), 80); assert_eq!(imb.peek(), 20); @@ -212,13 +212,13 @@ fn rescind_from_set_types_works() { assert_eq!(imb2.peek(), 5); drop(imb2); - assert_eq!(First::::total_issuance(()), 85); + assert_eq!(First::::total_issuance(&()), 85); assert!(First::::settle(&account1, imb1, Preservation::Preserve).is_ok()); - assert_eq!(First::::balance((), &account1), 85); - assert_eq!(First::::total_issuance(()), 85); + assert_eq!(First::::balance(&(), &account1), 85); + assert_eq!(First::::total_issuance(&()), 85); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -231,34 +231,34 @@ fn resolve_from_set_types_works() { let ed = 11; assert_ok!(>::create(asset1, account1, true, ed)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); - assert_eq!(First::::balance((), &account1), 100); - assert_eq!(First::::total_issuance(()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::balance(&(), &account1), 100); + assert_eq!(First::::total_issuance(&()), 100); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let imb = First::::issue((), 100); - assert_eq!(First::::total_issuance(()), 200); + let imb = First::::issue(&(), 100); + assert_eq!(First::::total_issuance(&()), 200); assert_eq!(imb.peek(), 100); let (imb1, imb2) = imb.split(10); assert_eq!(imb1.peek(), 10); assert_eq!(imb2.peek(), 90); - assert_eq!(First::::total_issuance(()), 200); + assert_eq!(First::::total_issuance(&()), 200); // ed requirements not met. let imb1 = First::::resolve(&account2, imb1).unwrap_err(); assert_eq!(imb1.peek(), 10); drop(imb1); - assert_eq!(First::::total_issuance(()), 190); - assert_eq!(First::::balance((), &account2), 0); + assert_eq!(First::::total_issuance(&()), 190); + assert_eq!(First::::balance(&(), &account2), 0); // resolve to new account `2`. assert_ok!(First::::resolve(&account2, imb2)); - assert_eq!(First::::total_issuance(()), 190); - assert_eq!(First::::balance((), &account2), 90); + assert_eq!(First::::total_issuance(&()), 190); + assert_eq!(First::::balance(&(), &account2), 90); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -271,48 +271,48 @@ fn settle_from_set_types_works() { let ed = 11; assert_ok!(>::create(asset1, account1, true, ed)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); - assert_ok!(Assets::mint_into(asset1, &account2, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account2, 100)); - assert_eq!(First::::balance((), &account2), 100); - assert_eq!(First::::total_issuance(()), 200); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::balance(&(), &account2), 100); + assert_eq!(First::::total_issuance(&()), 200); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); - let imb = First::::rescind((), 100); - assert_eq!(First::::total_issuance(()), 100); + let imb = First::::rescind(&(), 100); + assert_eq!(First::::total_issuance(&()), 100); assert_eq!(imb.peek(), 100); let (imb1, imb2) = imb.split(10); assert_eq!(imb1.peek(), 10); assert_eq!(imb2.peek(), 90); - assert_eq!(First::::total_issuance(()), 100); + assert_eq!(First::::total_issuance(&()), 100); // ed requirements not met. let imb2 = First::::settle(&account2, imb2, Preservation::Preserve).unwrap_err(); assert_eq!(imb2.peek(), 90); drop(imb2); - assert_eq!(First::::total_issuance(()), 190); - assert_eq!(First::::balance((), &account2), 100); + assert_eq!(First::::total_issuance(&()), 190); + assert_eq!(First::::balance(&(), &account2), 100); // settle to account `1`. assert_ok!(First::::settle(&account2, imb1, Preservation::Preserve)); - assert_eq!(First::::total_issuance(()), 190); - assert_eq!(First::::balance((), &account2), 90); + assert_eq!(First::::total_issuance(&()), 190); + assert_eq!(First::::balance(&(), &account2), 90); - let imb = First::::rescind((), 85); - assert_eq!(First::::total_issuance(()), 105); + let imb = First::::rescind(&(), 85); + assert_eq!(First::::total_issuance(&()), 105); assert_eq!(imb.peek(), 85); // settle to account `1` and expect some dust. let imb = First::::settle(&account2, imb, Preservation::Expendable).unwrap(); assert_eq!(imb.peek(), 5); - assert_eq!(First::::total_issuance(()), 105); - assert_eq!(First::::balance((), &account2), 0); + assert_eq!(First::::total_issuance(&()), 105); + assert_eq!(First::::balance(&(), &account2), 0); drop(imb); - assert_eq!(First::::total_issuance(()), 100); + assert_eq!(First::::total_issuance(&()), 100); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } @@ -324,11 +324,11 @@ fn withdraw_from_set_types_works() { let account2 = 2; assert_ok!(>::create(asset1, account1, true, 1)); - assert_ok!(Assets::mint_into(asset1, &account1, 100)); - assert_ok!(Assets::mint_into(asset1, &account2, 100)); + assert_ok!(Assets::mint_into(&asset1, &account1, 100)); + assert_ok!(Assets::mint_into(&asset1, &account2, 100)); - assert_eq!(First::::total_issuance(()), 200); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), 200); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); let imb = First::::withdraw( (), @@ -339,8 +339,8 @@ fn withdraw_from_set_types_works() { Fortitude::Polite, ) .unwrap(); - assert_eq!(First::::balance((), &account2), 50); - assert_eq!(First::::total_issuance(()), 200); + assert_eq!(First::::balance(&(), &account2), 50); + assert_eq!(First::::total_issuance(&()), 200); System::assert_has_event(RuntimeEvent::Assets(crate::Event::Withdrawn { asset_id: asset1, @@ -350,9 +350,9 @@ fn withdraw_from_set_types_works() { assert_eq!(imb.peek(), 50); drop(imb); - assert_eq!(First::::total_issuance(()), 150); - assert_eq!(First::::balance((), &account2), 50); + assert_eq!(First::::total_issuance(&()), 150); + assert_eq!(First::::balance(&(), &account2), 50); - assert_eq!(First::::total_issuance(()), Assets::total_issuance(asset1)); + assert_eq!(First::::total_issuance(&()), Assets::total_issuance(&asset1)); }); } diff --git a/substrate/frame/assets/src/types.rs b/substrate/frame/assets/src/types.rs index 11edc7d3fcb5..f9cd96e7da99 100644 --- a/substrate/frame/assets/src/types.rs +++ b/substrate/frame/assets/src/types.rs @@ -217,19 +217,19 @@ pub trait FrozenBalance { /// In special cases (privileged intervention) the account balance may also go below the sum. /// /// If `None` is returned, then nothing special is enforced. - fn frozen_balance(asset: AssetId, who: &AccountId) -> Option; + fn frozen_balance(asset: &AssetId, who: &AccountId) -> Option; /// Called after an account has been removed. /// /// NOTE: It is possible that the asset does no longer exist when this hook is called. - fn died(asset: AssetId, who: &AccountId); + fn died(asset: &AssetId, who: &AccountId); } impl FrozenBalance for () { - fn frozen_balance(_: AssetId, _: &AccountId) -> Option { + fn frozen_balance(_: &AssetId, _: &AccountId) -> Option { None } - fn died(_: AssetId, _: &AccountId) {} + fn died(_: &AssetId, _: &AccountId) {} } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/substrate/frame/broker/src/test_fungibles.rs b/substrate/frame/broker/src/test_fungibles.rs index d18bff149533..62d7afa27c2c 100644 --- a/substrate/frame/broker/src/test_fungibles.rs +++ b/substrate/frame/broker/src/test_fungibles.rs @@ -54,35 +54,35 @@ where type AssetId = AssetId; type Balance = MinimumBalance::Type; - fn total_issuance(asset: Self::AssetId) -> Self::Balance { + fn total_issuance(asset: &Self::AssetId) -> Self::Balance { TestAssetOf::get() .get(&(Instance::get(), asset.encode())) .and_then(|data| Decode::decode(&mut &data[..]).ok()) .unwrap_or_default() } - fn active_issuance(asset: Self::AssetId) -> Self::Balance { + fn active_issuance(asset: &Self::AssetId) -> Self::Balance { Self::total_issuance(asset) } /// The minimum balance any single account may have. - fn minimum_balance(_asset: Self::AssetId) -> Self::Balance { + fn minimum_balance(_asset: &Self::AssetId) -> Self::Balance { MinimumBalance::get() } - fn total_balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { + fn total_balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { TestBalanceOf::get() .get(&(Instance::get(), asset.encode(), who.encode())) .and_then(|data| Decode::decode(&mut &data[..]).ok()) .unwrap_or_default() } - fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { + fn balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { Self::total_balance(asset, who) } fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, _preservation: Preservation, _force: Fortitude, @@ -91,7 +91,7 @@ where } fn can_deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, _provenance: Provenance, @@ -106,7 +106,7 @@ where } fn can_withdraw( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> WithdrawConsequence { @@ -120,7 +120,7 @@ where WithdrawConsequence::Success } - fn asset_exists(asset: Self::AssetId) -> bool { + fn asset_exists(asset: &Self::AssetId) -> bool { TestAssetOf::get().contains_key(&(Instance::get(), asset.encode())) } } @@ -139,7 +139,7 @@ where fn handle_dust(_dust: Dust) {} fn write_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError> { @@ -159,7 +159,7 @@ where Ok(maybe_dust) } - fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance) { + fn set_total_issuance(asset: &Self::AssetId, amount: Self::Balance) { let mut ta = TestAssetOf::get(); ta.insert((Instance::get(), asset.encode()), amount.encode()); TestAssetOf::set(ta); diff --git a/substrate/frame/contracts/mock-network/src/tests.rs b/substrate/frame/contracts/mock-network/src/tests.rs index 48a94e172a02..c3820a3ffcfe 100644 --- a/substrate/frame/contracts/mock-network/src/tests.rs +++ b/substrate/frame/contracts/mock-network/src/tests.rs @@ -52,7 +52,7 @@ fn instantiate_test_contract(name: &str) -> AccountId { // Funds contract account with some balance and assets. ParaA::execute_with(|| { parachain::Balances::make_free_balance_be(&contract_addr, INITIAL_BALANCE); - parachain::Assets::mint_into(0u32.into(), &contract_addr, INITIAL_BALANCE).unwrap(); + parachain::Assets::mint_into(&0u128, &contract_addr, INITIAL_BALANCE).unwrap(); }); Relay::execute_with(|| { let sovereign_account = parachain_account_sovereign_account_id(1u32, contract_addr.clone()); diff --git a/substrate/frame/nft-fractionalization/src/lib.rs b/substrate/frame/nft-fractionalization/src/lib.rs index e97d3802fd20..cfce7fa054d9 100644 --- a/substrate/frame/nft-fractionalization/src/lib.rs +++ b/substrate/frame/nft-fractionalization/src/lib.rs @@ -364,7 +364,7 @@ pub mod pallet { beneficiary: &T::AccountId, amount: AssetBalanceOf, ) -> DispatchResult { - T::Assets::mint_into(asset_id, beneficiary, amount)?; + T::Assets::mint_into(&asset_id, beneficiary, amount)?; Ok(()) } @@ -374,7 +374,7 @@ pub mod pallet { account: &T::AccountId, amount: AssetBalanceOf, ) -> DispatchResult { - T::Assets::burn_from(asset_id.clone(), account, amount, Exact, Polite)?; + T::Assets::burn_from(&asset_id, account, amount, Exact, Polite)?; T::Assets::start_destroy(asset_id, None) } diff --git a/substrate/frame/nft-fractionalization/src/tests.rs b/substrate/frame/nft-fractionalization/src/tests.rs index 036cc668db2d..9add274ed8e6 100644 --- a/substrate/frame/nft-fractionalization/src/tests.rs +++ b/substrate/frame/nft-fractionalization/src/tests.rs @@ -91,10 +91,10 @@ fn fractionalize_should_work() { fractions, )); assert_eq!(assets(), vec![asset_id]); - assert_eq!(Assets::balance(asset_id, account(2)), fractions); + assert_eq!(Assets::balance(&asset_id, account(2)), fractions); assert_eq!(Balances::total_balance_on_hold(&account(1)), 2); - assert_eq!(String::from_utf8(Assets::name(0)).unwrap(), "Frac 0-0"); - assert_eq!(String::from_utf8(Assets::symbol(0)).unwrap(), "FRAC"); + assert_eq!(String::from_utf8(Assets::name(&0)).unwrap(), "Frac 0-0"); + assert_eq!(String::from_utf8(Assets::symbol(&0)).unwrap(), "FRAC"); assert_eq!(Nfts::owner(nft_collection_id, nft_id), Some(account(1))); assert_noop!( Nfts::transfer( @@ -256,7 +256,7 @@ fn unify_should_work() { account(1), )); - assert_eq!(Assets::balance(asset_id, account(2)), 0); + assert_eq!(Assets::balance(&asset_id, account(2)), 0); assert_eq!(Balances::reserved_balance(&account(1)), 1); assert_eq!(Nfts::owner(nft_collection_id, nft_id), Some(account(1))); assert!(!NftToAsset::::contains_key((&nft_collection_id, &nft_id))); @@ -279,8 +279,8 @@ fn unify_should_work() { fractions, )); assert_ok!(Assets::transfer(RuntimeOrigin::signed(account(1)), asset_id, account(2), 1)); - assert_eq!(Assets::balance(asset_id, account(1)), fractions - 1); - assert_eq!(Assets::balance(asset_id, account(2)), 1); + assert_eq!(Assets::balance(&asset_id, account(1)), fractions - 1); + assert_eq!(Assets::balance(&asset_id, account(2)), 1); assert_noop!( NftFractionalization::unify( RuntimeOrigin::signed(account(1)), diff --git a/substrate/frame/support/src/traits/tokens/fungible/item_of.rs b/substrate/frame/support/src/traits/tokens/fungible/item_of.rs index 5374cc52bab7..5735313b5818 100644 --- a/substrate/frame/support/src/traits/tokens/fungible/item_of.rs +++ b/substrate/frame/support/src/traits/tokens/fungible/item_of.rs @@ -49,36 +49,36 @@ impl< { type Balance = >::Balance; fn total_issuance() -> Self::Balance { - >::total_issuance(A::get()) + >::total_issuance(&A::get()) } fn active_issuance() -> Self::Balance { - >::active_issuance(A::get()) + >::active_issuance(&A::get()) } fn minimum_balance() -> Self::Balance { - >::minimum_balance(A::get()) + >::minimum_balance(&A::get()) } fn balance(who: &AccountId) -> Self::Balance { - >::balance(A::get(), who) + >::balance(&A::get(), who) } fn total_balance(who: &AccountId) -> Self::Balance { - >::total_balance(A::get(), who) + >::total_balance(&A::get(), who) } fn reducible_balance( who: &AccountId, preservation: Preservation, force: Fortitude, ) -> Self::Balance { - >::reducible_balance(A::get(), who, preservation, force) + >::reducible_balance(&A::get(), who, preservation, force) } fn can_deposit( who: &AccountId, amount: Self::Balance, provenance: Provenance, ) -> DepositConsequence { - >::can_deposit(A::get(), who, amount, provenance) + >::can_deposit(&A::get(), who, amount, provenance) } fn can_withdraw(who: &AccountId, amount: Self::Balance) -> WithdrawConsequence { - >::can_withdraw(A::get(), who, amount) + >::can_withdraw(&A::get(), who, amount) } } @@ -145,10 +145,10 @@ impl< who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError> { - >::write_balance(A::get(), who, amount) + >::write_balance(&A::get(), who, amount) } fn set_total_issuance(amount: Self::Balance) -> () { - >::set_total_issuance(A::get(), amount) + >::set_total_issuance(&A::get(), amount) } fn decrease_balance( who: &AccountId, @@ -158,7 +158,7 @@ impl< force: Fortitude, ) -> Result { >::decrease_balance( - A::get(), + &A::get(), who, amount, precision, @@ -171,7 +171,7 @@ impl< amount: Self::Balance, precision: Precision, ) -> Result { - >::increase_balance(A::get(), who, amount, precision) + >::increase_balance(&A::get(), who, amount, precision) } } @@ -230,7 +230,7 @@ impl< > Mutate for ItemOf { fn mint_into(who: &AccountId, amount: Self::Balance) -> Result { - >::mint_into(A::get(), who, amount) + >::mint_into(&A::get(), who, amount) } fn burn_from( who: &AccountId, @@ -238,13 +238,13 @@ impl< precision: Precision, force: Fortitude, ) -> Result { - >::burn_from(A::get(), who, amount, precision, force) + >::burn_from(&A::get(), who, amount, precision, force) } fn shelve(who: &AccountId, amount: Self::Balance) -> Result { - >::shelve(A::get(), who, amount) + >::shelve(&A::get(), who, amount) } fn restore(who: &AccountId, amount: Self::Balance) -> Result { - >::restore(A::get(), who, amount) + >::restore(&A::get(), who, amount) } fn transfer( source: &AccountId, @@ -252,11 +252,11 @@ impl< amount: Self::Balance, preservation: Preservation, ) -> Result { - >::transfer(A::get(), source, dest, amount, preservation) + >::transfer(&A::get(), source, dest, amount, preservation) } fn set_balance(who: &AccountId, amount: Self::Balance) -> Self::Balance { - >::set_balance(A::get(), who, amount) + >::set_balance(&A::get(), who, amount) } } @@ -387,21 +387,21 @@ impl< value: Self::Balance, precision: Precision, ) -> Result, DispatchError> { - >::deposit(A::get(), who, value, precision) + >::deposit(&A::get(), who, value, precision) .map(imbalance::from_fungibles) } fn issue(amount: Self::Balance) -> Credit { - let credit = >::issue(A::get(), amount); + let credit = >::issue(&A::get(), amount); imbalance::from_fungibles(credit) } fn pair( amount: Self::Balance, ) -> Result<(Debt, Credit), DispatchError> { - let (a, b) = >::pair(A::get(), amount)?; + let (a, b) = >::pair(&A::get(), amount)?; Ok((imbalance::from_fungibles(a), imbalance::from_fungibles(b))) } fn rescind(amount: Self::Balance) -> Debt { - let debt = >::rescind(A::get(), amount); + let debt = >::rescind(&A::get(), amount); imbalance::from_fungibles(debt) } fn resolve( diff --git a/substrate/frame/support/src/traits/tokens/fungible/union_of.rs b/substrate/frame/support/src/traits/tokens/fungible/union_of.rs index db44b2f43a4e..504b32b25a15 100644 --- a/substrate/frame/support/src/traits/tokens/fungible/union_of.rs +++ b/substrate/frame/support/src/traits/tokens/fungible/union_of.rs @@ -115,47 +115,47 @@ impl< type AssetId = AssetKind; type Balance = Left::Balance; - fn total_issuance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { + fn total_issuance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::total_issuance(), - Right(a) => >::total_issuance(a), + Right(a) => >::total_issuance(&a), } } - fn active_issuance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { + fn active_issuance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::active_issuance(), - Right(a) => >::active_issuance(a), + Right(a) => >::active_issuance(&a), } } - fn minimum_balance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { + fn minimum_balance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::minimum_balance(), - Right(a) => >::minimum_balance(a), + Right(a) => >::minimum_balance(&a), } } - fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - match Criterion::convert(asset) { + fn balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::balance(who), - Right(a) => >::balance(a, who), + Right(a) => >::balance(&a, who), } } - fn total_balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - match Criterion::convert(asset) { + fn total_balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::total_balance(who), - Right(a) => >::total_balance(a, who), + Right(a) => >::total_balance(&a, who), } } fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, preservation: Preservation, force: Fortitude, ) -> Self::Balance { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::reducible_balance(who, preservation, force), Right(a) => >::reducible_balance( - a, + &a, who, preservation, force, @@ -163,32 +163,32 @@ impl< } } fn can_deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, provenance: Provenance, ) -> DepositConsequence { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::can_deposit(who, amount, provenance), Right(a) => - >::can_deposit(a, who, amount, provenance), + >::can_deposit(&a, who, amount, provenance), } } fn can_withdraw( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> WithdrawConsequence { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::can_withdraw(who, amount), - Right(a) => >::can_withdraw(a, who, amount), + Right(a) => >::can_withdraw(&a, who, amount), } } - fn asset_exists(asset: Self::AssetId) -> bool { - match Criterion::convert(asset) { + fn asset_exists(asset: &Self::AssetId) -> bool { + match Criterion::convert(asset.clone()) { Left(()) => true, - Right(a) => >::asset_exists(a), + Right(a) => >::asset_exists(&a), } } } @@ -306,30 +306,30 @@ impl< } } fn write_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError> { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::write_balance(who, amount), - Right(a) => >::write_balance(a, who, amount), + Right(a) => >::write_balance(&a, who, amount), } } - fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance) -> () { - match Criterion::convert(asset) { + fn set_total_issuance(asset: &Self::AssetId, amount: Self::Balance) -> () { + match Criterion::convert(asset.clone()) { Left(()) => >::set_total_issuance(amount), - Right(a) => >::set_total_issuance(a, amount), + Right(a) => >::set_total_issuance(&a, amount), } } fn decrease_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::decrease_balance( who, amount, @@ -338,7 +338,7 @@ impl< force, ), Right(a) => >::decrease_balance( - a, + &a, who, amount, precision, @@ -348,16 +348,16 @@ impl< } } fn increase_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::increase_balance(who, amount, precision), Right(a) => >::increase_balance( - a, who, amount, precision, + &a, who, amount, precision, ), } } @@ -429,61 +429,62 @@ impl< > fungibles::Mutate for UnionOf { fn mint_into( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::mint_into(who, amount), - Right(a) => >::mint_into(a, who, amount), + Right(a) => >::mint_into(&a, who, amount), } } fn burn_from( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, force: Fortitude, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::burn_from(who, amount, precision, force), - Right(a) => - >::burn_from(a, who, amount, precision, force), + Right(a) => >::burn_from( + &a, who, amount, precision, force, + ), } } fn shelve( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::shelve(who, amount), - Right(a) => >::shelve(a, who, amount), + Right(a) => >::shelve(&a, who, amount), } } fn restore( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::restore(who, amount), - Right(a) => >::restore(a, who, amount), + Right(a) => >::restore(&a, who, amount), } } fn transfer( - asset: Self::AssetId, + asset: &Self::AssetId, source: &AccountId, dest: &AccountId, amount: Self::Balance, preservation: Preservation, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(()) => >::transfer(source, dest, amount, preservation), Right(a) => >::transfer( - a, + &a, source, dest, amount, @@ -492,10 +493,10 @@ impl< } } - fn set_balance(asset: Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { - match Criterion::convert(asset) { + fn set_balance(asset: &Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { + match Criterion::convert(asset.clone()) { Left(()) => >::set_balance(who, amount), - Right(a) => >::set_balance(a, who, amount), + Right(a) => >::set_balance(&a, who, amount), } } } @@ -701,33 +702,33 @@ impl< >; fn deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result, DispatchError> { match Criterion::convert(asset.clone()) { Left(()) => >::deposit(who, value, precision) - .map(|d| fungibles::imbalance::from_fungible(d, asset)), + .map(|d| fungibles::imbalance::from_fungible(d, asset.clone())), Right(a) => - >::deposit(a, who, value, precision) - .map(|d| fungibles::imbalance::from_fungibles(d, asset)), + >::deposit(&a, who, value, precision) + .map(|d| fungibles::imbalance::from_fungibles(d, asset.clone())), } } - fn issue(asset: Self::AssetId, amount: Self::Balance) -> fungibles::Credit { + fn issue(asset: &Self::AssetId, amount: Self::Balance) -> fungibles::Credit { match Criterion::convert(asset.clone()) { Left(()) => { let credit = >::issue(amount); - fungibles::imbalance::from_fungible(credit, asset) + fungibles::imbalance::from_fungible(credit, asset.clone()) }, Right(a) => { - let credit = >::issue(a, amount); - fungibles::imbalance::from_fungibles(credit, asset) + let credit = >::issue(&a, amount); + fungibles::imbalance::from_fungibles(credit, asset.clone()) }, } } fn pair( - asset: Self::AssetId, + asset: &Self::AssetId, amount: Self::Balance, ) -> Result<(fungibles::Debt, fungibles::Credit), DispatchError> { @@ -736,27 +737,27 @@ impl< let (a, b) = >::pair(amount)?; Ok(( fungibles::imbalance::from_fungible(a, asset.clone()), - fungibles::imbalance::from_fungible(b, asset), + fungibles::imbalance::from_fungible(b, asset.clone()), )) }, Right(a) => { - let (a, b) = >::pair(a, amount)?; + let (a, b) = >::pair(&a, amount)?; Ok(( fungibles::imbalance::from_fungibles(a, asset.clone()), - fungibles::imbalance::from_fungibles(b, asset), + fungibles::imbalance::from_fungibles(b, asset.clone()), )) }, } } - fn rescind(asset: Self::AssetId, amount: Self::Balance) -> fungibles::Debt { + fn rescind(asset: &Self::AssetId, amount: Self::Balance) -> fungibles::Debt { match Criterion::convert(asset.clone()) { Left(()) => { let debt = >::rescind(amount); - fungibles::imbalance::from_fungible(debt, asset) + fungibles::imbalance::from_fungible(debt, asset.clone()) }, Right(a) => { - let debt = >::rescind(a, amount); - fungibles::imbalance::from_fungibles(debt, asset) + let debt = >::rescind(&a, amount); + fungibles::imbalance::from_fungibles(debt, asset.clone()) }, } } diff --git a/substrate/frame/support/src/traits/tokens/fungibles/approvals.rs b/substrate/frame/support/src/traits/tokens/fungibles/approvals.rs index 09e3d20756a2..9ed2491cb5b3 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/approvals.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/approvals.rs @@ -22,7 +22,7 @@ use crate::dispatch::DispatchResult; pub trait Inspect: super::Inspect { // Check the amount approved by an owner to be spent by a delegate - fn allowance(asset: Self::AssetId, owner: &AccountId, delegate: &AccountId) -> Self::Balance; + fn allowance(asset: &Self::AssetId, owner: &AccountId, delegate: &AccountId) -> Self::Balance; } pub trait Mutate: Inspect { diff --git a/substrate/frame/support/src/traits/tokens/fungibles/freeze.rs b/substrate/frame/support/src/traits/tokens/fungibles/freeze.rs index 244f70058994..3ceaed550238 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/freeze.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/freeze.rs @@ -41,7 +41,7 @@ pub trait Inspect: super::Inspect { /// The amount of the balance which can become frozen. Defaults to `total_balance()`. fn balance_freezable(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - Self::total_balance(asset, who) + Self::total_balance(&asset, who) } /// Returns `true` if it's possible to introduce a freeze for the given `id` onto the diff --git a/substrate/frame/support/src/traits/tokens/fungibles/hold.rs b/substrate/frame/support/src/traits/tokens/fungibles/hold.rs index ef3fef7a300d..aacf633e53b3 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/hold.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/hold.rs @@ -106,7 +106,7 @@ pub trait Inspect: super::Inspect { ) -> DispatchResult { ensure!(Self::hold_available(asset.clone(), reason, who), TokenError::CannotCreateHold); ensure!( - amount <= Self::reducible_balance(asset, who, Protect, Force), + amount <= Self::reducible_balance(&asset, who, Protect, Force), TokenError::FundsUnavailable ); Ok(()) @@ -265,7 +265,7 @@ pub trait Mutate: Self::ensure_can_hold(asset.clone(), reason, who, amount)?; // Should be infallible now, but we proceed softly anyway. - Self::decrease_balance(asset.clone(), who, amount, Exact, Protect, Force)?; + Self::decrease_balance(&asset, who, amount, Exact, Protect, Force)?; Self::increase_balance_on_hold(asset.clone(), reason, who, amount, BestEffort)?; Self::done_hold(asset, reason, who, amount); Ok(()) @@ -290,7 +290,7 @@ pub trait Mutate: // We want to make sure we can deposit the amount in advance. If we can't then something is // very wrong. ensure!( - Self::can_deposit(asset.clone(), who, amount, Extant) == Success, + Self::can_deposit(&asset, who, amount, Extant) == Success, TokenError::CannotCreate ); // Get the amount we can actually take from the hold. This might be less than what we want @@ -298,7 +298,7 @@ pub trait Mutate: let amount = Self::decrease_balance_on_hold(asset.clone(), reason, who, amount, precision)?; // Increase the main balance by what we took. We always do a best-effort here because we // already checked that we can deposit before. - let actual = Self::increase_balance(asset.clone(), who, amount, BestEffort)?; + let actual = Self::increase_balance(&asset, who, amount, BestEffort)?; Self::done_release(asset, reason, who, actual); Ok(actual) } @@ -329,10 +329,7 @@ pub trait Mutate: ensure!(amount <= liquid, TokenError::Frozen); } let amount = Self::decrease_balance_on_hold(asset.clone(), reason, who, amount, precision)?; - Self::set_total_issuance( - asset.clone(), - Self::total_issuance(asset.clone()).saturating_sub(amount), - ); + Self::set_total_issuance(&asset, Self::total_issuance(&asset).saturating_sub(amount)); Self::done_burn_held(asset, reason, who, amount); Ok(amount) } @@ -396,7 +393,7 @@ pub trait Mutate: // We want to make sure we can deposit the amount in advance. If we can't then something is // very wrong. ensure!( - Self::can_deposit(asset.clone(), dest, amount, Extant) == Success, + Self::can_deposit(&asset, dest, amount, Extant) == Success, TokenError::CannotCreate ); ensure!( @@ -409,7 +406,7 @@ pub trait Mutate: let actual = if mode == OnHold { Self::increase_balance_on_hold(asset.clone(), reason, dest, amount, precision)? } else { - Self::increase_balance(asset.clone(), dest, amount, precision)? + Self::increase_balance(&asset, dest, amount, precision)? }; Self::done_transfer_on_hold(asset, reason, source, dest, actual); Ok(actual) @@ -444,11 +441,11 @@ pub trait Mutate: ) -> Result { ensure!(Self::hold_available(asset.clone(), reason, dest), TokenError::CannotCreateHold); ensure!( - Self::can_deposit(asset.clone(), dest, amount, Extant) == Success, + Self::can_deposit(&asset, dest, amount, Extant) == Success, TokenError::CannotCreate ); let actual = - Self::decrease_balance(asset.clone(), source, amount, precision, expendability, force)?; + Self::decrease_balance(&asset, source, amount, precision, expendability, force)?; Self::increase_balance_on_hold(asset.clone(), reason, dest, actual, precision)?; Self::done_transfer_on_hold(asset, reason, source, dest, actual); Ok(actual) diff --git a/substrate/frame/support/src/traits/tokens/fungibles/metadata.rs b/substrate/frame/support/src/traits/tokens/fungibles/metadata.rs index ab722426dadf..c7cdd8d2a6a6 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/metadata.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/metadata.rs @@ -24,11 +24,11 @@ use sp_std::vec::Vec; pub trait Inspect: super::Inspect { // Get name for an AssetId. - fn name(asset: Self::AssetId) -> Vec; + fn name(asset: &Self::AssetId) -> Vec; // Get symbol for an AssetId. - fn symbol(asset: Self::AssetId) -> Vec; + fn symbol(asset: &Self::AssetId) -> Vec; // Get decimals for an AssetId. - fn decimals(asset: Self::AssetId) -> u8; + fn decimals(asset: &Self::AssetId) -> u8; } pub trait Mutate: Inspect { diff --git a/substrate/frame/support/src/traits/tokens/fungibles/regular.rs b/substrate/frame/support/src/traits/tokens/fungibles/regular.rs index b30e0ae3a2a3..aa2ef407baf9 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/regular.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/regular.rs @@ -52,16 +52,16 @@ pub trait Inspect: Sized { type Balance: Balance; /// The total amount of issuance in the system. - fn total_issuance(asset: Self::AssetId) -> Self::Balance; + fn total_issuance(asset: &Self::AssetId) -> Self::Balance; /// The total amount of issuance in the system excluding those which are controlled by the /// system. - fn active_issuance(asset: Self::AssetId) -> Self::Balance { + fn active_issuance(asset: &Self::AssetId) -> Self::Balance { Self::total_issuance(asset) } /// The minimum balance any single account may have. - fn minimum_balance(asset: Self::AssetId) -> Self::Balance; + fn minimum_balance(asset: &Self::AssetId) -> Self::Balance; /// Get the total amount of funds whose ultimate beneficial ownership can be determined as /// `who`. @@ -74,14 +74,14 @@ pub trait Inspect: Sized { /// /// For the amount of the balance which may eventually be free to be removed from the account, /// use `balance()`. - fn total_balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance; + fn total_balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance; /// Get the balance of `who` which does not include funds which are exclusively allocated to /// subsystems of the chain ("on hold" or "reserved"). /// /// In general this isn't especially useful outside of tests, and for practical purposes, you'll /// want to use `reducible_balance()`. - fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance; + fn balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance; /// Get the maximum amount that `who` can withdraw/transfer successfully based on whether the /// account should be kept alive (`preservation`) or whether we are willing to force the @@ -90,7 +90,7 @@ pub trait Inspect: Sized { /// /// Always less than `free_balance()`. fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, preservation: Preservation, force: Fortitude, @@ -103,7 +103,7 @@ pub trait Inspect: Sized { /// - `amount`: How much should the balance be increased? /// - `mint`: Will `amount` be minted to deposit it into `account`? fn can_deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, provenance: Provenance, @@ -112,13 +112,13 @@ pub trait Inspect: Sized { /// Returns `Failed` if the `asset` balance of `who` may not be decreased by `amount`, otherwise /// the consequence. fn can_withdraw( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> WithdrawConsequence; /// Returns `true` if an `asset` exists. - fn asset_exists(asset: Self::AssetId) -> bool; + fn asset_exists(asset: &Self::AssetId) -> bool; } /// Special dust type which can be type-safely converted into a `Credit`. @@ -147,10 +147,8 @@ pub trait Unbalanced: Inspect { /// /// This should not be reimplemented. fn handle_raw_dust(asset: Self::AssetId, amount: Self::Balance) { - Self::handle_dust(Dust( - asset.clone(), - amount.min(Self::minimum_balance(asset).saturating_sub(One::one())), - )) + let minimum_balance = Self::minimum_balance(&asset).saturating_sub(One::one()); + Self::handle_dust(Dust(asset, amount.min(minimum_balance))) } /// Do something with the dust which has been destroyed from the system. `Dust` can be converted @@ -169,13 +167,13 @@ pub trait Unbalanced: Inspect { /// If this cannot be done for some reason (e.g. because the account cannot be created, deleted /// or would overflow) then an `Err` is returned. fn write_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError>; /// Set the total issuance to `amount`. - fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance); + fn set_total_issuance(asset: &Self::AssetId, amount: Self::Balance); /// Reduce the balance of `who` by `amount`. /// @@ -188,22 +186,22 @@ pub trait Unbalanced: Inspect { /// `Self::minimum_balance() - 1` greater than `amount` in the case that the reduction caused /// the account to be deleted. fn decrease_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, mut amount: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result { - let old_balance = Self::balance(asset.clone(), who); - let reducible = Self::reducible_balance(asset.clone(), who, preservation, force); + let old_balance = Self::balance(asset, who); + let reducible = Self::reducible_balance(asset, who, preservation, force); match precision { BestEffort => amount = amount.min(reducible), Exact => ensure!(reducible >= amount, TokenError::FundsUnavailable), } let new_balance = old_balance.checked_sub(&amount).ok_or(TokenError::FundsUnavailable)?; - if let Some(dust) = Self::write_balance(asset.clone(), who, new_balance)? { - Self::handle_dust(Dust(asset, dust)); + if let Some(dust) = Self::write_balance(asset, who, new_balance)? { + Self::handle_dust(Dust(asset.clone(), dust)); } Ok(old_balance.saturating_sub(new_balance)) } @@ -215,18 +213,18 @@ pub trait Unbalanced: Inspect { /// Minimum balance will be respected and an error will be returned if /// `amount < Self::minimum_balance()` when the account of `who` is zero. fn increase_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result { - let old_balance = Self::balance(asset.clone(), who); + let old_balance = Self::balance(asset, who); let new_balance = if let BestEffort = precision { old_balance.saturating_add(amount) } else { old_balance.checked_add(&amount).ok_or(ArithmeticError::Overflow)? }; - if new_balance < Self::minimum_balance(asset.clone()) { + if new_balance < Self::minimum_balance(asset) { // Attempt to increase from 0 to below minimum -> stays at zero. if let BestEffort = precision { Ok(Self::Balance::default()) @@ -237,8 +235,8 @@ pub trait Unbalanced: Inspect { if new_balance == old_balance { Ok(Self::Balance::default()) } else { - if let Some(dust) = Self::write_balance(asset.clone(), who, new_balance)? { - Self::handle_dust(Dust(asset, dust)); + if let Some(dust) = Self::write_balance(asset, who, new_balance)? { + Self::handle_dust(Dust(asset.clone(), dust)); } Ok(new_balance.saturating_sub(old_balance)) } @@ -246,10 +244,10 @@ pub trait Unbalanced: Inspect { } /// Reduce the active issuance by some amount. - fn deactivate(_asset: Self::AssetId, _: Self::Balance) {} + fn deactivate(_asset: &Self::AssetId, _: Self::Balance) {} /// Increase the active issuance by some amount, up to the outstanding amount reduced. - fn reactivate(_asset: Self::AssetId, _: Self::Balance) {} + fn reactivate(_asset: &Self::AssetId, _: Self::Balance) {} } /// Trait for providing a basic fungible asset. @@ -260,18 +258,15 @@ where /// Increase the balance of `who` by exactly `amount`, minting new tokens. If that isn't /// possible then an `Err` is returned and nothing is changed. fn mint_into( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - Self::total_issuance(asset.clone()) + Self::total_issuance(asset) .checked_add(&amount) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::increase_balance(asset.clone(), who, amount, Exact)?; - Self::set_total_issuance( - asset.clone(), - Self::total_issuance(asset.clone()).saturating_add(actual), - ); + let actual = Self::increase_balance(asset, who, amount, Exact)?; + Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_add(actual)); Self::done_mint_into(asset, who, amount); Ok(actual) } @@ -280,23 +275,19 @@ where /// minimum-balance requirements, burning the tokens. If that isn't possible then an `Err` is /// returned and nothing is changed. If successful, the amount of tokens reduced is returned. fn burn_from( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, force: Fortitude, ) -> Result { - let actual = Self::reducible_balance(asset.clone(), who, Expendable, force).min(amount); + let actual = Self::reducible_balance(asset, who, Expendable, force).min(amount); ensure!(actual == amount || precision == BestEffort, TokenError::FundsUnavailable); - Self::total_issuance(asset.clone()) + Self::total_issuance(asset) .checked_sub(&actual) .ok_or(ArithmeticError::Overflow)?; - let actual = - Self::decrease_balance(asset.clone(), who, actual, BestEffort, Expendable, force)?; - Self::set_total_issuance( - asset.clone(), - Self::total_issuance(asset.clone()).saturating_sub(actual), - ); + let actual = Self::decrease_balance(asset, who, actual, BestEffort, Expendable, force)?; + Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_sub(actual)); Self::done_burn_from(asset, who, actual); Ok(actual) } @@ -312,21 +303,17 @@ where /// Because of this expectation, any metadata associated with the asset is expected to survive /// the suspect-resume cycle. fn shelve( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - let actual = Self::reducible_balance(asset.clone(), who, Expendable, Polite).min(amount); + let actual = Self::reducible_balance(asset, who, Expendable, Polite).min(amount); ensure!(actual == amount, TokenError::FundsUnavailable); - Self::total_issuance(asset.clone()) + Self::total_issuance(asset) .checked_sub(&actual) .ok_or(ArithmeticError::Overflow)?; - let actual = - Self::decrease_balance(asset.clone(), who, actual, BestEffort, Expendable, Polite)?; - Self::set_total_issuance( - asset.clone(), - Self::total_issuance(asset.clone()).saturating_sub(actual), - ); + let actual = Self::decrease_balance(asset, who, actual, BestEffort, Expendable, Polite)?; + Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_sub(actual)); Self::done_shelve(asset, who, actual); Ok(actual) } @@ -342,18 +329,15 @@ where /// Because of this expectation, any metadata associated with the asset is expected to survive /// the suspect-resume cycle. fn restore( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - Self::total_issuance(asset.clone()) + Self::total_issuance(asset) .checked_add(&amount) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::increase_balance(asset.clone(), who, amount, Exact)?; - Self::set_total_issuance( - asset.clone(), - Self::total_issuance(asset.clone()).saturating_add(actual), - ); + let actual = Self::increase_balance(asset, who, amount, Exact)?; + Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_add(actual)); Self::done_restore(asset, who, amount); Ok(actual) } @@ -363,23 +347,23 @@ where /// A transfer where the source and destination account are identical is treated as No-OP after /// checking the preconditions. fn transfer( - asset: Self::AssetId, + asset: &Self::AssetId, source: &AccountId, dest: &AccountId, amount: Self::Balance, preservation: Preservation, ) -> Result { - let _extra = Self::can_withdraw(asset.clone(), source, amount) - .into_result(preservation != Expendable)?; - Self::can_deposit(asset.clone(), dest, amount, Extant).into_result()?; + let _extra = + Self::can_withdraw(asset, source, amount).into_result(preservation != Expendable)?; + Self::can_deposit(asset, dest, amount, Extant).into_result()?; if source == dest { return Ok(amount) } - Self::decrease_balance(asset.clone(), source, amount, BestEffort, preservation, Polite)?; + Self::decrease_balance(asset, source, amount, BestEffort, preservation, Polite)?; // This should never fail as we checked `can_deposit` earlier. But we do a best-effort // anyway. - let _ = Self::increase_balance(asset.clone(), dest, amount, BestEffort); + let _ = Self::increase_balance(asset, dest, amount, BestEffort); Self::done_transfer(asset, source, dest, amount); Ok(amount) } @@ -389,8 +373,8 @@ where /// error reporting. /// /// Returns the new balance. - fn set_balance(asset: Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { - let b = Self::balance(asset.clone(), who); + fn set_balance(asset: &Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { + let b = Self::balance(asset, who); if b > amount { Self::burn_from(asset, who, b - amount, BestEffort, Force).map(|d| b.saturating_sub(d)) } else { @@ -398,12 +382,12 @@ where } .unwrap_or(b) } - fn done_mint_into(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} - fn done_burn_from(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} - fn done_shelve(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} - fn done_restore(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_mint_into(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_burn_from(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_shelve(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_restore(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} fn done_transfer( - _asset: Self::AssetId, + _asset: &Self::AssetId, _source: &AccountId, _dest: &AccountId, _amount: Self::Balance, @@ -418,7 +402,7 @@ impl> HandleImbalanceDrop { fn handle(asset: U::AssetId, amount: U::Balance) { - U::set_total_issuance(asset.clone(), U::total_issuance(asset).saturating_add(amount)) + U::set_total_issuance(&asset, U::total_issuance(&asset).saturating_add(amount)) } } @@ -429,7 +413,7 @@ impl> HandleImbalanceDrop { fn handle(asset: U::AssetId, amount: U::Balance) { - U::set_total_issuance(asset.clone(), U::total_issuance(asset).saturating_sub(amount)) + U::set_total_issuance(&asset, U::total_issuance(&asset).saturating_sub(amount)) } } @@ -449,14 +433,15 @@ pub trait Balanced: Inspect + Unbalanced { /// /// This is infallible, but doesn't guarantee that the entire `amount` is burnt, for example /// in the case of underflow. - fn rescind(asset: Self::AssetId, amount: Self::Balance) -> Debt { - let old = Self::total_issuance(asset.clone()); + fn rescind(asset: &Self::AssetId, amount: Self::Balance) -> Debt { + let old = Self::total_issuance(asset); let new = old.saturating_sub(amount); - Self::set_total_issuance(asset.clone(), new); + Self::set_total_issuance(asset, new); let delta = old - new; - Self::done_rescind(asset.clone(), delta); + Self::done_rescind(asset, delta); Imbalance::::new( - asset, delta, + asset.clone(), + delta, ) } @@ -466,14 +451,15 @@ pub trait Balanced: Inspect + Unbalanced { /// /// This is infallible, but doesn't guarantee that the entire `amount` is issued, for example /// in the case of overflow. - fn issue(asset: Self::AssetId, amount: Self::Balance) -> Credit { - let old = Self::total_issuance(asset.clone()); + fn issue(asset: &Self::AssetId, amount: Self::Balance) -> Credit { + let old = Self::total_issuance(asset); let new = old.saturating_add(amount); - Self::set_total_issuance(asset.clone(), new); + Self::set_total_issuance(asset, new); let delta = new - old; - Self::done_issue(asset.clone(), delta); + Self::done_issue(asset, delta); Imbalance::::new( - asset, delta, + asset.clone(), + delta, ) } @@ -486,10 +472,10 @@ pub trait Balanced: Inspect + Unbalanced { /// pair, for example in the case where the amounts would cause overflow or underflow in /// [`Balanced::issue`] or [`Balanced::rescind`]. fn pair( - asset: Self::AssetId, + asset: &Self::AssetId, amount: Self::Balance, ) -> Result<(Debt, Credit), DispatchError> { - let issued = Self::issue(asset.clone(), amount); + let issued = Self::issue(asset, amount); let rescinded = Self::rescind(asset, amount); // Need to check amount in case by some edge case both issued and rescinded are below // `amount` by the exact same value @@ -511,15 +497,16 @@ pub trait Balanced: Inspect + Unbalanced { /// If the operation is successful, this will return `Ok` with a `Debt` of the total value /// added to the account. fn deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result, DispatchError> { - let increase = Self::increase_balance(asset.clone(), who, value, precision)?; - Self::done_deposit(asset.clone(), who, increase); + let increase = Self::increase_balance(asset, who, value, precision)?; + Self::done_deposit(asset, who, increase); Ok(Imbalance::::new( - asset, increase, + asset.clone(), + increase, )) } @@ -544,9 +531,8 @@ pub trait Balanced: Inspect + Unbalanced { preservation: Preservation, force: Fortitude, ) -> Result, DispatchError> { - let decrease = - Self::decrease_balance(asset.clone(), who, value, precision, preservation, force)?; - Self::done_withdraw(asset.clone(), who, decrease); + let decrease = Self::decrease_balance(&asset, who, value, precision, preservation, force)?; + Self::done_withdraw(&asset, who, decrease); Ok(Imbalance::::new( asset, decrease, )) @@ -563,7 +549,7 @@ pub trait Balanced: Inspect + Unbalanced { credit: Credit, ) -> Result<(), Credit> { let v = credit.peek(); - let debt = match Self::deposit(credit.asset(), who, v, Exact) { + let debt = match Self::deposit(&credit.asset(), who, v, Exact) { Err(_) => return Err(credit), Ok(d) => d, }; @@ -604,10 +590,10 @@ pub trait Balanced: Inspect + Unbalanced { } } - fn done_rescind(_asset: Self::AssetId, _amount: Self::Balance) {} - fn done_issue(_asset: Self::AssetId, _amount: Self::Balance) {} - fn done_deposit(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} - fn done_withdraw(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_rescind(_asset: &Self::AssetId, _amount: Self::Balance) {} + fn done_issue(_asset: &Self::AssetId, _amount: Self::Balance) {} + fn done_deposit(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} + fn done_withdraw(_asset: &Self::AssetId, _who: &AccountId, _amount: Self::Balance) {} } /// Dummy implementation of [`Inspect`] @@ -615,20 +601,20 @@ pub trait Balanced: Inspect + Unbalanced { impl Inspect for () { type AssetId = u32; type Balance = u32; - fn total_issuance(_: Self::AssetId) -> Self::Balance { + fn total_issuance(_: &Self::AssetId) -> Self::Balance { 0 } - fn minimum_balance(_: Self::AssetId) -> Self::Balance { + fn minimum_balance(_: &Self::AssetId) -> Self::Balance { 0 } - fn total_balance(_: Self::AssetId, _: &AccountId) -> Self::Balance { + fn total_balance(_: &Self::AssetId, _: &AccountId) -> Self::Balance { 0 } - fn balance(_: Self::AssetId, _: &AccountId) -> Self::Balance { + fn balance(_: &Self::AssetId, _: &AccountId) -> Self::Balance { 0 } fn reducible_balance( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Preservation, _: Fortitude, @@ -636,7 +622,7 @@ impl Inspect for () { 0 } fn can_deposit( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Self::Balance, _: Provenance, @@ -644,13 +630,13 @@ impl Inspect for () { DepositConsequence::Success } fn can_withdraw( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Self::Balance, ) -> WithdrawConsequence { WithdrawConsequence::Success } - fn asset_exists(_: Self::AssetId) -> bool { + fn asset_exists(_: &Self::AssetId) -> bool { false } } @@ -660,13 +646,13 @@ impl Inspect for () { impl Unbalanced for () { fn handle_dust(_: Dust) {} fn write_balance( - _: Self::AssetId, + _: &Self::AssetId, _: &AccountId, _: Self::Balance, ) -> Result, DispatchError> { Ok(None) } - fn set_total_issuance(_: Self::AssetId, _: Self::Balance) {} + fn set_total_issuance(_: &Self::AssetId, _: Self::Balance) {} } /// Dummy implementation of [`Mutate`] diff --git a/substrate/frame/support/src/traits/tokens/fungibles/roles.rs b/substrate/frame/support/src/traits/tokens/fungibles/roles.rs index 3e68d6b94518..992ac21a2e32 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/roles.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/roles.rs @@ -23,13 +23,13 @@ use sp_runtime::DispatchResult; pub trait Inspect: super::Inspect { // Get owner for an AssetId. - fn owner(asset: Self::AssetId) -> Option; + fn owner(asset: &Self::AssetId) -> Option; // Get issuer for an AssetId. - fn issuer(asset: Self::AssetId) -> Option; + fn issuer(asset: &Self::AssetId) -> Option; // Get admin for an AssetId. - fn admin(asset: Self::AssetId) -> Option; + fn admin(asset: &Self::AssetId) -> Option; // Get freezer for an AssetId. - fn freezer(asset: Self::AssetId) -> Option; + fn freezer(asset: &Self::AssetId) -> Option; } /// Trait for resetting the team configuration of an existing fungible asset. diff --git a/substrate/frame/support/src/traits/tokens/fungibles/union_of.rs b/substrate/frame/support/src/traits/tokens/fungibles/union_of.rs index 2c7d4bab7baa..f58c38290bbc 100644 --- a/substrate/frame/support/src/traits/tokens/fungibles/union_of.rs +++ b/substrate/frame/support/src/traits/tokens/fungibles/union_of.rs @@ -55,51 +55,51 @@ impl< type AssetId = AssetKind; type Balance = Left::Balance; - fn total_issuance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::total_issuance(a), - Right(a) => >::total_issuance(a), + fn total_issuance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::total_issuance(&a), + Right(a) => >::total_issuance(&a), } } - fn active_issuance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::active_issuance(a), - Right(a) => >::active_issuance(a), + fn active_issuance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::active_issuance(&a), + Right(a) => >::active_issuance(&a), } } - fn minimum_balance(asset: Self::AssetId) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::minimum_balance(a), - Right(a) => >::minimum_balance(a), + fn minimum_balance(asset: &Self::AssetId) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::minimum_balance(&a), + Right(a) => >::minimum_balance(&a), } } - fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::balance(a, who), - Right(a) => >::balance(a, who), + fn balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::balance(&a, who), + Right(a) => >::balance(&a, who), } } - fn total_balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::total_balance(a, who), - Right(a) => >::total_balance(a, who), + fn total_balance(asset: &Self::AssetId, who: &AccountId) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::total_balance(&a, who), + Right(a) => >::total_balance(&a, who), } } fn reducible_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, preservation: Preservation, force: Fortitude, ) -> Self::Balance { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => >::reducible_balance( - a, + &a, who, preservation, force, ), Right(a) => >::reducible_balance( - a, + &a, who, preservation, force, @@ -107,32 +107,32 @@ impl< } } fn can_deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, provenance: Provenance, ) -> DepositConsequence { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => - >::can_deposit(a, who, amount, provenance), + >::can_deposit(&a, who, amount, provenance), Right(a) => - >::can_deposit(a, who, amount, provenance), + >::can_deposit(&a, who, amount, provenance), } } fn can_withdraw( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> WithdrawConsequence { - match Criterion::convert(asset) { - Left(a) => >::can_withdraw(a, who, amount), - Right(a) => >::can_withdraw(a, who, amount), + match Criterion::convert(asset.clone()) { + Left(a) => >::can_withdraw(&a, who, amount), + Right(a) => >::can_withdraw(&a, who, amount), } } - fn asset_exists(asset: Self::AssetId) -> bool { - match Criterion::convert(asset) { - Left(a) => >::asset_exists(a), - Right(a) => >::asset_exists(a), + fn asset_exists(asset: &Self::AssetId) -> bool { + match Criterion::convert(asset.clone()) { + Left(a) => >::asset_exists(&a), + Right(a) => >::asset_exists(&a), } } } @@ -251,32 +251,32 @@ impl< } } fn write_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result, DispatchError> { - match Criterion::convert(asset) { - Left(a) => >::write_balance(a, who, amount), - Right(a) => >::write_balance(a, who, amount), + match Criterion::convert(asset.clone()) { + Left(a) => >::write_balance(&a, who, amount), + Right(a) => >::write_balance(&a, who, amount), } } - fn set_total_issuance(asset: Self::AssetId, amount: Self::Balance) -> () { - match Criterion::convert(asset) { - Left(a) => >::set_total_issuance(a, amount), - Right(a) => >::set_total_issuance(a, amount), + fn set_total_issuance(asset: &Self::AssetId, amount: Self::Balance) -> () { + match Criterion::convert(asset.clone()) { + Left(a) => >::set_total_issuance(&a, amount), + Right(a) => >::set_total_issuance(&a, amount), } } fn decrease_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => >::decrease_balance( - a, + &a, who, amount, precision, @@ -284,7 +284,7 @@ impl< force, ), Right(a) => >::decrease_balance( - a, + &a, who, amount, precision, @@ -294,17 +294,17 @@ impl< } } fn increase_balance( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => >::increase_balance( - a, who, amount, precision, + &a, who, amount, precision, ), Right(a) => >::increase_balance( - a, who, amount, precision, + &a, who, amount, precision, ), } } @@ -376,66 +376,67 @@ impl< > fungibles::Mutate for UnionOf { fn mint_into( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { - Left(a) => >::mint_into(a, who, amount), - Right(a) => >::mint_into(a, who, amount), + match Criterion::convert(asset.clone()) { + Left(a) => >::mint_into(&a, who, amount), + Right(a) => >::mint_into(&a, who, amount), } } fn burn_from( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, precision: Precision, force: Fortitude, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => - >::burn_from(a, who, amount, precision, force), - Right(a) => - >::burn_from(a, who, amount, precision, force), + >::burn_from(&a, who, amount, precision, force), + Right(a) => >::burn_from( + &a, who, amount, precision, force, + ), } } fn shelve( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { - Left(a) => >::shelve(a, who, amount), - Right(a) => >::shelve(a, who, amount), + match Criterion::convert(asset.clone()) { + Left(a) => >::shelve(&a, who, amount), + Right(a) => >::shelve(&a, who, amount), } } fn restore( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, amount: Self::Balance, ) -> Result { - match Criterion::convert(asset) { - Left(a) => >::restore(a, who, amount), - Right(a) => >::restore(a, who, amount), + match Criterion::convert(asset.clone()) { + Left(a) => >::restore(&a, who, amount), + Right(a) => >::restore(&a, who, amount), } } fn transfer( - asset: Self::AssetId, + asset: &Self::AssetId, source: &AccountId, dest: &AccountId, amount: Self::Balance, preservation: Preservation, ) -> Result { - match Criterion::convert(asset) { + match Criterion::convert(asset.clone()) { Left(a) => >::transfer( - a, + &a, source, dest, amount, preservation, ), Right(a) => >::transfer( - a, + &a, source, dest, amount, @@ -444,10 +445,10 @@ impl< } } - fn set_balance(asset: Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { - match Criterion::convert(asset) { - Left(a) => >::set_balance(a, who, amount), - Right(a) => >::set_balance(a, who, amount), + fn set_balance(asset: &Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { + match Criterion::convert(asset.clone()) { + Left(a) => >::set_balance(&a, who, amount), + Right(a) => >::set_balance(&a, who, amount), } } } @@ -680,62 +681,62 @@ impl< >; fn deposit( - asset: Self::AssetId, + asset: &Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result, DispatchError> { match Criterion::convert(asset.clone()) { - Left(a) => >::deposit(a, who, value, precision) - .map(|debt| imbalance::from_fungibles(debt, asset)), + Left(a) => >::deposit(&a, who, value, precision) + .map(|debt| imbalance::from_fungibles(debt, asset.clone())), Right(a) => - >::deposit(a, who, value, precision) - .map(|debt| imbalance::from_fungibles(debt, asset)), + >::deposit(&a, who, value, precision) + .map(|debt| imbalance::from_fungibles(debt, asset.clone())), } } - fn issue(asset: Self::AssetId, amount: Self::Balance) -> fungibles::Credit { + fn issue(asset: &Self::AssetId, amount: Self::Balance) -> fungibles::Credit { match Criterion::convert(asset.clone()) { Left(a) => { - let credit = >::issue(a, amount); - imbalance::from_fungibles(credit, asset) + let credit = >::issue(&a, amount); + imbalance::from_fungibles(credit, asset.clone()) }, Right(a) => { - let credit = >::issue(a, amount); - imbalance::from_fungibles(credit, asset) + let credit = >::issue(&a, amount); + imbalance::from_fungibles(credit, asset.clone()) }, } } fn pair( - asset: Self::AssetId, + asset: &Self::AssetId, amount: Self::Balance, ) -> Result<(fungibles::Debt, fungibles::Credit), DispatchError> { match Criterion::convert(asset.clone()) { Left(a) => { - let (a, b) = >::pair(a, amount)?; + let (a, b) = >::pair(&a, amount)?; Ok(( imbalance::from_fungibles(a, asset.clone()), - imbalance::from_fungibles(b, asset), + imbalance::from_fungibles(b, asset.clone()), )) }, Right(a) => { - let (a, b) = >::pair(a, amount)?; + let (a, b) = >::pair(&a, amount)?; Ok(( imbalance::from_fungibles(a, asset.clone()), - imbalance::from_fungibles(b, asset), + imbalance::from_fungibles(b, asset.clone()), )) }, } } - fn rescind(asset: Self::AssetId, amount: Self::Balance) -> fungibles::Debt { + fn rescind(asset: &Self::AssetId, amount: Self::Balance) -> fungibles::Debt { match Criterion::convert(asset.clone()) { Left(a) => { - let debt = >::rescind(a, amount); - imbalance::from_fungibles(debt, asset) + let debt = >::rescind(&a, amount); + imbalance::from_fungibles(debt, asset.clone()) }, Right(a) => { - let debt = >::rescind(a, amount); - imbalance::from_fungibles(debt, asset) + let debt = >::rescind(&a, amount); + imbalance::from_fungibles(debt, asset.clone()) }, } } diff --git a/substrate/frame/support/src/traits/tokens/pay.rs b/substrate/frame/support/src/traits/tokens/pay.rs index 62d7a056a3f1..adbc2ce75ba8 100644 --- a/substrate/frame/support/src/traits/tokens/pay.rs +++ b/substrate/frame/support/src/traits/tokens/pay.rs @@ -132,7 +132,7 @@ where asset: Self::AssetKind, amount: Self::Balance, ) -> Result { - >::transfer(asset, &A::get(), who, amount, Expendable)?; + >::transfer(&asset, &A::get(), who, amount, Expendable)?; Ok(()) } fn check_payment(_: ()) -> PaymentStatus { @@ -141,7 +141,7 @@ where #[cfg(feature = "runtime-benchmarks")] fn ensure_successful(_: &Self::Beneficiary, asset: Self::AssetKind, amount: Self::Balance) { >::create(asset.clone(), A::get(), true, amount).unwrap(); - >::mint_into(asset, &A::get(), amount).unwrap(); + >::mint_into(&asset, &A::get(), amount).unwrap(); } #[cfg(feature = "runtime-benchmarks")] fn ensure_concluded(_: Self::Id) {} diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs index aa2f26f3a6a8..f939f52f288c 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs @@ -113,7 +113,7 @@ fn default_post_info() -> PostDispatchInfo { fn setup_lp(asset_id: u32, balance_factor: u64) { let lp_provider = 5; let ed = Balances::minimum_balance(); - let ed_asset = Assets::minimum_balance(asset_id); + let ed_asset = Assets::minimum_balance(&asset_id); assert_ok!(Balances::force_set_balance( RuntimeOrigin::root(), lp_provider, @@ -121,7 +121,7 @@ fn setup_lp(asset_id: u32, balance_factor: u64) { )); let lp_provider_account = ::Lookup::unlookup(lp_provider); assert_ok!(Assets::mint_into( - asset_id.into(), + &asset_id, &lp_provider_account, 10_000 * balance_factor + ed_asset )); @@ -219,8 +219,8 @@ fn transaction_payment_in_asset_possible() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let len = 10; let tx_weight = 5; @@ -229,15 +229,15 @@ fn transaction_payment_in_asset_possible() { let fee_in_native = base_weight + tx_weight + len as u64; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); assert_eq!(input_quote, Some(201)); let fee_in_asset = input_quote.unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_5), len) @@ -246,7 +246,7 @@ fn transaction_payment_in_asset_possible() { assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); System::assert_has_event(RuntimeEvent::Assets(pallet_assets::Event::Withdrawn { asset_id, @@ -262,7 +262,7 @@ fn transaction_payment_in_asset_possible() { &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); assert_eq!(TipUnbalancedAmount::get(), 0); assert_eq!(FeeUnbalancedAmount::get(), fee_in_native); }); @@ -293,8 +293,8 @@ fn transaction_payment_in_asset_fails_if_no_pool_for_that_asset() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let len = 10; let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)).pre_dispatch( @@ -337,15 +337,15 @@ fn transaction_payment_without_fee() { // mint into the caller account let beneficiary = ::Lookup::unlookup(caller); - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 5; let len = 10; let fee_in_native = base_weight + weight + len as u64; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); @@ -359,11 +359,11 @@ fn transaction_payment_without_fee() { // assert that native balance is not used assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), fee_in_native, true, ) @@ -379,7 +379,7 @@ fn transaction_payment_without_fee() { )); // caller should get refunded - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset + refund); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset + refund); assert_eq!(Balances::free_balance(caller), 10 * balance_factor); }); } @@ -413,16 +413,16 @@ fn asset_transaction_payment_with_tip_and_refund() { let beneficiary = ::Lookup::unlookup(caller); let balance = 10000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 100; let tip = 5; let len = 10; let fee_in_native = base_weight + weight + len as u64 + tip; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); @@ -432,13 +432,13 @@ fn asset_transaction_payment_with_tip_and_refund() { let pre = ChargeAssetTxPayment::::from(tip, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_100), len) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let final_weight = 50; let expected_fee = fee_in_native - final_weight - tip; let expected_token_refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), fee_in_native - expected_fee - tip, true, ) @@ -463,7 +463,7 @@ fn asset_transaction_payment_with_tip_and_refund() { // caller should get refunded assert_eq!( - Assets::balance(asset_id, caller), + Assets::balance(&asset_id, caller), balance - fee_in_asset + expected_token_refund ); assert_eq!(Balances::free_balance(caller), 20 * balance_factor); @@ -503,8 +503,8 @@ fn payment_from_account_with_only_assets() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); // assert that native balance is not necessary assert_eq!(Balances::free_balance(caller), 0); @@ -514,8 +514,8 @@ fn payment_from_account_with_only_assets() { let fee_in_native = base_weight + weight + len as u64; let ed = Balances::minimum_balance(); let fee_in_asset = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native + ed, true, ) @@ -527,11 +527,11 @@ fn payment_from_account_with_only_assets() { .unwrap(); assert_eq!(Balances::free_balance(caller), ed); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), ed, true, ) @@ -544,7 +544,7 @@ fn payment_from_account_with_only_assets() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset + refund); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset + refund); assert_eq!(Balances::free_balance(caller), 0); assert_eq!(TipUnbalancedAmount::get(), 0); @@ -579,8 +579,8 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -591,7 +591,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { .pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len) .unwrap(); // `Pays::No` implies there are no fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -600,14 +600,15 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); } // validate even a small fee gets converted to asset. let fee_in_native = base_weight + weight + len as u64; + let fee_in_asset = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ) @@ -616,7 +617,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(Weight::from_parts(weight, 0)), len) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -625,7 +626,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); }); } @@ -653,8 +654,8 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -668,7 +669,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { .unwrap(); // `Pays::No` implies no pre-dispatch fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); let (_tip, _who, initial_payment, _asset_id) = ⪯ let not_paying = match initial_payment { @@ -686,7 +687,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); } @@ -714,8 +715,8 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -726,7 +727,7 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { ) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); // `Pays::Yes` on post-dispatch does not mean we pay (we never charge more than the // initial fee) @@ -737,6 +738,6 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); } diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs index 717114ab6bd0..f482dd6f1b22 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs @@ -125,7 +125,7 @@ where .map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))? .max(min_converted_fee); let can_withdraw = - >::can_withdraw(asset_id, who, converted_fee); + >::can_withdraw(&asset_id, who, converted_fee); if can_withdraw != WithdrawConsequence::Success { return Err(InvalidTransaction::Payment.into()) } diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/tests.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/tests.rs index 098ecf11dd92..e6d8be506b81 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/tests.rs @@ -174,8 +174,8 @@ fn transaction_payment_in_asset_possible() { let caller = 1; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 5; let len = 10; // we convert the from weight to fee based on the ratio between asset min balance and @@ -187,8 +187,8 @@ fn transaction_payment_in_asset_possible() { // assert that native balance is not used assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee); - assert_eq!(Assets::balance(asset_id, BLOCK_AUTHOR), 0); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee); + assert_eq!(Assets::balance(&asset_id, BLOCK_AUTHOR), 0); System::assert_has_event(RuntimeEvent::Assets(pallet_assets::Event::Withdrawn { asset_id, @@ -203,9 +203,9 @@ fn transaction_payment_in_asset_possible() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee); // check that the block author gets rewarded - assert_eq!(Assets::balance(asset_id, BLOCK_AUTHOR), fee); + assert_eq!(Assets::balance(&asset_id, BLOCK_AUTHOR), fee); System::assert_has_event(RuntimeEvent::Assets(pallet_assets::Event::Deposited { asset_id, @@ -239,8 +239,8 @@ fn transaction_payment_without_fee() { let caller = 1; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 5; let len = 10; // we convert the from weight to fee based on the ratio between asset min balance and @@ -252,8 +252,8 @@ fn transaction_payment_without_fee() { // assert that native balance is not used assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee); - assert_eq!(Assets::balance(asset_id, BLOCK_AUTHOR), 0); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee); + assert_eq!(Assets::balance(&asset_id, BLOCK_AUTHOR), 0); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -263,9 +263,9 @@ fn transaction_payment_without_fee() { &Ok(()) )); // caller should be refunded - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); // check that the block author did not get rewarded - assert_eq!(Assets::balance(asset_id, BLOCK_AUTHOR), 0); + assert_eq!(Assets::balance(&asset_id, BLOCK_AUTHOR), 0); }); } @@ -294,8 +294,8 @@ fn asset_transaction_payment_with_tip_and_refund() { let caller = 2; let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 100; let tip = 5; let len = 10; @@ -306,7 +306,7 @@ fn asset_transaction_payment_with_tip_and_refund() { let pre = ChargeAssetTxPayment::::from(tip, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(Weight::from_parts(weight, 0)), len) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_with_tip); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_with_tip); System::assert_has_event(RuntimeEvent::Assets(pallet_assets::Event::Withdrawn { asset_id, @@ -324,8 +324,8 @@ fn asset_transaction_payment_with_tip_and_refund() { )); let final_fee = fee_with_tip - (weight - final_weight) * min_balance / ExistentialDeposit::get(); - assert_eq!(Assets::balance(asset_id, caller), balance - (final_fee)); - assert_eq!(Assets::balance(asset_id, BLOCK_AUTHOR), final_fee); + assert_eq!(Assets::balance(&asset_id, caller), balance - (final_fee)); + assert_eq!(Assets::balance(&asset_id, BLOCK_AUTHOR), final_fee); System::assert_has_event(RuntimeEvent::Assets(pallet_assets::Event::Deposited { asset_id, @@ -358,8 +358,8 @@ fn payment_from_account_with_only_assets() { let caller = 333; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); // assert that native balance is not necessary assert_eq!(Balances::free_balance(caller), 0); let weight = 5; @@ -372,7 +372,7 @@ fn payment_from_account_with_only_assets() { .unwrap(); assert_eq!(Balances::free_balance(caller), 0); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -381,7 +381,7 @@ fn payment_from_account_with_only_assets() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee); assert_eq!(Balances::free_balance(caller), 0); }); } @@ -442,8 +442,8 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { let caller = 333; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; // we convert the from weight to fee based on the ratio between asset min balance and @@ -456,7 +456,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { .pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len) .unwrap(); // `Pays::No` still implies no fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -465,13 +465,13 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); } let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(Weight::from_parts(weight, 0)), len) .unwrap(); // check that at least one coin was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - 1); + assert_eq!(Assets::balance(&asset_id, caller), balance - 1); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -480,7 +480,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - 1); + assert_eq!(Assets::balance(&asset_id, caller), balance - 1); }); } @@ -507,8 +507,8 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { let caller = 333; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; // we convert the from weight to fee based on the ratio between asset min balance and @@ -520,7 +520,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { .pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len) .unwrap(); // `Pays::No` implies no pre-dispatch fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); let (_tip, _who, initial_payment, _asset_id) = ⪯ let not_paying = match initial_payment { &InitialPayment::Nothing => true, @@ -537,7 +537,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); } @@ -564,8 +564,8 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { let caller = 333; let beneficiary = ::Lookup::unlookup(caller); let balance = 100; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id.into(), &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; ChargeAssetTxPayment::::pre_dispatch_unsigned( @@ -575,7 +575,7 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { ) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); // `Pays::Yes` on post-dispatch does not mean we pay (we never charge more than the // initial fee) @@ -586,6 +586,6 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); }