@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/.turbo/turbo-build.log +365 -297
  2. package/.turbo/turbo-lint.log +142 -110
  3. package/.turbo/turbo-test.log +1273 -1222
  4. package/Cargo.lock +20 -5
  5. package/Cargo.toml +4 -1
  6. package/contracts/ERROR_SPEC.md +44 -0
  7. package/contracts/common-macros/src/auth.rs +113 -0
  8. package/contracts/common-macros/src/contract_ttl.rs +84 -0
  9. package/contracts/common-macros/src/lib.rs +181 -30
  10. package/contracts/common-macros/src/lz_contract.rs +83 -0
  11. package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
  12. package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
  13. package/contracts/common-macros/src/tests/mod.rs +2 -2
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
  16. package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap → common_macros__tests__auth__snapshot_only_auth_preserves_function_signature.snap} +4 -4
  17. package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap → common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap} +3 -3
  18. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
  19. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
  20. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
  21. package/contracts/common-macros/src/ttl_configurable.rs +19 -34
  22. package/contracts/common-macros/src/ttl_extendable.rs +36 -0
  23. package/contracts/common-macros/src/upgradeable.rs +5 -5
  24. package/contracts/common-macros/src/utils.rs +9 -0
  25. package/contracts/endpoint-v2/src/constants.rs +4 -4
  26. package/contracts/endpoint-v2/src/endpoint_v2.rs +38 -40
  27. package/contracts/endpoint-v2/src/errors.rs +4 -3
  28. package/contracts/endpoint-v2/src/events.rs +1 -1
  29. package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
  30. package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
  31. package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
  32. package/contracts/endpoint-v2/src/storage.rs +1 -1
  33. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +3 -3
  34. package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
  35. package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
  36. package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
  37. package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
  38. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
  39. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
  40. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
  41. package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
  42. package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
  43. package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
  44. package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
  45. package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
  46. package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
  47. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
  48. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
  49. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
  50. package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
  51. package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
  52. package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
  53. package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
  54. package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
  55. package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
  56. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +3 -3
  57. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
  58. package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
  59. package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
  60. package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
  61. package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
  62. package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
  63. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
  64. package/contracts/message-libs/treasury/src/errors.rs +2 -2
  65. package/contracts/message-libs/treasury/src/events.rs +1 -1
  66. package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
  67. package/contracts/message-libs/treasury/src/storage.rs +1 -1
  68. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
  69. package/contracts/message-libs/treasury/src/treasury.rs +14 -16
  70. package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
  71. package/contracts/message-libs/uln-302/src/send_uln.rs +24 -4
  72. package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
  73. package/contracts/oapps/counter/Cargo.toml +14 -1
  74. package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
  75. package/contracts/oapps/counter/integration_tests/{setup.rs → setup_sml.rs} +48 -80
  76. package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
  77. package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
  78. package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
  79. package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
  80. package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
  81. package/contracts/oapps/counter/src/counter.rs +67 -43
  82. package/contracts/oapps/counter/src/tests/mod.rs +0 -13
  83. package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
  84. package/contracts/oapps/oapp/src/errors.rs +5 -1
  85. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +93 -78
  86. package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
  87. package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
  88. package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
  89. package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
  90. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -8
  91. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
  92. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
  93. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
  94. package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
  95. package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
  96. package/contracts/oapps/oft/Cargo.toml +10 -7
  97. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
  98. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
  99. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
  100. package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
  101. package/contracts/oapps/oft/integration-tests/setup.rs +29 -110
  102. package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
  103. package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -14
  104. package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
  105. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
  106. package/contracts/oapps/oft/src/lib.rs +11 -13
  107. package/contracts/oapps/oft/src/oft.rs +147 -225
  108. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -13
  109. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +31 -14
  110. package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
  111. package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
  112. package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
  113. package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +129 -30
  114. package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
  115. package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
  116. package/contracts/oapps/oft-core/src/errors.rs +13 -0
  117. package/contracts/oapps/oft-core/src/lib.rs +18 -0
  118. package/contracts/oapps/oft-core/src/oft_core.rs +439 -0
  119. package/contracts/oapps/{oft → oft-core}/src/storage.rs +2 -0
  120. package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
  121. package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +2 -2
  122. package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
  123. package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -5
  124. package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
  125. package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +78 -37
  126. package/contracts/oapps/oft-core/src/types.rs +58 -0
  127. package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
  128. package/contracts/upgrader/src/lib.rs +4 -4
  129. package/contracts/utils/src/auth.rs +44 -0
  130. package/contracts/utils/src/errors.rs +31 -5
  131. package/contracts/utils/src/lib.rs +3 -0
  132. package/contracts/utils/src/multisig.rs +211 -0
  133. package/contracts/utils/src/ownable.rs +137 -13
  134. package/contracts/utils/src/tests/buffer_reader.rs +6 -6
  135. package/contracts/utils/src/tests/buffer_writer.rs +6 -6
  136. package/contracts/utils/src/tests/bytes_ext.rs +2 -4
  137. package/contracts/utils/src/tests/mod.rs +1 -0
  138. package/contracts/utils/src/tests/multisig.rs +731 -0
  139. package/contracts/utils/src/tests/option_ext.rs +2 -5
  140. package/contracts/utils/src/tests/ownable.rs +456 -7
  141. package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
  142. package/contracts/utils/src/tests/upgradeable.rs +4 -2
  143. package/contracts/utils/src/ttl_configurable.rs +23 -8
  144. package/contracts/utils/src/ttl_extendable.rs +27 -0
  145. package/contracts/utils/src/upgradeable.rs +2 -0
  146. package/contracts/workers/dvn/Cargo.toml +1 -1
  147. package/contracts/workers/dvn/src/auth.rs +7 -7
  148. package/contracts/workers/dvn/src/dvn.rs +10 -38
  149. package/contracts/workers/dvn/src/errors.rs +0 -7
  150. package/contracts/workers/dvn/src/events.rs +1 -14
  151. package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
  152. package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
  153. package/contracts/workers/dvn/src/storage.rs +3 -13
  154. package/contracts/workers/dvn/src/tests/auth.rs +4 -4
  155. package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
  156. package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
  157. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
  158. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
  159. package/contracts/workers/dvn/src/tests/setup.rs +5 -5
  160. package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
  161. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
  162. package/contracts/workers/executor/src/auth.rs +80 -16
  163. package/contracts/workers/executor/src/executor.rs +5 -31
  164. package/contracts/workers/executor/src/storage.rs +2 -9
  165. package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
  166. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +3 -6
  167. package/contracts/workers/executor-helper/Cargo.toml +1 -1
  168. package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
  169. package/contracts/workers/price-feed/Cargo.toml +1 -1
  170. package/contracts/workers/price-feed/src/price_feed.rs +7 -10
  171. package/contracts/workers/worker/src/errors.rs +4 -0
  172. package/contracts/workers/worker/src/tests/worker.rs +7 -6
  173. package/contracts/workers/worker/src/worker.rs +20 -16
  174. package/package.json +7 -5
  175. package/sdk/.turbo/turbo-build.log +1 -0
  176. package/sdk/.turbo/turbo-test.log +1019 -0
  177. package/sdk/dist/generated/bml.d.ts +95 -8
  178. package/sdk/dist/generated/bml.js +95 -36
  179. package/sdk/dist/generated/counter.d.ts +289 -44
  180. package/sdk/dist/generated/counter.js +119 -49
  181. package/sdk/dist/generated/dvn.d.ts +312 -229
  182. package/sdk/dist/generated/dvn.js +144 -83
  183. package/sdk/dist/generated/dvn_fee_lib.d.ts +258 -63
  184. package/sdk/dist/generated/dvn_fee_lib.js +95 -26
  185. package/sdk/dist/generated/endpoint.d.ts +219 -24
  186. package/sdk/dist/generated/endpoint.js +108 -41
  187. package/sdk/dist/generated/executor.d.ts +239 -87
  188. package/sdk/dist/generated/executor.js +135 -63
  189. package/sdk/dist/generated/executor_fee_lib.d.ts +278 -74
  190. package/sdk/dist/generated/executor_fee_lib.js +135 -59
  191. package/sdk/dist/generated/executor_helper.d.ts +163 -21
  192. package/sdk/dist/generated/executor_helper.js +124 -52
  193. package/sdk/dist/generated/oft.d.ts +1842 -0
  194. package/sdk/dist/generated/oft.js +345 -0
  195. package/sdk/dist/generated/price_feed.d.ts +258 -63
  196. package/sdk/dist/generated/price_feed.js +95 -26
  197. package/sdk/dist/generated/sml.d.ts +235 -34
  198. package/sdk/dist/generated/sml.js +126 -53
  199. package/sdk/dist/generated/treasury.d.ts +1016 -0
  200. package/sdk/dist/generated/treasury.js +248 -0
  201. package/sdk/dist/generated/uln302.d.ts +235 -34
  202. package/sdk/dist/generated/uln302.js +126 -53
  203. package/sdk/dist/generated/upgrader.d.ts +17 -2
  204. package/sdk/dist/generated/upgrader.js +19 -1
  205. package/sdk/dist/index.d.ts +2 -1
  206. package/sdk/dist/index.js +2 -1
  207. package/sdk/package.json +6 -3
  208. package/sdk/src/index.ts +2 -1
  209. package/sdk/test/counter-sml.test.ts +376 -0
  210. package/sdk/test/counter-uln.test.ts +493 -0
  211. package/sdk/test/{oft.test.ts → oft-sml.test.ts} +196 -321
  212. package/sdk/test/suites/constants.ts +22 -2
  213. package/sdk/test/suites/globalSetup.ts +450 -0
  214. package/sdk/test/suites/localnet.ts +23 -6
  215. package/sdk/test/upgrader.test.ts +7 -16
  216. package/sdk/test/utils.ts +558 -85
  217. package/sdk/turbo.json +8 -0
  218. package/sdk/vitest.config.ts +21 -0
  219. package/tools/ts-bindings-gen/Cargo.toml +2 -0
  220. package/tools/ts-bindings-gen/src/main.rs +52 -4
  221. package/contracts/common-macros/src/contract_impl.rs +0 -52
  222. package/contracts/common-macros/src/ownable.rs +0 -41
  223. package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
  224. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
  225. package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
  226. package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
  227. package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
  228. package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
  229. package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
  230. package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
  231. package/contracts/oapps/oapp-macros/src/util.rs +0 -107
  232. package/contracts/oapps/oft/src/constants.rs +0 -5
  233. package/contracts/oapps/oft/src/default_oft_impl.rs +0 -152
  234. package/contracts/oapps/oft/src/errors.rs +0 -8
  235. package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
  236. package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
  237. package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
  238. package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -903
  239. package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -749
  240. package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -432
  241. package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1078
  242. package/contracts/oapps/oft/src/types.rs +0 -38
  243. package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
  244. package/contracts/oapps/oft-std/src/lib.rs +0 -16
  245. package/contracts/oapps/oft-std/src/oft.rs +0 -156
  246. package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
  247. package/contracts/workers/dvn/src/multisig.rs +0 -157
  248. package/sdk/dist/generated/oft_std.d.ts +0 -1544
  249. package/sdk/dist/generated/oft_std.js +0 -271
  250. package/sdk/test/index.test.ts +0 -375
  251. /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
  252. /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
  253. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
  254. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
  255. /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
  256. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
  257. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
  258. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
  259. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
  260. /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
  261. /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
  262. /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
