@layerzerolabs/protocol-stellar-v2 0.2.13 → 0.2.15

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 (319) hide show
  1. package/.turbo/turbo-build.log +384 -278
  2. package/.turbo/turbo-lint.log +110 -78
  3. package/.turbo/turbo-test.log +1248 -1014
  4. package/Cargo.lock +130 -3
  5. package/Cargo.toml +2 -1
  6. package/contracts/common-macros/src/contract_impl.rs +6 -1
  7. package/contracts/common-macros/src/lib.rs +47 -8
  8. package/contracts/common-macros/src/ownable.rs +7 -25
  9. package/contracts/common-macros/src/storage.rs +1 -1
  10. package/contracts/common-macros/src/tests/contract_impl.rs +5 -0
  11. package/contracts/common-macros/src/tests/mod.rs +1 -0
  12. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +23 -7
  13. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +5 -25
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +48 -48
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +5 -25
  16. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +21 -0
  17. package/contracts/common-macros/src/tests/upgradeable.rs +31 -0
  18. package/contracts/common-macros/src/ttl_configurable.rs +14 -44
  19. package/contracts/common-macros/src/upgradeable.rs +76 -0
  20. package/contracts/endpoint-v2/src/endpoint_v2.rs +25 -1
  21. package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +175 -8
  22. package/contracts/endpoint-v2/src/tests/endpoint_v2/build_outbound_packet.rs +76 -0
  23. package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +342 -159
  24. package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +3 -15
  25. package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +20 -31
  26. package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +126 -164
  27. package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +1 -0
  28. package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +0 -1
  29. package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +0 -1
  30. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +311 -304
  31. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +423 -96
  32. package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +1 -1
  33. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +47 -20
  34. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +373 -403
  35. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +96 -22
  36. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +61 -9
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +4 -4
  38. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +8 -11
  39. package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +81 -30
  40. package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +209 -76
  41. package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +0 -1
  42. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library.rs +24 -0
  43. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library_timeout.rs +40 -0
  44. package/contracts/endpoint-v2/src/tests/message_lib_manager/default_send_library.rs +24 -0
  45. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_config.rs +108 -0
  46. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_library_index.rs +52 -0
  47. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_receive_library.rs +92 -0
  48. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_registered_libraries.rs +74 -0
  49. package/contracts/endpoint-v2/src/tests/message_lib_manager/get_send_library.rs +83 -0
  50. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_registered_library.rs +32 -0
  51. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_supported_eid.rs +28 -0
  52. package/contracts/endpoint-v2/src/tests/message_lib_manager/is_valid_receive_library.rs +261 -0
  53. package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +16 -0
  54. package/contracts/endpoint-v2/src/tests/message_lib_manager/receive_library_timeout.rs +62 -0
  55. package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +65 -43
  56. package/contracts/endpoint-v2/src/tests/message_lib_manager/registered_libraries_count.rs +42 -0
  57. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +61 -0
  58. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +3 -5
  59. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +59 -0
  60. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +15 -1
  61. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +155 -51
  62. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +114 -92
  63. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +235 -132
  64. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +93 -87
  65. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +346 -245
  66. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +406 -60
  67. package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +252 -78
  68. package/contracts/endpoint-v2/src/tests/message_lib_manager/timeout.rs +102 -0
  69. package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +212 -273
  70. package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +203 -0
  71. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +94 -0
  72. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +78 -248
  73. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +7 -282
  74. package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +6 -274
  75. package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +3 -2
  76. package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +86 -178
  77. package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +328 -212
  78. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound.rs +68 -0
  79. package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +6 -209
  80. package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +207 -159
  81. package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +142 -153
  82. package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +6 -179
  83. package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +163 -221
  84. package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +90 -121
  85. package/contracts/endpoint-v2/src/tests/mock.rs +18 -4
  86. package/contracts/endpoint-v2/src/tests/util/build_payload.rs +4 -70
  87. package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +2 -1
  88. package/contracts/endpoint-v2/src/tests/util/keccak256.rs +17 -106
  89. package/contracts/layerzero-views/Cargo.toml +35 -0
  90. package/contracts/layerzero-views/src/errors.rs +10 -0
  91. package/contracts/layerzero-views/src/layerzero_view.rs +229 -0
  92. package/contracts/layerzero-views/src/lib.rs +38 -0
  93. package/contracts/layerzero-views/src/storage.rs +18 -0
  94. package/contracts/layerzero-views/src/tests/layerzero_view_tests.rs +423 -0
  95. package/contracts/layerzero-views/src/tests/mod.rs +4 -0
  96. package/contracts/layerzero-views/src/tests/setup.rs +377 -0
  97. package/contracts/layerzero-views/src/types.rs +50 -0
  98. package/contracts/macro-integration-tests/Cargo.toml +30 -0
  99. package/contracts/macro-integration-tests/src/lib.rs +1 -0
  100. package/contracts/macro-integration-tests/tests/runtime/ownable/initialization.rs +62 -0
  101. package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +22 -0
  102. package/contracts/macro-integration-tests/tests/runtime/ownable/only_owner_guard.rs +97 -0
  103. package/contracts/macro-integration-tests/tests/runtime/ownable/ownership_transfer.rs +101 -0
  104. package/contracts/macro-integration-tests/tests/runtime/storage/keyed_roundtrip.rs +225 -0
  105. package/contracts/macro-integration-tests/tests/runtime/storage/mod.rs +4 -0
  106. package/contracts/macro-integration-tests/tests/runtime/storage/name_override_runtime.rs +52 -0
  107. package/contracts/macro-integration-tests/tests/runtime/storage/ttl_extension.rs +261 -0
  108. package/contracts/macro-integration-tests/tests/runtime/storage/unkeyed_roundtrip.rs +137 -0
  109. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +113 -0
  110. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +50 -0
  111. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +139 -0
  112. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +3 -0
  113. package/contracts/macro-integration-tests/tests/runtime.rs +5 -0
  114. package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.rs +12 -0
  115. package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.stderr +7 -0
  116. package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.rs +12 -0
  117. package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.stderr +7 -0
  118. package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.rs +21 -0
  119. package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.stderr +7 -0
  120. package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.rs +13 -0
  121. package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.stderr +7 -0
  122. package/contracts/macro-integration-tests/tests/ui/error/pass/attr_on_variant_allowed.rs +20 -0
  123. package/contracts/macro-integration-tests/tests/ui/error/pass/basic_auto_discriminants.rs +15 -0
  124. package/contracts/macro-integration-tests/tests/ui/error/pass/mixed_discriminants.rs +16 -0
  125. package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_owner_missing_env.rs +22 -0
  126. package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_owner_missing_env.stderr +16 -0
  127. package/contracts/macro-integration-tests/tests/ui/ownable/pass/minimal_contract.rs +26 -0
  128. package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +22 -0
  129. package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_owner_env_param_variants.rs +46 -0
  130. package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.rs +13 -0
  131. package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.stderr +7 -0
  132. package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.rs +13 -0
  133. package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.stderr +7 -0
  134. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.rs +10 -0
  135. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.stderr +7 -0
  136. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.rs +12 -0
  137. package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.stderr +7 -0
  138. package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.rs +10 -0
  139. package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.stderr +7 -0
  140. package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.rs +10 -0
  141. package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.stderr +7 -0
  142. package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.rs +12 -0
  143. package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.stderr +7 -0
  144. package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.rs +13 -0
  145. package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.stderr +7 -0
  146. package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.rs +13 -0
  147. package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.stderr +7 -0
  148. package/contracts/macro-integration-tests/tests/ui/storage/pass/default_value_on_variant.rs +14 -0
  149. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_instance_unit_basic.rs +14 -0
  150. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_persistent_named_fields_keyed.rs +16 -0
  151. package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_temporary_unit_option.rs +15 -0
  152. package/contracts/macro-integration-tests/tests/ui/storage/pass/name_override.rs +14 -0
  153. package/contracts/macro-integration-tests/tests/ui/storage/pass/no_auto_ttl_extension.rs +19 -0
  154. package/contracts/macro-integration-tests/tests/ui/storage/pass/ttl_provider_basic.rs +15 -0
  155. package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +44 -0
  156. package/contracts/macro-integration-tests/tests/ui_error.rs +11 -0
  157. package/contracts/macro-integration-tests/tests/ui_ownable.rs +11 -0
  158. package/contracts/macro-integration-tests/tests/ui_storage.rs +11 -0
  159. package/contracts/macro-integration-tests/tests/ui_ttl_configurable.rs +12 -0
  160. package/contracts/message-libs/blocked-message-lib/src/lib.rs +17 -17
  161. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +64 -0
  162. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet.rs +58 -0
  163. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet_header.rs +138 -0
  164. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/mod.rs +6 -0
  165. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload.rs +30 -0
  166. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload_hash.rs +15 -0
  167. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/test_helper.rs +39 -0
  168. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_dvn_option.rs +57 -0
  169. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +50 -0
  170. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +74 -0
  171. package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +280 -0
  172. package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +126 -0
  173. package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +48 -0
  174. package/contracts/message-libs/message-lib-common/src/tests/worker_options/mod.rs +7 -0
  175. package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +139 -0
  176. package/contracts/message-libs/message-lib-common/src/worker_options.rs +31 -1
  177. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +2 -2
  178. package/contracts/message-libs/treasury/src/errors.rs +0 -1
  179. package/contracts/message-libs/treasury/src/lib.rs +3 -3
  180. package/contracts/message-libs/treasury/src/storage.rs +2 -0
  181. package/contracts/message-libs/treasury/src/treasury.rs +12 -13
  182. package/contracts/message-libs/uln-302/Cargo.toml +1 -1
  183. package/contracts/message-libs/uln-302/src/errors.rs +0 -5
  184. package/contracts/message-libs/uln-302/src/events.rs +5 -6
  185. package/contracts/message-libs/uln-302/src/receive_uln.rs +24 -54
  186. package/contracts/message-libs/uln-302/src/send_uln.rs +89 -135
  187. package/contracts/message-libs/uln-302/src/storage.rs +5 -5
  188. package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +5 -7
  189. package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +3 -3
  190. package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +6 -9
  191. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
  192. package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +3 -3
  193. package/contracts/message-libs/uln-302/src/tests/setup.rs +9 -0
  194. package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +5 -0
  195. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +1 -2
  196. package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +1 -2
  197. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +37 -55
  198. package/contracts/message-libs/uln-302/src/uln302.rs +8 -5
  199. package/contracts/oapps/counter/src/counter.rs +0 -1
  200. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +306 -224
  201. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +0 -1
  202. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +0 -1
  203. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +0 -1
  204. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +0 -1
  205. package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_core.rs +1 -0
  206. package/contracts/oapps/oft/integration-tests/setup.rs +10 -3
  207. package/contracts/oapps/oft/integration-tests/utils.rs +1 -1
  208. package/contracts/oapps/oft/src/default_oft_impl.rs +9 -3
  209. package/contracts/oapps/oft/src/extensions/oft_fee.rs +5 -5
  210. package/contracts/oapps/oft/src/extensions/pausable.rs +1 -1
  211. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +18 -18
  212. package/contracts/oapps/oft/src/oft.rs +9 -9
  213. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -1
  214. package/contracts/oapps/oft/src/tests/extensions/setup.rs +26 -11
  215. package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +1 -1
  216. package/contracts/oapps/oft/src/tests/test_send.rs +4 -4
  217. package/contracts/oapps/oft/src/tests/test_utils.rs +93 -74
  218. package/contracts/oapps/oft-std/Cargo.toml +6 -0
  219. package/contracts/oapps/oft-std/integration-tests/extensions/mod.rs +3 -0
  220. package/contracts/oapps/oft-std/integration-tests/extensions/test_oft_fee.rs +157 -0
  221. package/contracts/oapps/oft-std/integration-tests/extensions/test_pausable.rs +162 -0
  222. package/contracts/oapps/oft-std/integration-tests/extensions/test_rate_limiter.rs +186 -0
  223. package/contracts/oapps/oft-std/integration-tests/mod.rs +3 -0
  224. package/contracts/oapps/oft-std/integration-tests/setup.rs +245 -0
  225. package/contracts/oapps/oft-std/integration-tests/utils.rs +427 -0
  226. package/contracts/oapps/oft-std/src/lib.rs +12 -1
  227. package/contracts/oapps/oft-std/src/oft.rs +122 -25
  228. package/contracts/upgrader/Cargo.toml +19 -0
  229. package/contracts/upgrader/src/lib.rs +96 -0
  230. package/contracts/upgrader/src/tests/mod.rs +1 -0
  231. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract1.wasm +0 -0
  232. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract2.wasm +0 -0
  233. package/contracts/upgrader/src/tests/test_upgrader.rs +120 -0
  234. package/contracts/utils/src/errors.rs +6 -1
  235. package/contracts/utils/src/lib.rs +2 -1
  236. package/contracts/utils/src/ownable.rs +49 -61
  237. package/contracts/utils/src/tests/mod.rs +3 -1
  238. package/contracts/utils/src/tests/option_ext.rs +21 -0
  239. package/contracts/utils/src/tests/ownable.rs +10 -69
  240. package/contracts/utils/src/tests/ttl_configurable.rs +596 -0
  241. package/contracts/utils/src/tests/upgradeable.rs +288 -0
  242. package/contracts/utils/src/{ttl.rs → ttl_configurable.rs} +67 -52
  243. package/contracts/utils/src/upgradeable.rs +54 -0
  244. package/contracts/workers/dvn/Cargo.toml +1 -1
  245. package/contracts/workers/dvn/src/auth.rs +21 -32
  246. package/contracts/workers/dvn/src/dvn.rs +40 -3
  247. package/contracts/workers/dvn/src/errors.rs +1 -0
  248. package/contracts/workers/dvn/src/multisig.rs +10 -6
  249. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +2 -2
  250. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +4 -4
  251. package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -2
  252. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +46 -14
  253. package/contracts/workers/dvn-fee-lib/src/errors.rs +3 -2
  254. package/contracts/workers/dvn-fee-lib/src/lib.rs +5 -11
  255. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +30 -16
  256. package/contracts/workers/executor/src/executor.rs +16 -2
  257. package/contracts/workers/executor-fee-lib/src/errors.rs +9 -7
  258. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +154 -119
  259. package/contracts/workers/executor-helper/Cargo.toml +0 -5
  260. package/contracts/workers/executor-helper/src/lib.rs +1 -7
  261. package/contracts/workers/price-feed/Cargo.toml +0 -1
  262. package/contracts/workers/price-feed/src/errors.rs +3 -2
  263. package/contracts/workers/price-feed/src/lib.rs +5 -6
  264. package/contracts/workers/price-feed/src/price_feed.rs +39 -17
  265. package/contracts/workers/worker/Cargo.toml +4 -0
  266. package/contracts/workers/worker/src/interfaces/price_feed.rs +3 -3
  267. package/contracts/workers/worker/src/lib.rs +2 -2
  268. package/contracts/workers/worker/src/tests/mod.rs +4 -0
  269. package/contracts/workers/worker/src/tests/setup.rs +147 -0
  270. package/contracts/workers/worker/src/tests/worker.rs +501 -0
  271. package/contracts/workers/worker/src/worker.rs +10 -16
  272. package/package.json +3 -3
  273. package/sdk/dist/generated/bml.d.ts +40 -30
  274. package/sdk/dist/generated/bml.js +16 -11
  275. package/sdk/dist/generated/counter.d.ts +168 -134
  276. package/sdk/dist/generated/counter.js +26 -21
  277. package/sdk/dist/generated/dvn.d.ts +1932 -0
  278. package/sdk/dist/generated/dvn.js +288 -0
  279. package/sdk/dist/generated/dvn_fee_lib.d.ts +615 -0
  280. package/sdk/dist/generated/dvn_fee_lib.js +123 -0
  281. package/sdk/dist/generated/endpoint.d.ts +75 -41
  282. package/sdk/dist/generated/endpoint.js +22 -17
  283. package/sdk/dist/generated/executor.d.ts +1809 -0
  284. package/sdk/dist/generated/executor.js +269 -0
  285. package/sdk/dist/generated/executor_fee_lib.d.ts +999 -0
  286. package/sdk/dist/generated/executor_fee_lib.js +208 -0
  287. package/sdk/dist/generated/executor_helper.d.ts +869 -0
  288. package/sdk/dist/generated/executor_helper.js +187 -0
  289. package/sdk/dist/generated/oft_std.d.ts +1544 -0
  290. package/sdk/dist/generated/oft_std.js +271 -0
  291. package/sdk/dist/generated/price_feed.d.ts +1002 -0
  292. package/sdk/dist/generated/price_feed.js +170 -0
  293. package/sdk/dist/generated/sml.d.ts +75 -41
  294. package/sdk/dist/generated/sml.js +22 -17
  295. package/sdk/dist/generated/uln302.d.ts +79 -60
  296. package/sdk/dist/generated/uln302.js +37 -37
  297. package/sdk/dist/generated/upgrader.d.ts +70 -0
  298. package/sdk/dist/generated/upgrader.js +19 -0
  299. package/sdk/dist/index.d.ts +8 -0
  300. package/sdk/dist/index.js +11 -0
  301. package/sdk/package.json +4 -3
  302. package/sdk/src/index.ts +13 -0
  303. package/sdk/test/index.test.ts +0 -1
  304. package/sdk/test/oft.test.ts +12 -23
  305. package/sdk/test/suites/testUpgradeable.ts +169 -0
  306. package/sdk/test/upgrader.test.ts +309 -0
  307. package/tools/ts-bindings-gen/src/main.rs +11 -1
  308. package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +0 -316
  309. package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +0 -388
  310. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +0 -162
  311. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +0 -319
  312. package/contracts/utils/src/tests/ttl.rs +0 -421
  313. /package/contracts/{oapp-macros → oapps/oapp-macros}/Cargo.toml +0 -0
  314. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/lib.rs +0 -0
  315. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_full.rs +0 -0
  316. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_options_type3.rs +0 -0
  317. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_receiver.rs +0 -0
  318. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_sender.rs +0 -0
  319. /package/contracts/{oapp-macros → oapps/oapp-macros}/src/util.rs +0 -0
