From 57fa08c1ad101f46a12fc469b75d30bd76658290 Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 28 Aug 2024 13:37:47 +0800 Subject: [PATCH] Fix build payload for foreign token --- contracts/src/Assets.sol | 18 ++++++++++++++---- contracts/src/SubstrateTypes.sol | 16 ++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/contracts/src/Assets.sol b/contracts/src/Assets.sol index d501f6e369..c88ead8846 100644 --- a/contracts/src/Assets.sol +++ b/contracts/src/Assets.sol @@ -247,8 +247,8 @@ library Assets { // The funds will be minted into the receiver's account on AssetHub if (destinationAddress.isAddress32()) { // The receiver has a 32-byte account ID - ticket.payload = SubstrateTypes.SendTokenToAssetHubAddress32( - token, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount + ticket.payload = SubstrateTypes.SendForeignTokenToAssetHubAddress32( + foreignID, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount ); } else { // AssetHub does not support 20-byte account IDs @@ -261,12 +261,22 @@ library Assets { if (destinationAddress.isAddress32()) { // The receiver has a 32-byte account ID ticket.payload = SubstrateTypes.SendForeignTokenToAddress32( - foreignID, destinationChain, destinationAddress.asAddress32(), destinationChainFee, amount + foreignID, + destinationChain, + destinationAddress.asAddress32(), + $.assetHubReserveTransferFee, + destinationChainFee, + amount ); } else if (destinationAddress.isAddress20()) { // The receiver has a 20-byte account ID ticket.payload = SubstrateTypes.SendForeignTokenToAddress20( - foreignID, destinationChain, destinationAddress.asAddress20(), destinationChainFee, amount + foreignID, + destinationChain, + destinationAddress.asAddress20(), + $.assetHubReserveTransferFee, + destinationChainFee, + amount ); } else { revert Unsupported(); diff --git a/contracts/src/SubstrateTypes.sol b/contracts/src/SubstrateTypes.sol index 0040297166..296f32ce57 100644 --- a/contracts/src/SubstrateTypes.sol +++ b/contracts/src/SubstrateTypes.sol @@ -134,7 +134,7 @@ library SubstrateTypes { ); } - function SendForeignTokenToAssetHubAddress32(address token, bytes32 recipient, uint128 xcmFee, uint128 amount) + function SendForeignTokenToAssetHubAddress32(bytes32 tokenID, bytes32 recipient, uint128 xcmFee, uint128 amount) internal view returns (bytes memory) @@ -143,7 +143,7 @@ library SubstrateTypes { bytes1(0x00), ScaleCodec.encodeU64(uint64(block.chainid)), bytes1(0x02), - SubstrateTypes.H160(token), + tokenID, bytes1(0x00), recipient, ScaleCodec.encodeU128(amount), @@ -157,6 +157,7 @@ library SubstrateTypes { ParaID paraID, bytes32 recipient, uint128 xcmFee, + uint128 destinationXcmFee, uint128 amount ) internal view returns (bytes memory) { return bytes.concat( @@ -167,8 +168,9 @@ library SubstrateTypes { bytes1(0x01), ScaleCodec.encodeU32(uint32(ParaID.unwrap(paraID))), recipient, - ScaleCodec.encodeU128(xcmFee), - ScaleCodec.encodeU128(amount) + ScaleCodec.encodeU128(destinationXcmFee), + ScaleCodec.encodeU128(amount), + ScaleCodec.encodeU128(xcmFee) ); } @@ -178,6 +180,7 @@ library SubstrateTypes { ParaID paraID, bytes20 recipient, uint128 xcmFee, + uint128 destinationXcmFee, uint128 amount ) internal view returns (bytes memory) { return bytes.concat( @@ -188,8 +191,9 @@ library SubstrateTypes { bytes1(0x02), ScaleCodec.encodeU32(uint32(ParaID.unwrap(paraID))), recipient, - ScaleCodec.encodeU128(xcmFee), - ScaleCodec.encodeU128(amount) + ScaleCodec.encodeU128(destinationXcmFee), + ScaleCodec.encodeU128(amount), + ScaleCodec.encodeU128(xcmFee) ); } }