@layerzerolabs/protocol-stellar-v2 0.2.8 → 0.2.10

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 (239) hide show
  1. package/.turbo/turbo-build.log +443 -302
  2. package/.turbo/turbo-lint.log +118 -96
  3. package/.turbo/turbo-test.log +853 -731
  4. package/Cargo.lock +120 -37
  5. package/Cargo.toml +8 -5
  6. package/contracts/common-macros/src/contract_impl.rs +44 -0
  7. package/contracts/common-macros/src/lib.rs +86 -40
  8. package/contracts/common-macros/src/ownable.rs +24 -32
  9. package/contracts/common-macros/src/storage.rs +95 -120
  10. package/contracts/common-macros/src/tests/contract_impl.rs +289 -0
  11. package/contracts/common-macros/src/tests/mod.rs +9 -0
  12. package/contracts/common-macros/src/tests/ownable.rs +151 -0
  13. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +85 -0
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +30 -0
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap +9 -0
  16. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +1072 -0
  17. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +45 -0
  18. package/contracts/common-macros/src/tests/storage.rs +485 -0
  19. package/contracts/common-macros/src/tests/test_helpers.rs +93 -0
  20. package/contracts/common-macros/src/tests/ttl_configurable.rs +34 -0
  21. package/contracts/common-macros/src/ttl_configurable.rs +31 -14
  22. package/contracts/common-macros/src/utils.rs +27 -0
  23. package/contracts/endpoint-v2/ARCHITECTURE.md +4 -4
  24. package/contracts/endpoint-v2/src/endpoint_v2.rs +18 -15
  25. package/contracts/endpoint-v2/src/interfaces/message_lib.rs +2 -3
  26. package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +5 -3
  27. package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +2 -2
  28. package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +2 -2
  29. package/contracts/endpoint-v2/src/interfaces/send_lib.rs +4 -4
  30. package/contracts/endpoint-v2/src/lib.rs +6 -5
  31. package/contracts/endpoint-v2/src/message_lib_manager.rs +14 -6
  32. package/contracts/endpoint-v2/src/messaging_channel.rs +6 -2
  33. package/contracts/endpoint-v2/src/messaging_composer.rs +6 -2
  34. package/contracts/endpoint-v2/src/storage.rs +10 -7
  35. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +16 -16
  36. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +46 -46
  37. package/contracts/endpoint-v2/src/tests/mock.rs +2 -2
  38. package/contracts/endpoint-v2/src/util.rs +8 -2
  39. package/contracts/message-libs/block-message-lib/Cargo.toml +1 -0
  40. package/contracts/message-libs/block-message-lib/src/lib.rs +5 -5
  41. package/contracts/message-libs/message-lib-common/src/errors.rs +8 -8
  42. package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +0 -1
  43. package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +3 -3
  44. package/contracts/message-libs/message-lib-common/src/lib.rs +0 -2
  45. package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +4 -6
  46. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +2 -2
  47. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +11 -11
  48. package/contracts/message-libs/message-lib-common/src/worker_options.rs +10 -16
  49. package/contracts/message-libs/simple-message-lib/src/errors.rs +0 -4
  50. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +49 -34
  51. package/contracts/message-libs/simple-message-lib/src/storage.rs +3 -7
  52. package/contracts/message-libs/simple-message-lib/src/test.rs +3 -3
  53. package/contracts/message-libs/treasury/src/storage.rs +1 -2
  54. package/contracts/message-libs/treasury/src/tests/setup.rs +3 -2
  55. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +0 -13
  56. package/contracts/message-libs/treasury/src/treasury.rs +18 -21
  57. package/contracts/message-libs/uln-302/Cargo.toml +1 -0
  58. package/contracts/message-libs/uln-302/src/interfaces/mod.rs +4 -4
  59. package/contracts/message-libs/uln-302/src/interfaces/{receive.rs → receive_uln.rs} +3 -3
  60. package/contracts/message-libs/uln-302/src/interfaces/{send.rs → send_uln.rs} +8 -80
  61. package/contracts/message-libs/uln-302/src/lib.rs +5 -4
  62. package/contracts/message-libs/uln-302/src/{receive.rs → receive_uln.rs} +20 -12
  63. package/contracts/message-libs/uln-302/src/{send.rs → send_uln.rs} +19 -13
  64. package/contracts/message-libs/uln-302/src/storage.rs +1 -2
  65. package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +3 -2
  66. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +30 -30
  67. package/contracts/message-libs/uln-302/src/tests/setup.rs +12 -11
  68. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +1 -1
  69. package/contracts/message-libs/uln-302/src/{config_validation.rs → types.rs} +79 -11
  70. package/contracts/message-libs/uln-302/src/uln302.rs +15 -10
  71. package/contracts/oapp-macros/Cargo.toml +2 -8
  72. package/contracts/oapp-macros/src/lib.rs +57 -311
  73. package/contracts/oapp-macros/src/oapp_core.rs +23 -32
  74. package/contracts/oapp-macros/src/oapp_full.rs +8 -2
  75. package/contracts/oapp-macros/src/oapp_options_type3.rs +21 -36
  76. package/contracts/oapp-macros/src/oapp_receiver.rs +38 -57
  77. package/contracts/oapp-macros/src/oapp_sender.rs +12 -14
  78. package/contracts/oapp-macros/src/util.rs +14 -10
  79. package/contracts/oapps/counter/Cargo.toml +2 -1
  80. package/contracts/oapps/counter/integration_tests/utils.rs +4 -4
  81. package/contracts/oapps/counter/src/codec.rs +8 -9
  82. package/contracts/oapps/counter/src/counter.rs +156 -147
  83. package/contracts/oapps/counter/src/storage.rs +1 -2
  84. package/contracts/oapps/counter/src/tests/test_codec.rs +5 -5
  85. package/contracts/oapps/counter/src/tests/test_counter.rs +11 -13
  86. package/contracts/oapps/oapp/Cargo.toml +1 -0
  87. package/contracts/oapps/oapp/src/errors.rs +1 -1
  88. package/contracts/oapps/oapp/src/lib.rs +3 -0
  89. package/contracts/oapps/oapp/src/macro_tests/mod.rs +1 -0
  90. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +312 -0
  91. package/contracts/oapps/oapp/src/oapp_core.rs +52 -53
  92. package/contracts/oapps/oapp/src/oapp_options_type3.rs +18 -28
  93. package/contracts/oapps/oapp/src/oapp_receiver.rs +82 -31
  94. package/contracts/oapps/oapp/src/oapp_sender.rs +55 -13
  95. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +16 -3
  96. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +33 -8
  97. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +6 -9
  98. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +28 -15
  99. package/contracts/oapps/oft/Cargo.toml +27 -0
  100. package/contracts/oapps/oft/integration-tests/mod.rs +3 -0
  101. package/contracts/oapps/oft/integration-tests/setup.rs +320 -0
  102. package/contracts/oapps/oft/integration-tests/test_with_sml.rs +155 -0
  103. package/contracts/oapps/oft/integration-tests/utils.rs +201 -0
  104. package/contracts/oapps/oft/src/codec/mod.rs +2 -0
  105. package/contracts/oapps/oft/src/codec/oft_compose_msg_codec.rs +55 -0
  106. package/contracts/oapps/oft/src/codec/oft_msg_codec.rs +62 -0
  107. package/contracts/oapps/oft/src/constants.rs +5 -0
  108. package/contracts/oapps/oft/src/errors.rs +8 -0
  109. package/contracts/oapps/oft/src/events.rs +19 -0
  110. package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +23 -0
  111. package/contracts/oapps/oft/src/interfaces/mod.rs +3 -0
  112. package/contracts/oapps/oft/src/lib.rs +22 -0
  113. package/contracts/oapps/oft/src/macro_tests/mod.rs +2 -0
  114. package/contracts/oapps/oft/src/macro_tests/test_all_default.rs +41 -0
  115. package/contracts/oapps/oft/src/macro_tests/test_override.rs +83 -0
  116. package/contracts/oapps/oft/src/oft.rs +320 -0
  117. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +50 -0
  118. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +50 -0
  119. package/contracts/oapps/oft/src/oft_types/mod.rs +10 -0
  120. package/contracts/oapps/oft/src/storage.rs +11 -0
  121. package/contracts/oapps/oft/src/tests/mod.rs +13 -0
  122. package/contracts/oapps/oft/src/tests/test_decimals.rs +89 -0
  123. package/contracts/oapps/oft/src/tests/test_lz_receive.rs +282 -0
  124. package/contracts/oapps/oft/src/tests/test_oft_compose_msg_codec.rs +68 -0
  125. package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +136 -0
  126. package/contracts/oapps/oft/src/tests/test_oft_version.rs +13 -0
  127. package/contracts/oapps/oft/src/tests/test_quote_oft.rs +159 -0
  128. package/contracts/oapps/oft/src/tests/test_quote_send.rs +195 -0
  129. package/contracts/oapps/oft/src/tests/test_resolve_address.rs +37 -0
  130. package/contracts/oapps/oft/src/tests/test_send.rs +915 -0
  131. package/contracts/oapps/oft/src/tests/test_token.rs +47 -0
  132. package/contracts/oapps/oft/src/tests/test_utils.rs +789 -0
  133. package/contracts/oapps/oft/src/types.rs +38 -0
  134. package/contracts/oapps/oft/src/utils.rs +67 -0
  135. package/contracts/oapps/oft-mint-burn/Cargo.toml +26 -0
  136. package/contracts/oapps/oft-mint-burn/src/lib.rs +3 -0
  137. package/contracts/oapps/oft-mint-burn/src/oft.rs +28 -0
  138. package/contracts/oapps/oft-mint-burn/src/tests/mod.rs +1 -0
  139. package/contracts/utils/src/buffer_reader.rs +8 -9
  140. package/contracts/utils/src/buffer_writer.rs +11 -5
  141. package/contracts/utils/src/errors.rs +5 -5
  142. package/contracts/utils/src/ownable.rs +14 -6
  143. package/contracts/utils/src/testing_utils.rs +11 -1
  144. package/contracts/utils/src/tests/buffer_reader.rs +491 -730
  145. package/contracts/utils/src/tests/buffer_writer.rs +336 -148
  146. package/contracts/utils/src/tests/bytes_ext.rs +125 -40
  147. package/contracts/utils/src/tests/mod.rs +3 -0
  148. package/contracts/utils/src/tests/ownable.rs +379 -27
  149. package/contracts/utils/src/tests/test_helper.rs +47 -0
  150. package/contracts/utils/src/tests/testing_utils.rs +555 -0
  151. package/contracts/utils/src/tests/ttl.rs +421 -0
  152. package/contracts/utils/src/ttl.rs +29 -89
  153. package/contracts/workers/dvn/Cargo.toml +31 -0
  154. package/contracts/workers/dvn/src/auth.rs +66 -0
  155. package/contracts/workers/dvn/src/dvn.rs +143 -0
  156. package/contracts/workers/dvn/src/errors.rs +21 -0
  157. package/contracts/workers/dvn/src/events.rs +19 -0
  158. package/contracts/workers/dvn/src/interfaces/dvn.rs +12 -0
  159. package/contracts/workers/dvn/src/interfaces/mod.rs +5 -0
  160. package/contracts/workers/dvn/src/interfaces/multisig.rs +15 -0
  161. package/contracts/workers/dvn/src/lib.rs +24 -0
  162. package/contracts/workers/dvn/src/multisig.rs +127 -0
  163. package/contracts/workers/dvn/src/storage.rs +35 -0
  164. package/contracts/workers/dvn/src/tests/auth.rs +237 -0
  165. package/contracts/workers/dvn/src/tests/dvn.rs +349 -0
  166. package/contracts/workers/dvn/src/tests/key_pair.rs +66 -0
  167. package/contracts/workers/dvn/src/tests/mod.rs +5 -0
  168. package/contracts/workers/dvn/src/tests/multisig/mod.rs +3 -0
  169. package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +133 -0
  170. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +108 -0
  171. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +109 -0
  172. package/contracts/workers/dvn/src/tests/setup.rs +109 -0
  173. package/contracts/workers/dvn/src/types.rs +26 -0
  174. package/contracts/workers/dvn-fee-lib/Cargo.toml +24 -0
  175. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +113 -0
  176. package/contracts/workers/dvn-fee-lib/src/errors.rs +8 -0
  177. package/contracts/workers/dvn-fee-lib/src/lib.rs +17 -0
  178. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +282 -0
  179. package/contracts/workers/dvn-fee-lib/src/tests/mod.rs +1 -0
  180. package/contracts/workers/executor/Cargo.toml +10 -7
  181. package/contracts/workers/executor/src/errors.rs +8 -0
  182. package/contracts/workers/executor/src/events.rs +4 -7
  183. package/contracts/workers/executor/src/interfaces/executor.rs +72 -22
  184. package/contracts/workers/executor/src/interfaces/mod.rs +0 -2
  185. package/contracts/workers/executor/src/lib.rs +16 -7
  186. package/contracts/workers/executor/src/lz_executor.rs +308 -0
  187. package/contracts/workers/executor/src/storage.rs +24 -16
  188. package/contracts/workers/executor-fee-lib/Cargo.toml +22 -0
  189. package/contracts/workers/executor-fee-lib/src/errors.rs +15 -0
  190. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +215 -0
  191. package/contracts/workers/executor-fee-lib/src/executor_option.rs +203 -0
  192. package/contracts/workers/executor-fee-lib/src/lib.rs +7 -0
  193. package/contracts/workers/executor-helper/Cargo.toml +29 -0
  194. package/contracts/workers/executor-helper/src/executor_helper.rs +161 -0
  195. package/contracts/workers/executor-helper/src/lib.rs +11 -0
  196. package/contracts/workers/{worker-common → worker}/Cargo.toml +1 -4
  197. package/contracts/workers/worker/src/errors.rs +24 -0
  198. package/contracts/workers/worker/src/events.rs +62 -0
  199. package/contracts/workers/worker/src/interfaces/dvn_fee_lib.rs +75 -0
  200. package/contracts/workers/worker/src/interfaces/executor_fee_lib.rs +84 -0
  201. package/contracts/workers/{worker-common → worker}/src/interfaces/mod.rs +2 -2
  202. package/contracts/workers/worker/src/interfaces/price_feed.rs +85 -0
  203. package/contracts/workers/worker/src/lib.rs +14 -0
  204. package/contracts/workers/worker/src/storage.rs +63 -0
  205. package/contracts/workers/worker/src/worker.rs +459 -0
  206. package/package.json +3 -3
  207. package/sdk/dist/generated/bml.d.ts +88 -17
  208. package/sdk/dist/generated/bml.js +62 -16
  209. package/sdk/dist/generated/counter.d.ts +281 -102
  210. package/sdk/dist/generated/counter.js +93 -41
  211. package/sdk/dist/generated/endpoint.d.ts +128 -105
  212. package/sdk/dist/generated/endpoint.js +47 -45
  213. package/sdk/dist/generated/sml.d.ts +212 -69
  214. package/sdk/dist/generated/sml.js +103 -53
  215. package/sdk/dist/generated/uln302.d.ts +270 -173
  216. package/sdk/dist/generated/uln302.js +112 -64
  217. package/sdk/package.json +11 -11
  218. package/sdk/test/index.test.ts +147 -42
  219. package/sdk/test/suites/constants.ts +7 -3
  220. package/sdk/test/suites/deploy.ts +65 -42
  221. package/sdk/test/suites/localnet.ts +2 -2
  222. package/sdk/test/suites/scan.ts +28 -25
  223. package/sdk/test/utils.ts +199 -0
  224. package/sdk/tsconfig.json +93 -95
  225. package/tools/ts-bindings-gen/src/main.rs +2 -0
  226. package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +0 -310
  227. package/contracts/common-macros/src/tests.rs +0 -287
  228. package/contracts/oapp-macros/tests/test_macros.rs +0 -522
  229. package/contracts/workers/executor/src/executor.rs +0 -347
  230. package/contracts/workers/executor/src/interfaces/types.rs +0 -51
  231. package/contracts/workers/worker-common/src/constants.rs +0 -17
  232. package/contracts/workers/worker-common/src/errors.rs +0 -6
  233. package/contracts/workers/worker-common/src/events.rs +0 -34
  234. package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +0 -35
  235. package/contracts/workers/worker-common/src/interfaces/price_feed.rs +0 -40
  236. package/contracts/workers/worker-common/src/interfaces/worker.rs +0 -60
  237. package/contracts/workers/worker-common/src/lib.rs +0 -19
  238. package/contracts/workers/worker-common/src/storage.rs +0 -32
  239. package/contracts/workers/worker-common/src/worker_common.rs +0 -166