@@ -0,0 +1,288 @@
1
+ use crate::upgradeable::{self, Upgradeable, UpgradeableInternal, UpgradeableStorage};
2
+ use soroban_sdk::{contract, contractimpl, Bytes, BytesN, Env, Symbol};
3
+
4
+ // #![no_std]
5
+
6
+ // use soroban_sdk::{contract, contractimpl, BytesN, Env, Symbol};
7
+ // use utils::upgradeable::{self, Upgradeable, UpgradeableInternal};
8
+
9
+ // #[contract]
10
+ // pub struct DummyContract;
11
+
12
+ // impl UpgradeableInternal for DummyContract {
13
+ // type MigrationData = ();
14
+
15
+ // fn _migrate(env: &Env, _migration_data: &Self::MigrationData) {
16
+ // // Store the migration data to verify it was called
17
+ // env.storage().instance().set(&Symbol::new(env, "migrated"), &true);
18
+ // }
19
+ // }
20
+
21
+ // #[contractimpl]
22
+ // impl Upgradeable for DummyContract {
23
+ // fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
24
+ // upgradeable::upgrade(env, new_wasm_hash);
25
+ // }
26
+
27
+ // fn migrate(env: &Env, migration_data: &()) {
28
+ // upgradeable::migrate::<Self>(env, migration_data);
29
+ // }
30
+ // }
31
+
32
+ // Hardcoded test WASM bytes for upgrade testing
33
+ // This is the compiled above dummy_contract WASM
34
+ const TEST_WASM: &[u8] = &[
35
+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x29, 0x08, 0x60, 0x01, 0x7e, 0x01, 0x7e, 0x60, 0x02, 0x7e,
36
+ 0x7e, 0x01, 0x7e, 0x60, 0x03, 0x7e, 0x7e, 0x7e, 0x01, 0x7e, 0x60, 0x01, 0x7f, 0x00, 0x60, 0x00, 0x01, 0x7e, 0x60,
37
+ 0x00, 0x00, 0x60, 0x03, 0x7f, 0x7f, 0x7f, 0x00, 0x60, 0x02, 0x7e, 0x7e, 0x00, 0x02, 0x31, 0x08, 0x01, 0x62, 0x01,
38
+ 0x38, 0x00, 0x00, 0x01, 0x6c, 0x01, 0x36, 0x00, 0x00, 0x01, 0x6c, 0x01, 0x30, 0x00, 0x01, 0x01, 0x6c, 0x01, 0x31,
39
+ 0x00, 0x01, 0x01, 0x62, 0x01, 0x6a, 0x00, 0x01, 0x01, 0x78, 0x01, 0x35, 0x00, 0x00, 0x01, 0x6c, 0x01, 0x5f, 0x00,
40
+ 0x02, 0x01, 0x76, 0x01, 0x67, 0x00, 0x01, 0x03, 0x08, 0x07, 0x00, 0x03, 0x00, 0x04, 0x05, 0x06, 0x07, 0x05, 0x03,
41
+ 0x01, 0x00, 0x11, 0x06, 0x21, 0x04, 0x7f, 0x01, 0x41, 0x80, 0x80, 0xc0, 0x00, 0x0b, 0x7f, 0x00, 0x41, 0x88, 0x80,
42
+ 0xc0, 0x00, 0x0b, 0x7f, 0x00, 0x41, 0x91, 0x80, 0xc0, 0x00, 0x0b, 0x7f, 0x00, 0x41, 0xa0, 0x80, 0xc0, 0x00, 0x0b,
43
+ 0x07, 0x3d, 0x06, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64,
44
+ 0x65, 0x00, 0x08, 0x07, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x65, 0x00, 0x0a, 0x01, 0x5f, 0x03, 0x01, 0x0a, 0x5f,
45
+ 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65, 0x6e, 0x64, 0x03, 0x02, 0x0b, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f,
46
+ 0x62, 0x61, 0x73, 0x65, 0x03, 0x03, 0x0a, 0x80, 0x05, 0x07, 0x41, 0x00, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x42,
47
+ 0xff, 0x01, 0x83, 0x42, 0xc8, 0x00, 0x52, 0x0d, 0x00, 0x20, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x42, 0x80,
48
+ 0x80, 0x80, 0x80, 0x70, 0x83, 0x42, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x51, 0x0d, 0x01, 0x0b, 0x00, 0x0b, 0x41,
49
+ 0x01, 0x10, 0x89, 0x80, 0x80, 0x80, 0x00, 0x20, 0x00, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x1a, 0x42, 0x02, 0x0b,
50
+ 0x15, 0x00, 0x10, 0x8b, 0x80, 0x80, 0x80, 0x00, 0x20, 0x00, 0xad, 0x42, 0xff, 0x01, 0x83, 0x10, 0x8e, 0x80, 0x80,
51
+ 0x80, 0x00, 0x0b, 0x97, 0x01, 0x01, 0x01, 0x7f, 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x10, 0x6b, 0x22, 0x01,
52
+ 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x02, 0x40, 0x20, 0x00, 0x42, 0xff, 0x01, 0x83, 0x42, 0x02, 0x52, 0x0d, 0x00,
53
+ 0x02, 0x40, 0x02, 0x40, 0x10, 0x8b, 0x80, 0x80, 0x80, 0x00, 0x22, 0x00, 0x42, 0x02, 0x10, 0x82, 0x80, 0x80, 0x80,
54
+ 0x00, 0x42, 0x01, 0x52, 0x0d, 0x00, 0x20, 0x00, 0x42, 0x02, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00, 0xa7, 0x41, 0xff,
55
+ 0x01, 0x71, 0x0e, 0x02, 0x00, 0x01, 0x02, 0x0b, 0x10, 0x8c, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x41, 0x00, 0x10,
56
+ 0x89, 0x80, 0x80, 0x80, 0x00, 0x20, 0x01, 0x41, 0x80, 0x80, 0xc0, 0x80, 0x00, 0x41, 0x08, 0x10, 0x8d, 0x80, 0x80,
57
+ 0x80, 0x00, 0x20, 0x01, 0x28, 0x02, 0x00, 0x41, 0x01, 0x46, 0x0d, 0x00, 0x20, 0x01, 0x29, 0x03, 0x08, 0x42, 0x01,
58
+ 0x10, 0x8e, 0x80, 0x80, 0x80, 0x00, 0x20, 0x01, 0x41, 0x10, 0x6a, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x42, 0x02,
59
+ 0x0f, 0x0b, 0x00, 0x0b, 0x63, 0x02, 0x01, 0x7f, 0x01, 0x7e, 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x10, 0x6b,
60
+ 0x22, 0x00, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x00, 0x41, 0x88, 0x80, 0xc0, 0x80, 0x00, 0x41, 0x09, 0x10,
61
+ 0x8d, 0x80, 0x80, 0x80, 0x00, 0x02, 0x40, 0x20, 0x00, 0x28, 0x02, 0x00, 0x41, 0x01, 0x47, 0x0d, 0x00, 0x00, 0x0b,
62
+ 0x20, 0x00, 0x20, 0x00, 0x29, 0x03, 0x08, 0x37, 0x03, 0x00, 0x20, 0x00, 0xad, 0x42, 0x20, 0x86, 0x42, 0x04, 0x84,
63
+ 0x42, 0x84, 0x80, 0x80, 0x80, 0x10, 0x10, 0x87, 0x80, 0x80, 0x80, 0x00, 0x21, 0x01, 0x20, 0x00, 0x41, 0x10, 0x6a,
64
+ 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x01, 0x0b, 0x11, 0x00, 0x42, 0x83, 0x80, 0x80, 0x80, 0xc0, 0xbb, 0x01,
65
+ 0x10, 0x85, 0x80, 0x80, 0x80, 0x00, 0x1a, 0x0b, 0x86, 0x02, 0x03, 0x01, 0x7f, 0x01, 0x7e, 0x04, 0x7f, 0x23, 0x80,
66
+ 0x80, 0x80, 0x80, 0x00, 0x41, 0x10, 0x6b, 0x22, 0x03, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x42, 0x00, 0x21, 0x04,
67
+ 0x20, 0x02, 0x21, 0x05, 0x20, 0x01, 0x21, 0x06, 0x02, 0x40, 0x02, 0x40, 0x03, 0x40, 0x20, 0x05, 0x45, 0x0d, 0x01,
68
+ 0x41, 0x01, 0x21, 0x07, 0x02, 0x40, 0x02, 0x40, 0x20, 0x06, 0x2d, 0x00, 0x00, 0x22, 0x08, 0x41, 0xdf, 0x00, 0x46,
69
+ 0x0d, 0x00, 0x02, 0x40, 0x20, 0x08, 0x41, 0x50, 0x6a, 0x41, 0xff, 0x01, 0x71, 0x41, 0x0a, 0x49, 0x0d, 0x00, 0x02,
70
+ 0x40, 0x20, 0x08, 0x41, 0xbf, 0x7f, 0x6a, 0x41, 0xff, 0x01, 0x71, 0x41, 0x1a, 0x49, 0x0d, 0x00, 0x20, 0x08, 0x41,
71
+ 0x9f, 0x7f, 0x6a, 0x41, 0xff, 0x01, 0x71, 0x41, 0x19, 0x4b, 0x0d, 0x03, 0x20, 0x08, 0x41, 0x45, 0x6a, 0x21, 0x07,
72
+ 0x0c, 0x02, 0x0b, 0x20, 0x08, 0x41, 0x4b, 0x6a, 0x21, 0x07, 0x0c, 0x01, 0x0b, 0x20, 0x08, 0x41, 0x52, 0x6a, 0x21,
73
+ 0x07, 0x0b, 0x20, 0x04, 0x42, 0x06, 0x86, 0x20, 0x07, 0xad, 0x42, 0xff, 0x01, 0x83, 0x84, 0x21, 0x04, 0x20, 0x05,
74
+ 0x41, 0x7f, 0x6a, 0x21, 0x05, 0x20, 0x06, 0x41, 0x01, 0x6a, 0x21, 0x06, 0x0c, 0x01, 0x0b, 0x0b, 0x20, 0x03, 0x20,
75
+ 0x08, 0xad, 0x42, 0x08, 0x86, 0x42, 0x01, 0x84, 0x37, 0x03, 0x00, 0x20, 0x01, 0xad, 0x42, 0x20, 0x86, 0x42, 0x04,
76
+ 0x84, 0x20, 0x02, 0xad, 0x42, 0x20, 0x86, 0x42, 0x04, 0x84, 0x10, 0x84, 0x80, 0x80, 0x80, 0x00, 0x21, 0x04, 0x0c,
77
+ 0x01, 0x0b, 0x20, 0x03, 0x20, 0x04, 0x42, 0x08, 0x86, 0x42, 0x0e, 0x84, 0x22, 0x04, 0x37, 0x02, 0x04, 0x0b, 0x20,
78
+ 0x00, 0x42, 0x00, 0x37, 0x03, 0x00, 0x20, 0x00, 0x20, 0x04, 0x37, 0x03, 0x08, 0x20, 0x03, 0x41, 0x10, 0x6a, 0x24,
79
+ 0x80, 0x80, 0x80, 0x80, 0x00, 0x0b, 0x0f, 0x00, 0x20, 0x00, 0x20, 0x01, 0x42, 0x02, 0x10, 0x86, 0x80, 0x80, 0x80,
80
+ 0x00, 0x1a, 0x0b, 0x0b, 0x1a, 0x01, 0x00, 0x41, 0x80, 0x80, 0xc0, 0x00, 0x0b, 0x11, 0x6d, 0x69, 0x67, 0x72, 0x61,
81
+ 0x74, 0x65, 0x64, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x00, 0xdf, 0x0d, 0x0e, 0x63, 0x6f, 0x6e,
82
+ 0x74, 0x72, 0x61, 0x63, 0x74, 0x73, 0x70, 0x65, 0x63, 0x76, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83
+ 0x00, 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
84
+ 0x00, 0x00, 0x00, 0x00, 0x0d, 0x6e, 0x65, 0x77, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x00,
85
+ 0x00, 0x00, 0x00, 0x00, 0x03, 0xee, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01,
87
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64,
88
+ 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x03, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89
+ 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x42, 0x75, 0x66, 0x66, 0x65,
90
+ 0x72, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
91
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x4c, 0x65, 0x6e, 0x67,
92
+ 0x74, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x49, 0x6e,
93
+ 0x76, 0x61, 0x6c, 0x69, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64,
94
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95
+ 0x00, 0x00, 0x00, 0x11, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x57, 0x72, 0x69, 0x74, 0x65, 0x72, 0x45, 0x72, 0x72,
96
+ 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x49, 0x6e,
97
+ 0x76, 0x61, 0x6c, 0x69, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64,
98
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x4c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99
+ 0x00, 0x00, 0x00, 0x08, 0x54, 0x74, 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
100
+ 0x00, 0x00, 0x00, 0x00, 0x10, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66,
101
+ 0x69, 0x67, 0x00, 0x00, 0x04, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x54, 0x74, 0x6c, 0x43, 0x6f,
102
+ 0x6e, 0x66, 0x69, 0x67, 0x46, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x04, 0xb1, 0x00, 0x00, 0x00, 0x00,
103
+ 0x00, 0x00, 0x00, 0x16, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x41, 0x6c, 0x72, 0x65, 0x61, 0x64,
104
+ 0x79, 0x46, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x04, 0xb2, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
105
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x4f, 0x77, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x72,
106
+ 0x72, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x4f, 0x77, 0x6e, 0x65,
107
+ 0x72, 0x41, 0x6c, 0x72, 0x65, 0x61, 0x64, 0x79, 0x53, 0x65, 0x74, 0x00, 0x00, 0x00, 0x05, 0x14, 0x00, 0x00, 0x00,
108
+ 0x00, 0x00, 0x00, 0x00, 0x0b, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x4e, 0x6f, 0x74, 0x53, 0x65, 0x74, 0x00, 0x00, 0x00,
109
+ 0x05, 0x15, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x42,
110
+ 0x79, 0x74, 0x65, 0x73, 0x45, 0x78, 0x74, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
111
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x4d, 0x69, 0x73, 0x6d, 0x61,
112
+ 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x05, 0x78, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x72,
114
+ 0x72, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x4d, 0x69, 0x67, 0x72,
115
+ 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4e, 0x6f, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x00, 0x00, 0x00, 0x05,
116
+ 0xdc, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x65, 0x6d, 0x69, 0x74,
117
+ 0x74, 0x65, 0x64, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x20,
118
+ 0x69, 0x73, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x2e, 0x00, 0x00, 0x00, 0x00,
119
+ 0x00, 0x00, 0x00, 0x14, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66,
120
+ 0x65, 0x72, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73,
121
+ 0x68, 0x69, 0x70, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00,
122
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x6f, 0x6c, 0x64, 0x5f, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x00, 0x00, 0x00,
123
+ 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x6e, 0x65, 0x77,
124
+ 0x5f, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125
+ 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x65, 0x6d, 0x69,
126
+ 0x74, 0x74, 0x65, 0x64, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70,
127
+ 0x20, 0x69, 0x73, 0x20, 0x72, 0x65, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x64, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00,
128
+ 0x00, 0x00, 0x00, 0x00, 0x12, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x6e, 0x6f, 0x75,
129
+ 0x6e, 0x63, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x4f, 0x77, 0x6e, 0x65, 0x72,
130
+ 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
131
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x6f, 0x6c, 0x64, 0x5f, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x00, 0x00,
132
+ 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
133
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x4f, 0x77,
134
+ 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
135
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x00, 0x00,
136
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x57, 0x41, 0x20, 0x70, 0x61, 0x69, 0x72, 0x20, 0x6f, 0x66, 0x20,
137
+ 0x54, 0x54, 0x4c, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x3a, 0x20, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f,
138
+ 0x6c, 0x64, 0x20, 0x28, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, 0x65, 0x72,
139
+ 0x20, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x65, 0x78, 0x74,
140
+ 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x6f, 0x20, 0x28, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x20, 0x54, 0x54, 0x4c, 0x29,
141
+ 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67,
142
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x28, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x20, 0x54,
143
+ 0x54, 0x4c, 0x20, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20,
144
+ 0x28, 0x69, 0x6e, 0x20, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x73, 0x29, 0x2e, 0x00, 0x00, 0x00, 0x09, 0x65, 0x78,
145
+ 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x33, 0x54,
146
+ 0x54, 0x4c, 0x20, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x74,
147
+ 0x72, 0x69, 0x67, 0x67, 0x65, 0x72, 0x73, 0x20, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x28,
148
+ 0x69, 0x6e, 0x20, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x73, 0x29, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x09, 0x74, 0x68,
149
+ 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00,
150
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69,
151
+ 0x67, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152
+ 0x00, 0x00, 0x00, 0x00, 0x06, 0x46, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,
154
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x00, 0x00,
155
+ 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x27, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x65, 0x6d, 0x69, 0x74, 0x74,
156
+ 0x65, 0x64, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x54, 0x54, 0x4c, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73,
157
+ 0x20, 0x61, 0x72, 0x65, 0x20, 0x73, 0x65, 0x74, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x54,
158
+ 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x53, 0x65, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
159
+ 0x00, 0x00, 0x00, 0x0d, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x53, 0x65, 0x74, 0x00, 0x00,
160
+ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e,
161
+ 0x63, 0x65, 0x00, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x07, 0xd0, 0x00, 0x00, 0x00, 0x09, 0x54, 0x74, 0x6c, 0x43, 0x6f,
162
+ 0x6e, 0x66, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
163
+ 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x07,
164
+ 0xd0, 0x00, 0x00, 0x00, 0x09, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00,
165
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2a, 0x45, 0x76, 0x65, 0x6e, 0x74,
166
+ 0x20, 0x65, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x54, 0x54, 0x4c, 0x20, 0x63,
167
+ 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x2e, 0x00,
168
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x54, 0x74, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73,
169
+ 0x46, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x54, 0x74, 0x6c, 0x43, 0x6f,
170
+ 0x6e, 0x66, 0x69, 0x67, 0x73, 0x46, 0x72, 0x6f, 0x7a, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
171
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x55, 0x70, 0x67,
172
+ 0x72, 0x61, 0x64, 0x65, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x00, 0x00, 0x00, 0x00,
173
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x4d, 0x69, 0x67, 0x72, 0x61,
174
+ 0x74, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x11, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x65,
175
+ 0x6e, 0x76, 0x6d, 0x65, 0x74, 0x61, 0x76, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
176
+ 0x00, 0x00, 0x6f, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x76, 0x30, 0x00,
177
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x72, 0x73, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
178
+ 0x31, 0x2e, 0x39, 0x30, 0x2e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x72, 0x73, 0x73,
179
+ 0x64, 0x6b, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x2f, 0x32, 0x33, 0x2e, 0x34, 0x2e, 0x30, 0x23, 0x36, 0x37, 0x33,
180
+ 0x64, 0x36, 0x63, 0x34, 0x66, 0x32, 0x33, 0x36, 0x38, 0x64, 0x32, 0x38, 0x32, 0x64, 0x32, 0x35, 0x64, 0x61, 0x32,
181
+ 0x39, 0x62, 0x64, 0x61, 0x35, 0x35, 0x63, 0x32, 0x31, 0x62, 0x38, 0x62, 0x65, 0x36, 0x39, 0x63, 0x61, 0x36, 0x00,
182
+ 0x00, 0x2b, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x76, 0x30, 0x00, 0x00,
183
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x63, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x32,
184
+ 0x33, 0x2e, 0x33, 0x2e, 0x30, 0x23, 0x00,
185
+ ];
186
+
187
+ // ============================================
188
+ // Dummy Contract for Testing
189
+ // ============================================
190
+
191
+ #[contract]
192
+ pub struct DummyContract;
193
+
194
+ // Regular trait implementation (not a contract implementation)
195
+ impl UpgradeableInternal for DummyContract {
196
+ type MigrationData = ();
197
+
198
+ fn __migrate(env: &Env, _migration_data: &Self::MigrationData) {
199
+ // Store the migration data to verify it was called
200
+ env.storage().instance().set(&Symbol::new(env, "migrated"), &0_u32);
201
+ }
202
+ }
203
+
204
+ #[contractimpl]
205
+ impl Upgradeable for DummyContract {
206
+ fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
207
+ upgradeable::upgrade(env, new_wasm_hash);
208
+ }
209
+
210
+ fn migrate(env: &Env, migration_data: &()) {
211
+ upgradeable::migrate::<Self>(env, migration_data);
212
+ }
213
+ }
214
+
215
+ #[test]
216
+ fn test_upgrade_success() {
217
+ let env = Env::default();
218
+ let contract_id = env.register(DummyContract, ());
219
+
220
+ // Upload valid contract WASM to get a valid hash
221
+ let wasm_hash = env.deployer().upload_contract_wasm(Bytes::from_slice(&env, TEST_WASM));
222
+
223
+ env.as_contract(&contract_id, || {
224
+ // Initially, migrating flag should not be set
225
+ assert_eq!(UpgradeableStorage::migrating(&env), None);
226
+ });
227
+
228
+ // Call the actual upgrade function with valid WASM hash
229
+ let client = DummyContractClient::new(&env, &contract_id);
230
+ client.upgrade(&wasm_hash);
231
+
232
+ env.as_contract(&contract_id, || {
233
+ // Verify the flag is set by upgrade()
234
+ assert_eq!(UpgradeableStorage::migrating(&env), Some(true));
235
+ });
236
+ }
237
+
238
+ #[test]
239
+ fn test_migrate_success() {
240
+ let env = Env::default();
241
+ let contract_id = env.register(DummyContract, ());
242
+ let client = DummyContractClient::new(&env, &contract_id);
243
+
244
+ let wasm_hash = env.deployer().upload_contract_wasm(Bytes::from_slice(&env, TEST_WASM));
245
+ client.upgrade(&wasm_hash);
246
+ client.migrate(&());
247
+
248
+ env.as_contract(&contract_id, || {
249
+ // Verify migration flag was cleared
250
+ assert_eq!(UpgradeableStorage::migrating(&env), Some(false));
251
+
252
+ // Verify migration data was stored (proving _migrate was called)
253
+ let stored_value: Option<bool> = env.storage().instance().get(&Symbol::new(&env, "migrated"));
254
+ assert_eq!(stored_value, Some(true));
255
+ });
256
+ }
257
+
258
+ #[test]
259
+ #[should_panic(expected = "Error(Contract, #1500)")]
260
+ fn test_migrate_fail_without_upgrade() {
261
+ let env = Env::default();
262
+ let contract_id = env.register(DummyContract, ());
263
+ let client = DummyContractClient::new(&env, &contract_id);
264
+
265
+ // Try to migrate without setting migrating flag first
266
+ // Should panic with MigrationNotAllowed
267
+ client.migrate(&());
268
+ }
269
+
270
+ // ============================================
271
+ // Integration test: upgrade then migrate
272
+ // ============================================
273
+
274
+ #[test]
275
+ #[should_panic(expected = "Error(Contract, #1500)")]
276
+ fn test_cannot_migrate_twice_without_upgrade() {
277
+ let env = Env::default();
278
+ let contract_id = env.register(DummyContract, ());
279
+ let client = DummyContractClient::new(&env, &contract_id);
280
+
281
+ // First upgrade and migrate with valid WASM
282
+ let wasm_hash = env.deployer().upload_contract_wasm(Bytes::from_slice(&env, TEST_WASM));
283
+ client.upgrade(&wasm_hash);
284
+ client.migrate(&());
285
+
286
+ // Try to migrate again without upgrade - should panic
287
+ client.migrate(&());
288
+ }
@@ -1,7 +1,10 @@
1
- use crate::errors::TtlError;
2
- use soroban_sdk::{assert_with_error, contractclient, contractevent, contracttype, Env};
1
+ use crate::{
2
+ errors::TtlConfigurableError,
3
+ ownable::{require_owner_auth, Ownable},
4
+ };
5
+ use soroban_sdk::{assert_with_error, contractevent, contracttrait, contracttype, Env};
3
6
 