package/sdk/turbo.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": ["//"],
3
+ "tasks": {
4
+ "build": {
5
+ "dependsOn": ["@layerzerolabs/protocol-stellar-v2#build", "^build"]
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ // Global setup runs ONCE before all test files
6
+ globalSetup: './test/suites/globalSetup.ts',
7
+ // Run tests sequentially to avoid conflicts with shared blockchain state
8
+ sequence: {
9
+ concurrent: false,
10
+ },
11
+ // Longer timeouts for blockchain operations
12
+ testTimeout: 120000,
13
+ hookTimeout: 240000,
14
+ // Don't isolate test files - they share the same localnet
15
+ isolate: false,
16
+ // Run test files sequentially
17
+ fileParallelism: false,
18
+ // Stop on first failure
19
+ bail: 1,
20
+ },
21
+ });
@@ -11,4 +11,6 @@ path = "src/main.rs"
11
11
  [dependencies]
12
12
  anyhow = "1.0"
13
13
  soroban-spec-typescript = "23.0.3"
14
+ sha2 = "0.10"
15
+ base64 = "0.22"
14
16
 
@@ -1,4 +1,6 @@
1
1
  use anyhow::Result;
2
+ use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
3
+ use sha2::{Digest, Sha256};
2
4
  use soroban_spec_typescript::generate_from_file;