@@ -0,0 +1,459 @@
1
+ use soroban_sdk::{assert_with_error, contracttrait, Address, Bytes, Env, Vec};
2
+ use utils::{
3
+ option_ext::OptionExt,
4
+ ownable::{enforce_owner_auth, require_owner_auth, Ownable},
5
+ };
6
+
7
+ use crate::{
8
+ errors::WorkerError,
9
+ events::{
10
+ Paused, SetAdmin, SetAllowlist, SetDefaultMultiplierBps, SetDenylist, SetDepositAddress, SetPriceFeed,
11
+ SetSupportedMessageLib, SetSupportedOptionTypes, SetWorkerFeeLib, Unpaused,
12
+ },
13
+ storage::WorkerStorage,
14
+ };
15
+
16
+ /// Worker interface providing common functionality for LayerZero workers.
17
+ #[contracttrait]
18
+ pub trait Worker: Ownable + Sized {
19
+ // ========================================================================
20
+ // Manager Functions
21
+ // ========================================================================
22
+
23
+ /// Sets the paused state of the worker.
24
+ ///
25
+ /// When paused, the worker will reject new job assignments (e.g., assign_job, get_fee).
26
+ /// Existing jobs in progress are not affected.
27
+ ///
28
+ /// # Arguments
29
+ /// * `paused` - `true` to pause, `false` to unpause
30
+ fn set_paused(env: &Env, paused: bool) {
31
+ let owner = enforce_owner_auth::<Self>(env);
32
+ assert_with_error!(env, Self::paused(env) != paused, WorkerError::PauseStatusUnchanged);
33
+
34
+ WorkerStorage::set_paused(env, &paused);
35
+ if paused {
36
+ Paused { pauser: owner }.publish(env);
37
+ } else {
38
+ Unpaused { unpauser: owner }.publish(env);
39
+ }
40
+ }
41
+
42
+ /// Sets whether a message library is supported by this worker.
43
+ ///
44
+ /// Message libraries (e.g., ULN302) call workers to assign jobs. Only supported
45
+ /// libraries can interact with this worker.
46
+ ///
47
+ /// # Arguments
48
+ /// * `message_lib` - The message library contract address
49
+ /// * `supported` - `true` to add support, `false` to remove support
50
+ fn set_supported_message_lib(env: &Env, message_lib: &Address, supported: bool) {
51
+ require_owner_auth::<Self>(env);
52
+ set_message_lib_no_auth::<Self>(env, message_lib, supported);
53
+ }
54
+
55
+ /// Sets allowlist status for an OApp address.
56
+ ///
57
+ /// When the allowlist is empty, all OApps are allowed (unless on denylist).
58
+ /// When the allowlist is not empty, only allowlisted OApps are allowed.
59
+ /// Denylist always takes precedence over allowlist.
60
+ ///
61
+ /// # Arguments
62
+ /// * `oapp` - The OApp contract address
63
+ /// * `allowed` - `true` to add to allowlist, `false` to remove
64
+ fn set_allowlist(env: &Env, oapp: &Address, allowed: bool) {
65
+ require_owner_auth::<Self>(env);
66
+
67
+ let is_on_list = Self::is_on_allowlist(env, oapp);
68
+ if allowed {
69
+ // Add to allowlist - ensure not already present
70
+ assert_with_error!(env, !is_on_list, WorkerError::AlreadyOnAllowlist);
71
+ WorkerStorage::set_allowlist(env, oapp, &true);
72
+ // Increment allowlist size
73
+ let size = Self::allowlist_size(env);
74
+ WorkerStorage::set_allowlist_size(env, &(size + 1));
75
+ } else {
76
+ // Remove from allowlist - ensure present
77
+ assert_with_error!(env, is_on_list, WorkerError::NotOnAllowlist);
78
+ WorkerStorage::remove_allowlist(env, oapp);
79
+ // Decrement allowlist size
80
+ let size = Self::allowlist_size(env);
81
+ WorkerStorage::set_allowlist_size(env, &(size - 1));
82
+ }
83
+ SetAllowlist { oapp: oapp.clone(), allowed }.publish(env);
84
+ }
85
+
86
+ /// Sets denylist status for an OApp address.
87
+ ///
88
+ /// Denylisted OApps are blocked from using this worker, even if they're on
89
+ /// the allowlist (denylist takes precedence).
90
+ ///
91
+ /// # Arguments
92
+ /// * `oapp` - The OApp contract address
93
+ /// * `denied` - `true` to add to denylist, `false` to remove
94
+ fn set_denylist(env: &Env, oapp: &Address, denied: bool) {
95
+ require_owner_auth::<Self>(env);
96
+ let is_on_list = Self::is_on_denylist(env, oapp);
97
+
98
+ if denied {
99
+ // Add to denylist - ensure not already present
100
+ assert_with_error!(env, !is_on_list, WorkerError::AlreadyOnDenylist);
101
+ WorkerStorage::set_denylist(env, oapp, &true);
102
+ } else {
103
+ // Remove from denylist - ensure present
104
+ assert_with_error!(env, is_on_list, WorkerError::NotOnDenylist);
105
+ WorkerStorage::remove_denylist(env, oapp);
106
+ }
107
+ SetDenylist { oapp: oapp.clone(), denied }.publish(env);
108
+ }
109
+
110
+ // ========================================================================
111
+ // Admin(managed by the manager) Functions
112
+ // ========================================================================
113
+
114
+ /// Sets the default fee multiplier in basis points.
115
+ ///
116
+ /// The multiplier is applied to base fees during fee calculation. Used when
117
+ /// no destination-specific multiplier is configured.
118
+ ///
119
+ /// # Arguments
120
+ /// * `admin` - Admin address (must provide authorization)
121
+ /// * `multiplier_bps` - Multiplier in basis points (10000 = 1x, 12000 = 1.2x)
122
+ fn set_default_multiplier_bps(env: &Env, admin: &Address, multiplier_bps: u32) {
123
+ require_admin_auth::<Self>(env, admin);
124
+ set_default_multiplier_bps_no_auth(env, multiplier_bps);
125
+ }
126
+
127
+ /// Sets the deposit address where worker fees are collected.
128
+ ///
129
+ /// When jobs are assigned, fees are directed to this address.
130
+ ///
131
+ /// # Arguments
132
+ /// * `admin` - Admin address (must provide authorization)
133
+ /// * `deposit_address` - Address to receive collected fees
134
+ fn set_deposit_address(env: &Env, admin: &Address, deposit_address: &Address) {
135
+ require_admin_auth::<Self>(env, admin);
136
+ WorkerStorage::set_deposit_address(env, deposit_address);
137
+ SetDepositAddress { deposit_address: deposit_address.clone() }.publish(env);
138
+ }
139
+
140
+ /// Sets supported executor option types for a destination endpoint.
141
+ ///
142
+ /// # Arguments
143
+ /// * `admin` - Admin address (must provide authorization)
144
+ /// * `eid` - Destination endpoint ID (chain identifier)
145
+ /// * `option_types` - Encoded supported option types
146
+ fn set_supported_option_types(env: &Env, admin: &Address, eid: u32, option_types: Bytes) {
147
+ require_admin_auth::<Self>(env, admin);
148
+ WorkerStorage::set_supported_option_types(env, eid, &option_types);
149
+ SetSupportedOptionTypes { dst_eid: eid, option_types }.publish(env);
150
+ }
151
+
152
+ /// Sets the worker fee library contract address.
153
+ ///
154
+ /// The fee library calculates fees based on executor options and price feed data.
155
+ ///
156
+ /// # Arguments
157
+ /// * `admin` - Admin address (must provide authorization)
158
+ /// * `worker_fee_lib` - Fee library contract address implementing `IExecutorFeeLib`
159
+ fn set_worker_fee_lib(env: &Env, admin: &Address, worker_fee_lib: &Address) {
160
+ require_admin_auth::<Self>(env, admin);
161
+ WorkerStorage::set_worker_fee_lib(env, worker_fee_lib);
162
+ SetWorkerFeeLib { fee_lib: worker_fee_lib.clone() }.publish(env);
163
+ }
164
+
165
+ /// Sets the price feed contract address.
166
+ ///
167
+ /// The price feed provides gas prices and exchange rates for cross-chain
168
+ /// fee calculations.
169
+ ///
170
+ /// # Arguments
171
+ /// * `admin` - Admin address (must provide authorization)
172
+ /// * `price_feed` - Price feed contract address implementing `ILayerZeroPriceFeed`
173
+ fn set_price_feed(env: &Env, admin: &Address, price_feed: &Address) {
174
+ require_admin_auth::<Self>(env, admin);
175
+ WorkerStorage::set_price_feed(env, price_feed);
176
+ SetPriceFeed { price_feed: price_feed.clone() }.publish(env);
177
+ }
178
+
179
+ // ========================================================================
180
+ // View Functions
181
+ // ========================================================================
182
+
183
+ /// Returns whether an address is an admin.
184
+ ///
185
+ /// # Arguments
186
+ /// * `admin` - The address to check
187
+ fn is_admin(env: &Env, admin: &Address) -> bool {
188
+ Self::admins(env).contains(admin)
189
+ }
190
+
191
+ /// Returns all admin addresses.
192
+ fn admins(env: &Env) -> Vec<Address> {
193
+ WorkerStorage::admins(env).unwrap_or(Vec::new(env))
194
+ }
195
+
196
+ /// Returns whether the worker is paused.
197
+ fn paused(env: &Env) -> bool {
198
+ WorkerStorage::paused(env)
199
+ }
200
+
201
+ /// Returns whether a message library is supported.
202
+ ///
203
+ /// # Arguments
204
+ /// * `message_lib` - Message library contract address
205
+ fn is_supported_message_lib(env: &Env, message_lib: &Address) -> bool {
206
+ Self::message_libs(env).contains(message_lib)
207
+ }
208
+
209
+ /// Returns all supported message library addresses.
210
+ ///
211
+ /// # Returns
212
+ /// Vector of supported message library contract addresses.
213
+ fn message_libs(env: &Env) -> Vec<Address> {
214
+ WorkerStorage::message_libs(env).unwrap_or(Vec::new(env))
215
+ }
216
+
217
+ /// Returns whether an OApp is on the allowlist.
218
+ ///
219
+ /// # Arguments
220
+ /// * `oapp` - OApp contract address
221
+ fn is_on_allowlist(env: &Env, oapp: &Address) -> bool {
222
+ WorkerStorage::has_allowlist(env, oapp)
223
+ }
224
+
225
+ /// Returns whether an OApp is on the denylist.
226
+ ///
227
+ /// # Arguments
228
+ /// * `oapp` - OApp contract address
229
+ fn is_on_denylist(env: &Env, oapp: &Address) -> bool {
230
+ WorkerStorage::has_denylist(env, oapp)
231
+ }
232
+
233
+ /// Returns whether an OApp has access control list (ACL) permission.
234
+ ///
235
+ /// ACL evaluation order:
236
+ /// 1. If on denylist → denied
237
+ /// 2. If allowlist is empty OR on allowlist → allowed
238
+ /// 3. Otherwise → denied
239
+ ///
240
+ /// # Arguments
241
+ /// * `sender` - OApp contract address to check
242
+ fn has_acl(env: &Env, sender: &Address) -> bool {
243
+ if Self::is_on_denylist(env, sender) {
244
+ return false;
245
+ }
246
+ if Self::allowlist_size(env) == 0 || Self::is_on_allowlist(env, sender) {
247
+ return true;
248
+ }
249
+ false
250
+ }
251
+
252
+ /// Returns the number of addresses on the allowlist.
253
+ fn allowlist_size(env: &Env) -> u32 {
254
+ WorkerStorage::allowlist_size(env)
255
+ }
256
+
257
+ /// Returns the default fee multiplier in basis points.
258
+ fn default_multiplier_bps(env: &Env) -> u32 {
259
+ WorkerStorage::default_multiplier_bps(env).unwrap_or(0)
260
+ }
261
+
262
+ /// Returns the deposit address where fees are collected.
263
+ fn deposit_address(env: &Env) -> Address {
264
+ WorkerStorage::deposit_address(env).unwrap_or_panic(env, WorkerError::DepositAddressNotSet)
265
+ }
266
+
267
+ /// Returns the price feed contract address.
268
+ fn price_feed(env: &Env) -> Address {
269
+ WorkerStorage::price_feed(env).unwrap_or_panic(env, WorkerError::PriceFeedNotSet)
270
+ }
271
+
272
+ /// Returns supported option types for a destination endpoint.
273
+ ///
274
+ /// # Arguments
275
+ /// * `eid` - Destination endpoint ID (chain identifier)
276
+ fn get_supported_option_types(env: &Env, eid: u32) -> Option<Bytes> {
277
+ WorkerStorage::supported_option_types(env, eid)
278
+ }
279
+
280
+ /// Returns the worker fee library contract address.
281
+ fn worker_fee_lib(env: &Env) -> Address {
282
+ WorkerStorage::worker_fee_lib(env).unwrap_or_panic(env, WorkerError::WorkerFeeLibNotSet)
283
+ }
284
+ }
285
+
286
+ // ============================================================================================
287
+ // Worker Initializer
288
+ // ============================================================================================
289
+
290
+ /// Initializes a worker contract with configuration.
291
+ ///
292
+ /// This function should be called only once to initialize the worker once.
293
+ ///
294
+ /// # Arguments
295
+ /// * `admins` - Initial admin addresses (must not be empty)
296
+ /// * `message_libs` - Supported message library addresses
297
+ /// * `price_feed` - Price feed contract address
298
+ /// * `default_multiplier_bps` - Default fee multiplier in basis points
299
+ pub fn init_worker<T: Worker>(
300
+ env: &Env,
301
+ admins: &Vec<Address>,
302
+ message_libs: &Vec<Address>,
303
+ price_feed: &Address,
304
+ default_multiplier_bps: u32,
305
+ ) {
306
+ assert_with_error!(env, T::admins(env).is_empty(), WorkerError::ReInitialize);
307
+ assert_with_error!(env, !admins.is_empty(), WorkerError::NoAdminsProvided);
308
+
309
+ for admin in admins {
310
+ set_admin_no_auth::<T>(env, &admin, true);
311
+ }
312
+
313
+ for lib in message_libs {
314
+ set_message_lib_no_auth::<T>(env, &lib, true);
315
+ }
316
+
317
+ set_price_feed_no_auth(env, price_feed);
318
+ set_default_multiplier_bps_no_auth(env, default_multiplier_bps);
319
+ }
320
+
321
+ // ============================================================================================
322
+ // Assert Helper Functions
323
+ // ============================================================================================
324
+
325
+ /// Requires admin authorization for the given address.
326
+ ///
327
+ /// # Arguments
328
+ /// * `admin` - The address to check for admin status
329
+ ///
330
+ /// # Errors
331
+ /// * `Unauthorized` - If the address is not an admin or authorization fails.
332
+ pub fn require_admin_auth<T: Worker>(env: &Env, admin: &Address) {
333
+ admin.require_auth();
334
+ assert_with_error!(env, T::is_admin(env, admin), WorkerError::Unauthorized);
335
+ }
336
+
337
+ /// Asserts that an OApp has ACL permission, panics otherwise.
338
+ ///
339
+ /// # Arguments
340
+ /// * `sender` - OApp contract address to check
341
+ ///
342
+ /// # Errors
343
+ /// * `NotAllowed` - If the OApp is not allowed to use this worker.
344
+ pub fn assert_acl<T: Worker>(env: &Env, sender: &Address) {
345
+ assert_with_error!(env, T::has_acl(env, sender), WorkerError::NotAllowed);
346
+ }
347
+
348
+ /// Asserts that the worker is not paused, panics otherwise.
349
+ ///
350
+ /// # Errors
351
+ /// * `WorkerIsPaused` - If the worker is currently paused.
352
+ pub fn assert_not_paused<T: Worker>(env: &Env) {
353
+ assert_with_error!(env, !T::paused(env), WorkerError::WorkerIsPaused);
354
+ }
355
+
356
+ /// Asserts that a message library is supported, panics otherwise.
357
+ ///
358
+ /// # Arguments
359
+ /// * `message_lib` - Message library contract address to check
360
+ ///
361
+ /// # Errors
362
+ /// * `UnsupportedMessageLib` - If the message library is not supported.
363
+ pub fn assert_supported_message_lib<T: Worker>(env: &Env, message_lib: &Address) {
364
+ assert_with_error!(env, T::is_supported_message_lib(env, message_lib), WorkerError::UnsupportedMessageLib);
365
+ }
366
+
367
+ // ============================================================================================
368
+ // Internal Functions
369
+ // ============================================================================================
370
+
371
+ /// Sets admin status for an address without authentication.
372
+ ///
373
+ /// Adds or removes an admin from the admin list and updates storage.
374
+ ///
375
+ /// # Arguments
376
+ /// * `admin` - Address to set admin status for
377
+ /// * `active` - `true` to add admin, `false` to remove
378
+ fn set_admin_no_auth<T: Worker>(env: &Env, admin: &Address, active: bool) {
379
+ let mut admins = T::admins(env);
380
+
381
+ if active {
382
+ // Add admin - ensure not already active
383
+ assert_with_error!(env, !admins.contains(admin), WorkerError::AdminAlreadyExists);
384
+ admins.push_back(admin.clone());
385
+ } else {
386
+ // Remove admin - ensure present
387
+ assert_with_error!(env, admins.contains(admin), WorkerError::AdminNotFound);
388
+ assert_with_error!(env, admins.len() > 1, WorkerError::AttemptingToRemoveOnlyAdmin);
389
+ let index = admins.first_index_of(admin).unwrap();
390
+ admins.remove(index);
391
+ }
392
+ WorkerStorage::set_admins(env, &admins);
393
+ SetAdmin { admin: admin.clone(), active }.publish(env);
394
+ }
395
+
396
+ /// Sets admin status for an address by owner.
397
+ ///
398
+ /// # Arguments
399
+ /// * `admin` - The address to set admin status for
400
+ /// * `active` - `true` to add admin, `false` to remove
401
+ pub fn set_admin_by_owner<T: Worker>(env: &Env, admin: &Address, active: bool) {
402
+ require_owner_auth::<T>(env);
403
+ set_admin_no_auth::<T>(env, admin, active);
404
+ }
405
+
406
+ /// Sets admin status for an address by admin.
407
+ ///
408
+ /// # Arguments
409
+ /// * `caller` - The admin calling this function (must provide authorization)
410
+ /// * `admin` - The address to set admin status for
411
+ /// * `active` - `true` to add admin, `false` to remove
412
+ pub fn set_admin_by_admin<T: Worker>(env: &Env, caller: &Address, admin: &Address, active: bool) {
413
+ require_admin_auth::<T>(env, caller);
414
+ set_admin_no_auth::<T>(env, admin, active);
415
+ }
416
+
417
+ /// Sets message library support status without authentication.
418
+ ///
419
+ /// Adds or removes a message library from the supported libraries list.
420
+ ///
421
+ /// # Arguments
422
+ /// * `message_lib` - Message library contract address
423
+ /// * `supported` - `true` to add support, `false` to remove
424
+ fn set_message_lib_no_auth<T: Worker>(env: &Env, message_lib: &Address, supported: bool) {
425
+ let mut libs = T::message_libs(env);
426
+
427
+ if supported {
428
+ // Add message lib - ensure not already supported
429
+ assert_with_error!(env, !libs.contains(message_lib), WorkerError::MessageLibAlreadySupported);
430
+ libs.push_back(message_lib.clone());
431
+ WorkerStorage::set_message_libs(env, &libs);
432
+ } else {
433
+ // Remove message lib - ensure present
434
+ assert_with_error!(env, libs.contains(message_lib), WorkerError::MessageLibNotSupported);
435
+ let index = libs.first_index_of(message_lib).unwrap();
436
+ libs.remove(index);
437
+ WorkerStorage::set_message_libs(env, &libs);
438
+ }
439
+
440
+ SetSupportedMessageLib { message_lib: message_lib.clone(), supported }.publish(env);
441
+ }
442
+
443
+ /// Sets the price feed contract address without authentication.
444
+ ///
445
+ /// # Arguments
446
+ /// * `price_feed` - Price feed contract address
447
+ fn set_price_feed_no_auth(env: &Env, price_feed: &Address) {
448
+ WorkerStorage::set_price_feed(env, price_feed);
449
+ SetPriceFeed { price_feed: price_feed.clone() }.publish(env);
450
+ }
451
+
452
+ /// Sets the default fee multiplier in basis points without authentication.
453
+ ///
454
+ /// # Arguments
455
+ /// * `default_multiplier_bps` - Default multiplier in basis points (10000 = 1x)
456
+ fn set_default_multiplier_bps_no_auth(env: &Env, multiplier_bps: u32) {
457
+ WorkerStorage::set_default_multiplier_bps(env, &multiplier_bps);
458
+ SetDefaultMultiplierBps { multiplier_bps }.publish(env);
459
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@layerzerolabs/protocol-stellar-v2",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "private": false,
5
5
  "devDependencies": {
6
6
  "@types/node": "^22.18.6",
7
7
  "tsx": "^4.19.3",
8
8
  "typescript": "^5.8.2",
9
- "@layerzerolabs/common-node-utils": "0.2.8",
10
- "@layerzerolabs/vm-tooling-stellar": "0.2.8"
9
+ "@layerzerolabs/common-node-utils": "0.2.10",
10
+ "@layerzerolabs/vm-tooling-stellar": "0.2.10"
11
11
  },
12
12
  "publishConfig": {
13
13
  "access": "restricted",
@@ -4,6 +4,80 @@ import type { u32, u64, i128 } from '@stellar/stellar-sdk/contract';
4
4
  export * from '@stellar/stellar-sdk';
5
5
  export * as contract from '@stellar/stellar-sdk/contract';
6
6
  export * as rpc from '@stellar/stellar-sdk/rpc';
7
+ export declare const EndpointError: {
8
+ 1: {
9
+ message: string;
10
+ };
11
+ 2: {
12
+ message: string;
13
+ };
14
+ 3: {
15
+ message: string;
16
+ };
17
+ 4: {
18
+ message: string;
19
+ };
20
+ 5: {
21
+ message: string;
22
+ };
23
+ 6: {
24
+ message: string;
25
+ };
26
+ 7: {
27
+ message: string;
28
+ };
29
+ 8: {
30
+ message: string;
31
+ };
32
+ 9: {
33
+ message: string;
34
+ };
35
+ 10: {
36
+ message: string;
37
+ };
38
+ 11: {
39
+ message: string;
40
+ };
41
+ 12: {
42
+ message: string;
43
+ };
44
+ 13: {
45
+ message: string;
46
+ };
47
+ 14: {
48
+ message: string;
49
+ };
50
+ 15: {
51
+ message: string;
52
+ };
53
+ 16: {
54
+ message: string;
55
+ };
56
+ 17: {
57
+ message: string;
58
+ };
59
+ 18: {
60
+ message: string;
61
+ };
62
+ 19: {
63
+ message: string;
64
+ };
65
+ 20: {
66
+ message: string;
67
+ };
68
+ 21: {
69
+ message: string;
70
+ };
71
+ 22: {
72
+ message: string;
73
+ };
74
+ 23: {
75
+ message: string;
76
+ };
77
+ 24: {
78
+ message: string;
79
+ };
80
+ };
7
81
  /**
8
82
  * Parameters for sending a cross-chain message.
9
83
  */
@@ -190,13 +264,13 @@ export interface OutboundPacket {
190
264
  */
191
265
  export interface FeeRecipient {
192
266
  /**
193
- * Address to receive the fee.
194
- */
195
- address: string;
196
- /**
197
267
  * Amount of fee to pay.
198
268
  */
199
269
  amount: i128;
270
+ /**
271
+ * The address to send the fee to.
272
+ */
273
+ to: string;
200
274
  }
201
275
  /**
202
276
  * Result of send operation containing fees and encoded packet.
@@ -216,39 +290,39 @@ export interface FeesAndPacket {
216
290
  zro_fee_recipients: Array<FeeRecipient>;
217
291
  }
218
292
  export declare const BufferReaderError: {
219
- 10000: {
293
+ 1000: {
220
294
  message: string;
221
295
  };
222
- 10001: {
296
+ 1001: {
223
297
  message: string;
224
298
  };
225
299
  };
226
300
  export declare const BufferWriterError: {
227
- 10100: {
301
+ 1100: {
228
302
  message: string;
229
303
  };
230
304
  };
231
305
  export declare const TtlError: {
232
- 10200: {
306
+ 1200: {
233
307
  message: string;
234
308
  };
235
- 10201: {
309
+ 1201: {
236
310
  message: string;
237
311
  };
238
- 10202: {
312
+ 1202: {
239
313
  message: string;
240
314
  };
241
315
  };
242
316
  export declare const OwnableError: {
243
- 10300: {
317
+ 1300: {
244
318
  message: string;
245
319
  };
246
- 10301: {
320
+ 1301: {
247
321
  message: string;
248
322
  };
249
323
  };
250
324
  export declare const BytesExtError: {
251
- 10400: {
325
+ 1400: {
252
326
  message: string;
253
327
  };
254
328
  };
@@ -269,7 +343,7 @@ export interface TtlConfig {
269
343
  */
270
344
  threshold: u32;
271
345
  }
272
- export type TtlConfigData = {
346
+ export type TtlConfigStorage = {
273
347
  tag: "Frozen";
274
348
  values: void;
275
349
  } | {
@@ -278,9 +352,6 @@ export type TtlConfigData = {
278
352
  } | {
279
353
  tag: "Persistent";
280
354
  values: void;
281
- } | {
282
- tag: "Temporary";
283
- values: void;
284
355
  };
285
356
  export interface Client {
286
357
  /**