4
- /// Number of ledgers per day (~5 second ledger close time).
7
+ /// Ledgers per day (~5 second close time).
5
8
  pub const LEDGERS_PER_DAY: u32 = (24 * 3600) / 5;
6
9
 
7
10
  /// Maximum TTL (1 year) allowed by the protocol.
@@ -11,12 +14,7 @@ pub const LEDGERS_PER_DAY: u32 = (24 * 3600) / 5;
11
14
  /// extend_to value.
12
15
  pub const MAX_TTL: u32 = 365 * LEDGERS_PER_DAY;
13
16
 
14
- /// Default TTL for instance storage (30 days, extends at 29 days remaining).
15
- pub const DEFAULT_INSTANCE_TTL: TtlConfig = TtlConfig::new(29 * LEDGERS_PER_DAY, 30 * LEDGERS_PER_DAY);
16
- /// Default TTL for persistent storage (30 days, extends at 29 days remaining).
17
- pub const DEFAULT_PERSISTENT_TTL: TtlConfig = TtlConfig::new(29 * LEDGERS_PER_DAY, 30 * LEDGERS_PER_DAY);
18
-
19
- /// A pair of TTL values: threshold (when to trigger extension) and extend_to (target TTL).
17
+ /// TTL configuration: threshold (when to extend) and extend_to (target TTL).
20
18
  #[contracttype]
