From fce3089762b46d4af85c8ab5a734b455b0598dba Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 May 2023 11:02:09 +0000 Subject: [PATCH 1/8] Remove the `Copy` bound on `AssetId` --- frame/asset-rate/src/benchmarking.rs | 8 +- frame/asset-rate/src/lib.rs | 10 +- frame/assets/src/benchmarking.rs | 2 +- frame/assets/src/extra_mutator.rs | 6 +- frame/assets/src/functions.rs | 136 ++++++++++-------- frame/assets/src/impl_stored_map.rs | 4 +- frame/assets/src/lib.rs | 40 +++--- .../src/traits/tokens/fungibles/hold.rs | 61 ++++---- .../src/traits/tokens/fungibles/imbalance.rs | 10 +- .../src/traits/tokens/fungibles/regular.rs | 97 +++++++------ frame/support/src/traits/tokens/misc.rs | 4 +- 11 files changed, 206 insertions(+), 172 deletions(-) diff --git a/frame/asset-rate/src/benchmarking.rs b/frame/asset-rate/src/benchmarking.rs index dde0d764affb2..1209f8db6693b 100644 --- a/frame/asset-rate/src/benchmarking.rs +++ b/frame/asset-rate/src/benchmarking.rs @@ -38,7 +38,7 @@ mod benchmarks { fn create() -> Result<(), BenchmarkError> { let asset_id: T::AssetId = ASSET_ID.into(); #[extrinsic_call] - _(RawOrigin::Root, asset_id, default_conversion_rate()); + _(RawOrigin::Root, asset_id.clone(), default_conversion_rate()); assert_eq!( pallet_asset_rate::ConversionRateToNative::::get(asset_id), @@ -52,12 +52,12 @@ mod benchmarks { let asset_id: T::AssetId = ASSET_ID.into(); assert_ok!(AssetRate::::create( RawOrigin::Root.into(), - asset_id, + asset_id.clone(), default_conversion_rate() )); #[extrinsic_call] - _(RawOrigin::Root, asset_id, FixedU128::from_u32(2)); + _(RawOrigin::Root, asset_id.clone(), FixedU128::from_u32(2)); assert_eq!( pallet_asset_rate::ConversionRateToNative::::get(asset_id), @@ -76,7 +76,7 @@ mod benchmarks { )); #[extrinsic_call] - _(RawOrigin::Root, asset_id); + _(RawOrigin::Root, asset_id.clone()); assert!(pallet_asset_rate::ConversionRateToNative::::get(asset_id).is_none()); Ok(()) diff --git a/frame/asset-rate/src/lib.rs b/frame/asset-rate/src/lib.rs index 8c6597a389833..ecc793184094b 100644 --- a/frame/asset-rate/src/lib.rs +++ b/frame/asset-rate/src/lib.rs @@ -161,10 +161,10 @@ pub mod pallet { T::CreateOrigin::ensure_origin(origin)?; ensure!( - !ConversionRateToNative::::contains_key(asset_id), + !ConversionRateToNative::::contains_key(asset_id.clone()), Error::::AlreadyExists ); - ConversionRateToNative::::set(asset_id, Some(rate)); + ConversionRateToNative::::set(asset_id.clone(), Some(rate)); Self::deposit_event(Event::AssetRateCreated { asset_id, rate }); Ok(()) @@ -184,7 +184,7 @@ pub mod pallet { T::UpdateOrigin::ensure_origin(origin)?; let mut old = FixedU128::zero(); - ConversionRateToNative::::mutate(asset_id, |maybe_rate| { + ConversionRateToNative::::mutate(asset_id.clone(), |maybe_rate| { if let Some(r) = maybe_rate { old = *r; *r = rate; @@ -209,10 +209,10 @@ pub mod pallet { T::RemoveOrigin::ensure_origin(origin)?; ensure!( - ConversionRateToNative::::contains_key(asset_id), + ConversionRateToNative::::contains_key(asset_id.clone()), Error::::UnknownAssetId ); - ConversionRateToNative::::remove(asset_id); + ConversionRateToNative::::remove(asset_id.clone()); Self::deposit_event(Event::AssetRateRemoved { asset_id }); Ok(()) diff --git a/frame/assets/src/benchmarking.rs b/frame/assets/src/benchmarking.rs index a2483650715a2..747e072ddde2b 100644 --- a/frame/assets/src/benchmarking.rs +++ b/frame/assets/src/benchmarking.rs @@ -144,7 +144,7 @@ benchmarks_instance_pallet! { let caller = T::CreateOrigin::ensure_origin(origin, &asset_id.into()).unwrap(); let caller_lookup = T::Lookup::unlookup(caller.clone()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - }: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, 1u32.into()) + }: _(SystemOrigin::Signed(caller.clone()), asset_id.clone(), caller_lookup, 1u32.into()) verify { assert_last_event::(Event::Created { asset_id: asset_id.into(), creator: caller.clone(), owner: caller }.into()); } diff --git a/frame/assets/src/extra_mutator.rs b/frame/assets/src/extra_mutator.rs index 96fb765cb0382..bf7fd12f40f0b 100644 --- a/frame/assets/src/extra_mutator.rs +++ b/frame/assets/src/extra_mutator.rs @@ -62,7 +62,7 @@ impl, I: 'static> ExtraMutator { id: T::AssetId, who: impl sp_std::borrow::Borrow, ) -> Option> { - if let Some(a) = Account::::get(id, who.borrow()) { + if let Some(a) = Account::::get(&id, who.borrow()) { Some(ExtraMutator:: { id, who: who.borrow().clone(), @@ -77,7 +77,7 @@ impl, I: 'static> ExtraMutator { /// Commit any changes to storage. pub fn commit(&mut self) -> Result<(), ()> { if let Some(extra) = self.pending.take() { - Account::::try_mutate(self.id, self.who.borrow(), |maybe_account| { + Account::::try_mutate(&self.id, self.who.borrow(), |maybe_account| { maybe_account.as_mut().ok_or(()).map(|account| account.extra = extra) }) } else { @@ -88,7 +88,7 @@ impl, I: 'static> ExtraMutator { /// Revert any changes, even those already committed by `self` and drop self. pub fn revert(mut self) -> Result<(), ()> { self.pending = None; - Account::::try_mutate(self.id, self.who.borrow(), |maybe_account| { + Account::::try_mutate(&self.id, self.who.borrow(), |maybe_account| { maybe_account .as_mut() .ok_or(()) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index d7c5bbe95e9fe..d0a431d85dde1 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -165,7 +165,7 @@ impl, I: 'static> Pallet { 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, who) { + if let Some(frozen) = T::Freezer::frozen_balance(id.clone(), who) { match frozen.checked_add(&details.min_balance) { Some(required) if rest < required => return Frozen, None => return Overflow, @@ -265,7 +265,7 @@ impl, I: 'static> Pallet { amount: T::Balance, f: DebitFlags, ) -> Result { - let actual = Self::reducible_balance(id, target, f.keep_alive)?.min(amount); + let actual = Self::reducible_balance(id.clone(), 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); @@ -361,7 +361,7 @@ 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` @@ -416,7 +416,7 @@ impl, I: 'static> Pallet { amount: T::Balance, maybe_check_issuer: Option, ) -> DispatchResult { - Self::increase_balance(id, beneficiary, amount, |details| -> DispatchResult { + Self::increase_balance(id.clone(), beneficiary, amount, |details| -> DispatchResult { if let Some(check_issuer) = maybe_check_issuer { ensure!(check_issuer == details.issuer, Error::::NoPermission); } @@ -450,30 +450,35 @@ impl, I: 'static> Pallet { return Ok(()) } - Self::can_increase(id, beneficiary, amount, true).into_result()?; - Asset::::try_mutate(id, |maybe_details| -> DispatchResult { + Self::can_increase(id.clone(), beneficiary, amount, true).into_result()?; + Asset::::try_mutate(id.clone(), |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 { - match maybe_account { - Some(ref mut account) => { - account.balance.saturating_accrue(amount); - }, - maybe_account @ None => { - // Note this should never fail as it's already checked by `can_increase`. - ensure!(amount >= details.min_balance, TokenError::BelowMinimum); - *maybe_account = Some(AssetAccountOf:: { - balance: amount, - reason: Self::new_account(beneficiary, details, None)?, - status: AccountStatus::Liquid, - extra: T::Extra::default(), - }); - }, - } - Ok(()) - })?; + Account::::try_mutate( + id.clone(), + beneficiary, + |maybe_account| -> DispatchResult { + match maybe_account { + Some(ref mut account) => { + account.balance.saturating_accrue(amount); + }, + maybe_account @ None => { + // Note this should never fail as it's already checked by + // `can_increase`. + ensure!(amount >= details.min_balance, TokenError::BelowMinimum); + *maybe_account = Some(AssetAccountOf:: { + balance: amount, + reason: Self::new_account(beneficiary, details, None)?, + status: AccountStatus::Liquid, + extra: T::Extra::default(), + }); + }, + } + Ok(()) + }, + )?; Ok(()) })?; Ok(()) @@ -493,13 +498,13 @@ impl, I: 'static> Pallet { maybe_check_admin: Option, f: DebitFlags, ) -> Result { - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!( d.status == AssetStatus::Live || d.status == AssetStatus::Frozen, Error::::AssetNotLive ); - let actual = Self::decrease_balance(id, target, amount, f, |actual, details| { + let actual = Self::decrease_balance(id.clone(), target, amount, f, |actual, details| { // Check admin rights. if let Some(check_admin) = maybe_check_admin { ensure!(check_admin == details.admin, Error::::NoPermission); @@ -536,17 +541,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, target, amount, f)?; + let actual = Self::prep_debit(id.clone(), target, amount, f)?; let mut target_died: Option = None; - Asset::::try_mutate(id, |maybe_details| -> DispatchResult { + Asset::::try_mutate(id.clone(), |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.clone(), target, |maybe_account| -> DispatchResult { let mut account = maybe_account.take().ok_or(Error::::NoAccount)?; debug_assert!(account.balance >= actual, "checked in prep; qed"); @@ -590,7 +595,7 @@ impl, I: 'static> Pallet { f: TransferFlags, ) -> Result { let (balance, died) = - Self::transfer_and_die(id, source, dest, amount, maybe_need_admin, f)?; + Self::transfer_and_die(id.clone(), source, dest, amount, maybe_need_admin, f)?; if let Some(Remove) = died { T::Freezer::died(id, source); } @@ -611,18 +616,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, source, amount, f.into())?; - let (credit, maybe_burn) = Self::prep_credit(id, dest, amount, debit, f.burn_dust)?; + 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 mut source_account = - Account::::get(id, &source).ok_or(Error::::NoAccount)?; + Account::::get(id.clone(), &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 +652,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.clone(), &dest, |maybe_account| -> DispatchResult { match maybe_account { Some(ref mut account) => { // Calculate new balance; this will not saturate since it's already checked @@ -676,11 +681,11 @@ 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.clone(), &source); return Ok(()) } } - Account::::insert(id, &source, &source_account); + Account::::insert(id.clone(), &source, &source_account); Ok(()) })?; @@ -707,11 +712,11 @@ impl, I: 'static> Pallet { is_sufficient: bool, min_balance: T::Balance, ) -> DispatchResult { - ensure!(!Asset::::contains_key(id), Error::::InUse); + ensure!(!Asset::::contains_key(&id), Error::::InUse); ensure!(!min_balance.is_zero(), Error::::MinBalanceZero); Asset::::insert( - id, + id.clone(), AssetDetails { owner: owner.clone(), issuer: owner.clone(), @@ -738,7 +743,7 @@ impl, I: 'static> Pallet { id: T::AssetId, maybe_check_owner: Option, ) -> DispatchResult { - Asset::::try_mutate_exists(id, |maybe_details| -> Result<(), DispatchError> { + Asset::::try_mutate_exists(id.clone(), |maybe_details| -> Result<(), DispatchError> { let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; if let Some(check_owner) = maybe_check_owner { ensure!(details.owner == check_owner, Error::::NoPermission); @@ -760,13 +765,14 @@ impl, I: 'static> Pallet { ) -> Result { let mut dead_accounts: Vec = vec![]; let mut remaining_accounts = 0; - let _ = - Asset::::try_mutate_exists(id, |maybe_details| -> Result<(), DispatchError> { + let _ = Asset::::try_mutate_exists( + id.clone(), + |maybe_details| -> Result<(), DispatchError> { let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; // Should only destroy accounts while the asset is in a destroying state ensure!(details.status == AssetStatus::Destroying, Error::::IncorrectStatus); - for (who, v) in Account::::drain_prefix(id) { + for (who, v) in Account::::drain_prefix(id.clone()) { let _ = Self::dead_account(&who, &mut details, &v.reason, true); dead_accounts.push(who); if dead_accounts.len() >= (max_items as usize) { @@ -775,10 +781,11 @@ impl, I: 'static> Pallet { } remaining_accounts = details.accounts; Ok(()) - })?; + }, + )?; for who in &dead_accounts { - T::Freezer::died(id, &who); + T::Freezer::died(id.clone(), &who); } Self::deposit_event(Event::AccountsDestroyed { @@ -798,14 +805,15 @@ impl, I: 'static> Pallet { max_items: u32, ) -> Result { let mut removed_approvals = 0; - let _ = - Asset::::try_mutate_exists(id, |maybe_details| -> Result<(), DispatchError> { + let _ = Asset::::try_mutate_exists( + id.clone(), + |maybe_details| -> Result<(), DispatchError> { let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; // Should only destroy accounts while the asset is in a destroying state. ensure!(details.status == AssetStatus::Destroying, Error::::IncorrectStatus); - for ((owner, _), approval) in Approvals::::drain_prefix((id,)) { + for ((owner, _), approval) in Approvals::::drain_prefix((id.clone(),)) { T::Currency::unreserve(&owner, approval.deposit); removed_approvals = removed_approvals.saturating_add(1); details.approvals = details.approvals.saturating_sub(1); @@ -819,7 +827,8 @@ impl, I: 'static> Pallet { approvals_remaining: details.approvals as u32, }); Ok(()) - })?; + }, + )?; Ok(removed_approvals) } @@ -827,7 +836,7 @@ impl, I: 'static> Pallet { /// /// On success, the `Event::Destroyed` event is emitted. pub(super) fn do_finish_destroy(id: T::AssetId) -> DispatchResult { - Asset::::try_mutate_exists(id, |maybe_details| -> Result<(), DispatchError> { + Asset::::try_mutate_exists(id.clone(), |maybe_details| -> Result<(), DispatchError> { let details = maybe_details.take().ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Destroying, Error::::IncorrectStatus); ensure!(details.accounts == 0, Error::::InUse); @@ -855,10 +864,10 @@ impl, I: 'static> Pallet { delegate: &T::AccountId, amount: T::Balance, ) -> DispatchResult { - let mut d = Asset::::get(id).ok_or(Error::::Unknown)?; + let mut d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); Approvals::::try_mutate( - (id, &owner, &delegate), + (id.clone(), &owner, &delegate), |maybe_approved| -> DispatchResult { let mut approved = match maybe_approved.take() { // an approval already exists and is being updated @@ -879,7 +888,7 @@ impl, I: 'static> Pallet { Ok(()) }, )?; - Asset::::insert(id, d); + Asset::::insert(id.clone(), d); Self::deposit_event(Event::ApprovedTransfer { asset_id: id, source: owner.clone(), @@ -906,22 +915,23 @@ impl, I: 'static> Pallet { ) -> DispatchResult { let mut owner_died: Option = None; - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); Approvals::::try_mutate_exists( - (id, &owner, delegate), + (id.clone(), &owner, delegate), |maybe_approved| -> DispatchResult { let mut approved = maybe_approved.take().ok_or(Error::::Unapproved)?; let remaining = 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, owner, destination, amount, None, f)?.1; + owner_died = + Self::transfer_and_die(id.clone(), owner, destination, amount, None, f)?.1; if remaining.is_zero() { T::Currency::unreserve(owner, approved.deposit); - Asset::::mutate(id, |maybe_details| { + Asset::::mutate(id.clone(), |maybe_details| { if let Some(details) = maybe_details { details.approvals.saturating_dec(); } @@ -954,11 +964,11 @@ impl, I: 'static> Pallet { let bounded_symbol: BoundedVec = symbol.clone().try_into().map_err(|_| Error::::BadMetadata)?; - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); ensure!(from == &d.owner, Error::::NoPermission); - Metadata::::try_mutate_exists(id, |metadata| { + Metadata::::try_mutate_exists(id.clone(), |metadata| { ensure!(metadata.as_ref().map_or(true, |m| !m.is_frozen), Error::::NoPermission); let old_deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); diff --git a/frame/assets/src/impl_stored_map.rs b/frame/assets/src/impl_stored_map.rs index 5ead708469a94..b71c6afb19550 100644 --- a/frame/assets/src/impl_stored_map.rs +++ b/frame/assets/src/impl_stored_map.rs @@ -21,7 +21,7 @@ use super::*; impl, I: 'static> StoredMap<(T::AssetId, T::AccountId), T::Extra> for Pallet { fn get(id_who: &(T::AssetId, T::AccountId)) -> T::Extra { - let &(id, ref who) = id_who; + let &(ref id, ref who) = id_who; Account::::get(id, who).map(|a| a.extra).unwrap_or_default() } @@ -29,7 +29,7 @@ impl, I: 'static> StoredMap<(T::AssetId, T::AccountId), T::Extra> f id_who: &(T::AssetId, T::AccountId), f: impl FnOnce(&mut Option) -> Result, ) -> Result { - let &(id, ref who) = id_who; + let &(ref id, ref who) = id_who; let mut maybe_extra = Account::::get(id, who).map(|a| a.extra); let r = f(&mut maybe_extra)?; // They want to write some value or delete it. diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 33aacd9323bf2..3bcf5a9845b7a 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -434,7 +434,7 @@ pub mod pallet { for (id, account_id, amount) in &self.accounts { let result = >::increase_balance( - *id, + id.clone(), account_id, *amount, |details| -> DispatchResult { @@ -615,14 +615,14 @@ pub mod pallet { let owner = T::CreateOrigin::ensure_origin(origin, &id)?; let admin = T::Lookup::lookup(admin)?; - ensure!(!Asset::::contains_key(id), Error::::InUse); + ensure!(!Asset::::contains_key(&id), Error::::InUse); ensure!(!min_balance.is_zero(), Error::::MinBalanceZero); let deposit = T::AssetDeposit::get(); T::Currency::reserve(&owner, deposit)?; Asset::::insert( - id, + id.clone(), AssetDetails { owner: owner.clone(), issuer: admin.clone(), @@ -947,7 +947,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!( d.status == AssetStatus::Live || d.status == AssetStatus::Frozen, Error::::AssetNotLive @@ -984,7 +984,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - let details = Asset::::get(id).ok_or(Error::::Unknown)?; + let details = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!( details.status == AssetStatus::Live || details.status == AssetStatus::Frozen, Error::::AssetNotLive @@ -1016,7 +1016,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - Asset::::try_mutate(id, |maybe_details| { + Asset::::try_mutate(id.clone(), |maybe_details| { let d = maybe_details.as_mut().ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); ensure!(origin == d.freezer, Error::::NoPermission); @@ -1042,7 +1042,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - Asset::::try_mutate(id, |maybe_details| { + Asset::::try_mutate(id.clone(), |maybe_details| { let d = maybe_details.as_mut().ok_or(Error::::Unknown)?; ensure!(origin == d.admin, Error::::NoPermission); ensure!(d.status == AssetStatus::Frozen, Error::::NotFrozen); @@ -1074,7 +1074,7 @@ pub mod pallet { let owner = T::Lookup::lookup(owner)?; let id: T::AssetId = id.into(); - Asset::::try_mutate(id, |maybe_details| { + Asset::::try_mutate(id.clone(), |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::LiveAsset); ensure!(origin == details.owner, Error::::NoPermission); @@ -1082,7 +1082,7 @@ pub mod pallet { return Ok(()) } - let metadata_deposit = Metadata::::get(id).deposit; + let metadata_deposit = Metadata::::get(&id).deposit; let deposit = details.deposit + metadata_deposit; // Move the deposit to the new owner. @@ -1121,7 +1121,7 @@ pub mod pallet { let freezer = T::Lookup::lookup(freezer)?; let id: T::AssetId = id.into(); - Asset::::try_mutate(id, |maybe_details| { + Asset::::try_mutate(id.clone(), |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); ensure!(origin == details.owner, Error::::NoPermission); @@ -1181,11 +1181,11 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); ensure!(origin == d.owner, Error::::NoPermission); - Metadata::::try_mutate_exists(id, |metadata| { + Metadata::::try_mutate_exists(id.clone(), |metadata| { let deposit = metadata.take().ok_or(Error::::Unknown)?.deposit; T::Currency::unreserve(&d.owner, deposit); Self::deposit_event(Event::MetadataCleared { asset_id: id }); @@ -1226,8 +1226,8 @@ pub mod pallet { let bounded_symbol: BoundedVec = symbol.clone().try_into().map_err(|_| Error::::BadMetadata)?; - ensure!(Asset::::contains_key(id), Error::::Unknown); - Metadata::::try_mutate_exists(id, |metadata| { + ensure!(Asset::::contains_key(&id), Error::::Unknown); + Metadata::::try_mutate_exists(id.clone(), |metadata| { let deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); *metadata = Some(AssetMetadata { deposit, @@ -1267,8 +1267,8 @@ pub mod pallet { T::ForceOrigin::ensure_origin(origin)?; let id: T::AssetId = id.into(); - let d = Asset::::get(id).ok_or(Error::::Unknown)?; - Metadata::::try_mutate_exists(id, |metadata| { + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; + Metadata::::try_mutate_exists(id.clone(), |metadata| { let deposit = metadata.take().ok_or(Error::::Unknown)?.deposit; T::Currency::unreserve(&d.owner, deposit); Self::deposit_event(Event::MetadataCleared { asset_id: id }); @@ -1313,7 +1313,7 @@ pub mod pallet { T::ForceOrigin::ensure_origin(origin)?; let id: T::AssetId = id.into(); - Asset::::try_mutate(id, |maybe_asset| { + Asset::::try_mutate(id.clone(), |maybe_asset| { let mut asset = maybe_asset.take().ok_or(Error::::Unknown)?; ensure!(asset.status != AssetStatus::Destroying, Error::::AssetNotLive); asset.owner = T::Lookup::lookup(owner)?; @@ -1437,11 +1437,11 @@ pub mod pallet { let owner = T::Lookup::lookup(owner)?; let delegate = T::Lookup::lookup(delegate)?; - let approval = - Approvals::::take((id, &owner, &delegate)).ok_or(Error::::Unknown)?; + let approval = Approvals::::take((id.clone(), &owner, &delegate)) + .ok_or(Error::::Unknown)?; T::Currency::unreserve(&owner, approval.deposit); d.approvals.saturating_dec(); - Asset::::insert(id, d); + Asset::::insert(id.clone(), d); Self::deposit_event(Event::ApprovalCancelled { asset_id: id, owner, delegate }); Ok(()) diff --git a/frame/support/src/traits/tokens/fungibles/hold.rs b/frame/support/src/traits/tokens/fungibles/hold.rs index 68580ebff4bce..8fc038c57be3d 100644 --- a/frame/support/src/traits/tokens/fungibles/hold.rs +++ b/frame/support/src/traits/tokens/fungibles/hold.rs @@ -98,7 +98,7 @@ pub trait Inspect: super::Inspect { who: &AccountId, amount: Self::Balance, ) -> DispatchResult { - ensure!(Self::hold_available(asset, reason, who), TokenError::CannotCreateHold); + ensure!(Self::hold_available(asset.clone(), reason, who), TokenError::CannotCreateHold); ensure!( amount <= Self::reducible_balance(asset, who, Protect, Force), TokenError::FundsUnavailable @@ -173,7 +173,7 @@ pub trait Unbalanced: Inspect { mut amount: Self::Balance, precision: Precision, ) -> Result { - let old_balance = Self::balance_on_hold(asset, reason, who); + let old_balance = Self::balance_on_hold(asset.clone(), reason, who); if let BestEffort = precision { amount = amount.min(old_balance); } @@ -193,7 +193,7 @@ pub trait Unbalanced: Inspect { amount: Self::Balance, precision: Precision, ) -> Result { - let old_balance = Self::balance_on_hold(asset, reason, who); + let old_balance = Self::balance_on_hold(asset.clone(), reason, who); let new_balance = if let BestEffort = precision { old_balance.saturating_add(amount) } else { @@ -221,11 +221,13 @@ pub trait Balanced: super::Balanced + Unbalanced (Credit, Self::Balance) { - let decrease = Self::decrease_balance_on_hold(asset, reason, who, amount, BestEffort) - .unwrap_or(Default::default()); + let decrease = + Self::decrease_balance_on_hold(asset.clone(), reason, who, amount, BestEffort) + .unwrap_or(Default::default()); let credit = Imbalance::::new( - asset, decrease, + asset.clone(), + decrease, ); Self::done_slash(asset, reason, who, decrease); (credit, amount.saturating_sub(decrease)) @@ -255,10 +257,10 @@ pub trait Mutate: // NOTE: This doesn't change the total balance of the account so there's no need to // check liquidity. - Self::ensure_can_hold(asset, reason, who, amount)?; + Self::ensure_can_hold(asset.clone(), reason, who, amount)?; // Should be infallible now, but we proceed softly anyway. - Self::decrease_balance(asset, who, amount, Exact, Protect, Force)?; - Self::increase_balance_on_hold(asset, reason, who, amount, BestEffort)?; + Self::decrease_balance(asset.clone(), who, amount, Exact, Protect, Force)?; + Self::increase_balance_on_hold(asset.clone(), reason, who, amount, BestEffort)?; Self::done_hold(asset, reason, who, amount); Ok(()) } @@ -281,13 +283,16 @@ 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, who, amount, Extant) == Success, TokenError::CannotCreate); + ensure!( + Self::can_deposit(asset.clone(), who, amount, Extant) == Success, + TokenError::CannotCreate + ); // Get the amount we can actually take from the hold. This might be less than what we want // if we're only doing a best-effort. - let amount = Self::decrease_balance_on_hold(asset, reason, who, amount, precision)?; + 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, who, amount, BestEffort)?; + let actual = Self::increase_balance(asset.clone(), who, amount, BestEffort)?; Self::done_release(asset, reason, who, actual); Ok(actual) } @@ -310,14 +315,17 @@ pub trait Mutate: force: Fortitude, ) -> Result { // We must check total-balance requirements if `!force`. - let liquid = Self::reducible_total_balance_on_hold(asset, who, force); + let liquid = Self::reducible_total_balance_on_hold(asset.clone(), who, force); if let BestEffort = precision { amount = amount.min(liquid); } else { ensure!(amount <= liquid, TokenError::Frozen); } - let amount = Self::decrease_balance_on_hold(asset, reason, who, amount, precision)?; - Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_sub(amount)); + 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::done_burn_held(asset, reason, who, amount); Ok(amount) } @@ -348,8 +356,8 @@ pub trait Mutate: force: Fortitude, ) -> Result { // We must check total-balance requirements if `!force`. - let have = Self::balance_on_hold(asset, reason, source); - let liquid = Self::reducible_total_balance_on_hold(asset, source, force); + let have = Self::balance_on_hold(asset.clone(), reason, source); + let liquid = Self::reducible_total_balance_on_hold(asset.clone(), source, force); if let BestEffort = precision { amount = amount.min(liquid).min(have); } else { @@ -360,19 +368,20 @@ 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, dest, amount, Extant) == Success, + Self::can_deposit(asset.clone(), dest, amount, Extant) == Success, TokenError::CannotCreate ); ensure!( - mode == Free || Self::hold_available(asset, reason, dest), + mode == Free || Self::hold_available(asset.clone(), reason, dest), TokenError::CannotCreateHold ); - let amount = Self::decrease_balance_on_hold(asset, reason, source, amount, precision)?; + let amount = + Self::decrease_balance_on_hold(asset.clone(), reason, source, amount, precision)?; let actual = if mode == OnHold { - Self::increase_balance_on_hold(asset, reason, dest, amount, precision)? + Self::increase_balance_on_hold(asset.clone(), reason, dest, amount, precision)? } else { - Self::increase_balance(asset, dest, amount, precision)? + Self::increase_balance(asset.clone(), dest, amount, precision)? }; Self::done_transfer_on_hold(asset, reason, source, dest, actual); Ok(actual) @@ -405,14 +414,14 @@ pub trait Mutate: expendability: Preservation, force: Fortitude, ) -> Result { - ensure!(Self::hold_available(asset, reason, dest), TokenError::CannotCreateHold); + ensure!(Self::hold_available(asset.clone(), reason, dest), TokenError::CannotCreateHold); ensure!( - Self::can_deposit(asset, dest, amount, Extant) == Success, + Self::can_deposit(asset.clone(), dest, amount, Extant) == Success, TokenError::CannotCreate ); let actual = - Self::decrease_balance(asset, source, amount, precision, expendability, force)?; - Self::increase_balance_on_hold(asset, reason, dest, actual, precision)?; + Self::decrease_balance(asset.clone(), 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/frame/support/src/traits/tokens/fungibles/imbalance.rs b/frame/support/src/traits/tokens/fungibles/imbalance.rs index ab18eec3811ff..1668268ea2dcf 100644 --- a/frame/support/src/traits/tokens/fungibles/imbalance.rs +++ b/frame/support/src/traits/tokens/fungibles/imbalance.rs @@ -59,7 +59,7 @@ impl< { fn drop(&mut self) { if !self.amount.is_zero() { - OnDrop::handle(self.asset, self.amount) + OnDrop::handle(self.asset.clone(), self.amount) } } } @@ -104,9 +104,9 @@ impl< pub fn split(self, amount: B) -> (Self, Self) { let first = self.amount.min(amount); let second = self.amount - first; - let asset = self.asset; + let asset = self.asset.clone(); sp_std::mem::forget(self); - (Imbalance::new(asset, first), Imbalance::new(asset, second)) + (Imbalance::new(asset.clone(), first), Imbalance::new(asset, second)) } pub fn merge(mut self, other: Self) -> Result { if self.asset == other.asset { @@ -135,7 +135,7 @@ impl< > { if self.asset == other.asset { let (a, b) = (self.amount, other.amount); - let asset = self.asset; + let asset = self.asset.clone(); sp_std::mem::forget((self, other)); if a == b { @@ -154,7 +154,7 @@ impl< } pub fn asset(&self) -> A { - self.asset + self.asset.clone() } } diff --git a/frame/support/src/traits/tokens/fungibles/regular.rs b/frame/support/src/traits/tokens/fungibles/regular.rs index 27d1a50b34805..5a9d3e6e4b56e 100644 --- a/frame/support/src/traits/tokens/fungibles/regular.rs +++ b/frame/support/src/traits/tokens/fungibles/regular.rs @@ -146,7 +146,7 @@ pub trait Unbalanced: Inspect { /// This should not be reimplemented. fn handle_raw_dust(asset: Self::AssetId, amount: Self::Balance) { Self::handle_dust(Dust( - asset, + asset.clone(), amount.min(Self::minimum_balance(asset).saturating_sub(One::one())), )) } @@ -193,13 +193,13 @@ pub trait Unbalanced: Inspect { preservation: Preservation, force: Fortitude, ) -> Result { - let old_balance = Self::balance(asset, who); - let free = Self::reducible_balance(asset, who, preservation, force); + let old_balance = Self::balance(asset.clone(), who); + let free = Self::reducible_balance(asset.clone(), who, preservation, force); if let BestEffort = precision { amount = amount.min(free); } let new_balance = old_balance.checked_sub(&amount).ok_or(TokenError::FundsUnavailable)?; - if let Some(dust) = Self::write_balance(asset, who, new_balance)? { + if let Some(dust) = Self::write_balance(asset.clone(), who, new_balance)? { Self::handle_dust(Dust(asset, dust)); } Ok(old_balance.saturating_sub(new_balance)) @@ -217,13 +217,13 @@ pub trait Unbalanced: Inspect { amount: Self::Balance, precision: Precision, ) -> Result { - let old_balance = Self::balance(asset, who); + let old_balance = Self::balance(asset.clone(), 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) { + if new_balance < Self::minimum_balance(asset.clone()) { // Attempt to increase from 0 to below minimum -> stays at zero. if let BestEffort = precision { Ok(Self::Balance::default()) @@ -234,7 +234,7 @@ pub trait Unbalanced: Inspect { if new_balance == old_balance { Ok(Self::Balance::default()) } else { - if let Some(dust) = Self::write_balance(asset, who, new_balance)? { + if let Some(dust) = Self::write_balance(asset.clone(), who, new_balance)? { Self::handle_dust(Dust(asset, dust)); } Ok(new_balance.saturating_sub(old_balance)) @@ -258,11 +258,14 @@ pub trait Mutate: Inspect + Unbalanced { who: &AccountId, amount: Self::Balance, ) -> Result { - Self::total_issuance(asset) + Self::total_issuance(asset.clone()) .checked_add(&amount) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::increase_balance(asset, who, amount, Exact)?; - Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_add(actual)); + let actual = Self::increase_balance(asset.clone(), who, amount, Exact)?; + Self::set_total_issuance( + asset.clone(), + Self::total_issuance(asset.clone()).saturating_add(actual), + ); Self::done_mint_into(asset, who, amount); Ok(actual) } @@ -277,13 +280,17 @@ pub trait Mutate: Inspect + Unbalanced { precision: Precision, force: Fortitude, ) -> Result { - let actual = Self::reducible_balance(asset, who, Expendable, force).min(amount); + let actual = Self::reducible_balance(asset.clone(), who, Expendable, force).min(amount); ensure!(actual == amount || precision == BestEffort, TokenError::FundsUnavailable); - Self::total_issuance(asset) + Self::total_issuance(asset.clone()) .checked_sub(&actual) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::decrease_balance(asset, who, actual, BestEffort, Expendable, force)?; - Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_sub(actual)); + 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), + ); Self::done_burn_from(asset, who, actual); Ok(actual) } @@ -303,13 +310,17 @@ pub trait Mutate: Inspect + Unbalanced { who: &AccountId, amount: Self::Balance, ) -> Result { - let actual = Self::reducible_balance(asset, who, Expendable, Polite).min(amount); + let actual = Self::reducible_balance(asset.clone(), who, Expendable, Polite).min(amount); ensure!(actual == amount, TokenError::FundsUnavailable); - Self::total_issuance(asset) + Self::total_issuance(asset.clone()) .checked_sub(&actual) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::decrease_balance(asset, who, actual, BestEffort, Expendable, Polite)?; - Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_sub(actual)); + 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), + ); Self::done_shelve(asset, who, actual); Ok(actual) } @@ -329,11 +340,14 @@ pub trait Mutate: Inspect + Unbalanced { who: &AccountId, amount: Self::Balance, ) -> Result { - Self::total_issuance(asset) + Self::total_issuance(asset.clone()) .checked_add(&amount) .ok_or(ArithmeticError::Overflow)?; - let actual = Self::increase_balance(asset, who, amount, Exact)?; - Self::set_total_issuance(asset, Self::total_issuance(asset).saturating_add(actual)); + let actual = Self::increase_balance(asset.clone(), who, amount, Exact)?; + Self::set_total_issuance( + asset.clone(), + Self::total_issuance(asset.clone()).saturating_add(actual), + ); Self::done_restore(asset, who, amount); Ok(actual) } @@ -346,13 +360,13 @@ pub trait Mutate: Inspect + Unbalanced { amount: Self::Balance, preservation: Preservation, ) -> Result { - let _extra = - Self::can_withdraw(asset, source, amount).into_result(preservation != Expendable)?; - Self::can_deposit(asset, dest, amount, Extant).into_result()?; - Self::decrease_balance(asset, source, amount, BestEffort, preservation, Polite)?; + let _extra = Self::can_withdraw(asset.clone(), source, amount) + .into_result(preservation != Expendable)?; + Self::can_deposit(asset.clone(), dest, amount, Extant).into_result()?; + Self::decrease_balance(asset.clone(), 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, dest, amount, BestEffort); + let _ = Self::increase_balance(asset.clone(), dest, amount, BestEffort); Self::done_transfer(asset, source, dest, amount); Ok(amount) } @@ -363,7 +377,7 @@ pub trait Mutate: Inspect + Unbalanced { /// /// Returns the new balance. fn set_balance(asset: Self::AssetId, who: &AccountId, amount: Self::Balance) -> Self::Balance { - let b = Self::balance(asset, who); + let b = Self::balance(asset.clone(), who); if b > amount { Self::burn_from(asset, who, b - amount, BestEffort, Force).map(|d| b.saturating_sub(d)) } else { @@ -391,7 +405,7 @@ impl> HandleImbalanceDrop { fn handle(asset: U::AssetId, amount: U::Balance) { - U::set_total_issuance(asset, U::total_issuance(asset).saturating_add(amount)) + U::set_total_issuance(asset.clone(), U::total_issuance(asset).saturating_add(amount)) } } @@ -402,7 +416,7 @@ impl> HandleImbalanceDrop { fn handle(asset: U::AssetId, amount: U::Balance) { - U::set_total_issuance(asset, U::total_issuance(asset).saturating_sub(amount)) + U::set_total_issuance(asset.clone(), U::total_issuance(asset).saturating_sub(amount)) } } @@ -423,11 +437,11 @@ 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); + let old = Self::total_issuance(asset.clone()); let new = old.saturating_sub(amount); - Self::set_total_issuance(asset, new); + Self::set_total_issuance(asset.clone(), new); let delta = old - new; - Self::done_rescind(asset, delta); + Self::done_rescind(asset.clone(), delta); Imbalance::::new( asset, delta, ) @@ -440,11 +454,11 @@ 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); + let old = Self::total_issuance(asset.clone()); let new = old.saturating_add(amount); - Self::set_total_issuance(asset, new); + Self::set_total_issuance(asset.clone(), new); let delta = new - old; - Self::done_issue(asset, delta); + Self::done_issue(asset.clone(), delta); Imbalance::::new( asset, delta, ) @@ -458,7 +472,7 @@ pub trait Balanced: Inspect + Unbalanced { asset: Self::AssetId, amount: Self::Balance, ) -> (Debt, Credit) { - (Self::rescind(asset, amount), Self::issue(asset, amount)) + (Self::rescind(asset.clone(), amount), Self::issue(asset, amount)) } /// Mints `value` into the account of `who`, creating it as needed. @@ -476,8 +490,8 @@ pub trait Balanced: Inspect + Unbalanced { value: Self::Balance, precision: Precision, ) -> Result, DispatchError> { - let increase = Self::increase_balance(asset, who, value, precision)?; - Self::done_deposit(asset, who, increase); + let increase = Self::increase_balance(asset.clone(), who, value, precision)?; + Self::done_deposit(asset.clone(), who, increase); Ok(Imbalance::::new( asset, increase, )) @@ -504,8 +518,9 @@ pub trait Balanced: Inspect + Unbalanced { preservation: Preservation, force: Fortitude, ) -> Result, DispatchError> { - let decrease = Self::decrease_balance(asset, who, value, precision, preservation, force)?; - Self::done_withdraw(asset, who, decrease); + let decrease = + Self::decrease_balance(asset.clone(), who, value, precision, preservation, force)?; + Self::done_withdraw(asset.clone(), who, decrease); Ok(Imbalance::::new( asset, decrease, )) @@ -545,7 +560,7 @@ pub trait Balanced: Inspect + Unbalanced { ) -> Result, Debt> { let amount = debt.peek(); let asset = debt.asset(); - let credit = match Self::withdraw(asset, who, amount, Exact, preservation, Polite) { + let credit = match Self::withdraw(asset.clone(), who, amount, Exact, preservation, Polite) { Err(_) => return Err(debt), Ok(d) => d, }; diff --git a/frame/support/src/traits/tokens/misc.rs b/frame/support/src/traits/tokens/misc.rs index 0ba900e95f9b8..45da4f5a70e93 100644 --- a/frame/support/src/traits/tokens/misc.rs +++ b/frame/support/src/traits/tokens/misc.rs @@ -221,10 +221,10 @@ impl WithdrawReasons { /// Simple amalgamation trait to collect together properties for an AssetId under one roof. pub trait AssetId: - FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen + FullCodec + Clone + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen { } -impl AssetId +impl AssetId for T { } From a366c9ea9dcd4e6613b142705547828ecea4345f Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 May 2023 11:24:58 +0000 Subject: [PATCH 2/8] Also relax the `Copy` bound in the assets pallet --- frame/assets/src/functions.rs | 22 ++++++++++++---------- frame/assets/src/lib.rs | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index d0a431d85dde1..c291a08afa595 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -128,7 +128,7 @@ impl, I: 'static> Pallet { amount: T::Balance, increase_supply: bool, ) -> DepositConsequence { - let details = match Asset::::get(id) { + let details = match Asset::::get(id.clone()) { Some(details) => details, None => return DepositConsequence::UnknownAsset, }; @@ -219,10 +219,10 @@ impl, I: 'static> Pallet { 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) { @@ -320,7 +320,7 @@ impl, I: 'static> Pallet { depositor: T::AccountId, check_depositor: bool, ) -> DispatchResult { - ensure!(!Account::::contains_key(id, &who), Error::::AlreadyExists); + ensure!(!Account::::contains_key(&id, &who), Error::::AlreadyExists); let deposit = T::AssetAccountDeposit::get(); let mut details = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); @@ -332,7 +332,7 @@ impl, I: 'static> Pallet { T::Currency::reserve(&depositor, deposit)?; Asset::::insert(&id, details); Account::::insert( - id, + id.clone(), &who, AssetAccountOf:: { balance: Zero::zero(), @@ -350,7 +350,7 @@ impl, I: 'static> Pallet { 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)?; ensure!(matches!(details.status, Live | Frozen), Error::::IncorrectStatus); @@ -380,7 +380,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, caller: &T::AccountId, ) -> 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)?; @@ -392,11 +392,11 @@ 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); @@ -1004,7 +1004,9 @@ 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, account.clone()).map(|balance| (id, balance))) + .filter_map(|id| { + Self::maybe_balance(id.clone(), account.clone()).map(|balance| (id, balance)) + }) .collect::>() } } diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 3bcf5a9845b7a..e804d883bacdf 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -250,7 +250,7 @@ pub mod pallet { type RemoveItemsLimit: Get; /// Identifier for the class of asset. - type AssetId: Member + Parameter + Copy + MaybeSerializeDeserialize + MaxEncodedLen; + type AssetId: Member + Parameter + Clone + MaybeSerializeDeserialize + MaxEncodedLen; /// Wrapper around `Self::AssetId` to use in dispatchable call signatures. Allows the use /// of compact encoding in instances of the pallet, which will prevent breaking changes @@ -955,7 +955,7 @@ pub mod pallet { ensure!(origin == d.freezer, Error::::NoPermission); let who = T::Lookup::lookup(who)?; - Account::::try_mutate(id, &who, |maybe_account| -> DispatchResult { + Account::::try_mutate(&id, &who, |maybe_account| -> DispatchResult { maybe_account.as_mut().ok_or(Error::::NoAccount)?.status = AccountStatus::Frozen; Ok(()) @@ -992,7 +992,7 @@ pub mod pallet { ensure!(origin == details.admin, Error::::NoPermission); let who = T::Lookup::lookup(who)?; - Account::::try_mutate(id, &who, |maybe_account| -> DispatchResult { + Account::::try_mutate(&id, &who, |maybe_account| -> DispatchResult { maybe_account.as_mut().ok_or(Error::::NoAccount)?.status = AccountStatus::Liquid; Ok(()) @@ -1389,15 +1389,15 @@ pub mod pallet { let owner = ensure_signed(origin)?; let delegate = T::Lookup::lookup(delegate)?; let id: T::AssetId = id.into(); - let mut d = Asset::::get(id).ok_or(Error::::Unknown)?; + let mut d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); - let approval = - Approvals::::take((id, &owner, &delegate)).ok_or(Error::::Unknown)?; + let approval = Approvals::::take((id.clone(), &owner, &delegate)) + .ok_or(Error::::Unknown)?; T::Currency::unreserve(&owner, approval.deposit); d.approvals.saturating_dec(); - Asset::::insert(id, d); + Asset::::insert(id.clone(), d); Self::deposit_event(Event::ApprovalCancelled { asset_id: id, owner, delegate }); Ok(()) @@ -1424,7 +1424,7 @@ pub mod pallet { delegate: AccountIdLookupOf, ) -> DispatchResult { let id: T::AssetId = id.into(); - let mut d = Asset::::get(id).ok_or(Error::::Unknown)?; + let mut d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(d.status == AssetStatus::Live, Error::::AssetNotLive); T::ForceOrigin::try_origin(origin) .map(|_| ()) @@ -1539,7 +1539,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - let mut details = Asset::::get(id).ok_or(Error::::Unknown)?; + let mut details = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!(origin == details.owner, Error::::NoPermission); let old_min_balance = details.min_balance; @@ -1629,7 +1629,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); - let d = Asset::::get(id).ok_or(Error::::Unknown)?; + let d = Asset::::get(&id).ok_or(Error::::Unknown)?; ensure!( d.status == AssetStatus::Live || d.status == AssetStatus::Frozen, Error::::AssetNotLive @@ -1637,7 +1637,7 @@ pub mod pallet { ensure!(origin == d.freezer, Error::::NoPermission); let who = T::Lookup::lookup(who)?; - Account::::try_mutate(id, &who, |maybe_account| -> DispatchResult { + Account::::try_mutate(&id, &who, |maybe_account| -> DispatchResult { maybe_account.as_mut().ok_or(Error::::NoAccount)?.status = AccountStatus::Blocked; Ok(()) From b3a939be151a93b86932fd725a153713fc73bac2 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 May 2023 11:27:12 +0000 Subject: [PATCH 3/8] Fix warnings on the newest nightly Rust --- frame/assets/src/extra_mutator.rs | 4 ++-- frame/assets/src/functions.rs | 4 ++-- frame/assets/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/assets/src/extra_mutator.rs b/frame/assets/src/extra_mutator.rs index bf7fd12f40f0b..2a44df5f0c661 100644 --- a/frame/assets/src/extra_mutator.rs +++ b/frame/assets/src/extra_mutator.rs @@ -77,7 +77,7 @@ impl, I: 'static> ExtraMutator { /// Commit any changes to storage. pub fn commit(&mut self) -> Result<(), ()> { if let Some(extra) = self.pending.take() { - Account::::try_mutate(&self.id, self.who.borrow(), |maybe_account| { + Account::::try_mutate(&self.id, &self.who, |maybe_account| { maybe_account.as_mut().ok_or(()).map(|account| account.extra = extra) }) } else { @@ -88,7 +88,7 @@ impl, I: 'static> ExtraMutator { /// Revert any changes, even those already committed by `self` and drop self. pub fn revert(mut self) -> Result<(), ()> { self.pending = None; - Account::::try_mutate(&self.id, self.who.borrow(), |maybe_account| { + Account::::try_mutate(&self.id, &self.who, |maybe_account| { maybe_account .as_mut() .ok_or(()) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index c291a08afa595..4552b56a6bb68 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -744,7 +744,7 @@ impl, I: 'static> Pallet { maybe_check_owner: Option, ) -> DispatchResult { Asset::::try_mutate_exists(id.clone(), |maybe_details| -> Result<(), DispatchError> { - let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; + let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; if let Some(check_owner) = maybe_check_owner { ensure!(details.owner == check_owner, Error::::NoPermission); } @@ -808,7 +808,7 @@ impl, I: 'static> Pallet { let _ = Asset::::try_mutate_exists( id.clone(), |maybe_details| -> Result<(), DispatchError> { - let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; + let details = maybe_details.as_mut().ok_or(Error::::Unknown)?; // Should only destroy accounts while the asset is in a destroying state. ensure!(details.status == AssetStatus::Destroying, Error::::IncorrectStatus); diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index e804d883bacdf..44420f8060788 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -162,7 +162,7 @@ use sp_runtime::{ traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero}, ArithmeticError, TokenError, }; -use sp_std::{borrow::Borrow, prelude::*}; +use sp_std::prelude::*; use frame_support::{ dispatch::{DispatchError, DispatchResult}, From 49d0b1a903463221d03fc6e636a877eb600dd2c5 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 May 2023 11:30:53 +0000 Subject: [PATCH 4/8] Remove some unnecessary `clone()`s --- frame/assets/src/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index 4552b56a6bb68..f93a1b1e9983d 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -128,7 +128,7 @@ impl, I: 'static> Pallet { amount: T::Balance, increase_supply: bool, ) -> DepositConsequence { - let details = match Asset::::get(id.clone()) { + let details = match Asset::::get(&id) { Some(details) => details, None => return DepositConsequence::UnknownAsset, }; @@ -451,7 +451,7 @@ impl, I: 'static> Pallet { } Self::can_increase(id.clone(), beneficiary, amount, true).into_result()?; - Asset::::try_mutate(id.clone(), |maybe_details| -> DispatchResult { + 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)?; From 4130ea7a5da315cd3901617b205e454e0a23366d Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 16 May 2023 11:58:46 +0000 Subject: [PATCH 5/8] Try to satisfy clippy --- frame/assets/src/impl_stored_map.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/assets/src/impl_stored_map.rs b/frame/assets/src/impl_stored_map.rs index b71c6afb19550..a7a5a0859f701 100644 --- a/frame/assets/src/impl_stored_map.rs +++ b/frame/assets/src/impl_stored_map.rs @@ -21,7 +21,7 @@ use super::*; impl, I: 'static> StoredMap<(T::AssetId, T::AccountId), T::Extra> for Pallet { fn get(id_who: &(T::AssetId, T::AccountId)) -> T::Extra { - let &(ref id, ref who) = id_who; + let (id, who) = id_who; Account::::get(id, who).map(|a| a.extra).unwrap_or_default() } @@ -29,7 +29,7 @@ impl, I: 'static> StoredMap<(T::AssetId, T::AccountId), T::Extra> f id_who: &(T::AssetId, T::AccountId), f: impl FnOnce(&mut Option) -> Result, ) -> Result { - let &(ref id, ref who) = id_who; + let (id, who) = id_who; let mut maybe_extra = Account::::get(id, who).map(|a| a.extra); let r = f(&mut maybe_extra)?; // They want to write some value or delete it. From 289c057ba234cb29b76125c43504376a9f33a3e1 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Wed, 17 May 2023 03:56:21 +0000 Subject: [PATCH 6/8] Remove some more unnecessary `clone()`s --- frame/assets/src/functions.rs | 70 ++++++++++++++++------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index f93a1b1e9983d..f89ae428fb441 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -332,7 +332,7 @@ impl, I: 'static> Pallet { T::Currency::reserve(&depositor, deposit)?; Asset::::insert(&id, details); Account::::insert( - id.clone(), + &id, &who, AssetAccountOf:: { balance: Zero::zero(), @@ -456,29 +456,25 @@ impl, I: 'static> Pallet { ensure!(details.status == AssetStatus::Live, Error::::AssetNotLive); check(details)?; - Account::::try_mutate( - id.clone(), - beneficiary, - |maybe_account| -> DispatchResult { - match maybe_account { - Some(ref mut account) => { - account.balance.saturating_accrue(amount); - }, - maybe_account @ None => { - // Note this should never fail as it's already checked by - // `can_increase`. - ensure!(amount >= details.min_balance, TokenError::BelowMinimum); - *maybe_account = Some(AssetAccountOf:: { - balance: amount, - reason: Self::new_account(beneficiary, details, None)?, - status: AccountStatus::Liquid, - extra: T::Extra::default(), - }); - }, - } - Ok(()) - }, - )?; + Account::::try_mutate(&id, beneficiary, |maybe_account| -> DispatchResult { + match maybe_account { + Some(ref mut account) => { + account.balance.saturating_accrue(amount); + }, + maybe_account @ None => { + // Note this should never fail as it's already checked by + // `can_increase`. + ensure!(amount >= details.min_balance, TokenError::BelowMinimum); + *maybe_account = Some(AssetAccountOf:: { + balance: amount, + reason: Self::new_account(beneficiary, details, None)?, + status: AccountStatus::Liquid, + extra: T::Extra::default(), + }); + }, + } + Ok(()) + })?; Ok(()) })?; Ok(()) @@ -547,11 +543,11 @@ impl, I: 'static> Pallet { let actual = Self::prep_debit(id.clone(), target, amount, f)?; let mut target_died: Option = None; - Asset::::try_mutate(id.clone(), |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.clone(), 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"); @@ -624,7 +620,7 @@ impl, I: 'static> Pallet { let (credit, maybe_burn) = Self::prep_credit(id.clone(), dest, amount, debit, f.burn_dust)?; let mut source_account = - Account::::get(id.clone(), &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 { @@ -652,7 +648,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.clone(), &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 @@ -681,11 +677,11 @@ 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.clone(), &source); + Account::::remove(&id, &source); return Ok(()) } } - Account::::insert(id.clone(), &source, &source_account); + Account::::insert(&id, &source, &source_account); Ok(()) })?; @@ -716,7 +712,7 @@ impl, I: 'static> Pallet { ensure!(!min_balance.is_zero(), Error::::MinBalanceZero); Asset::::insert( - id.clone(), + &id, AssetDetails { owner: owner.clone(), issuer: owner.clone(), @@ -765,14 +761,13 @@ impl, I: 'static> Pallet { ) -> Result { let mut dead_accounts: Vec = vec![]; let mut remaining_accounts = 0; - let _ = Asset::::try_mutate_exists( - id.clone(), - |maybe_details| -> Result<(), DispatchError> { + let _ = + Asset::::try_mutate_exists(&id, |maybe_details| -> Result<(), DispatchError> { let mut details = maybe_details.as_mut().ok_or(Error::::Unknown)?; // Should only destroy accounts while the asset is in a destroying state ensure!(details.status == AssetStatus::Destroying, Error::::IncorrectStatus); - for (who, v) in Account::::drain_prefix(id.clone()) { + for (who, v) in Account::::drain_prefix(&id) { let _ = Self::dead_account(&who, &mut details, &v.reason, true); dead_accounts.push(who); if dead_accounts.len() >= (max_items as usize) { @@ -781,8 +776,7 @@ impl, I: 'static> Pallet { } remaining_accounts = details.accounts; Ok(()) - }, - )?; + })?; for who in &dead_accounts { T::Freezer::died(id.clone(), &who); @@ -888,7 +882,7 @@ impl, I: 'static> Pallet { Ok(()) }, )?; - Asset::::insert(id.clone(), d); + Asset::::insert(&id, d); Self::deposit_event(Event::ApprovedTransfer { asset_id: id, source: owner.clone(), From 1a61e16acc46247287e356ff5dc15de48ba62e5c Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 23 May 2023 08:07:34 +0000 Subject: [PATCH 7/8] Add more `.clone()`s for newly merged code --- frame/nft-fractionalization/src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/frame/nft-fractionalization/src/lib.rs b/frame/nft-fractionalization/src/lib.rs index c61719c5c707a..e1c8b8fea8907 100644 --- a/frame/nft-fractionalization/src/lib.rs +++ b/frame/nft-fractionalization/src/lib.rs @@ -241,13 +241,19 @@ pub mod pallet { let deposit = T::Deposit::get(); T::Currency::hold(&T::HoldReason::get(), &nft_owner, deposit)?; Self::do_lock_nft(nft_collection_id, nft_id)?; - Self::do_create_asset(asset_id, pallet_account.clone())?; - Self::do_mint_asset(asset_id, &beneficiary, fractions)?; - Self::do_set_metadata(asset_id, &who, &pallet_account, &nft_collection_id, &nft_id)?; + Self::do_create_asset(asset_id.clone(), pallet_account.clone())?; + Self::do_mint_asset(asset_id.clone(), &beneficiary, fractions)?; + Self::do_set_metadata( + asset_id.clone(), + &who, + &pallet_account, + &nft_collection_id, + &nft_id, + )?; NftToAsset::::insert( (nft_collection_id, nft_id), - Details { asset: asset_id, fractions, asset_creator: nft_owner, deposit }, + Details { asset: asset_id.clone(), fractions, asset_creator: nft_owner, deposit }, ); Self::deposit_event(Event::NftFractionalized { @@ -295,7 +301,7 @@ pub mod pallet { let deposit = details.deposit; let asset_creator = details.asset_creator; - Self::do_burn_asset(asset_id, &who, details.fractions)?; + Self::do_burn_asset(asset_id.clone(), &who, details.fractions)?; Self::do_unlock_nft(nft_collection_id, nft_id, &beneficiary)?; T::Currency::release(&T::HoldReason::get(), &asset_creator, deposit, BestEffort)?; @@ -356,7 +362,7 @@ pub mod pallet { account: &T::AccountId, amount: AssetBalanceOf, ) -> DispatchResult { - T::Assets::burn_from(asset_id, account, amount, Exact, Polite)?; + T::Assets::burn_from(asset_id.clone(), account, amount, Exact, Polite)?; T::Assets::start_destroy(asset_id, None) } From edd005d4830d0301c813cff93a84a2a74611318c Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 23 May 2023 08:34:05 +0000 Subject: [PATCH 8/8] Also add `clone()`s in the benchmarks --- frame/nft-fractionalization/src/benchmarking.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/nft-fractionalization/src/benchmarking.rs b/frame/nft-fractionalization/src/benchmarking.rs index a04e8de12ffe8..1600ae78c4bdf 100644 --- a/frame/nft-fractionalization/src/benchmarking.rs +++ b/frame/nft-fractionalization/src/benchmarking.rs @@ -93,7 +93,7 @@ benchmarks! { let collection = T::BenchmarkHelper::collection(0); let nft = T::BenchmarkHelper::nft(0); let (caller, caller_lookup) = mint_nft::(nft); - }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset, caller_lookup, 1000u32.into()) + }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset.clone(), caller_lookup, 1000u32.into()) verify { assert_last_event::( Event::NftFractionalized { @@ -115,11 +115,11 @@ benchmarks! { SystemOrigin::Signed(caller.clone()).into(), collection, nft, - asset, + asset.clone(), caller_lookup.clone(), 1000u32.into(), )?; - }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset, caller_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset.clone(), caller_lookup) verify { assert_last_event::( Event::NftUnified {