Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transfer_assets_using_type_and_then extrinsic in pallet-xcm precompile #54

Merged
merged 12 commits into from
Oct 8, 2024
1 change: 1 addition & 0 deletions pallets/emergency-para-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate as pallet_emergency_para_xcm;
use cumulus_pallet_parachain_system::ParachainSetCode;
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, AggregateMessageOrigin, ParaId,
XcmpMessageHandler,
};
use frame_support::parameter_types;
use frame_support::traits::ConstU32;
Expand Down
5 changes: 5 additions & 0 deletions precompiles/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ xcm-primitives = { workspace = true }
# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-weights = { workspace = true }
parity-scale-codec = { workspace = true, features = [ "derive" ] }

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

# Polkadot
xcm = { workspace = true }
xcm-executor = { workspace = true }
pallet-xcm = { workspace = true }

# Cumulus
Expand Down Expand Up @@ -61,7 +64,9 @@ std = [
"frame-system/std",
"pallet-evm/std",
"pallet-xcm/std",
"parity-scale-codec/std",
"precompile-utils/std",
"scale-info/std",
"sp-core/std",
"sp-std/std",
"xcm/std",
Expand Down
119 changes: 95 additions & 24 deletions precompiles/pallet-xcm/XcmInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,68 +29,139 @@ interface XCM {
uint256 amount;
}

// The values start at `0` and are represented as `uint8`
enum TransferType {
Teleport,
LocalReserve,
DestinationReserve
}

/// @dev Function to send assets via XCM using transfer_assets() pallet-xcm extrinsic.
/// @custom:selector 59df8416
/// @custom:selector 9ea8ada7
/// @param dest The destination chain.
/// @param beneficiary The actual account that will receive the tokens on dest.
/// @param assets The combination (array) of assets to send.
/// @param assets The combination (array) of assets to send in Location format.
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
/// @param weight The weight to be used for the whole XCM operation.
/// (uint64::MAX in refTime means Unlimited weight)
function transferAssetsLocation(
Location memory dest,
Location memory beneficiary,
AssetLocationInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
uint32 feeAssetItem
) external;

/// @dev Function to send assets via XCM to a 20 byte-like parachain
/// using transfer_assets() pallet-xcm extrinsic.
/// @custom:selector b489262e
/// @custom:selector a0aeb5fe
/// @param paraId The para-id of the destination chain.
/// @param beneficiary The actual account that will receive the tokens on paraId destination.
/// @param assets The combination (array) of assets to send.
/// @param assets The combination (array) of assets to send in Address format.
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
/// @param weight The weight to be used for the whole XCM operation.
/// (uint64::MAX in refTime means Unlimited weight)
function transferAssetsToPara20(
uint32 paraId,
address beneficiary,
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
uint32 feeAssetItem
) external;

/// @dev Function to send assets via XCM to a 32 byte-like parachain
/// using transfer_assets() pallet-xcm extrinsic.
/// @custom:selector 4461e6f5
/// @custom:selector f23032c3
/// @param paraId The para-id of the destination chain.
/// @param beneficiary The actual account that will receive the tokens on paraId destination.
/// @param assets The combination (array) of assets to send.
/// @param assets The combination (array) of assets to send in Address format.
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
/// @param weight The weight to be used for the whole XCM operation.
/// (uint64::MAX in refTime means Unlimited weight)
function transferAssetsToPara32(
uint32 paraId,
bytes32 beneficiary,
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
uint32 feeAssetItem
) external;

/// @dev Function to send assets via XCM to the relay chain
/// using transfer_assets() pallet-xcm extrinsic.
/// @custom:selector d7c89659
/// @custom:selector 6521cc2c
/// @param beneficiary The actual account that will receive the tokens on the relay chain.
/// @param assets The combination (array) of assets to send.
/// @param assets The combination (array) of assets to send in Address format.
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
/// @param weight The weight to be used for the whole XCM operation.
/// (uint64::MAX in refTime means Unlimited weight)
function transferAssetsToRelay(
bytes32 beneficiary,
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
uint32 feeAssetItem
) external;

/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
/// extrinsic.
/// Important: in this selector RemoteReserve type (for either assets or fees) is not allowed.
/// If users want to send assets and fees (in Location format) with a remote reserve,
/// they must use the selector fc19376c.
/// @custom:selector 8425d893
/// @param dest The destination chain.
/// @param assets The combination (array) of assets to send in Location format.
/// @param assetsTransferType The TransferType corresponding to assets being sent.
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
/// @param feesTransferType The TransferType corresponding to the asset used as fees.
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
function transferAssetsUsingTypeAndThenLocation(
Location memory dest,
AssetLocationInfo[] memory assets,
TransferType assetsTransferType,
uint8 remoteFeesIdIndex,
TransferType feesTransferType,
bytes memory customXcmOnDest
) external;

/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
/// extrinsic.
/// @custom:selector fc19376c
/// @param dest The destination chain.
/// @param assets The combination (array) of assets to send in Location format.
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
/// @param remoteReserve The remote reserve corresponding for assets and fees. They MUST
/// share the same reserve.
function transferAssetsUsingTypeAndThenLocation(
Location memory dest,
AssetLocationInfo[] memory assets,
uint8 remoteFeesIdIndex,
bytes memory customXcmOnDest,
Location memory remoteReserve
) external;

/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
/// extrinsic.
/// Important: in this selector RemoteReserve type (for either assets or fees) is not allowed.
/// If users want to send assets and fees (in Address format) with a remote reserve,
/// they must use the selector aaecfc62.
/// @custom:selector 998093ee
/// @param dest The destination chain.
/// @param assets The combination (array) of assets to send in Address format.
/// @param assetsTransferType The TransferType corresponding to assets being sent.
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
/// @param feesTransferType The TransferType corresponding to the asset used as fees.
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
function transferAssetsUsingTypeAndThenAddress(
Location memory dest,
AssetAddressInfo[] memory assets,
TransferType assetsTransferType,
uint8 remoteFeesIdIndex,
TransferType feesTransferType,
bytes memory customXcmOnDest
) external;

/// @dev Function to send assets through transfer_assets_using_type_and_then() pallet-xcm
/// extrinsic.
/// @custom:selector aaecfc62
/// @param dest The destination chain.
/// @param assets The combination (array) of assets to send in Address format.
/// @param remoteFeesIdIndex The index of the asset (inside assets array) to use as fees.
/// @param customXcmOnDest The XCM message to execute on destination chain (SCALE encoded).
/// @param remoteReserve The remote reserve corresponding for assets and fees. They MUST
/// share the same reserve.
function transferAssetsUsingTypeAndThenAddress(
Location memory dest,
AssetAddressInfo[] memory assets,
uint8 remoteFeesIdIndex,
bytes memory customXcmOnDest,
Location memory remoteReserve
) external;
}
Loading
Loading