Skip to content

Commit 1825737

Browse files
acatangiufranciscoaguirrebkontur
authored
pallet-xcm: enhance reserve_transfer_assets to support remote reserves (#1672)
## Motivation `pallet-xcm` is the main user-facing interface for XCM functionality, including assets manipulation functions like `teleportAssets()` and `reserve_transfer_assets()` calls. While `teleportAsset()` works both ways, `reserve_transfer_assets()` works only for sending reserve-based assets to a remote destination and beneficiary when the reserve is the _local chain_. ## Solution This PR enhances `pallet_xcm::(limited_)reserve_withdraw_assets` to support transfers when reserves are other chains. This will allow complete, **bi-directional** reserve-based asset transfers user stories using `pallet-xcm`. Enables following scenarios: - transferring assets with local reserve (was previously supported iff asset used as fee also had local reserve - now it works in all cases), - transferring assets with reserve on destination, - transferring assets with reserve on remote/third-party chain (iff assets and fees have same remote reserve), - transferring assets with reserve different than the reserve of the asset to be used as fees - meaning can be used to transfer random asset with local/dest reserve while using DOT for fees on all involved chains, even if DOT local/dest reserve doesn't match asset reserve, - transferring assets with any type of local/dest reserve while using fees which can be teleported between involved chains. All of the above is done by pallet inner logic without the user having to specify which scenario/reserves/teleports/etc. The correct scenario and corresponding XCM programs are identified, and respectively, built automatically based on runtime configuration of trusted teleporters and trusted reserves. #### Current limitations: - while `fees` and "non-fee" `assets` CAN have different reserves (or fees CAN be teleported), the remaining "non-fee" `assets` CANNOT, among themselves, have different reserve locations (this is also implicitly enforced by `MAX_ASSETS_FOR_TRANSFER=2`, but this can be safely increased in the future). - `fees` and "non-fee" `assets` CANNOT have **different remote** reserves (this could also be supported in the future, but adds even more complexity while possibly not being worth it - we'll see what the future holds). Fixes #1584 Fixes #2055 --------- Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Branislav Kontur <[email protected]>
1 parent 29654a4 commit 1825737

File tree

80 files changed

+3650
-1437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3650
-1437
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachain-template/runtime/src/xcm_config.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ pub type XcmRouter = WithUniqueTopic<(
150150
XcmpQueue,
151151
)>;
152152

153-
#[cfg(feature = "runtime-benchmarks")]
154-
parameter_types! {
155-
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
156-
}
157-
158153
impl pallet_xcm::Config for Runtime {
159154
type RuntimeEvent = RuntimeEvent;
160155
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
@@ -180,8 +175,6 @@ impl pallet_xcm::Config for Runtime {
180175
type SovereignAccountOf = LocationToAccountId;
181176
type MaxLockers = ConstU32<8>;
182177
type WeightInfo = pallet_xcm::TestWeightInfo;
183-
#[cfg(feature = "runtime-benchmarks")]
184-
type ReachableDest = ReachableDest;
185178
type AdminOrigin = EnsureRoot<AccountId>;
186179
type MaxRemoteLockConsumers = ConstU32<0>;
187180
type RemoteLockConsumerIdentifier = ();

cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize;
2121
// Cumulus
2222
use emulated_integration_tests_common::{
2323
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
24-
impl_assets_helpers_for_system_parachain, xcm_emulator::decl_test_parachains,
24+
impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains,
2525
};
2626
use rococo_emulated_chain::Rococo;
2727

@@ -51,5 +51,5 @@ decl_test_parachains! {
5151

5252
// AssetHubRococo implementation
5353
impl_accounts_helpers_for_parachain!(AssetHubRococo);
54-
impl_assert_events_helpers_for_parachain!(AssetHubRococo);
55-
impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo);
54+
impl_assert_events_helpers_for_parachain!(AssetHubRococo, false);
55+
impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo);

cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize;
2121
// Cumulus
2222
use emulated_integration_tests_common::{
2323
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
24-
impl_assets_helpers_for_system_parachain, xcm_emulator::decl_test_parachains,
24+
impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains,
2525
};
2626
use westend_emulated_chain::Westend;
2727

@@ -51,5 +51,5 @@ decl_test_parachains! {
5151

5252
// AssetHubWestend implementation
5353
impl_accounts_helpers_for_parachain!(AssetHubWestend);
54-
impl_assert_events_helpers_for_parachain!(AssetHubWestend);
55-
impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend);
54+
impl_assert_events_helpers_for_parachain!(AssetHubWestend, false);
55+
impl_assets_helpers_for_parachain!(AssetHubWestend, Westend);

cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use frame_support::traits::OnInitialize;
1919
// Cumulus
2020
use emulated_integration_tests_common::{
2121
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
22-
impl_assets_helpers_for_system_parachain, xcm_emulator::decl_test_parachains,
22+
impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains,
2323
};
2424
use wococo_emulated_chain::Wococo;
2525

@@ -49,5 +49,5 @@ decl_test_parachains! {
4949

5050
// AssetHubWococo implementation
5151
impl_accounts_helpers_for_parachain!(AssetHubWococo);
52-
impl_assert_events_helpers_for_parachain!(AssetHubWococo);
53-
impl_assets_helpers_for_system_parachain!(AssetHubWococo, Wococo);
52+
impl_assert_events_helpers_for_parachain!(AssetHubWococo, false);
53+
impl_assets_helpers_for_parachain!(AssetHubWococo, Wococo);

cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ decl_test_parachains! {
4646

4747
// BridgeHubRococo implementation
4848
impl_accounts_helpers_for_parachain!(BridgeHubRococo);
49-
impl_assert_events_helpers_for_parachain!(BridgeHubRococo);
49+
impl_assert_events_helpers_for_parachain!(BridgeHubRococo, false);

cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ decl_test_parachains! {
4646

4747
// BridgeHubWestend implementation
4848
impl_accounts_helpers_for_parachain!(BridgeHubWestend);
49-
impl_assert_events_helpers_for_parachain!(BridgeHubWestend);
49+
impl_assert_events_helpers_for_parachain!(BridgeHubWestend, false);

cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ decl_test_parachains! {
4444

4545
// BridgeHubWococo implementation
4646
impl_accounts_helpers_for_parachain!(BridgeHubWococo);
47-
impl_assert_events_helpers_for_parachain!(BridgeHubWococo);
47+
impl_assert_events_helpers_for_parachain!(BridgeHubWococo, false);

cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ parachains-common = { path = "../../../../../../../parachains/common" }
2222
cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false }
2323
emulated-integration-tests-common = { path = "../../../../common", default-features = false }
2424
penpal-runtime = { path = "../../../../../../runtimes/testing/penpal" }
25+
rococo-emulated-chain = { path = "../../../relays/rococo" }

cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use frame_support::traits::OnInitialize;
2121

2222
// Cumulus
2323
use emulated_integration_tests_common::{
24-
impl_assert_events_helpers_for_parachain, xcm_emulator::decl_test_parachains,
24+
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
25+
impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains,
2526
};
27+
use rococo_emulated_chain::Rococo;
2628

2729
// Penpal Parachain declaration
2830
decl_test_parachains! {
@@ -40,6 +42,7 @@ decl_test_parachains! {
4042
pallets = {
4143
PolkadotXcm: penpal_runtime::PolkadotXcm,
4244
Assets: penpal_runtime::Assets,
45+
Balances: penpal_runtime::Balances,
4346
}
4447
},
4548
pub struct PenpalB {
@@ -56,10 +59,13 @@ decl_test_parachains! {
5659
pallets = {
5760
PolkadotXcm: penpal_runtime::PolkadotXcm,
5861
Assets: penpal_runtime::Assets,
62+
Balances: penpal_runtime::Balances,
5963
}
6064
},
6165
}
6266

6367
// Penpal implementation
64-
impl_assert_events_helpers_for_parachain!(PenpalA);
65-
impl_assert_events_helpers_for_parachain!(PenpalB);
68+
impl_accounts_helpers_for_parachain!(PenpalA);
69+
impl_assets_helpers_for_parachain!(PenpalA, Rococo);
70+
impl_assert_events_helpers_for_parachain!(PenpalA, true);
71+
impl_assert_events_helpers_for_parachain!(PenpalB, true);

0 commit comments

Comments
 (0)