Skip to content

Commit 949edc3

Browse files
committed
rs: sdk
1 parent aeba2df commit 949edc3

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

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"

svm/modules/executor-requests/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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 = "2024"
5+
6+
[dependencies]
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
pub fn make_vaa_v1_request(chain: u16, address: [u8; 32], sequence: u64) -> Vec<u8> {
7+
let mut out = Vec::with_capacity({
8+
4 // type
9+
+ 2 // chain
10+
+ 32 // address
11+
+ 8 // sequence
12+
});
13+
out.extend_from_slice(REQ_VAA_V1);
14+
out.extend_from_slice(&chain.to_be_bytes());
15+
out.extend_from_slice(&address);
16+
out.extend_from_slice(&sequence.to_be_bytes());
17+
out
18+
}
19+
20+
pub fn make_ntt_v1_request(
21+
source_chain: u16,
22+
source_manager: [u8; 32],
23+
message_id: [u8; 32],
24+
) -> Vec<u8> {
25+
let mut out = Vec::with_capacity({
26+
4 // type
27+
+ 2 // source chain
28+
+ 32 // source_manager
29+
+ 32 // message_id
30+
});
31+
out.extend_from_slice(REQ_NTT_V1);
32+
out.extend_from_slice(&source_chain.to_be_bytes());
33+
out.extend_from_slice(&source_manager);
34+
out.extend_from_slice(&message_id);
35+
out
36+
}
37+
38+
pub fn make_cctp_v1_request(source_domain: u32, nonce: u64) -> Vec<u8> {
39+
let mut out = Vec::with_capacity({
40+
4 // type
41+
+ 4 // source domain
42+
+ 8 // nonce
43+
});
44+
out.extend_from_slice(REQ_CCTP_V1);
45+
out.extend_from_slice(&source_domain.to_be_bytes());
46+
out.extend_from_slice(&nonce.to_be_bytes());
47+
out
48+
}
49+
50+
pub fn make_cctp_v2_request() -> Vec<u8> {
51+
let mut out = Vec::with_capacity({
52+
4 // type
53+
});
54+
out.extend_from_slice(REQ_CCTP_V2);
55+
out
56+
}
57+
58+
#[cfg(test)]
59+
mod tests {
60+
use super::*;
61+
62+
#[test]
63+
fn test_vaa_v1() {
64+
let result = make_vaa_v1_request(
65+
10002,
66+
[
67+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6,
68+
0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57, 0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0,
69+
0xf5, 0xe3, 0x8c, 0x76,
70+
],
71+
29,
72+
);
73+
assert_eq!(
74+
result,
75+
[
76+
0x45, 0x52, 0x56, 0x31, 0x27, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77+
0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6, 0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57,
78+
0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0, 0xf5, 0xe3, 0x8c, 0x76, 0x00, 0x00, 0x00, 0x00,
79+
0x00, 0x00, 0x00, 0x1d
80+
]
81+
);
82+
}
83+
84+
#[test]
85+
fn test_ntt_v1() {
86+
let mut sequence: [u8; 32] = [0; 32];
87+
sequence[24..].copy_from_slice(&29_u64.to_be_bytes());
88+
let result = make_ntt_v1_request(
89+
10002,
90+
[
91+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6,
92+
0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57, 0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0,
93+
0xf5, 0xe3, 0x8c, 0x76,
94+
],
95+
sequence,
96+
);
97+
assert_eq!(
98+
result,
99+
[
100+
0x45, 0x52, 0x4E, 0x31, 0x27, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101+
0x00, 0x00, 0x00, 0x00, 0xd4, 0xa6, 0xa7, 0x2a, 0x02, 0x55, 0x99, 0xfd, 0x73, 0x57,
102+
0xc0, 0xf1, 0x57, 0xc7, 0x18, 0xd0, 0xf5, 0xe3, 0x8c, 0x76, 0x00, 0x00, 0x00, 0x00,
103+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d
105+
]
106+
);
107+
}
108+
109+
#[test]
110+
fn test_cctp_v1() {
111+
let result = make_cctp_v1_request(6, 6344);
112+
assert_eq!(
113+
result,
114+
[
115+
0x45, 0x52, 0x43, 0x31, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116+
0x18, 0xc8
117+
]
118+
);
119+
}
120+
121+
#[test]
122+
fn test_cctp_v2() {
123+
let result = make_cctp_v2_request();
124+
assert_eq!(result, [0x45, 0x52, 0x43, 0x32]);
125+
}
126+
}

0 commit comments

Comments
 (0)