Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pallets/asset-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ pub mod pallet {
let index_tokens = Self::index_token_equivalent(asset_id, units)?;

// transfer the caller's fund into the treasury account
Self::remove_liquid(who.clone(), asset_id, units, index_tokens, recipient.clone())?;
Self::remove_liquid(&who, asset_id, units, index_tokens, recipient.clone())?;

Self::deposit_event(Event::AssetRemoved(asset_id, units, who, recipient, index_tokens));
Ok(().into())
Expand Down Expand Up @@ -1080,7 +1080,7 @@ pub mod pallet {
}

fn remove_liquid(
who: T::AccountId,
who: &T::AccountId,
asset_id: T::AssetId,
units: T::Balance,
nav: T::Balance,
Expand All @@ -1090,21 +1090,21 @@ pub mod pallet {
return Ok(());
}
ensure!(Self::is_liquid_asset(&asset_id), Error::<T>::ExpectedLiquid);
ensure!(T::IndexToken::can_slash(&who, nav), Error::<T>::InsufficientDeposit);
ensure!(T::IndexToken::can_slash(who, nav), Error::<T>::InsufficientDeposit);

let recipient = recipient.unwrap_or_else(|| who.clone());

// Execute the transfer which will take of updating the balance
T::RemoteAssetManager::transfer_asset(recipient, asset_id, units)?;

// burn index token accordingly, no index token changes in the meantime
T::IndexToken::slash(&who, nav);
T::IndexToken::slash(who, nav);

Ok(())
}

fn remove_saft(
who: T::AccountId,
who: &T::AccountId,
asset_id: T::AssetId,
units: T::Balance,
saft_nav: T::Balance,
Expand All @@ -1119,12 +1119,12 @@ pub mod pallet {
let index_token = Self::saft_equivalent(saft_nav)?;

ensure!(!Self::is_liquid_asset(&asset_id), Error::<T>::ExpectedSAFT);
ensure!(T::IndexToken::can_slash(&who, index_token), Error::<T>::InsufficientDeposit);
ensure!(T::IndexToken::can_slash(who, index_token), Error::<T>::InsufficientDeposit);

// burn SAFT by withdrawing from the index
T::Currency::withdraw(asset_id, &Self::treasury_account(), units)?;
// burn index token accordingly, no index token changes in the meantime
T::IndexToken::slash(&who, index_token);
T::IndexToken::slash(who, index_token);

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/saft-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_saft())]
#[transactional]
pub fn remove_saft(origin: OriginFor<T>, asset_id: T::AssetId, saft_id: SAFTId) -> DispatchResult {
Self::do_remove_saft(T::AdminOrigin::ensure_origin(origin.clone())?, asset_id, saft_id)
Self::do_remove_saft(T::AdminOrigin::ensure_origin(origin)?, asset_id, saft_id)
}

/// Removes saft assets with root origin
Expand Down Expand Up @@ -351,7 +351,7 @@ pub mod pallet {
let saft = ActiveSAFTs::<T>::take(asset_id, saft_id).ok_or(Error::<T>::SAFTNotFound)?;

// reflect the change in NAV
T::AssetRecorder::remove_saft(who, asset_id, saft.units, saft.nav)?;
T::AssetRecorder::remove_saft(&who, asset_id, saft.units, saft.nav)?;
SAFTNetAssetValue::<T>::mutate(asset_id, |nav| *nav = nav.saturating_sub(saft.nav));

Self::deposit_event(Event::<T>::SAFTRemoved(asset_id, saft_id));
Expand Down
6 changes: 3 additions & 3 deletions primitives/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub trait AssetRecorder<AccountId, AssetId, Balance> {
/// Updates the index by burning the given amount of index token from
/// the caller's account.
fn remove_liquid(
who: AccountId,
who: &AccountId,
id: AssetId,
units: Balance,
nav: Balance,
Expand All @@ -277,13 +277,13 @@ pub trait AssetRecorder<AccountId, AssetId, Balance> {

/// Burns the given amount of SAFT token from the index and
/// the nav from the caller's account
fn remove_saft(who: AccountId, id: AssetId, units: Balance, nav: Balance) -> DispatchResult;
fn remove_saft(who: &AccountId, id: AssetId, units: Balance, nav: Balance) -> DispatchResult;
}

/// Helper trait for runtime benchmarks
#[cfg(feature = "runtime-benchmarks")]
pub trait AssetRecorderBenchmarks<AssetId, Balance> {
fn add_asset(asset_id: AssetId, units: Balance, localtion: MultiLocation, amount: Balance) -> DispatchResult;
fn add_asset(asset_id: AssetId, units: Balance, location: MultiLocation, amount: Balance) -> DispatchResult;

fn deposit_saft_equivalent(saft_nav: Balance) -> DispatchResult;
}
Expand Down