diff --git a/code/parachain/runtime/common/src/xcmp.rs b/code/parachain/runtime/common/src/xcmp.rs index 16d3c907b35..27fd2952a18 100644 --- a/code/parachain/runtime/common/src/xcmp.rs +++ b/code/parachain/runtime/common/src/xcmp.rs @@ -3,7 +3,7 @@ use crate::{fees::NativeBalance, prelude::*, AccountId, Balance}; use frame_support::{ dispatch::Weight, log, match_types, parameter_types, - traits::{tokens::BalanceConversion, Contains, Get}, + traits::{tokens::BalanceConversion, Contains, Get, PalletInfoAccess}, weights::{WeightToFee, WeightToFeePolynomial}, }; use num_traits::{One, Zero}; @@ -178,45 +178,53 @@ impl Convert for AccountIdToMultiLocation { } } -pub struct CurrencyIdConvert( - PhantomData<(AssetRegistry, WellKnownCurrency, ThisParaId)>, +pub struct CurrencyIdConvert( + PhantomData<(ForeignAssetsToXcm, WellKnownCurrency, AssetsRegistry, ThisParaId)>, ); impl< - AssetRegistry: Convert>, + ForeignAssetsToXcm: Convert>, WellKnown: WellKnownCurrency, + AssetsRegistry: PalletInfoAccess, ThisParaId: Get, > sp_runtime::traits::Convert> - for CurrencyIdConvert + for CurrencyIdConvert { fn convert(id: CurrencyId) -> Option { - WellKnown::local_to_remote(id).or_else(|| AssetRegistry::convert(id)) + WellKnown::local_to_remote(id).or_else(|| ForeignAssetsToXcm::convert(id)) } } impl< - AssetsRegistry: Convert>, + ForeignAssetsToXcm: Convert>, WellKnown: WellKnownCurrency, + AssetsRegistry: PalletInfoAccess, ThisParaId: Get, > Convert> - for CurrencyIdConvert + for CurrencyIdConvert { fn convert(location: MultiLocation) -> Option { log::trace!(target: "xcmp::convert", "converting {:?} on {:?}", &location, ThisParaId::get()); match location { topology::relay::LOCATION => Some(WellKnown::RELAY_NATIVE), topology::this::LOCAL => Some(WellKnown::NATIVE), - MultiLocation { parents, interior: X2(Parachain(id), GeneralIndex(index)) } - if parents == 1 && Id::from(id) == ThisParaId::get() => - Some(CurrencyId(index)), - MultiLocation { parents: 0, interior: X1(GeneralIndex(index)) } => + MultiLocation { + parents, + interior: X3(Parachain(id), PalletInstance(pallet_index), GeneralIndex(index)), + } if parents == 1 && + Id::from(id) == ThisParaId::get() && + pallet_index == AssetsRegistry::index() as u8 => Some(CurrencyId(index)), + MultiLocation { + parents, + interior: X2(PalletInstance(pallet_index), GeneralIndex(index)), + } if parents == 0 && pallet_index == AssetsRegistry::index() as u8 => Some(CurrencyId(index)), _ => if let Some(currency_id) = WellKnown::remote_to_local(location) { Some(currency_id) } else { log::trace!(target: "xcmp", "using assets registry for {:?}", location); - let result = AssetsRegistry::convert(location).map(Into::into); + let result = ForeignAssetsToXcm::convert(location).map(Into::into); if let Some(result) = result { log::trace!(target: "xcmp", "mapped remote to {:?} local", result); } else { @@ -230,10 +238,12 @@ impl< } impl< - T: Convert>, + ForeignAssetsToXcm: Convert>, WellKnown: WellKnownCurrency, + AssetsRegistry: PalletInfoAccess, ThisParaId: Get, - > Convert> for CurrencyIdConvert + > Convert> + for CurrencyIdConvert { fn convert(asset: MultiAsset) -> Option { log::trace!(target: "xcmp", "converting {:?}", &asset); diff --git a/code/parachain/runtime/composable/src/xcmp.rs b/code/parachain/runtime/composable/src/xcmp.rs index 7642ea8fe2d..f9d276248f4 100644 --- a/code/parachain/runtime/composable/src/xcmp.rs +++ b/code/parachain/runtime/composable/src/xcmp.rs @@ -333,25 +333,37 @@ impl< } } -pub struct ForeignXcm; +pub struct ForeignAssetsToXcm; -impl Convert> for ForeignXcm { +impl Convert> for ForeignAssetsToXcm { fn convert(a: CurrencyId) -> Option { match AssetsRegistry::asset_to_remote(a) { + // XCMed assets Some(ForeignAssetId::Xcm(VersionedMultiLocation::V3(xcm))) => Some(xcm), - _ => None, + // IBCed assets + _ => Some(MultiLocation { + parents: 0, + interior: X2( + PalletInstance(::index() as u8), + GeneralIndex(a.into()), + ), + }), } } } -impl Convert> for ForeignXcm { +impl Convert> for ForeignAssetsToXcm { fn convert(a: MultiLocation) -> Option { AssetsRegistry::location_to_asset(ForeignAssetId::Xcm(VersionedMultiLocation::V3(a))) } } -type AssetsIdConverter = - CurrencyIdConvert; +type AssetsIdConverter = CurrencyIdConvert< + ForeignAssetsToXcm, + primitives::topology::Composable, + AssetsRegistry, + ParachainInfo, +>; pub type Trader = TransactionFeePoolTrader< AssetsIdConverter, diff --git a/code/parachain/runtime/picasso/src/xcmp.rs b/code/parachain/runtime/picasso/src/xcmp.rs index f1683618acd..0cdf8283165 100644 --- a/code/parachain/runtime/picasso/src/xcmp.rs +++ b/code/parachain/runtime/picasso/src/xcmp.rs @@ -322,25 +322,37 @@ impl< } } -pub struct ForeignXcm; +pub struct ForeignAssetsToXcm; -impl Convert> for ForeignXcm { +impl Convert> for ForeignAssetsToXcm { fn convert(a: CurrencyId) -> Option { match AssetsRegistry::asset_to_remote(a) { + // XCMed assets Some(ForeignAssetId::Xcm(VersionedMultiLocation::V3(xcm))) => Some(xcm), - _ => None, + // IBCed assets + _ => Some(MultiLocation { + parents: 0, + interior: X2( + PalletInstance(::index() as u8), + GeneralIndex(a.into()), + ), + }), } } } -impl Convert> for ForeignXcm { +impl Convert> for ForeignAssetsToXcm { fn convert(a: MultiLocation) -> Option { AssetsRegistry::location_to_asset(ForeignAssetId::Xcm(VersionedMultiLocation::V3(a))) } } -type AssetsIdConverter = - CurrencyIdConvert; +type AssetsIdConverter = CurrencyIdConvert< + ForeignAssetsToXcm, + primitives::topology::Picasso, + AssetsRegistry, + ParachainInfo, +>; pub type Trader = TransactionFeePoolTrader< AssetsIdConverter,