@layerzerolabs/protocol-stellar-v2 0.2.8
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.
- package/.turbo/turbo-build.log +727 -0
- package/.turbo/turbo-lint.log +158 -0
- package/.turbo/turbo-test.log +796 -0
- package/Cargo.lock +2237 -0
- package/Cargo.toml +63 -0
- package/clippy.toml +7 -0
- package/contracts/common-macros/Cargo.toml +20 -0
- package/contracts/common-macros/src/error.rs +53 -0
- package/contracts/common-macros/src/event.rs +16 -0
- package/contracts/common-macros/src/lib.rs +255 -0
- package/contracts/common-macros/src/ownable.rs +63 -0
- package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +310 -0
- package/contracts/common-macros/src/storage.rs +439 -0
- package/contracts/common-macros/src/tests.rs +287 -0
- package/contracts/common-macros/src/ttl_configurable.rs +60 -0
- package/contracts/endpoint-v2/ARCHITECTURE.md +233 -0
- package/contracts/endpoint-v2/Cargo.toml +30 -0
- package/contracts/endpoint-v2/src/constants.rs +52 -0
- package/contracts/endpoint-v2/src/endpoint_v2.rs +305 -0
- package/contracts/endpoint-v2/src/errors.rs +29 -0
- package/contracts/endpoint-v2/src/events.rs +207 -0
- package/contracts/endpoint-v2/src/interfaces/layerzero_composer.rs +26 -0
- package/contracts/endpoint-v2/src/interfaces/layerzero_endpoint_v2.rs +170 -0
- package/contracts/endpoint-v2/src/interfaces/layerzero_receiver.rs +43 -0
- package/contracts/endpoint-v2/src/interfaces/message_lib.rs +62 -0
- package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +220 -0
- package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +121 -0
- package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +63 -0
- package/contracts/endpoint-v2/src/interfaces/mod.rs +17 -0
- package/contracts/endpoint-v2/src/interfaces/send_lib.rs +70 -0
- package/contracts/endpoint-v2/src/lib.rs +22 -0
- package/contracts/endpoint-v2/src/message_lib_manager.rs +315 -0
- package/contracts/endpoint-v2/src/messaging_channel.rs +218 -0
- package/contracts/endpoint-v2/src/messaging_composer.rs +76 -0
- package/contracts/endpoint-v2/src/storage.rs +78 -0
- package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +131 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +237 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +42 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +76 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +211 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +18 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +10 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +10 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +424 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +144 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +72 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +29 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +513 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +43 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +27 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +30 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +202 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +59 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +172 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +23 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +10 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +131 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +35 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +28 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +79 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +246 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +285 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +180 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +405 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +80 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +131 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +358 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +316 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +288 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +316 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +388 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +307 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +10 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +239 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +324 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +242 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +232 -0
- package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +212 -0
- package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +213 -0
- package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +269 -0
- package/contracts/endpoint-v2/src/tests/messaging_composer/mod.rs +4 -0
- package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +173 -0
- package/contracts/endpoint-v2/src/tests/mock.rs +132 -0
- package/contracts/endpoint-v2/src/tests/mod.rs +12 -0
- package/contracts/endpoint-v2/src/tests/util/build_payload.rs +126 -0
- package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +82 -0
- package/contracts/endpoint-v2/src/tests/util/keccak256.rs +115 -0
- package/contracts/endpoint-v2/src/tests/util/mod.rs +3 -0
- package/contracts/endpoint-v2/src/util.rs +52 -0
- package/contracts/message-libs/Cargo.toml +12 -0
- package/contracts/message-libs/block-message-lib/Cargo.toml +19 -0
- package/contracts/message-libs/block-message-lib/src/lib.rs +70 -0
- package/contracts/message-libs/lib.rs +2 -0
- package/contracts/message-libs/message-lib-common/Cargo.toml +24 -0
- package/contracts/message-libs/message-lib-common/src/errors.rs +20 -0
- package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +55 -0
- package/contracts/message-libs/message-lib-common/src/interfaces/executor.rs +46 -0
- package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +7 -0
- package/contracts/message-libs/message-lib-common/src/interfaces/treasury.rs +17 -0
- package/contracts/message-libs/message-lib-common/src/lib.rs +14 -0
- package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +99 -0
- package/contracts/message-libs/message-lib-common/src/testing_utils.rs +27 -0
- package/contracts/message-libs/message-lib-common/src/tests/mod.rs +2 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +162 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +319 -0
- package/contracts/message-libs/message-lib-common/src/worker_options.rs +190 -0
- package/contracts/message-libs/simple-message-lib/Cargo.toml +26 -0
- package/contracts/message-libs/simple-message-lib/src/errors.rs +11 -0
- package/contracts/message-libs/simple-message-lib/src/lib.rs +14 -0
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +136 -0
- package/contracts/message-libs/simple-message-lib/src/storage.rs +27 -0
- package/contracts/message-libs/simple-message-lib/src/test.rs +280 -0
- package/contracts/message-libs/treasury/Cargo.toml +27 -0
- package/contracts/message-libs/treasury/src/errors.rs +10 -0
- package/contracts/message-libs/treasury/src/events.rs +28 -0
- package/contracts/message-libs/treasury/src/interfaces/mod.rs +3 -0
- package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +20 -0
- package/contracts/message-libs/treasury/src/lib.rs +20 -0
- package/contracts/message-libs/treasury/src/storage.rs +18 -0
- package/contracts/message-libs/treasury/src/tests/mod.rs +2 -0
- package/contracts/message-libs/treasury/src/tests/setup.rs +112 -0
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +562 -0
- package/contracts/message-libs/treasury/src/treasury.rs +140 -0
- package/contracts/message-libs/uln-302/Cargo.toml +28 -0
- package/contracts/message-libs/uln-302/src/config_validation.rs +173 -0
- package/contracts/message-libs/uln-302/src/errors.rs +29 -0
- package/contracts/message-libs/uln-302/src/events.rs +72 -0
- package/contracts/message-libs/uln-302/src/interfaces/mod.rs +5 -0
- package/contracts/message-libs/uln-302/src/interfaces/receive.rs +82 -0
- package/contracts/message-libs/uln-302/src/interfaces/send.rs +159 -0
- package/contracts/message-libs/uln-302/src/lib.rs +20 -0
- package/contracts/message-libs/uln-302/src/receive.rs +199 -0
- package/contracts/message-libs/uln-302/src/send.rs +349 -0
- package/contracts/message-libs/uln-302/src/storage.rs +47 -0
- package/contracts/message-libs/uln-302/src/tests/config/mod.rs +2 -0
- package/contracts/message-libs/uln-302/src/tests/config/oapp_uln_config.rs +291 -0
- package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +163 -0
- package/contracts/message-libs/uln-302/src/tests/mod.rs +7 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/commit_verification.rs +183 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/confirmations.rs +128 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +104 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/mod.rs +66 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +79 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/verifiable.rs +463 -0
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +173 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +132 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +117 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/mod.rs +6 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/quote.rs +586 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +834 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +95 -0
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +80 -0
- package/contracts/message-libs/uln-302/src/tests/setup.rs +268 -0
- package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +47 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +51 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +51 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/get_oapp_executor_config.rs +48 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/mod.rs +4 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +998 -0
- package/contracts/message-libs/uln-302/src/uln302.rs +117 -0
- package/contracts/oapp-macros/Cargo.toml +21 -0
- package/contracts/oapp-macros/src/lib.rs +408 -0
- package/contracts/oapp-macros/src/oapp_core.rs +49 -0
- package/contracts/oapp-macros/src/oapp_full.rs +15 -0
- package/contracts/oapp-macros/src/oapp_options_type3.rs +46 -0
- package/contracts/oapp-macros/src/oapp_receiver.rs +67 -0
- package/contracts/oapp-macros/src/oapp_sender.rs +23 -0
- package/contracts/oapp-macros/src/util.rs +103 -0
- package/contracts/oapp-macros/tests/test_macros.rs +522 -0
- package/contracts/oapps/Cargo.toml +12 -0
- package/contracts/oapps/counter/Cargo.toml +24 -0
- package/contracts/oapps/counter/integration_tests/mod.rs +3 -0
- package/contracts/oapps/counter/integration_tests/setup.rs +201 -0
- package/contracts/oapps/counter/integration_tests/test_with_sml.rs +166 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +144 -0
- package/contracts/oapps/counter/src/codec.rs +63 -0
- package/contracts/oapps/counter/src/counter.rs +235 -0
- package/contracts/oapps/counter/src/errors.rs +9 -0
- package/contracts/oapps/counter/src/lib.rs +16 -0
- package/contracts/oapps/counter/src/options.rs +30 -0
- package/contracts/oapps/counter/src/storage.rs +33 -0
- package/contracts/oapps/counter/src/tests/mod.rs +37 -0
- package/contracts/oapps/counter/src/tests/test_codec.rs +64 -0
- package/contracts/oapps/counter/src/tests/test_counter.rs +390 -0
- package/contracts/oapps/counter/src/u256_ext.rs +21 -0
- package/contracts/oapps/lib.rs +2 -0
- package/contracts/oapps/oapp/Cargo.toml +21 -0
- package/contracts/oapps/oapp/src/errors.rs +9 -0
- package/contracts/oapps/oapp/src/lib.rs +10 -0
- package/contracts/oapps/oapp/src/oapp_core.rs +92 -0
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +89 -0
- package/contracts/oapps/oapp/src/oapp_receiver.rs +72 -0
- package/contracts/oapps/oapp/src/oapp_sender.rs +66 -0
- package/contracts/oapps/oapp/src/tests/mod.rs +4 -0
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +162 -0
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +180 -0
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +157 -0
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +283 -0
- package/contracts/utils/Cargo.toml +21 -0
- package/contracts/utils/src/buffer_reader.rs +143 -0
- package/contracts/utils/src/buffer_writer.rs +117 -0
- package/contracts/utils/src/bytes_ext.rs +19 -0
- package/contracts/utils/src/errors.rs +30 -0
- package/contracts/utils/src/lib.rs +15 -0
- package/contracts/utils/src/option_ext.rs +38 -0
- package/contracts/utils/src/ownable.rs +88 -0
- package/contracts/utils/src/testing_utils.rs +100 -0
- package/contracts/utils/src/tests/buffer_reader.rs +1006 -0
- package/contracts/utils/src/tests/buffer_writer.rs +330 -0
- package/contracts/utils/src/tests/bytes_ext.rs +77 -0
- package/contracts/utils/src/tests/mod.rs +4 -0
- package/contracts/utils/src/tests/ownable.rs +149 -0
- package/contracts/utils/src/ttl.rs +164 -0
- package/contracts/workers/Cargo.toml +13 -0
- package/contracts/workers/executor/Cargo.toml +26 -0
- package/contracts/workers/executor/src/events.rs +22 -0
- package/contracts/workers/executor/src/executor.rs +347 -0
- package/contracts/workers/executor/src/interfaces/executor.rs +40 -0
- package/contracts/workers/executor/src/interfaces/mod.rs +5 -0
- package/contracts/workers/executor/src/interfaces/types.rs +51 -0
- package/contracts/workers/executor/src/lib.rs +10 -0
- package/contracts/workers/executor/src/storage.rs +23 -0
- package/contracts/workers/lib.rs +2 -0
- package/contracts/workers/worker-common/Cargo.toml +18 -0
- package/contracts/workers/worker-common/src/constants.rs +17 -0
- package/contracts/workers/worker-common/src/errors.rs +6 -0
- package/contracts/workers/worker-common/src/events.rs +34 -0
- package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +35 -0
- package/contracts/workers/worker-common/src/interfaces/mod.rs +7 -0
- package/contracts/workers/worker-common/src/interfaces/price_feed.rs +40 -0
- package/contracts/workers/worker-common/src/interfaces/worker.rs +60 -0
- package/contracts/workers/worker-common/src/lib.rs +19 -0
- package/contracts/workers/worker-common/src/storage.rs +32 -0
- package/contracts/workers/worker-common/src/worker_common.rs +166 -0
- package/package.json +25 -0
- package/rust-toolchain.toml +4 -0
- package/rustfmt.toml +17 -0
- package/sdk/.turbo/turbo-build.log +4 -0
- package/sdk/dist/generated/bml.d.ts +452 -0
- package/sdk/dist/generated/bml.js +72 -0
- package/sdk/dist/generated/counter.d.ts +824 -0
- package/sdk/dist/generated/counter.js +125 -0
- package/sdk/dist/generated/endpoint.d.ts +1676 -0
- package/sdk/dist/generated/endpoint.js +216 -0
- package/sdk/dist/generated/sml.d.ts +810 -0
- package/sdk/dist/generated/sml.js +132 -0
- package/sdk/dist/generated/uln302.d.ts +1227 -0
- package/sdk/dist/generated/uln302.js +185 -0
- package/sdk/dist/index.d.ts +5 -0
- package/sdk/dist/index.js +5 -0
- package/sdk/node_modules/.bin/tsc +21 -0
- package/sdk/node_modules/.bin/tsserver +21 -0
- package/sdk/node_modules/.bin/vitest +21 -0
- package/sdk/node_modules/.bin/zx +21 -0
- package/sdk/package.json +40 -0
- package/sdk/src/index.ts +5 -0
- package/sdk/test/index.test.ts +271 -0
- package/sdk/test/suites/constants.ts +13 -0
- package/sdk/test/suites/deploy.ts +277 -0
- package/sdk/test/suites/localnet.ts +42 -0
- package/sdk/test/suites/scan.ts +189 -0
- package/sdk/tsconfig.json +106 -0
- package/tools/ts-bindings-gen/Cargo.toml +14 -0
- package/tools/ts-bindings-gen/src/main.rs +147 -0
- package/turbo.json +12 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
resolver = "2"
|
|
3
|
+
members = [
|
|
4
|
+
"contracts/*",
|
|
5
|
+
"contracts/message-libs/*",
|
|
6
|
+
"contracts/oapps/*",
|
|
7
|
+
"contracts/workers/*",
|
|
8
|
+
"tools/*",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
[workspace.package]
|
|
12
|
+
edition = "2021"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
version = "0.0.1"
|
|
15
|
+
|
|
16
|
+
[workspace.dependencies]
|
|
17
|
+
soroban-sdk = {version = "23.3.0", features = ["hazmat-address"]}
|
|
18
|
+
cfg-if = { version = "1.0", default-features = false }
|
|
19
|
+
hex-literal = "1.0.0"
|
|
20
|
+
endpoint-v2 = { path = "contracts/endpoint-v2", default-features = false }
|
|
21
|
+
utils = { path = "contracts/utils" }
|
|
22
|
+
common-macros = { path = "contracts/common-macros" }
|
|
23
|
+
oapp-macros = { path = "contracts/oapp-macros" }
|
|
24
|
+
message-lib-common = { path = "contracts/message-libs/message-lib-common" }
|
|
25
|
+
oapp = { path = "contracts/oapps/oapp" }
|
|
26
|
+
simple-message-lib = { path = "contracts/message-libs/simple-message-lib" }
|
|
27
|
+
treasury = { path = "contracts/message-libs/treasury" }
|
|
28
|
+
worker-common = { path = "contracts/workers/worker-common" }
|
|
29
|
+
executor = { path = "contracts/workers/executor" }
|
|
30
|
+
stellar-access = "0.5.0"
|
|
31
|
+
stellar-macros = "0.5.0"
|
|
32
|
+
stellar-contract-utils = "0.5.0"
|
|
33
|
+
insta = "1.44.3"
|
|
34
|
+
|
|
35
|
+
# Fast dev builds for testing
|
|
36
|
+
[profile.dev]
|
|
37
|
+
opt-level = 0
|
|
38
|
+
incremental = true
|
|
39
|
+
codegen-units = 256
|
|
40
|
+
|
|
41
|
+
# Optimize dependencies even in dev (compile once, run many tests)
|
|
42
|
+
[profile.dev.package."*"]
|
|
43
|
+
opt-level = 2
|
|
44
|
+
|
|
45
|
+
# Test profile optimizations
|
|
46
|
+
[profile.test]
|
|
47
|
+
opt-level = 1
|
|
48
|
+
incremental = true
|
|
49
|
+
|
|
50
|
+
[profile.release]
|
|
51
|
+
opt-level = "z"
|
|
52
|
+
overflow-checks = true
|
|
53
|
+
debug = 0
|
|
54
|
+
strip = "symbols"
|
|
55
|
+
debug-assertions = false
|
|
56
|
+
panic = "abort"
|
|
57
|
+
codegen-units = 1
|
|
58
|
+
lto = true
|
|
59
|
+
|
|
60
|
+
# For more information about this profile see https://soroban.stellar.org/docs/basic-tutorials/logging#cargotoml-profile
|
|
61
|
+
[profile.release-with-logs]
|
|
62
|
+
inherits = "release"
|
|
63
|
+
debug-assertions = true
|
package/clippy.toml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Clippy configuration for Stellar protocol contracts
|
|
2
|
+
|
|
3
|
+
# Set the too_many_arguments threshold to 11.
|
|
4
|
+
# This aligns with Stellar: contract functions are limited to 10 parameters, plus 1 for 'env'.
|
|
5
|
+
# (Default is 7; raised here to prevent unnecessary clippy warnings on valid contract interfaces.)
|
|
6
|
+
too-many-arguments-threshold = 11
|
|
7
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "common-macros"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
publish = false
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
proc-macro = true
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
proc-macro2 = "1.0"
|
|
13
|
+
quote = "1.0"
|
|
14
|
+
syn = { version = "2.0", features = ["full", "extra-traits"] }
|
|
15
|
+
heck = "0.5"
|
|
16
|
+
itertools = "0.14"
|
|
17
|
+
prettyplease = "0.2.37"
|
|
18
|
+
|
|
19
|
+
[dev-dependencies]
|
|
20
|
+
insta = { workspace = true }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
use proc_macro::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{parse_macro_input, parse_quote, spanned::Spanned, ExprLit, Fields, ItemEnum, Lit, Token};
|
|
4
|
+
|
|
5
|
+
/// The default starting value for error enum discriminants when no explicit value is provided.
|
|
6
|
+
/// This ensures error codes start from 1 instead of 0.
|
|
7
|
+
const DEFAULT_OFFSET: u32 = 1;
|
|
8
|
+
|
|
9
|
+
pub fn generate_error(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
10
|
+
assert!(attr.is_empty(), "contract_error attribute is not supported");
|
|
11
|
+
|
|
12
|
+
let mut data_enum = parse_macro_input!(item as ItemEnum);
|
|
13
|
+
|
|
14
|
+
let mut current_value = DEFAULT_OFFSET;
|
|
15
|
+
for variant in &mut data_enum.variants {
|
|
16
|
+
assert!(matches!(variant.fields, Fields::Unit), "Error enum variants must be unit variants");
|
|
17
|
+
|
|
18
|
+
// Handle variant discriminant assignment
|
|
19
|
+
if let Some((_, disc)) = &variant.discriminant {
|
|
20
|
+
// Explicit discriminant - validate it's greater than previous and update counter
|
|
21
|
+
let val = parse_discriminant_value(disc);
|
|
22
|
+
assert!(
|
|
23
|
+
val >= current_value,
|
|
24
|
+
"Error enum discriminant must be greater than or equal to the previous discriminant"
|
|
25
|
+
);
|
|
26
|
+
current_value = val + 1;
|
|
27
|
+
} else {
|
|
28
|
+
// No discriminant - assign the next sequential value
|
|
29
|
+
variant.discriminant = Some((Token), parse_quote!(#current_value)));
|
|
30
|
+
current_value += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
quote! {
|
|
35
|
+
#[soroban_sdk::contracterror]
|
|
36
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
|
37
|
+
#[repr(u32)]
|
|
38
|
+
#data_enum
|
|
39
|
+
}
|
|
40
|
+
.into()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Parses a discriminant value from a variant, returning the u32 value if valid.
|
|
44
|
+
/// Panics if the discriminant is not a valid integer literal.
|
|
45
|
+
fn parse_discriminant_value(disc: &syn::Expr) -> u32 {
|
|
46
|
+
if let syn::Expr::Lit(ExprLit { lit: Lit::Int(lit_int), .. }) = disc {
|
|
47
|
+
lit_int.base10_parse().expect("Error enum discriminant must be a valid u32 integer")
|
|
48
|
+
} else {
|
|
49
|
+
panic!("Error enum discriminant must be an integer literal")
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// TODO: add test for this
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use proc_macro::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{parse_macro_input, DeriveInput};
|
|
4
|
+
|
|
5
|
+
pub fn generate_event(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
6
|
+
let input = parse_macro_input!(item as DeriveInput);
|
|
7
|
+
let struct_name = input.ident.to_string();
|
|
8
|
+
|
|
9
|
+
let expanded = quote! {
|
|
10
|
+
#[soroban_sdk::contractevent(topics = [#struct_name])]
|
|
11
|
+
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
12
|
+
#input
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
TokenStream::from(expanded)
|
|
16
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
//! Common procedural macros for Stellar smart contracts.
|
|
2
|
+
//!
|
|
3
|
+
//! This crate provides foundational macros for Stellar contract development:
|
|
4
|
+
//! - **Storage macros** - Strongly-typed contract storage API generation
|
|
5
|
+
//! - **Event macros** - Contract event generation with proper derives
|
|
6
|
+
//! - **Error macros** - Contract error enum generation
|
|
7
|
+
//! - **Ownable macros** - Owner-based access control implementation
|
|
8
|
+
//!
|
|
9
|
+
//! # Quick Links
|
|
10
|
+
//! - [`storage`] - Storage enum to API macro
|
|
11
|
+
//! - [`event`] - Event struct generation macro
|
|
12
|
+
//! - [`contract_error`] - Error enum generation macro
|
|
13
|
+
//! - [`ownable`] - Ownable trait implementation macro
|
|
14
|
+
//! - [`only_owner`] - Owner-only access control attribute macro
|
|
15
|
+
//!
|
|
16
|
+
//!
|
|
17
|
+
use proc_macro::TokenStream;
|
|
18
|
+
use quote::quote;
|
|
19
|
+
use syn::{parse_macro_input, ItemFn, ItemStruct};
|
|
20
|
+
|
|
21
|
+
mod error;
|
|
22
|
+
mod event;
|
|
23
|
+
mod ownable;
|
|
24
|
+
mod storage;
|
|
25
|
+
mod ttl_configurable;
|
|
26
|
+
|
|
27
|
+
#[cfg(test)]
|
|
28
|
+
mod tests;
|
|
29
|
+
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Storage Macro
|
|
32
|
+
// ============================================================================
|
|
33
|
+
|
|
34
|
+
/// Generates strongly-typed storage API from enum variants.
|
|
35
|
+
///
|
|
36
|
+
/// Transforms a storage enum into getter/setter/remove/set_or_remove/has/extend_ttl methods with TTL support.
|
|
37
|
+
///
|
|
38
|
+
/// # Example
|
|
39
|
+
/// ```ignore
|
|
40
|
+
/// #[storage(MyTtlProvider)]
|
|
41
|
+
/// pub enum DataKey {
|
|
42
|
+
/// #[instance(u32)]
|
|
43
|
+
/// Counter,
|
|
44
|
+
///
|
|
45
|
+
/// #[persistent(Address)]
|
|
46
|
+
/// #[default(0)]
|
|
47
|
+
/// Nonce { user: Address },
|
|
48
|
+
///
|
|
49
|
+
/// #[temporary(BytesN<32>)]
|
|
50
|
+
/// #[no_auto_ttl_extension]
|
|
51
|
+
/// TempData,
|
|
52
|
+
/// }
|
|
53
|
+
///
|
|
54
|
+
/// // Generated API:
|
|
55
|
+
/// DataKey::counter(&env) // -> Option<u32>
|
|
56
|
+
/// DataKey::set_counter(&env, &value) // set value
|
|
57
|
+
/// DataKey::has_counter(&env) // -> bool
|
|
58
|
+
/// DataKey::remove_counter(&env) // remove entry
|
|
59
|
+
/// DataKey::set_or_remove_counter(&env, &opt) // set if Some, remove if None
|
|
60
|
+
/// DataKey::extend_ttl_counter(&env, threshold, extend_to) // manual TTL extension
|
|
61
|
+
///
|
|
62
|
+
/// // With fields (keyed storage):
|
|
63
|
+
/// DataKey::nonce(&env, user) // -> u64 (has default)
|
|
64
|
+
/// DataKey::set_nonce(&env, user, &value)
|
|
65
|
+
/// DataKey::set_or_remove_nonce(&env, user, &opt) // conditionally set or remove
|
|
66
|
+
/// ```
|
|
67
|
+
///
|
|
68
|
+
/// # Storage Types (required, exactly one per variant)
|
|
69
|
+
/// - `#[instance(Type)]` - Stored with contract instance
|
|
70
|
+
/// - `#[persistent(Type)]` - Durable ledger entries
|
|
71
|
+
/// - `#[temporary(Type)]` - Short-lived entries
|
|
72
|
+
///
|
|
73
|
+
/// # Variant Attributes (optional)
|
|
74
|
+
/// - `#[default(expr)]` - Default value; changes getter return from `Option<T>` to `T`
|
|
75
|
+
/// - `#[no_auto_ttl_extension]` - Disables automatic TTL extension on access
|
|
76
|
+
/// - `#[name("custom")]` - Override the generated function name base
|
|
77
|
+
#[proc_macro_attribute]
|
|
78
|
+
pub fn storage(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
79
|
+
storage::generate_storage(attr.into(), item.into()).into()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Event Macro
|
|
84
|
+
// ============================================================================
|
|
85
|
+
|
|
86
|
+
/// Generates a contract event struct with necessary derives.
|
|
87
|
+
///
|
|
88
|
+
/// Combines `#[contractevent]` from soroban-sdk with standard derives
|
|
89
|
+
/// required for events (Clone, Debug, Eq, PartialEq).
|
|
90
|
+
///
|
|
91
|
+
/// Automatically uses the struct name as the topic.
|
|
92
|
+
///
|
|
93
|
+
/// # Example
|
|
94
|
+
/// ```ignore
|
|
95
|
+
/// #[event]
|
|
96
|
+
/// pub struct MyEvent {
|
|
97
|
+
/// pub data: u32,
|
|
98
|
+
/// }
|
|
99
|
+
/// ```
|
|
100
|
+
///
|
|
101
|
+
/// Generated code:
|
|
102
|
+
/// ```ignore
|
|
103
|
+
/// #[contractevent(topics = ["MyEvent"])]
|
|
104
|
+
/// #[derive(Clone, Debug, Eq, PartialEq)]
|
|
105
|
+
/// pub struct MyEvent {
|
|
106
|
+
/// pub data: u32,
|
|
107
|
+
/// }
|
|
108
|
+
/// ```
|
|
109
|
+
#[proc_macro_attribute]
|
|
110
|
+
pub fn event(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
111
|
+
event::generate_event(attr, item)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ============================================================================
|
|
115
|
+
// Error Macro
|
|
116
|
+
// ============================================================================
|
|
117
|
+
|
|
118
|
+
/// Generates a contract error enum with necessary derives.
|
|
119
|
+
///
|
|
120
|
+
/// Combines `#[contracterror]` from soroban-sdk with standard derives
|
|
121
|
+
/// required for errors (Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)
|
|
122
|
+
/// and `#[repr(u32)]`.
|
|
123
|
+
///
|
|
124
|
+
/// # Example
|
|
125
|
+
/// ```ignore
|
|
126
|
+
/// #[contract_error]
|
|
127
|
+
/// pub enum MyError {
|
|
128
|
+
/// MyError1 = 1,
|
|
129
|
+
/// MyError2 = 2,
|
|
130
|
+
/// }
|
|
131
|
+
/// ```
|
|
132
|
+
///
|
|
133
|
+
/// Generated code:
|
|
134
|
+
/// ```ignore
|
|
135
|
+
/// #[contracterror]
|
|
136
|
+
/// #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
|
137
|
+
/// #[repr(u32)]
|
|
138
|
+
/// pub enum MyError {
|
|
139
|
+
/// MyError1 = 1,
|
|
140
|
+
/// MyError2 = 2,
|
|
141
|
+
/// }
|
|
142
|
+
/// ```
|
|
143
|
+
#[proc_macro_attribute]
|
|
144
|
+
pub fn contract_error(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
145
|
+
error::generate_error(attr, item)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ============================================================================
|
|
149
|
+
// Ownable Macro
|
|
150
|
+
// ============================================================================
|
|
151
|
+
|
|
152
|
+
/// Generates ownable implementation with owner-based access control.
|
|
153
|
+
///
|
|
154
|
+
/// Implements the `Ownable` trait and provides owner initialization and
|
|
155
|
+
/// ownership transfer functionality.
|
|
156
|
+
///
|
|
157
|
+
/// # Example
|
|
158
|
+
/// ```ignore
|
|
159
|
+
/// #[ownable]
|
|
160
|
+
/// pub struct MyContract;
|
|
161
|
+
/// ```
|
|
162
|
+
///
|
|
163
|
+
/// Generated code includes:
|
|
164
|
+
/// - `__init_owner(env, owner)` - Internal method to initialize owner
|
|
165
|
+
/// - `owner(env)` - Get current owner
|
|
166
|
+
/// - `transfer_ownership(env, new_owner)` - Transfer ownership
|
|
167
|
+
#[proc_macro_attribute]
|
|
168
|
+
pub fn ownable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
169
|
+
let input = parse_macro_input!(item as ItemStruct);
|
|
170
|
+
|
|
171
|
+
// Generate the ownable implementation
|
|
172
|
+
let ownable_impl = ownable::generate_ownable_impl(&input.ident);
|
|
173
|
+
|
|
174
|
+
TokenStream::from(quote! {
|
|
175
|
+
#input
|
|
176
|
+
#ownable_impl
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Only Owner Macro
|
|
182
|
+
// ============================================================================
|
|
183
|
+
|
|
184
|
+
/// Restricts function access to the contract owner only.
|
|
185
|
+
///
|
|
186
|
+
/// This attribute macro injects an owner authentication check at the beginning
|
|
187
|
+
/// of the function. The function will panic if called by a non-owner address.
|
|
188
|
+
///
|
|
189
|
+
/// # Requirements
|
|
190
|
+
/// - The function must have an `Env` parameter (by value or reference)
|
|
191
|
+
/// - The containing contract must implement the `Ownable` trait (use `#[ownable]`)
|
|
192
|
+
///
|
|
193
|
+
/// # Example
|
|
194
|
+
/// ```ignore
|
|
195
|
+
/// #[ownable]
|
|
196
|
+
/// pub struct MyContract;
|
|
197
|
+
///
|
|
198
|
+
/// #[soroban_sdk::contractimpl]
|
|
199
|
+
/// impl MyContract {
|
|
200
|
+
/// #[only_owner]
|
|
201
|
+
/// pub fn admin_action(env: Env) {
|
|
202
|
+
/// // Only the owner can execute this
|
|
203
|
+
/// }
|
|
204
|
+
/// }
|
|
205
|
+
/// ```
|
|
206
|
+
///
|
|
207
|
+
/// Generated code (conceptual):
|
|
208
|
+
/// ```ignore
|
|
209
|
+
/// pub fn admin_action(env: Env) {
|
|
210
|
+
/// utils::ownable::require_owner_auth::<Self>(&env);
|
|
211
|
+
/// // Original function body
|
|
212
|
+
/// }
|
|
213
|
+
/// ```
|
|
214
|
+
#[proc_macro_attribute]
|
|
215
|
+
pub fn only_owner(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
216
|
+
let input_fn = parse_macro_input!(item as ItemFn);
|
|
217
|
+
ownable::prepend_only_owner_check(input_fn).into()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ============================================================================
|
|
221
|
+
// TTL Configuration Macro
|
|
222
|
+
// ============================================================================
|
|
223
|
+
|
|
224
|
+
/// Generates TtlConfigurable trait implementation with ownable support.
|
|
225
|
+
///
|
|
226
|
+
/// This macro automatically applies `#[ownable]` for owner management.:
|
|
227
|
+
/// - `#[ownable]` - Applies the ownable macro for owner management
|
|
228
|
+
/// - TtlConfigurable trait implementation - TTL configuration with freeze support
|
|
229
|
+
///
|
|
230
|
+
/// # Example
|
|
231
|
+
/// ```ignore
|
|
232
|
+
/// #[ttl_configurable]
|
|
233
|
+
/// pub struct MyContract;
|
|
234
|
+
///
|
|
235
|
+
/// #[contractimpl]
|
|
236
|
+
/// impl MyContract {
|
|
237
|
+
/// pub fn __constructor(env: &Env, owner: &Address) {
|
|
238
|
+
/// Self::__init_owner(env, owner);
|
|
239
|
+
/// }
|
|
240
|
+
/// }
|
|
241
|
+
/// ```
|
|
242
|
+
///
|
|
243
|
+
/// Generated code includes:
|
|
244
|
+
/// - `#[ownable]` attribute on the struct (provides owner management)
|
|
245
|
+
/// - `set_ttl_config(env, instance, persistent, temporary)` - Set TTL config (owner only)
|
|
246
|
+
/// - `ttl_config(env)` - Get current TTL configuration (instance, persistent, temporary)
|
|
247
|
+
/// - `freeze_ttl_config(env)` - Permanently freeze TTL config (owner only)
|
|
248
|
+
/// - `is_ttl_config_frozen(env)` - Check if TTL config is frozen
|
|
249
|
+
///
|
|
250
|
+
/// See [`ownable`] for the owner management methods also generated.
|
|
251
|
+
#[proc_macro_attribute]
|
|
252
|
+
pub fn ttl_configurable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
253
|
+
let input = parse_macro_input!(item as ItemStruct);
|
|
254
|
+
ttl_configurable::generate_ttl_configurable_impl(&input).into()
|
|
255
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
use proc_macro2::{Ident, TokenStream};
|
|
2
|
+
use quote::{quote, ToTokens};
|
|
3
|
+
use syn::{parse_quote, FnArg, ItemFn, Pat, Type, TypePath};
|
|
4
|
+
|
|
5
|
+
pub fn generate_ownable_impl(name: &Ident) -> TokenStream {
|
|
6
|
+
quote! {
|
|
7
|
+
use utils::ownable::Ownable as _;
|
|
8
|
+
|
|
9
|
+
impl #name {
|
|
10
|
+
/// Initialize the contract owner. Should be called during contract initialization.
|
|
11
|
+
pub(crate) fn __init_owner(env: &soroban_sdk::Env, owner: &soroban_sdk::Address) {
|
|
12
|
+
utils::ownable::DefaultOwnable::init_owner(env, owner);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// Implement the Ownable trait for the contract.
|
|
17
|
+
#[soroban_sdk::contractimpl]
|
|
18
|
+
impl utils::ownable::Ownable for #name {
|
|
19
|
+
fn owner(env: &soroban_sdk::Env) -> Option<soroban_sdk::Address> {
|
|
20
|
+
utils::ownable::DefaultOwnable::owner(env)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn transfer_ownership(env: &soroban_sdk::Env, new_owner: &soroban_sdk::Address) {
|
|
24
|
+
utils::ownable::DefaultOwnable::transfer_ownership(env, new_owner)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fn renounce_ownership(env: &soroban_sdk::Env) {
|
|
28
|
+
utils::ownable::DefaultOwnable::renounce_ownership(env)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Prepends an owner authentication check to a method.
|
|
35
|
+
pub fn prepend_only_owner_check(mut input_fn: ItemFn) -> TokenStream {
|
|
36
|
+
// Find the Env argument in the function signature
|
|
37
|
+
let env_ident = input_fn
|
|
38
|
+
.sig
|
|
39
|
+
.inputs
|
|
40
|
+
.iter()
|
|
41
|
+
.find_map(|arg| {
|
|
42
|
+
let FnArg::Typed(pat_type) = arg else { return None };
|
|
43
|
+
if !is_env_type(&pat_type.ty) {
|
|
44
|
+
return None;
|
|
45
|
+
}
|
|
46
|
+
let Pat::Ident(pat) = pat_type.pat.as_ref() else { return None };
|
|
47
|
+
Some(&pat.ident)
|
|
48
|
+
})
|
|
49
|
+
.expect("function must have an Env argument");
|
|
50
|
+
|
|
51
|
+
// Insert the owner authentication check at the beginning of the function body
|
|
52
|
+
input_fn.block.stmts.insert(0, parse_quote!(utils::ownable::require_owner_auth::<Self>(#env_ident);));
|
|
53
|
+
input_fn.into_token_stream()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Checks if a type is an `Env` type.
|
|
57
|
+
fn is_env_type(ty: &Type) -> bool {
|
|
58
|
+
match ty {
|
|
59
|
+
Type::Path(TypePath { path, .. }) => path.segments.last().is_some_and(|seg| seg.ident == "Env"),
|
|
60
|
+
Type::Reference(r) => is_env_type(&r.elem),
|
|
61
|
+
_ => false,
|
|
62
|
+
}
|
|
63
|
+
}
|