Skip to content

Commit 767eb0c

Browse files
authored
Add support for transfer_assets_using_type_and_then extrinsic in pallet-xcm precompile (#54)
* start adding transfer_assets_using_type_and_then to pallet-xcm precompile * add function variant for address type * use WeightLimit::Unlimited in all selectors * add remaining functions and overall refactor * remove unnecessary selectors and add a couple tests * add more tests * pr suggestions * add documentation for solidity selectors * fmt * fix test * fix rust tests compilation * add clarification for SCALE encoding in custom xcm
1 parent ddc8eca commit 767eb0c

5 files changed

Lines changed: 601 additions & 104 deletions

File tree

pallets/emergency-para-xcm/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate as pallet_emergency_para_xcm;
1919
use cumulus_pallet_parachain_system::ParachainSetCode;
2020
use cumulus_primitives_core::{
2121
relay_chain::BlockNumber as RelayBlockNumber, AggregateMessageOrigin, ParaId,
22+
XcmpMessageHandler,
2223
};
2324
use frame_support::parameter_types;
2425
use frame_support::traits::ConstU32;

precompiles/pallet-xcm/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ xcm-primitives = { workspace = true }
1616
# Substrate
1717
frame-support = { workspace = true }
1818
frame-system = { workspace = true }
19+
scale-info = { workspace = true }
1920
sp-core = { workspace = true }
2021
sp-runtime = { workspace = true }
2122
sp-std = { workspace = true }
2223
sp-weights = { workspace = true }
24+
parity-scale-codec = { workspace = true, features = [ "derive" ] }
2325

2426
# Frontier
2527
evm = { workspace = true, features = [ "with-codec" ] }
@@ -28,6 +30,7 @@ pallet-evm = { workspace = true, features = [ "forbid-evm-reentrancy" ] }
2830

2931
# Polkadot
3032
xcm = { workspace = true }
33+
xcm-executor = { workspace = true }
3134
pallet-xcm = { workspace = true }
3235

3336
# Cumulus
@@ -61,7 +64,9 @@ std = [
6164
"frame-system/std",
6265
"pallet-evm/std",
6366
"pallet-xcm/std",
67+
"parity-scale-codec/std",
6468
"precompile-utils/std",
69+
"scale-info/std",
6570
"sp-core/std",
6671
"sp-std/std",
6772
"xcm/std",

precompiles/pallet-xcm/XcmInterface.sol

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,68 +29,139 @@ interface XCM {
2929
uint256 amount;
3030
}
3131

32+
// The values start at `0` and are represented as `uint8`
33+
enum TransferType {
34+
Teleport,
35+
LocalReserve,
36+
DestinationReserve
37+
}
38+
3239
/// @dev Function to send assets via XCM using transfer_assets() pallet-xcm extrinsic.
33-
/// @custom:selector 59df8416
40+
/// @custom:selector 9ea8ada7
3441
/// @param dest The destination chain.
3542
/// @param beneficiary The actual account that will receive the tokens on dest.
36-
/// @param assets The combination (array) of assets to send.
43+
/// @param assets The combination (array) of assets to send in Location format.
3744
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
38-
/// @param weight The weight to be used for the whole XCM operation.
39-
/// (uint64::MAX in refTime means Unlimited weight)
4045
function transferAssetsLocation(
4146
Location memory dest,
4247
Location memory beneficiary,
4348
AssetLocationInfo[] memory assets,
44-
uint32 feeAssetItem,
45-
Weight memory weight
49+
uint32 feeAssetItem
4650
) external;
4751

4852
/// @dev Function to send assets via XCM to a 20 byte-like parachain
4953
/// using transfer_assets() pallet-xcm extrinsic.
50-
/// @custom:selector b489262e
54+
/// @custom:selector a0aeb5fe
5155
/// @param paraId The para-id of the destination chain.
5256
/// @param beneficiary The actual account that will receive the tokens on paraId destination.
53-
/// @param assets The combination (array) of assets to send.
57+
/// @param assets The combination (array) of assets to send in Address format.
5458
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
55-
/// @param weight The weight to be used for the whole XCM operation.
56-
/// (uint64::MAX in refTime means Unlimited weight)
5759
function transferAssetsToPara20(
5860
uint32 paraId,
5961
address beneficiary,
6062
AssetAddressInfo[] memory assets,
61-
uint32 feeAssetItem,
62-
Weight memory weight
63+
uint32 feeAssetItem
6364
) external;
6465

6566
/// @dev Function to send assets via XCM to a 32 byte-like parachain
6667
/// using transfer_assets() pallet-xcm extrinsic.
67-
/// @custom:selector 4461e6f5
68+
/// @custom:selector f23032c3
6869
/// @param paraId The para-id of the destination chain.
6970
/// @param beneficiary The actual account that will receive the tokens on paraId destination.
70-
/// @param assets The combination (array) of assets to send.
71+
/// @param assets The combination (array) of assets to send in Address format.
7172
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
72-
/// @param weight The weight to be used for the whole XCM operation.
73-
/// (uint64::MAX in refTime means Unlimited weight)
7473
function transferAssetsToPara32(
7574
uint32 paraId,
7675
bytes32 beneficiary,
7776
AssetAddressInfo[] memory assets,
78-
uint32 feeAssetItem,
79-
Weight memory weight
77+
uint32 feeAssetItem
8078
) external;
8179

8280
/// @dev Function to send assets via XCM to the relay chain
8381
/// using transfer_assets() pallet-xcm extrinsic.
84-
/// @custom:selector d7c89659
82+
/// @custom:selector 6521cc2c
8583
/// @param beneficiary The actual account that will receive the tokens on the relay chain.
86-
/// @param assets The combination (array) of assets to send.
84+
/// @param assets The combination (array) of assets to send in Address format.
8785
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
88-
/// @param weight The weight to be used for the whole XCM operation.
89-
/// (uint64::MAX in refTime means Unlimited weight)
9086
function transferAssetsToRelay(
9187
bytes32 beneficiary,
9288
AssetAddressInfo[] memory assets,
93-
uint32 feeAssetItem,
94-
Weight memory weight
89+
uint32 feeAssetItem
90+
) external;
91+
92+
/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
93+
/// extrinsic.
94+
/// Important: in this selector RemoteReserve type (for either assets or fees) is not allowed.
95+
/// If users want to send assets and fees (in Location format) with a remote reserve,
96+
/// they must use the selector fc19376c.
97+
/// @custom:selector 8425d893
98+
/// @param dest The destination chain.
99+
/// @param assets The combination (array) of assets to send in Location format.
100+
/// @param assetsTransferType The TransferType corresponding to assets being sent.
101+
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
102+
/// @param feesTransferType The TransferType corresponding to the asset used as fees.
103+
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
104+
function transferAssetsUsingTypeAndThenLocation(
105+
Location memory dest,
106+
AssetLocationInfo[] memory assets,
107+
TransferType assetsTransferType,
108+
uint8 remoteFeesIdIndex,
109+
TransferType feesTransferType,
110+
bytes memory customXcmOnDest
111+
) external;
112+
113+
/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
114+
/// extrinsic.
115+
/// @custom:selector fc19376c
116+
/// @param dest The destination chain.
117+
/// @param assets The combination (array) of assets to send in Location format.
118+
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
119+
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
120+
/// @param remoteReserve The remote reserve corresponding for assets and fees. They MUST
121+
/// share the same reserve.
122+
function transferAssetsUsingTypeAndThenLocation(
123+
Location memory dest,
124+
AssetLocationInfo[] memory assets,
125+
uint8 remoteFeesIdIndex,
126+
bytes memory customXcmOnDest,
127+
Location memory remoteReserve
128+
) external;
129+
130+
/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
131+
/// extrinsic.
132+
/// Important: in this selector RemoteReserve type (for either assets or fees) is not allowed.
133+
/// If users want to send assets and fees (in Address format) with a remote reserve,
134+
/// they must use the selector aaecfc62.
135+
/// @custom:selector 998093ee
136+
/// @param dest The destination chain.
137+
/// @param assets The combination (array) of assets to send in Address format.
138+
/// @param assetsTransferType The TransferType corresponding to assets being sent.
139+
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
140+
/// @param feesTransferType The TransferType corresponding to the asset used as fees.
141+
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
142+
function transferAssetsUsingTypeAndThenAddress(
143+
Location memory dest,
144+
AssetAddressInfo[] memory assets,
145+
TransferType assetsTransferType,
146+
uint8 remoteFeesIdIndex,
147+
TransferType feesTransferType,
148+
bytes memory customXcmOnDest
149+
) external;
150+
151+
/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
152+
/// extrinsic.
153+
/// @custom:selector aaecfc62
154+
/// @param dest The destination chain.
155+
/// @param assets The combination (array) of assets to send in Address format.
156+
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
157+
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
158+
/// @param remoteReserve The remote reserve corresponding for assets and fees. They MUST
159+
/// share the same reserve.
160+
function transferAssetsUsingTypeAndThenAddress(
161+
Location memory dest,
162+
AssetAddressInfo[] memory assets,
163+
uint8 remoteFeesIdIndex,
164+
bytes memory customXcmOnDest,
165+
Location memory remoteReserve
95166
) external;
96167
}

0 commit comments

Comments
 (0)