Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
43ef694
asset-hubs runtimes: add xcm reserve transfer tests
acatangiu Sep 5, 2023
945b34c
pallet-xcm: filter assets teleports based on XcmExecutor configuration
acatangiu Sep 21, 2023
ce215a1
xcm: MultiLocation: add .chain_location() helper function
acatangiu Sep 20, 2023
a5fd746
pallet-xcm: enchance reserve_transfer_assets() to support various res…
acatangiu Sep 25, 2023
c581d76
use correct fees beneficiary on assets reserve chain
acatangiu Sep 25, 2023
fe52d48
build dest-reserve and remote-reserve XCM programs
acatangiu Sep 26, 2023
5d847e3
deduplicate teleport and reserve transfer tests
acatangiu Sep 26, 2023
026a779
add test cases plan
acatangiu Sep 26, 2023
4465c65
add pallet-assets to mock test runtime
acatangiu Sep 26, 2023
2392dd9
fix add assets to mock pallet-xcm runtime
acatangiu Sep 26, 2023
67daafe
add test for asset-reserve and fee-reserve both at destination
acatangiu Sep 27, 2023
88b3024
add test for asset-reserve and fee-reserve both at remote chain
acatangiu Sep 27, 2023
513e15a
add test for asset-reserve at destination while fee-reserve is local
acatangiu Sep 27, 2023
19eec17
add test for asset local-reserve while fee-reserve is destination
acatangiu Sep 27, 2023
1687c53
add test for asset local-reserve while fee-reserve is remote chain
acatangiu Sep 27, 2023
abf029d
refactor tests using better naming and conceptual examples
acatangiu Sep 27, 2023
576c770
add test for asset destination-reserve while fee-reserve is remote chain
acatangiu Sep 28, 2023
280c4b1
fix some typos
acatangiu Sep 28, 2023
bab8fc2
deduplicate code for do_teleport_assets()
acatangiu Sep 28, 2023
f7a4a2e
add test for asset local-reserve while teleporting fees
acatangiu Sep 28, 2023
f88de5e
add test for asset destination-reserve while teleporting fees
acatangiu Sep 28, 2023
f7abb0a
fix cases when asset reserve is remote, add test remote-asset and tel…
acatangiu Sep 28, 2023
7b920ec
add test for transfer asset remote reserve and fee local reserve
acatangiu Sep 28, 2023
3130566
add test for transfer asset remote reserve and fee destination reserve
acatangiu Sep 28, 2023
1b17e84
disallow teleportable assets in reserve-transfer, add regression test
acatangiu Sep 29, 2023
84e213a
asset-hubs: fix emulated tests and deduplicate code
acatangiu Sep 29, 2023
ce00c28
asset-hubs: use non-system para IDs in tests where non-system paras a…
acatangiu Sep 29, 2023
1dfcd01
pallet-xcm: refactor newly added tests
acatangiu Sep 29, 2023
24f9b72
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 10, 2023
022ef71
pallet-xcm: fix benchmarks
acatangiu Oct 10, 2023
9827c3b
fix pallet-xcm benchmarks for all runtimes
acatangiu Oct 10, 2023
23588a8
address review comments
acatangiu Oct 11, 2023
931e093
expose TransferType through XcmExecutor::traits::AssetTransferSupport…
acatangiu Oct 11, 2023
bf39726
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 11, 2023
8ac30aa
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 13, 2023
09badd6
allow transfer for non-fungible assets too
acatangiu Oct 13, 2023
648ba8a
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 19, 2023
f8e8b4a
fix merge damage
acatangiu Oct 20, 2023
71bd4b3
fmt
acatangiu Oct 23, 2023
4ab90f7
pallet-xcm: split asset transfer tests to own file
acatangiu Oct 23, 2023
3070994
address review comments
acatangiu Oct 23, 2023
f045c73
pallet-xcm: disallow combining remote reserves with other xfer types
acatangiu Oct 23, 2023
fe93ef4
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 23, 2023
d1a9709
xcm-barriers: allow SetFeesMode in BuyExecution barrier and fix tests
acatangiu Oct 23, 2023
50d844f
verify assets and beneficiary in over-bridge test
acatangiu Oct 24, 2023
0bf64e6
fix AHs tests
acatangiu Oct 24, 2023
c711961
AHs: fix emulated tests
acatangiu Oct 24, 2023
67929a5
AHs: include delivery-fee checking in tests
acatangiu Oct 24, 2023
dd46f23
fix runtime-benchmarks for AHRococo
acatangiu Oct 24, 2023
e8cbcb9
fix clippy
acatangiu Oct 24, 2023
d725103
withdraw fees before buyexecution - still broken because of executor …
acatangiu Oct 25, 2023
3d97f19
pallet-xcm: uses single custom XCM to send both fees and assets
acatangiu Oct 25, 2023
ac3773e
pallet-xcm: handle teleport checking account when custom burn+teleport
acatangiu Oct 25, 2023
cb6f53a
fixes plus tests
acatangiu Oct 25, 2023
560d788
fix pallet-xcm tests
acatangiu Oct 25, 2023
3bc2d73
fix AHs tests
acatangiu Oct 25, 2023
f838cd5
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 26, 2023
bd60203
remove unused SetFeesMode instruction
acatangiu Oct 26, 2023
2e71447
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 27, 2023
371ac2d
pallet-xcm: fix broken reserve_transfer_assets benchmark
acatangiu Oct 26, 2023
9b58ff0
try add pallet-assets for benchmarking to rococo
acatangiu Oct 27, 2023
942977e
Revert "try add pallet-assets for benchmarking to rococo"
acatangiu Oct 27, 2023
3b9965b
pallet-xcm benchmarking: most chains do not have pallet-assets, use p…
acatangiu Oct 27, 2023
adcd688
pallet-xcm: fix teleport_assets benchmark
acatangiu Oct 27, 2023
eca0c3e
fix runtimes benchmarks for pallet-xcm
acatangiu Oct 27, 2023
b648df2
AHs simplify test_cases_over_bridge
acatangiu Oct 27, 2023
da7d8ff
runtimes: add dedicated benchmarking config for pallet-xcm
acatangiu Oct 27, 2023
8d85faa
AHs benchmarks: fix transfer to sibling parachain
acatangiu Oct 28, 2023
37552fd
Update polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs
acatangiu Oct 30, 2023
6714d39
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Oct 30, 2023
a79ed78
Merge branch 'master' into pallet-xcm-fully-support-reserve-transfers
acatangiu Oct 30, 2023
7a61129
fmt
acatangiu Oct 30, 2023
0f76530
Update polkadot/xcm/xcm-builder/src/barriers.rs
acatangiu Oct 31, 2023
9d3f2dd
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Oct 31, 2023
9feb4b0
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Oct 31, 2023
0a38b70
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Oct 31, 2023
02447d0
fmt
acatangiu Oct 31, 2023
84e3e29
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Oct 31, 2023
b67cb0f
xcm-emulator: configure penpal for asset transfers and enhance existi…
acatangiu Nov 1, 2023
ec87ce6
xcm-emulator: add relay to penpal native transfer test
acatangiu Nov 1, 2023
da3c12e
xcm-emulator: add ah to penpal native asset transfer test
acatangiu Nov 1, 2023
ac9bf49
xcm: MultiLocation::chain_location() takes nonmut reference
acatangiu Nov 1, 2023
e85e339
pallet-xcm: benchmarks: enforce single asset transfer at the api level
acatangiu Nov 1, 2023
9f7538d
xcm-executor: rename AssetTransferSupport to XcmAssetTransfer
acatangiu Nov 1, 2023
45279cc
clippy
acatangiu Nov 1, 2023
59cf104
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 1, 2023
e9c7205
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 2, 2023
6ba36f8
AssetHub tests: account for Westend higher delivery fees
acatangiu Nov 2, 2023
7728527
fix merge damage
acatangiu Nov 2, 2023
a4089c8
Added withdraw reserve to scripts
bkontur Nov 2, 2023
44e1918
bridge-hub-westend-runtime: fix benchmarks
acatangiu Nov 2, 2023
a59ccf3
xcm-emulator: add ah to penpal multiple mixed assets transfer test
acatangiu Nov 3, 2023
27c7cea
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 3, 2023
582c616
fix merge damage
acatangiu Nov 3, 2023
94aaffd
remove limited from test names, all transfers use limited method now
acatangiu Nov 3, 2023
fe2cb6a
barriers: allow withdrawing multiple assets in AllowTopLevelPaidExecu…
acatangiu Nov 5, 2023
2ebefc0
pallet-xcm: add trace logs
acatangiu Nov 6, 2023
839af41
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 6, 2023
56c52f1
fix runtime-benchmarks
acatangiu Nov 6, 2023
669e109
Merge branch 'master' into pallet-xcm-fully-support-reserve-transfers
acatangiu Nov 6, 2023
ba91cd6
pallet-xcm: fix tests
acatangiu Nov 6, 2023
8951238
xcm-emulator: remove unused pallet import
acatangiu Nov 7, 2023
dd2a06f
xcm-barrier: enforce MAX_ASSETS_FOR_BUY_EXECUTION
acatangiu Nov 7, 2023
6d67ea1
rename some variables and fns
acatangiu Nov 7, 2023
db1e826
add explicit incomplete local execution error
acatangiu Nov 7, 2023
54d7465
rename fns
acatangiu Nov 7, 2023
39e7b66
pallet-xcm: fix pallet extrinsic default weights
acatangiu Nov 7, 2023
ceddec5
pallet-xcm: also buy execution as part of custom fee handling
acatangiu Nov 8, 2023
7f78c73
pallet-xcm: fix lossy fees math
acatangiu Nov 8, 2023
45131b1
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 8, 2023
cb8226d
fix merge damage
acatangiu Nov 8, 2023
d0c8944
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 8, 2023
c5522e4
fix merge damage
acatangiu Nov 8, 2023
9827904
Merge branch 'master' of github.com:paritytech/polkadot-sdk into pall…
acatangiu Nov 13, 2023
0cc32e3
fix merge damage
acatangiu Nov 13, 2023
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
Prev Previous commit
Next Next commit
expose TransferType through XcmExecutor::traits::AssetTransferSupport…
… instead of pallet_xcm
  • Loading branch information
