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

Commit

Permalink
added a second trader, separated local and foreign assets
Browse files Browse the repository at this point in the history
  • Loading branch information
PatricioNapoli committed Jul 20, 2023
1 parent b3adbf6 commit aa9b8c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 15 additions & 1 deletion parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,21 @@ impl xcm_executor::Config for XcmConfig {
pallet_asset_conversion::Pallet<Runtime>,
WeightToFee,
MultiAssetsConvertedConcreteId,
LocalAndForeignAssets<Assets, ForeignAssets, TrustBackedAssetsPalletLocation>,
Assets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
// Revenue could also be Foreign Fungible? Maybe with multi-asset treasury..?
FungiblesTransactor,
AccountId,
XcmAssetFeesReceiver,
>,
>,
cumulus_primitives_utility::SwapFirstAssetTrader<
Runtime,
LocationToAccountId,
pallet_asset_conversion::Pallet<Runtime>,
WeightToFee,
MultiAssetsConvertedConcreteId,
ForeignAssets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
// Revenue could also be Foreign Fungible? Maybe with multi-asset treasury..?
FungiblesTransactor,
Expand Down
13 changes: 9 additions & 4 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ impl<
HandleRefund: TakeRevenue,
> WeightTrader
for SwapFirstAssetTrader<T, AccountIdConverter, SWP, WeightToFee, Matcher, ConcreteAssets, HandleRefund>
where
T::MultiAssetId: From<ConcreteAssets::AssetId>,
T::HigherPrecisionBalance: From<ConcreteAssets::Balance>,
{
fn new() -> Self {
Self(None, PhantomData)
Expand Down Expand Up @@ -341,8 +344,8 @@ for SwapFirstAssetTrader<T, AccountIdConverter, SWP, WeightToFee, Matcher, Concr

let amount_taken = SWP::swap_tokens_for_exact_tokens(
acc.clone(),
vec![multi_id, T::MultiAssetIdConverter::get_native()],
T::HigherPrecisionBalance::from(fee),
vec![multi_id.into(), T::MultiAssetIdConverter::get_native()],
fee.into(),
None,
acc.clone(),
true
Expand All @@ -354,14 +357,16 @@ for SwapFirstAssetTrader<T, AccountIdConverter, SWP, WeightToFee, Matcher, Concr
// Substract amount_taken from payment_balance
let unused = payment_balance.checked_sub(&amount_taken).ok_or(XcmError::TooExpensive)?;

let unused_asset: T::Balance = unused.try_into().map_err(|_| XcmError::AssetNotFound)?;
let unused_asset: T::AssetBalance = unused.try_into().map_err(|_| XcmError::AssetNotFound)?;

let required = first.id.into_multiasset(unused_asset.try_into().map_err(|_| XcmError::AssetNotFound)?);

// Record outstanding asset
self.0 = Some(SwapAssetTraderRefunder {
outstanding_concrete_asset: first.clone(),
});

Ok(unused_asset)
Ok(required.into())
}

fn refund_weight(&mut self, ctx: &XcmContext, weight: Weight) -> Option<MultiAsset> {
Expand Down

0 comments on commit aa9b8c8

Please sign in to comment.