@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.19

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 (262) hide show
  1. package/.turbo/turbo-build.log +365 -297
  2. package/.turbo/turbo-lint.log +142 -110
  3. package/.turbo/turbo-test.log +1273 -1222
  4. package/Cargo.lock +20 -5
  5. package/Cargo.toml +4 -1
  6. package/contracts/ERROR_SPEC.md +44 -0
  7. package/contracts/common-macros/src/auth.rs +113 -0
  8. package/contracts/common-macros/src/contract_ttl.rs +84 -0
  9. package/contracts/common-macros/src/lib.rs +181 -30
  10. package/contracts/common-macros/src/lz_contract.rs +83 -0
  11. package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
  12. package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
  13. package/contracts/common-macros/src/tests/mod.rs +2 -2
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
  16. package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap → common_macros__tests__auth__snapshot_only_auth_preserves_function_signature.snap} +4 -4
  17. package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap → common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap} +3 -3
  18. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
  19. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
  20. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
  21. package/contracts/common-macros/src/ttl_configurable.rs +19 -34
  22. package/contracts/common-macros/src/ttl_extendable.rs +36 -0
  23. package/contracts/common-macros/src/upgradeable.rs +5 -5
  24. package/contracts/common-macros/src/utils.rs +9 -0
  25. package/contracts/endpoint-v2/src/constants.rs +4 -4
  26. package/contracts/endpoint-v2/src/endpoint_v2.rs +38 -40
  27. package/contracts/endpoint-v2/src/errors.rs +4 -3
  28. package/contracts/endpoint-v2/src/events.rs +1 -1
  29. package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
  30. package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
  31. package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
  32. package/contracts/endpoint-v2/src/storage.rs +1 -1
  33. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +3 -3
  34. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
  35. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
  36. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
  38. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
  39. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
  40. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
  41. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
  42. package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
  43. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
  44. package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
  45. package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
  46. package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
  47. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
  48. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
  49. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
  50. package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
  51. package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
  52. package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
  53. package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
  54. package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
  55. package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
  56. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +3 -3
  57. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
  58. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
  59. package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
  60. package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
  61. package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
  62. package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
  63. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
  64. package/contracts/message-libs/treasury/src/errors.rs +2 -2
  65. package/contracts/message-libs/treasury/src/events.rs +1 -1
  66. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
  67. package/contracts/message-libs/treasury/src/storage.rs +1 -1
  68. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
  69. package/contracts/message-libs/treasury/src/treasury.rs +14 -16
  70. package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
  71. package/contracts/message-libs/uln-302/src/send_uln.rs +24 -4
  72. package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
  73. package/contracts/oapps/counter/Cargo.toml +14 -1
  74. package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
  75. package/contracts/oapps/counter/integration_tests/{setup.rs → setup_sml.rs} +48 -80
  76. package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
  77. package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
  78. package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
  79. package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
  80. package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
  81. package/contracts/oapps/counter/src/counter.rs +67 -43
  82. package/contracts/oapps/counter/src/tests/mod.rs +0 -13
  83. package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
  84. package/contracts/oapps/oapp/src/errors.rs +5 -1
  85. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +93 -78
  86. package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
  87. package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
  88. package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
  89. package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
  90. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -8
  91. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
  92. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
  93. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
  94. package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
  95. package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
  96. package/contracts/oapps/oft/Cargo.toml +10 -7
  97. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
  98. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
  99. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
  100. package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
  101. package/contracts/oapps/oft/integration-tests/setup.rs +29 -110
  102. package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
  103. package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -14
  104. package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
  105. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
  106. package/contracts/oapps/oft/src/lib.rs +11 -13
  107. package/contracts/oapps/oft/src/oft.rs +147 -225
  108. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -13
  109. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +31 -14
  110. package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
  111. package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
  112. package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
  113. package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +129 -30
  114. package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
  115. package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
  116. package/contracts/oapps/oft-core/src/errors.rs +13 -0
  117. package/contracts/oapps/oft-core/src/lib.rs +18 -0
  118. package/contracts/oapps/oft-core/src/oft_core.rs +439 -0
  119. package/contracts/oapps/{oft → oft-core}/src/storage.rs +2 -0
  120. package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
  121. package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +2 -2
  122. package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
  123. package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -5
  124. package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
  125. package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +78 -37
  126. package/contracts/oapps/oft-core/src/types.rs +58 -0
  127. package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
  128. package/contracts/upgrader/src/lib.rs +4 -4
  129. package/contracts/utils/src/auth.rs +44 -0
  130. package/contracts/utils/src/errors.rs +31 -5
  131. package/contracts/utils/src/lib.rs +3 -0
  132. package/contracts/utils/src/multisig.rs +211 -0
  133. package/contracts/utils/src/ownable.rs +137 -13
  134. package/contracts/utils/src/tests/buffer_reader.rs +6 -6
  135. package/contracts/utils/src/tests/buffer_writer.rs +6 -6
  136. package/contracts/utils/src/tests/bytes_ext.rs +2 -4
  137. package/contracts/utils/src/tests/mod.rs +1 -0
  138. package/contracts/utils/src/tests/multisig.rs +731 -0
  139. package/contracts/utils/src/tests/option_ext.rs +2 -5
  140. package/contracts/utils/src/tests/ownable.rs +456 -7
  141. package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
  142. package/contracts/utils/src/tests/upgradeable.rs +4 -2
  143. package/contracts/utils/src/ttl_configurable.rs +23 -8
  144. package/contracts/utils/src/ttl_extendable.rs +27 -0
  145. package/contracts/utils/src/upgradeable.rs +2 -0
  146. package/contracts/workers/dvn/Cargo.toml +1 -1
  147. package/contracts/workers/dvn/src/auth.rs +7 -7
  148. package/contracts/workers/dvn/src/dvn.rs +10 -38
  149. package/contracts/workers/dvn/src/errors.rs +0 -7
  150. package/contracts/workers/dvn/src/events.rs +1 -14
  151. package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
  152. package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
  153. package/contracts/workers/dvn/src/storage.rs +3 -13
  154. package/contracts/workers/dvn/src/tests/auth.rs +4 -4
  155. package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
  156. package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
  157. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
  158. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
  159. package/contracts/workers/dvn/src/tests/setup.rs +5 -5
  160. package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
  161. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
  162. package/contracts/workers/executor/src/auth.rs +80 -16
  163. package/contracts/workers/executor/src/executor.rs +5 -31
  164. package/contracts/workers/executor/src/storage.rs +2 -9
  165. package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
  166. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +3 -6
  167. package/contracts/workers/executor-helper/Cargo.toml +1 -1
  168. package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
  169. package/contracts/workers/price-feed/Cargo.toml +1 -1
  170. package/contracts/workers/price-feed/src/price_feed.rs +7 -10
  171. package/contracts/workers/worker/src/errors.rs +4 -0
  172. package/contracts/workers/worker/src/tests/worker.rs +7 -6
  173. package/contracts/workers/worker/src/worker.rs +20 -16
  174. package/package.json +7 -5
  175. package/sdk/.turbo/turbo-build.log +1 -0
  176. package/sdk/.turbo/turbo-test.log +1019 -0
  177. package/sdk/dist/generated/bml.d.ts +95 -8
  178. package/sdk/dist/generated/bml.js +95 -36
  179. package/sdk/dist/generated/counter.d.ts +289 -44
  180. package/sdk/dist/generated/counter.js +119 -49
  181. package/sdk/dist/generated/dvn.d.ts +312 -229
  182. package/sdk/dist/generated/dvn.js +144 -83
  183. package/sdk/dist/generated/dvn_fee_lib.d.ts +258 -63
  184. package/sdk/dist/generated/dvn_fee_lib.js +95 -26
  185. package/sdk/dist/generated/endpoint.d.ts +219 -24
  186. package/sdk/dist/generated/endpoint.js +108 -41
  187. package/sdk/dist/generated/executor.d.ts +239 -87
  188. package/sdk/dist/generated/executor.js +135 -63
  189. package/sdk/dist/generated/executor_fee_lib.d.ts +278 -74
  190. package/sdk/dist/generated/executor_fee_lib.js +135 -59
  191. package/sdk/dist/generated/executor_helper.d.ts +163 -21
  192. package/sdk/dist/generated/executor_helper.js +124 -52
  193. package/sdk/dist/generated/oft.d.ts +1842 -0
  194. package/sdk/dist/generated/oft.js +345 -0
  195. package/sdk/dist/generated/price_feed.d.ts +258 -63
  196. package/sdk/dist/generated/price_feed.js +95 -26
  197. package/sdk/dist/generated/sml.d.ts +235 -34
  198. package/sdk/dist/generated/sml.js +126 -53
  199. package/sdk/dist/generated/treasury.d.ts +1016 -0
  200. package/sdk/dist/generated/treasury.js +248 -0
  201. package/sdk/dist/generated/uln302.d.ts +235 -34
  202. package/sdk/dist/generated/uln302.js +126 -53
  203. package/sdk/dist/generated/upgrader.d.ts +17 -2
  204. package/sdk/dist/generated/upgrader.js +19 -1
  205. package/sdk/dist/index.d.ts +2 -1
  206. package/sdk/dist/index.js +2 -1
  207. package/sdk/package.json +6 -3
  208. package/sdk/src/index.ts +2 -1
  209. package/sdk/test/counter-sml.test.ts +376 -0
  210. package/sdk/test/counter-uln.test.ts +493 -0
  211. package/sdk/test/{oft.test.ts → oft-sml.test.ts} +196 -321
  212. package/sdk/test/suites/constants.ts +22 -2
  213. package/sdk/test/suites/globalSetup.ts +450 -0
  214. package/sdk/test/suites/localnet.ts +23 -6
  215. package/sdk/test/upgrader.test.ts +7 -16
  216. package/sdk/test/utils.ts +558 -85
  217. package/sdk/turbo.json +8 -0
  218. package/sdk/vitest.config.ts +21 -0
  219. package/tools/ts-bindings-gen/Cargo.toml +2 -0
  220. package/tools/ts-bindings-gen/src/main.rs +52 -4
  221. package/contracts/common-macros/src/contract_impl.rs +0 -52
  222. package/contracts/common-macros/src/ownable.rs +0 -41
  223. package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
  224. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
  225. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
  226. package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
  227. package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
  228. package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
  229. package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
  230. package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
  231. package/contracts/oapps/oapp-macros/src/util.rs +0 -107
  232. package/contracts/oapps/oft/src/constants.rs +0 -5
  233. package/contracts/oapps/oft/src/default_oft_impl.rs +0 -152
  234. package/contracts/oapps/oft/src/errors.rs +0 -8
  235. package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
  236. package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
  237. package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
  238. package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -903
  239. package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -749
  240. package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -432
  241. package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1078
  242. package/contracts/oapps/oft/src/types.rs +0 -38
  243. package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
  244. package/contracts/oapps/oft-std/src/lib.rs +0 -16
  245. package/contracts/oapps/oft-std/src/oft.rs +0 -156
  246. package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
  247. package/contracts/workers/dvn/src/multisig.rs +0 -157
  248. package/sdk/dist/generated/oft_std.d.ts +0 -1544
  249. package/sdk/dist/generated/oft_std.js +0 -271
  250. package/sdk/test/index.test.ts +0 -375
  251. /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
  252. /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
  253. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
  254. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
  255. /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
  256. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
  257. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
  258. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
  259. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
  260. /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
  261. /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
  262. /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
