Skip to content

Commit ee88f2e

Browse files
committed
pallet-xcm::transfer_assets_using_type() supports custom actions on destination
Change `transfer_assets_using_type()` to not assume `DepositAssets` as the intended use of the assets on the destination. Instead provides the caller with the ability to specify custom XCM that be executed on `dest` chain as the last step of the transfer, thus allowing custom usecases for the transferred assets. E.g. some are used/swapped/etc there, while some are sent further to yet another chain. Note: this is an API change for `transfer_assets_using_type()`, but it is ok as the previous version has not been yet released. Thus, its first release will include the new API proposed by this PR. Signed-off-by: Adrian Catangiu <[email protected]>
1 parent eda5e5c commit ee88f2e

File tree

5 files changed

+112
-70
lines changed

5 files changed

+112
-70
lines changed

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,37 @@ fn para_to_para_assethub_hop_assertions(t: ParaToParaThroughAHTest) {
5454
fn ah_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResult {
5555
let fee_idx = t.args.fee_asset_item as usize;
5656
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
57+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
58+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
59+
beneficiary: t.args.beneficiary,
60+
}]);
5761
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::transfer_assets_using_type(
5862
t.signed_origin,
5963
bx!(t.args.dest.into()),
60-
bx!(t.args.beneficiary.into()),
6164
bx!(t.args.assets.into()),
6265
bx!(TransferType::LocalReserve),
6366
bx!(fee.id.into()),
6467
bx!(TransferType::LocalReserve),
68+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
6569
t.args.weight_limit,
6670
)
6771
}
6872

6973
fn para_to_ah_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult {
7074
let fee_idx = t.args.fee_asset_item as usize;
7175
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
76+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
77+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
78+
beneficiary: t.args.beneficiary,
79+
}]);
7280
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
7381
t.signed_origin,
7482
bx!(t.args.dest.into()),
75-
bx!(t.args.beneficiary.into()),
7683
bx!(t.args.assets.into()),
7784
bx!(TransferType::DestinationReserve),
7885
bx!(fee.id.into()),
7986
bx!(TransferType::DestinationReserve),
87+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
8088
t.args.weight_limit,
8189
)
8290
}
@@ -85,44 +93,56 @@ fn para_to_para_transfer_assets_through_ah(t: ParaToParaThroughAHTest) -> Dispat
8593
let fee_idx = t.args.fee_asset_item as usize;
8694
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
8795
let asset_hub_location: Location = PenpalA::sibling_location_of(AssetHubRococo::para_id());
96+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
97+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
98+
beneficiary: t.args.beneficiary,
99+
}]);
88100
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
89101
t.signed_origin,
90102
bx!(t.args.dest.into()),
91-
bx!(t.args.beneficiary.into()),
92103
bx!(t.args.assets.into()),
93104
bx!(TransferType::RemoteReserve(asset_hub_location.clone().into())),
94105
bx!(fee.id.into()),
95106
bx!(TransferType::RemoteReserve(asset_hub_location.into())),
107+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
96108
t.args.weight_limit,
97109
)
98110
}
99111

100112
fn para_to_asset_hub_teleport_foreign_assets(t: ParaToSystemParaTest) -> DispatchResult {
101113
let fee_idx = t.args.fee_asset_item as usize;
102114
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
115+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
116+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
117+
beneficiary: t.args.beneficiary,
118+
}]);
103119
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
104120
t.signed_origin,
105121
bx!(t.args.dest.into()),
106-
bx!(t.args.beneficiary.into()),
107122
bx!(t.args.assets.into()),
108123
bx!(TransferType::Teleport),
109124
bx!(fee.id.into()),
110125
bx!(TransferType::DestinationReserve),
126+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
111127
t.args.weight_limit,
112128
)
113129
}
114130

115131
fn asset_hub_to_para_teleport_foreign_assets(t: SystemParaToParaTest) -> DispatchResult {
116132
let fee_idx = t.args.fee_asset_item as usize;
117133
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
134+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
135+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
136+
beneficiary: t.args.beneficiary,
137+
}]);
118138
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::transfer_assets_using_type(
119139
t.signed_origin,
120140
bx!(t.args.dest.into()),
121-
bx!(t.args.beneficiary.into()),
122141
bx!(t.args.assets.into()),
123142
bx!(TransferType::Teleport),
124143
bx!(fee.id.into()),
125144
bx!(TransferType::LocalReserve),
145+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
126146
t.args.weight_limit,
127147
)
128148
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,37 @@ fn para_to_para_assethub_hop_assertions(t: ParaToParaThroughAHTest) {
5454
fn ah_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResult {
5555
let fee_idx = t.args.fee_asset_item as usize;
5656
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
57+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
58+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
59+
beneficiary: t.args.beneficiary,
60+
}]);
5761
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::transfer_assets_using_type(
5862
t.signed_origin,
5963
bx!(t.args.dest.into()),
60-
bx!(t.args.beneficiary.into()),
6164
bx!(t.args.assets.into()),
6265
bx!(TransferType::LocalReserve),
6366
bx!(fee.id.into()),
6467
bx!(TransferType::LocalReserve),
68+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
6569
t.args.weight_limit,
6670
)
6771
}
6872

