Skip to content

Commit ee1115c

Browse files
authored
evm: Add CCTP request (#2)
* evm: Add CCTP request * Update readme files
1 parent ba4414b commit ee1115c

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

.cspell/custom-dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Custom Dictionary Words
22
Aptos
3+
CCTP
34
Devnet
45
hashv
56
idls

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ uint32 payloadLen // Length of the payload
205205
bytes payload // The full payload, the keccak of which was sent to `endpoint.sendMessage`
206206
```
207207

208+
##### NTT v1 Request
209+
210+
```solidity
211+
bytes4 prefix = "ERN1" // 4-byte prefix for this struct
212+
uint16 srcChain
213+
bytes32 srcManager
214+
bytes32 messageId
215+
```
216+
217+
##### CCTP v1 Request
218+
219+
```solidity
220+
bytes4 prefix = "ERC1" // 4-byte prefix for this struct
221+
uint32 sourceDomain
222+
uint64 nonce
223+
```
224+
208225
#### Relay Instructions
209226

210227
##### Gas Instruction

evm/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,54 @@ executor.requestExecution{value: executionAmount}(
4646

4747
<!-- cspell:enable -->
4848

49+
#### Example v1 NTT Request
50+
51+
<!-- cspell:disable -->
52+
53+
```solidity
54+
import "example-messaging-executor/evm/src/interfaces/IExecutor.sol";
55+
import "example-messaging-executor/evm/src/libraries/ExecutorMessages.sol";
56+
...
57+
uint64 msgId = nttm.transfer{value: msg.value - executorArgs.value}(
58+
amount, recipientChain, recipientAddress, refundAddress, shouldQueue, encodedInstructions
59+
);
60+
61+
executor.requestExecution{value: executorArgs.value}(
62+
recipientChain,
63+
nttm.getPeer(recipientChain).peerAddress,
64+
executorArgs.refundAddress,
65+
executorArgs.signedQuote,
66+
ExecutorMessages.makeNTTv1Request(
67+
chainId, bytes32(uint256(uint160(address(nttm)))), bytes32(uint256(msgId))
68+
),
69+
executorArgs.instructions
70+
);
71+
```
72+
73+
<!-- cspell:enable -->
74+
75+
#### Example v1 CCTP Request
76+
77+
<!-- cspell:disable -->
78+
79+
```solidity
80+
import "example-messaging-executor/evm/src/interfaces/IExecutor.sol";
81+
import "example-messaging-executor/evm/src/libraries/ExecutorMessages.sol";
82+
...
83+
uint64 nonce = circleTokenMessenger.depositForBurn(amount, destinationDomain, mintRecipient, burnToken);
84+
85+
executor.requestExecution{value: executorArgs.value}(
86+
0,
87+
bytes32(0),
88+
executorArgs.refundAddress,
89+
executorArgs.signedQuote,
90+
ExecutorMessages.makeCCTPv1Request(sourceDomain, nonce),
91+
executorArgs.instructions
92+
);
93+
```
94+
95+
<!-- cspell:enable -->
96+
4997
### Execution Support
5098

5199
#### v1 VAA Execution
@@ -56,6 +104,22 @@ Your contract must implement the following function.
56104
function receiveMessage(bytes calldata encodedTransferMessage) public payable
57105
```
58106

107+
#### v1 NTT Execution
108+
109+
The NTT Transceiver contract implements the following function.
110+
111+
```solidity
112+
function receiveMessage(bytes memory encodedMessage) external
113+
```
114+
115+
#### v1 CCTP Execution
116+
117+
The Circle Message Transmitter contract implements the following function.
118+
119+
```solidity
120+
function receiveMessage(bytes calldata message,bytes calldata attestation) external override whenNotPaused returns (bool success)
121+
```
122+
59123
## Executor Development
60124

61125
### Testing

evm/src/libraries/ExecutorMessages.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ library ExecutorMessages {
55
bytes4 private constant REQ_MM = "ERM1";
66
bytes4 private constant REQ_VAA_V1 = "ERV1";
77
bytes4 private constant REQ_NTT_V1 = "ERN1";
8+
bytes4 private constant REQ_CCTP_V1 = "ERC1";
89

910
/// @notice Payload length will not fit in a uint32.
1011
/// @dev Selector: 492f620d.
@@ -54,4 +55,12 @@ library ExecutorMessages {
5455
{
5556
return abi.encodePacked(REQ_NTT_V1, srcChain, srcManager, messageId);
5657
}
58+
59+
/// @notice Encodes a version 1 CCTP request payload.
60+
/// @param sourceDomain The source chain for the CCTP transfer.
61+
/// @param nonce The nonce of the CCTP transfer.
62+
/// @return bytes The encoded request.
63+
function makeCCTPv1Request(uint32 sourceDomain, uint64 nonce) internal pure returns (bytes memory) {
64+
return abi.encodePacked(REQ_CCTP_V1, sourceDomain, nonce);
65+
}
5766
}

evm/test/ExecutorMessages.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ contract ExecutorMessagesTest is Test {
3838
bytes memory buf = ExecutorMessages.makeNTTv1Request(srcChain, srcManager, messageId);
3939
assertEq(keccak256(expected), keccak256(buf));
4040
}
41+
42+
function test_makeCCTPv1Request() public pure {
43+
uint32 srcDomain = 7;
44+
uint64 nonce = 42;
45+
bytes memory expected = abi.encodePacked("ERC1", srcDomain, nonce);
46+
bytes memory buf = ExecutorMessages.makeCCTPv1Request(srcDomain, nonce);
47+
assertEq(keccak256(expected), keccak256(buf));
48+
}
4149
}

0 commit comments

Comments
 (0)