@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
@@ -1,11 +1,7 @@
1
1
  use crate::errors::OAppError;
2
- use common_macros::{event, storage};
3
- use soroban_sdk::{assert_with_error, contracttype, panic_with_error, Bytes, Env, Vec};
4
- use utils::ttl::DefaultTtlConfigProvider;
5
-
6
- // =====================================================
7
- // Types and Traits
8
- // =====================================================
2
+ use common_macros::{event, only_owner, storage};
3
+ use soroban_sdk::{assert_with_error, contracttrait, contracttype, panic_with_error, Bytes, Env, Vec};
4
+ use utils::ownable::Ownable;
9
5
 
10
6
  pub const OPTION_TYPE3: u32 = 3;
11
7
 
@@ -17,19 +13,7 @@ pub struct EnforcedOptionParam {
17
13
  pub options: Bytes,
18
14
  }
19
15
 
20
- pub trait OAppOptionsType3 {
21
- fn enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes;
22
-
23
- fn set_enforced_options(env: &Env, options: Vec<EnforcedOptionParam>);
24
-
25
- fn combine_options(env: &Env, eid: u32, msg_type: u32, extra_options: &Bytes) -> Bytes;
26
- }
27
-
28
- // =====================================================
29
- // Implement overrides for the OAppOptionsType3 trait
30
- // =====================================================
31
-
32
- #[storage(DefaultTtlConfigProvider)]
16
+ #[storage]
33
17
  pub enum OAppOptionsType3Storage {
34
18
  #[persistent(Bytes)]
35
19
  #[default(Bytes::new(env))]
@@ -41,12 +25,18 @@ pub struct EnforcedOptionSet {
41
25
  pub enforced_option_params: Vec<EnforcedOptionParam>,
42
26
  }
43
27
 
44
- pub trait OAppOptionsType3Overrides {
45
- fn __enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes {
28
+ // =========================================================================
29
+ // OAppOptionsType3 Trait and Default Implementation
30
+ // =========================================================================
31
+
32
+ #[contracttrait(client_name = "OAppOptionsType3Client")]
33
+ pub trait OAppOptionsType3: Ownable + Sized {
34
+ fn enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes {
46
35
  OAppOptionsType3Storage::enforced_options(env, eid, msg_type)
47
36
  }
48
37
 
49
- fn __set_enforced_options(env: &Env, options: Vec<EnforcedOptionParam>) {
38
+ #[only_owner]
39
+ fn set_enforced_options(env: &Env, options: Vec<EnforcedOptionParam>) {
50
40
  for option in &options {
51
41
  assert_option_type3(env, &option.options);
52
42
  OAppOptionsType3Storage::set_enforced_options(env, option.eid, option.msg_type, &option.options);
@@ -54,8 +44,8 @@ pub trait OAppOptionsType3Overrides {
54
44
  EnforcedOptionSet { enforced_option_params: options }.publish(env);
55
45
  }
56
46
 
57
- fn __combine_options(env: &Env, eid: u32, msg_type: u32, extra_options: &Bytes) -> Bytes {
58
- let mut enforced_options = Self::__enforced_options(env, eid, msg_type);
47
+ fn combine_options(env: &Env, eid: u32, msg_type: u32, extra_options: &Bytes) -> Bytes {
48
+ let mut enforced_options = Self::enforced_options(env, eid, msg_type);
59
49
 
60
50
  if enforced_options.is_empty() {
61
51
  return extra_options.clone();
@@ -76,9 +66,9 @@ pub trait OAppOptionsType3Overrides {
76
66
  }
77
67
  }
78
68
 
79
- // =====================================================
80
- // Internal Helpers
81
- // =====================================================
69
+ // =========================================================================
70
+ // Helpers Functions
71
+ // =========================================================================
82
72
 
83
73
  pub fn assert_option_type3(env: &Env, options: &Bytes) {
84
74
  let mut options_version_bytes = [0u8; 2];
@@ -1,46 +1,75 @@
1
1
  use crate::{errors::OAppError, oapp_core::OAppCore};
2
- use endpoint_v2::{ILayerZeroReceiver, LayerZeroEndpointV2Client, Origin};
3
- use soroban_sdk::{assert_with_error, Address, Bytes, BytesN, Env};
2
+ use endpoint_v2::{LayerZeroEndpointV2Client, Origin};
3
+ use soroban_sdk::{assert_with_error, contracttrait, token::TokenClient, Address, Bytes, BytesN, Env};
4
4
 
5
5
  // =====================================================
6
- // OAppReceiver Traits
6
+ // OAppReceiver Trait
7
7
  // =====================================================
8
8
 
9
- pub trait OAppReceiver: ILayerZeroReceiver {
10
- /// Indicates whether an address is an approved composeMsg sender to the Endpoint.
11
- ///
12
- /// Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
13
- /// The default sender IS the OAppReceiver implementer.
9
+ /// Trait for OApps that can receive cross-chain messages from LayerZero.
10
+ ///
11
+ /// This trait combines the functionality of `ILayerZeroReceiver` (from endpoint-v2) with
12
+ /// OApp-specific features. It maintains the same function signatures as `ILayerZeroReceiver`
13
+ /// for `allow_initialize_path`, `next_nonce`, and `lz_receive`, which allows the endpoint
14
+ /// to call these methods via `LayerZeroReceiverClient` (client calls are resolved by function name).
15
+ ///
16
+ /// # Default Implementations
17
+ /// - `allow_initialize_path`: Returns true if the origin's sender matches the configured peer
18
+ /// - `next_nonce`: Returns 0 (no nonce ordering enforcement)
19
+ /// - `is_compose_msg_sender`: Returns true if sender is the current contract
20
+ ///
21
+ /// # Required Implementation
22
+ /// - `lz_receive`: Must be implemented by each OApp to handle incoming messages
23
+ ///
24
+ /// # Usage
25
+ /// When using `#[oapp_macros::oapp]`, the macro generates `lz_receive` that
26
+ /// automatically calls `verify_and_clear_payload` before delegating to `__lz_receive`.
27
+ /// **Do NOT call `verify_and_clear_payload` in your `__lz_receive` implementation.**
28
+ ///
29
+ /// ```ignore
30
+ /// #[oapp_macros::oapp]
31
+ /// pub struct MyOApp;
32
+ ///
33
+ /// impl MyOApp {
34
+ /// pub fn __lz_receive(env: &Env, executor: &Address, origin: &Origin, ...) {
35
+ /// // Handle the incoming message (verify_and_clear_payload already called)
36
+ /// }
37
+ /// }
38
+ /// ```
39
+ #[contracttrait(client_name = "OAppReceiverClient")]
40
+ pub trait OAppReceiver: OAppCore {
41
+ /// Checks if a messaging path can be initialized for the given origin.
14
42
  ///
15
43
  /// # Arguments
16
- /// * `origin` - The origin information containing the source endpoint and sender address
17
- /// * `message` - The lzReceive payload
18
- /// * `sender` - The sender address to check
44
+ /// * `origin` - The origin of the message
19
45
  ///
20
46
  /// # Returns
21
- /// True if the sender is a valid composeMsg sender, false otherwise
22
- fn is_compose_msg_sender(env: &Env, origin: &Origin, message: &Bytes, sender: &Address) -> bool;
23
- }
24
-
25
- // =====================================================
26
- // Implement overrides for the OAppReceiver trait
27
- // =====================================================
28
-
29
- pub trait OAppReceiverOverrides: OAppCore {
30
- fn __is_compose_msg_sender(env: &Env, _origin: &Origin, _message: &Bytes, sender: &Address) -> bool {
31
- env.current_contract_address() == *sender
32
- }
33
-
34
- fn __allow_initialize_path(env: &Env, origin: &Origin) -> bool {
47
+ /// True if the path can be initialized, false otherwise
48
+ fn allow_initialize_path(env: &Env, origin: &Origin) -> bool {
35
49
  let peer = Self::peer(env, origin.src_eid);
36
50
  peer.is_some_and(|peer| peer == origin.sender)
37
51
  }
38
52
 
39
- fn __next_nonce(_env: &Env, _src_eid: u32, _sender: &BytesN<32>) -> u64 {
53
+ /// Returns the next expected nonce for ordered message delivery.
54
+ /// 0 means there is NO nonce ordered enforcement.
55
+ ///
56
+ /// # Arguments
57
+ /// * `src_eid` - The source endpoint ID
58
+ /// * `sender` - The sender OApp address
59
+ fn next_nonce(_env: &Env, _src_eid: u32, _sender: &BytesN<32>) -> u64 {
40
60
  0
41
61
  }
42
62
 
43
- fn __lz_receive(
63
+ /// Receives and processes a cross-chain message.
64
+ ///
65
+ /// # Arguments
66
+ /// * `executor` - The executor address delivering the message
67
+ /// * `origin` - The origin information (source EID, sender, nonce)
68
+ /// * `guid` - The message GUID
69
+ /// * `message` - The message content
70
+ /// * `extra_data` - Additional executor-provided data (untrusted)
71
+ /// * `value` - The native token value sent with the message
72
+ fn lz_receive(
44
73
  env: &Env,
45
74
  executor: &Address,
46
75
  origin: &Origin,
@@ -49,6 +78,22 @@ pub trait OAppReceiverOverrides: OAppCore {
49
78
  extra_data: &Bytes,
50
79
  value: i128,
51
80
  );
81
+
82
+ /// Indicates whether an address is an approved composeMsg sender to the Endpoint.
83
+ ///
84
+ /// Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
85
+ /// The default sender IS the OAppReceiver implementer.
86
+ ///
87
+ /// # Arguments
88
+ /// * `origin` - The origin information containing the source endpoint and sender address
89
+ /// * `message` - The lzReceive payload
90
+ /// * `sender` - The sender address to check
91
+ ///
92
+ /// # Returns
93
+ /// True if the sender is a valid composeMsg sender, false otherwise
94
+ fn is_compose_msg_sender(env: &Env, _origin: &Origin, _message: &Bytes, sender: &Address) -> bool {
95
+ env.current_contract_address() == *sender
96
+ }
52
97
  }
53
98
 
54
99
  // =====================================================
@@ -61,12 +106,18 @@ pub fn verify_and_clear_payload<T: OAppCore>(
61
106
  origin: &Origin,
62
107
  guid: &BytesN<32>,
63
108
  message: &Bytes,
109
+ value: i128,
64
110
  ) {
65
111
  executor.require_auth();
66
112
  assert_with_error!(env, Some(origin.sender.clone()) == T::peer(env, origin.src_eid), OAppError::OnlyPeer);
67
113
 
68
- let contract_address = env.current_contract_address();
69
- let endpoint_address = T::endpoint(env);
70
- let endpoint = LayerZeroEndpointV2Client::new(env, &endpoint_address);
71
- endpoint.clear(&contract_address, origin, &contract_address, guid, message);
114
+ let curr_address = env.current_contract_address();
115
+ let endpoint = LayerZeroEndpointV2Client::new(env, &T::endpoint(env));
116
+ endpoint.clear(&curr_address, origin, &curr_address, guid, message);
117
+
118
+ if value > 0 {
119
+ let native_token = endpoint.native_token();
120
+ let token_client = TokenClient::new(env, &native_token);
121
+ token_client.transfer(executor, &curr_address, &value);
122
+ }
72
123
  }
@@ -3,8 +3,29 @@ use endpoint_v2::{LayerZeroEndpointV2Client, MessagingFee, MessagingParams, Mess
3
3
  use soroban_sdk::{token::TokenClient, Address, Bytes, Env};
4
4
  use utils::option_ext::OptionExt;
5
5
 
6
- pub trait OAppSenderOverrides: OAppCore {
7
- fn __quote(env: &Env, dst_eid: u32, message: &Bytes, options: &Bytes, pay_in_zro: bool) -> MessagingFee {
6
+ /// A helper trait for sending cross-chain messages via LayerZero.
7
+ ///
8
+ /// Contracts should implement this trait to gain access to the `lz_quote` and `lz_send` helper
9
+ /// methods for cross-chain messaging. This trait provides default implementations that handle
10
+ /// fee payment and message dispatch through the LayerZero endpoint.
11
+ ///
12
+ /// # Important
13
+ /// This trait is intended to be used as an **internal helper** only. Do **NOT** expose these
14
+ /// methods as part of your contract's public interface (i.e., do not use `#[contractimpl]` on
15
+ /// the implementation of this trait). Instead, call these methods internally from your
16
+ /// contract's own public functions.
17
+ pub trait OAppSender: OAppCore {
18
+ /// Quote the messaging fee for sending a message to the other chain
19
+ ///
20
+ /// # Arguments
21
+ /// * `dst_eid`: The destination endpoint ID
22
+ /// * `message`: The message to send
23
+ /// * `options`: The options for the message
24
+ /// * `pay_in_zro`: Whether to pay the fee in ZRO
25
+ ///
26
+ /// # Returns
27
+ /// * `MessagingFee`: The messaging fee for the message
28
+ fn lz_quote(env: &Env, dst_eid: u32, message: &Bytes, options: &Bytes, pay_in_zro: bool) -> MessagingFee {
8
29
  let endpoint = Self::endpoint(env);
9
30
  let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
10
31
  let receiver = Self::peer(env, dst_eid).unwrap_or_panic(env, OAppError::NoPeer);
@@ -14,27 +35,38 @@ pub trait OAppSenderOverrides: OAppCore {
14
35
  )
15
36
  }
16
37
 
17
- fn __lz_send(
38
+ /// Send a message to the other chain
39
+ ///
40
+ /// # Arguments
41
+ /// * `payer`: The address of the payer
42
+ /// * `dst_eid`: The destination endpoint ID
43
+ /// * `message`: The message to send
44
+ /// * `options`: The options for the message
45
+ /// * `fee`: The messaging fee
46
+ /// * `refund_address`: The address to receive any excess fees
47
+ ///
48
+ /// # Returns
49
+ /// * `MessagingReceipt`: The receipt for the sent message
50
+ fn lz_send(
18
51
  env: &Env,
19
- sender: &Address,
52
+ payer: &Address,
20
53
  dst_eid: u32,
21
54
  message: &Bytes,
22
55
  options: &Bytes,
23
56
  fee: &MessagingFee,
24
57
  refund_address: &Address,
25
58
  ) -> MessagingReceipt {
26
- Self::__pay_native(env, sender, fee.native_fee);
59
+ // Pay the messaging fees
60
+ Self::pay_native(env, payer, fee.native_fee);
27
61
  if fee.zro_fee > 0 {
28
- Self::__pay_zro(env, sender, fee.zro_fee);
62
+ Self::pay_zro(env, payer, fee.zro_fee);
29
63
  }
30
64
 
31
- let oapp = env.current_contract_address();
32
- let endpoint = Self::endpoint(env);
33
- let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
65
+ // Send the message to the other chain
66
+ let endpoint_client = LayerZeroEndpointV2Client::new(env, &Self::endpoint(env));
34
67
  let peer = Self::peer(env, dst_eid).unwrap_or_panic(env, OAppError::NoPeer);
35
-
36
68
  endpoint_client.send(
37
- &oapp,
69
+ &env.current_contract_address(),
38
70
  &MessagingParams {
39
71
  dst_eid,
40
72
  receiver: peer,
@@ -46,7 +78,12 @@ pub trait OAppSenderOverrides: OAppCore {
46
78
  )
47
79
  }
48
80
 
49
- fn __pay_native(env: &Env, payer: &Address, native_fee: i128) {
81
+ /// Pay the native fee to the endpoint for sending a message to the other chain
82
+ ///
83
+ /// # Arguments
84
+ /// * `payer`: The address of the payer
85
+ /// * `native_fee`: The native fee to pay
86
+ fn pay_native(env: &Env, payer: &Address, native_fee: i128) {
50
87
  let endpoint = Self::endpoint(env);
51
88
  let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
52
89
  let native_token = endpoint_client.native_token();
@@ -55,7 +92,12 @@ pub trait OAppSenderOverrides: OAppCore {
55
92
  token_client.transfer(payer, &endpoint, &native_fee);
56
93
  }
57
94
 
58
- fn __pay_zro(env: &Env, payer: &Address, zro_fee: i128) {
95
+ /// Pay the ZRO fee to the endpoint for sending a message to the other chain
96
+ ///
97
+ /// # Arguments
98
+ /// * `payer`: The address of the payer
99
+ /// * `zro_fee`: The ZRO fee to pay
100
+ fn pay_zro(env: &Env, payer: &Address, zro_fee: i128) {
59
101
  let endpoint = Self::endpoint(env);
60
102
  let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
61
103
  let zro_token = endpoint_client.zro().unwrap_or_panic(env, OAppError::ZROTokenUnavailable);
@@ -17,14 +17,27 @@ impl DummyEndpoint {
17
17
  }
18
18
  }
19
19
 
20
- #[oapp_macros::oapp_core]
20
+ #[oapp_macros::oapp]
21
21
  pub struct DummyOApp;
22
22
 
23
+ impl DummyOApp {
24
+ fn __lz_receive(
25
+ _env: &Env,
26
+ _executor: &Address,
27
+ _origin: &endpoint_v2::Origin,
28
+ _guid: &BytesN<32>,
29
+ _message: &soroban_sdk::Bytes,
30
+ _extra_data: &soroban_sdk::Bytes,
31
+ _value: i128,
32
+ ) {
33
+ // Not used in core tests
34
+ }
35
+ }
36
+
23
37
  #[contractimpl]
24
38
  impl DummyOApp {
25
39
  pub fn __constructor(env: &Env, owner: &Address, endpoint: &Address) {
26
- Self::__init_owner(env, owner);
27
- Self::__oapp_initialize(env, endpoint, &None);
40
+ oapp::oapp_core::oapp_initialize::<Self>(env, owner, endpoint, &None);
28
41
  }
29
42
  }
30
43
 
@@ -1,10 +1,10 @@
1
1
  use crate as oapp;
2
2
  use crate::oapp_options_type3::EnforcedOptionParam;
3
3
  use crate::oapp_options_type3::EnforcedOptionSet;
4
- use crate::oapp_options_type3::OAppOptionsType3;
4
+ use common_macros::contract_impl;
5
+ use soroban_sdk::contract;
5
6
  use soroban_sdk::contractimpl;
6
7
  use soroban_sdk::{
7
- contract,
8
8
  testutils::{Address as _, MockAuth, MockAuthInvoke},
9
9
  vec, Address, Bytes, Env, IntoVal,
10
10
  };
@@ -18,14 +18,37 @@ const MSG_TYPE_SEND: u32 = 1;
18
18
  const MSG_TYPE_RECEIVE: u32 = 2;
19
19
 
20
20
  #[contract]
21
- #[common_macros::ownable]
22
- #[oapp_macros::oapp_options_type3]
23
- pub struct DummyOAppOptionsType3;
21
+ pub struct DummyEndpoint;
24
22
 
25
23
  #[contractimpl]
24
+ impl DummyEndpoint {
25
+ pub fn set_delegate(_env: Env, _oapp: &Address, _delegate: &Option<Address>) {
26
+ // do nothing
27
+ }
28
+ }
29
+
30
+ #[oapp_macros::oapp]
31
+ #[oapp_macros::oapp_manual_impl(core, sender, receiver)]
32
+ pub struct DummyOAppOptionsType3;
33
+
34
+ #[contract_impl]
35
+ impl DummyOAppOptionsType3 {
36
+ pub fn __constructor(env: &Env, owner: &Address, endpoint: &Address, delegate: &Option<Address>) {
37
+ oapp::oapp_core::oapp_initialize::<Self>(env, owner, endpoint, delegate);
38
+ }
39
+ }
40
+
26
41
  impl DummyOAppOptionsType3 {
27
- pub fn __constructor(env: &Env, owner: &Address) {
28
- Self::__init_owner(env, owner);
42
+ fn __lz_receive(
43
+ _env: &Env,
44
+ _executor: &Address,
45
+ _origin: &endpoint_v2::Origin,
46
+ _guid: &soroban_sdk::BytesN<32>,
47
+ _message: &Bytes,
48
+ _extra_data: &Bytes,
49
+ _value: i128,
50
+ ) {
51
+ // Dummy implementation for testing
29
52
  }
30
53
  }
31
54
 
@@ -39,7 +62,9 @@ fn setup<'a>() -> TestSetup<'a> {
39
62
  let env = Env::default();
40
63
 
41
64
  let owner = Address::generate(&env);
42
- let oapp = env.register(DummyOAppOptionsType3, (&owner,));
65
+ let endpoint = env.register(DummyEndpoint, ());
66
+ let delegate: Option<Address> = Some(owner.clone());
67
+ let oapp = env.register(DummyOAppOptionsType3, (&owner, &endpoint, &delegate));
43
68
  let oapp_client = DummyOAppOptionsType3Client::new(&env, &oapp);
44
69
 
45
70
  TestSetup { env, owner, oapp_client }
@@ -1,18 +1,16 @@
1
1
  use crate as oapp;
2
+ use crate::errors::OAppError;
2
3
  use crate::oapp_core::OAppCoreStorage;
3
- use crate::oapp_receiver::OAppReceiverOverrides;
4
4
  use crate::tests::test_oapp_core::DummyEndpoint;
5
- use crate::{errors::OAppError, oapp_receiver::OAppReceiver};
6
- use endpoint_v2::{ILayerZeroReceiver, Origin};
7
- use soroban_sdk::contractimpl;
8
- use soroban_sdk::{assert_with_error, testutils::Address as _, Address, Bytes, BytesN, Env};
5
+ use endpoint_v2::Origin;
6
+ use soroban_sdk::{assert_with_error, contractimpl, testutils::Address as _, Address, Bytes, BytesN, Env};
9
7
  use utils::option_ext::OptionExt;
10
8
  use utils::ownable::Ownable;
11
9
 
12
- #[oapp_macros::oapp_receiver]
10
+ #[oapp_macros::oapp]
13
11
  pub struct DummyOAppReceiver;
14
12
 
15
- impl OAppReceiverOverrides for DummyOAppReceiver {
13
+ impl DummyOAppReceiver {
16
14
  fn __lz_receive(
17
15
  _env: &Env,
18
16
  _executor: &Address,
@@ -29,8 +27,7 @@ impl OAppReceiverOverrides for DummyOAppReceiver {
29
27
  #[contractimpl]
30
28
  impl DummyOAppReceiver {
31
29
  pub fn __constructor(env: &Env, owner: &Address, endpoint: &Address) {
32
- Self::__init_owner(env, owner);
33
- Self::__oapp_initialize(env, endpoint, &None);
30
+ oapp::oapp_core::oapp_initialize::<Self>(env, owner, endpoint, &None);
34
31
  }
35
32
 
36
33
  pub fn assert_allowed_peer(env: &Env, origin: &Origin) {
@@ -1,5 +1,5 @@
1
1
  use crate as oapp;
2
- use crate::{errors::OAppError, oapp_core::OAppCore};
2
+ use crate::errors::OAppError;
3
3
  use endpoint_v2::{MessagingFee, MessagingParams, MessagingReceipt};
4
4
  use soroban_sdk::{
5
5
  contract, contractimpl, symbol_short,
@@ -47,21 +47,34 @@ impl MockEndpoint {
47
47
  }
48
48
  }
49
49
 
50
- #[oapp_macros::oapp_sender]
50
+ #[oapp_macros::oapp]
51
51
  pub struct DummyOAppSender;
52
52
 
53
+ impl DummyOAppSender {
54
+ fn __lz_receive(
55
+ _env: &Env,
56
+ _executor: &Address,
57
+ _origin: &endpoint_v2::Origin,
58
+ _guid: &BytesN<32>,
59
+ _message: &Bytes,
60
+ _extra_data: &Bytes,
61
+ _value: i128,
62
+ ) {
63
+ // Not used in sender tests
64
+ }
65
+ }
66
+
53
67
  #[contractimpl]
54
68
  impl DummyOAppSender {
55
69
  pub fn __constructor(env: &Env, owner: &Address, endpoint: &Address) {
56
- Self::__init_owner(env, owner);
57
- Self::__oapp_initialize(env, endpoint, &None);
70
+ oapp::oapp_core::oapp_initialize::<Self>(env, owner, endpoint, &None);
58
71
  }
59
72
 
60
73
  pub fn quote(env: &Env, dst_eid: u32, message: &Bytes, options: &Bytes, pay_in_zro: bool) -> MessagingFee {
61
- Self::__quote(env, dst_eid, message, options, pay_in_zro)
74
+ Self::lz_quote(env, dst_eid, message, options, pay_in_zro)
62
75
  }
63
76
 
64
- pub fn lz_send(
77
+ pub fn send(
65
78
  env: &Env,
66
79
  sender: &Address,
67
80
  dst_eid: u32,
@@ -71,17 +84,17 @@ impl DummyOAppSender {
71
84
  refund_address: &Address,
72
85
  ) -> MessagingReceipt {
73
86
  sender.require_auth();
74
- Self::__lz_send(env, sender, dst_eid, message, options, fee, refund_address)
87
+ Self::lz_send(env, sender, dst_eid, message, options, fee, refund_address)
75
88
  }
76
89
 
77
- pub fn pay_native(env: &Env, payer: &Address, native_fee: i128) {
90
+ pub fn pay_native_fee(env: &Env, payer: &Address, native_fee: i128) {
78
91
  payer.require_auth();
79
- Self::__pay_native(env, payer, native_fee)
92
+ Self::pay_native(env, payer, native_fee)
80
93
  }
81
94
 
82
- pub fn pay_zro(env: &Env, payer: &Address, zro_fee: i128) {
95
+ pub fn pay_zro_fee(env: &Env, payer: &Address, zro_fee: i128) {
83
96
  payer.require_auth();
84
- Self::__pay_zro(env, payer, zro_fee)
97
+ Self::pay_zro(env, payer, zro_fee)
85
98
  }
86
99
  }
87
100
 
@@ -202,7 +215,7 @@ fn test_lz_send_native_only() {
202
215
  let fee = MessagingFee { native_fee: 1000, zro_fee: 0 };
203
216
 
204
217
  // Send message (auth is mocked automatically)
205
- let receipt = oapp_client.lz_send(&sender, &REMOTE_EID, &message, &options, &fee, &refund_address);
218
+ let receipt = oapp_client.send(&sender, &REMOTE_EID, &message, &options, &fee, &refund_address);
206
219
 
207
220
  // Verify receipt
208
221
  assert_eq!(receipt.nonce, 1);
@@ -238,7 +251,7 @@ fn test_lz_send_with_zro() {
238
251
  let refund_address = Address::generate(&env);
239
252
 
240
253
  // Send message with ZRO payment
241
- let receipt = oapp_client.lz_send(&sender, &REMOTE_EID, &message, &options, &fee, &refund_address);
254
+ let receipt = oapp_client.send(&sender, &REMOTE_EID, &message, &options, &fee, &refund_address);
242
255
 
243
256
  assert_eq!(receipt.fee.zro_fee, fee.zro_fee);
244
257
  }
@@ -256,7 +269,7 @@ fn test_pay_native() {
256
269
  native_token_admin_client.mint(&payer, &payment_amount);
257
270
 
258
271
  // Make payment
259
- oapp_client.pay_native(&payer, &payment_amount);
272
+ oapp_client.pay_native_fee(&payer, &payment_amount);
260
273
 
261
274
  // Verify balances
262
275
  assert_eq!(native_token_admin_client.balance(&payer), 0);
@@ -279,5 +292,5 @@ fn test_pay_native_insufficient_balance() {
279
292
  native_token_admin_client.mint(&payer, &balance);
280
293
 
281
294
  // This should panic due to insufficient balance
282
- oapp_client.pay_native(&payer, &payment_amount);
295
+ oapp_client.pay_native_fee(&payer, &payment_amount);
283
296
  }
@@ -0,0 +1,27 @@
1
+ [package]
2
+ name = "oft"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ license.workspace = true
6
+
7
+ [lib]
8
+ crate-type = ["rlib"]
9
+ doctest = false
10
+
11
+ [dependencies]
12
+ soroban-sdk = { workspace = true }
13
+ endpoint-v2 = { workspace = true, features = ["library"] }
14
+ utils = { workspace = true }
15
+ oapp = { workspace = true }
16
+ common-macros = { workspace = true }
17
+
18
+ [dev-dependencies]
19
+ soroban-sdk = { workspace = true, features = ["testutils"] }
20
+ simple-message-lib = { workspace = true }
21
+ message-lib-common = { workspace = true, features = ["testutils"] }
22
+ endpoint-v2 = { workspace = true, features = ["testutils"] }
23
+ utils = { workspace = true, features = ["testutils"] }
24
+ insta = { workspace = true }
25
+ oapp-macros = { workspace = true }
26
+ stellar-macros = { workspace = true }
27
+ stellar-tokens = { workspace = true }
@@ -0,0 +1,3 @@
1
+ pub mod setup;
2
+ pub mod test_with_sml;
3
+ pub mod utils;