From 4fdb4f59d2aa3db73784237754b248d9f7495c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Mon, 20 May 2024 09:50:25 -0500 Subject: [PATCH 1/9] feat(pallet-assets): define call for transfer_all --- substrate/frame/assets/src/benchmarking.rs | 10 +++++ substrate/frame/assets/src/lib.rs | 49 +++++++++++++++++++++- substrate/frame/assets/src/tests.rs | 44 +++++++++++++++++++ substrate/frame/assets/src/weights.rs | 21 ++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-) diff --git a/substrate/frame/assets/src/benchmarking.rs b/substrate/frame/assets/src/benchmarking.rs index 1b65bb953d77..70a67aaad9a2 100644 --- a/substrate/frame/assets/src/benchmarking.rs +++ b/substrate/frame/assets/src/benchmarking.rs @@ -553,5 +553,15 @@ benchmarks_instance_pallet! { assert_last_event::(Event::Blocked { asset_id: asset_id.into(), who: caller }.into()); } + transfer_all { + let amount = T::Balance::from(100u32); + let (asset_id, caller, caller_lookup) = create_default_minted_asset::(true, amount); + let target: T::AccountId = account("target", 0, SEED); + let target_lookup = T::Lookup::unlookup(target.clone()); + }: _(SystemOrigin::Signed(caller.clone()), asset_id.clone(), target_lookup, false) + verify { + assert_last_event::(Event::Transferred { asset_id: asset_id.into(), from: caller, to: target, amount }.into()); + } + impl_benchmark_test_suite!(Assets, crate::mock::new_test_ext(), crate::mock::Test) } diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index d52149225558..9ae97a5828b3 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -180,7 +180,11 @@ use frame_support::{ pallet_prelude::DispatchResultWithPostInfo, storage::KeyPrefixIterator, traits::{ - tokens::{fungibles, DepositConsequence, WithdrawConsequence}, + tokens::{ + fungibles, DepositConsequence, Fortitude, + Preservation::{Expendable, Preserve}, + WithdrawConsequence, + }, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency, StoredMap, }, @@ -1687,6 +1691,49 @@ pub mod pallet { Self::deposit_event(Event::::Blocked { asset_id: id, who }); Ok(()) } + + /// Transfer the entire transferable balance from the caller asset account. + /// + /// NOTE: This function only attempts to transfer _transferable_ balances. This means that + /// any held, frozen, or existential deposits (when `keep_alive` is `true`), will not be + /// transferred by this function. To ensure that this function results in a killed account, + /// you might need to prepare the account by removing any reference counters, storage + /// deposits, etc... + /// + /// The dispatch origin of this call must be Signed. + /// + /// - `id`: The identifier of the asset for the account holding a deposit. + /// - `dest`: The recipient of the transfer. + /// - `keep_alive`: A boolean to determine if the `transfer_all` operation should send all + /// of the funds the asset account has, causing the sender asset account to be killed + /// (false), or transfer everything except at least the existential deposit, which will + /// guarantee to keep the sender asset account alive (true). + #[pallet::call_index(32)] + #[pallet::weight(T::WeightInfo::refund_other())] + pub fn transfer_all( + origin: OriginFor, + id: T::AssetIdParameter, + dest: AccountIdLookupOf, + keep_alive: bool, + ) -> DispatchResult { + let transactor = ensure_signed(origin)?; + let keep_alive = if keep_alive { Preserve } else { Expendable }; + let reducible_balance = >::reducible_balance( + id.clone().into(), + &transactor, + keep_alive, + Fortitude::Polite, + ); + let dest = T::Lookup::lookup(dest)?; + >::transfer( + id.into(), + &transactor, + &dest, + reducible_balance, + keep_alive, + )?; + Ok(()) + } } /// Implements [`AccountTouch`] trait. diff --git a/substrate/frame/assets/src/tests.rs b/substrate/frame/assets/src/tests.rs index c7021bcad531..2fa1e7120dda 100644 --- a/substrate/frame/assets/src/tests.rs +++ b/substrate/frame/assets/src/tests.rs @@ -795,6 +795,50 @@ fn transferring_to_blocked_account_should_not_work() { }); } +#[test] +fn transfer_all_works_1() { + new_test_ext().execute_with(|| { + // setup + assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 0, true, 100)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 1, 200)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 2, 100)); + // transfer all and allow death + assert_ok!(Assets::transfer_all(Some(1).into(), 0, 2, false)); + assert_eq!(Assets::balance(0, &1), 0); + assert_eq!(Assets::balance(0, &2), 300); + }); +} + +#[test] +fn transfer_all_works_2() { + new_test_ext().execute_with(|| { + // setup + assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 0, true, 100)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 1, 200)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 2, 100)); + // transfer all and allow death + assert_ok!(Assets::transfer_all(Some(1).into(), 0, 2, true)); + assert_eq!(Assets::balance(0, &1), 100); + assert_eq!(Assets::balance(0, &2), 200); + }); +} + +// /// TODO: Cover this case once #3951 is merged +// #[test] +// fn transfer_all_works_3() { +// new_test_ext().execute_with(|| { +// // setup +// assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 0, true, 100)); +// assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 1, 200)); +// assert_ok!(AssetFreezer::set_frozen(&TestId::Foo, 0, &1, 10)); +// assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 2, 100)); +// // transfer all and allow death w/ reserved +// assert_ok!(Assets::transfer_all(Some(1).into(), 0, 2, true)); +// assert_eq!(Assets::balance(0, &1), 110); +// assert_eq!(Assets::balance(0, &2), 200); +// }); +// } + #[test] fn origin_guards_should_work() { new_test_ext().execute_with(|| { diff --git a/substrate/frame/assets/src/weights.rs b/substrate/frame/assets/src/weights.rs index 7886cd364d51..57f7e951b73c 100644 --- a/substrate/frame/assets/src/weights.rs +++ b/substrate/frame/assets/src/weights.rs @@ -83,6 +83,7 @@ pub trait WeightInfo { fn refund() -> Weight; fn refund_other() -> Weight; fn block() -> Weight; + fn transfer_all() -> Weight; } /// Weights for `pallet_assets` using the Substrate node and recommended hardware. @@ -530,6 +531,16 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests. @@ -976,4 +987,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } From b7086a800098504f4bb89c9d479ff5e7d50934c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Mon, 20 May 2024 10:01:29 -0500 Subject: [PATCH 2/9] change(prdoc): add prdoc for pull request --- prdoc/pr_4527.prdoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 prdoc/pr_4527.prdoc diff --git a/prdoc/pr_4527.prdoc b/prdoc/pr_4527.prdoc new file mode 100644 index 000000000000..edc637abbe4b --- /dev/null +++ b/prdoc/pr_4527.prdoc @@ -0,0 +1,23 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Call implementation for `transfer_all` + +doc: + - audience: Runtime Dev + description: | + This PR introduces the `transfer_all` call for `pallet-assets`. + The parameters are analog to the same call in `pallet-balances`. + This change shouldn't break the existing APIs. + This change requires running benchmarkings to set accurate weights for + the call. + - audience: Runtime User + description: | + This PR introduces the `transfer_all` call for `pallet-assets`. + The parameters are analog to the same call in `pallet-balances`. + When using this call, consider that transferring all funds of an asset + account might kill it when setting `keep_alive` as false. + +crates: + - name: pallet-assets + bump: minor From 4d7a32820657a32c0e8e025d2500d74c173ee3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Mon, 20 May 2024 10:05:11 -0500 Subject: [PATCH 3/9] change(parachains/assets): update weights on asset-hub parachains --- .../src/weights/pallet_assets_foreign.rs | 10 ++++++++++ .../src/weights/pallet_assets_local.rs | 10 ++++++++++ .../asset-hub-rococo/src/weights/pallet_assets_pool.rs | 10 ++++++++++ .../src/weights/pallet_assets_foreign.rs | 10 ++++++++++ .../src/weights/pallet_assets_local.rs | 10 ++++++++++ .../src/weights/pallet_assets_pool.rs | 10 ++++++++++ 6 files changed, 60 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_foreign.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_foreign.rs index 5148edb0ee9e..c76c1137335a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_foreign.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_foreign.rs @@ -531,4 +531,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_local.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_local.rs index 4ee235830aed..cf4f60042bc6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_local.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_local.rs @@ -528,4 +528,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_pool.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_pool.rs index df7ad2c63386..2cd85de00989 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_pool.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_pool.rs @@ -528,4 +528,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_foreign.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_foreign.rs index 52ba2fd6c40f..2692de9aeb50 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_foreign.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_foreign.rs @@ -537,4 +537,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_local.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_local.rs index e78366b91cbe..d2e12549a45c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_local.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_local.rs @@ -535,4 +535,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_pool.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_pool.rs index 65cae81069c4..8368f6e583cc 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_pool.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_assets_pool.rs @@ -529,4 +529,14 @@ impl pallet_assets::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 46_573_000 picoseconds. + Weight::from_parts(47_385_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } From d3247a11efa51015307a754a573baa890199e148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Mon, 20 May 2024 11:24:55 -0500 Subject: [PATCH 4/9] fix(prdoc): missing bumps for asset-hub testing runtimes --- prdoc/pr_4527.prdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prdoc/pr_4527.prdoc b/prdoc/pr_4527.prdoc index edc637abbe4b..1f198ee86001 100644 --- a/prdoc/pr_4527.prdoc +++ b/prdoc/pr_4527.prdoc @@ -20,4 +20,8 @@ doc: crates: - name: pallet-assets + bump: major + - name: asset-hub-rococo-runtime + bump: minor + - name: asset-hub-westend-runtime bump: minor From baf45ad906d2455e218e0e39ca72940040b14a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Wed, 29 May 2024 21:51:53 -0500 Subject: [PATCH 5/9] fix(prdoc): bump pallet-assets as minor change --- prdoc/pr_4527.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4527.prdoc b/prdoc/pr_4527.prdoc index 1f198ee86001..16f84ebcfe27 100644 --- a/prdoc/pr_4527.prdoc +++ b/prdoc/pr_4527.prdoc @@ -20,7 +20,7 @@ doc: crates: - name: pallet-assets - bump: major + bump: minor - name: asset-hub-rococo-runtime bump: minor - name: asset-hub-westend-runtime From 5d3c18960aa30c45673632165f7e618b56bec6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Thu, 30 May 2024 16:31:10 -0500 Subject: [PATCH 6/9] fix(pallet-assets): update documentation of `transfer_all` call to refer to minimum balance instead of existential depost --- substrate/frame/assets/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 9ae97a5828b3..1c7a81f79f7e 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -1695,7 +1695,7 @@ pub mod pallet { /// Transfer the entire transferable balance from the caller asset account. /// /// NOTE: This function only attempts to transfer _transferable_ balances. This means that - /// any held, frozen, or existential deposits (when `keep_alive` is `true`), will not be + /// any held, frozen, or minimum balance (when `keep_alive` is `true`), will not be /// transferred by this function. To ensure that this function results in a killed account, /// you might need to prepare the account by removing any reference counters, storage /// deposits, etc... @@ -1706,7 +1706,7 @@ pub mod pallet { /// - `dest`: The recipient of the transfer. /// - `keep_alive`: A boolean to determine if the `transfer_all` operation should send all /// of the funds the asset account has, causing the sender asset account to be killed - /// (false), or transfer everything except at least the existential deposit, which will + /// (false), or transfer everything except at least the minimum balance, which will /// guarantee to keep the sender asset account alive (true). #[pallet::call_index(32)] #[pallet::weight(T::WeightInfo::refund_other())] From 1ba0962db8e79baffe3b9c270910d693117369c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Fri, 28 Jun 2024 11:20:14 -0500 Subject: [PATCH 7/9] change(pallet-assets): address review suggestions --- prdoc/pr_4527.prdoc | 4 +-- substrate/frame/assets/src/benchmarking.rs | 2 +- substrate/frame/assets/src/tests.rs | 29 +++++++++++----------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/prdoc/pr_4527.prdoc b/prdoc/pr_4527.prdoc index 16f84ebcfe27..1c12b9659641 100644 --- a/prdoc/pr_4527.prdoc +++ b/prdoc/pr_4527.prdoc @@ -8,7 +8,7 @@ doc: description: | This PR introduces the `transfer_all` call for `pallet-assets`. The parameters are analog to the same call in `pallet-balances`. - This change shouldn't break the existing APIs. + This change is expected to be backwards-compatible. This change requires running benchmarkings to set accurate weights for the call. - audience: Runtime User @@ -20,7 +20,7 @@ doc: crates: - name: pallet-assets - bump: minor + bump: major - name: asset-hub-rococo-runtime bump: minor - name: asset-hub-westend-runtime diff --git a/substrate/frame/assets/src/benchmarking.rs b/substrate/frame/assets/src/benchmarking.rs index 70a67aaad9a2..81719ba4b69c 100644 --- a/substrate/frame/assets/src/benchmarking.rs +++ b/substrate/frame/assets/src/benchmarking.rs @@ -554,7 +554,7 @@ benchmarks_instance_pallet! { } transfer_all { - let amount = T::Balance::from(100u32); + let amount = T::Balance::from(2u32); let (asset_id, caller, caller_lookup) = create_default_minted_asset::(true, amount); let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); diff --git a/substrate/frame/assets/src/tests.rs b/substrate/frame/assets/src/tests.rs index 5fc199cd392f..114138a4e682 100644 --- a/substrate/frame/assets/src/tests.rs +++ b/substrate/frame/assets/src/tests.rs @@ -823,21 +823,20 @@ fn transfer_all_works_2() { }); } -// /// TODO: Cover this case once #3951 is merged -// #[test] -// fn transfer_all_works_3() { -// new_test_ext().execute_with(|| { -// // setup -// assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 0, true, 100)); -// assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 1, 200)); -// assert_ok!(AssetFreezer::set_frozen(&TestId::Foo, 0, &1, 10)); -// assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 2, 100)); -// // transfer all and allow death w/ reserved -// assert_ok!(Assets::transfer_all(Some(1).into(), 0, 2, true)); -// assert_eq!(Assets::balance(0, &1), 110); -// assert_eq!(Assets::balance(0, &2), 200); -// }); -// } +#[test] +fn transfer_all_works_3() { + new_test_ext().execute_with(|| { + // setup + assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 0, true, 100)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 1, 210)); + set_frozen_balance(0, 1, 10); + assert_ok!(Assets::mint(RuntimeOrigin::signed(0), 0, 2, 100)); + // transfer all and allow death w/ frozen + assert_ok!(Assets::transfer_all(Some(1).into(), 0, 2, false)); + assert_eq!(Assets::balance(0, &1), 110); + assert_eq!(Assets::balance(0, &2), 200); + }); +} #[test] fn origin_guards_should_work() { From 7e11870131facb5b5a4d9464abc6a417531dc3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Tue, 2 Jul 2024 13:16:35 -0500 Subject: [PATCH 8/9] change: address requested changes --- prdoc/pr_4527.prdoc | 6 ------ substrate/frame/assets/src/benchmarking.rs | 7 ++++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/prdoc/pr_4527.prdoc b/prdoc/pr_4527.prdoc index 1c12b9659641..12056f87575b 100644 --- a/prdoc/pr_4527.prdoc +++ b/prdoc/pr_4527.prdoc @@ -11,12 +11,6 @@ doc: This change is expected to be backwards-compatible. This change requires running benchmarkings to set accurate weights for the call. - - audience: Runtime User - description: | - This PR introduces the `transfer_all` call for `pallet-assets`. - The parameters are analog to the same call in `pallet-balances`. - When using this call, consider that transferring all funds of an asset - account might kill it when setting `keep_alive` as false. crates: - name: pallet-assets diff --git a/substrate/frame/assets/src/benchmarking.rs b/substrate/frame/assets/src/benchmarking.rs index 81719ba4b69c..c13c6c80ba67 100644 --- a/substrate/frame/assets/src/benchmarking.rs +++ b/substrate/frame/assets/src/benchmarking.rs @@ -31,6 +31,7 @@ use sp_std::prelude::*; use crate::Pallet as Assets; const SEED: u32 = 0; +const MIN_BALANCE: u32 = 1; fn default_asset_id, I: 'static>() -> T::AssetIdParameter { T::BenchmarkHelper::create_asset_id_parameter(0) @@ -48,7 +49,7 @@ fn create_default_asset, I: 'static>( asset_id.clone(), caller_lookup.clone(), is_sufficient, - 1u32.into(), + MIN_BALANCE.into(), ) .is_ok()); (asset_id, caller, caller_lookup) @@ -547,14 +548,14 @@ benchmarks_instance_pallet! { } block { - let (asset_id, caller, caller_lookup) = create_default_minted_asset::(true, 100u32.into()); + let (asset_id, caller, caller_lookup) = crfeate_default_minted_asset::(true, 100u32.into()); }: _(SystemOrigin::Signed(caller.clone()), asset_id.clone(), caller_lookup) verify { assert_last_event::(Event::Blocked { asset_id: asset_id.into(), who: caller }.into()); } transfer_all { - let amount = T::Balance::from(2u32); + let amount = T::Balance::from(2 * MIN_BALANCE); let (asset_id, caller, caller_lookup) = create_default_minted_asset::(true, amount); let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); From 1ac9bbbc5a726c82c813da97741929732d47eac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Tue, 2 Jul 2024 13:18:59 -0500 Subject: [PATCH 9/9] fix(pallet-assets): typo --- substrate/frame/assets/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/assets/src/benchmarking.rs b/substrate/frame/assets/src/benchmarking.rs index c13c6c80ba67..9d7c0346404c 100644 --- a/substrate/frame/assets/src/benchmarking.rs +++ b/substrate/frame/assets/src/benchmarking.rs @@ -548,7 +548,7 @@ benchmarks_instance_pallet! { } block { - let (asset_id, caller, caller_lookup) = crfeate_default_minted_asset::(true, 100u32.into()); + let (asset_id, caller, caller_lookup) = create_default_minted_asset::(true, 100u32.into()); }: _(SystemOrigin::Signed(caller.clone()), asset_id.clone(), caller_lookup) verify { assert_last_event::(Event::Blocked { asset_id: asset_id.into(), who: caller }.into());