21
19
  #[derive(Clone, Copy, Debug, PartialEq, Eq)]
22
20
  pub struct TtlConfig {
@@ -38,11 +36,32 @@ impl TtlConfig {
38
36
  }
39
37
  }
40
38
 
39
+ // =============================================================================
40
+ // Events
41
+ // =============================================================================
42
+
43
+ /// Event emitted when TTL configs are set.
44
+ #[contractevent]
45
+ #[derive(Clone, Debug, Eq, PartialEq)]
46
+ pub struct TtlConfigsSet {
47
+ pub instance: Option<TtlConfig>,
48
+ pub persistent: Option<TtlConfig>,
49
+ }
50
+
51
+ /// Event emitted when TTL configs are frozen.
52
+ #[contractevent]
53
+ #[derive(Clone, Debug, Eq, PartialEq)]
54
+ pub struct TtlConfigsFrozen {}
55
+
56
+ // =============================================================================
57
+ // Storage for default implementation
58
+ // =============================================================================
59
+
41
60
  /// Storage keys for TTL configuration.
42
61
  ///
43
- /// Note: These instance storage entries do NOT have automatic TTL extension enabled to avoid
44
- /// infinite recursion--extending TTL config storage would require reading the TTL config,
45
- /// which would trigger another extension, creating a deep loop.
62
+ /// Note: Auto-TTL extension is disabled for these instance storage entries to avoid infinite
63
+ /// recursion. Extending TTL config storage would require reading the TTL config, which would
64
+ /// trigger another extension, creating a deep loop.
46
65
  #[common_macros::storage]
