@layerzerolabs/protocol-stellar-v2 0.2.8

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.
Files changed (265) hide show
  1. package/.turbo/turbo-build.log +727 -0
  2. package/.turbo/turbo-lint.log +158 -0
  3. package/.turbo/turbo-test.log +796 -0
  4. package/Cargo.lock +2237 -0
  5. package/Cargo.toml +63 -0
  6. package/clippy.toml +7 -0
  7. package/contracts/common-macros/Cargo.toml +20 -0
  8. package/contracts/common-macros/src/error.rs +53 -0
  9. package/contracts/common-macros/src/event.rs +16 -0
  10. package/contracts/common-macros/src/lib.rs +255 -0
  11. package/contracts/common-macros/src/ownable.rs +63 -0
  12. package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +310 -0
  13. package/contracts/common-macros/src/storage.rs +439 -0
  14. package/contracts/common-macros/src/tests.rs +287 -0
  15. package/contracts/common-macros/src/ttl_configurable.rs +60 -0
  16. package/contracts/endpoint-v2/ARCHITECTURE.md +233 -0
  17. package/contracts/endpoint-v2/Cargo.toml +30 -0
  18. package/contracts/endpoint-v2/src/constants.rs +52 -0
  19. package/contracts/endpoint-v2/src/endpoint_v2.rs +305 -0
  20. package/contracts/endpoint-v2/src/errors.rs +29 -0
  21. package/contracts/endpoint-v2/src/events.rs +207 -0
  22. package/contracts/endpoint-v2/src/interfaces/layerzero_composer.rs +26 -0
  23. package/contracts/endpoint-v2/src/interfaces/layerzero_endpoint_v2.rs +170 -0
  24. package/contracts/endpoint-v2/src/interfaces/layerzero_receiver.rs +43 -0
  25. package/contracts/endpoint-v2/src/interfaces/message_lib.rs +62 -0
  26. package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +220 -0
  27. package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +121 -0
  28. package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +63 -0
  29. package/contracts/endpoint-v2/src/interfaces/mod.rs +17 -0
  30. package/contracts/endpoint-v2/src/interfaces/send_lib.rs +70 -0
  31. package/contracts/endpoint-v2/src/lib.rs +22 -0
  32. package/contracts/endpoint-v2/src/message_lib_manager.rs +315 -0
  33. package/contracts/endpoint-v2/src/messaging_channel.rs +218 -0
  34. package/contracts/endpoint-v2/src/messaging_composer.rs +76 -0
  35. package/contracts/endpoint-v2/src/storage.rs +78 -0
  36. package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +131 -0
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +237 -0
  38. package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +42 -0
  39. package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +76 -0
  40. package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +211 -0
  41. package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +18 -0
  42. package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +10 -0
  43. package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +10 -0
  44. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +424 -0
  45. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +144 -0
  46. package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +72 -0
  47. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +29 -0
  48. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +513 -0
  49. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +43 -0
  50. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +27 -0
  51. package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +30 -0
  52. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +202 -0
  53. package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +59 -0
  54. package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +172 -0
  55. package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +23 -0
  56. package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +10 -0
  57. package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +131 -0
  58. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +35 -0
  59. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +28 -0
  60. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +79 -0
  61. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +246 -0
  62. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +285 -0
  63. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +180 -0
  64. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +405 -0
  65. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +80 -0
  66. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +131 -0
  67. package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +358 -0
  68. package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +316 -0
  69. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +288 -0
  70. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +316 -0
  71. package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +388 -0
  72. package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +307 -0
  73. package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +10 -0
  74. package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +239 -0
  75. package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +324 -0
  76. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +242 -0
  77. package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +232 -0
  78. package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +212 -0
  79. package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +213 -0
  80. package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +269 -0
  81. package/contracts/endpoint-v2/src/tests/messaging_composer/mod.rs +4 -0
  82. package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +173 -0
  83. package/contracts/endpoint-v2/src/tests/mock.rs +132 -0
  84. package/contracts/endpoint-v2/src/tests/mod.rs +12 -0
  85. package/contracts/endpoint-v2/src/tests/util/build_payload.rs +126 -0
  86. package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +82 -0
  87. package/contracts/endpoint-v2/src/tests/util/keccak256.rs +115 -0
  88. package/contracts/endpoint-v2/src/tests/util/mod.rs +3 -0
  89. package/contracts/endpoint-v2/src/util.rs +52 -0
  90. package/contracts/message-libs/Cargo.toml +12 -0
  91. package/contracts/message-libs/block-message-lib/Cargo.toml +19 -0
  92. package/contracts/message-libs/block-message-lib/src/lib.rs +70 -0
  93. package/contracts/message-libs/lib.rs +2 -0
  94. package/contracts/message-libs/message-lib-common/Cargo.toml +24 -0
  95. package/contracts/message-libs/message-lib-common/src/errors.rs +20 -0
  96. package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +55 -0
  97. package/contracts/message-libs/message-lib-common/src/interfaces/executor.rs +46 -0
  98. package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +7 -0
  99. package/contracts/message-libs/message-lib-common/src/interfaces/treasury.rs +17 -0
  100. package/contracts/message-libs/message-lib-common/src/lib.rs +14 -0
  101. package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +99 -0
  102. package/contracts/message-libs/message-lib-common/src/testing_utils.rs +27 -0
  103. package/contracts/message-libs/message-lib-common/src/tests/mod.rs +2 -0
  104. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +162 -0
  105. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +319 -0
  106. package/contracts/message-libs/message-lib-common/src/worker_options.rs +190 -0
  107. package/contracts/message-libs/simple-message-lib/Cargo.toml +26 -0
  108. package/contracts/message-libs/simple-message-lib/src/errors.rs +11 -0
  109. package/contracts/message-libs/simple-message-lib/src/lib.rs +14 -0
  110. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +136 -0
  111. package/contracts/message-libs/simple-message-lib/src/storage.rs +27 -0
  112. package/contracts/message-libs/simple-message-lib/src/test.rs +280 -0
  113. package/contracts/message-libs/treasury/Cargo.toml +27 -0
  114. package/contracts/message-libs/treasury/src/errors.rs +10 -0
  115. package/contracts/message-libs/treasury/src/events.rs +28 -0
  116. package/contracts/message-libs/treasury/src/interfaces/mod.rs +3 -0
  117. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +20 -0
  118. package/contracts/message-libs/treasury/src/lib.rs +20 -0
  119. package/contracts/message-libs/treasury/src/storage.rs +18 -0
  120. package/contracts/message-libs/treasury/src/tests/mod.rs +2 -0
  121. package/contracts/message-libs/treasury/src/tests/setup.rs +112 -0
  122. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +562 -0
  123. package/contracts/message-libs/treasury/src/treasury.rs +140 -0
  124. package/contracts/message-libs/uln-302/Cargo.toml +28 -0
  125. package/contracts/message-libs/uln-302/src/config_validation.rs +173 -0
  126. package/contracts/message-libs/uln-302/src/errors.rs +29 -0
  127. package/contracts/message-libs/uln-302/src/events.rs +72 -0
  128. package/contracts/message-libs/uln-302/src/interfaces/mod.rs +5 -0
  129. package/contracts/message-libs/uln-302/src/interfaces/receive.rs +82 -0
  130. package/contracts/message-libs/uln-302/src/interfaces/send.rs +159 -0
  131. package/contracts/message-libs/uln-302/src/lib.rs +20 -0
  132. package/contracts/message-libs/uln-302/src/receive.rs +199 -0
  133. package/contracts/message-libs/uln-302/src/send.rs +349 -0
  134. package/contracts/message-libs/uln-302/src/storage.rs +47 -0
  135. package/contracts/message-libs/uln-302/src/tests/config/mod.rs +2 -0
  136. package/contracts/message-libs/uln-302/src/tests/config/oapp_uln_config.rs +291 -0
  137. package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +163 -0
  138. package/contracts/message-libs/uln-302/src/tests/mod.rs +7 -0
  139. package/contracts/message-libs/uln-302/src/tests/receive_uln302/commit_verification.rs +183 -0
  140. package/contracts/message-libs/uln-302/src/tests/receive_uln302/confirmations.rs +128 -0
  141. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +104 -0
  142. package/contracts/message-libs/uln-302/src/tests/receive_uln302/mod.rs +66 -0
  143. package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +79 -0
  144. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verifiable.rs +463 -0
  145. package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +173 -0
  146. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +132 -0
  147. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +117 -0
  148. package/contracts/message-libs/uln-302/src/tests/send_uln302/mod.rs +6 -0
  149. package/contracts/message-libs/uln-302/src/tests/send_uln302/quote.rs +586 -0
  150. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +834 -0
  151. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +95 -0
  152. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +80 -0
  153. package/contracts/message-libs/uln-302/src/tests/setup.rs +268 -0
  154. package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +47 -0
  155. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +51 -0
  156. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +51 -0
  157. package/contracts/message-libs/uln-302/src/tests/uln302/get_oapp_executor_config.rs +48 -0
  158. package/contracts/message-libs/uln-302/src/tests/uln302/mod.rs +4 -0
  159. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +998 -0
  160. package/contracts/message-libs/uln-302/src/uln302.rs +117 -0
  161. package/contracts/oapp-macros/Cargo.toml +21 -0
  162. package/contracts/oapp-macros/src/lib.rs +408 -0
  163. package/contracts/oapp-macros/src/oapp_core.rs +49 -0
  164. package/contracts/oapp-macros/src/oapp_full.rs +15 -0
  165. package/contracts/oapp-macros/src/oapp_options_type3.rs +46 -0
  166. package/contracts/oapp-macros/src/oapp_receiver.rs +67 -0
  167. package/contracts/oapp-macros/src/oapp_sender.rs +23 -0
  168. package/contracts/oapp-macros/src/util.rs +103 -0
  169. package/contracts/oapp-macros/tests/test_macros.rs +522 -0
  170. package/contracts/oapps/Cargo.toml +12 -0
  171. package/contracts/oapps/counter/Cargo.toml +24 -0
  172. package/contracts/oapps/counter/integration_tests/mod.rs +3 -0
  173. package/contracts/oapps/counter/integration_tests/setup.rs +201 -0
  174. package/contracts/oapps/counter/integration_tests/test_with_sml.rs +166 -0
  175. package/contracts/oapps/counter/integration_tests/utils.rs +144 -0
  176. package/contracts/oapps/counter/src/codec.rs +63 -0
  177. package/contracts/oapps/counter/src/counter.rs +235 -0
  178. package/contracts/oapps/counter/src/errors.rs +9 -0
  179. package/contracts/oapps/counter/src/lib.rs +16 -0
  180. package/contracts/oapps/counter/src/options.rs +30 -0
  181. package/contracts/oapps/counter/src/storage.rs +33 -0
  182. package/contracts/oapps/counter/src/tests/mod.rs +37 -0
  183. package/contracts/oapps/counter/src/tests/test_codec.rs +64 -0
  184. package/contracts/oapps/counter/src/tests/test_counter.rs +390 -0
  185. package/contracts/oapps/counter/src/u256_ext.rs +21 -0
  186. package/contracts/oapps/lib.rs +2 -0
  187. package/contracts/oapps/oapp/Cargo.toml +21 -0
  188. package/contracts/oapps/oapp/src/errors.rs +9 -0
  189. package/contracts/oapps/oapp/src/lib.rs +10 -0
  190. package/contracts/oapps/oapp/src/oapp_core.rs +92 -0
  191. package/contracts/oapps/oapp/src/oapp_options_type3.rs +89 -0
  192. package/contracts/oapps/oapp/src/oapp_receiver.rs +72 -0
  193. package/contracts/oapps/oapp/src/oapp_sender.rs +66 -0
  194. package/contracts/oapps/oapp/src/tests/mod.rs +4 -0
  195. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +162 -0
  196. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +180 -0
  197. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +157 -0
  198. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +283 -0
  199. package/contracts/utils/Cargo.toml +21 -0
  200. package/contracts/utils/src/buffer_reader.rs +143 -0
  201. package/contracts/utils/src/buffer_writer.rs +117 -0
  202. package/contracts/utils/src/bytes_ext.rs +19 -0
  203. package/contracts/utils/src/errors.rs +30 -0
  204. package/contracts/utils/src/lib.rs +15 -0
  205. package/contracts/utils/src/option_ext.rs +38 -0
  206. package/contracts/utils/src/ownable.rs +88 -0
  207. package/contracts/utils/src/testing_utils.rs +100 -0
  208. package/contracts/utils/src/tests/buffer_reader.rs +1006 -0
  209. package/contracts/utils/src/tests/buffer_writer.rs +330 -0
  210. package/contracts/utils/src/tests/bytes_ext.rs +77 -0
  211. package/contracts/utils/src/tests/mod.rs +4 -0
  212. package/contracts/utils/src/tests/ownable.rs +149 -0
  213. package/contracts/utils/src/ttl.rs +164 -0
  214. package/contracts/workers/Cargo.toml +13 -0
  215. package/contracts/workers/executor/Cargo.toml +26 -0
  216. package/contracts/workers/executor/src/events.rs +22 -0
  217. package/contracts/workers/executor/src/executor.rs +347 -0
  218. package/contracts/workers/executor/src/interfaces/executor.rs +40 -0
  219. package/contracts/workers/executor/src/interfaces/mod.rs +5 -0
  220. package/contracts/workers/executor/src/interfaces/types.rs +51 -0
  221. package/contracts/workers/executor/src/lib.rs +10 -0
  222. package/contracts/workers/executor/src/storage.rs +23 -0
  223. package/contracts/workers/lib.rs +2 -0
  224. package/contracts/workers/worker-common/Cargo.toml +18 -0
  225. package/contracts/workers/worker-common/src/constants.rs +17 -0
  226. package/contracts/workers/worker-common/src/errors.rs +6 -0
  227. package/contracts/workers/worker-common/src/events.rs +34 -0
  228. package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +35 -0
  229. package/contracts/workers/worker-common/src/interfaces/mod.rs +7 -0
  230. package/contracts/workers/worker-common/src/interfaces/price_feed.rs +40 -0
  231. package/contracts/workers/worker-common/src/interfaces/worker.rs +60 -0
  232. package/contracts/workers/worker-common/src/lib.rs +19 -0
  233. package/contracts/workers/worker-common/src/storage.rs +32 -0
  234. package/contracts/workers/worker-common/src/worker_common.rs +166 -0
  235. package/package.json +25 -0
  236. package/rust-toolchain.toml +4 -0
  237. package/rustfmt.toml +17 -0
  238. package/sdk/.turbo/turbo-build.log +4 -0
  239. package/sdk/dist/generated/bml.d.ts +452 -0
  240. package/sdk/dist/generated/bml.js +72 -0
  241. package/sdk/dist/generated/counter.d.ts +824 -0
  242. package/sdk/dist/generated/counter.js +125 -0
  243. package/sdk/dist/generated/endpoint.d.ts +1676 -0
  244. package/sdk/dist/generated/endpoint.js +216 -0
  245. package/sdk/dist/generated/sml.d.ts +810 -0
  246. package/sdk/dist/generated/sml.js +132 -0
  247. package/sdk/dist/generated/uln302.d.ts +1227 -0
  248. package/sdk/dist/generated/uln302.js +185 -0
  249. package/sdk/dist/index.d.ts +5 -0
  250. package/sdk/dist/index.js +5 -0
  251. package/sdk/node_modules/.bin/tsc +21 -0
  252. package/sdk/node_modules/.bin/tsserver +21 -0
  253. package/sdk/node_modules/.bin/vitest +21 -0
  254. package/sdk/node_modules/.bin/zx +21 -0
  255. package/sdk/package.json +40 -0
  256. package/sdk/src/index.ts +5 -0
  257. package/sdk/test/index.test.ts +271 -0
  258. package/sdk/test/suites/constants.ts +13 -0
  259. package/sdk/test/suites/deploy.ts +277 -0
  260. package/sdk/test/suites/localnet.ts +42 -0
  261. package/sdk/test/suites/scan.ts +189 -0
  262. package/sdk/tsconfig.json +106 -0
  263. package/tools/ts-bindings-gen/Cargo.toml +14 -0
  264. package/tools/ts-bindings-gen/src/main.rs +147 -0
  265. package/turbo.json +12 -0