acatangiu committed Oct 11, 2023
commit 931e09371562d6ffaa2cb7fb09b9a43ea5901e0a
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 18 additions & 59 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use sp_runtime::{
};
use sp_std::{boxed::Box, marker::PhantomData, prelude::*, result::Result, vec};
use xcm::{latest::QueryResponseInfo, prelude::*};
use xcm_executor::traits::{AssetTransferFilter, ConvertOrigin, Properties};
use xcm_executor::traits::{
AssetTransferError, AssetTransferSupport, ConvertOrigin, Properties, TransferType,
};

use frame_support::{
dispatch::GetDispatchInfo, pallet_prelude::*, traits::WithdrawReasons, PalletId,
Expand Down Expand Up @@ -206,7 +208,7 @@ pub mod pallet {
type XcmExecuteFilter: Contains<(MultiLocation, Xcm<<Self as Config>::RuntimeCall>)>;

/// Something to execute an XCM message.
type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + AssetTransferFilter;
type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + AssetTransferSupport;

/// Our XCM filter which messages to be teleported using the dedicated extrinsic must pass.
type XcmTeleportFilter: Contains<(MultiLocation, Vec<MultiAsset>)>;
Expand Down Expand Up @@ -443,7 +445,7 @@ pub mod pallet {
/// The location is invalid since it already has a subscription from us.
AlreadySubscribed,
/// Invalid asset for the operation.
InvalidAsset,
InvalidAsset(AssetTransferError),
/// The owner does not own (all) of the asset that they wish to do the operation on.
LowBalance,
/// The asset owner has too many locks on the asset.
Expand All @@ -456,8 +458,6 @@ pub mod pallet {
LockNotFound,
/// The unlock operation cannot succeed because there are still consumers of the lock.
InUse,
/// Reserve chain could not be determined for assets to be transferred.
UnknownReserve,
/// Too many assets with different reserve locations have been attempted for transfer.
TooManyReserves,
}
Expand Down Expand Up @@ -1211,54 +1211,6 @@ impl<T: Config> QueryHandler for Pallet<T> {
}
}

#[derive(Copy, Clone, PartialEq, Debug)]
enum TransferType {
Teleport,
LocalReserve,
DestinationReserve,
RemoteReserve(MultiLocation),
}

impl TransferType {
/// Determine transfer type to be used for transferring `asset` from local chain to `dest`.
pub fn determine_for<T: Config>(
asset: &MultiAsset,
dest: &MultiLocation,
) -> Result<TransferType, Error<T>> {
if <T::XcmExecutor as AssetTransferFilter>::IsTeleporter::contains(asset, dest) {
// we trust destination for teleporting asset
return Ok(TransferType::Teleport)
} else if <T::XcmExecutor as AssetTransferFilter>::IsReserve::contains(asset, dest) {
// we trust destination as asset reserve location
return Ok(TransferType::DestinationReserve)
}

// try to determine reserve location based on asset id/location
let asset_location = match asset.id {
Concrete(location) => Ok(location.chain_location()),
_ => Err(Error::<T>::InvalidAsset),
}?;
if asset_location == MultiLocation::here() ||
<T::XcmExecutor as AssetTransferFilter>::IsTeleporter::contains(
asset,
&asset_location,
) {
// local asset, or remote location that allows local teleports => local reserve
Ok(TransferType::LocalReserve)
} else if <T::XcmExecutor as AssetTransferFilter>::IsReserve::contains(
asset,
&asset_location,
) {
// remote location that is recognized as reserve location for asset
Ok(TransferType::RemoteReserve(asset_location))
} else {
// remote location that is not configured either as teleporter or reserve => cannot
// determine asset reserve
Err(Error::<T>::UnknownReserve)
}
}
}

impl<T: Config> Pallet<T> {
/// Validate `assets` to be reserve-transferred and return their reserve location.
fn validate_assets_and_find_reserve(
Expand All @@ -1270,9 +1222,11 @@ impl<T: Config> Pallet<T> {
// Ensure fungible asset.
ensure!(
matches!(asset.fun, Fungibility::Fungible(x) if !x.is_zero()),
Error::<T>::InvalidAsset
Error::<T>::InvalidAsset(AssetTransferError::NotFungible)
);
let transfer_type = TransferType::determine_for::<T>(&asset, dest)?;
let transfer_type =
<T::XcmExecutor as AssetTransferSupport>::determine_for(&asset, dest)
.map_err(Error::<T>::InvalidAsset)?;
// Ensure asset is not teleportable to `dest`.
ensure!(transfer_type != TransferType::Teleport, Error::<T>::Filtered);
if let Some(reserve) = reserve.as_ref() {
Expand Down Expand Up @@ -1310,7 +1264,9 @@ impl<T: Config> Pallet<T> {
return Err(Error::<T>::Empty.into())
}
let mut fees = assets.swap_remove(fee_asset_item as usize);
let fees_transfer_type = TransferType::determine_for::<T>(&fees, &dest)?;
let fees_transfer_type =
<T::XcmExecutor as AssetTransferSupport>::determine_for(&fees, &dest)
.map_err(Error::<T>::InvalidAsset)?;
let assets_transfer_type = if assets.is_empty() {
// Single asset to transfer (one used for fees where transfer type is determined above).
ensure!(fees_transfer_type != TransferType::Teleport, Error::<T>::Filtered);
Expand Down Expand Up @@ -1353,7 +1309,8 @@ impl<T: Config> Pallet<T> {
assets_reserve,
beneficiary,
vec![fees.clone()],
TransferType::determine_for::<T>(&fees, &assets_reserve)?,
<T::XcmExecutor as AssetTransferSupport>::determine_for(&fees, &assets_reserve)
.map_err(Error::<T>::InvalidAsset)?,
fees.clone(),
quarter_weight_limit.clone(),
)?;
Expand Down Expand Up @@ -1414,7 +1371,9 @@ impl<T: Config> Pallet<T> {
ensure!(T::XcmTeleportFilter::contains(&value), Error::<T>::Filtered);
let (origin_location, assets) = value;
for asset in assets.iter() {
let transfer_type = TransferType::determine_for::<T>(asset, &dest)?;
let transfer_type =
<T::XcmExecutor as AssetTransferSupport>::determine_for(asset, &dest)
.map_err(Error::<T>::InvalidAsset)?;
ensure!(matches!(transfer_type, TransferType::Teleport), Error::<T>::Filtered);
}
let fees = assets.get(fee_asset_item as usize).ok_or(Error::<T>::Empty)?.clone();
Expand Down Expand Up @@ -1922,7 +1881,7 @@ impl<T: Config> Pallet<T> {
*amount = amount.saturating_div(2);
Ok(())
},
NonFungible(_) => Err(Error::<T>::InvalidAsset),
NonFungible(_) => Err(Error::<T>::InvalidAsset(AssetTransferError::NotFungible)),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions polkadot/xcm/xcm-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version = "1.0.0"
impl-trait-for-tuples = "0.2.2"
environmental = { version = "1.1.4", default-features = false }
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] }
xcm = { package = "staging-xcm", path = "..", default-features = false }
sp-std = { path = "../../../substrate/primitives/std", default-features = false }
sp-io = { path = "../../../substrate/primitives/io", default-features = false }
Expand All @@ -33,6 +34,7 @@ std = [
"frame-support/std",
"log/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use traits::{
mod assets;
pub use assets::Assets;
mod config;
use crate::traits::AssetTransferFilter;
use crate::traits::AssetTransferSupport;
pub use config::Config;

/// A struct to specify how fees are being paid.
Expand Down Expand Up @@ -255,7 +255,7 @@ impl<Config: config::Config> ExecuteXcm<Config::RuntimeCall> for XcmExecutor<Con
}
}

impl<Config: config::Config> AssetTransferFilter for XcmExecutor<Config> {
impl<Config: config::Config> AssetTransferSupport for XcmExecutor<Config> {
type IsReserve = Config::IsReserve;
type IsTeleporter = Config::IsTeleporter;
}
Expand Down
61 changes: 58 additions & 3 deletions polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,71 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use frame_support::traits::ContainsPair;
use frame_support::traits::{ContainsPair, PalletError};
use scale_info::TypeInfo;
use sp_runtime::codec::{Decode, Encode};
use xcm::prelude::*;

/// A trait for identifying asset transfer type.
pub trait AssetTransferFilter {
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
pub enum Error {
/// Invalid non-concrete asset.
NotConcrete,
/// Invalid non-fungible asset.
NotFungible,
/// Reserve chain could not be determined for assets.
UnknownReserve,
}

impl PalletError for Error {
const MAX_ENCODED_SIZE: usize = 1;
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum TransferType {
Teleport,
LocalReserve,
DestinationReserve,
RemoteReserve(MultiLocation),
}

/// A trait for identifying asset transfer type based on `IsTeleporter` and `IsReserve`
/// configurations.
pub trait AssetTransferSupport {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems too generic, maybe something like DetermineAssetTransferType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also exposes

	/// How to withdraw and deposit an asset.
	type AssetTransactor: TransactAsset;

so it's more than just determining asset transfer type/strategy..

Copy link
Contributor

@KiChjang KiChjang Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too have reservations about the naming, but aside from that, what I'm more interested in is how this trait composes with the Config trait. It would seem to me that it is just reassigning the 3 associated types in this trait. Given that's the case, there are a couple of things that we can do to DRY up these 2 traits:

  1. Remove the 3 associated type items in Config, and make AssetTransferSupport a supertrait of Config, i.e. implementors of Config MUST also implement AssetTransferSupport;
  2. Remove the 3 associated type items here in AssetTransferSupport, and make Config a supertrait of AssetTransferSupport

I'd probably prefer (1) as the executor has to make use of AssetTransactor, IsReserve and IsTeleporter in its own processing.

Copy link
Contributor Author

@acatangiu acatangiu Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work that way - xcm_executor::config::Config is not actually exposed to pallets, but traits implemented on the executor itself are exposed (such as ExecuteXcm). Actual XcmExecutor doesn't implement Config (it's hidden within) - making AssetTransferSupport a supertrait of Config or even the other way around doesn't then help us in using it like:

type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + <need-some-custom-trait-here-anyway-cannot-be-config>;

More so, looks like xcm_executor::config::Config is the general XcmConfig configured for runtimes - and it's pretty nice that it's flat and all XCM configurations go in a single place, splitting its types to subtraits just makes it harder for builders IMO (also is a breaking change at the code level).

Anyway I made a prototype of your suggestion at acatangiu@f40c210 - have a look - I am leaning towards keeping it as is. We duplicate a couple types in the implementation underbelly, but at the benefit of adding this enhancement transparently (no API breaks).

Also renamed the trait to XcmAssetTransfers hope it sounds better :)

/// Combinations of (Asset, Location) pairs which we trust as reserves. Meaning
/// reserve-based-transfers are to be used for assets matching this filter.
type IsReserve: ContainsPair<MultiAsset, MultiLocation>;

/// Combinations of (Asset, Location) pairs which we trust as teleporters. Meaning teleports are
/// to be used for assets matching this filter.
type IsTeleporter: ContainsPair<MultiAsset, MultiLocation>;

/// Determine transfer type to be used for transferring `asset` from local chain to `dest`.
fn determine_for(asset: &MultiAsset, dest: &MultiLocation) -> Result<TransferType, Error> {
if Self::IsTeleporter::contains(asset, dest) {
// we trust destination for teleporting asset
return Ok(TransferType::Teleport)
} else if Self::IsReserve::contains(asset, dest) {
// we trust destination as asset reserve location
return Ok(TransferType::DestinationReserve)
}

// try to determine reserve location based on asset id/location
let asset_location = match asset.id {
Concrete(location) => Ok(location.chain_location()),
_ => Err(Error::NotConcrete),
}?;
if asset_location == MultiLocation::here() ||
Self::IsTeleporter::contains(asset, &asset_location)
{
// if local asset, or remote location that allows local teleports => local reserve
Ok(TransferType::LocalReserve)
} else if Self::IsReserve::contains(asset, &asset_location) {
// remote location that is recognized as reserve location for asset
Ok(TransferType::RemoteReserve(asset_location))
} else {
// remote location that is not configured either as teleporter or reserve => cannot
// determine asset reserve
Err(Error::UnknownReserve)
}
}
}
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-executor/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use asset_exchange::AssetExchange;
mod asset_lock;
pub use asset_lock::{AssetLock, Enact, LockError};
mod asset_transfer;
pub use asset_transfer::AssetTransferFilter;
pub use asset_transfer::{AssetTransferSupport, Error as AssetTransferError, TransferType};
mod export;
pub use export::{export_xcm, validate_export, ExportXcm};
mod fee_manager;
Expand Down