Skip to content

Commit

Permalink
Fix build payload for foreign token
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Aug 28, 2024
1 parent e1bd6c5 commit 57fa08c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
18 changes: 14 additions & 4 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
16 changes: 10 additions & 6 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -157,6 +157,7 @@ library SubstrateTypes {
ParaID paraID,
bytes32 recipient,
uint128 xcmFee,
uint128 destinationXcmFee,
uint128 amount
) internal view returns (bytes memory) {
return bytes.concat(
Expand All @@ -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)
);
}

Expand All @@ -178,6 +180,7 @@ library SubstrateTypes {
ParaID paraID,
bytes20 recipient,
uint128 xcmFee,
uint128 destinationXcmFee,
uint128 amount
) internal view returns (bytes memory) {
return bytes.concat(
Expand All @@ -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)
);
}
}

0 comments on commit 57fa08c

Please sign in to comment.