@@ -1,20 +1,22 @@
1
- use core::ops::Mul;
1
+ //! Utility functions for OFT-STD integration tests.
2
2
 
3
- use crate::{
4
- codec::{oft_compose_msg_codec::OFTComposeMsg, oft_msg_codec},
5
- integration_tests::setup::{decode_packet, ChainSetup},
6
- types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
7
- };
3
+ use crate::extensions::rate_limiter::Direction;
4
+ use crate::integration_tests::setup::{decode_packet, ChainSetup};
8
5
  use endpoint_v2::{MessagingFee, Origin, OutboundPacket};
9
6
  use message_lib_common::packet_codec_v1;
7
+ use oft_core::types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam};
10
8
  use soroban_sdk::{
11
9
  address_payload::AddressPayload,
12
- testutils::{Events, MockAuth, MockAuthInvoke},
10
+ testutils::{Events, Ledger, MockAuth, MockAuthInvoke},
13
11
  token::StellarAssetClient,
14
12
  xdr::ToXdr,
15
13
  Address, Bytes, BytesN, Env, IntoVal, Map, Symbol, Val, Vec,
16
14
  };
17
15
 
16
+ // ============================================================================
17
+ // Address Conversion Utilities
18
+ // ============================================================================
19
+
18
20
  pub fn address_to_peer_bytes32(address: &Address) -> BytesN<32> {
19
21
  match address.to_payload().unwrap() {
20
22
  AddressPayload::ContractIdHash(payload) => payload,
@@ -26,6 +28,16 @@ pub fn peer_bytes32_to_address(env: &Env, bytes32: &BytesN<32>) -> Address {
26
28
  AddressPayload::ContractIdHash(bytes32.clone()).to_address(env)
27
29
  }
28
30
 
31
+ #[allow(dead_code)]
32
+ pub fn create_recipient_address(env: &Env) -> Address {
33
+ let bytes = BytesN::from_array(env, &[0u8; 32]);
34
+ peer_bytes32_to_address(env, &bytes)
35
+ }
36
+
37
+ // ============================================================================
38
+ // OFT Core Operations
39
+ // ============================================================================
40
+
29
41
  pub fn quote_oft(chain: &ChainSetup<'_>, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
30
42
  chain.oft.quote_oft(send_param)
31
43
  }
@@ -49,6 +61,7 @@ pub fn quote_send(
49
61
  chain.oft.quote_send(sender, send_param, &pay_in_zro)
50
62
  }
51
63
 
64
+ /// Send without fee (standard OFT send)
52
65
  pub fn send(
53
66
  env: &Env,
54
67
  chain: &ChainSetup<'_>,
@@ -83,6 +96,88 @@ pub fn send(
83
96
  chain.oft.send(sender, send_param, fee, refund_address);
84
97
  }
85
98
 
99
+ /// Send with fee (OFT fee extension enabled)
100
+ /// Order: transfer fee to deposit -> burn tokens -> transfer native fee
101
+ pub fn send_with_fee(
102
+ env: &Env,
103
+ chain: &ChainSetup<'_>,
104
+ sender: &Address,
105
+ send_param: &SendParam,
106
+ fee: &MessagingFee,
107
+ refund_address: &Address,
108
+ oft_receipt: &OFTReceipt,
109
+ fee_deposit_address: &Address,
110
+ ) {
111
+ let fee_amount = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
112
+ env.mock_auths(&[MockAuth {
113
+ address: sender,
114
+ invoke: &MockAuthInvoke {
115
+ contract: &chain.oft.address,
116
+ fn_name: "send",
117
+ args: (sender, send_param, fee, refund_address).into_val(env),
118
+ sub_invokes: &[
119
+ MockAuthInvoke {
120
+ contract: &chain.oft_token,
121
+ fn_name: "transfer",
122
+ args: (sender, fee_deposit_address, &fee_amount).into_val(env),
123
+ sub_invokes: &[],
124
+ },
125
+ MockAuthInvoke {
126
+ contract: &chain.oft_token,
127
+ fn_name: "burn",
128
+ args: (sender, &oft_receipt.amount_received_ld).into_val(env),
129
+ sub_invokes: &[],
130
+ },
131
+ MockAuthInvoke {
132
+ contract: &chain.native_token,
133
+ fn_name: "transfer",
134
+ args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
135
+ sub_invokes: &[],
136
+ },
137
+ ],
138
+ },
139
+ }]);
140
+ chain.oft.send(sender, send_param, fee, refund_address);
141
+ }
142
+
143
+ pub fn try_send(
144
+ env: &Env,
145
+ chain: &ChainSetup<'_>,
146
+ sender: &Address,
147
+ send_param: &SendParam,
148
+ fee: &MessagingFee,
149
+ refund_address: &Address,
150
+ oft_receipt: &OFTReceipt,
151
+ ) -> bool {
152
+ env.mock_auths(&[MockAuth {
153
+ address: sender,
154
+ invoke: &MockAuthInvoke {
155
+ contract: &chain.oft.address,
156
+ fn_name: "send",
157
+ args: (sender, send_param, fee, refund_address).into_val(env),
158
+ sub_invokes: &[
159
+ MockAuthInvoke {
160
+ contract: &chain.native_token,
161
+ fn_name: "transfer",
162
+ args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
163
+ sub_invokes: &[],
164
+ },
165
+ MockAuthInvoke {
166
+ contract: &chain.oft_token,
167
+ fn_name: "burn",
168
+ args: (sender, &oft_receipt.amount_received_ld).into_val(env),
169
+ sub_invokes: &[],
170
+ },
171
+ ],
172
+ },
173
+ }]);
174
+ chain.oft.try_send(sender, send_param, fee, refund_address).is_ok()
175
+ }
176
+
177
+ // ============================================================================
178
+ // Packet Handling
179
+ // ============================================================================
180
+
86
181
  pub fn validate_packet(env: &Env, chain: &ChainSetup<'_>, packet_event: &(Bytes, Bytes, Address)) {
87
182
  let packet = decode_packet(env, &packet_event.0);
88
183
  let encoded_header = packet_codec_v1::encode_packet_header(env, &packet);
@@ -131,26 +226,30 @@ pub fn lz_receive(
131
226
  );
132
227
  }
133
228
 
134
- pub fn lz_compose(
229
+ pub fn try_lz_receive(
135
230
  env: &Env,
136
231
  chain: &ChainSetup<'_>,
137
232
  executor: &Address,
138
233
  packet: &OutboundPacket,
139
- index: u32,
140
- extra_data: &Bytes,
234
+ recipient: &Address,
141
235
  value: i128,
142
- ) {
143
- let oft_msg = oft_msg_codec::OFTMessage::decode(&packet.message);
144
- let oft_compose_msg = OFTComposeMsg {
145
- nonce: packet.nonce,
146
- src_eid: packet.src_eid,
147
- amount_ld: (oft_msg.amount_sd as i128).mul(chain.oft.decimal_conversion_rate()),
148
- compose_from: oft_msg.compose_from.unwrap(),
149
- compose_msg: oft_msg.compose_msg.unwrap(),
150
- }
151
- .encode(&env);
236
+ ) -> bool {
237
+ let origin =
238
+ Origin { src_eid: packet.src_eid, sender: address_to_peer_bytes32(&packet.sender), nonce: packet.nonce };
239
+ let extra_options = recipient.to_xdr(env);
152
240
 
153
- chain.composer.lz_compose(executor, &chain.oft.address, &packet.guid, &index, &oft_compose_msg, extra_data, &value);
241
+ env.mock_auths(&[MockAuth {
242
+ address: executor,
243
+ invoke: &MockAuthInvoke {
244
+ contract: &chain.oft.address,
245
+ fn_name: "lz_receive",
246
+ args: (executor, &origin, &packet.guid, &packet.message, &extra_options, &value).into_val(env),
247
+ sub_invokes: &[],
248
+ },
249
+ }]);
250
+ endpoint_v2::LayerZeroReceiverClient::new(env, &chain.oft.address)
251
+ .try_lz_receive(executor, &origin, &packet.guid, &packet.message, &extra_options, &value)
252
+ .is_ok()
154
253
  }
155
254
 
156
255
  // returns (encoded_payload, options, send_library)
@@ -172,6 +271,10 @@ pub fn scan_packet_sent_event(env: &Env, endpoint: &Address) -> Option<(Bytes, B
172
271
  packet
173
272
  }
174
273
 
274
+ // ============================================================================
275
+ // Token Operations
276
+ // ============================================================================
277
+
175
278
  pub fn mint_to(env: &Env, owner: &Address, token: &Address, to: &Address, amount: i128) {
176
279
  env.mock_auths(&[MockAuth {
177
280
  address: owner,
@@ -199,3 +302,133 @@ pub fn transfer_sac_admin(env: &Env, owner: &Address, token: &Address, new_admin
199
302
  }]);
200
303
  StellarAssetClient::new(env, token).set_admin(new_admin);
201
304
  }
305
+
306
+ pub fn token_balance(env: &Env, token: &Address, account: &Address) -> i128 {
307
+ soroban_sdk::token::TokenClient::new(env, token).balance(account)
308
+ }
309
+
310
+ // ============================================================================
311
+ // Pausable Extension Operations
312
+ // ============================================================================
313
+
314
+ pub fn set_paused(env: &Env, chain: &ChainSetup<'_>, paused: bool) {
315
+ env.mock_auths(&[MockAuth {
316
+ address: &chain.owner,
317
+ invoke: &MockAuthInvoke {
318
+ contract: &chain.oft.address,
319
+ fn_name: "set_paused",
320
+ args: (&paused,).into_val(env),
321
+ sub_invokes: &[],
322
+ },
323
+ }]);
324
+ chain.oft.set_paused(&paused);
325
+ }
326
+
327
+ pub fn is_paused(chain: &ChainSetup<'_>) -> bool {
328
+ chain.oft.is_paused()
329
+ }
330
+
331
+ // ============================================================================
332
+ // OFT Fee Extension Operations
333
+ // ============================================================================
334
+
335
+ pub fn set_fee_deposit_address(env: &Env, chain: &ChainSetup<'_>, deposit_address: &Address) {
336
+ env.mock_auths(&[MockAuth {
337
+ address: &chain.owner,
338
+ invoke: &MockAuthInvoke {
339
+ contract: &chain.oft.address,
340
+ fn_name: "set_fee_deposit_address",
341
+ args: (deposit_address,).into_val(env),
342
+ sub_invokes: &[],
343
+ },
344
+ }]);
345
+ chain.oft.set_fee_deposit_address(deposit_address);
346
+ }
347
+
348
+ pub fn set_default_fee_bps(env: &Env, chain: &ChainSetup<'_>, fee_bps: u64) {
349
+ env.mock_auths(&[MockAuth {
350
+ address: &chain.owner,
351
+ invoke: &MockAuthInvoke {
352
+ contract: &chain.oft.address,
353
+ fn_name: "set_default_fee_bps",
354
+ args: (&fee_bps,).into_val(env),
355
+ sub_invokes: &[],
356
+ },
357
+ }]);
358
+ chain.oft.set_default_fee_bps(&fee_bps);
359
+ }
360
+
361
+ pub fn set_fee_bps(env: &Env, chain: &ChainSetup<'_>, dst_eid: u32, fee_bps: u64) {
362
+ env.mock_auths(&[MockAuth {
363
+ address: &chain.owner,
364
+ invoke: &MockAuthInvoke {
365
+ contract: &chain.oft.address,
366
+ fn_name: "set_fee_bps",
367
+ args: (&dst_eid, &fee_bps).into_val(env),
368
+ sub_invokes: &[],
369
+ },
370
+ }]);
371
+ chain.oft.set_fee_bps(&dst_eid, &fee_bps);
372
+ }
373
+
374
+ // ============================================================================
375
+ // Rate Limiter Extension Operations
376
+ // ============================================================================
377
+
378
+ pub fn set_rate_limit(
379
+ env: &Env,
380
+ chain: &ChainSetup<'_>,
381
+ direction: &Direction,
382
+ dst_eid: u32,
383
+ limit: i128,
384
+ window_seconds: u64,
385
+ ) {
386
+ env.mock_auths(&[MockAuth {
387
+ address: &chain.owner,
388
+ invoke: &MockAuthInvoke {
389
+ contract: &chain.oft.address,
390
+ fn_name: "set_rate_limit",
391
+ args: (direction, &dst_eid, &limit, &window_seconds).into_val(env),
392
+ sub_invokes: &[],
393
+ },
394
+ }]);
395
+ chain.oft.set_rate_limit(direction, &dst_eid, &limit, &window_seconds);
396
+ }
397
+
398
+ pub fn rate_limit_capacity(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
399
+ chain.oft.rate_limit_capacity(direction, &eid)
400
+ }
401
+
402
+ pub fn rate_limit_in_flight(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
403
+ chain.oft.rate_limit_in_flight(direction, &eid)
404
+ }
405
+
406
+ // ============================================================================
407
+ // Time Utilities
408
+ // ============================================================================
409
+
410
+ pub fn advance_time(env: &Env, seconds: u64) {
411
+ let current = env.ledger().timestamp();
412
+ env.ledger().set_timestamp(current + seconds);
413
+ }
414
+
415
+ #[allow(dead_code)]
416
+ pub fn set_timestamp(env: &Env, timestamp: u64) {
417
+ env.ledger().set_timestamp(timestamp);
418
+ }
419
+
420
+ // ============================================================================
421
+ // SendParam Builder
422
+ // ============================================================================
423
+
424
+ pub fn create_send_param(env: &Env, dst_eid: u32, amount_ld: i128, min_amount_ld: i128, to: &BytesN<32>) -> SendParam {
425
+ SendParam {
426
+ dst_eid,
427
+ to: to.clone(),
428
+ amount_ld,
429
+ min_amount_ld,
430
+ extra_options: Bytes::new(env),
431
+ compose_msg: Bytes::new(env),
432
+ oft_cmd: Bytes::new(env),
433
+ }
434
+ }
@@ -1,5 +1,5 @@
1
- use common_macros::{contract_error, only_owner, storage};
2
- use soroban_sdk::{assert_with_error, contractevent, contracttrait, token::TokenClient, Address, Env};
1
+ use common_macros::{contract_error, contract_trait, only_auth, storage};
2
+ use soroban_sdk::{assert_with_error, contractevent, token::TokenClient, Address, Env};
3
3
  use utils::{option_ext::OptionExt, ownable::Ownable};
4
4
 
5
5
  /// Base fee in basis points (10,000 BPS = 100%)
@@ -52,9 +52,9 @@ pub struct FeeDepositAddressSet {
52
52
  pub fee_deposit_address: Address,
53
53
  }
54
54
 
55
- #[contracttrait]
55
+ #[contract_trait]
56
56
  pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
57
- #[only_owner]
57
+ #[only_auth]
58
58
  fn set_default_fee_bps(env: &Env, default_fee_bps: u64) {
59
59
  assert_with_error!(env, default_fee_bps <= BASE_FEE_BPS, OFTFeeError::InvalidFeeBps);
60
60
  let current_default = OFTFeeStorage::default_fee_bps(env);
@@ -63,7 +63,7 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
63
63
  DefaultFeeBpsSet { fee_bps: default_fee_bps }.publish(env);
64
64
  }
65
65
 
66
- #[only_owner]
66
+ #[only_auth]
67
67
  fn set_fee_bps(env: &Env, dst_eid: u32, fee_bps: u64) {
68
68
  assert_with_error!(env, fee_bps <= BASE_FEE_BPS, OFTFeeError::InvalidFeeBps);
69
69
  if OFTFeeStorage::has_fee_bps(env, dst_eid) {
@@ -74,14 +74,14 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
74
74
  FeeBpsSet { dst_eid, fee_bps }.publish(env);
75
75
  }
76
76
 
77
- #[only_owner]
77
+ #[only_auth]
78
78
  fn unset_fee_bps(env: &Env, dst_eid: u32) {
79
79
  assert_with_error!(env, OFTFeeStorage::has_fee_bps(env, dst_eid), OFTFeeError::NotFound);
80
80
  OFTFeeStorage::remove_fee_bps(env, dst_eid);
81
81
  FeeBpsUnset { dst_eid }.publish(env);
82
82
  }
83
83
 
84
- #[only_owner]
84
+ #[only_auth]
85
85
  fn set_fee_deposit_address(env: &Env, fee_deposit_address: Address) {
86
86
  if let Some(current_address) = OFTFeeStorage::fee_deposit_address(env) {
87
87
  assert_with_error!(env, current_address != fee_deposit_address, OFTFeeError::SameValue);
@@ -118,15 +118,15 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
118
118
  /// Internal trait for OFT fee operations used by OFT hooks.
119
119
  /// Contains only truly internal methods that are called from OFTInner implementations.
120
120
  pub trait OFTFeeInternal {
121
- /// Calculates the amount after fee deduction (read-only, mirrors `__debit_view`).
122
- /// Used internally by `__debit_view` to calculate amount after fee.
121
+ /// Calculates the fee amount for a given transfer (read-only).
122
+ /// Used internally by `__debit_view` to calculate the fee.
123
123
  ///
124
124
  /// # Arguments
125
125
  /// * `dst_eid` - Destination endpoint ID to determine which fee rate to apply
126
126
  /// * `amount_ld` - The original amount in local decimals
127
127
  ///
128
128
  /// # Returns
129
- /// The amount after fee deduction (original amount - calculated fee)
129
+ /// The fee amount to be deducted
130
130
  fn __fee_view(env: &Env, dst_eid: u32, amount_ld: i128) -> i128 {
131
131
  // Calculate effective fee (destination-specific or default)
132
132
  let fee_bps = if OFTFeeStorage::has_fee_bps(env, dst_eid) {
@@ -135,7 +135,7 @@ pub trait OFTFeeInternal {
135
135
  OFTFeeStorage::default_fee_bps(env)
136
136
  };
137
137
  if fee_bps == 0 {
138
- return amount_ld;
138
+ return 0;
139
139
  }
140
140
  // Check that fee deposit address is set (required for fee collection)
141
141
  assert_with_error!(
@@ -143,8 +143,7 @@ pub trait OFTFeeInternal {
143
143
  OFTFeeStorage::fee_deposit_address(env).is_some(),
144
144
  OFTFeeError::InvalidFeeDepositAddress
145
145
  );
146
- let preliminary_fee = (amount_ld * fee_bps as i128) / BASE_FEE_BPS as i128;
147
- amount_ld - preliminary_fee
146
+ (amount_ld * fee_bps as i128) / BASE_FEE_BPS as i128
148
147
  }
149
148
 
150
149
  /// Charges the fee by transferring the fee amount from sender to the fee deposit address.
@@ -155,7 +154,7 @@ pub trait OFTFeeInternal {
155
154
  /// * `sender` - The sender address to transfer fee from
156
155
  /// * `fee_amount` - The fee amount to transfer
157
156
  fn __charge_fee(env: &Env, token: &Address, sender: &Address, fee_amount: i128) {
158
- if fee_amount > 0 {
157
+ if fee_amount != 0 {
159
158
  assert_with_error!(
160
159
  env,
161
160
  OFTFeeStorage::fee_deposit_address(env).is_some(),
@@ -1,5 +1,5 @@
1
- use common_macros::{contract_error, only_owner, storage};
2
- use soroban_sdk::{assert_with_error, contractevent, contracttrait, Env};
1
+ use common_macros::{contract_error, contract_trait, only_auth, storage};
2
+ use soroban_sdk::{assert_with_error, contractevent, Env};
3
3
  use utils::ownable::Ownable;
4
4
 
5
5
  #[storage]
@@ -21,9 +21,9 @@ pub struct PausedSet {
21
21
  pub paused: bool,
22
22
  }
23
23
 
24
- #[contracttrait]
24
+ #[contract_trait]
25
25
  pub trait OFTPausable: OFTPausableInternal + Ownable + Sized {
26
- #[only_owner]
26
+ #[only_auth]
27
27
  fn set_paused(env: &Env, paused: bool) {
28
28
  let current_paused = OFTPausableStorage::paused(env);
29
29
  assert_with_error!(env, current_paused != paused, OFTPausableError::PauseStatusUnchanged);
@@ -1,5 +1,5 @@
1
- use common_macros::{contract_error, only_owner, storage};
2
- use soroban_sdk::{assert_with_error, contractevent, contracttrait, contracttype, panic_with_error, Env};
1
+ use common_macros::{contract_error, contract_trait, only_auth, storage};
2
+ use soroban_sdk::{assert_with_error, contractevent, contracttype, panic_with_error, Env};
3
3
  use utils::ownable::Ownable;
4
4
 
5
5
  #[contracttype]
@@ -87,9 +87,9 @@ fn checkpoint_rate_limit_in_flight(env: &Env, direction: &Direction, eid: u32) {
87
87
  RateLimitStorage::set_rate_limit(env, direction, eid, &rate_limit);
88
88
  }
89
89
 
90
- #[contracttrait]
90
+ #[contract_trait]
91
91
  pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
92
- #[only_owner]
92
+ #[only_auth]
93
93
  fn set_rate_limit(env: &Env, direction: &Direction, eid: u32, limit: i128, window_seconds: u64) {
94
94
  assert_with_error!(env, limit > 0, RateLimitError::InvalidLimit);
95
95
  assert_with_error!(env, window_seconds > 0, RateLimitError::InvalidWindowSeconds);
@@ -122,7 +122,7 @@ pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
122
122
  }
123
123
  }
124
124
 
125
- #[only_owner]
125
+ #[only_auth]
126
126
  fn unset_rate_limit(env: &Env, direction: &Direction, eid: u32) {
127
127
  assert_with_error!(env, RateLimitStorage::has_rate_limit(env, direction, eid), RateLimitError::SameValue);
128
128
  RateLimitStorage::remove_rate_limit(env, direction, eid);
@@ -1,21 +1,19 @@
1
1
  #![no_std]
2
2
 
3
- pub mod codec;
4
- pub mod constants;
5
- pub mod default_oft_impl;
6
- pub mod errors;
7
- pub mod events;
8
3
  pub mod extensions;
9
- pub mod interfaces;
10
- pub mod oft;
11
4
  pub mod oft_types;
12
- pub mod storage;
13
- pub mod types;
14
- pub mod utils;
5
+
6
+ pub use extensions::*;
7
+ pub use oft_types::*;
8
+
9
+ cfg_if::cfg_if! {
10
+ // Include implementation when NOT in library mode, OR when testutils is enabled (for tests)
11
+ if #[cfg(any(not(feature = "library"), feature = "testutils"))] {
12
+ mod oft;
13
+ pub use oft::*;
14
+ }
15
+ }
15
16
 
16
17
  #[cfg(test)]
17
18
  #[path = "../integration-tests/mod.rs"]
18
19
  pub mod integration_tests;
19
-
20
- #[cfg(test)]
21
- pub mod tests;