@layerzerolabs/protocol-stellar-v2 0.2.13 → 0.2.18

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 (435) hide show
  1. package/.turbo/turbo-build.log +484 -337
  2. package/.turbo/turbo-lint.log +126 -56
  3. package/.turbo/turbo-test.log +1403 -984
  4. package/Cargo.lock +142 -3
  5. package/Cargo.toml +5 -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 +219 -29
  10. package/contracts/common-macros/src/lz_contract.rs +83 -0
  11. package/contracts/common-macros/src/storage.rs +1 -1
  12. package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
  13. package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
  14. package/contracts/common-macros/src/tests/mod.rs +3 -2
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
  16. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
  17. 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
  18. 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} +26 -10
  19. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
  20. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +48 -48
  21. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -41
  22. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +21 -0
  23. package/contracts/common-macros/src/tests/upgradeable.rs +31 -0
  24. package/contracts/common-macros/src/ttl_configurable.rs +21 -66
  25. package/contracts/common-macros/src/ttl_extendable.rs +36 -0
  26. package/contracts/common-macros/src/upgradeable.rs +76 -0
  27. package/contracts/common-macros/src/utils.rs +9 -0
  28. package/contracts/endpoint-v2/src/constants.rs +4 -4
  29. package/contracts/endpoint-v2/src/endpoint_v2.rs +58 -36
  30. package/contracts/endpoint-v2/src/errors.rs +4 -3
  31. package/contracts/endpoint-v2/src/events.rs +1 -1
  32. package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
  33. package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
  34. package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
  35. package/contracts/endpoint-v2/src/storage.rs +1 -1
  36. package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +175 -8
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/build_outbound_packet.rs +76 -0
  38. package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +342 -159
  39. package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +3 -15
  40. package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +20 -31
  41. package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +126 -164
  42. package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +1 -0
  43. package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +0 -1
  44. package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +0 -1
  45. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +311 -304
  46. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +423 -96
  47. package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +1 -1
  48. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +47 -20
  49. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +373 -403
  50. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +96 -22
  51. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +62 -10
  52. package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +4 -4
  53. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +8 -11
  54. package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +81 -30
  55. package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +209 -76
  56. package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +0 -1
  57. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library.rs +24 -0
  58. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library_timeout.rs +40 -0
  59. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_send_library.rs +24 -0
  60. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_config.rs +108 -0
  61. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_library_index.rs +52 -0
  62. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_receive_library.rs +92 -0
  63. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_registered_libraries.rs +74 -0
  64. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_send_library.rs +83 -0
  65. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_registered_library.rs +32 -0
  66. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_supported_eid.rs +28 -0
  67. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_valid_receive_library.rs +261 -0
  68. package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +16 -0
  69. package/contracts/endpoint-v2/src/tests/message_lib_manager/receive_library_timeout.rs +62 -0
  70. package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +65 -43
  71. package/contracts/endpoint-v2/src/tests/message_lib_manager/registered_libraries_count.rs +42 -0
  72. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +61 -0
  73. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +4 -6
  74. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +59 -0
  75. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +16 -2
  76. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +155 -51
  77. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +114 -92
  78. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +235 -132
  79. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +93 -87
  80. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +346 -245
  81. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +406 -60
  82. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +252 -78
  83. package/contracts/endpoint-v2/src/tests/message_lib_manager/timeout.rs +102 -0
  84. package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +212 -273
  85. package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +203 -0
  86. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +94 -0
  87. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +78 -248
  88. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +7 -282
  89. package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +6 -274
  90. package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +3 -2
  91. package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +86 -178
  92. package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +328 -212
  93. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound.rs +68 -0
  94. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +6 -209
  95. package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +207 -159
  96. package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +142 -153
  97. package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +6 -179
  98. package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +163 -221
  99. package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +90 -121
  100. package/contracts/endpoint-v2/src/tests/mock.rs +18 -4
  101. package/contracts/endpoint-v2/src/tests/util/build_payload.rs +4 -70
  102. package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +2 -1
  103. package/contracts/endpoint-v2/src/tests/util/keccak256.rs +17 -106
  104. package/contracts/layerzero-views/Cargo.toml +35 -0
  105. package/contracts/layerzero-views/src/errors.rs +10 -0
  106. package/contracts/layerzero-views/src/layerzero_view.rs +226 -0
  107. package/contracts/layerzero-views/src/lib.rs +38 -0
  108. package/contracts/layerzero-views/src/storage.rs +18 -0
  109. package/contracts/layerzero-views/src/tests/layerzero_view_tests.rs +423 -0
  110. package/contracts/layerzero-views/src/tests/mod.rs +4 -0
  111. package/contracts/layerzero-views/src/tests/setup.rs +377 -0
  112. package/contracts/layerzero-views/src/types.rs +50 -0
  113. package/contracts/macro-integration-tests/Cargo.toml +30 -0
  114. package/contracts/macro-integration-tests/src/lib.rs +1 -0
  115. package/contracts/macro-integration-tests/tests/runtime/ownable/initialization.rs +62 -0
  116. package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +22 -0
  117. package/contracts/macro-integration-tests/tests/runtime/ownable/only_auth_guard.rs +97 -0
  118. package/contracts/macro-integration-tests/tests/runtime/ownable/ownership_transfer.rs +101 -0
  119. package/contracts/macro-integration-tests/tests/runtime/storage/keyed_roundtrip.rs +225 -0
  120. package/contracts/macro-integration-tests/tests/runtime/storage/mod.rs +4 -0
  121. package/contracts/macro-integration-tests/tests/runtime/storage/name_override_runtime.rs +52 -0
  122. package/contracts/macro-integration-tests/tests/runtime/storage/ttl_extension.rs +261 -0
  123. package/contracts/macro-integration-tests/tests/runtime/storage/unkeyed_roundtrip.rs +137 -0
  124. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +113 -0
  125. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +139 -0
  126. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +2 -0
  127. package/contracts/macro-integration-tests/tests/runtime.rs +5 -0
  128. package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.rs +12 -0
  129. package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.stderr +7 -0
  130. package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.rs +12 -0
  131. package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.stderr +7 -0
  132. package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.rs +21 -0
  133. package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.stderr +7 -0
  134. package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.rs +13 -0
  135. package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.stderr +7 -0
  136. package/contracts/macro-integration-tests/tests/ui/error/pass/attr_on_variant_allowed.rs +20 -0
  137. package/contracts/macro-integration-tests/tests/ui/error/pass/basic_auto_discriminants.rs +15 -0
  138. package/contracts/macro-integration-tests/tests/ui/error/pass/mixed_discriminants.rs +16 -0
  139. package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.rs +22 -0
  140. package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.stderr +16 -0
  141. package/contracts/macro-integration-tests/tests/ui/ownable/pass/minimal_contract.rs +26 -0
  142. package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +21 -0
  143. package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_auth_env_param_variants.rs +46 -0
  144. package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.rs +13 -0
  145. package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.stderr +7 -0
  146. package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.rs +13 -0
  147. package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.stderr +7 -0
  148. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.rs +10 -0
  149. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.stderr +7 -0
  150. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.rs +12 -0
  151. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.stderr +7 -0
  152. package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.rs +10 -0
  153. package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.stderr +7 -0
  154. package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.rs +10 -0
  155. package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.stderr +7 -0
  156. package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.rs +12 -0
  157. package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.stderr +7 -0
  158. package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.rs +13 -0
  159. package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.stderr +7 -0
  160. package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.rs +13 -0
  161. package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.stderr +7 -0
  162. package/contracts/macro-integration-tests/tests/ui/storage/pass/default_value_on_variant.rs +14 -0
  163. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_instance_unit_basic.rs +14 -0
  164. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_persistent_named_fields_keyed.rs +16 -0
  165. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_temporary_unit_option.rs +15 -0
  166. package/contracts/macro-integration-tests/tests/ui/storage/pass/name_override.rs +14 -0
  167. package/contracts/macro-integration-tests/tests/ui/storage/pass/no_auto_ttl_extension.rs +19 -0
  168. package/contracts/macro-integration-tests/tests/ui/storage/pass/ttl_provider_basic.rs +15 -0
  169. package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +44 -0
  170. package/contracts/macro-integration-tests/tests/ui_error.rs +11 -0
  171. package/contracts/macro-integration-tests/tests/ui_ownable.rs +11 -0
  172. package/contracts/macro-integration-tests/tests/ui_storage.rs +11 -0
  173. package/contracts/macro-integration-tests/tests/ui_ttl_configurable.rs +12 -0
  174. package/contracts/message-libs/blocked-message-lib/src/lib.rs +17 -17
  175. package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
  176. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +64 -0
  177. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet.rs +58 -0
  178. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet_header.rs +138 -0
  179. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/mod.rs +6 -0
  180. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload.rs +30 -0
  181. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload_hash.rs +15 -0
  182. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/test_helper.rs +39 -0
  183. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_dvn_option.rs +57 -0
  184. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +49 -0
  185. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +73 -0
  186. package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +280 -0
  187. package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +126 -0
  188. package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +48 -0
  189. package/contracts/message-libs/message-lib-common/src/tests/worker_options/mod.rs +7 -0
  190. package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +139 -0
  191. package/contracts/message-libs/message-lib-common/src/worker_options.rs +31 -1
  192. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
  193. package/contracts/message-libs/treasury/src/errors.rs +2 -3
  194. package/contracts/message-libs/treasury/src/events.rs +1 -1
  195. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
  196. package/contracts/message-libs/treasury/src/lib.rs +3 -3
  197. package/contracts/message-libs/treasury/src/storage.rs +3 -1
  198. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
  199. package/contracts/message-libs/treasury/src/treasury.rs +23 -26
  200. package/contracts/message-libs/uln-302/Cargo.toml +1 -1
  201. package/contracts/message-libs/uln-302/src/errors.rs +0 -5
  202. package/contracts/message-libs/uln-302/src/events.rs +5 -6
  203. package/contracts/message-libs/uln-302/src/receive_uln.rs +37 -56
  204. package/contracts/message-libs/uln-302/src/send_uln.rs +112 -138
  205. package/contracts/message-libs/uln-302/src/storage.rs +5 -5
  206. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +5 -7
  207. package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +3 -3
  208. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +6 -9
  209. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
  210. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +3 -3
  211. package/contracts/message-libs/uln-302/src/tests/setup.rs +9 -0
  212. package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +5 -0
  213. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +1 -2
  214. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +1 -2
  215. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +37 -55
  216. package/contracts/message-libs/uln-302/src/uln302.rs +10 -25
  217. package/contracts/oapps/counter/Cargo.toml +14 -1
  218. package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
  219. package/contracts/oapps/counter/integration_tests/setup_sml.rs +169 -0
  220. package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
  221. package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
  222. package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
  223. package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
  224. package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
  225. package/contracts/oapps/counter/src/counter.rs +67 -44
  226. package/contracts/oapps/counter/src/tests/mod.rs +0 -13
  227. package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
  228. package/contracts/oapps/oapp/src/errors.rs +5 -1
  229. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +318 -221
  230. package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
  231. package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
  232. package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
  233. package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
  234. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -9
  235. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -18
  236. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -8
  237. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -16
  238. package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
  239. package/contracts/oapps/oapp-macros/src/lib.rs +211 -0
  240. package/contracts/oapps/oft/integration-tests/setup.rs +34 -9
  241. package/contracts/oapps/oft/integration-tests/utils.rs +1 -1
  242. package/contracts/oapps/oft/src/errors.rs +6 -1
  243. package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -13
  244. package/contracts/oapps/oft/src/extensions/pausable.rs +5 -5
  245. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +23 -23
  246. package/contracts/oapps/oft/src/lib.rs +4 -2
  247. package/contracts/oapps/oft/src/oft.rs +31 -71
  248. package/contracts/oapps/oft/src/oft_impl.rs +201 -0
  249. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +2 -4
  250. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -4
  251. package/contracts/oapps/oft/src/storage.rs +2 -0
  252. package/contracts/oapps/oft/src/tests/extensions/setup.rs +60 -31
  253. package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +5 -3
  254. package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +5 -3
  255. package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +6 -4
  256. package/contracts/oapps/oft/src/tests/test_decimals.rs +2 -2
  257. package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +1 -2
  258. package/contracts/oapps/oft/src/tests/test_send.rs +4 -4
  259. package/contracts/oapps/oft/src/tests/test_utils.rs +122 -81
  260. package/contracts/oapps/oft/src/types.rs +20 -0
  261. package/contracts/oapps/oft-std/Cargo.toml +6 -0
  262. package/contracts/oapps/oft-std/integration-tests/extensions/mod.rs +3 -0
  263. package/contracts/oapps/oft-std/integration-tests/extensions/test_oft_fee.rs +157 -0
  264. package/contracts/oapps/oft-std/integration-tests/extensions/test_pausable.rs +162 -0
  265. package/contracts/oapps/oft-std/integration-tests/extensions/test_rate_limiter.rs +186 -0
  266. package/contracts/oapps/oft-std/integration-tests/mod.rs +3 -0
  267. package/contracts/oapps/{counter/integration_tests → oft-std/integration-tests}/setup.rs +76 -30
  268. package/contracts/oapps/oft-std/integration-tests/utils.rs +427 -0
  269. package/contracts/oapps/oft-std/src/lib.rs +12 -1
  270. package/contracts/oapps/oft-std/src/oft.rs +141 -26
  271. package/contracts/upgrader/Cargo.toml +19 -0
  272. package/contracts/upgrader/src/lib.rs +96 -0
  273. package/contracts/upgrader/src/tests/mod.rs +1 -0
  274. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract1.wasm +0 -0
  275. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract2.wasm +0 -0
  276. package/contracts/upgrader/src/tests/test_upgrader.rs +120 -0
  277. package/contracts/utils/src/auth.rs +44 -0
  278. package/contracts/utils/src/errors.rs +32 -5
  279. package/contracts/utils/src/lib.rs +5 -1
  280. package/contracts/utils/src/multisig.rs +211 -0
  281. package/contracts/utils/src/ownable.rs +50 -60
  282. package/contracts/utils/src/tests/buffer_reader.rs +6 -6
  283. package/contracts/utils/src/tests/buffer_writer.rs +6 -6
  284. package/contracts/utils/src/tests/bytes_ext.rs +2 -4
  285. package/contracts/utils/src/tests/mod.rs +4 -1
  286. package/contracts/utils/src/tests/multisig.rs +731 -0
  287. package/contracts/utils/src/tests/option_ext.rs +18 -0
  288. package/contracts/utils/src/tests/ownable.rs +22 -70
  289. package/contracts/utils/src/tests/ttl_configurable.rs +607 -0
  290. package/contracts/utils/src/tests/upgradeable.rs +290 -0
  291. package/contracts/utils/src/ttl_configurable.rs +153 -0
  292. package/contracts/utils/src/ttl_extendable.rs +27 -0
  293. package/contracts/utils/src/upgradeable.rs +56 -0
  294. package/contracts/workers/dvn/Cargo.toml +2 -2
  295. package/contracts/workers/dvn/src/auth.rs +24 -35
  296. package/contracts/workers/dvn/src/dvn.rs +23 -14
  297. package/contracts/workers/dvn/src/errors.rs +1 -7
  298. package/contracts/workers/dvn/src/events.rs +1 -14
  299. package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
  300. package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
  301. package/contracts/workers/dvn/src/storage.rs +3 -13
  302. package/contracts/workers/dvn/src/tests/auth.rs +4 -4
  303. package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
  304. package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
  305. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
  306. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
  307. package/contracts/workers/dvn/src/tests/setup.rs +5 -5
  308. package/contracts/workers/dvn-fee-lib/Cargo.toml +0 -1
  309. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +45 -16
  310. package/contracts/workers/dvn-fee-lib/src/errors.rs +3 -2
  311. package/contracts/workers/dvn-fee-lib/src/lib.rs +5 -11
  312. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +30 -16
  313. package/contracts/workers/executor/src/auth.rs +80 -16
  314. package/contracts/workers/executor/src/executor.rs +17 -29
  315. package/contracts/workers/executor/src/storage.rs +2 -9
  316. package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
  317. package/contracts/workers/executor-fee-lib/src/errors.rs +9 -7
  318. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +153 -121
  319. package/contracts/workers/executor-helper/Cargo.toml +1 -6
  320. package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
  321. package/contracts/workers/executor-helper/src/lib.rs +1 -7
  322. package/contracts/workers/price-feed/Cargo.toml +1 -2
  323. package/contracts/workers/price-feed/src/errors.rs +3 -2
  324. package/contracts/workers/price-feed/src/lib.rs +5 -6
  325. package/contracts/workers/price-feed/src/price_feed.rs +42 -23
  326. package/contracts/workers/worker/Cargo.toml +4 -0
  327. package/contracts/workers/worker/src/errors.rs +4 -0
  328. package/contracts/workers/worker/src/interfaces/price_feed.rs +3 -3
  329. package/contracts/workers/worker/src/lib.rs +2 -2
  330. package/contracts/workers/worker/src/tests/mod.rs +4 -0
  331. package/contracts/workers/worker/src/tests/setup.rs +147 -0
  332. package/contracts/workers/worker/src/tests/worker.rs +502 -0
  333. package/contracts/workers/worker/src/worker.rs +28 -30
  334. package/package.json +8 -5
  335. package/sdk/.turbo/turbo-build.log +1 -0
  336. package/sdk/.turbo/turbo-test.log +1009 -0
  337. package/sdk/dist/generated/bml.d.ts +104 -37
  338. package/sdk/dist/generated/bml.js +83 -42
  339. package/sdk/dist/generated/counter.d.ts +334 -175
  340. package/sdk/dist/generated/counter.js +109 -63
  341. package/sdk/dist/generated/dvn.d.ts +1985 -0
  342. package/sdk/dist/generated/dvn.js +326 -0
  343. package/sdk/dist/generated/dvn_fee_lib.d.ts +690 -0
  344. package/sdk/dist/generated/dvn_fee_lib.js +163 -0
  345. package/sdk/dist/generated/endpoint.d.ts +155 -46
  346. package/sdk/dist/generated/endpoint.js +93 -50
  347. package/sdk/dist/generated/executor.d.ts +1841 -0
  348. package/sdk/dist/generated/executor.js +312 -0
  349. package/sdk/dist/generated/executor_fee_lib.d.ts +1083 -0
  350. package/sdk/dist/generated/executor_fee_lib.js +255 -0
  351. package/sdk/dist/generated/executor_helper.d.ts +981 -0
  352. package/sdk/dist/generated/executor_helper.js +236 -0
  353. package/sdk/dist/generated/oft_std.d.ts +1722 -0
  354. package/sdk/dist/generated/oft_std.js +316 -0
  355. package/sdk/dist/generated/price_feed.d.ts +1077 -0
  356. package/sdk/dist/generated/price_feed.js +210 -0
  357. package/sdk/dist/generated/sml.d.ts +171 -56
  358. package/sdk/dist/generated/sml.js +111 -62
  359. package/sdk/dist/generated/treasury.d.ts +896 -0
  360. package/sdk/dist/generated/treasury.js +219 -0
  361. package/sdk/dist/generated/uln302.d.ts +175 -75
  362. package/sdk/dist/generated/uln302.js +126 -82
  363. package/sdk/dist/generated/upgrader.d.ts +70 -0
  364. package/sdk/dist/generated/upgrader.js +19 -0
  365. package/sdk/dist/index.d.ts +10 -0
  366. package/sdk/dist/index.js +14 -0
  367. package/sdk/dist/wasm/blocked-message-lib.d.ts +1 -0
  368. package/sdk/dist/wasm/blocked-message-lib.js +2 -0
  369. package/sdk/dist/wasm/counter.d.ts +1 -0
  370. package/sdk/dist/wasm/counter.js +2 -0
  371. package/sdk/dist/wasm/dvn-fee-lib.d.ts +1 -0
  372. package/sdk/dist/wasm/dvn-fee-lib.js +2 -0
  373. package/sdk/dist/wasm/dvn.d.ts +1 -0
  374. package/sdk/dist/wasm/dvn.js +2 -0
  375. package/sdk/dist/wasm/endpoint-v2.d.ts +1 -0
  376. package/sdk/dist/wasm/endpoint-v2.js +2 -0
  377. package/sdk/dist/wasm/executor-fee-lib.d.ts +1 -0
  378. package/sdk/dist/wasm/executor-fee-lib.js +2 -0
  379. package/sdk/dist/wasm/executor-helper.d.ts +1 -0
  380. package/sdk/dist/wasm/executor-helper.js +2 -0
  381. package/sdk/dist/wasm/executor.d.ts +1 -0
  382. package/sdk/dist/wasm/executor.js +2 -0
  383. package/sdk/dist/wasm/layerzero-views.d.ts +1 -0
  384. package/sdk/dist/wasm/layerzero-views.js +2 -0
  385. package/sdk/dist/wasm/oft-std.d.ts +1 -0
  386. package/sdk/dist/wasm/oft-std.js +2 -0
  387. package/sdk/dist/wasm/price-feed.d.ts +1 -0
  388. package/sdk/dist/wasm/price-feed.js +2 -0
  389. package/sdk/dist/wasm/simple-message-lib.d.ts +1 -0
  390. package/sdk/dist/wasm/simple-message-lib.js +2 -0
  391. package/sdk/dist/wasm/treasury.d.ts +1 -0
  392. package/sdk/dist/wasm/treasury.js +2 -0
  393. package/sdk/dist/wasm/uln302.d.ts +1 -0
  394. package/sdk/dist/wasm/uln302.js +2 -0
  395. package/sdk/dist/wasm/upgrader.d.ts +1 -0
  396. package/sdk/dist/wasm/upgrader.js +2 -0
  397. package/sdk/dist/wasm.d.ts +15 -0
  398. package/sdk/dist/wasm.js +15 -0
  399. package/sdk/package.json +7 -4
  400. package/sdk/src/index.ts +17 -0
  401. package/sdk/test/counter-sml.test.ts +376 -0
  402. package/sdk/test/counter-uln.test.ts +493 -0
  403. package/sdk/test/{oft.test.ts → oft-sml.test.ts} +187 -323
  404. package/sdk/test/suites/constants.ts +22 -2
  405. package/sdk/test/suites/dummyContractClient.ts +169 -0
  406. package/sdk/test/suites/globalSetup.ts +450 -0
  407. package/sdk/test/suites/localnet.ts +23 -6
  408. package/sdk/test/upgrader.test.ts +300 -0
  409. package/sdk/test/utils.ts +558 -85
  410. package/sdk/vitest.config.ts +21 -0
  411. package/tools/ts-bindings-gen/src/main.rs +12 -1
  412. package/turbo.json +2 -0
  413. package/contracts/common-macros/src/contract_impl.rs +0 -47
  414. package/contracts/common-macros/src/ownable.rs +0 -59
  415. package/contracts/common-macros/src/tests/contract_impl.rs +0 -381
  416. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -32
  417. package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +0 -316
  418. package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +0 -388
  419. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +0 -162
  420. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +0 -319
  421. package/contracts/oapp-macros/src/lib.rs +0 -154
  422. package/contracts/oapp-macros/src/oapp_core.rs +0 -40
  423. package/contracts/oapp-macros/src/oapp_full.rs +0 -21
  424. package/contracts/oapp-macros/src/oapp_options_type3.rs +0 -31
  425. package/contracts/oapp-macros/src/oapp_receiver.rs +0 -48
  426. package/contracts/oapp-macros/src/oapp_sender.rs +0 -21
  427. package/contracts/oapp-macros/src/util.rs +0 -107
  428. package/contracts/oapps/oft/src/constants.rs +0 -5
  429. package/contracts/oapps/oft/src/default_oft_impl.rs +0 -146
  430. package/contracts/utils/src/tests/ttl.rs +0 -421
  431. package/contracts/utils/src/ttl.rs +0 -123
  432. package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
  433. package/contracts/workers/dvn/src/multisig.rs +0 -153
  434. package/sdk/test/index.test.ts +0 -376
  435. /package/contracts/{oapp-macros → oapps/oapp-macros}/Cargo.toml +0 -0