3
5
  use std::{fs, path::Path};
4
6
 
@@ -37,6 +39,44 @@ export type MigrationData = void;
37
39
  "#
38
40
  }
39
41
 
42
+ /// Generate embedded WASM code section
43
+ fn generate_wasm_embed(wasm_bytes: &[u8]) -> String {
44
+ // Compute SHA-256 hash (this is what Stellar uses for wasmHash)
45
+ let wasm_hash = Sha256::digest(wasm_bytes);
46
+ let wasm_hash_hex = format!("{:x}", wasm_hash);
47
+
48
+ // Base64 encode the WASM bytes
49
+ let wasm_base64 = BASE64.encode(wasm_bytes);
50
+
51
+ format!(
52
+ r#"/**
53
+ * Embedded WASM bytecode (base64-encoded)
54
+ * Size: {} bytes ({:.2} KB)
55
+ */
56
+ export const WASM_BASE64 = "{}";
57
+
58
+ /**
59
+ * Pre-computed WASM hash (SHA-256)
60
+ * Use this when the WASM is already uploaded on-chain
61
+ */
62
+ export const WASM_HASH = "{}";
63
+
64
+ /**
65
+ * Get the WASM bytecode as a Buffer
66
+ * Use this to upload the WASM to the network
67
+ */
68
+ export function getWasmBuffer(): Buffer {{
69
+ return Buffer.from(WASM_BASE64, 'base64');
70
+ }}
71
+
72
+ "#,
73
+ wasm_bytes.len(),
74
+ wasm_bytes.len() as f64 / 1024.0,
75
+ wasm_base64,
76
+ wasm_hash_hex
77
+ )
78
+ }
79
+
40
80
  fn main() -> Result<()> {
41
81
  println!("🚀 Generating TypeScript bindings for Stellar contracts...\n");
42
82
 
@@ -52,6 +92,7 @@ fn main() -> Result<()> {
52
92
  ("simple_message_lib", "sml.ts"),
53
93
  ("blocked_message_lib", "bml.ts"),
54
94
  ("uln302", "uln302.ts"),
95
+ ("treasury", "treasury.ts"),
55
96
  ("upgrader", "upgrader.ts"),
56
97
  // Worker contracts
57
98
  ("dvn", "dvn.ts"),
@@ -62,7 +103,7 @@ fn main() -> Result<()> {
62
103
  ("price_feed", "price_feed.ts"),
63
104
  // OApp contracts
64
105
  ("counter", "counter.ts"),
65
- ("oft_std", "oft_std.ts"),
106
+ ("oft", "oft.ts"),
66
107
  // Add more contracts here as needed:
67
108
  ];
68
109
 
@@ -88,6 +129,13 @@ fn main() -> Result<()> {
88
129
  continue;
89
130
  }
90
131
 
132
+ // Read WASM bytes for embedding
133
+ let wasm_bytes = fs::read(&wasm_path)?;
134
+ println!(" WASM size: {} bytes ({:.2} KB)", wasm_bytes.len(), wasm_bytes.len() as f64 / 1024.0);
135
+
136
+ // Generate the embedded WASM section
137
+ let wasm_embed = generate_wasm_embed(&wasm_bytes);
138
+
91
139
  // Generate TypeScript bindings
92
140
  println!(" Generating bindings...");
93
141
  let wasm_path_str =
@@ -131,8 +179,8 @@ fn main() -> Result<()> {
131
179
  }"#,
132
180
  );
133
181
 
134
- // Combine imports header with generated code
135
- let complete_code = format!("{}{}", generate_imports_header(), ts_code);
182
+ // Combine imports header + embedded WASM + generated code
183
+ let complete_code = format!("{}{}{}", generate_imports_header(), wasm_embed, ts_code);
136
184
 
137
185
  // Write to contract-specific TypeScript file
138
186
  fs::write(&output_file, &complete_code)?;
@@ -144,7 +192,7 @@ fn main() -> Result<()> {
144
192
  }
145
193
 
146
194
  println!("\n✅ TypeScript binding generation complete!");
147
- println!(" Generated {} contract(s)", generated_contracts.len());
195
+ println!(" Generated {} contract(s) with embedded WASM", generated_contracts.len());
148
196
 
149
197
  if generated_contracts.is_empty() {
150
198
  println!("\n💡 Tip: Build your contracts first before generating bindings:");
@@ -1,52 +0,0 @@
1
- use crate::utils;
2
- use proc_macro2::TokenStream;
3
- use quote::quote;
4
- use syn::{parse_quote, ImplItem, ItemImpl, Visibility};
5
-
6
- /// Generates a `#[soroban_sdk::contractimpl]` with automatic instance TTL extension.
7
- pub fn contract_impl(attr: TokenStream, input: TokenStream) -> TokenStream {
8
- let mut impl_block: ItemImpl = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse impl block: {}", e));
9
-
10
- let is_trait_impl = impl_block.trait_.is_some();
11
-
12
- for item in &mut impl_block.items {
13
- let ImplItem::Fn(method) = item else { continue };
14
-
15
- // For trait impls, process all methods; for inherent impls, only public methods
16
- if !is_trait_impl && !matches!(method.vis, Visibility::Public(_)) {
17
- continue;
18
- }
19
-
20
- // Skip the constructor as TTL config is typically not set during initialization
21
- if method.sig.ident == "__constructor" {
22
- continue;
23
- }
24
-
25
- // Skip methods without Env parameter
26
- let Some(env_param) = utils::find_env_param(&method.sig.inputs) else { continue };
27
-
28
- // Get a reference to env (handles both `Env` and `&Env` parameter types)
29
- let env_ref = env_param.as_ref_tokens();
30
- let env_ident = env_param.ident;
31
-
32
- // Use fully qualified syntax to call ttl_configs from TtlConfigurable trait
33
- let extend_ttl_stmt = parse_quote! {
34
- if let Some(instance_ttl) = utils::ttl_configurable::TtlConfigStorage::instance(#env_ref) {
35
- #env_ident.storage().instance().extend_ttl(instance_ttl.threshold, instance_ttl.extend_to);
36
- }
37
- };
38
- method.block.stmts.insert(0, extend_ttl_stmt);
39
- }
40
-
41
- if attr.is_empty() {
42
- quote! {
43
- #[soroban_sdk::contractimpl]
44
- #impl_block
45
- }
46
- } else {
47
- quote! {
48
- #[soroban_sdk::contractimpl(#attr)]
49
- #impl_block
50
- }
51
- }
52
- }
@@ -1,41 +0,0 @@
1
- use crate::utils;
2
- use proc_macro2::TokenStream;
3
- use quote::{quote, ToTokens};
4
- use syn::{parse_quote, ItemFn, ItemStruct};
5
-
6
- /// Generates the ownable implementation from the `#[ownable]` attribute macro.
7
- pub fn generate_ownable_impl(input: TokenStream) -> TokenStream {
8
- let item_struct: ItemStruct = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse struct: {}", e));
9
- let name = &item_struct.ident;
10
-
11
- let ownable_impl = quote! {
12
- use utils::ownable::OwnableInitializer as _;
13
- use utils::ownable::Ownable;
14
-
15
- // Import OwnableInitializer at module level so user code can call Self::init_owner()
16
- impl utils::ownable::OwnableInitializer for #name {}
17
-
18
- /// Implement the Ownable trait for the contract with default implementations.
19
- #[common_macros::contract_impl(contracttrait)]
20
- impl Ownable for #name {}
21
- };
22
-
23
- quote! {
24
- #item_struct
25
- #ownable_impl
26
- }
27
- }
28
-
29
- /// Prepends an owner authentication check to a method.
30
- pub fn prepend_only_owner_check(input: TokenStream) -> TokenStream {
31
- let mut input_fn: ItemFn = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse function: {}", e));
32
-
33
- let env_param = utils::expect_env_param(&input_fn.sig.inputs);
34
-
35
- // Get a reference to env (handles both `Env` and `&Env` parameter types)
36
- let env_ref = env_param.as_ref_tokens();
37
-
38
- // Insert the owner authentication check at the beginning of the function body
39
- input_fn.block.stmts.insert(0, parse_quote!(utils::ownable::require_owner_auth::<Self>(#env_ref);));
40
- input_fn.into_token_stream()
41
- }
@@ -1,386 +0,0 @@
1
- use proc_macro2::TokenStream;
2
- use quote::quote;
3
-
4
- use crate::tests::test_helpers::assert_panics_contains;
5
-
6
- // ============================================
7
- // Snapshot Test: ContractImpl Code Generation
8
- // ============================================
9
-
10
- /// Comprehensive snapshot test covering all contract_impl macro features:
11
- /// - Inherent impl: public methods with Env (adds TTL), private/pub(crate) methods (skipped)
12
- /// - Trait impl: all methods with Env get TTL extension
13
- /// - Qualified Env types (soroban_sdk::Env)
14
- /// - Env parameter not in first position
15
- /// - Methods without Env (skipped)
16
- #[test]
17
- fn snapshot_generated_contract_impl_code() {
18
- // Test inherent impl with empty attr
19
- let empty_attr = TokenStream::new();
20
- let inherent_input = quote! {
21
- impl MyContract {
22
- /// Public method with Env - should have TTL extension
23
- pub fn public_with_env(env: Env, value: u32) -> u32 {
24
- value * 2
25
- }
26
-
27
- /// Public method with qualified Env path - should have TTL extension
28
- pub fn with_qualified_env(env: soroban_sdk::Env) -> u32 {
29
- 42
30
- }
31
-
32
- /// Public method with Env not as first parameter - should have TTL extension
33
- pub fn env_second(value: u32, env: &Env) -> u32 {
34
- value * 2
35
- }
36
-
37
- /// Public method without Env - should NOT have TTL extension
38
- pub fn public_without_env(value: u32) -> u32 {
39
- value * 4
40
- }
41
-
42
- /// Private method with Env - should NOT have TTL extension (not public)
43
- fn private_with_env(env: Env, value: u32) -> u32 {
44
- value * 5
45
- }
46
-
47
- /// Pub(crate) method with Env - should NOT have TTL extension (not fully public)
48
- pub(crate) fn pub_crate_with_env(env: Env, value: u32) -> u32 {
49
- value * 7
50
- }
51
-
52
- /// Constructor method - should NOT have TTL extension
53
- pub fn __constructor(env: &Env, value: u32) {
54
- let _ = value * 2;
55
- }
56
- }
57
- };
58
-
59
- let inherent_result = crate::contract_impl::contract_impl(empty_attr.clone(), inherent_input);
60
- let inherent_formatted =
61
- prettyplease::unparse(&syn::parse2::<syn::File>(inherent_result).expect("failed to parse generated code"));
62
-
63
- // Test trait impl with empty attr
64
- let trait_input = quote! {
65
- impl SomeTrait for MyContract {
66
- /// Trait method with Env - should have TTL extension
67
- fn trait_method_with_env(env: Env, value: u32) -> u32 {
68
- value * 2
69
- }
70
-
71
- /// Trait method without Env - should NOT have TTL extension
72
- fn trait_method_without_env(value: u32) -> u32 {
73
- value * 4
74
- }
75
-
76
- /// Trait method with macro attribute - should have TTL extension
77
- #[common_macros::only_owner]
78
- fn trait_method_with_only_owner_attribute(env: Env, value: u32) -> u32 {
79
- value * 5
80
- }
81
- }
82
- };
83
-
84
- let trait_result = crate::contract_impl::contract_impl(empty_attr, trait_input);
85
- let trait_formatted =
86
- prettyplease::unparse(&syn::parse2::<syn::File>(trait_result).expect("failed to parse generated code"));
87
-
88
- // Test trait impl with contracttrait attr
89
- let contracttrait_attr = quote! { contracttrait };
90
- let contracttrait_input = quote! {
91
- impl AnotherTrait for MyContract {
92
- /// Trait method with contracttrait attr - should have TTL extension
93
- fn contracttrait_method(env: &Env, value: u32) -> u32 {
94
- value * 3
95
- }
96
- }
97
- };
98
-
99
- let contracttrait_result = crate::contract_impl::contract_impl(contracttrait_attr, contracttrait_input);
100
- let contracttrait_formatted =
101
- prettyplease::unparse(&syn::parse2::<syn::File>(contracttrait_result).expect("failed to parse generated code"));
102
-
103
- // Combine all for single snapshot
104
- let combined = format!(
105
- "// === Inherent Impl (no attr) ===\n\n{}\n\n// === Trait Impl (no attr) ===\n\n{}\n\n// === Trait Impl (contracttrait attr) ===\n\n{}",
106
- inherent_formatted, trait_formatted, contracttrait_formatted
107
- );
108
-
109
- insta::assert_snapshot!(combined);
110
- }
111
-
112
- // ============================================
113
- // Error Cases: Invalid Input
114
- // ============================================
115
-
116
- #[test]
117
- fn test_non_impl_block_input() {
118
- let invalid_inputs = vec![
119
- (
120
- "struct",
121
- quote! {
122
- struct MyStruct {
123
- field: u32,
124
- }
125
- },
126
- ),
127
- (
128
- "enum",
129
- quote! {
130
- enum MyEnum {
131
- Variant1,
132
- Variant2,
133
- }
134
- },
135
- ),
136
- ("function", quote! { fn a_function() {} }),
137
- ("const item", quote! { const A_CONST: u32 = 1; }),
138
- ("type alias", quote! { type AnAlias = u32; }),
139
- (
140
- "trait",
141
- quote! {
142
- trait ATrait {
143
- fn method(&self);
144
- }
145
- },
146
- ),
147
- ];
148
-
149
- for (case, input) in invalid_inputs {
150
- assert_panics_contains(case, "failed to parse impl block", || {
151
- crate::contract_impl::contract_impl(TokenStream::new(), input.clone());
152
- });
153
- }
154
- }
155
-
156
- // ============================================
157
- // Unit Tests: Behavior Verification
158
- // ============================================
159
-
160
- /// Verifies that the macro adds #[soroban_sdk::contractimpl] attribute without parentheses when attr is empty
161
- #[test]
162
- fn test_adds_soroban_contractimpl_attribute_without_attr() {
163
- let input = quote! {
164
- impl MyContract {
165
- pub fn my_method(env: Env) {}
166
- }
167
- };
168
-
169
- let result = crate::contract_impl::contract_impl(TokenStream::new(), input);
170
- let result_str = result.to_string();
171
-
172
- // Should have contractimpl without parentheses when attr is empty
173
- assert!(
174
- result_str.contains("# [soroban_sdk :: contractimpl]"),
175
- "should add #[soroban_sdk::contractimpl] attribute without parentheses when attr is empty. Got: {}",
176
- result_str
177
- );
178
- // Should NOT have empty parentheses
179
- assert!(
180
- !result_str.contains("contractimpl ()"),
181
- "should NOT have empty parentheses when attr is empty. Got: {}",
182
- result_str
183
- );
184
- }
185
-
186
- /// Verifies that the macro adds #[soroban_sdk::contractimpl(attr)] when attr is provided
187
- #[test]
188
- fn test_adds_soroban_contractimpl_attribute_with_attr() {
189
- let input = quote! {
190
- impl SomeTrait for MyContract {
191
- fn my_method(env: Env) {}
192
- }
193
- };
194
-
195
- let attr = quote! { contracttrait };
196
- let result = crate::contract_impl::contract_impl(attr, input);
197
- let result_str = result.to_string();
198
-
199
- // Should have contractimpl with the attr in parentheses
200
- assert!(
201
- result_str.contains("contractimpl (contracttrait)"),
202
- "should add #[soroban_sdk::contractimpl(contracttrait)] attribute. Got: {}",
203
- result_str
204
- );
205
- }
206
-
207
- /// Expected TTL extension behavior for a test case
208
- #[derive(Clone)]
209
- enum TtlExpectation {
210
- /// TTL extension should NOT be inserted
211
- None,
212
- /// TTL extension should be inserted with the given env patterns
213
- /// - `instance_arg`: pattern in `TtlConfigStorage::instance(...)` (e.g., "& env" for owned, "env" for ref)
214
- /// - `storage_ident`: identifier for `.storage()` call
215
- Present { instance_arg: &'static str, storage_ident: &'static str },
216
- }
217
-
218
- struct TtlTestCase {
219
- name: &'static str,
220
- input: TokenStream,
221
- expectation: TtlExpectation,
222
- }
223
-
224
- impl TtlTestCase {
225
- fn expect_ttl(
226
- name: &'static str,
227
- input: TokenStream,
228
- instance_arg: &'static str,
229
- storage_ident: &'static str,
230
- ) -> Self {
231
- Self { name, input, expectation: TtlExpectation::Present { instance_arg, storage_ident } }
232
- }
233
-
234
- fn expect_no_ttl(name: &'static str, input: TokenStream) -> Self {
235
- Self { name, input, expectation: TtlExpectation::None }
236
- }
237
-
238
- fn run(&self) {
239
- let result = crate::contract_impl::contract_impl(TokenStream::new(), self.input.clone());
240
- let result_str = result.to_string();
241
- let has_ttl = result_str.contains("TtlConfigStorage :: instance");
242
-
243
- match &self.expectation {
244
- TtlExpectation::None => {
245
- assert!(!has_ttl, "{}: TTL extension should NOT be present, but was found", self.name);
246
- }
247
- TtlExpectation::Present { instance_arg, storage_ident } => {
248
- assert!(has_ttl, "{}: TTL extension should be present, but was not found", self.name);
249
- assert!(result_str.contains("extend_ttl"), "{}: should insert extend_ttl call", self.name);
250
-
251
- let instance_pattern = format!("TtlConfigStorage :: instance ({})", instance_arg);
252
- assert!(
253
- result_str.contains(&instance_pattern),
254
- "{}: expected '{}' in TtlConfigStorage::instance call. Got: {}",
255
- self.name,
256
- instance_arg,
257
- result_str
258
- );
259
-
260
- let storage_pattern = format!("{} . storage ()", storage_ident);
261
- assert!(
262
- result_str.contains(&storage_pattern),
263
- "{}: expected '{}.storage()' call",
264
- self.name,
265
- storage_ident
266
- );
267
- }
268
- }
269
- }
270
- }
271
-
272
- #[test]
273
- fn test_ttl_extension_with_owned_env() {
274
- TtlTestCase::expect_ttl(
275
- "public method with owned Env",
276
- quote! {
277
- impl MyContract {
278
- pub fn my_method(env: Env) { let x = 1; }
279
- }
280
- },
281
- "& env", // instance takes reference
282
- "env", // storage called on ident
283
- )
284
- .run();
285
- }
286
-
287
- #[test]
288
- fn test_ttl_extension_with_ref_env() {
289
- TtlTestCase::expect_ttl(
290
- "public method with ref Env",
291
- quote! {
292
- impl MyContract {
293
- pub fn my_method(env: &Env) { let x = 1; }
294
- }
295
- },
296
- "env", // instance takes ident directly (already a ref)
297
- "env",
298
- )
299
- .run();
300
- }
301
-
302
- #[test]
303
- fn test_ttl_extension_with_custom_env_ident_owned() {
304
- TtlTestCase::expect_ttl(
305
- "custom Env identifier (owned)",
306
- quote! {
307
- impl MyContract {
308
- pub fn my_method(my_custom_env: Env) { let x = 1; }
309
- }
310
- },
311
- "& my_custom_env",
312
- "my_custom_env",
313
- )
314
- .run();
315
- }
316
-
317
- #[test]
318
- fn test_ttl_extension_with_custom_env_ident_ref() {
319
- TtlTestCase::expect_ttl(
320
- "custom Env identifier (ref)",
321
- quote! {
322
- impl MyContract {
323
- pub fn my_method(my_custom_env: &Env) { let x = 1; }
324
- }
325
- },
326
- "my_custom_env",
327
- "my_custom_env",
328
- )
329
- .run();
330
- }
331
-
332
- #[test]
333
- fn test_ttl_extension_for_trait_impl_owned_env() {
334
- TtlTestCase::expect_ttl(
335
- "trait impl method with owned Env",
336
- quote! {
337
- impl SomeTrait for MyContract {
338
- fn trait_method(env: Env) { let x = 1; }
339
- }
340
- },
341
- "& env",
342
- "env",
343
- )
344
- .run();
345
- }
346
-
347
- #[test]
348
- fn test_ttl_extension_for_trait_impl_ref_env() {
349
- TtlTestCase::expect_ttl(
350
- "trait impl method with ref Env",
351
- quote! {
352
- impl SomeTrait for MyContract {
353
- fn trait_method(env: &Env) { let x = 1; }
354
- }
355
- },
356
- "env",
357
- "env",
358
- )
359
- .run();
360
- }
361
-
362
- #[test]
363
- fn test_no_ttl_extension_for_private_method() {
364
- TtlTestCase::expect_no_ttl(
365
- "private method with Env",
366
- quote! {
367
- impl MyContract {
368
- fn private_method(env: Env) { let x = 1; }
369
- }
370
- },
371
- )
372
- .run();
373
- }
374
-
375
- #[test]
376
- fn test_no_ttl_extension_without_env_param() {
377
- TtlTestCase::expect_no_ttl(
378
- "public method without Env",
379
- quote! {
380
- impl MyContract {
381
- pub fn no_env_method(value: u32) -> u32 { value }
382
- }
383
- },
384
- )
385
- .run();
386
- }
@@ -1,12 +0,0 @@
1
- ---
2
- source: contracts/common-macros/src/tests/ownable.rs
3
- assertion_line: 17
4
- expression: formatted
5
- ---
6
- pub struct MyContract;
7
- use utils::ownable::OwnableInitializer as _;
8
- use utils::ownable::Ownable;
9
- impl utils::ownable::OwnableInitializer for MyContract {}
10
- /// Implement the Ownable trait for the contract with default implementations.
11
- #[common_macros::contract_impl(contracttrait)]
12
- impl Ownable for MyContract {}
@@ -1,50 +0,0 @@
1
- // Runtime tests: `extend_instance_ttl` behavior.
2
- //
3
- // Tests covered:
4
- // - `extend_instance_ttl` exists on `#[ttl_configurable]` contracts and manually extends instance TTL.
5
-
6
- use common_macros::{ownable, ttl_configurable};
7
- use soroban_sdk::{
8
- contract, contractimpl,
9
- testutils::{storage::Instance as _, Address as _, Ledger as _},
10
- Address, Env,
11
- };
12
-
13
- #[contract]
14
- #[ttl_configurable]
15
- #[ownable]
16
- pub struct TestContract;
17
-
18
- #[contractimpl]
19
- impl TestContract {
20
- pub fn init(env: Env, owner: Address) {
21
- Self::init_owner(&env, &owner);
22
- }
23
- }
24
-
25
- #[test]
26
- fn extend_instance_ttl_extends() {
27
- let env = Env::default();
28
- let contract_id = env.register(TestContract, ());
29
- let client = TestContractClient::new(&env, &contract_id);
30
-
31
- // Write something to ensure instance storage exists and has a TTL.
32
- let owner = Address::generate(&env);
33
- client.init(&owner);
34
-
35
- let (ttl_before, seq_before) =
36
- env.as_contract(&contract_id, || (env.storage().instance().get_ttl(), env.ledger().sequence()));
37
- let live_until = seq_before + ttl_before;
38
-
39
- // Choose a threshold near the current TTL and extend further.
40
- let threshold = ttl_before.saturating_sub(1);
41
- let extend_to = ttl_before + 50;
42
-
43
- // Set sequence so remaining TTL == threshold (i.e. at the trigger point).
44
- env.ledger().set_sequence_number(live_until - threshold);
45
-
46
- client.extend_instance_ttl(&threshold, &extend_to);
47
-
48
- let ttl_after = env.as_contract(&contract_id, || env.storage().instance().get_ttl());
49
- assert_eq!(ttl_after, extend_to);
50
- }