@layerzerolabs/protocol-stellar-v2 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.turbo/turbo-build.log +443 -302
  2. package/.turbo/turbo-lint.log +118 -96
  3. package/.turbo/turbo-test.log +853 -731
  4. package/Cargo.lock +120 -37
  5. package/Cargo.toml +8 -5
  6. package/contracts/common-macros/src/contract_impl.rs +44 -0
  7. package/contracts/common-macros/src/lib.rs +86 -40
  8. package/contracts/common-macros/src/ownable.rs +24 -32
  9. package/contracts/common-macros/src/storage.rs +95 -120
  10. package/contracts/common-macros/src/tests/contract_impl.rs +289 -0
  11. package/contracts/common-macros/src/tests/mod.rs +9 -0
  12. package/contracts/common-macros/src/tests/ownable.rs +151 -0
  13. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +85 -0
  14. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +30 -0
  15. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap +9 -0
  16. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +1072 -0
  17. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +45 -0
  18. package/contracts/common-macros/src/tests/storage.rs +485 -0
  19. package/contracts/common-macros/src/tests/test_helpers.rs +93 -0
  20. package/contracts/common-macros/src/tests/ttl_configurable.rs +34 -0
  21. package/contracts/common-macros/src/ttl_configurable.rs +31 -14
  22. package/contracts/common-macros/src/utils.rs +27 -0
  23. package/contracts/endpoint-v2/ARCHITECTURE.md +4 -4
  24. package/contracts/endpoint-v2/src/endpoint_v2.rs +18 -15
  25. package/contracts/endpoint-v2/src/interfaces/message_lib.rs +2 -3
  26. package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +5 -3
  27. package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +2 -2
  28. package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +2 -2
  29. package/contracts/endpoint-v2/src/interfaces/send_lib.rs +4 -4
  30. package/contracts/endpoint-v2/src/lib.rs +6 -5
  31. package/contracts/endpoint-v2/src/message_lib_manager.rs +14 -6
  32. package/contracts/endpoint-v2/src/messaging_channel.rs +6 -2
  33. package/contracts/endpoint-v2/src/messaging_composer.rs +6 -2
  34. package/contracts/endpoint-v2/src/storage.rs +10 -7
  35. package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +16 -16
  36. package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +46 -46
  37. package/contracts/endpoint-v2/src/tests/mock.rs +2 -2
  38. package/contracts/endpoint-v2/src/util.rs +8 -2
  39. package/contracts/message-libs/block-message-lib/Cargo.toml +1 -0
  40. package/contracts/message-libs/block-message-lib/src/lib.rs +5 -5
  41. package/contracts/message-libs/message-lib-common/src/errors.rs +8 -8
  42. package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +0 -1
  43. package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +3 -3
  44. package/contracts/message-libs/message-lib-common/src/lib.rs +0 -2
  45. package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +4 -6
  46. package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +2 -2
  47. package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +11 -11
  48. package/contracts/message-libs/message-lib-common/src/worker_options.rs +10 -16
  49. package/contracts/message-libs/simple-message-lib/src/errors.rs +0 -4
  50. package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +49 -34
  51. package/contracts/message-libs/simple-message-lib/src/storage.rs +3 -7
  52. package/contracts/message-libs/simple-message-lib/src/test.rs +3 -3
  53. package/contracts/message-libs/treasury/src/storage.rs +1 -2
  54. package/contracts/message-libs/treasury/src/tests/setup.rs +3 -2
  55. package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +0 -13
  56. package/contracts/message-libs/treasury/src/treasury.rs +18 -21
  57. package/contracts/message-libs/uln-302/Cargo.toml +1 -0
  58. package/contracts/message-libs/uln-302/src/interfaces/mod.rs +4 -4
  59. package/contracts/message-libs/uln-302/src/interfaces/{receive.rs → receive_uln.rs} +3 -3
  60. package/contracts/message-libs/uln-302/src/interfaces/{send.rs → send_uln.rs} +8 -80
  61. package/contracts/message-libs/uln-302/src/lib.rs +5 -4
  62. package/contracts/message-libs/uln-302/src/{receive.rs → receive_uln.rs} +20 -12
  63. package/contracts/message-libs/uln-302/src/{send.rs → send_uln.rs} +19 -13
  64. package/contracts/message-libs/uln-302/src/storage.rs +1 -2
  65. package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +3 -2
  66. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +30 -30
  67. package/contracts/message-libs/uln-302/src/tests/setup.rs +12 -11
  68. package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +1 -1
  69. package/contracts/message-libs/uln-302/src/{config_validation.rs → types.rs} +79 -11
  70. package/contracts/message-libs/uln-302/src/uln302.rs +15 -10
  71. package/contracts/oapp-macros/Cargo.toml +2 -8
  72. package/contracts/oapp-macros/src/lib.rs +57 -311
  73. package/contracts/oapp-macros/src/oapp_core.rs +23 -32
  74. package/contracts/oapp-macros/src/oapp_full.rs +8 -2
  75. package/contracts/oapp-macros/src/oapp_options_type3.rs +21 -36
  76. package/contracts/oapp-macros/src/oapp_receiver.rs +38 -57
  77. package/contracts/oapp-macros/src/oapp_sender.rs +12 -14
  78. package/contracts/oapp-macros/src/util.rs +14 -10
  79. package/contracts/oapps/counter/Cargo.toml +2 -1
  80. package/contracts/oapps/counter/integration_tests/utils.rs +4 -4
  81. package/contracts/oapps/counter/src/codec.rs +8 -9
  82. package/contracts/oapps/counter/src/counter.rs +156 -147
  83. package/contracts/oapps/counter/src/storage.rs +1 -2
  84. package/contracts/oapps/counter/src/tests/test_codec.rs +5 -5
  85. package/contracts/oapps/counter/src/tests/test_counter.rs +11 -13
  86. package/contracts/oapps/oapp/Cargo.toml +1 -0
  87. package/contracts/oapps/oapp/src/errors.rs +1 -1
  88. package/contracts/oapps/oapp/src/lib.rs +3 -0
  89. package/contracts/oapps/oapp/src/macro_tests/mod.rs +1 -0
  90. package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +312 -0
  91. package/contracts/oapps/oapp/src/oapp_core.rs +52 -53
  92. package/contracts/oapps/oapp/src/oapp_options_type3.rs +18 -28
  93. package/contracts/oapps/oapp/src/oapp_receiver.rs +82 -31
  94. package/contracts/oapps/oapp/src/oapp_sender.rs +55 -13
  95. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +16 -3
  96. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +33 -8
  97. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +6 -9
  98. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +28 -15
  99. package/contracts/oapps/oft/Cargo.toml +27 -0
  100. package/contracts/oapps/oft/integration-tests/mod.rs +3 -0
  101. package/contracts/oapps/oft/integration-tests/setup.rs +320 -0
  102. package/contracts/oapps/oft/integration-tests/test_with_sml.rs +155 -0
  103. package/contracts/oapps/oft/integration-tests/utils.rs +201 -0
  104. package/contracts/oapps/oft/src/codec/mod.rs +2 -0
  105. package/contracts/oapps/oft/src/codec/oft_compose_msg_codec.rs +55 -0
  106. package/contracts/oapps/oft/src/codec/oft_msg_codec.rs +62 -0
  107. package/contracts/oapps/oft/src/constants.rs +5 -0
  108. package/contracts/oapps/oft/src/errors.rs +8 -0
  109. package/contracts/oapps/oft/src/events.rs +19 -0
  110. package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +23 -0
  111. package/contracts/oapps/oft/src/interfaces/mod.rs +3 -0
  112. package/contracts/oapps/oft/src/lib.rs +22 -0
  113. package/contracts/oapps/oft/src/macro_tests/mod.rs +2 -0
  114. package/contracts/oapps/oft/src/macro_tests/test_all_default.rs +41 -0
  115. package/contracts/oapps/oft/src/macro_tests/test_override.rs +83 -0
  116. package/contracts/oapps/oft/src/oft.rs +320 -0
  117. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +50 -0
  118. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +50 -0
  119. package/contracts/oapps/oft/src/oft_types/mod.rs +10 -0
  120. package/contracts/oapps/oft/src/storage.rs +11 -0
  121. package/contracts/oapps/oft/src/tests/mod.rs +13 -0
  122. package/contracts/oapps/oft/src/tests/test_decimals.rs +89 -0
  123. package/contracts/oapps/oft/src/tests/test_lz_receive.rs +282 -0
  124. package/contracts/oapps/oft/src/tests/test_oft_compose_msg_codec.rs +68 -0
  125. package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +136 -0
  126. package/contracts/oapps/oft/src/tests/test_oft_version.rs +13 -0
  127. package/contracts/oapps/oft/src/tests/test_quote_oft.rs +159 -0
  128. package/contracts/oapps/oft/src/tests/test_quote_send.rs +195 -0
  129. package/contracts/oapps/oft/src/tests/test_resolve_address.rs +37 -0
  130. package/contracts/oapps/oft/src/tests/test_send.rs +915 -0
  131. package/contracts/oapps/oft/src/tests/test_token.rs +47 -0
  132. package/contracts/oapps/oft/src/tests/test_utils.rs +789 -0
  133. package/contracts/oapps/oft/src/types.rs +38 -0
  134. package/contracts/oapps/oft/src/utils.rs +67 -0
  135. package/contracts/oapps/oft-mint-burn/Cargo.toml +26 -0
  136. package/contracts/oapps/oft-mint-burn/src/lib.rs +3 -0
  137. package/contracts/oapps/oft-mint-burn/src/oft.rs +28 -0
  138. package/contracts/oapps/oft-mint-burn/src/tests/mod.rs +1 -0
  139. package/contracts/utils/src/buffer_reader.rs +8 -9
  140. package/contracts/utils/src/buffer_writer.rs +11 -5
  141. package/contracts/utils/src/errors.rs +5 -5
  142. package/contracts/utils/src/ownable.rs +14 -6
  143. package/contracts/utils/src/testing_utils.rs +11 -1
  144. package/contracts/utils/src/tests/buffer_reader.rs +491 -730
  145. package/contracts/utils/src/tests/buffer_writer.rs +336 -148
  146. package/contracts/utils/src/tests/bytes_ext.rs +125 -40
  147. package/contracts/utils/src/tests/mod.rs +3 -0
  148. package/contracts/utils/src/tests/ownable.rs +379 -27
  149. package/contracts/utils/src/tests/test_helper.rs +47 -0
  150. package/contracts/utils/src/tests/testing_utils.rs +555 -0
  151. package/contracts/utils/src/tests/ttl.rs +421 -0
  152. package/contracts/utils/src/ttl.rs +29 -89
  153. package/contracts/workers/dvn/Cargo.toml +31 -0
  154. package/contracts/workers/dvn/src/auth.rs +66 -0
  155. package/contracts/workers/dvn/src/dvn.rs +143 -0
  156. package/contracts/workers/dvn/src/errors.rs +21 -0
  157. package/contracts/workers/dvn/src/events.rs +19 -0
  158. package/contracts/workers/dvn/src/interfaces/dvn.rs +12 -0
  159. package/contracts/workers/dvn/src/interfaces/mod.rs +5 -0
  160. package/contracts/workers/dvn/src/interfaces/multisig.rs +15 -0
  161. package/contracts/workers/dvn/src/lib.rs +24 -0
  162. package/contracts/workers/dvn/src/multisig.rs +127 -0
  163. package/contracts/workers/dvn/src/storage.rs +35 -0
  164. package/contracts/workers/dvn/src/tests/auth.rs +237 -0
  165. package/contracts/workers/dvn/src/tests/dvn.rs +349 -0
  166. package/contracts/workers/dvn/src/tests/key_pair.rs +66 -0
  167. package/contracts/workers/dvn/src/tests/mod.rs +5 -0
  168. package/contracts/workers/dvn/src/tests/multisig/mod.rs +3 -0
  169. package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +133 -0
  170. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +108 -0
  171. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +109 -0
  172. package/contracts/workers/dvn/src/tests/setup.rs +109 -0
  173. package/contracts/workers/dvn/src/types.rs +26 -0
  174. package/contracts/workers/dvn-fee-lib/Cargo.toml +24 -0
  175. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +113 -0
  176. package/contracts/workers/dvn-fee-lib/src/errors.rs +8 -0
  177. package/contracts/workers/dvn-fee-lib/src/lib.rs +17 -0
  178. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +282 -0
  179. package/contracts/workers/dvn-fee-lib/src/tests/mod.rs +1 -0
  180. package/contracts/workers/executor/Cargo.toml +10 -7
  181. package/contracts/workers/executor/src/errors.rs +8 -0
  182. package/contracts/workers/executor/src/events.rs +4 -7
  183. package/contracts/workers/executor/src/interfaces/executor.rs +72 -22
  184. package/contracts/workers/executor/src/interfaces/mod.rs +0 -2
  185. package/contracts/workers/executor/src/lib.rs +16 -7
  186. package/contracts/workers/executor/src/lz_executor.rs +308 -0
  187. package/contracts/workers/executor/src/storage.rs +24 -16
  188. package/contracts/workers/executor-fee-lib/Cargo.toml +22 -0
  189. package/contracts/workers/executor-fee-lib/src/errors.rs +15 -0
  190. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +215 -0
  191. package/contracts/workers/executor-fee-lib/src/executor_option.rs +203 -0
  192. package/contracts/workers/executor-fee-lib/src/lib.rs +7 -0
  193. package/contracts/workers/executor-helper/Cargo.toml +29 -0
  194. package/contracts/workers/executor-helper/src/executor_helper.rs +161 -0
  195. package/contracts/workers/executor-helper/src/lib.rs +11 -0
  196. package/contracts/workers/{worker-common → worker}/Cargo.toml +1 -4
  197. package/contracts/workers/worker/src/errors.rs +24 -0
  198. package/contracts/workers/worker/src/events.rs +62 -0
  199. package/contracts/workers/worker/src/interfaces/dvn_fee_lib.rs +75 -0
  200. package/contracts/workers/worker/src/interfaces/executor_fee_lib.rs +84 -0
  201. package/contracts/workers/{worker-common → worker}/src/interfaces/mod.rs +2 -2
  202. package/contracts/workers/worker/src/interfaces/price_feed.rs +85 -0
  203. package/contracts/workers/worker/src/lib.rs +14 -0
  204. package/contracts/workers/worker/src/storage.rs +63 -0
  205. package/contracts/workers/worker/src/worker.rs +459 -0
  206. package/package.json +3 -3
  207. package/sdk/dist/generated/bml.d.ts +88 -17
  208. package/sdk/dist/generated/bml.js +62 -16
  209. package/sdk/dist/generated/counter.d.ts +281 -102
  210. package/sdk/dist/generated/counter.js +93 -41
  211. package/sdk/dist/generated/endpoint.d.ts +128 -105
  212. package/sdk/dist/generated/endpoint.js +47 -45
  213. package/sdk/dist/generated/sml.d.ts +212 -69
  214. package/sdk/dist/generated/sml.js +103 -53
  215. package/sdk/dist/generated/uln302.d.ts +270 -173
  216. package/sdk/dist/generated/uln302.js +112 -64
  217. package/sdk/package.json +11 -11
  218. package/sdk/test/index.test.ts +147 -42
  219. package/sdk/test/suites/constants.ts +7 -3
  220. package/sdk/test/suites/deploy.ts +65 -42
  221. package/sdk/test/suites/localnet.ts +2 -2
  222. package/sdk/test/suites/scan.ts +28 -25
  223. package/sdk/test/utils.ts +199 -0
  224. package/sdk/tsconfig.json +93 -95
  225. package/tools/ts-bindings-gen/src/main.rs +2 -0
  226. package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +0 -310
  227. package/contracts/common-macros/src/tests.rs +0 -287
  228. package/contracts/oapp-macros/tests/test_macros.rs +0 -522
  229. package/contracts/workers/executor/src/executor.rs +0 -347
  230. package/contracts/workers/executor/src/interfaces/types.rs +0 -51
  231. package/contracts/workers/worker-common/src/constants.rs +0 -17
  232. package/contracts/workers/worker-common/src/errors.rs +0 -6
  233. package/contracts/workers/worker-common/src/events.rs +0 -34
  234. package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +0 -35
  235. package/contracts/workers/worker-common/src/interfaces/price_feed.rs +0 -40
  236. package/contracts/workers/worker-common/src/interfaces/worker.rs +0 -60
  237. package/contracts/workers/worker-common/src/lib.rs +0 -19
  238. package/contracts/workers/worker-common/src/storage.rs +0 -32
  239. package/contracts/workers/worker-common/src/worker_common.rs +0 -166