47
66
  pub enum TtlConfigStorage {
48
67
  #[instance(bool)]
@@ -56,32 +75,34 @@ pub enum TtlConfigStorage {
56
75
  Persistent,
57
76
  }
58
77
 
59
- /// Trait for contracts that allow TTL configuration management.
60
- #[contractclient(name = "TtlConfigurableClient")]
61
- pub trait TtlConfigurable {
62
- /// Sets TTL configs. None values remove the config.
63
- fn set_ttl_configs(env: &Env, instance: &Option<TtlConfig>, persistent: &Option<TtlConfig>);
64
-
65
- /// Returns current TTL configs (instance, persistent).
66
- fn ttl_configs(env: &Env) -> (Option<TtlConfig>, Option<TtlConfig>);
67
-
68
- /// Permanently freezes TTL configs, preventing further changes.
69
- fn freeze_ttl_configs(env: &Env);
70
-
71
- /// Returns whether TTL configs are frozen.
72
- fn is_ttl_configs_frozen(env: &Env) -> bool;
73
- }
74
-
75
- /// Default implementation of TtlConfigurable.
76
- pub struct DefaultTtlConfigurable;
77
-
78
- impl TtlConfigurable for DefaultTtlConfigurable {
78
+ /// Trait for contracts that support configurable TTL (Time-To-Live) management.
79
+ ///
80
+ /// Allows the contract owner to configure how long instance and persistent storage entries
81
+ /// remain alive on Stellar.
82
+ ///
83
+ /// The owner can also permanently freeze the configuration to prevent future changes,
84
+ /// providing immutability guarantees to users.
85
+ #[contracttrait]
86
+ pub trait TtlConfigurable: Ownable {
87
+ /// Sets TTL configs for instance and persistent storage.
88
+ ///
89
+ /// - `None` values remove the corresponding config (disables auto-extension for that type)
90
+ /// - Validates that `threshold <= extend_to <= MAX_TTL`
91
+ ///
92
+ /// # Arguments
93
+ /// - `instance` - TTL config for instance storage
94
+ /// - `persistent` - TTL config for persistent storage
95
+ ///
96
+ /// # Panics
97
+ /// - `TtlConfigFrozen` if configs are frozen
98
+ /// - `InvalidTtlConfig` if validation fails
79
99
  fn set_ttl_configs(env: &Env, instance: &Option<TtlConfig>, persistent: &Option<TtlConfig>) {
80
- assert_with_error!(env, !Self::is_ttl_configs_frozen(env), TtlError::TtlConfigFrozen);
100
+ require_owner_auth::<Self>(env);
101
+ assert_with_error!(env, !Self::is_ttl_configs_frozen(env), TtlConfigurableError::TtlConfigFrozen);
81
102
 
82
103
  let max_ttl = u32::min(MAX_TTL, env.storage().max_ttl());
83
104
  let all_valid = [instance, persistent].iter().all(|c| c.is_none_or(|cfg| cfg.is_valid(max_ttl)));
84
- assert_with_error!(env, all_valid, TtlError::InvalidTtlConfig);
105
+ assert_with_error!(env, all_valid, TtlConfigurableError::InvalidTtlConfig);
85
106
 
86
107
  TtlConfigStorage::set_or_remove_instance(env, instance);
87
108
  TtlConfigStorage::set_or_remove_persistent(env, persistent);
@@ -89,35 +110,29 @@ impl TtlConfigurable for DefaultTtlConfigurable {
89
110
  TtlConfigsSet { instance: *instance, persistent: *persistent }.publish(env);
90
111
  }
91
112
 
113
+ /// Returns the current TTL configs as (instance_config, persistent_config).
92
114
  fn ttl_configs(env: &Env) -> (Option<TtlConfig>, Option<TtlConfig>) {
93
115
  (TtlConfigStorage::instance(env), TtlConfigStorage::persistent(env))
94
116
  }
95
117
 
118
+ /// Permanently freezes TTL configs, preventing any future modifications.
119
+ ///
120
+ /// This is irreversible and provides immutability guarantees to users.
121
+ /// Emits `TtlConfigsFrozen` event.
122
+ ///
123
+ /// # Panics
124
+ /// - `TtlConfigAlreadyFrozen` if already frozen
96
125
  fn freeze_ttl_configs(env: &Env) {
97
- assert_with_error!(env, !Self::is_ttl_configs_frozen(env), TtlError::TtlConfigAlreadyFrozen);
126
+ require_owner_auth::<Self>(env);
127
+ assert_with_error!(env, !Self::is_ttl_configs_frozen(env), TtlConfigurableError::TtlConfigAlreadyFrozen);
128
+
98
129
  TtlConfigStorage::set_frozen(env, &true);
99
130
 
100
131
  TtlConfigsFrozen {}.publish(env);
101
132
  }
102
133
 
134
+ /// Returns whether TTL configs are frozen.
103
135
  fn is_ttl_configs_frozen(env: &Env) -> bool {
104
136
  TtlConfigStorage::frozen(env)
105
137
  }
106
138
  }
107
-
108
- // ============================================
109
- // Events
110
- // ============================================
111
-
112
- /// Event emitted when TTL configs are set.
113
- #[contractevent]
114
- #[derive(Clone, Debug, Eq, PartialEq)]
115
- pub struct TtlConfigsSet {
116
- pub instance: Option<TtlConfig>,
117
- pub persistent: Option<TtlConfig>,
118
- }
119
-
120
- /// Event emitted when TTL configs are frozen.
121
- #[contractevent]
122
- #[derive(Clone, Debug, Eq, PartialEq)]
123
- pub struct TtlConfigsFrozen {}
@@ -0,0 +1,54 @@
1
+ use crate::errors::UpgradeableError;
2
+ use common_macros::storage;
3
+ use soroban_sdk::{assert_with_error, BytesN, Env, FromVal, Val};
4
+
5
+ // ============================================
6
+ // Upgradeable Interface
7
+ // ============================================
8
+
9
+ /// Trait for contracts with upgrade and migration support.
10
+ pub trait Upgradeable: UpgradeableInternal {
11
+ /// Upgrades the contract to new WASM bytecode.
12
+ /// Sets a migration flag that must be cleared by calling `migrate`.
13
+ fn upgrade(env: &Env, new_wasm_hash: BytesN<32>);
14
+
15
+ /// Runs migration logic after an upgrade.
16
+ /// Can only be called when the migration flag is set by a previous `upgrade` call.
17
+ fn migrate(env: &Env, migration_data: &Self::MigrationData);
18
+ }
19
+
20
+ /// Trait for defining contract-specific migration logic.
21
+ /// Contracts using `#[upgradeable]` must implement this trait.
22
+ pub trait UpgradeableInternal {
23
+ /// The type of data required for migration.
24
+ /// This is the type used as the `migration_data` parameter in `Upgradeable::migrate` for this contract.
25
+ type MigrationData: FromVal<Env, Val>;
26
+
27
+ /// Internal migration logic to be implemented by the contract.
28
+ fn __migrate(env: &Env, migration_data: &Self::MigrationData);
29
+ }
30
+
31
+ // ============================================
32
+ // Storage and Helper Functions
33
+ // ============================================
34
+
35
+ /// Storage keys for upgrade migration state.
36
+ #[storage]
37
+ pub enum UpgradeableStorage {
38
+ #[instance(bool)]
39
+ Migrating,
40
+ }
41
+
42
+ /// Upgrades the contract to new WASM bytecode and sets the migration flag.
43
+ pub fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
44
+ UpgradeableStorage::set_migrating(env, &true);
45
+ env.deployer().update_current_contract_wasm(new_wasm_hash);
46
+ }
47
+
48
+ /// Runs migration logic after an upgrade.
49
+ /// Can only be called when the migration flag is set by a previous `upgrade` call.
50
+ pub fn migrate<T: UpgradeableInternal>(env: &Env, migration_data: &T::MigrationData) {
51
+ assert_with_error!(env, UpgradeableStorage::migrating(env).unwrap_or(false), UpgradeableError::MigrationNotAllowed);
52
+ UpgradeableStorage::set_migrating(env, &false);
53
+ T::__migrate(env, migration_data);
54
+ }
@@ -20,7 +20,7 @@ worker = { workspace = true }
20
20
  message-lib-common = { workspace = true }
21
21
  utils = { workspace = true }
22
22
  common-macros = { workspace = true }
23
- endpoint-v2 = { workspace = true }
23
+ endpoint-v2 = { workspace = true, features = ["library"] }
24
24
 
25
25
  [dev-dependencies]
26
26
  soroban-sdk = { workspace = true, features = ["testutils"] }
@@ -65,16 +65,14 @@ impl CustomAccountInterface for LzDVN {
65
65
  return Err(DvnError::AuthDataExpired);
66
66
  }
67
67
 
68
- // 2. Admin verification (skip for quorum_change_admin)
69
- if !Self::is_invoking_quorum_change_admin(&env, &auth_contexts) {
70
- let Sender::Admin(public_key, signature) = sender else {
71
- return Err(DvnError::OnlyAdmin);
72
- };
73
- Self::verify_admin_signature(&env, &public_key, &signature, &signature_payload)?;
68
+ // 2. Admin verification (quorum_change_admin bypasses this - allows quorum-only admin changes)
69
+ let requires_admin = !Self::is_invoking_quorum_change_admin(&env, &auth_contexts);
70
+ if requires_admin {
71
+ Self::verify_admin_signature(&env, &sender, &signature_payload)?;
74
72
  }
75
73
 
76
74
  // 3. Replay protection
77
- let calls = Self::extract_execution_calls(&env, &auth_contexts)?;
75
+ let calls = Self::collect_contract_calls(&env, &auth_contexts)?;
78
76
  let hash = Self::hash_call_data(&env, vid, expiration, &calls);
79
77
  if DvnStorage::used_hash(&env, &hash) {
80
78
  return Err(DvnError::HashAlreadyUsed);
@@ -93,21 +91,15 @@ impl CustomAccountInterface for LzDVN {
93
91
  // ============================================================================
94
92
 
95
93
  impl LzDVN {
96
- /// Verifies that the admin signature is valid and from a registered admin.
97
- ///
98
- /// # Arguments
99
- /// * `public_key` - The admin's Ed25519 public key (32 bytes)
100
- /// * `signature` - The admin's signature over the signature payload (64 bytes)
101
- /// * `signature_payload` - The payload that was signed
94
+ /// Verifies that the sender is an admin with a valid signature.
102
95
  ///
103
96
  /// # Errors
104
- /// Returns `DvnError::OnlyAdmin` if the signer is not a registered admin.
105
- fn verify_admin_signature(
106
- env: &Env,
107
- public_key: &BytesN<32>,
108
- signature: &BytesN<64>,
109
- signature_payload: &Hash<32>,
110
- ) -> Result<(), DvnError> {
97
+ /// - `DvnError::OnlyAdmin` if sender is not `Sender::Admin` or not a registered admin.
98
+ fn verify_admin_signature(env: &Env, sender: &Sender, signature_payload: &Hash<32>) -> Result<(), DvnError> {
99
+ let Sender::Admin(public_key, signature) = sender else {
100
+ return Err(DvnError::OnlyAdmin);
101
+ };
102
+
111
103
  let admin_address = Address::from_payload(env, AddressPayload::AccountIdPublicKeyEd25519(public_key.clone()));
112
104
  if !Self::is_admin(env, &admin_address) {
113
105
  return Err(DvnError::OnlyAdmin);
@@ -118,8 +110,8 @@ impl LzDVN {
118
110
  Ok(())
119
111
  }
120
112
 
121
- /// Extracts the execution calls from the auth contexts.
122
- fn extract_execution_calls(env: &Env, auth_contexts: &Vec<Context>) -> Result<Vec<Call>, DvnError> {
113
+ /// Collects contract calls from the auth contexts.
114
+ fn collect_contract_calls(env: &Env, auth_contexts: &Vec<Context>) -> Result<Vec<Call>, DvnError> {
123
115
  auth_contexts.iter().try_fold(vec![env], |mut calls, context| {
124
116
  let Context::Contract(ctx) = context else {
125
117
  return Err(DvnError::NonContractInvoke);
@@ -129,16 +121,13 @@ impl LzDVN {
129
121
  })
130
122
  }
131
123
 
132
- /// Checks if the auth context is for `quorum_change_admin` on this contract.
133
- /// This function doesn't require admin verification (quorum-only).
124
+ /// Checks if the first auth context is a call to `quorum_change_admin` on this contract.
125
+ ///
126
+ /// Used to allow quorum-only admin changes without requiring existing admin authorization.
134
127
  fn is_invoking_quorum_change_admin(env: &Env, auth_contexts: &Vec<Context>) -> bool {
135
- // Must be exactly one call (no bundling with other operations)
136
- if auth_contexts.len() != 1 {
137
- return false;
138
- }
139
- let Context::Contract(ctx) = auth_contexts.first().unwrap() else {
140
- return false;
141
- };
142
- ctx.contract == env.current_contract_address() && ctx.fn_name == Symbol::new(env, "quorum_change_admin")
128
+ auth_contexts.first().is_some_and(|ctx| {
129
+ let Context::Contract(c) = ctx else { return false };
130
+ c.contract == env.current_contract_address() && c.fn_name == Symbol::new(env, "quorum_change_admin")
131
+ })
143
132
  }
144
133
  }