6973
fn para_to_ah_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult {
7074
let fee_idx = t.args.fee_asset_item as usize;
7175
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
76+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
77+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
78+
beneficiary: t.args.beneficiary,
79+
}]);
7280
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
7381
t.signed_origin,
7482
bx!(t.args.dest.into()),
75-
bx!(t.args.beneficiary.into()),
7683
bx!(t.args.assets.into()),
7784
bx!(TransferType::DestinationReserve),
7885
bx!(fee.id.into()),
7986
bx!(TransferType::DestinationReserve),
87+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
8088
t.args.weight_limit,
8189
)
8290
}
@@ -85,44 +93,56 @@ fn para_to_para_transfer_assets_through_ah(t: ParaToParaThroughAHTest) -> Dispat
8593
let fee_idx = t.args.fee_asset_item as usize;
8694
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
8795
let asset_hub_location: Location = PenpalA::sibling_location_of(AssetHubWestend::para_id());
96+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
97+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
98+
beneficiary: t.args.beneficiary,
99+
}]);
88100
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
89101
t.signed_origin,
90102
bx!(t.args.dest.into()),
91-
bx!(t.args.beneficiary.into()),
92103
bx!(t.args.assets.into()),
93104
bx!(TransferType::RemoteReserve(asset_hub_location.clone().into())),
94105
bx!(fee.id.into()),
95106
bx!(TransferType::RemoteReserve(asset_hub_location.into())),
107+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
96108
t.args.weight_limit,
97109
)
98110
}
99111

100112
fn para_to_asset_hub_teleport_foreign_assets(t: ParaToSystemParaTest) -> DispatchResult {
101113
let fee_idx = t.args.fee_asset_item as usize;
102114
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
115+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
116+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
117+
beneficiary: t.args.beneficiary,
118+
}]);
103119
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
104120
t.signed_origin,
105121
bx!(t.args.dest.into()),
106-
bx!(t.args.beneficiary.into()),
107122
bx!(t.args.assets.into()),
108123
bx!(TransferType::Teleport),
109124
bx!(fee.id.into()),
110125
bx!(TransferType::DestinationReserve),
126+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
111127
t.args.weight_limit,
112128
)
113129
}
114130

115131
fn asset_hub_to_para_teleport_foreign_assets(t: SystemParaToParaTest) -> DispatchResult {
116132
let fee_idx = t.args.fee_asset_item as usize;
117133
let fee: Asset = t.args.assets.inner().get(fee_idx).cloned().unwrap();
134+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
135+
assets: Wild(AllCounted(t.args.assets.len() as u32)),
136+
beneficiary: t.args.beneficiary,
137+
}]);
118138
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::transfer_assets_using_type(
119139
t.signed_origin,
120140
bx!(t.args.dest.into()),
121-
bx!(t.args.beneficiary.into()),
122141
bx!(t.args.assets.into()),
123142
bx!(TransferType::Teleport),
124143
bx!(fee.id.into()),
125144
bx!(TransferType::LocalReserve),
145+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
126146
t.args.weight_limit,
127147
)
128148
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ fn send_asset_from_penpal_rococo_through_local_asset_hub_to_westend_asset_hub(
6060
AccountId32Junction { network: None, id: AssetHubWestendReceiver::get().into() }.into();
6161
let assets: Assets = (id.clone(), transfer_amount).into();
6262
let fees_id: AssetId = id.into();
63+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
64+
assets: Wild(AllCounted(assets.len() as u32)),
65+
beneficiary,
66+
}]);
6367

6468
<PenpalA as PenpalAPallet>::PolkadotXcm::transfer_assets_using_type(
6569
signed_origin,
6670
bx!(destination.into()),
67-
bx!(beneficiary.into()),
6871
bx!(assets.clone().into()),
6972
bx!(TransferType::RemoteReserve(local_asset_hub.clone().into())),
7073
bx!(fees_id.into()),
7174
bx!(TransferType::RemoteReserve(local_asset_hub.into())),
75+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
7276
WeightLimit::Unlimited,
7377
)
7478
}));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ fn send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub(
5959
AccountId32Junction { network: None, id: AssetHubRococoReceiver::get().into() }.into();
6060
let assets: Assets = (id.clone(), transfer_amount).into();
6161
let fees_id: AssetId = id.into();
62+
let custom_xcm_on_dest = Xcm::<()>(vec![DepositAsset {
63+
assets: Wild(AllCounted(assets.len() as u32)),
64+
beneficiary,
65+
}]);
6266

6367
<PenpalB as PenpalBPallet>::PolkadotXcm::transfer_assets_using_type(
6468
signed_origin,
6569
bx!(destination.into()),
66-
bx!(beneficiary.into()),
6770
bx!(assets.into()),
6871
bx!(TransferType::RemoteReserve(local_asset_hub.clone().into())),
6972
bx!(fees_id.into()),
7073
bx!(TransferType::RemoteReserve(local_asset_hub.into())),
74+
bx!(VersionedXcm::from(custom_xcm_on_dest)),
7175
WeightLimit::Unlimited,
7276
)
7377
}));

0 commit comments

Comments
 (0)