@@ -0,0 +1,38 @@
1
+ use soroban_sdk::{contracttype, Bytes, BytesN};
2
+
3
+ /// Parameters for sending OFT tokens cross-chain
4
+ #[contracttype]
5
+ #[derive(Clone, PartialEq, Eq, Debug)]
6
+ pub struct SendParam {
7
+ pub dst_eid: u32,
8
+ pub to: BytesN<32>,
9
+ pub amount_ld: i128,
10
+ pub min_amount_ld: i128,
11
+ pub extra_options: Bytes,
12
+ pub compose_msg: Bytes,
13
+ pub oft_cmd: Bytes,
14
+ }
15
+
16
+ /// Transfer limits for OFT operations
17
+ #[contracttype]
18
+ #[derive(Clone, PartialEq, Eq, Debug)]
19
+ pub struct OFTLimit {
20
+ pub min_amount_ld: i128,
21
+ pub max_amount_ld: i128,
22
+ }
23
+
24
+ /// Receipt containing amounts sent and received in an OFT transfer
25
+ #[contracttype]
26
+ #[derive(Clone, PartialEq, Eq, Debug)]
27
+ pub struct OFTReceipt {
28
+ pub amount_sent_ld: i128,
29
+ pub amount_received_ld: i128,
30
+ }
31
+
32
+ /// Details about fees charged in an OFT operation
33
+ #[contracttype]
34
+ #[derive(Clone, PartialEq, Eq, Debug)]
35
+ pub struct OFTFeeDetail {
36
+ pub fee_amount_ld: i128,
37
+ pub description: Bytes,
38
+ }
@@ -0,0 +1,67 @@
1
+ use soroban_sdk::{address_payload::AddressPayload, assert_with_error, Address, BytesN, Env};
2
+
3
+ use crate::errors::OFTError;
4
+
5
+ // =====================================================
6
+ // OFT Helper Functions
7
+ // =====================================================
8
+
9
+ /// Converts from shared decimals (SD) to local decimals (LD).
10
+ pub fn to_ld(amount_sd: u64, conversion_rate: i128) -> i128 {
11
+ (amount_sd as i128) * conversion_rate
12
+ }
13
+
14
+ /// Converts from local decimals (LD) to shared decimals (SD).
15
+ pub fn to_sd(env: &Env, amount_ld: i128, conversion_rate: i128) -> u64 {
16
+ let amount_sd = amount_ld / conversion_rate;
17
+ assert_with_error!(env, amount_sd <= u64::MAX as i128, OFTError::Overflow);
18
+ amount_sd as u64
19
+ }
20
+
21
+ /// Removes dust from amount based on decimal conversion rate.
22
+ pub fn remove_dust(amount_ld: i128, conversion_rate: i128) -> i128 {
23
+ (amount_ld / conversion_rate) * conversion_rate
24
+ }
25
+
26
+ // =====================================================
27
+ // Address Helper Functions
28
+ // =====================================================
29
+
30
+ /// Extracts the 32-byte payload from an address.
31
+ ///
32
+ /// This function extracts the raw 32-byte payload from a Stellar address,
33
+ /// which can be either a contract ID hash or an Ed25519 public key.
34
+ /// This payload can later be resolved back to an address using `resolve_address`.
35
+ ///
36
+ /// # Arguments
37
+ /// * `address` - The Stellar address to extract the payload from
38
+ ///
39
+ /// # Returns
40
+ /// A 32-byte payload (contract ID hash or Ed25519 public key)
41
+ pub fn address_to_bytes32(address: &Address) -> BytesN<32> {
42
+ match address.to_payload().unwrap() {
43
+ AddressPayload::ContractIdHash(payload) => payload,
44
+ AddressPayload::AccountIdPublicKeyEd25519(payload) => payload,
45
+ }
46
+ }
47
+
48
+ /// Resolves a 32-byte payload to an address.
49
+ ///
50
+ /// This function attempts to convert the 32-byte payload to a contract address first.
51
+ /// If the contract exists, it returns the contract address.
52
+ /// If the contract doesn't exist, it falls back to creating a G-address (account address).
53
+ ///
54
+ /// # Arguments
55
+ /// * `env` - The Soroban environment
56
+ /// * `bytes32` - The 32-byte payload to resolve
57
+ ///
58
+ /// # Returns
59
+ /// The resolved address (either contract or account address)
60
+ pub fn resolve_address(env: &Env, bytes32: &BytesN<32>) -> Address {
61
+ let contract_address = Address::from_payload(env, AddressPayload::ContractIdHash(bytes32.clone()));
62
+ if contract_address.exists() {
63
+ contract_address
64
+ } else {
65
+ Address::from_payload(env, AddressPayload::AccountIdPublicKeyEd25519(bytes32.clone()))
66
+ }
67
+ }
@@ -0,0 +1,26 @@
1
+ [package]
2
+ name = "oft-mint-burn"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ license.workspace = true
6
+
7
+ [lib]
8
+ crate-type = ["cdylib"]
9
+ doctest = false
10
+
11
+ [dependencies]
12
+ soroban-sdk = { workspace = true }
13
+ endpoint-v2 = { workspace = true, features = ["library"] }
14
+ utils = { workspace = true }
15
+ oapp = { workspace = true }
16
+ common-macros = { workspace = true }
17
+ oapp-macros = { workspace = true }
18
+ oft = { workspace = true }
19
+
20
+ [dev-dependencies]
21
+ soroban-sdk = { workspace = true, features = ["testutils"] }
22
+ assert_unordered = "0.3.5"
23
+ simple-message-lib = { workspace = true }
24
+ message-lib-common = { workspace = true, features = ["testutils"] }
25
+ endpoint-v2 = { workspace = true, features = ["testutils"] }
26
+ executor = { workspace = true, features = ["testutils"] }
@@ -0,0 +1,3 @@
1
+ #![no_std]
2
+
3
+ pub mod oft;
@@ -0,0 +1,28 @@
1
+ use oapp_macros::oapp;
2
+ use oft::oft::{oft_initialize, OFTInner, OFT};
3
+ use oft::oft_types::mint_burn;
4
+ use oft::types::OFTReceipt;
5
+ use soroban_sdk::{contractimpl, Address, Env};
6
+
7
+ #[oapp]
8
+ pub struct OFTMintBurn;
9
+
10
+ #[contractimpl]
11
+ impl OFTMintBurn {
12
+ pub fn __constructor(env: &Env, token: &Address, owner: &Address, endpoint: &Address, delegate: &Option<Address>) {
13
+ oft_initialize::<Self>(env, owner, token, endpoint, delegate)
14
+ }
15
+ }
16
+
17
+ #[contractimpl(contracttrait)]
18
+ impl OFT for OFTMintBurn {}
19
+
20
+ impl OFTInner for OFTMintBurn {
21
+ fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
22
+ mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid)
23
+ }
24
+
25
+ fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
26
+ mint_burn::credit::<Self>(env, to, amount_ld, src_eid)
27
+ }
28
+ }
@@ -34,9 +34,7 @@ impl<'a> BufferReader<'a> {
34
34
  Self { buffer, pos: 0 }
35
35
  }
