|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.19; |
| 3 | + |
| 4 | +// from https://github.com/wormholelabs-xyz/example-messaging-executor/blob/ec5daea3c03f8860a62c23e28db5c6dc8771a9ce/evm/src/libraries/ExecutorMessages.sol |
| 5 | +library ExecutorMessages { |
| 6 | + bytes4 private constant REQ_VAA_V1 = "ERV1"; |
| 7 | + bytes4 private constant REQ_NTT_V1 = "ERN1"; |
| 8 | + bytes4 private constant REQ_CCTP_V1 = "ERC1"; |
| 9 | + bytes4 private constant REQ_CCTP_V2 = "ERC2"; |
| 10 | + |
| 11 | + /// @notice Payload length will not fit in a uint32. |
| 12 | + /// @dev Selector: 492f620d. |
| 13 | + error PayloadTooLarge(); |
| 14 | + |
| 15 | + /// @notice Encodes a version 1 VAA request payload. |
| 16 | + /// @param emitterChain The emitter chain from the VAA. |
| 17 | + /// @param emitterAddress The emitter address from the VAA. |
| 18 | + /// @param sequence The sequence number from the VAA. |
| 19 | + /// @return bytes The encoded request. |
| 20 | + function makeVAAv1Request(uint16 emitterChain, bytes32 emitterAddress, uint64 sequence) |
| 21 | + internal |
| 22 | + pure |
| 23 | + returns (bytes memory) |
| 24 | + { |
| 25 | + return abi.encodePacked(REQ_VAA_V1, emitterChain, emitterAddress, sequence); |
| 26 | + } |
| 27 | + |
| 28 | + /// @notice Encodes a version 1 NTT request payload. |
| 29 | + /// @param srcChain The source chain for the NTT transfer. |
| 30 | + /// @param srcManager The source manager for the NTT transfer. |
| 31 | + /// @param messageId The manager message id for the NTT transfer. |
| 32 | + /// @return bytes The encoded request. |
| 33 | + function makeNTTv1Request(uint16 srcChain, bytes32 srcManager, bytes32 messageId) |
| 34 | + internal |
| 35 | + pure |
| 36 | + returns (bytes memory) |
| 37 | + { |
| 38 | + return abi.encodePacked(REQ_NTT_V1, srcChain, srcManager, messageId); |
| 39 | + } |
| 40 | + |
| 41 | + /// @notice Encodes a version 1 CCTP request payload. |
| 42 | + /// @param sourceDomain The source chain for the CCTP transfer. |
| 43 | + /// @param nonce The nonce of the CCTP transfer. |
| 44 | + /// @return bytes The encoded request. |
| 45 | + function makeCCTPv1Request(uint32 sourceDomain, uint64 nonce) internal pure returns (bytes memory) { |
| 46 | + return abi.encodePacked(REQ_CCTP_V1, sourceDomain, nonce); |
| 47 | + } |
| 48 | + |
| 49 | + /// @notice Encodes a version 2 CCTP request payload. |
| 50 | + /// This request currently assumes the Executor will auto detect the event off chain. |
| 51 | + /// That may change in the future, in which case this interface would change. |
| 52 | + /// @return bytes The encoded request. |
| 53 | + function makeCCTPv2Request() internal pure returns (bytes memory) { |
| 54 | + return abi.encodePacked(REQ_CCTP_V2, uint8(1)); |
| 55 | + } |
| 56 | +} |
0 commit comments