Skip to content

Commit cd67cb1

Browse files
committed
rs: sdk
1 parent aeba2df commit cd67cb1

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
lines changed

svm/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
2-
members = [
2+
members = [
3+
"modules/*",
34
"programs/*"
45
]
56
resolver = "2"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "executor-requests"
3+
version = "0.0.1"
4+
edition = "2021"
5+
6+
[dependencies]
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
const REQ_VAA_V1: &[u8; 4] = b"ERV1";
2+
const REQ_NTT_V1: &[u8; 4] = b"ERN1";
3+
const REQ_CCTP_V1: &[u8; 4] = b"ERC1";
4+
const REQ_CCTP_V2: &[u8; 4] = b"ERC2";
5+
6+
/// Encodes a version 1 VAA request payload.
7+
pub fn make_vaa_v1_request(chain: u16, address: [u8; 32], sequence: u64) -> Vec<u8> {
8+
let mut out = Vec::with_capacity({
9+
4 // type
10+
+ 2 // chain
11+
+ 32 // address
12+
+ 8 // sequence
13+
});
14+
out.extend_from_slice(REQ_VAA_V1);
15+
out.extend_from_slice(&chain.to_be_bytes());
16+
out.extend_from_slice(&address);
17+
out.extend_from_slice(&sequence.to_be_bytes());
18+
out
19+
}
20+
21+
/// Encodes a version 1 NTT request payload.
22+
pub fn make_ntt_v1_request(
23+
source_chain: u16,
24+
source_manager: [u8; 32],
25+
message_id: [u8; 32],
26+
) -> Vec<u8> {
27+
let mut out = Vec::with_capacity({
28+
4 // type
29+
+ 2 // source chain
30+
+ 32 // source_manager
31+
+ 32 // message_id
32+
});
33+
out.extend_from_slice(REQ_NTT_V1);
34+
out.extend_from_slice(&source_chain.to_be_bytes());
35+
out.extend_from_slice(&source_manager);
36+
out.extend_from_slice(&message_id);
37+
out
38+
}
39+
40+
/// Encodes a version 1 CCTP request payload.
41+
pub fn make_cctp_v1_request(source_domain: u32, nonce: u64) -> Vec<u8> {
42+
let mut out = Vec::with_capacity({
43+
4 // type
44+
+ 4 // source domain
45+
+ 8 // nonce
46+
});
47+
out.extend_from_slice(REQ_CCTP_V1);
48+
out.extend_from_slice(&source_domain.to_be_bytes());
49+
out.extend_from_slice(&nonce.to_be_bytes());
50+
out
51+
}
52+
53+
/// Encodes a version 2 CCTP request payload.
54+
/// This request currently assumes the Executor will auto detect the event off chain.
55+
/// That may change in the future, in which case this interface would change.
56+
pub fn make_cctp_v2_request() -> Vec<u8> {
57+
let mut out = Vec::with_capacity({
58+
4 // type
59+
+ 1 // discovery
60+
});
61+
out.extend_from_slice(REQ_CCTP_V2);
62+
out.extend_from_slice(&[1]); // auto discovery
63+
out
64+
}
65+
66+
#[cfg(test)]
67+
mod tests {
68+
use super::*;
69+
70+
#[test]
71+
fn test_vaa_v1() {
72+
let result = make_vaa_v1_request(
73+
10002,
74+
[
75+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6,
76+
0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57, 0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0,
77+
0xf5, 0xe3, 0x8c, 0x76,
78+
],
79+
29,
80+
);
81+
assert_eq!(
82+
result,
83+
[
84+
0x45, 0x52, 0x56, 0x31, 0x27, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85+
0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6, 0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57,
86+
0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0, 0xf5, 0xe3, 0x8c, 0x76, 0x00, 0x00, 0x00, 0x00,
87+
0x00, 0x00, 0x00, 0x1d
88+
]
89+
);
90+
}
91+
92+
#[test]
93+
fn test_ntt_v1() {
94+
let mut sequence: [u8; 32] = [0; 32];
95+
sequence[24..].copy_from_slice(&29_u64.to_be_bytes());
96+
let result = make_ntt_v1_request(
97+
10002,
98+
[
99+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6,
100+
0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57, 0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0,
101+
0xf5, 0xe3, 0x8c, 0x76,
102+
],
103+
sequence,
104+
);
105+
assert_eq!(
106+
result,
107+
[
108+
0x45, 0x52, 0x4E, 0x31, 0x27, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109+
0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6, 0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57,
110+
0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0, 0xf5, 0xe3, 0x8c, 0x76, 0x00, 0x00, 0x00, 0x00,
111+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d
113+
]
114+
);
115+
}
116+
117+
#[test]
118+
fn test_cctp_v1() {
119+
let result = make_cctp_v1_request(6, 6344);
120+
assert_eq!(
121+
result,
122+
[
123+
0x45, 0x52, 0x43, 0x31, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124+
0x18, 0xc8
125+
]
126+
);
127+
}
128+
129+
#[test]
130+
fn test_cctp_v2() {
131+
let result = make_cctp_v2_request();
132+
assert_eq!(result, [0x45, 0x52, 0x43, 0x32, 0x01]);
133+
}
134+
}

0 commit comments

Comments
 (0)