Skip to content

Commit

Permalink
fix: do_transfer_multiassets zero fee issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Nov 17, 2023
1 parent 64e09c5 commit dbcc789
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,40 +520,37 @@ pub mod module {
T::MultiLocationsFilter::contains(&dest),
Error::<T>::NotSupportedMultiLocation
);

// Fee payment can only be made by using the non-zero amount of fungibles
ensure!(
matches!(fee.fun, Fungibility::Fungible(x) if !x.is_zero()),
Error::<T>::InvalidAsset
);

let origin_location = T::AccountIdToMultiLocation::convert(who.clone());

let mut non_fee_reserve: Option<MultiLocation> = None;
let asset_len = assets.len();
for i in 0..asset_len {
let asset = assets.get(i).ok_or(Error::<T>::AssetIndexNonExistent)?;

if fee == *asset {
// Fee payment can only be made by using fungibles
ensure!(
matches!(asset.fun, Fungibility::Fungible(x) if !x.is_zero()),
Error::<T>::InvalidAsset
);
} else {
match asset.fun {
Fungibility::Fungible(x) => ensure!(!x.is_zero(), Error::<T>::InvalidAsset),
Fungibility::NonFungible(AssetInstance::Undefined) => {
return Err(Error::<T>::InvalidAsset.into())
}
_ => {}
}
match asset.fun {
Fungibility::Fungible(x) => ensure!(!x.is_zero(), Error::<T>::InvalidAsset),
Fungibility::NonFungible(AssetInstance::Undefined) => return Err(Error::<T>::InvalidAsset.into()),
_ => {}
}

// `assets` includes fee, the reserve location is decided by non fee asset
if non_fee_reserve.is_none() {
non_fee_reserve = T::ReserveProvider::reserve(asset);
}
// `assets` includes fee, the reserve location is decided by non fee asset
if non_fee_reserve.is_none() && asset.id != fee.id {
non_fee_reserve = T::ReserveProvider::reserve(asset);
}

// make sure all non fee assets share the same reserve
if non_fee_reserve.is_some() {
ensure!(
non_fee_reserve == T::ReserveProvider::reserve(asset),
Error::<T>::DistinctReserveForAssetAndFee
);
}
// make sure all non fee assets share the same reserve
if non_fee_reserve.is_some() {
ensure!(
non_fee_reserve == T::ReserveProvider::reserve(asset),
Error::<T>::DistinctReserveForAssetAndFee
);
}
}

Expand Down

0 comments on commit dbcc789

Please sign in to comment.