Skip to content

Commit

Permalink
use WeightLimit::Unlimited in all selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Oct 3, 2024
1 parent 76702b2 commit cada24d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 98 deletions.
34 changes: 10 additions & 24 deletions precompiles/pallet-xcm/XcmInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,56 @@ interface XCM {
}

/// @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 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 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 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 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;

function transferAssetsUsingTypeAndThenLocation(
Expand All @@ -110,8 +98,7 @@ interface XCM {
uint8 remoteFeesIdIndex,
TransferType feesTransferType,
Location memory maybeFeesRemoteReserve,
bytes memory customXcmOnDest,
Weight memory weight
bytes memory customXcmOnDest
) external;

function transferAssetsUsingTypeAndThenAddress(
Expand All @@ -122,7 +109,6 @@ interface XCM {
uint8 remoteFeesIdIndex,
TransferType feesTransferType,
Location memory maybeFeesRemoteReserve,
bytes memory customXcmOnDest,
Weight memory weight
bytes memory customXcmOnDest
) external;
}
68 changes: 13 additions & 55 deletions precompiles/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sp_runtime::traits::Dispatchable;
use sp_std::{boxed::Box, marker::PhantomData, vec, vec::Vec};
use sp_weights::Weight;
use xcm::{
latest::{Asset, AssetId, Assets, Fungibility, Location},
latest::{Asset, AssetId, Assets, Fungibility, Location, WeightLimit},
prelude::WeightLimit::*,
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm, MAX_XCM_DECODE_DEPTH,
};
Expand Down Expand Up @@ -83,16 +83,14 @@ where
(uint8,bytes[]),\
(uint8,bytes[]),\
((uint8,bytes[]),uint256)[],\
uint32,\
(uint64,uint64))"
uint32)"
)]
fn transfer_assets_location(
handle: &mut impl PrecompileHandle,
dest: Location,
beneficiary: Location,
assets: BoundedVec<(Location, Convert<U256, u128>), GetArrayLimit>,
fee_asset_item: u32,
weight: Weight,
) -> EvmResult {
// No DB access before try_dispatch but some logical stuff.
// To prevent spam, we charge an arbitrary amount of gas.
Expand All @@ -110,17 +108,12 @@ where
.collect::<Vec<Asset>>()
.into();

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let call = pallet_xcm::Call::<Runtime>::transfer_assets {
dest: Box::new(VersionedLocation::V4(dest)),
beneficiary: Box::new(VersionedLocation::V4(beneficiary)),
assets: Box::new(VersionedAssets::V4(assets_to_send)),
fee_asset_item,
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -132,16 +125,14 @@ where
uint32,\
address,\
(address,uint256)[],\
uint32,\
(uint64,uint64))"
uint32)"
)]
fn transfer_assets_to_para_20(
handle: &mut impl PrecompileHandle,
para_id: u32,
beneficiary: Address,
assets: BoundedVec<(Address, Convert<U256, u128>), GetArrayLimit>,
fee_asset_item: u32,
weight: Weight,
) -> EvmResult {
// Account for a possible storage read inside LocationMatcher::convert().
//
Expand All @@ -156,11 +147,6 @@ where

let assets_to_send: Vec<Asset> = Self::check_and_prepare_assets(assets)?;

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let dest = XcmSiblingDestinationGenerator::generate(para_id);
let beneficiary = XcmLocalBeneficiary20Generator::generate(beneficiary.0 .0);

Expand All @@ -169,7 +155,7 @@ where
beneficiary: Box::new(VersionedLocation::V4(beneficiary)),
assets: Box::new(VersionedAssets::V4(assets_to_send.into())),
fee_asset_item,
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -182,16 +168,14 @@ where
uint32,\
bytes32,\
(address,uint256)[],\
uint32,\
(uint64,uint64))"
uint32)"
)]
fn transfer_assets_to_para_32(
handle: &mut impl PrecompileHandle,
para_id: u32,
beneficiary: H256,
assets: BoundedVec<(Address, Convert<U256, u128>), GetArrayLimit>,
fee_asset_item: u32,
weight: Weight,
) -> EvmResult {
// Account for a possible storage read inside LocationMatcher::convert().
//
Expand All @@ -206,11 +190,6 @@ where

let assets_to_send: Vec<Asset> = Self::check_and_prepare_assets(assets)?;

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let dest = XcmSiblingDestinationGenerator::generate(para_id);
let beneficiary = XcmLocalBeneficiary32Generator::generate(beneficiary.0);

Expand All @@ -219,7 +198,7 @@ where
beneficiary: Box::new(VersionedLocation::V4(beneficiary)),
assets: Box::new(VersionedAssets::V4(assets_to_send.into())),
fee_asset_item,
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -231,15 +210,13 @@ where
"transferAssetsToRelay(\
bytes32,\
(address,uint256)[],\
uint32,\
(uint64,uint64))"
uint32)"
)]
fn transfer_assets_to_relay(
handle: &mut impl PrecompileHandle,
beneficiary: H256,
assets: BoundedVec<(Address, Convert<U256, u128>), GetArrayLimit>,
fee_asset_item: u32,
weight: Weight,
) -> EvmResult {
// Account for a possible storage read inside LocationMatcher::convert().
//
Expand All @@ -254,11 +231,6 @@ where

let assets_to_send: Vec<Asset> = Self::check_and_prepare_assets(assets)?;

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let dest = Location::parent();
let beneficiary = XcmLocalBeneficiary32Generator::generate(beneficiary.0);

Expand All @@ -267,7 +239,7 @@ where
beneficiary: Box::new(VersionedLocation::V4(beneficiary)),
assets: Box::new(VersionedAssets::V4(assets_to_send.into())),
fee_asset_item,
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -284,8 +256,7 @@ where
uint8,\
uint8,\
(uint8,bytes[]),\
bytes,\
(uint64,uint64))"
bytes)"
)]
fn transfer_assets_using_type_and_then_location(
handle: &mut impl PrecompileHandle,
Expand All @@ -297,7 +268,6 @@ where
fees_transfer_type: u8,
maybe_fees_remote_reserve: Location,
custom_xcm_on_dest: BoundedBytes<GetXcmSizeLimit>,
weight: Weight,
) -> EvmResult {
// No DB access before try_dispatch but some logical stuff.
// To prevent spam, we charge an arbitrary amount of gas.
Expand All @@ -323,11 +293,6 @@ where
.collect::<Vec<Asset>>()
.into();

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let assets_transfer_type =
Self::check_transfer_type(assets_transfer_type, maybe_assets_remote_reserve)?;
let fees_transfer_type =
Expand All @@ -346,7 +311,7 @@ where
remote_fees_id: Box::new(VersionedAssetId::V4(remote_fees_id)),
fees_transfer_type: Box::new(fees_transfer_type),
custom_xcm_on_dest: Box::new(custom_xcm_on_dest),
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -363,8 +328,7 @@ where
uint8,\
uint8,\
(uint8,bytes[]),\
bytes,\
(uint64,uint64))"
bytes)"
)]
fn transfer_assets_using_type_and_then_address(
handle: &mut impl PrecompileHandle,
Expand All @@ -376,7 +340,6 @@ where
fees_transfer_type: u8,
maybe_fees_remote_reserve: Location,
custom_xcm_on_dest: BoundedBytes<GetXcmSizeLimit>,
weight: Weight,
) -> EvmResult {
// Account for a possible storage read inside LocationMatcher::convert().
//
Expand All @@ -398,11 +361,6 @@ where
AssetId(asset.id.0.clone())
};

let weight_limit = match weight.ref_time() {
u64::MAX => Unlimited,
_ => Limited(weight),
};

let assets_transfer_type =
Self::check_transfer_type(assets_transfer_type, maybe_assets_remote_reserve)?;
let fees_transfer_type =
Expand All @@ -421,7 +379,7 @@ where
remote_fees_id: Box::new(VersionedAssetId::V4(remote_fees_id)),
fees_transfer_type: Box::new(fees_transfer_type),
custom_xcm_on_dest: Box::new(custom_xcm_on_dest),
weight_limit,
weight_limit: WeightLimit::Unlimited,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand Down
Loading

0 comments on commit cada24d

Please sign in to comment.