Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Try to fix bounds for AssetId #2955

Merged
Merged
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
16 changes: 6 additions & 10 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<
T::HigherPrecisionBalance: From<ConcreteAssets::Balance> + TryInto<T::AssetBalance>,
<T::HigherPrecisionBalance as TryInto<T::AssetBalance>>::Error: core::fmt::Debug,
T::AssetBalance: Into<Fungibility>,
MultiLocation: From<ConcreteAssets::AssetId> + Into<T::MultiAssetId>,
ConcreteAssets::AssetId: Into<T::MultiAssetId>,
{
fn new() -> Self {
Self(None, PhantomData)
Expand Down Expand Up @@ -349,16 +349,14 @@ impl<
let (asset_id, local_asset_balance) =
Matcher::matches_fungibles(first).map_err(|_| XcmError::AssetNotFound)?;

let asset_loc: MultiLocation = asset_id.into();

let fee = WeightToFee::weight_to_fee(&weight);

let origin = ctx.origin.ok_or(XcmError::BadOrigin)?;
let acc = AccountIdConverter::convert_location(&origin).ok_or(XcmError::InvalidLocation)?;

let amount_taken = SWP::swap_tokens_for_exact_tokens(
acc.clone(),
vec![asset_loc.into(), T::MultiAssetIdConverter::get_native()],
vec![asset_id.into(), T::MultiAssetIdConverter::get_native()],
fee.into(),
None,
acc.clone(),
Expand All @@ -384,7 +382,7 @@ impl<

if let Some(SwapAssetTraderRefunder {
// mut weight_outstanding,
outstanding_concrete_asset,
outstanding_concrete_asset: MultiAsset { id, fun },
}) = self.0.clone()
{
let swap_back = WeightToFee::weight_to_fee(&weight);
Expand All @@ -393,9 +391,7 @@ impl<
return None
}
let (asset_id, _local_asset_balance) =
Matcher::matches_fungibles(&outstanding_concrete_asset).ok()?;

let asset_loc: MultiLocation = asset_id.clone().into();
Matcher::matches_fungibles(&(id, fun).into()).ok()?;

let origin = ctx.origin?;
let acc = AccountIdConverter::convert_location(&origin)?;
Expand All @@ -404,7 +400,7 @@ impl<
// This read should have already be cached in buy_weight
let amount_refunded = SWP::swap_tokens_for_exact_tokens(
acc.clone(),
vec![asset_loc.into(), T::MultiAssetIdConverter::get_native()],
vec![asset_id.into(), T::MultiAssetIdConverter::get_native()],
swap_back.into(),
None,
acc.clone(),
Expand All @@ -416,7 +412,7 @@ impl<

// Only refund if positive
if amount_refunded > 0.into() {
Some((asset_id.clone(), amount_refunded.try_into().ok()?).into())
Some((id, amount_refunded.try_into().ok()?).into())
} else {
None
}
Expand Down
Loading