@@ -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]
@@ -77,9 +77,19 @@ fn calculate_in_flight(env: &Env, direction: &Direction, eid: u32) -> i128 {
77
77
  }
78
78
  }
79
79
 
80
- #[contracttrait]
80
+ /// Checkpoints the current in-flight amount by applying decay and updating timestamp.
81
+ /// Used internally before modifying rate limit state.
82
+ fn checkpoint_rate_limit_in_flight(env: &Env, direction: &Direction, eid: u32) {
83
+ let in_flight = calculate_in_flight(env, direction, eid);
84
+ let mut rate_limit = RateLimitStorage::rate_limit(env, direction, eid).unwrap();
85
+ rate_limit.in_flight_on_last_update = in_flight;
86
+ rate_limit.last_update = env.ledger().timestamp();
87
+ RateLimitStorage::set_rate_limit(env, direction, eid, &rate_limit);
88
+ }
89
+
90
+ #[contract_trait]
81
91
  pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
82
- #[only_owner]
92
+ #[only_auth]
83
93
  fn set_rate_limit(env: &Env, direction: &Direction, eid: u32, limit: i128, window_seconds: u64) {
84
94
  assert_with_error!(env, limit > 0, RateLimitError::InvalidLimit);
85
95
  assert_with_error!(env, window_seconds > 0, RateLimitError::InvalidWindowSeconds);
@@ -90,7 +100,7 @@ pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
90
100
  limit != rate_limit_data.limit || window_seconds != rate_limit_data.window_seconds,
91
101
  RateLimitError::SameValue
92
102
  );
