Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
};
use assets_common::{
matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset, ParentLocation},
TrustBackedAssetsAsLocation,
ForeignAssetsFilter, TrustBackedAssetsAsLocation,
};
use frame_support::{
parameter_types,
Expand All @@ -43,7 +43,7 @@ use parachains_common::{
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use sp_runtime::traits::{AccountIdConversion, ConvertInto, TryConvertInto};
use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertInto};
use testnet_parachains_constants::rococo::snowbridge::{
EthereumNetwork, INBOUND_QUEUE_PALLET_INDEX,
};
Expand Down Expand Up @@ -163,18 +163,22 @@ pub type UniquesTransactor = NonFungiblesAdapter<
CheckingAccount,
>;

pub type ExcludeFromForeignAssets = (
// Ignore `TrustBackedAssets` explicitly
StartsWith<TrustBackedAssetsPalletLocation>,
// Ignore asset which starts explicitly with our `GlobalConsensus(NetworkId)`, means:
// - foreign assets from our consensus should be: `Location {parents: 1, X*(Parachain(xyz),
// ..)}
// - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` wont be
// accepted here
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
);

pub type ForeignAssetsOnlyFilter = ForeignAssetsFilter<ExcludeFromForeignAssets>;

/// `AssetId`/`Balance` converter for `ForeignAssets`.
pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConvertedConcreteId<
(
// Ignore `TrustBackedAssets` explicitly
StartsWith<TrustBackedAssetsPalletLocation>,
// Ignore assets that start explicitly with our `GlobalConsensus(NetworkId)`, means:
// - foreign assets from our consensus should be: `Location {parents: 1, X*(Parachain(xyz),
// ..)}`
// - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` won't
// be accepted here
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
),
ExcludeFromForeignAssets,
Balance,
xcm::v5::Location,
>;
Expand Down Expand Up @@ -389,29 +393,21 @@ impl xcm_executor::Config for XcmConfig {
Balances,
ResolveTo<StakingPot, Balances>,
>,
cumulus_primitives_utility::SwapFirstAssetTrader<
cumulus_primitives_utility::SwapAssetTrader<
TokenLocation,
crate::AssetConversion,
Identity,
(StartsWith<TrustBackedAssetsPalletLocation>, ForeignAssetsOnlyFilter),
WeightToFee,
crate::NativeAndNonPoolAssets,
(
TrustBackedAssetsAsLocation<
TrustBackedAssetsPalletLocation,
Balance,
xcm::v5::Location,
>,
ForeignAssetsConvertedConcreteId,
),
ResolveAssetTo<StakingPot, crate::NativeAndNonPoolAssets>,
AccountId,
crate::AssetConversion,
>,
// This trader allows to pay with `is_sufficient=true` "Trust Backed" assets from dedicated
// `pallet_assets` instance - `Assets`.
cumulus_primitives_utility::TakeFirstAssetTrader<
cumulus_primitives_utility::ConcreteAssetTrader<
AccountId,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
TrustBackedAssetsConvertedConcreteId,
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
StartsWith<TrustBackedAssetsPalletLocation>,
Assets,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
FungiblesTransactor,
AccountId,
Expand All @@ -420,11 +416,14 @@ impl xcm_executor::Config for XcmConfig {
>,
// This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated
// `pallet_assets` instance - `ForeignAssets`.
cumulus_primitives_utility::TakeFirstAssetTrader<
cumulus_primitives_utility::ConcreteAssetTrader<
AccountId,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger,
ForeignAssetsConvertedConcreteId,
WithLatestLocationConverter<
<Runtime as pallet_assets::Config<ForeignAssetsInstance>>::AssetId,
>,
ForeignAssetsOnlyFilter,
ForeignAssets,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
ForeignFungiblesTransactor,
AccountId,
Expand Down Expand Up @@ -507,6 +506,7 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type Trader = <XcmConfig as xcm_executor::Config>::Trader;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
28 changes: 1 addition & 27 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1692,33 +1692,7 @@ impl_runtime_apis! {
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
let native_asset = xcm_config::WestendLocation::get();
let fee_in_native = WeightToFee::weight_to_fee(&weight);
let latest_asset_id: Result<AssetId, ()> = asset.clone().try_into();
match latest_asset_id {
Ok(asset_id) if asset_id.0 == native_asset => {
// for native asset
Ok(fee_in_native)
},
Ok(asset_id) => {
// Try to get current price of `asset_id` in `native_asset`.
if let Ok(Some(swapped_in_native)) = assets_common::PoolAdapter::<Runtime>::quote_price_tokens_for_exact_tokens(
asset_id.0.clone(),
native_asset,
fee_in_native,
true, // We include the fee.
) {
Ok(swapped_in_native)
} else {
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
Err(XcmPaymentApiError::AssetNotFound)
}
},
Err(_) => {
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
Err(XcmPaymentApiError::VersionedConversionFailed)
}
}
PolkadotXcm::query_weight_to_asset_fee(weight, asset)
}

fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
};
use assets_common::{
matching::{FromSiblingParachain, IsForeignConcreteAsset, ParentLocation},
TrustBackedAssetsAsLocation,
ForeignAssetsFilter, TrustBackedAssetsAsLocation,
};
use frame_support::{
parameter_types,
Expand All @@ -44,7 +44,7 @@ use parachains_common::{
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use snowbridge_outbound_queue_primitives::v2::exporter::PausableExporter;
use sp_runtime::traits::{AccountIdConversion, ConvertInto, TryConvertInto};
use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertInto};
use westend_runtime_constants::system_parachain::COLLECTIVES_ID;
use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH};
use xcm_builder::{
Expand Down Expand Up @@ -158,18 +158,22 @@ pub type UniquesTransactor = NonFungiblesAdapter<
CheckingAccount,
>;

pub type ExcludeFromForeignAssets = (
// Ignore `TrustBackedAssets` explicitly
StartsWith<TrustBackedAssetsPalletLocation>,
// Ignore asset which starts explicitly with our `GlobalConsensus(NetworkId)`, means:
// - foreign assets from our consensus should be: `Location {parents: 1, X*(Parachain(xyz),
// ..)}
// - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` wont be
// accepted here
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
);

pub type ForeignAssetsOnlyFilter = ForeignAssetsFilter<ExcludeFromForeignAssets>;

/// `AssetId`/`Balance` converter for `ForeignAssets`.
pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConvertedConcreteId<
(
// Ignore `TrustBackedAssets` explicitly
StartsWith<TrustBackedAssetsPalletLocation>,
// Ignore asset which starts explicitly with our `GlobalConsensus(NetworkId)`, means:
// - foreign assets from our consensus should be: `Location {parents: 1, X*(Parachain(xyz),
// ..)}
// - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` wont
// be accepted here
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
),
ExcludeFromForeignAssets,
Balance,
xcm::v5::Location,
>;
Expand Down Expand Up @@ -410,29 +414,21 @@ impl xcm_executor::Config for XcmConfig {
Balances,
ResolveTo<StakingPot, Balances>,
>,
cumulus_primitives_utility::SwapFirstAssetTrader<
cumulus_primitives_utility::SwapAssetTrader<
WestendLocation,
crate::AssetConversion,
Identity,
(StartsWith<TrustBackedAssetsPalletLocation>, ForeignAssetsOnlyFilter),
WeightToFee,
crate::NativeAndNonPoolAssets,
(
TrustBackedAssetsAsLocation<
TrustBackedAssetsPalletLocation,
Balance,
xcm::v5::Location,
>,
ForeignAssetsConvertedConcreteId,
),
ResolveAssetTo<StakingPot, crate::NativeAndNonPoolAssets>,
AccountId,
crate::AssetConversion,
>,
// This trader allows to pay with `is_sufficient=true` "Trust Backed" assets from dedicated
// `pallet_assets` instance - `Assets`.
cumulus_primitives_utility::TakeFirstAssetTrader<
cumulus_primitives_utility::ConcreteAssetTrader<
AccountId,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
TrustBackedAssetsConvertedConcreteId,
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
StartsWith<TrustBackedAssetsPalletLocation>,
Assets,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
FungiblesTransactor,
AccountId,
Expand All @@ -441,11 +437,14 @@ impl xcm_executor::Config for XcmConfig {
>,
// This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated
// `pallet_assets` instance - `ForeignAssets`.
cumulus_primitives_utility::TakeFirstAssetTrader<
cumulus_primitives_utility::ConcreteAssetTrader<
AccountId,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger,
ForeignAssetsConvertedConcreteId,
WithLatestLocationConverter<
<Runtime as pallet_assets::Config<ForeignAssetsInstance>>::AssetId,
>,
ForeignAssetsOnlyFilter,
ForeignAssets,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
ForeignFungiblesTransactor,
AccountId,
Expand Down Expand Up @@ -533,6 +532,7 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type Trader = <XcmConfig as xcm_executor::Config>::Trader;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Loading
Loading