Skip to content

Commit

Permalink
Add encode functions (#70)
Browse files Browse the repository at this point in the history
* Add encode functions

* Rename file

---------

Co-authored-by: Andreas <[email protected]>
  • Loading branch information
AgusVelez5 and nonergodic authored Dec 11, 2024
1 parent 86b9f07 commit 7d58ee7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ struct DeliveryOverride {
bytes32 redeliveryHash;
}

function encode(DeliveryInstruction memory strct)
pure
returns (bytes memory encoded)
{
encoded = abi.encodePacked(
PAYLOAD_ID_DELIVERY_INSTRUCTION,
strct.targetChain,
strct.targetAddress,
encodeBytes(strct.payload),
strct.requestedReceiverValue,
strct.extraReceiverValue
);
encoded = abi.encodePacked(
encoded,
encodeBytes(strct.encodedExecutionInfo),
strct.refundChain,
strct.refundAddress,
strct.refundDeliveryProvider,
strct.sourceDeliveryProvider,
strct.senderAddress,
encodeMessageKeyArray(strct.messageKeys)
);
}

function decodeDeliveryInstruction(
bytes memory encoded
) pure returns (DeliveryInstruction memory strct) {
Expand All @@ -63,6 +87,22 @@ function decodeDeliveryInstruction(
encoded.checkLength(offset);
}

function encode(RedeliveryInstruction memory strct)
pure
returns (bytes memory encoded)
{
bytes memory vaaKey = abi.encodePacked(VAA_KEY_TYPE, encodeVaaKey(strct.deliveryVaaKey));
encoded = abi.encodePacked(
PAYLOAD_ID_REDELIVERY_INSTRUCTION,
vaaKey,
strct.targetChain,
strct.newRequestedReceiverValue,
encodeBytes(strct.newEncodedExecutionInfo),
strct.newSourceDeliveryProvider,
strct.newSenderAddress
);
}

function decodeRedeliveryInstruction(
bytes memory encoded
) pure returns (RedeliveryInstruction memory strct) {
Expand Down
2 changes: 1 addition & 1 deletion src/testing/WormholeRelayer/MockOffchainRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {CCTPMessageLib} from "wormhole-sdk/WormholeRelayer/CCTPBase.sol";
import {VM_ADDRESS} from "wormhole-sdk/testing/Constants.sol";
import "wormhole-sdk/testing/WormholeOverride.sol";
import "wormhole-sdk/testing/CctpOverride.sol";
import "wormhole-sdk/testing/WormholeRelayer/DeliveryInstructionDecoder.sol";
import "wormhole-sdk/testing/WormholeRelayer/DeliveryInstructionSerde.sol";
import "wormhole-sdk/testing/WormholeRelayer/ExecutionParameters.sol";

using BytesParsing for bytes;
Expand Down
2 changes: 1 addition & 1 deletion src/testing/WormholeRelayerTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "./UsdcDealer.sol";
import "./WormholeOverride.sol";
import "./CctpOverride.sol";
import "./ERC20Mock.sol";
import "./WormholeRelayer/DeliveryInstructionDecoder.sol";
import "./WormholeRelayer/DeliveryInstructionSerde.sol";
import "./WormholeRelayer/ExecutionParameters.sol";
import "./WormholeRelayer/MockOffchainRelayer.sol";

Expand Down

0 comments on commit 7d58ee7

Please sign in to comment.