@layerzerolabs/protocol-stellar-v2 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +273 -219
- package/.turbo/turbo-lint.log +79 -107
- package/.turbo/turbo-test.log +1016 -840
- package/Cargo.lock +14 -6
- package/contracts/common-macros/src/contract_impl.rs +6 -3
- package/contracts/common-macros/src/error.rs +9 -17
- package/contracts/common-macros/src/lib.rs +4 -37
- package/contracts/common-macros/src/ownable.rs +9 -5
- package/contracts/common-macros/src/tests/contract_impl.rs +178 -86
- package/contracts/common-macros/src/tests/error.rs +168 -0
- package/contracts/common-macros/src/tests/mod.rs +2 -4
- package/contracts/common-macros/src/tests/ownable.rs +37 -60
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +16 -6
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__error__snapshot_generated_contract_error_code.snap +20 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +3 -1
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap +12 -2
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +5 -1
- package/contracts/common-macros/src/tests/utils.rs +267 -0
- package/contracts/common-macros/src/ttl_configurable.rs +15 -12
- package/contracts/common-macros/src/utils.rs +35 -6
- package/contracts/endpoint-v2/src/endpoint_v2.rs +4 -4
- package/contracts/endpoint-v2/src/events.rs +40 -22
- package/contracts/endpoint-v2/src/interfaces/message_lib.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/send_lib.rs +2 -2
- package/contracts/endpoint-v2/src/message_lib_manager.rs +3 -3
- package/contracts/endpoint-v2/src/messaging_channel.rs +1 -1
- package/contracts/endpoint-v2/src/messaging_composer.rs +1 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +4 -8
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +3 -7
- package/contracts/message-libs/{block-message-lib → blocked-message-lib}/Cargo.toml +1 -1
- package/contracts/message-libs/treasury/src/events.rs +9 -6
- package/contracts/message-libs/uln-302/src/events.rs +19 -11
- package/contracts/message-libs/uln-302/src/interfaces/receive_uln.rs +2 -2
- package/contracts/message-libs/uln-302/src/interfaces/send_uln.rs +2 -2
- package/contracts/message-libs/uln-302/src/receive_uln.rs +2 -2
- package/contracts/message-libs/uln-302/src/send_uln.rs +3 -3
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +5 -5
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +5 -5
- package/contracts/message-libs/uln-302/src/tests/setup.rs +3 -3
- package/contracts/message-libs/uln-302/src/types.rs +24 -24
- package/contracts/message-libs/uln-302/src/uln302.rs +2 -2
- package/contracts/oapp-macros/src/oapp_core.rs +1 -1
- package/contracts/oapps/counter/integration_tests/utils.rs +1 -1
- package/contracts/oapps/oapp/src/oapp_core.rs +4 -3
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +4 -3
- package/contracts/oapps/oft/integration-tests/setup.rs +4 -3
- package/contracts/oapps/oft/integration-tests/utils.rs +1 -1
- package/contracts/oapps/oft/src/default_oft_impl.rs +146 -0
- package/contracts/oapps/oft/src/events.rs +5 -4
- package/contracts/oapps/oft/src/extensions/mod.rs +3 -0
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +168 -0
- package/contracts/oapps/oft/src/extensions/pausable.rs +50 -0
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +200 -0
- package/contracts/oapps/oft/src/lib.rs +2 -3
- package/contracts/oapps/oft/src/oft.rs +16 -85
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -1
- package/contracts/oapps/oft/src/tests/extensions/mod.rs +11 -0
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +888 -0
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +749 -0
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +432 -0
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +1078 -0
- package/contracts/oapps/oft/src/tests/mod.rs +2 -0
- package/contracts/oapps/oft/src/tests/test_utils.rs +24 -6
- package/contracts/oapps/{oft-mint-burn → oft-std}/Cargo.toml +1 -8
- package/contracts/oapps/oft-std/src/lib.rs +5 -0
- package/contracts/oapps/oft-std/src/oft.rs +59 -0
- package/contracts/utils/src/ownable.rs +8 -6
- package/contracts/utils/src/tests/ownable.rs +0 -63
- package/contracts/utils/src/tests/testing_utils.rs +7 -5
- package/contracts/utils/src/ttl.rs +21 -2
- package/contracts/workers/dvn/src/auth.rs +108 -30
- package/contracts/workers/dvn/src/dvn.rs +103 -33
- package/contracts/workers/dvn/src/errors.rs +10 -13
- package/contracts/workers/dvn/src/events.rs +7 -5
- package/contracts/workers/dvn/src/interfaces/dvn.rs +76 -3
- package/contracts/workers/dvn/src/interfaces/multisig.rs +41 -0
- package/contracts/workers/dvn/src/lib.rs +6 -8
- package/contracts/workers/dvn/src/multisig.rs +98 -72
- package/contracts/workers/dvn/src/storage.rs +9 -12
- package/contracts/workers/dvn/src/tests/auth.rs +56 -26
- package/contracts/workers/dvn/src/tests/dvn.rs +40 -41
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +8 -8
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +9 -9
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +6 -6
- package/contracts/workers/dvn/src/tests/setup.rs +5 -5
- package/contracts/workers/dvn-fee-lib/Cargo.toml +2 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +4 -3
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +8 -6
- package/contracts/workers/executor/src/auth.rs +93 -0
- package/contracts/workers/executor/src/events.rs +5 -4
- package/contracts/workers/executor/src/{lz_executor.rs → executor.rs} +30 -103
- package/contracts/workers/executor/src/interfaces/executor.rs +5 -2
- package/contracts/workers/executor/src/interfaces/mod.rs +1 -1
- package/contracts/workers/executor/src/lib.rs +6 -5
- package/contracts/workers/price-feed/Cargo.toml +21 -0
- package/contracts/workers/price-feed/src/errors.rs +9 -0
- package/contracts/workers/price-feed/src/events.rs +30 -0
- package/contracts/workers/price-feed/src/lib.rs +11 -0
- package/contracts/workers/price-feed/src/price_feed.rs +265 -0
- package/contracts/workers/price-feed/src/storage.rs +42 -0
- package/contracts/workers/price-feed/src/types.rs +59 -0
- package/contracts/workers/worker/src/events.rs +23 -13
- package/contracts/workers/worker/src/interfaces/dvn_fee_lib.rs +2 -1
- package/contracts/workers/worker/src/worker.rs +32 -21
- package/package.json +3 -3
- package/sdk/dist/generated/bml.js +24 -22
- package/sdk/dist/generated/counter.d.ts +102 -0
- package/sdk/dist/generated/counter.js +36 -24
- package/sdk/dist/generated/endpoint.js +24 -22
- package/sdk/dist/generated/sml.js +24 -22
- package/sdk/dist/generated/uln302.d.ts +1 -1
- package/sdk/dist/generated/uln302.js +34 -32
- package/sdk/package.json +1 -1
- package/sdk/test/index.test.ts +1 -1
- package/sdk/test/oft.test.ts +847 -0
- package/sdk/test/suites/scan.ts +20 -4
- package/tools/ts-bindings-gen/src/main.rs +2 -1
- package/contracts/common-macros/src/event.rs +0 -16
- package/contracts/oapps/oft/src/macro_tests/mod.rs +0 -2
- package/contracts/oapps/oft/src/macro_tests/test_all_default.rs +0 -41
- package/contracts/oapps/oft/src/macro_tests/test_override.rs +0 -83
- package/contracts/oapps/oft-mint-burn/src/lib.rs +0 -3
- package/contracts/oapps/oft-mint-burn/src/oft.rs +0 -28
- package/contracts/oapps/oft-mint-burn/src/tests/mod.rs +0 -1
- package/contracts/workers/dvn/src/types.rs +0 -26
- /package/contracts/message-libs/{block-message-lib → blocked-message-lib}/src/lib.rs +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
use quote::quote;
|
|
2
|
+
use syn::{parse_quote, punctuated::Punctuated, token::Comma, FnArg};
|
|
3
|
+
|
|
4
|
+
use crate::tests::test_helpers::assert_panics_contains;
|
|
5
|
+
|
|
6
|
+
// ============================================
|
|
7
|
+
// find_env_param Tests
|
|
8
|
+
// ============================================
|
|
9
|
+
|
|
10
|
+
fn parse_fn_args(input: proc_macro2::TokenStream) -> Punctuated<FnArg, Comma> {
|
|
11
|
+
let item_fn: syn::ItemFn = syn::parse2(input).expect("failed to parse function");
|
|
12
|
+
item_fn.sig.inputs
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn test_find_env_param_owned_env_is_not_reference() {
|
|
17
|
+
let args = parse_fn_args(quote! { fn f(env: Env) {} });
|
|
18
|
+
let param = crate::utils::find_env_param(&args);
|
|
19
|
+
assert!(param.is_some());
|
|
20
|
+
let param = param.unwrap();
|
|
21
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
22
|
+
assert!(!param.is_reference, "Env should not be marked as reference");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[test]
|
|
26
|
+
fn test_find_env_param_ref_env_is_reference() {
|
|
27
|
+
let args = parse_fn_args(quote! { fn f(env: &Env) {} });
|
|
28
|
+
let param = crate::utils::find_env_param(&args);
|
|
29
|
+
assert!(param.is_some());
|
|
30
|
+
let param = param.unwrap();
|
|
31
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
32
|
+
assert!(param.is_reference, "&Env should be marked as reference");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[test]
|
|
36
|
+
fn test_find_env_param_mut_ref_env_is_reference() {
|
|
37
|
+
let args = parse_fn_args(quote! { fn f(env: &mut Env) {} });
|
|
38
|
+
let param = crate::utils::find_env_param(&args);
|
|
39
|
+
assert!(param.is_some());
|
|
40
|
+
let param = param.unwrap();
|
|
41
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
42
|
+
assert!(param.is_reference, "&mut Env should be marked as reference");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[test]
|
|
46
|
+
fn test_find_env_param_qualified_owned_env() {
|
|
47
|
+
let args = parse_fn_args(quote! { fn f(my_env: soroban_sdk::Env) {} });
|
|
48
|
+
let param = crate::utils::find_env_param(&args);
|
|
49
|
+
assert!(param.is_some());
|
|
50
|
+
let param = param.unwrap();
|
|
51
|
+
assert_eq!(param.ident.to_string(), "my_env");
|
|
52
|
+
assert!(!param.is_reference, "soroban_sdk::Env should not be marked as reference");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[test]
|
|
56
|
+
fn test_find_env_param_qualified_ref_env() {
|
|
57
|
+
let args = parse_fn_args(quote! { fn f(my_env: &soroban_sdk::Env) {} });
|
|
58
|
+
let param = crate::utils::find_env_param(&args);
|
|
59
|
+
assert!(param.is_some());
|
|
60
|
+
let param = param.unwrap();
|
|
61
|
+
assert_eq!(param.ident.to_string(), "my_env");
|
|
62
|
+
assert!(param.is_reference, "&soroban_sdk::Env should be marked as reference");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[test]
|
|
66
|
+
fn test_find_env_param_returns_none_for_no_env() {
|
|
67
|
+
let args = parse_fn_args(quote! { fn f(x: u32) {} });
|
|
68
|
+
let param = crate::utils::find_env_param(&args);
|
|
69
|
+
assert!(param.is_none());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[test]
|
|
73
|
+
fn test_find_env_param_finds_deeply_nested_env() {
|
|
74
|
+
let args = parse_fn_args(quote! { fn f(e: some::deep::module::Env) {} });
|
|
75
|
+
let param = crate::utils::find_env_param(&args);
|
|
76
|
+
assert!(param.is_some());
|
|
77
|
+
let param = param.unwrap();
|
|
78
|
+
assert_eq!(param.ident.to_string(), "e");
|
|
79
|
+
assert!(!param.is_reference, "some::deep::module::Env should not be marked as reference");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[test]
|
|
83
|
+
fn test_find_env_param_finds_env_not_first_param() {
|
|
84
|
+
let args = parse_fn_args(quote! { fn f(x: u32, y: String, env: &Env) {} });
|
|
85
|
+
let param = crate::utils::find_env_param(&args);
|
|
86
|
+
assert!(param.is_some());
|
|
87
|
+
let param = param.unwrap();
|
|
88
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
89
|
+
assert!(param.is_reference, "&Env should be marked as reference");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[test]
|
|
93
|
+
fn test_find_env_param_returns_first_env_when_multiple() {
|
|
94
|
+
let args = parse_fn_args(quote! { fn f(first_env: Env, second_env: Env) {} });
|
|
95
|
+
let param = crate::utils::find_env_param(&args);
|
|
96
|
+
assert!(param.is_some());
|
|
97
|
+
let param = param.unwrap();
|
|
98
|
+
assert_eq!(param.ident.to_string(), "first_env");
|
|
99
|
+
assert!(!param.is_reference, "first_env should not be marked as reference");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[test]
|
|
103
|
+
fn test_find_env_param_returns_none_for_empty_args() {
|
|
104
|
+
let args = parse_fn_args(quote! { fn f() {} });
|
|
105
|
+
let param = crate::utils::find_env_param(&args);
|
|
106
|
+
assert!(param.is_none());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#[test]
|
|
110
|
+
fn test_find_env_param_returns_none_for_wildcard_pattern() {
|
|
111
|
+
// Wildcard pattern _ is not a valid identifier pattern
|
|
112
|
+
let args = parse_fn_args(quote! { fn f(_: Env) {} });
|
|
113
|
+
let param = crate::utils::find_env_param(&args);
|
|
114
|
+
assert!(param.is_none());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[test]
|
|
118
|
+
fn test_find_env_param_returns_none_for_tuple_pattern() {
|
|
119
|
+
// Tuple destructuring is not a simple identifier pattern
|
|
120
|
+
let args = parse_fn_args(quote! { fn f((env, _): (Env, u32)) {} });
|
|
121
|
+
let param = crate::utils::find_env_param(&args);
|
|
122
|
+
assert!(param.is_none());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#[test]
|
|
126
|
+
fn test_find_env_param_ignores_self_receiver() {
|
|
127
|
+
// Method with self receiver - find_env_param should skip receiver and find env
|
|
128
|
+
let args: Punctuated<FnArg, Comma> = parse_quote!(&self, env: &Env);
|
|
129
|
+
let param = crate::utils::find_env_param(&args);
|
|
130
|
+
assert!(param.is_some());
|
|
131
|
+
let param = param.unwrap();
|
|
132
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
133
|
+
assert!(param.is_reference, "&Env should be marked as reference");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[test]
|
|
137
|
+
fn test_find_env_param_returns_none_for_self_only() {
|
|
138
|
+
// Method with only self receiver
|
|
139
|
+
let args: Punctuated<FnArg, Comma> = parse_quote!(&self);
|
|
140
|
+
let param = crate::utils::find_env_param(&args);
|
|
141
|
+
assert!(param.is_none());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#[test]
|
|
145
|
+
fn test_find_env_param_with_double_reference() {
|
|
146
|
+
let args = parse_fn_args(quote! { fn f(env: &&Env) {} });
|
|
147
|
+
let param = crate::utils::find_env_param(&args);
|
|
148
|
+
assert!(param.is_some());
|
|
149
|
+
let param = param.unwrap();
|
|
150
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
151
|
+
assert!(param.is_reference, "&&Env should be marked as reference");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ============================================
|
|
155
|
+
// expect_env_param Tests
|
|
156
|
+
// ============================================
|
|
157
|
+
|
|
158
|
+
#[test]
|
|
159
|
+
fn test_expect_env_param_returns_param_for_owned_env() {
|
|
160
|
+
let args = parse_fn_args(quote! { fn f(env: Env) {} });
|
|
161
|
+
let param = crate::utils::expect_env_param(&args);
|
|
162
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
163
|
+
assert!(!param.is_reference);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#[test]
|
|
167
|
+
fn test_expect_env_param_returns_param_for_ref_env() {
|
|
168
|
+
let args = parse_fn_args(quote! { fn f(env: &Env) {} });
|
|
169
|
+
let param = crate::utils::expect_env_param(&args);
|
|
170
|
+
assert_eq!(param.ident.to_string(), "env");
|
|
171
|
+
assert!(param.is_reference);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#[test]
|
|
175
|
+
fn test_expect_env_param_panics_when_no_env() {
|
|
176
|
+
assert_panics_contains("no Env param", "function must have an Env argument", || {
|
|
177
|
+
let args = parse_fn_args(quote! { fn f(x: u32) {} });
|
|
178
|
+
crate::utils::expect_env_param(&args);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ============================================
|
|
183
|
+
// EnvParam::as_ref_tokens Tests
|
|
184
|
+
// ============================================
|
|
185
|
+
|
|
186
|
+
#[test]
|
|
187
|
+
fn test_as_ref_tokens_for_owned_env_adds_ampersand() {
|
|
188
|
+
let args = parse_fn_args(quote! { fn f(env: Env) {} });
|
|
189
|
+
let param = crate::utils::find_env_param(&args).unwrap();
|
|
190
|
+
let tokens = param.as_ref_tokens();
|
|
191
|
+
// For owned Env, as_ref_tokens should produce `&env`
|
|
192
|
+
assert_eq!(tokens.to_string(), "& env");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#[test]
|
|
196
|
+
fn test_as_ref_tokens_for_ref_env_no_ampersand() {
|
|
197
|
+
let args = parse_fn_args(quote! { fn f(env: &Env) {} });
|
|
198
|
+
let param = crate::utils::find_env_param(&args).unwrap();
|
|
199
|
+
let tokens = param.as_ref_tokens();
|
|
200
|
+
// For reference Env, as_ref_tokens should produce `env` (no extra &)
|
|
201
|
+
assert_eq!(tokens.to_string(), "env");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
#[test]
|
|
205
|
+
fn test_as_ref_tokens_for_custom_named_owned_env() {
|
|
206
|
+
let args = parse_fn_args(quote! { fn f(my_environment: Env) {} });
|
|
207
|
+
let param = crate::utils::find_env_param(&args).unwrap();
|
|
208
|
+
let tokens = param.as_ref_tokens();
|
|
209
|
+
assert_eq!(tokens.to_string(), "& my_environment");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#[test]
|
|
213
|
+
fn test_as_ref_tokens_for_custom_named_ref_env() {
|
|
214
|
+
let args = parse_fn_args(quote! { fn f(my_environment: &Env) {} });
|
|
215
|
+
let param = crate::utils::find_env_param(&args).unwrap();
|
|
216
|
+
let tokens = param.as_ref_tokens();
|
|
217
|
+
assert_eq!(tokens.to_string(), "my_environment");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ============================================
|
|
221
|
+
// is_env_type Tests (comprehensive coverage)
|
|
222
|
+
// ============================================
|
|
223
|
+
|
|
224
|
+
#[test]
|
|
225
|
+
fn test_is_env_type_recognizes_env_types() {
|
|
226
|
+
let env_types = [
|
|
227
|
+
"Env",
|
|
228
|
+
"&Env",
|
|
229
|
+
"&&Env",
|
|
230
|
+
"&mut Env",
|
|
231
|
+
"soroban_sdk::Env",
|
|
232
|
+
"&soroban_sdk::Env",
|
|
233
|
+
"some::deeply::nested::module::Env",
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
for ty_str in env_types {
|
|
237
|
+
let ty = syn::parse_str::<syn::Type>(ty_str).expect("failed to parse type");
|
|
238
|
+
assert!(crate::utils::is_env_type(&ty), "{ty_str} should be recognized as an Env type");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
#[test]
|
|
243
|
+
fn test_is_env_type_rejects_non_env_types() {
|
|
244
|
+
let non_env_types = ["u32", "bool", "String", "Address", "&u32", "soroban_sdk::Address", "Environment"];
|
|
245
|
+
|
|
246
|
+
for ty_str in non_env_types {
|
|
247
|
+
let ty = syn::parse_str::<syn::Type>(ty_str).expect("failed to parse type");
|
|
248
|
+
assert!(!crate::utils::is_env_type(&ty), "{ty_str} should NOT be recognized as an Env type");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[test]
|
|
253
|
+
fn test_is_env_type_rejects_other_type_variants() {
|
|
254
|
+
let other_variants = [
|
|
255
|
+
("(Env, u32)", "tuple"),
|
|
256
|
+
("[Env; 1]", "array"),
|
|
257
|
+
("[Env]", "slice"),
|
|
258
|
+
("Option<Env>", "generic"),
|
|
259
|
+
("!", "never"),
|
|
260
|
+
("fn() -> Env", "fn pointer"),
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
for (ty_str, label) in other_variants {
|
|
264
|
+
let ty = syn::parse_str::<syn::Type>(ty_str).expect("failed to parse type");
|
|
265
|
+
assert!(!crate::utils::is_env_type(&ty), "{label} type {ty_str} should NOT be recognized as an Env type");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -19,8 +19,7 @@ pub fn generate_ttl_configurable_impl(input: TokenStream) -> TokenStream {
|
|
|
19
19
|
let expanded = quote! {
|
|
20
20
|
use utils::ttl::TtlConfigurable as _;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
#[soroban_sdk::contractimpl]
|
|
22
|
+
#[common_macros::contract_impl]
|
|
24
23
|
impl utils::ttl::TtlConfigurable for #name {
|
|
25
24
|
|
|
26
25
|
#[common_macros::only_owner]
|
|
@@ -53,17 +52,21 @@ pub fn generate_ttl_configurable_impl(input: TokenStream) -> TokenStream {
|
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
let inherent_impl = quote! {
|
|
55
|
+
/// Uses `soroban_sdk::contractimpl` directly instead of `common_macros::contract_impl`
|
|
56
|
+
/// because `contract_impl` automatically extends TTL on every invocation. Since this
|
|
57
|
+
/// impl block provides manual TTL extension control, auto-extension would be redundant
|
|
58
|
+
/// and could mask the intended behavior of `extend_instance_ttl`.
|
|
56
59
|
#[soroban_sdk::contractimpl]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
impl #name {
|
|
61
|
+
/// Extends the instance TTL.
|
|
62
|
+
///
|
|
63
|
+
/// # Arguments
|
|
64
|
+
///
|
|
65
|
+
/// * `threshold` - The threshold to extend the TTL.
|
|
66
|
+
/// * `extend_to` - The TTL to extend to.
|
|
67
|
+
pub fn extend_instance_ttl(env: &soroban_sdk::Env, threshold: u32, extend_to: u32) {
|
|
68
|
+
env.storage().instance().extend_ttl(threshold, extend_to);
|
|
69
|
+
}
|
|
67
70
|
}
|
|
68
71
|
};
|
|
69
72
|
|
|
@@ -1,20 +1,44 @@
|
|
|
1
|
+
use proc_macro2::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
1
3
|
use syn::{punctuated::Punctuated, token::Comma, FnArg, Ident, Pat, Type, TypePath};
|
|
2
4
|
|
|
3
|
-
///
|
|
4
|
-
pub
|
|
5
|
+
/// Information about an `Env` parameter in a function signature.
|
|
6
|
+
pub struct EnvParam<'a> {
|
|
7
|
+
/// The identifier of the Env parameter
|
|
8
|
+
pub ident: &'a Ident,
|
|
9
|
+
/// Whether the parameter is a reference type (`&Env` or `&mut Env`)
|
|
10
|
+
pub is_reference: bool,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
impl EnvParam<'_> {
|
|
14
|
+
/// Returns a token stream that produces a `&Env` reference.
|
|
15
|
+
/// - If the parameter is already a reference (`&Env`), returns the ident as-is
|
|
16
|
+
/// - If the parameter is owned (`Env`), returns `&ident`
|
|
17
|
+
pub fn as_ref_tokens(&self) -> TokenStream {
|
|
18
|
+
let ident = self.ident;
|
|
19
|
+
if self.is_reference {
|
|
20
|
+
quote!(#ident)
|
|
21
|
+
} else {
|
|
22
|
+
quote!(&#ident)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Finds the `Env` argument in a function signature and returns its info.
|
|
28
|
+
pub fn find_env_param(args: &Punctuated<FnArg, Comma>) -> Option<EnvParam<'_>> {
|
|
5
29
|
args.iter().find_map(|arg| {
|
|
6
30
|
let FnArg::Typed(pat_type) = arg else { return None };
|
|
7
31
|
if !is_env_type(&pat_type.ty) {
|
|
8
32
|
return None;
|
|
9
33
|
}
|
|
10
34
|
let Pat::Ident(pat) = pat_type.pat.as_ref() else { return None };
|
|
11
|
-
Some(&pat.ident)
|
|
35
|
+
Some(EnvParam { ident: &pat.ident, is_reference: is_reference_type(&pat_type.ty) })
|
|
12
36
|
})
|
|
13
37
|
}
|
|
14
38
|
|
|
15
|
-
/// Expects the `Env` argument
|
|
16
|
-
pub fn
|
|
17
|
-
|
|
39
|
+
/// Expects the `Env` argument in a function signature and returns its info.
|
|
40
|
+
pub fn expect_env_param(args: &Punctuated<FnArg, Comma>) -> EnvParam<'_> {
|
|
41
|
+
find_env_param(args).expect("function must have an Env argument")
|
|
18
42
|
}
|
|
19
43
|
|
|
20
44
|
/// Checks if a type is an `Env` type.
|
|
@@ -25,3 +49,8 @@ pub fn is_env_type(ty: &Type) -> bool {
|
|
|
25
49
|
_ => false,
|
|
26
50
|
}
|
|
27
51
|
}
|
|
52
|
+
|
|
53
|
+
/// Checks if a type is a reference type.
|
|
54
|
+
fn is_reference_type(ty: &Type) -> bool {
|
|
55
|
+
matches!(ty, Type::Reference(_))
|
|
56
|
+
}
|
|
@@ -5,10 +5,10 @@ use crate::{
|
|
|
5
5
|
},
|
|
6
6
|
errors::EndpointError,
|
|
7
7
|
events::{
|
|
8
|
-
ComposeDelivered, ComposeSent, DefaultReceiveLibrarySet,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
ComposeDelivered, ComposeSent, DefaultReceiveLibTimeoutSet, DefaultReceiveLibrarySet, DefaultSendLibrarySet,
|
|
9
|
+
DelegateSet, InboundNonceSkipped, LibraryRegistered, LzComposeAlert, LzReceiveAlert, PacketBurnt,
|
|
10
|
+
PacketDelivered, PacketNilified, PacketSent, PacketVerified, ReceiveLibrarySet, ReceiveLibraryTimeoutSet,
|
|
11
|
+
SendLibrarySet, ZROSet,
|
|
12
12
|
},
|
|
13
13
|
interfaces::{ILayerZeroEndpointV2, IMessageLibManager, IMessagingChannel, MessagingFee, MessagingReceipt, Origin},
|
|
14
14
|
storage::EndpointStorage,
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
use crate::{Origin, Timeout};
|
|
2
|
-
use
|
|
3
|
-
use soroban_sdk::{Address, Bytes, BytesN};
|
|
2
|
+
use soroban_sdk::{contractevent, Address, Bytes, BytesN};
|
|
4
3
|
|
|
5
4
|
// ============================================================================
|
|
6
5
|
// EndpointV2 Events
|
|
7
6
|
// ============================================================================
|
|
8
7
|
|
|
9
|
-
#[
|
|
8
|
+
#[contractevent]
|
|
9
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
10
10
|
pub struct PacketSent {
|
|
11
11
|
pub encoded_packet: Bytes,
|
|
12
12
|
pub options: Bytes,
|
|
13
13
|
pub send_library: Address,
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
#[
|
|
16
|
+
#[contractevent]
|
|
17
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
17
18
|
pub struct PacketVerified {
|
|
18
19
|
#[topic]
|
|
19
20
|
pub origin: Origin,
|
|
@@ -22,7 +23,8 @@ pub struct PacketVerified {
|
|
|
22
23
|
pub payload_hash: BytesN<32>,
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
#[
|
|
26
|
+
#[contractevent]
|
|
27
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
26
28
|
pub struct PacketDelivered {
|
|
27
29
|
#[topic]
|
|
28
30
|
pub origin: Origin,
|
|
@@ -30,7 +32,8 @@ pub struct PacketDelivered {
|
|
|
30
32
|
pub receiver: Address,
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
#[
|
|
35
|
+
#[contractevent]
|
|
36
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
34
37
|
pub struct LzReceiveAlert {
|
|
35
38
|
#[topic]
|
|
36
39
|
pub receiver: Address,
|
|
@@ -47,12 +50,14 @@ pub struct LzReceiveAlert {
|
|
|
47
50
|
pub reason: Bytes,
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
#[
|
|
53
|
+
#[contractevent]
|
|
54
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
51
55
|
pub struct ZROSet {
|
|
52
56
|
pub zro: Address,
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
#[
|
|
59
|
+
#[contractevent]
|
|
60
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
56
61
|
pub struct DelegateSet {
|
|
57
62
|
#[topic]
|
|
58
63
|
pub oapp: Address,
|
|
@@ -63,7 +68,8 @@ pub struct DelegateSet {
|
|
|
63
68
|
// Messaging Channel Events
|
|
64
69
|
// ============================================================================
|
|
65
70
|
|
|
66
|
-
#[
|
|
71
|
+
#[contractevent]
|
|
72
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
67
73
|
pub struct InboundNonceSkipped {
|
|
68
74
|
#[topic]
|
|
69
75
|
pub src_eid: u32,
|
|
@@ -75,7 +81,8 @@ pub struct InboundNonceSkipped {
|
|
|
75
81
|
pub nonce: u64,
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
#[
|
|
84
|
+
#[contractevent]
|
|
85
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
79
86
|
pub struct PacketNilified {
|
|
80
87
|
#[topic]
|
|
81
88
|
pub src_eid: u32,
|
|
@@ -88,7 +95,8 @@ pub struct PacketNilified {
|
|
|
88
95
|
pub payload_hash: Option<BytesN<32>>,
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
#[
|
|
98
|
+
#[contractevent]
|
|
99
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
92
100
|
pub struct PacketBurnt {
|
|
93
101
|
#[topic]
|
|
94
102
|
pub src_eid: u32,
|
|
@@ -105,33 +113,38 @@ pub struct PacketBurnt {
|
|
|
105
113
|
// Message Lib Manager Events
|
|
106
114
|
// ============================================================================
|
|
107
115
|
|
|
108
|
-
#[
|
|
116
|
+
#[contractevent]
|
|
117
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
109
118
|
pub struct LibraryRegistered {
|
|
110
119
|
pub new_lib: Address,
|
|
111
120
|
}
|
|
112
121
|
|
|
113
|
-
#[
|
|
122
|
+
#[contractevent]
|
|
123
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
114
124
|
pub struct DefaultSendLibrarySet {
|
|
115
125
|
#[topic]
|
|
116
126
|
pub dst_eid: u32,
|
|
117
127
|
pub new_lib: Address,
|
|
118
128
|
}
|
|
119
129
|
|
|
120
|
-
#[
|
|
130
|
+
#[contractevent]
|
|
131
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
121
132
|
pub struct DefaultReceiveLibrarySet {
|
|
122
133
|
#[topic]
|
|
123
134
|
pub src_eid: u32,
|
|
124
135
|
pub new_lib: Address,
|
|
125
136
|
}
|
|
126
137
|
|
|
127
|
-
#[
|
|
128
|
-
|
|
138
|
+
#[contractevent]
|
|
139
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
140
|
+
pub struct DefaultReceiveLibTimeoutSet {
|
|
129
141
|
#[topic]
|
|
130
142
|
pub src_eid: u32,
|
|
131
143
|
pub timeout: Option<Timeout>,
|
|
132
144
|
}
|
|
133
145
|
|
|
134
|
-
#[
|
|
146
|
+
#[contractevent]
|
|
147
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
135
148
|
pub struct SendLibrarySet {
|
|
136
149
|
#[topic]
|
|
137
150
|
pub sender: Address,
|
|
@@ -140,7 +153,8 @@ pub struct SendLibrarySet {
|
|
|
140
153
|
pub new_lib: Option<Address>,
|
|
141
154
|
}
|
|
142
155
|
|
|
143
|
-
#[
|
|
156
|
+
#[contractevent]
|
|
157
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
144
158
|
pub struct ReceiveLibrarySet {
|
|
145
159
|
#[topic]
|
|
146
160
|
pub receiver: Address,
|
|
@@ -149,7 +163,8 @@ pub struct ReceiveLibrarySet {
|
|
|
149
163
|
pub new_lib: Option<Address>,
|
|
150
164
|
}
|
|
151
165
|
|
|
152
|
-
#[
|
|
166
|
+
#[contractevent]
|
|
167
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
153
168
|
pub struct ReceiveLibraryTimeoutSet {
|
|
154
169
|
#[topic]
|
|
155
170
|
pub receiver: Address,
|
|
@@ -162,7 +177,8 @@ pub struct ReceiveLibraryTimeoutSet {
|
|
|
162
177
|
// Message Composer Events
|
|
163
178
|
// ============================================================================
|
|
164
179
|
|
|
165
|
-
#[
|
|
180
|
+
#[contractevent]
|
|
181
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
166
182
|
pub struct ComposeSent {
|
|
167
183
|
#[topic]
|
|
168
184
|
pub from: Address,
|
|
@@ -175,7 +191,8 @@ pub struct ComposeSent {
|
|
|
175
191
|
pub message: Bytes,
|
|
176
192
|
}
|
|
177
193
|
|
|
178
|
-
#[
|
|
194
|
+
#[contractevent]
|
|
195
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
179
196
|
pub struct ComposeDelivered {
|
|
180
197
|
#[topic]
|
|
181
198
|
pub from: Address,
|
|
@@ -187,7 +204,8 @@ pub struct ComposeDelivered {
|
|
|
187
204
|
pub index: u32,
|
|
188
205
|
}
|
|
189
206
|
|
|
190
|
-
#[
|
|
207
|
+
#[contractevent]
|
|
208
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
191
209
|
pub struct LzComposeAlert {
|
|
192
210
|
#[topic]
|
|
193
211
|
pub from: Address,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use crate::SetConfigParam;
|
|
2
|
-
use soroban_sdk::{
|
|
2
|
+
use soroban_sdk::{contractclient, contracttype, Address, Bytes, Env, Vec};
|
|
3
3
|
|
|
4
4
|
/// Type of message library indicating supported operations.
|
|
5
5
|
#[contracttype]
|
|
@@ -30,7 +30,7 @@ pub struct MessageLibVersion {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/// Interface for message libraries that handle cross-chain message verification and delivery.
|
|
33
|
-
#[
|
|
33
|
+
#[contractclient(name = "MessageLibClient")]
|
|
34
34
|
pub trait IMessageLib {
|
|
35
35
|
/// Sets the configuration for an OApp by the Endpoint.
|
|
36
36
|
///
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use soroban_sdk::{
|
|
1
|
+
use soroban_sdk::{contractclient, contracttype, Address, Bytes, Env, Vec};
|
|
2
2
|
|
|
3
3
|
/// Timeout configuration for receive library transitions.
|
|
4
4
|
#[contracttype]
|
|
@@ -45,7 +45,7 @@ pub struct ResolvedLibrary {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/// EndpointV2's Interface for managing message libraries.
|
|
48
|
-
#[
|
|
48
|
+
#[contractclient(name = "MessageLibManagerClient")]
|
|
49
49
|
pub trait IMessageLibManager {
|
|
50
50
|
/// Registers a new message library with the endpoint.
|
|
51
51
|
///
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
use soroban_sdk::{
|
|
1
|
+
use soroban_sdk::{contractclient, Address, BytesN, Env};
|
|
2
2
|
|
|
3
3
|
/// EndpointV2's Interface for managing messaging channels, nonces, and payload hashes.
|
|
4
|
-
#[
|
|
4
|
+
#[contractclient(name = "MessagingChannelClient")]
|
|
5
5
|
pub trait IMessagingChannel {
|
|
6
6
|
/// Skips the next expected inbound nonce without verifying.
|
|
7
7
|
///
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
use soroban_sdk::{
|
|
1
|
+
use soroban_sdk::{contractclient, Address, Bytes, BytesN, Env};
|
|
2
2
|
|
|
3
3
|
/// EndpointV2's Interface for managing composed messages between OApps and composers.
|
|
4
|
-
#[
|
|
4
|
+
#[contractclient(name = "MessagingComposerClient")]
|
|
5
5
|
pub trait IMessagingComposer {
|
|
6
6
|
/// Sends a composed message from an OApp to a composer.
|
|
7
7
|
/// The OApp can send compose to multiple composers with the same GUID.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use super::{IMessageLib, MessagingFee};
|
|
2
|
-
use soroban_sdk::{
|
|
2
|
+
use soroban_sdk::{contractclient, contracttype, Address, Bytes, BytesN, Env, Vec};
|
|
3
3
|
|
|
4
4
|
/// Outbound packet containing all information for cross-chain transmission.
|
|
5
5
|
#[contracttype]
|
|
@@ -44,7 +44,7 @@ pub struct FeesAndPacket {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/// Interface for send libraries that handle outbound message encoding and fee calculation.
|
|
47
|
-
#[
|
|
47
|
+
#[contractclient(name = "SendLibClient")]
|
|
48
48
|
pub trait ISendLib: IMessageLib {
|
|
49
49
|
/// Quotes the fee for sending a packet without actually sending.
|
|
50
50
|
///
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
use super::*;
|
|
2
2
|
|
|
3
|
-
#[contract_impl
|
|
3
|
+
#[contract_impl]
|
|
4
4
|
impl IMessageLibManager for EndpointV2 {
|
|
5
5
|
/// Registers a new message library with the endpoint.
|
|
6
6
|
#[only_owner]
|
|
@@ -56,7 +56,7 @@ impl IMessageLibManager for EndpointV2 {
|
|
|
56
56
|
None
|
|
57
57
|
};
|
|
58
58
|
EndpointStorage::set_or_remove_default_receive_library_timeout(env, src_eid, &timeout);
|
|
59
|
-
|
|
59
|
+
DefaultReceiveLibTimeoutSet { src_eid, timeout: timeout.clone() }.publish(env);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/// Sets or removes the default receive library timeout for a source endpoint.
|
|
@@ -70,7 +70,7 @@ impl IMessageLibManager for EndpointV2 {
|
|
|
70
70
|
assert_with_error!(env, !t.is_expired(env), EndpointError::InvalidExpiry);
|
|
71
71
|
}
|
|
72
72
|
EndpointStorage::set_or_remove_default_receive_library_timeout(env, src_eid, timeout);
|
|
73
|
-
|
|
73
|
+
DefaultReceiveLibTimeoutSet { src_eid, timeout: timeout.clone() }.publish(env);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// ============================================================================================
|