93
- Self::__checkpoint_rate_limit_in_flight(env, direction, eid);
103
+ checkpoint_rate_limit_in_flight(env, direction, eid);
94
104
  let mut rate_limit = RateLimitStorage::rate_limit(env, direction, eid).unwrap();
95
105
  rate_limit.limit = limit;
96
106
  rate_limit.window_seconds = window_seconds;
@@ -112,7 +122,7 @@ pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
112
122
  }
113
123
  }
114
124
 
115
- #[only_owner]
125
+ #[only_auth]
116
126
  fn unset_rate_limit(env: &Env, direction: &Direction, eid: u32) {
117
127
  assert_with_error!(env, RateLimitStorage::has_rate_limit(env, direction, eid), RateLimitError::SameValue);
118
128
  RateLimitStorage::remove_rate_limit(env, direction, eid);
@@ -146,18 +156,18 @@ pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
146
156
  }
147
157
 
148
158
  /// Internal trait for rate limiter operations used by OFT hooks.
149
- /// Contains only truly internal methods that are called from OFTInner implementations.
159
+ /// Contains only truly internal methods that are called from OFTInternal implementations.
150
160
  pub trait RateLimiterInternal {
151
- /// Tries to consume the specified amount from the rate limit capacity.
152
- /// Used internally by `send` and `__lz_receive` to enforce rate limits.
161
+ /// Consumes the specified amount from the rate limit capacity.
162
+ /// Used internally by `__debit` and `__credit` to enforce rate limits.
153
163
  ///
154
164
  /// # Errors
155
165
  /// * `ExceededRateLimit` - If the amount exceeds the available capacity.
156
- fn __try_consume_rate_limit_capacity(env: &Env, direction: &Direction, eid: u32, amount: i128) {
166
+ fn __consume_rate_limit_capacity(env: &Env, direction: &Direction, eid: u32, amount: i128) {
157
167
  if !RateLimitStorage::has_rate_limit(env, direction, eid) {
158
168
  return;
159
169
  }
160
- Self::__checkpoint_rate_limit_in_flight(env, direction, eid);
170
+ checkpoint_rate_limit_in_flight(env, direction, eid);
161
171
  let mut rate_limit = RateLimitStorage::rate_limit(env, direction, eid).unwrap();
162
172
  // Check against remaining capacity (limit - current in_flight), not total limit
163
173
  let capacity = if rate_limit.limit > rate_limit.in_flight_on_last_update {
@@ -173,12 +183,12 @@ pub trait RateLimiterInternal {
173
183
  }
174
184
 
175
185
  /// Releases the specified amount back to the rate limit capacity.
176
- /// Used internally by `__lz_receive` to release outbound capacity on inbound messages.
186
+ /// Used internally by `__credit` to release outbound capacity on inbound messages.
177
187
  fn __release_rate_limit_capacity(env: &Env, direction: &Direction, eid: u32, amount: i128) {
178
188
  if !RateLimitStorage::has_rate_limit(env, direction, eid) {
179
189
  return;
180
190
  }
181
- Self::__checkpoint_rate_limit_in_flight(env, direction, eid);
191
+ checkpoint_rate_limit_in_flight(env, direction, eid);
182
192
  let mut rate_limit = RateLimitStorage::rate_limit(env, direction, eid).unwrap();
183
193
  if amount >= rate_limit.in_flight_on_last_update {
184
194
  rate_limit.in_flight_on_last_update = 0;
@@ -187,14 +197,4 @@ pub trait RateLimiterInternal {
187
197
  }
188
198
  RateLimitStorage::set_rate_limit(env, direction, eid, &rate_limit);
189
199
  }
190
-
191
- /// Checkpoints the current in-flight amount by applying decay and updating timestamp.
192
- /// Used internally before modifying rate limit state.
193
- fn __checkpoint_rate_limit_in_flight(env: &Env, direction: &Direction, eid: u32) {
194
- let in_flight = calculate_in_flight(env, direction, eid);
195
- let mut rate_limit = RateLimitStorage::rate_limit(env, direction, eid).unwrap();
196
- rate_limit.in_flight_on_last_update = in_flight;
197
- rate_limit.last_update = env.ledger().timestamp();
198
- RateLimitStorage::set_rate_limit(env, direction, eid, &rate_limit);
199
- }
200
200
  }
@@ -1,18 +1,20 @@
1
1
  #![no_std]
2
2
 
3
3
  pub mod codec;
4
- pub mod constants;
5
- pub mod default_oft_impl;
6
4
  pub mod errors;
7
5
  pub mod events;
8
6
  pub mod extensions;
9
7
  pub mod interfaces;
10
8
  pub mod oft;
9
+ pub mod oft_impl;
11
10
  pub mod oft_types;
12
11
  pub mod storage;
13
12
  pub mod types;
14
13
  pub mod utils;
15
14
 
15
+ // Re-export commonly used items
16
+ pub use oft_impl::initialize_oft;
17
+
16
18
  #[cfg(test)]
17
19
  #[path = "../integration-tests/mod.rs"]
18
20
  pub mod integration_tests;
@@ -1,14 +1,15 @@
1
1
  //! OFT traits - the main interface for OFT contracts.
2
2
  //!
3
3
  //! This module provides two traits:
4
- //! - `OFTInner`: Internal methods NOT exposed as contract endpoints (`__debit`, `__credit`, etc.)
4
+ //! - `OFTInternal`: Internal methods NOT exposed as contract endpoints (`__debit`, `__credit`, etc.)
5
5
  //! - `OFT`: Public methods exposed as contract endpoints (using `#[contracttrait]`)
6
6
  //!
7
7
  //! ## Usage
8
8
  //!
9
9
  //! ```ignore
10
10
  //! use oapp_macros::{oapp, oapp_options_type3};
11
- //! use oft::oft::{oft_initialize, OFTInner, OFT};
11
+ //! use oft::oft::{OFTInternal, OFT};
12
+ //! use oft::initialize_oft;
12
13
  //!
13
14
  //! #[oapp]
14
15
  //! pub struct MyOFT;
@@ -16,7 +17,7 @@
16
17
  //! #[contractimpl]
17
18
  //! impl MyOFT {
18
19
  //! pub fn __constructor(env: &Env, token: &Address, owner: &Address, endpoint: &Address, delegate: &Option<Address>) {
19
- //! oft_initialize::<Self>(env, owner, token, endpoint, delegate)
20
+ //! initialize_oft::<Self>(env, owner, token, endpoint, delegate)
20
21
  //! }
21
22
  //! }
22
23
  //!
@@ -26,7 +27,7 @@
26
27
  //!
27
28
  //! // Internal methods - NOT exposed as contract endpoints
28
29
  //! // IMPORTANT: Do NOT use #[contractimpl] here to keep methods internal
29
- //! impl OFTInner for MyOFT {
30
+ //! impl OFTInternal for MyOFT {
30
31
  //! fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
31
32
  //! // Your debit logic (e.g., burn or lock tokens)
32
33
  //! oft::oft_types::mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid)
@@ -43,44 +44,16 @@
43
44
  // inside this crate and in external crates implementing the OFT trait.
44
45
  extern crate self as oft;
45
46
 
46
- use crate::{errors::OFTError, storage::OFTStorage, types::OFTReceipt};
47
- use endpoint_v2::Origin;
47
+ use crate::{oft_impl, storage::OFTStorage, types::OFTReceipt};
48
+ use common_macros::contract_trait;
48
49
  use oapp::{
49
- oapp_core::{oapp_initialize, OAppCore},
50
- oapp_options_type3::OAppOptionsType3,
51
- oapp_receiver::OAppReceiver,
52
- oapp_sender::OAppSender,
50
+ oapp_core::OAppCore, oapp_options_type3::OAppOptionsType3, oapp_receiver::OAppReceiver,
51
+ oapp_sender::OAppSenderInternal,
53
52
  };
54
- use soroban_sdk::{assert_with_error, contracttrait, token::TokenClient, Address, Bytes, BytesN, Env};
55
- use utils::ownable::OwnableInitializer;
53
+ use soroban_sdk::{Address, Bytes, Env};
56
54
 
57
55
  // =====================================================
58
- // OFT Initialization
59
- // =====================================================
60
-
61
- /// Initializes the OFT contract with token, endpoint, and decimal configuration.
62
- /// The `shared_decimals` must be <= token's local decimals.
63
- pub fn oft_initialize<T: OFT + OwnableInitializer>(
64
- env: &Env,
65
- owner: &Address,
66
- token: &Address,
67
- endpoint: &Address,
68
- delegate: &Option<Address>,
69
- shared_decimals: u32,
70
- ) {
71
- // Initialize OApp (includes owner initialization)
72
- oapp_initialize::<T>(env, owner, endpoint, delegate);
73
-
74
- let local_decimals = TokenClient::new(env, token).decimals();
75
- assert_with_error!(env, local_decimals >= shared_decimals, OFTError::InvalidLocalDecimals);
76
-
77
- // Initialize OFT storage
78
- OFTStorage::set_token(env, token);
79
- OFTStorage::set_decimal_conversion_rate(env, &10_i128.pow(local_decimals - shared_decimals));
80
- }
81
-
82
- // =====================================================
83
- // OFTInner Trait (NOT exposed as contract endpoints)
56
+ // OFTInternal Trait (NOT exposed as contract endpoints)
84
57
  // =====================================================
85
58
 
86
59
  /// Internal OFT trait containing methods that should NOT be exposed as contract endpoints.
@@ -90,33 +63,33 @@ pub fn oft_initialize<T: OFT + OwnableInitializer>(
90
63
  ///
91
64
  /// ```ignore
92
65
  /// // Correct - methods stay internal
93
- /// impl OFTInner for MyOFT { ... }
66
+ /// impl OFTInternal for MyOFT { ... }
94
67
  ///
95
68
  /// // WRONG - would expose methods as endpoints
96
69
  /// #[contractimpl]
97
- /// impl OFTInner for MyOFT { ... }
70
+ /// impl OFTInternal for MyOFT { ... }
98
71
  /// ```
99
72
  ///
100
73
  /// Internal OFT trait for token debit/credit operations.
101
74
  ///
102
75
  /// This trait contains only the internal token operations. The OApp supertraits
103
76
  /// are on `OFT` instead, keeping this trait focused on token logic.
104
- pub trait OFTInner: OAppCore {
77
+ pub trait OFTInternal: OAppCore {
105
78
  // =========================================================================
106
79
  // Required Methods (no defaults - user MUST implement)
107
80
  // =========================================================================
108
81
 
109
- /// Debits tokens from sender for cross-chain transfer.
82
+ /// Debits tokens from the specified address for cross-chain transfer.
110
83
  ///
111
84
  /// # Arguments
112
- /// * `sender` - The address sending tokens
113
- /// * `amount_ld` - Amount in local decimals to debit
114
- /// * `min_amount_ld` - Minimum amount acceptable (slippage protection)
115
- /// * `dst_eid` - Destination endpoint ID
85
+ /// * `from` - The address to debit the tokens from
86
+ /// * `amount_ld` - The amount of tokens to send in local decimals
87
+ /// * `min_amount_ld` - The minimum amount to send in local decimals
88
+ /// * `dst_eid` - The destination chain ID
116
89
  ///
117
90
  /// # Returns
118
- /// Receipt with amounts sent and received (after fees/dust removal)
119
- fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt;
91
+ /// `OFTReceipt` containing the amount sent and amount received
92
+ fn __debit(env: &Env, from: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt;
120
93
 
121
94
  /// Credits tokens to recipient after receiving cross-chain transfer.
122
95
  ///
@@ -135,33 +108,20 @@ pub trait OFTInner: OAppCore {
135
108
 
136
109
  /// Calculates debit amounts without executing (view function).
137
110
  fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
138
- crate::default_oft_impl::default_debit_view(env, amount_ld, min_amount_ld, dst_eid)
111
+ oft_impl::debit_view(env, amount_ld, min_amount_ld, dst_eid)
139
112
  }
140
113
 
141
114
  /// Builds OFT message and combines options for cross-chain transfer.
142
115
  fn __build_msg_and_options(
143
116
  env: &Env,
144
- sender: &Address,
117
+ from: &Address,
145
118
  send_param: &oft::types::SendParam,
146
- amount_ld: i128,
119
+ receive_amount_ld: i128,
147
120
  ) -> (Bytes, Bytes)
148
121
  where
149
122
  Self: OAppOptionsType3,
150
123
  {
151
- crate::default_oft_impl::default_build_msg_and_options::<Self>(env, sender, send_param, amount_ld)
152
- }
153
-
154
- /// Handles OFT receive logic.
155
- fn __lz_receive(
156
- env: &Env,
157
- _executor: &Address,
158
- origin: &Origin,
159
- guid: &BytesN<32>,
160
- message: &Bytes,
161
- _extra_data: &Bytes,
162
- _value: i128,
163
- ) {
164
- crate::default_oft_impl::default_lz_receive::<Self>(env, _executor, origin, guid, message, _extra_data, _value)
124
+ oft_impl::build_msg_and_options::<Self>(env, from, send_param, receive_amount_ld)
165
125
  }
166
126
  }
167
127
 
@@ -175,9 +135,9 @@ pub trait OFTInner: OAppCore {
175
135
  /// contract endpoints. Users implement this with `#[contractimpl(contracttrait)]`.
176
136
  ///
177
137
  /// Internal methods like `__debit`, `__credit`, `__debit_view`, and `__build_msg_and_options`
178
- /// are in the `OFTInner` trait and are NOT exposed as contract endpoints.
179
- #[contracttrait(client_name = "OFTClient")]
180
- pub trait OFT: OFTInner + OAppReceiver + OAppSender + OAppOptionsType3 {
138
+ /// are in the `OFTInternal` trait and are NOT exposed as contract endpoints.
139
+ #[contract_trait]
140
+ pub trait OFT: OFTInternal + OAppReceiver + OAppSenderInternal + OAppOptionsType3 {
181
141
  /// Retrieves the token address associated with this OFT.
182
142
  fn token(env: &Env) -> Address {
183
143
  OFTStorage::token(env).unwrap()
@@ -220,7 +180,7 @@ pub trait OFT: OFTInner + OAppReceiver + OAppSender + OAppOptionsType3 {
220
180
  env: &Env,
221
181
  send_param: &oft::types::SendParam,
222
182
  ) -> (oft::types::OFTLimit, soroban_sdk::Vec<oft::types::OFTFeeDetail>, oft::types::OFTReceipt) {
223
- crate::default_oft_impl::default_quote_oft::<Self>(env, send_param)
183
+ oft_impl::quote_oft::<Self>(env, send_param)
224
184
  }
225
185
 
226
186
  /// Quotes a send operation including LayerZero messaging fees.
@@ -230,7 +190,7 @@ pub trait OFT: OFTInner + OAppReceiver + OAppSender + OAppOptionsType3 {
230
190
  send_param: &oft::types::SendParam,
231
191
  pay_in_zro: bool,
232
192
  ) -> endpoint_v2::MessagingFee {
233
- crate::default_oft_impl::default_quote_send::<Self>(env, sender, send_param, pay_in_zro)
193
+ oft_impl::quote_send::<Self>(env, sender, send_param, pay_in_zro)
234
194
  }
235
195
 
236
196
  /// Sends tokens cross-chain to another endpoint.
@@ -246,6 +206,6 @@ pub trait OFT: OFTInner + OAppReceiver + OAppSender + OAppOptionsType3 {
246
206
  fee: &endpoint_v2::MessagingFee,
247
207
  refund_address: &Address,
248
208
  ) -> (endpoint_v2::MessagingReceipt, oft::types::OFTReceipt) {
249
- crate::default_oft_impl::default_send::<Self>(env, sender, send_param, fee, refund_address)
209
+ oft_impl::send::<Self>(env, sender, send_param, fee, refund_address)
250
210
  }
251
211
  }
@@ -0,0 +1,201 @@
1
+ //! Default OFT implementations.
2
+ //!
3
+ //! This module provides default standalone functions for common OFT operations that can be
4
+ //! reused by trait implementations.
5
+
6
+ use crate::{
7
+ codec::{oft_compose_msg_codec::OFTComposeMsg, oft_msg_codec::OFTMessage},
8
+ errors::OFTError,
9
+ events::{self, OFTSent},
10
+ oft::{OFTInternal, OFT},
11
+ storage::OFTStorage,
12
+ types::{self, OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
13
+ utils,
14
+ };
15
+ use ::utils::{option_ext::OptionExt, ownable::OwnableInitializer};
16
+ use endpoint_v2::{MessagingComposerClient, MessagingFee, MessagingReceipt, Origin};
17
+ use oapp::{oapp_core::initialize_oapp, oapp_options_type3::OAppOptionsType3};
18
+ use soroban_sdk::{assert_with_error, token::TokenClient, vec, Address, Bytes, BytesN, Env, Vec};
19
+
20
+ /// Initializes the OFT contract with token, endpoint, and decimal configuration.
21
+ /// The `shared_decimals` must be <= token's local decimals.
22
+ pub fn initialize_oft<T: OFT + OwnableInitializer>(
23
+ env: &Env,
24
+ owner: &Address,
25
+ token: &Address,
26
+ endpoint: &Address,
27
+ delegate: &Option<Address>,
28
+ shared_decimals: u32,
29
+ ) {
30
+ // Initialize OApp (includes owner initialization)
31
+ initialize_oapp::<T>(env, owner, endpoint, delegate);
32
+
33
+ let local_decimals = TokenClient::new(env, token).decimals();
34
+ assert_with_error!(env, local_decimals >= shared_decimals, OFTError::InvalidLocalDecimals);
35
+
36
+ // Initialize OFT storage
37
+ OFTStorage::set_token(env, token);
38
+ OFTStorage::set_decimal_conversion_rate(env, &10_i128.pow(local_decimals - shared_decimals));
39
+ }
40
+
41
+ /// Simulates a debit operation without executing, used for quoting.
42
+ ///
43
+ /// # Arguments
44
+ /// * `amount_ld` - The amount of tokens to send in local decimals
45
+ /// * `min_amount_ld` - The minimum amount to send in local decimals (slippage protection)
46
+ /// * `dst_eid` - The destination chain ID (unused in default implementation)
47
+ ///
48
+ /// # Returns
49
+ /// `OFTReceipt` containing the amount sent and amount received after dust removal
50
+ pub fn debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, _dst_eid: u32) -> OFTReceipt {
51
+ let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
52
+ let amount_sent_ld = utils::remove_dust(amount_ld, conversion_rate);
53
+ let amount_received_ld = amount_sent_ld;
54
+
55
+ assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
56
+
57
+ OFTReceipt { amount_sent_ld, amount_received_ld }
58
+ }
59
+
60
+ /// Builds the OFT message payload and combines enforced options for cross-chain transfer.
61
+ ///
62
+ /// # Arguments
63
+ /// * `from` - The address initiating the transfer
64
+ /// * `send_param` - The send parameters including destination, recipient, and options
65
+ /// * `receive_amount_ld` - The amount to be received in local decimals (after dust removal)
66
+ ///
67
+ /// # Returns
68
+ /// A tuple of (encoded message, combined options)
69
+ pub fn build_msg_and_options<T: OAppOptionsType3>(
70
+ env: &Env,
71
+ from: &Address,
72
+ send_param: &SendParam,
73
+ receive_amount_ld: i128,
74
+ ) -> (Bytes, Bytes) {
75
+ let has_compose = !send_param.compose_msg.is_empty();
76
+ let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
77
+ let (msg, _) = OFTMessage {
78
+ send_to: send_param.to.clone(),
79
+ amount_sd: utils::to_sd(env, receive_amount_ld, conversion_rate),
80
+ compose_from: if has_compose { Some(utils::address_to_bytes32(from)) } else { None },
81
+ compose_msg: if has_compose { Some(send_param.compose_msg.clone()) } else { None },
82
+ }
83
+ .encode(env);
84
+ let msg_type = if has_compose { types::SEND_AND_CALL } else { types::SEND };
85
+
86
+ (msg, T::combine_options(env, send_param.dst_eid, msg_type, &send_param.extra_options))
87
+ }
88
+
89
+ /// Quotes an OFT transfer without executing.
90
+ ///
91
+ /// # Arguments
92
+ /// * `send_param` - The send parameters to quote
93
+ ///
94
+ /// # Returns
95
+ /// A tuple of (transfer limits, fee details, estimated receipt)
96
+ pub fn quote_oft<T: OFTInternal>(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
97
+ let limit = OFTLimit { min_amount_ld: 0, max_amount_ld: i128::MAX }; // No limits in default implementation
98
+ let fee_details = vec![env]; // No fee details in default implementation
99
+ let oft_receipt = T::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
100
+ (limit, fee_details, oft_receipt)
101
+ }
102
+
103
+ /// Quotes the LayerZero messaging fee for a send operation.
104
+ ///
105
+ /// # Arguments
106
+ /// * `from` - The address initiating the transfer
107
+ /// * `send_param` - The send parameters to quote
108
+ /// * `pay_in_zro` - Whether to pay the fee in ZRO token
109
+ ///
110
+ /// # Returns
111
+ /// The messaging fee required for the transfer
112
+ pub fn quote_send<T: OFT>(env: &Env, from: &Address, send_param: &SendParam, pay_in_zro: bool) -> MessagingFee {
113
+ let OFTReceipt { amount_received_ld, .. } =
114
+ T::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
115
+
116
+ let (msg, options) = build_msg_and_options::<T>(env, from, send_param, amount_received_ld);
117
+ T::__quote(env, send_param.dst_eid, &msg, &options, pay_in_zro)
118
+ }
119
+
120
+ /// Executes a cross-chain token transfer via LayerZero.
121
+ ///
122
+ /// Debits tokens from the `from` address, builds the message, and sends via the endpoint.
123
+ /// The `from` address must be authenticated.
124
+ ///
125
+ /// # Arguments
126
+ /// * `from` - The address sending tokens (must authorize)
127
+ /// * `send_param` - The send parameters (destination, recipient, amount, options)
128
+ /// * `fee` - The messaging fee to pay
129
+ /// * `refund_address` - The address to refund excess fees to
130
+ ///
131
+ /// # Returns
132
+ /// A tuple of (messaging receipt, OFT receipt with amounts)
133
+ pub fn send<T: OFT>(
134
+ env: &Env,
135
+ from: &Address,
136
+ send_param: &SendParam,
137
+ fee: &MessagingFee,
138
+ refund_address: &Address,
139
+ ) -> (MessagingReceipt, OFTReceipt) {
140
+ from.require_auth();
141
+
142
+ let oft_receipt = T::__debit(env, from, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
143
+
144
+ let (msg, options) = build_msg_and_options::<T>(env, from, send_param, oft_receipt.amount_received_ld);
145
+ let msg_receipt = T::__lz_send(env, send_param.dst_eid, &msg, &options, from, fee, refund_address);
146
+
147
+ OFTSent {
148
+ guid: msg_receipt.guid.clone(),
149
+ dst_eid: send_param.dst_eid,
150
+ from: from.clone(),
151
+ amount_sent_ld: oft_receipt.amount_sent_ld,
152
+ amount_received_ld: oft_receipt.amount_received_ld,
153
+ }
154
+ .publish(env);
155
+
156
+ (msg_receipt, oft_receipt)
157
+ }
158
+
159
+ /// Handles incoming cross-chain OFT transfer from LayerZero endpoint.
160
+ ///
161
+ /// Credits tokens to the recipient and optionally queues a compose message.
162
+ ///
163
+ /// # Arguments
164
+ /// * `executor` - The address of the executor handling the message (unused in default implementation)
165
+ /// * `origin` - The origin information (source chain, sender, nonce)
166
+ /// * `guid` - The unique message identifier
167
+ /// * `message` - The encoded OFT message payload
168
+ /// * `extra_data` - Additional data (unused in default implementation)
169
+ /// * `value` - The native token value sent with the message (unused in default implementation)
170
+ pub fn lz_receive<T: OFTInternal>(
171
+ env: &Env,
172
+ _executor: &Address,
173
+ origin: &Origin,
174
+ guid: &BytesN<32>,
175
+ message: &Bytes,
176
+ _extra_data: &Bytes,
177
+ _value: i128,
178
+ ) {
179
+ let oft_msg = OFTMessage::decode(message);
180
+ let send_to = utils::resolve_address(env, &oft_msg.send_to);
181
+
182
+ let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
183
+ let amount_received_ld =
184
+ T::__credit(env, &send_to, utils::to_ld(oft_msg.amount_sd, conversion_rate), origin.src_eid);
185
+
186
+ if oft_msg.is_composed() {
187
+ let compose_msg = OFTComposeMsg {
188
+ nonce: origin.nonce,
189
+ src_eid: origin.src_eid,
190
+ amount_ld: amount_received_ld,
191
+ compose_from: oft_msg.compose_from.unwrap(),
192
+ compose_msg: oft_msg.compose_msg.unwrap(),
193
+ }
194
+ .encode(env);
195
+
196
+ let endpoint_client = MessagingComposerClient::new(env, &T::endpoint(env));
197
+ endpoint_client.send_compose(&env.current_contract_address(), &send_to, guid, &0, &compose_msg);
198
+ }
199
+
200
+ events::OFTReceived { guid: guid.clone(), src_eid: origin.src_eid, to: send_to, amount_received_ld }.publish(env);
201
+ }
@@ -4,11 +4,9 @@
4
4
  //! tokens from the contract on credit (receive).
5
5
  //! Used for OFT adapters that wrap existing tokens.
6
6
 
7
+ use crate::{oft::OFT, types::OFTReceipt};
7
8
  use soroban_sdk::{token::TokenClient, Address, Env};
8
9
 
9
- use crate::oft::OFT;
10
- use crate::types::OFTReceipt;
11
-
12
10
  /// Debit tokens using LockUnlock OFT type (locks tokens in contract).
13
11
  ///
14
12
  /// # Parameters
@@ -22,7 +20,7 @@ use crate::types::OFTReceipt;
22
20
  /// `OFTReceipt` containing the amount sent and amount received
23
21
  pub fn debit<T: OFT>(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
24
22
  let receipt: OFTReceipt = T::__debit_view(env, amount_ld, min_amount_ld, dst_eid);
25
- TokenClient::new(env, &T::token(env)).transfer(sender, env.current_contract_address(), &receipt.amount_sent_ld);
23
+ TokenClient::new(env, &T::token(env)).transfer(sender, env.current_contract_address(), &receipt.amount_received_ld);
26
24
  receipt
27
25
  }
28
26
 
@@ -3,12 +3,9 @@
3
3
  //! This OFT type burns tokens on debit (send) and mints tokens on credit (receive).
4
4
  //! Used when the OFT contract has mint/burn authority over the token.
5
5
 
6
+ use crate::{interfaces::MintBurnTokenClient, oft::OFT, types::OFTReceipt};
6
7
  use soroban_sdk::{Address, Env};
7
8
 
8
- use crate::interfaces::MintBurnTokenClient;
9
- use crate::oft::OFT;
10
- use crate::types::OFTReceipt;
11
-
12
9
  /// Debit tokens using MintBurn OFT type (burns tokens from sender).
13
10
  ///
14
11
  /// # Parameters
@@ -3,9 +3,11 @@ use soroban_sdk::Address;
3
3
 
4
4
  #[storage]
5
5
  pub enum OFTStorage {
6
+ /// The decimal conversion rate used for cross-chain normalization
6
7
  #[instance(i128)]
7
8
  DecimalConversionRate,
8
9
 
10
+ /// The address of the underlying token contract
9
11
  #[instance(Address)]
10
12
  Token,
11
13
  }