36
36
 
37
- // TODO: should we pass and return a self instead of mutable reference?
38
- /// Sets the absolute position in the buffer.
39
- pub fn set_position(&mut self, pos: u32) -> &mut Self {
37
+ pub fn seek(&mut self, pos: u32) -> &mut Self {
40
38
  assert_with_error!(self.buffer.env(), pos <= self.buffer.len(), BufferReaderError::InvalidLength);
41
39
  self.pos = pos;
42
40
  self
@@ -44,7 +42,7 @@ impl<'a> BufferReader<'a> {
44
42
 
45
43
  /// Advances the position by `len` bytes without reading.
46
44
  pub fn skip(&mut self, len: u32) -> &mut Self {
47
- self.set_position(self.pos + len)
45
+ self.seek(self.pos + len)
48
46
  }
49
47
 
50
48
  /// Moves the position backwards by `len` bytes.
@@ -55,7 +53,7 @@ impl<'a> BufferReader<'a> {
55
53
  }
56
54
 
57
55
  // Generates: read_u8 (1 byte), read_u16 (2 bytes), read_u32 (4 bytes), read_u64 (8 bytes), read_u128 (16 bytes)
58
- impl_read_uint!(read_u8, u8, 1; read_u16, u16, 2; read_u32, u32, 4; read_u64, u64, 8; read_u128, u128, 16);
56
+ impl_read_uint!(read_u8, u8, 1; read_u16, u16, 2; read_u32, u32, 4; read_u64, u64, 8; read_u128, u128, 16; read_i128, i128, 16);
59
57
 
60
58
  /// Reads a boolean (1 byte, non-zero = true).
61
59
  pub fn read_bool(&mut self) -> bool {
@@ -94,9 +92,8 @@ impl<'a> BufferReader<'a> {
94
92
  value
95
93
  }
96
94
 
97
- /// Reads all remaining bytes from current position to end.
98
95
  pub fn read_bytes_until_end(&mut self) -> Bytes {
99
- self.read_bytes(self.remaining())
96
+ self.read_bytes(self.remaining_len())
100
97
  }
101
98
 
102
99
  /// Returns the current read position.
@@ -120,7 +117,7 @@ impl<'a> BufferReader<'a> {
120
117
  }
121
118
 
122
119
  /// Returns the number of bytes remaining after current position.
123
- pub fn remaining(&self) -> u32 {
120
+ pub fn remaining_len(&self) -> u32 {
124
121
  self.buffer.len() - self.pos
125
122
  }
126
123
 
@@ -129,7 +126,9 @@ impl<'a> BufferReader<'a> {
129
126
  self.buffer.env()
130
127
  }
131
128
 
132
- // === Internal Functions ===
129
+ // ============================================================================================
130
+ // Internal Functions
131
+ // ============================================================================================
133
132
 
134
133
  /// Compose an address from its type byte and 32-byte payload.
135
134
  fn compose_address(&self, payload_type: u8, payload: BytesN<32>) -> Address {
@@ -47,7 +47,7 @@ impl BufferWriter {
47
47
  }
48
48
 
49
49
  // Generates: write_u8 (1 byte), write_u16 (2 bytes), write_u32 (4 bytes), write_u64 (8 bytes), write_u128 (16 bytes)
50
- impl_write_uint!(write_u8, u8; write_u16, u16; write_u32, u32; write_u64, u64; write_u128, u128);
50
+ impl_write_uint!(write_u8, u8; write_u16, u16; write_u32, u32; write_u64, u64; write_u128, u128; write_i128, i128);
51
51
 
52
52
  /// Write a boolean value to the buffer (true as 1, false as 0).
53
53
  pub fn write_bool(&mut self, value: bool) -> &mut Self {
@@ -66,6 +66,11 @@ impl BufferWriter {
66
66
  self
67
67
  }
68
68
 
69
+ pub fn write_array<const N: usize>(&mut self, array: &[u8; N]) -> &mut Self {
70
+ self.buffer.extend_from_array(array);
71
+ self
72
+ }
73
+
69
74
  /// Write a fixed-size BytesN<N> to the buffer.
70
75
  pub fn write_bytes_n<const N: usize>(&mut self, bytes_n: &BytesN<N>) -> &mut Self {
71
76
  self.buffer.extend_from_array(&bytes_n.to_array());
@@ -85,9 +90,8 @@ impl BufferWriter {
85
90
  }
86
91
 
87
92
  /// Get the complete buffer as a Bytes, consuming the writer.
88
- pub fn to_bytes(self) -> Bytes {
89
- let Self { buffer } = self;
90
- buffer
93
+ pub fn to_bytes(&self) -> Bytes {
94
+ self.buffer.clone()
91
95
  }
92
96
 
93
97
  /// Get the current length of the buffer.
@@ -105,7 +109,9 @@ impl BufferWriter {
105
109
  self.buffer.env()
106
110
  }
107
111
 
108
- // === Internal Functions ===
112
+ // ============================================================================================
113
+ // Internal Functions
114
+ // ============================================================================================
109
115
 
110
116
  /// Decompose an address into its type byte and 32-byte payload.
111
117
  fn decompose_address(&self, address: &Address) -> (u8, BytesN<32>) {
@@ -2,29 +2,29 @@ use common_macros::contract_error;
2
2
 
3
3
  #[contract_error]
4
4
  pub enum BufferReaderError {
5
- InvalidLength = 10000,
5
+ InvalidLength = 1000,
6
6
  InvalidAddressPayload,
7
7
  }
8
8
 
9
9
  #[contract_error]
10
10
  pub enum BufferWriterError {
11
- InvalidAddressPayload = 10100,
11
+ InvalidAddressPayload = 1100,
12
12
  }
13
13
 
14
14
  #[contract_error]
15
15
  pub enum TtlError {
16
- InvalidTtlConfig = 10200,
16
+ InvalidTtlConfig = 1200,
17
17
  TtlConfigFrozen,
18
18
  TtlConfigAlreadyFrozen,
19
19
  }
20
20
 
21
21
  #[contract_error]
22
22
  pub enum OwnableError {
23
- OwnerAlreadySet = 10300,
23
+ OwnerAlreadySet = 1300,
24
24
  OwnerNotSet,
25
25
  }
26
26
 
27
27
  #[contract_error]
28
28
  pub enum BytesExtError {
29
- LengthMismatch = 10400,
29
+ LengthMismatch = 1400,
30
30
  }
@@ -1,9 +1,18 @@
1
- use crate as utils;
1
+ use crate::errors::OwnableError;
2
2
  use crate::option_ext::OptionExt;
3
- use crate::{errors::OwnableError, ttl::DefaultTtlConfigProvider};
4
3
  use common_macros::{event, storage};
5
4
  use soroban_sdk::{assert_with_error, contractclient, Address, Env};
6
5
 
6
+ // ============================================
7
+ // Ownable Initializer Interface
8
+ // ============================================
9
+
10
+ /// Trait for initializing contract ownership.
11
+ pub trait OwnableInitializer {
12
+ /// Initializes the owner. Should only be called once at contract initialization.
13
+ fn init_owner(env: &Env, owner: &Address);
14
+ }
15
+
7
16
  // ============================================
8
17
  // Ownable Interface
9
18
  // ============================================
@@ -55,7 +64,7 @@ pub struct OwnershipRenounced {
55
64
  pub struct DefaultOwnable;
56
65
 
57
66
  /// Storage keys for DefaultOwnable.
58
- #[storage(DefaultTtlConfigProvider)]
67
+ #[storage]
59
68
  pub enum DefaultOwnableStorage {
60
69
  #[instance(Address)]
61
70
  Owner,
@@ -79,9 +88,8 @@ impl Ownable for DefaultOwnable {
79
88
  }
80
89
  }
81
90
 
82
- impl DefaultOwnable {
83
- /// Initializes the owner. This should only be called once at contract initialization.
84
- pub fn init_owner(env: &Env, owner: &Address) {
91
+ impl OwnableInitializer for DefaultOwnable {
92
+ fn init_owner(env: &Env, owner: &Address) {
85
93
  assert_with_error!(env, !DefaultOwnableStorage::has_owner(env), OwnableError::OwnerAlreadySet);
86
94
  DefaultOwnableStorage::set_owner(env, owner);
87
95
  }
@@ -80,12 +80,22 @@ impl<E: Event> IntoExpectedEvent for E {}
80
80
  /// ```
81
81
  pub fn assert_events(env: &Env, contract: &Address, expected_events: &[ExpectedEvent]) {
82
82
  let events = env.events().all();
83
+ // Track which emitted events have already been matched so that duplicate expectations
84
+ // require duplicate emissions (multiset semantics).
85
+ //
86
+ // Note: this module is only compiled for tests / testutils usage, where `std` is available.
87
+ extern crate std;
88
+ let mut used: std::vec::Vec<bool> = std::vec![false; events.len() as usize];
83
89
 
84
90
  for (i, expected) in expected_events.iter().enumerate() {
85
91
  let mut found = false;
86
- for (address, topics, data) in events.iter() {
92
+ for (idx, (address, topics, data)) in events.iter().enumerate() {
93
+ if used[idx] {
94
+ continue;
95
+ }
87
96
  if &address == contract && topics_eq(env, &topics, &expected.topics) && data_eq(env, &data, &expected.data)
88
97
  {
98
+ used[idx] = true;
89
99
  found = true;
90
100
  break;
91
101
  }