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

Commit

Permalink
unified local and foreign trader conversion, fixed bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
PatricioNapoli committed Jul 24, 2023
1 parent b1e4532 commit 470903b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
19 changes: 5 additions & 14 deletions parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use assets_common::{
matching::{
FromSiblingParachain, IsForeignConcreteAsset, StartsWith, StartsWithExplicitGlobalConsensus,
},
AssetIdForTrustBackedAssetsConvert,
};
use frame_support::{
match_types, parameter_types,
Expand Down Expand Up @@ -476,21 +477,11 @@ impl xcm_executor::Config for XcmConfig {
pallet_asset_conversion::Pallet<Runtime>,
WeightToFee,
TrustBackedAssetsConvertedConcreteId,
Assets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
// Revenue could also be Foreign Fungible? Maybe with multi-asset treasury..?
FungiblesTransactor,
AccountId,
XcmAssetFeesReceiver,
LocalAndForeignAssets<
Assets,
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
ForeignAssets,
>,
>,
cumulus_primitives_utility::SwapFirstAssetTrader<
Runtime,
LocationToAccountId,
pallet_asset_conversion::Pallet<Runtime>,
WeightToFee,
ForeignAssetsConvertedConcreteId,
ForeignAssets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
// Revenue could also be Foreign Fungible? Maybe with multi-asset treasury..?
FungiblesTransactor,
Expand Down
11 changes: 6 additions & 5 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ use frame_support::{
},
weights::Weight,
};
use pallet_asset_conversion::{Config, MultiAssetIdConverter, Swap};
use pallet_asset_conversion::{Config, MultiAssetIdConversionResult, MultiAssetIdConverter, Swap};
use polkadot_runtime_common::xcm_sender::ConstantPrice;
use sp_runtime::{
traits::{CheckedSub, Saturating},
SaturatedConversion,
};
use sp_std::{marker::PhantomData, prelude::*};
use std::ops::Mul;
use xcm::{latest::prelude::*, WrapVersion};
use xcm_builder::TakeRevenue;
use xcm_executor::traits::{ConvertLocation, MatchesFungibles, TransactAsset, WeightTrader};
Expand Down Expand Up @@ -314,7 +315,7 @@ impl<
> where
T::HigherPrecisionBalance: From<ConcreteAssets::Balance> + Into<T::AssetBalance>,
T::AssetBalance: Into<Fungibility>,
MultiLocation: From<ConcreteAssets::AssetId> + Into<T::AssetId>,
MultiLocation: From<ConcreteAssets::AssetId> + Into<T::MultiAssetId>,
{
fn new() -> Self {
Self(None, PhantomData)
Expand Down Expand Up @@ -344,19 +345,19 @@ impl<
// Take the first multiasset from the selected MultiAssets
let first = multiassets.get(0).ok_or(XcmError::AssetNotFound)?;

// Get the multi asset id in which we can pay for fees
// Get the asset id in which we can pay for fees
let (asset_id, local_asset_balance) =
Matcher::matches_fungibles(first).map_err(|_| XcmError::AssetNotFound)?;

let multi_id: MultiLocation = asset_id.into();
let asset_loc: MultiLocation = asset_id.into();

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

let acc = AccountIdConverter::convert_location(&ctx.origin.unwrap()).unwrap();

let amount_taken = SWP::swap_tokens_for_exact_tokens(
acc.clone(),
vec![T::MultiAssetId::from(multi_id.into()), T::MultiAssetIdConverter::get_native()],
vec![asset_loc.into(), T::MultiAssetIdConverter::get_native()],
fee.into(),
None,
acc.clone(),
Expand Down

0 comments on commit 470903b

Please sign in to comment.