@@ -0,0 +1,28 @@
1
+ [package]
2
+ name = "uln302"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ license.workspace = true
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+ doctest = false
11
+
12
+ [features]
13
+ library = []
14
+ testutils = []
15
+
16
+ [dependencies]
17
+ cfg-if = { workspace = true }
18
+ soroban-sdk = { workspace = true }
19
+ # workspace dependencies
20
+ utils = { workspace = true }
21
+ common-macros = { workspace = true }
22
+ endpoint-v2 = { workspace = true, features = ["library"] }
23
+ message-lib-common = { workspace = true }
24
+
25
+ [dev-dependencies]
26
+ soroban-sdk = { workspace = true, features = ["testutils"] }
27
+ message-lib-common = { workspace = true, features = ["testutils"] }
28
+ utils = { workspace = true, features = ["testutils"] }
@@ -0,0 +1,173 @@
1
+ use crate::errors::Uln302Error;
2
+ use crate::interfaces::{ExecutorConfig, OAppUlnConfig, UlnConfig};
3
+ use crate::OAppExecutorConfig;
4
+ use soroban_sdk::{assert_with_error, map, vec, Env, IntoVal, TryFromVal, Val, Vec};
5
+
6
+ /// Maximum number of DVNs allowed in a configuration.
7
+ pub const MAX_DVNS: u32 = 127;
8
+
9
+ // ================================================
10
+ // Uln Config Validation
11
+ // ================================================
12
+
13
+ impl UlnConfig {
14
+ /// Validates the required DVNs configuration.
15
+ ///
16
+ /// Checks:
17
+ /// - No duplicate addresses in the required DVNs list
18
+ /// - Required DVNs count does not exceed MAX_DVNS limit
19
+ pub fn validate_required_dvns(&self, env: &Env) {
20
+ assert_with_error!(env, !has_duplicates(env, &self.required_dvns), Uln302Error::DuplicateRequiredDVNs);
21
+ assert_with_error!(env, self.required_dvns.len() <= MAX_DVNS, Uln302Error::InvalidRequiredDVNCount);
22
+ }
23
+
24
+ /// Validates the optional DVNs configuration and threshold.
25
+ ///
26
+ /// Checks:
27
+ /// - No duplicate addresses in the optional DVNs list
28
+ /// - Optional DVNs count does not exceed MAX_DVNS limit
29
+ /// - Threshold is valid: either (0 threshold with 0 DVNs) or (threshold between 1 and DVN count)
30
+ pub fn validate_optional_dvns(&self, env: &Env) {
31
+ assert_with_error!(env, !has_duplicates(env, &self.optional_dvns), Uln302Error::DuplicateOptionalDVNs);
32
+ assert_with_error!(env, self.optional_dvns.len() <= MAX_DVNS, Uln302Error::InvalidOptionalDVNCount);
33
+ assert_with_error!(
34
+ env,
35
+ (self.optional_dvn_threshold == 0 && self.optional_dvns.is_empty())
36
+ || (self.optional_dvn_threshold > 0 && self.optional_dvn_threshold <= self.optional_dvns.len()),
37
+ Uln302Error::InvalidOptionalDVNThreshold
38
+ );
39
+ }
40
+
41
+ /// Validates a UlnConfig for using as a default config.
42
+ ///
43
+ /// Performs comprehensive validation including:
44
+ /// - Required DVNs validation (no duplicates, within limits)
45
+ /// - Optional DVNs validation (no duplicates, within limits, valid threshold)
46
+ /// - At least one DVN requirement (either required or optional with threshold > 0)
47
+ pub fn validate_default_config(&self, env: &Env) {
48
+ self.validate_required_dvns(env);
49
+ self.validate_optional_dvns(env);
50
+ self.validate_at_least_one_dvn(env);
51
+ }
52
+
53
+ /// Validates that the configuration has at least one DVN for verification.
54
+ ///
55
+ /// A valid configuration must have either:
56
+ /// - At least one required DVN, OR
57
+ /// - An optional DVN threshold greater than 0
58
+ pub fn validate_at_least_one_dvn(&self, env: &Env) {
59
+ assert_with_error!(
60
+ env,
61
+ !self.required_dvns.is_empty() || self.optional_dvn_threshold > 0,
62
+ Uln302Error::UlnAtLeastOneDVN
63
+ );
64
+ }
65
+ }
66
+
67
+ impl OAppUlnConfig {
68
+ /// Creates a default OAppUlnConfig that uses all default values.
69
+ pub fn default(env: &Env) -> Self {
70
+ OAppUlnConfig {
71
+ use_default_confirmations: true,
72
+ use_default_required_dvns: true,
73
+ use_default_optional_dvns: true,
74
+ uln_config: UlnConfig {
75
+ confirmations: 0,
76
+ required_dvns: vec![&env],
77
+ optional_dvns: vec![&env],
78
+ optional_dvn_threshold: 0,
79
+ },
80
+ }
81
+ }
82
+
83
+ /// Validates an OAppUlnConfig for correctness.
84
+ ///
85
+ /// Checks:
86
+ /// - When using defaults, corresponding config values must be empty/zero
87
+ /// - When not using defaults, the provided values must be valid
88
+ pub fn validate_oapp_config(&self, env: &Env) {
89
+ assert_with_error!(
90
+ env,
91
+ !self.use_default_confirmations || self.uln_config.confirmations == 0,
92
+ Uln302Error::InvalidConfirmations
93
+ );
94
+
95
+ if self.use_default_required_dvns {
96
+ assert_with_error!(env, self.uln_config.required_dvns.is_empty(), Uln302Error::InvalidRequiredDVNs);
97
+ } else {
98
+ self.uln_config.validate_required_dvns(env);
99
+ }
100
+
101
+ if self.use_default_optional_dvns {
102
+ assert_with_error!(
103
+ env,
104
+ self.uln_config.optional_dvn_threshold == 0 && self.uln_config.optional_dvns.is_empty(),
105
+ Uln302Error::InvalidOptionalDVNs
106
+ );
107
+ } else {
108
+ self.uln_config.validate_optional_dvns(env);
109
+ }
110
+ }
111
+
112
+ /// Merges this OAppUlnConfig with a default UlnConfig to produce the effective config.
113
+ pub fn apply_default_config(&self, default_config: &UlnConfig) -> UlnConfig {
114
+ let confirmations =
115
+ if self.use_default_confirmations { default_config.confirmations } else { self.uln_config.confirmations };
116
+ let required_dvns = if self.use_default_required_dvns {
117
+ default_config.required_dvns.clone()
118
+ } else {
119
+ self.uln_config.required_dvns.clone()
120
+ };
121
+ let (optional_dvns, optional_dvn_threshold) = if self.use_default_optional_dvns {
122
+ (default_config.optional_dvns.clone(), default_config.optional_dvn_threshold)
123
+ } else {
124
+ (self.uln_config.optional_dvns.clone(), self.uln_config.optional_dvn_threshold)
125
+ };
126
+
127
+ UlnConfig { confirmations, required_dvns, optional_dvns, optional_dvn_threshold }
128
+ }
129
+ }
130
+
131
+ // ================================================
132
+ // Executor Config Validation
133
+ // ================================================
134
+
135
+ impl ExecutorConfig {
136
+ /// Validates the executor config for use as a default configuration.
137
+ pub fn validate_default_config(&self, env: &Env) {
138
+ assert_with_error!(env, self.max_message_size != 0, Uln302Error::ZeroMessageSize);
139
+ }
140
+ }
141
+
142
+ impl OAppExecutorConfig {
143
+ /// Merges this OAppExecutorConfig with a default ExecutorConfig to produce the effective config.
144
+ pub fn apply_default_config(&self, default_config: &ExecutorConfig) -> ExecutorConfig {
145
+ ExecutorConfig {
146
+ max_message_size: if self.max_message_size != 0 {
147
+ self.max_message_size
148
+ } else {
149
+ default_config.max_message_size
150
+ },
151
+ executor: self.executor.clone().unwrap_or(default_config.executor.clone()),
152
+ }
153
+ }
154
+ }
155
+
156
+ // ================================================
157
+ // Helper Functions
158
+ // ================================================
159
+
160
+ /// Checks if a vector contains duplicate elements.
161
+ fn has_duplicates<T>(env: &Env, items: &Vec<T>) -> bool
162
+ where
163
+ T: IntoVal<Env, Val> + TryFromVal<Env, Val> + Clone,
164
+ {
165
+ let mut seen = map![env];
166
+ for item in items {
167
+ if seen.contains_key(item.clone()) {
168
+ return true;
169
+ }
170
+ seen.set(item, true);
171
+ }
172
+ false
173
+ }
@@ -0,0 +1,29 @@
1
+ use common_macros::contract_error;
2
+
3
+ #[contract_error]
4
+ pub enum Uln302Error {
5
+ DefaultExecutorConfigNotFound,
6
+ DefaultReceiveUlnConfigNotFound,
7
+ DefaultSendUlnConfigNotFound,
8
+ DuplicateOptionalDVNs,
9
+ DuplicateRequiredDVNs,
10
+ InvalidConfig,
11
+ InvalidConfigType,
12
+ InvalidConfirmations,
13
+ InvalidEID,
14
+ InvalidMessageSize,
15
+ InvalidOptionalDVNCount,
16
+ InvalidOptionalDVNs,
17
+ InvalidOptionalDVNThreshold,
18
+ InvalidPacketHeader,
19
+ InvalidRequiredDVNCount,
20
+ InvalidRequiredDVNs,
21
+ OAppExecutorConfigNotFound,
22
+ OAppReceiveUlnConfigNotFound,
23
+ OAppSendUlnConfigNotFound,
24
+ OnlyEndpoint,
25
+ UlnAtLeastOneDVN,
26
+ UnsupportedEid,
27
+ Verifying,
28
+ ZeroMessageSize,
29
+ }
@@ -0,0 +1,72 @@
1
+ use crate::{
2
+ interfaces::{OAppExecutorConfig, OAppUlnConfig, SetDefaultUlnConfigParam},
3
+ SetDefaultExecutorConfigParam,
4
+ };
5
+ use common_macros::event;
6
+ use endpoint_v2::FeeRecipient;
7
+ use soroban_sdk::{Address, Bytes, BytesN, Vec};
8
+
9
+ #[event]
10
+ pub struct ExecutorConfigSet {
11
+ #[topic]
12
+ pub sender: Address,
13
+ #[topic]
14
+ pub dst_eid: u32,
15
+ pub config: OAppExecutorConfig,
16
+ }
17
+
18
+ #[event]
19
+ pub struct UlnSendConfigSet {
20
+ #[topic]
21
+ pub sender: Address,
22
+ #[topic]
23
+ pub dst_eid: u32,
24
+ pub config: OAppUlnConfig,
25
+ }
26
+
27
+ #[event]
28
+ pub struct UlnReceiveConfigSet {
29
+ #[topic]
30
+ pub receiver: Address,
31
+ #[topic]
32
+ pub src_eid: u32,
33
+ pub config: OAppUlnConfig,
34
+ }
35
+
36
+ #[event]
37
+ pub struct DefaultExecutorConfigSet {
38
+ pub params: Vec<SetDefaultExecutorConfigParam>,
39
+ }
40
+
41
+ #[event]
42
+ pub struct DefaultUlnSendConfigSet {
43
+ pub params: Vec<SetDefaultUlnConfigParam>,
44
+ }
45
+
46
+ #[event]
47
+ pub struct DefaultUlnReceiveConfigSet {
48
+ pub params: Vec<SetDefaultUlnConfigParam>,
49
+ }
50
+
51
+ #[event]
52
+ pub struct ExecutorFeePaid {
53
+ #[topic]
54
+ pub executor: Address,
55
+ pub fee: FeeRecipient,
56
+ }
57
+
58
+ #[event]
59
+ pub struct DVNFeePaid {
60
+ #[topic]
61
+ pub dvns: Vec<Address>,
62
+ pub fees: Vec<FeeRecipient>,
63
+ }
64
+
65
+ #[event]
66
+ pub struct PayloadVerified {
67
+ #[topic]
68
+ pub dvn: Address,
69
+ pub header: Bytes,
70
+ pub confirmations: u64,
71
+ pub proof_hash: BytesN<32>,
72
+ }
@@ -0,0 +1,5 @@
1
+ pub mod receive;
2
+ pub mod send;
3
+
4
+ pub use receive::*;
5
+ pub use send::*;
@@ -0,0 +1,82 @@
1
+ use crate::interfaces::{OAppUlnConfig, SetDefaultUlnConfigParam, UlnConfig};
2
+ use soroban_sdk::{contractclient, Address, Bytes, BytesN, Env, Vec};
3
+
4
+ /// Interface for ULN302 receive library functions.
5
+ ///
6
+ /// Handles DVN verification and message commitment on the receiving chain.
7
+ #[contractclient(name = "ReceiveUln302Client")]
8
+ pub trait IReceiveUln302 {
9
+ /// Called by a DVN to verify a message with a specific number of confirmations.
10
+ ///
11
+ /// # Arguments
12
+ /// * `dvn` - The DVN address
13
+ /// * `packet_header` - The raw packet header bytes
14
+ /// * `payload_hash` - The hash of the message payload
15
+ /// * `confirmations` - The number of block confirmations the DVN has observed
16
+ fn verify(env: &Env, dvn: &Address, packet_header: &Bytes, payload_hash: &BytesN<32>, confirmations: u64);
17
+
18
+ /// Returns the block confirmations a DVN has reported for a message.
19
+ ///
20
+ /// # Arguments
21
+ /// * `dvn` - The DVN address
22
+ /// * `header_hash` - The hash of the packet header
23
+ /// * `payload_hash` - The hash of the message payload
24
+ fn confirmations(env: &Env, dvn: &Address, header_hash: &BytesN<32>, payload_hash: &BytesN<32>) -> Option<u64>;
25
+
26
+ /// Checks if a message has been verified by enough DVNs to be committed.
27
+ ///
28
+ /// Evaluates whether all required DVNs and the threshold of optional DVNs
29
+ /// have verified the message with sufficient block confirmations.
30
+ ///
31
+ /// # Arguments
32
+ /// * `packet_header` - The raw packet header bytes
33
+ /// * `payload_hash` - The hash of the message payload
34
+ ///
35
+ /// # Returns
36
+ /// True if the message has been verified by enough DVNs to be committed, false otherwise
37
+ fn verifiable(env: &Env, packet_header: &Bytes, payload_hash: &BytesN<32>) -> bool;
38
+
39
+ /// Permissonless to commit a verified message to the endpoint after sufficient DVN verification.
40
+ ///
41
+ /// Checks that all required DVNs and the optional DVN threshold have verified
42
+ /// the message, then calls `verify` on the endpoint to make the message executable.
43
+ ///
44
+ /// # Arguments
45
+ /// * `packet_header` - The raw packet header bytes
46
+ /// * `payload_hash` - The hash of the message payload
47
+ fn commit_verification(env: &Env, packet_header: &Bytes, payload_hash: &BytesN<32>);
48
+
49
+ /// Sets default receive ULN configurations for multiple source endpoints.
50
+ ///
51
+ /// # Arguments
52
+ /// * `params` - A vector of `SetDefaultUlnConfigParam`, each containing a source EID and its ULN config
53
+ fn set_default_receive_uln_configs(env: &Env, params: &Vec<SetDefaultUlnConfigParam>);
54
+
55
+ /// Returns the default receive ULN configuration for a source endpoint.
56
+ ///
57
+ /// # Arguments
58
+ /// * `src_eid` - The source endpoint ID
59
+ fn default_receive_uln_config(env: &Env, src_eid: u32) -> Option<UlnConfig>;
60
+
61
+ /// Returns the OApp-specific receive ULN configuration for a specific source endpoint.
62
+ ///
63
+ /// # Arguments
64
+ /// * `receiver` - The receiver OApp address
65
+ /// * `src_eid` - The source endpoint ID
66
+ fn oapp_receive_uln_config(env: &Env, receiver: &Address, src_eid: u32) -> Option<OAppUlnConfig>;
67
+
68
+ /// Gets the effective receive ULN configuration.
69
+ ///
70
+ /// Merges the OApp-specific config with the default config. OApp settings take precedence.
71
+ ///
72
+ /// # Arguments
73
+ /// * `receiver` - The receiver OApp address
74
+ /// * `src_eid` - The source endpoint ID
75
+ ///
76
+ /// # Returns
77
+ /// The effective receive ULN configuration
78
+ ///
79
+ /// # Panics
80
+ /// Panics if the default receive ULN configuration is not set for the source endpoint.
81
+ fn effective_receive_uln_config(env: &Env, receiver: &Address, src_eid: u32) -> UlnConfig;
82
+ }
@@ -0,0 +1,159 @@
1
+ use endpoint_v2::ISendLib;
2
+ use soroban_sdk::{contractclient, contracttype, Address, Env, Vec};
3
+
4
+ // ================================================
5
+ // Config Types
6
+ // ================================================
7
+
8
+ /// Ultra Light Node configuration for message verification.
9
+ #[contracttype]
10
+ #[derive(Clone, Eq, PartialEq, Debug)]
11
+ pub struct UlnConfig {
12
+ /// Number of block confirmations required before message verification begins.
13
+ pub confirmations: u64,
14
+ /// List of DVN addresses that must ALL verify the message (no threshold).
15
+ pub required_dvns: Vec<Address>,
16
+ /// List of DVN addresses from which a threshold number must verify.
17
+ pub optional_dvns: Vec<Address>,
18
+ /// Minimum number of optional DVNs required to verify.
19
+ pub optional_dvn_threshold: u32,
20
+ }
21
+
22
+ /// OApp-specific ULN configuration with default override flags.
23
+ #[contracttype]
24
+ #[derive(Clone, Eq, PartialEq, Debug)]
25
+ pub struct OAppUlnConfig {
26
+ /// Whether to use default confirmations.
27
+ pub use_default_confirmations: bool,
28
+ /// Whether to use default required DVNs.
29
+ pub use_default_required_dvns: bool,
30
+ /// Whether to use default optional DVNs.
31
+ pub use_default_optional_dvns: bool,
32
+ /// OApp-specific ULN configuration (used when defaults are not applied).
33
+ pub uln_config: UlnConfig,
34
+ }
35
+
36
+ /// Parameter for setting default ULN configuration for a destination/source endpoint.
37
+ #[contracttype]
38
+ #[derive(Clone, Eq, PartialEq, Debug)]
39
+ pub struct SetDefaultUlnConfigParam {
40
+ /// The destination endpoint ID (for send) or source endpoint ID (for receive).
41
+ pub dst_eid: u32,
42
+ /// The ULN configuration to set as default.
43
+ pub config: UlnConfig,
44
+ }
45
+
46
+ // === Executor Config Types ===
47
+
48
+ /// Executor configuration for message delivery.
49
+ #[contracttype]
50
+ #[derive(Clone, Eq, PartialEq, Debug)]
51
+ pub struct ExecutorConfig {
52
+ /// Maximum size of messages that can be executed (in bytes).
53
+ pub max_message_size: u32,
54
+ /// Address of the executor contract responsible for message execution.
55
+ pub executor: Address,
56
+ }
57
+
58
+ /// OApp-specific executor configuration.
59
+ ///
60
+ /// If executor is `None`, the default executor is used.
61
+ #[contracttype]
62
+ #[derive(Clone, Default, Eq, PartialEq, Debug)]
63
+ pub struct OAppExecutorConfig {
64
+ /// Maximum size of messages that can be executed (in bytes). 0 means use default configuration.
65
+ pub max_message_size: u32,
66
+ /// Address of the executor contract to be used for message execution. None means use default configuration.
67
+ pub executor: Option<Address>,
68
+ }
69
+
70
+ /// Parameter for setting default executor configuration for a destination endpoint.
71
+ #[contracttype]
72
+ #[derive(Clone, Eq, PartialEq, Debug)]
73
+ pub struct SetDefaultExecutorConfigParam {
74
+ /// The destination endpoint ID.
75
+ pub dst_eid: u32,
76
+ /// The executor configuration to set as default.
77
+ pub config: ExecutorConfig,
78
+ }
79
+
80
+ // ================================================
81
+ // ISendUln302 Trait
82
+ // ================================================
83
+
84
+ /// Interface for ULN302 send library functions.
85
+ ///
86
+ /// Extends `ISendLib` with ULN-specific configuration management for executors and DVNs.
87
+ #[contractclient(name = "SendUln302Client")]
88
+ pub trait ISendUln302: ISendLib {
89
+ /// Returns the treasury address for fee collection.
90
+ fn treasury(env: &Env) -> Address;
91
+
92
+ /// Sets default executor configurations for multiple destination endpoints.
93
+ ///
94
+ /// # Arguments
95
+ /// * `params` - A vector of `SetDefaultExecutorConfigParam`, each containing a destination EID and its executor config
96
+ fn set_default_executor_configs(env: &Env, params: &Vec<SetDefaultExecutorConfigParam>);
97
+
98
+ /// Returns the default executor configuration for a destination endpoint.
99
+ ///
100
+ /// # Arguments
101
+ /// * `dst_eid` - The destination endpoint ID
102
+ fn default_executor_config(env: &Env, dst_eid: u32) -> Option<ExecutorConfig>;
103
+
104
+ /// Returns the OApp-specific executor configuration for a specific destination endpoint.
105
+ ///
106
+ /// # Arguments
107
+ /// * `sender` - The sender OApp address
108
+ /// * `dst_eid` - The destination endpoint ID
109
+ fn oapp_executor_config(env: &Env, sender: &Address, dst_eid: u32) -> Option<OAppExecutorConfig>;
110
+
111
+ /// Gets the effective executor configuration (OApp config merged with default).
112
+ ///
113
+ /// Merges the OApp-specific config with the default config. OApp settings take precedence.
114
+ ///
115
+ /// # Arguments
116
+ /// * `sender` - The sender OApp address
117
+ /// * `dst_eid` - The destination endpoint ID
118
+ ///
119
+ /// # Returns
120
+ /// The effective executor configuration
121
+ ///
122
+ /// # Panics
123
+ /// Panics if the default executor configuration is not set for the destination endpoint.
124
+ fn effective_executor_config(env: &Env, sender: &Address, dst_eid: u32) -> ExecutorConfig;
125
+
126
+ /// Sets default send ULN configurations for multiple destination endpoints.
127
+ ///
128
+ /// # Arguments
129
+ /// * `params` - A vector of `SetDefaultUlnConfigParam`, each containing a destination EID and its ULN config
130
+ fn set_default_send_uln_configs(env: &Env, params: &Vec<SetDefaultUlnConfigParam>);
131
+
132
+ /// Returns the default send ULN configuration for a destination endpoint.
133
+ ///
134
+ /// # Arguments
135
+ /// * `dst_eid` - The destination endpoint ID
136
+ fn default_send_uln_config(env: &Env, dst_eid: u32) -> Option<UlnConfig>;
137
+
138
+ /// Returns the OApp-specific send ULN configuration for a specific destination endpoint.
139
+ ///
140
+ /// # Arguments
141
+ /// * `sender` - The sender OApp address
142
+ /// * `dst_eid` - The destination endpoint ID
143
+ fn oapp_send_uln_config(env: &Env, sender: &Address, dst_eid: u32) -> Option<OAppUlnConfig>;
144
+
145
+ /// Gets the effective send ULN configuration (OApp config merged with default).
146
+ ///
147
+ /// Merges the OApp-specific config with the default config. OApp settings take precedence.
148
+ ///
149
+ /// # Arguments
150
+ /// * `sender` - The sender OApp address
151
+ /// * `dst_eid` - The destination endpoint ID
152
+ ///
153
+ /// # Returns
154
+ /// The effective send ULN configuration
155
+ ///
156
+ /// # Panics
157
+ /// Panics if the default send ULN configuration is not set for the destination endpoint.
158
+ fn effective_send_uln_config(env: &Env, sender: &Address, dst_eid: u32) -> UlnConfig;
159
+ }
@@ -0,0 +1,20 @@
1
+ #![no_std]
2
+
3
+ mod interfaces;
4
+
5
+ pub use interfaces::*;
6
+
7
+ cfg_if::cfg_if! {
8
+ if #[cfg(any(not(feature = "library"), feature = "testutils"))] {
9
+ mod config_validation;
10
+ mod errors;
11
+ mod events;
12
+ mod storage;
13
+ mod uln302;
14
+
15
+ pub use uln302::{Uln302, Uln302Client};
16
+ }
17
+ }
18
+
19
+ #[cfg(test)]
20
+ mod tests;