@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +350 -309
- package/.turbo/turbo-lint.log +146 -108
- package/.turbo/turbo-test.log +1423 -1238
- package/Cargo.lock +12 -0
- package/Cargo.toml +3 -0
- package/contracts/ERROR_SPEC.md +44 -0
- package/contracts/common-macros/src/auth.rs +113 -0
- package/contracts/common-macros/src/contract_ttl.rs +84 -0
- package/contracts/common-macros/src/lib.rs +181 -30
- package/contracts/common-macros/src/lz_contract.rs +83 -0
- package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
- package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
- package/contracts/common-macros/src/tests/mod.rs +2 -2
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
- 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
- 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
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
- package/contracts/common-macros/src/ttl_configurable.rs +19 -34
- package/contracts/common-macros/src/ttl_extendable.rs +36 -0
- package/contracts/common-macros/src/upgradeable.rs +5 -5
- package/contracts/common-macros/src/utils.rs +9 -0
- package/contracts/endpoint-v2/src/constants.rs +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +38 -40
- package/contracts/endpoint-v2/src/errors.rs +4 -3
- package/contracts/endpoint-v2/src/events.rs +1 -1
- package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
- package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
- package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
- package/contracts/endpoint-v2/src/storage.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
- package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
- package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
- package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +3 -3
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
- package/contracts/message-libs/treasury/src/errors.rs +2 -2
- package/contracts/message-libs/treasury/src/events.rs +1 -1
- package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
- package/contracts/message-libs/treasury/src/storage.rs +1 -1
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
- package/contracts/message-libs/treasury/src/treasury.rs +14 -16
- package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
- package/contracts/message-libs/uln-302/src/send_uln.rs +23 -3
- package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
- package/contracts/oapps/counter/Cargo.toml +14 -1
- package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
- package/contracts/oapps/counter/integration_tests/{setup.rs → setup_sml.rs} +48 -80
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
- package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
- package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
- package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
- package/contracts/oapps/counter/src/counter.rs +67 -43
- package/contracts/oapps/counter/src/tests/mod.rs +0 -13
- package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
- package/contracts/oapps/oapp/src/errors.rs +5 -1
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +93 -78
- package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
- package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
- package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
- package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
- package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
- package/contracts/oapps/oft/integration-tests/setup.rs +25 -7
- package/contracts/oapps/oft/src/errors.rs +6 -1
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +8 -8
- package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
- package/contracts/oapps/oft/src/lib.rs +4 -2
- package/contracts/oapps/oft/src/oft.rs +24 -64
- package/contracts/oapps/oft/src/oft_impl.rs +201 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -3
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -4
- package/contracts/oapps/oft/src/storage.rs +2 -0
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +36 -22
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +5 -3
- package/contracts/oapps/oft/src/tests/test_decimals.rs +2 -2
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +1 -2
- package/contracts/oapps/oft/src/tests/test_utils.rs +45 -23
- package/contracts/oapps/oft/src/types.rs +20 -0
- package/contracts/oapps/oft-std/integration-tests/setup.rs +4 -2
- package/contracts/oapps/oft-std/src/oft.rs +24 -6
- package/contracts/upgrader/src/lib.rs +4 -4
- package/contracts/utils/src/auth.rs +44 -0
- package/contracts/utils/src/errors.rs +27 -5
- package/contracts/utils/src/lib.rs +3 -0
- package/contracts/utils/src/multisig.rs +211 -0
- package/contracts/utils/src/ownable.rs +12 -10
- package/contracts/utils/src/tests/buffer_reader.rs +6 -6
- package/contracts/utils/src/tests/buffer_writer.rs +6 -6
- package/contracts/utils/src/tests/bytes_ext.rs +2 -4
- package/contracts/utils/src/tests/mod.rs +1 -0
- package/contracts/utils/src/tests/multisig.rs +731 -0
- package/contracts/utils/src/tests/option_ext.rs +2 -5
- package/contracts/utils/src/tests/ownable.rs +16 -5
- package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
- package/contracts/utils/src/tests/upgradeable.rs +4 -2
- package/contracts/utils/src/ttl_configurable.rs +23 -8
- package/contracts/utils/src/ttl_extendable.rs +27 -0
- package/contracts/utils/src/upgradeable.rs +2 -0
- package/contracts/workers/dvn/Cargo.toml +1 -1
- package/contracts/workers/dvn/src/auth.rs +7 -7
- package/contracts/workers/dvn/src/dvn.rs +10 -38
- package/contracts/workers/dvn/src/errors.rs +0 -7
- package/contracts/workers/dvn/src/events.rs +1 -14
- package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
- package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
- package/contracts/workers/dvn/src/storage.rs +3 -13
- package/contracts/workers/dvn/src/tests/auth.rs +4 -4
- package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
- package/contracts/workers/dvn/src/tests/setup.rs +5 -5
- package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
- package/contracts/workers/executor/src/auth.rs +80 -16
- package/contracts/workers/executor/src/executor.rs +5 -31
- package/contracts/workers/executor/src/storage.rs +2 -9
- package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +3 -6
- package/contracts/workers/executor-helper/Cargo.toml +1 -1
- package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
- package/contracts/workers/price-feed/Cargo.toml +1 -1
- package/contracts/workers/price-feed/src/price_feed.rs +7 -10
- package/contracts/workers/worker/src/errors.rs +4 -0
- package/contracts/workers/worker/src/tests/worker.rs +7 -6
- package/contracts/workers/worker/src/worker.rs +20 -16
- package/package.json +8 -5
- package/sdk/.turbo/turbo-build.log +1 -0
- package/sdk/.turbo/turbo-test.log +1009 -0
- package/sdk/dist/generated/bml.d.ts +65 -8
- package/sdk/dist/generated/bml.js +70 -34
- package/sdk/dist/generated/counter.d.ts +167 -42
- package/sdk/dist/generated/counter.js +86 -45
- package/sdk/dist/generated/dvn.d.ts +282 -229
- package/sdk/dist/generated/dvn.js +119 -81
- package/sdk/dist/generated/dvn_fee_lib.d.ts +142 -67
- package/sdk/dist/generated/dvn_fee_lib.js +64 -24
- package/sdk/dist/generated/endpoint.d.ts +97 -22
- package/sdk/dist/generated/endpoint.js +75 -37
- package/sdk/dist/generated/executor.d.ts +117 -85
- package/sdk/dist/generated/executor.js +102 -59
- package/sdk/dist/generated/executor_fee_lib.d.ts +162 -78
- package/sdk/dist/generated/executor_fee_lib.js +104 -57
- package/sdk/dist/generated/executor_helper.d.ts +133 -21
- package/sdk/dist/generated/executor_helper.js +99 -50
- package/sdk/dist/generated/oft_std.d.ts +233 -55
- package/sdk/dist/generated/oft_std.js +99 -54
- package/sdk/dist/generated/price_feed.d.ts +142 -67
- package/sdk/dist/generated/price_feed.js +64 -24
- package/sdk/dist/generated/sml.d.ts +113 -32
- package/sdk/dist/generated/sml.js +93 -49
- package/sdk/dist/generated/treasury.d.ts +896 -0
- package/sdk/dist/generated/treasury.js +219 -0
- package/sdk/dist/generated/uln302.d.ts +113 -32
- package/sdk/dist/generated/uln302.js +93 -49
- package/sdk/dist/generated/upgrader.d.ts +2 -2
- package/sdk/dist/generated/upgrader.js +1 -1
- package/sdk/dist/index.d.ts +2 -0
- package/sdk/dist/index.js +3 -0
- package/sdk/dist/wasm/blocked-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/blocked-message-lib.js +2 -0
- package/sdk/dist/wasm/counter.d.ts +1 -0
- package/sdk/dist/wasm/counter.js +2 -0
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/dvn-fee-lib.js +2 -0
- package/sdk/dist/wasm/dvn.d.ts +1 -0
- package/sdk/dist/wasm/dvn.js +2 -0
- package/sdk/dist/wasm/endpoint-v2.d.ts +1 -0
- package/sdk/dist/wasm/endpoint-v2.js +2 -0
- package/sdk/dist/wasm/executor-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/executor-fee-lib.js +2 -0
- package/sdk/dist/wasm/executor-helper.d.ts +1 -0
- package/sdk/dist/wasm/executor-helper.js +2 -0
- package/sdk/dist/wasm/executor.d.ts +1 -0
- package/sdk/dist/wasm/executor.js +2 -0
- package/sdk/dist/wasm/layerzero-views.d.ts +1 -0
- package/sdk/dist/wasm/layerzero-views.js +2 -0
- package/sdk/dist/wasm/oft-std.d.ts +1 -0
- package/sdk/dist/wasm/oft-std.js +2 -0
- package/sdk/dist/wasm/price-feed.d.ts +1 -0
- package/sdk/dist/wasm/price-feed.js +2 -0
- package/sdk/dist/wasm/simple-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/simple-message-lib.js +2 -0
- package/sdk/dist/wasm/treasury.d.ts +1 -0
- package/sdk/dist/wasm/treasury.js +2 -0
- package/sdk/dist/wasm/uln302.d.ts +1 -0
- package/sdk/dist/wasm/uln302.js +2 -0
- package/sdk/dist/wasm/upgrader.d.ts +1 -0
- package/sdk/dist/wasm/upgrader.js +2 -0
- package/sdk/dist/wasm.d.ts +15 -0
- package/sdk/dist/wasm.js +15 -0
- package/sdk/package.json +4 -2
- package/sdk/src/index.ts +4 -0
- package/sdk/test/counter-sml.test.ts +376 -0
- package/sdk/test/counter-uln.test.ts +493 -0
- package/sdk/test/{oft.test.ts → oft-sml.test.ts} +185 -310
- package/sdk/test/suites/constants.ts +22 -2
- package/sdk/test/suites/globalSetup.ts +450 -0
- package/sdk/test/suites/localnet.ts +23 -6
- package/sdk/test/upgrader.test.ts +7 -16
- package/sdk/test/utils.ts +558 -85
- package/sdk/vitest.config.ts +21 -0
- package/tools/ts-bindings-gen/src/main.rs +1 -0
- package/turbo.json +2 -0
- package/contracts/common-macros/src/contract_impl.rs +0 -52
- package/contracts/common-macros/src/ownable.rs +0 -41
- package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
- package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
- package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
- package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
- package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
- package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
- package/contracts/oapps/oapp-macros/src/util.rs +0 -107
- package/contracts/oapps/oft/src/constants.rs +0 -5
- package/contracts/oapps/oft/src/default_oft_impl.rs +0 -152
- package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
- package/contracts/workers/dvn/src/multisig.rs +0 -157
- package/sdk/test/index.test.ts +0 -375
- /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
package/Cargo.lock
CHANGED
|
@@ -332,14 +332,26 @@ version = "0.0.1"
|
|
|
332
332
|
dependencies = [
|
|
333
333
|
"assert_unordered",
|
|
334
334
|
"common-macros",
|
|
335
|
+
"dvn",
|
|
336
|
+
"dvn-fee-lib",
|
|
337
|
+
"ed25519-dalek",
|
|
335
338
|
"endpoint-v2",
|
|
336
339
|
"executor",
|
|
340
|
+
"executor-fee-lib",
|
|
341
|
+
"executor-helper",
|
|
342
|
+
"k256",
|
|
337
343
|
"message-lib-common",
|
|
338
344
|
"oapp",
|
|
339
345
|
"oapp-macros",
|
|
346
|
+
"price-feed",
|
|
347
|
+
"rand",
|
|
348
|
+
"sha3",
|
|
340
349
|
"simple-message-lib",
|
|
341
350
|
"soroban-sdk",
|
|
351
|
+
"treasury",
|
|
352
|
+
"uln302",
|
|
342
353
|
"utils",
|
|
354
|
+
"worker",
|
|
343
355
|
]
|
|
344
356
|
|
|
345
357
|
[[package]]
|
package/Cargo.toml
CHANGED
|
@@ -30,6 +30,9 @@ worker = { path = "contracts/workers/worker" }
|
|
|
30
30
|
executor = { path = "contracts/workers/executor" }
|
|
31
31
|
executor-helper = { path = "contracts/workers/executor-helper" }
|
|
32
32
|
executor-fee-lib = { path = "contracts/workers/executor-fee-lib" }
|
|
33
|
+
dvn = { path = "contracts/workers/dvn" }
|
|
34
|
+
dvn-fee-lib = { path = "contracts/workers/dvn-fee-lib" }
|
|
35
|
+
price-feed = { path = "contracts/workers/price-feed" }
|
|
33
36
|
oft = { path = "contracts/oapps/oft" }
|
|
34
37
|
stellar-macros = { git = "https://github.com/OpenZeppelin/stellar-contracts.git", tag = "v0.5.1" }
|
|
35
38
|
stellar-tokens = { git = "https://github.com/OpenZeppelin/stellar-contracts.git", tag = "v0.5.1" }
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Stellar LayerZero Protocol - Error Code Specification
|
|
2
|
+
|
|
3
|
+
This document defines the error code allocation strategy for the Stellar LayerZero contracts.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Each library has a unique error code range to:
|
|
8
|
+
|
|
9
|
+
- **Prevent collisions**: Avoid error code conflicts between different libraries
|
|
10
|
+
- **Enable traceability**: Quickly identify which library an error originated from based on its code
|
|
11
|
+
- **Simplify debugging**: Error codes are globally unique, making it easier to track and diagnose issues
|
|
12
|
+
|
|
13
|
+
## Allocation Rules
|
|
14
|
+
|
|
15
|
+
- **Library allocation**: Each library is allocated a 100-unit block (e.g., 1000-1099, 1100-1199). Total errors in one library should not exceed 100.
|
|
16
|
+
- **Sub-range allocation**: Each error type within a library is allocated a 10-unit block. Example from `utils` (1000-1099):
|
|
17
|
+
|
|
18
|
+
- BufferReaderError: 1000-1009
|
|
19
|
+
- BufferWriterError: 1010-1019
|
|
20
|
+
- TtlConfigurableError: 1020-1029
|
|
21
|
+
- OwnableError: 1030-1039
|
|
22
|
+
- BytesExtError: 1040-1049
|
|
23
|
+
- UpgradeableError: 1050-1059
|
|
24
|
+
- MultisigError: 1060-1069
|
|
25
|
+
|
|
26
|
+
If an error type exceeds 10 errors (e.g., 12 errors), it extends into the next block but the following error type should start at the next 10-unit boundary (e.g., if errors are 1000-1011, next sub-range starts at 1020).
|
|
27
|
+
|
|
28
|
+
- **Auto-increment**: Within each error enum, values auto-increment from the starting value.
|
|
29
|
+
|
|
30
|
+
## Error Code Ranges
|
|
31
|
+
|
|
32
|
+
| Range | Category | Library | Description |
|
|
33
|
+
| ----------- | --------------- | ------------------ | ------------------------------------------------------------ |
|
|
34
|
+
| 1 - 999 | Contract Errors | - | Application-specific contract errors (auto-increment from 1) |
|
|
35
|
+
| 1000 - 1099 | Protocol Lib | utils | `utils/src/errors.rs` |
|
|
36
|
+
| 1100 - 1199 | Protocol Lib | message-lib-common | `message-libs/message-lib-common/src/errors.rs` |
|
|
37
|
+
| 1200 - 1299 | Protocol Lib | worker | `workers/worker/src/errors.rs` |
|
|
38
|
+
| 1300 - 1999 | Protocol Lib | (reserved) | Future protocol libs |
|
|
39
|
+
| 2000 - 2099 | OApp Lib | oapp | `oapps/oapp/src/errors.rs` |
|
|
40
|
+
| 2100 - 2999 | OApp Lib | (reserved) | Future OApp libs |
|
|
41
|
+
| 3000 - 3099 | OFT Lib | oft | `oapps/oft/src/errors.rs` |
|
|
42
|
+
| 3100 - 3999 | OFT Lib | (reserved) | Future OFT libs |
|
|
43
|
+
|
|
44
|
+
---
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//! Authorization macros for Stellar contracts.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides macros for implementing authorization patterns:
|
|
4
|
+
//! - `#[ownable]` - Owner-based access control (external owner address)
|
|
5
|
+
//! - `#[multisig]` - Multisig-based access control (self-owning pattern)
|
|
6
|
+
//! - `#[only_auth]` - Authorization check attribute for functions
|
|
7
|
+
|
|
8
|
+
use crate::utils;
|
|
9
|
+
use proc_macro2::TokenStream;
|
|
10
|
+
use quote::{quote, ToTokens};
|
|
11
|
+
use syn::{parse_quote, ItemFn, ItemStruct};
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Ownable Macro Implementation
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
/// Generates the ownable implementation from the `#[ownable]` attribute macro.
|
|
18
|
+
///
|
|
19
|
+
/// This macro implements both `Auth` and `Ownable` traits for the contract:
|
|
20
|
+
/// - `Auth::authorizer()` returns the stored owner address
|
|
21
|
+
/// - `Ownable` provides ownership management (transfer, renounce)
|
|
22
|
+
pub fn generate_ownable_impl(input: TokenStream) -> TokenStream {
|
|
23
|
+
let item_struct: ItemStruct = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse struct: {}", e));
|
|
24
|
+
let name = &item_struct.ident;
|
|
25
|
+
let impl_mod = utils::impl_mod_ident(name, "ownable");
|
|
26
|
+
|
|
27
|
+
quote! {
|
|
28
|
+
#item_struct
|
|
29
|
+
|
|
30
|
+
use utils::{auth::Auth as _, ownable::{Ownable as _, OwnableInitializer as _}};
|
|
31
|
+
|
|
32
|
+
#[doc(hidden)]
|
|
33
|
+
mod #impl_mod {
|
|
34
|
+
use super::*;
|
|
35
|
+
use utils::{
|
|
36
|
+
auth::Auth,
|
|
37
|
+
errors::OwnableError,
|
|
38
|
+
option_ext::OptionExt as _,
|
|
39
|
+
ownable::{Ownable, OwnableInitializer},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
impl OwnableInitializer for #name {}
|
|
43
|
+
|
|
44
|
+
#[common_macros::contract_impl]
|
|
45
|
+
impl Auth for #name {
|
|
46
|
+
fn authorizer(env: &soroban_sdk::Env) -> soroban_sdk::Address {
|
|
47
|
+
<Self as Ownable>::owner(env).unwrap_or_panic(env, OwnableError::OwnerNotSet)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[common_macros::contract_impl(contracttrait)]
|
|
52
|
+
impl Ownable for #name {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Multisig Macro Implementation
|
|
59
|
+
// ============================================================================
|
|
60
|
+
|
|
61
|
+
/// Generates the multisig implementation from the `#[multisig]` attribute macro.
|
|
62
|
+
///
|
|
63
|
+
/// This macro implements both `Auth` and `Multisig` traits for the contract:
|
|
64
|
+
/// - `Auth::authorizer()` returns the contract's own address (self-owning pattern)
|
|
65
|
+
/// - `Multisig` provides signature verification and signer management
|
|
66
|
+
pub fn generate_multisig_impl(input: TokenStream) -> TokenStream {
|
|
67
|
+
let item_struct: ItemStruct = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse struct: {}", e));
|
|
68
|
+
let name = &item_struct.ident;
|
|
69
|
+
let impl_mod = utils::impl_mod_ident(name, "multisig");
|
|
70
|
+
|
|
71
|
+
quote! {
|
|
72
|
+
#item_struct
|
|
73
|
+
|
|
74
|
+
use utils::{auth::Auth as _, multisig::Multisig as _};
|
|
75
|
+
|
|
76
|
+
#[doc(hidden)]
|
|
77
|
+
mod #impl_mod {
|
|
78
|
+
use super::*;
|
|
79
|
+
use utils::{auth::Auth, multisig::Multisig};
|
|
80
|
+
|
|
81
|
+
#[common_macros::contract_impl]
|
|
82
|
+
impl Auth for #name {
|
|
83
|
+
fn authorizer(env: &soroban_sdk::Env) -> soroban_sdk::Address {
|
|
84
|
+
env.current_contract_address()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[common_macros::contract_impl(contracttrait)]
|
|
89
|
+
impl Multisig for #name {}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// Only Auth Macro Implementation
|
|
96
|
+
// ============================================================================
|
|
97
|
+
|
|
98
|
+
/// Prepends an auth check to a method using the `Auth` trait.
|
|
99
|
+
///
|
|
100
|
+
/// Works with any contract that implements the `Auth` trait, including both
|
|
101
|
+
/// `Ownable` and `Multisig` contracts.
|
|
102
|
+
pub fn prepend_only_auth_check(input: TokenStream) -> TokenStream {
|
|
103
|
+
let mut input_fn: ItemFn = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse function: {}", e));
|
|
104
|
+
|
|
105
|
+
let env_param = utils::expect_env_param(&input_fn.sig.inputs);
|
|
106
|
+
|
|
107
|
+
// Get a reference to env (handles both `Env` and `&Env` parameter types)
|
|
108
|
+
let env_ref = env_param.as_ref_tokens();
|
|
109
|
+
|
|
110
|
+
// Insert the auth check at the beginning of the function body
|
|
111
|
+
input_fn.block.stmts.insert(0, parse_quote!(utils::auth::require_auth::<Self>(#env_ref);));
|
|
112
|
+
input_fn.into_token_stream()
|
|
113
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
use crate::utils;
|
|
2
|
+
use proc_macro2::TokenStream;
|
|
3
|
+
use quote::quote;
|
|
4
|
+
use syn::{ImplItem, ItemImpl, ItemTrait, TraitItem, Visibility};
|
|
5
|
+
|
|
6
|
+
/// Generates a `#[soroban_sdk::contractimpl]` with automatic instance TTL extension.
|
|
7
|
+
pub fn contractimpl_with_ttl(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
|
+
// Inject TTL extension at the start of the method body
|
|
29
|
+
method.block.stmts.insert(0, extend_instance_ttl_stmt(&env_param));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let contract_attr = if attr.is_empty() {
|
|
33
|
+
quote! { #[soroban_sdk::contractimpl]}
|
|
34
|
+
} else {
|
|
35
|
+
quote! { #[soroban_sdk::contractimpl(#attr)] }
|
|
36
|
+
};
|
|
37
|
+
quote! {
|
|
38
|
+
#contract_attr
|
|
39
|
+
#impl_block
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Generates a `#[soroban_sdk::contracttrait]` with automatic instance TTL extension.
|
|
44
|
+
///
|
|
45
|
+
/// This macro processes trait definitions and injects TTL extension logic into
|
|
46
|
+
/// default method implementations that have an `Env` parameter.
|
|
47
|
+
pub fn contracttrait_with_ttl(attr: TokenStream, input: TokenStream) -> TokenStream {
|
|
48
|
+
let mut trait_def: ItemTrait =
|
|
49
|
+
syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse trait definition: {}", e));
|
|
50
|
+
|
|
51
|
+
for item in &mut trait_def.items {
|
|
52
|
+
let TraitItem::Fn(method) = item else { continue };
|
|
53
|
+
|
|
54
|
+
// Only process methods with default implementations (have a body)
|
|
55
|
+
let Some(ref mut block) = method.default else { continue };
|
|
56
|
+
|
|
57
|
+
// Skip methods without Env parameter
|
|
58
|
+
let Some(env_param) = utils::find_env_param(&method.sig.inputs) else { continue };
|
|
59
|
+
|
|
60
|
+
// Inject TTL extension at the start of the method body
|
|
61
|
+
block.stmts.insert(0, extend_instance_ttl_stmt(&env_param));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let trait_attr = if attr.is_empty() {
|
|
65
|
+
quote! { #[soroban_sdk::contracttrait]}
|
|
66
|
+
} else {
|
|
67
|
+
quote! { #[soroban_sdk::contracttrait(#attr)] }
|
|
68
|
+
};
|
|
69
|
+
quote! {
|
|
70
|
+
#trait_attr
|
|
71
|
+
#trait_def
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Generates a statement that extends instance TTL if configured.
|
|
76
|
+
fn extend_instance_ttl_stmt(env_param: &utils::EnvParam<'_>) -> syn::Stmt {
|
|
77
|
+
let env_ref = env_param.as_ref_tokens();
|
|
78
|
+
let env_ident = env_param.ident;
|
|
79
|
+
syn::parse_quote! {
|
|
80
|
+
if let Some(instance_ttl) = utils::ttl_configurable::TtlConfigStorage::instance(#env_ref) {
|
|
81
|
+
#env_ident.storage().instance().extend_ttl(instance_ttl.threshold, instance_ttl.extend_to);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
//! This crate provides foundational macros for Stellar contract development:
|
|
4
4
|
//! - **Storage macros** - Strongly-typed contract storage API generation
|
|
5
5
|
//! - **Error macros** - Contract error enum generation
|
|
6
|
-
//! - **
|
|
6
|
+
//! - **Auth macros** - Authorization-based access control (ownable, multisig, only_auth)
|
|
7
7
|
//! - **TTL macros** - Time-to-live configuration and automatic extension
|
|
8
|
+
//! - **Wrapper macros** - Convenient macro combinations for common patterns
|
|
8
9
|
//!
|
|
9
10
|
//! # Quick Links
|
|
10
11
|
//! - [`storage`] - Storage enum to API macro
|
|
11
12
|
//! - [`contract_error`] - Error enum generation macro
|
|
12
13
|
//! - [`ownable`] - Ownable trait implementation macro
|
|
13
|
-
//! - [`
|
|
14
|
+
//! - [`multisig`] - Multisig trait implementation macro
|
|
15
|
+
//! - [`only_auth`] - Auth-based access control attribute macro
|
|
14
16
|
//! - [`ttl_configurable`] - TTL configuration with freeze support
|
|
17
|
+
//! - [`ttl_extendable`] - Manual instance TTL extension
|
|
15
18
|
//! - [`contract_impl`] - Contract impl with automatic instance TTL extension
|
|
19
|
+
//! - [`contract_trait`] - Contract trait with automatic instance TTL extension
|
|
16
20
|
//! - [`upgradeable`] - Upgradeable trait implementation macro
|
|
21
|
+
//! - [`lz_contract`] - Wrapper macro combining common LayerZero contract attributes
|
|
17
22
|
//!
|
|
18
|
-
|
|
23
|
+
|
|
19
24
|
use proc_macro::TokenStream;
|
|
20
25
|
|
|
21
|
-
mod
|
|
26
|
+
mod auth;
|
|
27
|
+
mod contract_ttl;
|
|
22
28
|
mod error;
|
|
23
|
-
mod
|
|
29
|
+
mod lz_contract;
|
|
24
30
|
mod storage;
|
|
25
31
|
mod ttl_configurable;
|
|
32
|
+
mod ttl_extendable;
|
|
26
33
|
mod upgradeable;
|
|
27
34
|
mod utils;
|
|
28
35
|
|
|
@@ -142,46 +149,74 @@ pub fn contract_error(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
142
149
|
/// - `Ownable` trait impl - `owner(env)`, `transfer_ownership(env, new_owner)`, `renounce_ownership(env)`
|
|
143
150
|
#[proc_macro_attribute]
|
|
144
151
|
pub fn ownable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
145
|
-
|
|
152
|
+
auth::generate_ownable_impl(item.into()).into()
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
// ============================================================================
|
|
149
|
-
//
|
|
156
|
+
// Multisig Macro
|
|
150
157
|
// ============================================================================
|
|
151
158
|
|
|
152
|
-
///
|
|
159
|
+
/// Generates multisig implementation with self-owning access control.
|
|
153
160
|
///
|
|
154
|
-
///
|
|
155
|
-
///
|
|
161
|
+
/// Implements the `Multisig` trait and the `Auth` trait with self-owning pattern,
|
|
162
|
+
/// where the contract's own address is the authorizer. This allows multisig
|
|
163
|
+
/// quorum approval to serve as the authorizer for owner-protected operations
|
|
164
|
+
/// like TTL configuration and upgrades.
|
|
165
|
+
///
|
|
166
|
+
/// # Example
|
|
167
|
+
/// ```ignore
|
|
168
|
+
/// #[multisig]
|
|
169
|
+
/// pub struct MyContract;
|
|
170
|
+
/// ```
|
|
171
|
+
///
|
|
172
|
+
/// Generated code includes:
|
|
173
|
+
/// - `Auth` trait impl - `authorizer(env)` returns `env.current_contract_address()`
|
|
174
|
+
/// - `Multisig` trait impl - `set_signer(...)`, `set_threshold(...)`, `verify_signatures(...)`
|
|
175
|
+
#[proc_macro_attribute]
|
|
176
|
+
pub fn multisig(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
177
|
+
auth::generate_multisig_impl(item.into()).into()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Only Auth Macro
|
|
182
|
+
// ============================================================================
|
|
183
|
+
|
|
184
|
+
/// Restricts function access to the contract authorizer only.
|
|
185
|
+
///
|
|
186
|
+
/// This attribute macro injects an auth check at the beginning of the function
|
|
187
|
+
/// using the `Auth` trait. The function will panic if called without authorization.
|
|
188
|
+
///
|
|
189
|
+
/// Works with any contract that implements `Auth`, including both `Ownable` and
|
|
190
|
+
/// `Multisig` contracts.
|
|
156
191
|
///
|
|
157
192
|
/// # Requirements
|
|
158
193
|
/// - The function must have an `Env` parameter (by value or reference)
|
|
159
|
-
/// - The containing contract must implement the `
|
|
194
|
+
/// - The containing contract must implement the `Auth` trait
|
|
160
195
|
///
|
|
161
196
|
/// # Example
|
|
162
197
|
/// ```ignore
|
|
163
|
-
/// #[ownable]
|
|
198
|
+
/// #[ownable] // or implement Multisig
|
|
164
199
|
/// pub struct MyContract;
|
|
165
200
|
///
|
|
166
201
|
/// #[soroban_sdk::contractimpl]
|
|
167
202
|
/// impl MyContract {
|
|
168
|
-
/// #[
|
|
169
|
-
/// pub fn
|
|
170
|
-
/// // Only the
|
|
203
|
+
/// #[only_auth]
|
|
204
|
+
/// pub fn protected_action(env: Env) {
|
|
205
|
+
/// // Only the authorizer can execute this
|
|
171
206
|
/// }
|
|
172
207
|
/// }
|
|
173
208
|
/// ```
|
|
174
209
|
///
|
|
175
210
|
/// Generated code (conceptual):
|
|
176
211
|
/// ```ignore
|
|
177
|
-
/// pub fn
|
|
178
|
-
/// utils::
|
|
212
|
+
/// pub fn protected_action(env: Env) {
|
|
213
|
+
/// utils::auth::require_auth::<Self>(&env);
|
|
179
214
|
/// // Original function body
|
|
180
215
|
/// }
|
|
181
216
|
/// ```
|
|
182
217
|
#[proc_macro_attribute]
|
|
183
|
-
pub fn
|
|
184
|
-
|
|
218
|
+
pub fn only_auth(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
219
|
+
auth::prepend_only_auth_check(item.into()).into()
|
|
185
220
|
}
|
|
186
221
|
|
|
187
222
|
// ============================================================================
|
|
@@ -191,14 +226,14 @@ pub fn only_owner(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
191
226
|
/// Generates TtlConfigurable trait implementation.
|
|
192
227
|
///
|
|
193
228
|
/// This macro implements the `TtlConfigurable` trait for a contract struct,
|
|
194
|
-
/// providing TTL configuration management with
|
|
229
|
+
/// providing TTL configuration management with auth-based access control.
|
|
195
230
|
///
|
|
196
231
|
/// # Requirements
|
|
197
|
-
/// The contract must implement the `
|
|
232
|
+
/// The contract must implement the `Auth` trait (typically via `#[ownable]` or `Multisig`).
|
|
198
233
|
///
|
|
199
234
|
/// # Example
|
|
200
235
|
/// ```ignore
|
|
201
|
-
/// #[ownable]
|
|
236
|
+
/// #[ownable] // or implement Multisig for self-owning contracts
|
|
202
237
|
/// #[ttl_configurable]
|
|
203
238
|
/// pub struct MyContract;
|
|
204
239
|
///
|
|
@@ -211,15 +246,39 @@ pub fn only_owner(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
211
246
|
/// ```
|
|
212
247
|
///
|
|
213
248
|
/// Generated code includes:
|
|
214
|
-
/// - `set_ttl_configs(env, instance, persistent)` - Set TTL configs (
|
|
249
|
+
/// - `set_ttl_configs(env, instance, persistent)` - Set TTL configs (auth required)
|
|
215
250
|
/// - `ttl_configs(env)` - Get current TTL configs (instance, persistent)
|
|
216
|
-
/// - `freeze_ttl_configs(env)` - Permanently freeze TTL configs (
|
|
251
|
+
/// - `freeze_ttl_configs(env)` - Permanently freeze TTL configs (auth required)
|
|
217
252
|
/// - `is_ttl_configs_frozen(env)` - Check if TTL configs are frozen
|
|
218
253
|
#[proc_macro_attribute]
|
|
219
254
|
pub fn ttl_configurable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
220
255
|
ttl_configurable::generate_ttl_configurable_impl(item.into()).into()
|
|
221
256
|
}
|
|
222
257
|
|
|
258
|
+
// ============================================================================
|
|
259
|
+
// TTL Extendable Macro
|
|
260
|
+
// ============================================================================
|
|
261
|
+
|
|
262
|
+
/// Generates TtlExtendable trait implementation for manual instance TTL extension.
|
|
263
|
+
///
|
|
264
|
+
/// This macro implements the `TtlExtendable` trait, providing a public
|
|
265
|
+
/// `extend_instance_ttl` function that allows external callers to extend
|
|
266
|
+
/// the contract's instance storage TTL.
|
|
267
|
+
///
|
|
268
|
+
/// # Example
|
|
269
|
+
/// ```ignore
|
|
270
|
+
/// #[contract]
|
|
271
|
+
/// #[ttl_extendable]
|
|
272
|
+
/// pub struct MyContract;
|
|
273
|
+
/// ```
|
|
274
|
+
///
|
|
275
|
+
/// Generated code includes:
|
|
276
|
+
/// - `extend_instance_ttl(env, threshold, extend_to)` - Extends instance TTL
|
|
277
|
+
#[proc_macro_attribute]
|
|
278
|
+
pub fn ttl_extendable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
279
|
+
ttl_extendable::generate_ttl_extendable_impl(item.into()).into()
|
|
280
|
+
}
|
|
281
|
+
|
|
223
282
|
// ============================================================================
|
|
224
283
|
// Contract Impl Macro
|
|
225
284
|
// ============================================================================
|
|
@@ -267,24 +326,77 @@ pub fn ttl_configurable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
267
326
|
/// ```
|
|
268
327
|
#[proc_macro_attribute]
|
|
269
328
|
pub fn contract_impl(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
270
|
-
|
|
329
|
+
contract_ttl::contractimpl_with_ttl(attr.into(), item.into()).into()
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ============================================================================
|
|
333
|
+
// Contract Trait Macro
|
|
334
|
+
// ============================================================================
|
|
335
|
+
|
|
336
|
+
/// Wraps `#[soroban_sdk::contracttrait]` with automatic instance TTL extension.
|
|
337
|
+
///
|
|
338
|
+
/// This macro applies `#[soroban_sdk::contracttrait]` and injects TTL extension logic
|
|
339
|
+
/// at the beginning of each default trait method to keep the contract instance alive.
|
|
340
|
+
///
|
|
341
|
+
/// # Requirements
|
|
342
|
+
/// - The implementing contract must have `#[ttl_configurable]` applied
|
|
343
|
+
/// - Methods must have an `Env` parameter to receive TTL extension
|
|
344
|
+
/// - Only methods with default implementations are processed
|
|
345
|
+
///
|
|
346
|
+
/// # Behavior
|
|
347
|
+
/// - All default methods with an `Env` parameter receive TTL extension
|
|
348
|
+
/// - Methods without a body (abstract methods) are not modified
|
|
349
|
+
/// - Methods without an `Env` parameter are skipped
|
|
350
|
+
///
|
|
351
|
+
/// # Example
|
|
352
|
+
/// ```ignore
|
|
353
|
+
/// #[contract_trait]
|
|
354
|
+
/// pub trait MyTrait {
|
|
355
|
+
/// /// This method will have TTL extension injected
|
|
356
|
+
/// fn my_method(env: &Env) {
|
|
357
|
+
/// // TTL extension is automatically injected here
|
|
358
|
+
/// // ... your code
|
|
359
|
+
/// }
|
|
360
|
+
///
|
|
361
|
+
/// /// Abstract methods are not modified
|
|
362
|
+
/// fn abstract_method(env: &Env) -> u32;
|
|
363
|
+
/// }
|
|
364
|
+
/// ```
|
|
365
|
+
///
|
|
366
|
+
/// Generated code (conceptual):
|
|
367
|
+
/// ```ignore
|
|
368
|
+
/// #[soroban_sdk::contracttrait]
|
|
369
|
+
/// pub trait MyTrait {
|
|
370
|
+
/// fn my_method(env: &Env) {
|
|
371
|
+
/// if let Some(ttl) = utils::ttl_configurable::TtlConfigStorage::instance(env) {
|
|
372
|
+
/// env.storage().instance().extend_ttl(ttl.threshold, ttl.extend_to);
|
|
373
|
+
/// }
|
|
374
|
+
/// // ... your code
|
|
375
|
+
/// }
|
|
376
|
+
///
|
|
377
|
+
/// fn abstract_method(env: &Env) -> u32;
|
|
378
|
+
/// }
|
|
379
|
+
/// ```
|
|
380
|
+
#[proc_macro_attribute]
|
|
381
|
+
pub fn contract_trait(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
382
|
+
contract_ttl::contracttrait_with_ttl(attr.into(), item.into()).into()
|
|
271
383
|
}
|
|
272
384
|
|
|
273
385
|
// ============================================================================
|
|
274
386
|
// Upgradeable Macro
|
|
275
387
|
// ============================================================================
|
|
276
388
|
|
|
277
|
-
/// Generates upgradeable implementation with
|
|
389
|
+
/// Generates upgradeable implementation with auth-based access control.
|
|
278
390
|
///
|
|
279
391
|
/// Implements the `Upgradeable` trait for contract upgrade and migration functionality.
|
|
280
392
|
///
|
|
281
393
|
/// # Requirements
|
|
282
|
-
/// - The contract must
|
|
394
|
+
/// - The contract must implement the `Auth` trait (via `#[ownable]` or `Multisig`)
|
|
283
395
|
/// - The contract must implement `UpgradeableInternal` trait with migration logic
|
|
284
396
|
///
|
|
285
397
|
/// # Example
|
|
286
398
|
/// ```ignore
|
|
287
|
-
/// #[ownable]
|
|
399
|
+
/// #[ownable] // or implement Multisig for self-owning contracts
|
|
288
400
|
/// #[upgradeable]
|
|
289
401
|
/// pub struct MyContract;
|
|
290
402
|
///
|
|
@@ -298,10 +410,49 @@ pub fn contract_impl(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
298
410
|
/// ```
|
|
299
411
|
///
|
|
300
412
|
/// Generated code includes:
|
|
301
|
-
/// - `upgrade(env, new_wasm_hash)` - Upgrades the contract WASM (
|
|
302
|
-
/// - `migrate(env, migration_data)` - Runs migration after upgrade (
|
|
413
|
+
/// - `upgrade(env, new_wasm_hash)` - Upgrades the contract WASM (auth required)
|
|
414
|
+
/// - `migrate(env, migration_data)` - Runs migration after upgrade (auth required)
|
|
303
415
|
/// - `contractmeta!` with `binver` set to the Cargo package version (if not 0.0.0)
|
|
304
416
|
#[proc_macro_attribute]
|
|
305
417
|
pub fn upgradeable(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
306
418
|
upgradeable::generate_upgradeable_impl(item.into()).into()
|
|
307
419
|
}
|
|
420
|
+
|
|
421
|
+
// ============================================================================
|
|
422
|
+
// LZ Contract Wrapper Macro
|
|
423
|
+
// ============================================================================
|
|
424
|
+
|
|
425
|
+
/// Wrapper macro that combines common LayerZero contract attributes.
|
|
426
|
+
///
|
|
427
|
+
/// This macro simplifies contract declarations by combining multiple commonly
|
|
428
|
+
/// used macros into a single attribute.
|
|
429
|
+
///
|
|
430
|
+
/// # Default (no options)
|
|
431
|
+
/// `#[lz_contract]` generates:
|
|
432
|
+
/// - `#[contract]` - Soroban contract
|
|
433
|
+
/// - `#[ttl_configurable]` - TTL configuration with auth
|
|
434
|
+
/// - `#[ttl_extendable]` - Manual TTL extension
|
|
435
|
+
/// - `#[ownable]` - Single-owner access control
|
|
436
|
+
///
|
|
437
|
+
/// # Options
|
|
438
|
+
/// - `upgradeable` - Adds `#[upgradeable]` for contract upgrade support
|
|
439
|
+
/// - `multisig` - Uses `#[multisig]` instead of `#[ownable]`
|
|
440
|
+
///
|
|
441
|
+
/// # Examples
|
|
442
|
+
/// ```ignore
|
|
443
|
+
/// // Basic contract with ownable auth
|
|
444
|
+
/// #[lz_contract]
|
|
445
|
+
/// pub struct EndpointV2;
|
|
446
|
+
///
|
|
447
|
+
/// // Contract with upgrade support
|
|
448
|
+
/// #[lz_contract(upgradeable)]
|
|
449
|
+
/// pub struct DVNFeeLib;
|
|
450
|
+
///
|
|
451
|
+
/// // Contract with multisig auth and upgrade support
|
|
452
|
+
/// #[lz_contract(multisig, upgradeable)]
|
|
453
|
+
/// pub struct DVN;
|
|
454
|
+
/// ```
|
|
455
|
+
#[proc_macro_attribute]
|
|
456
|
+
pub fn lz_contract(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
457
|
+
lz_contract::generate_lz_contract(attr.into(), item.into()).into()
|
|
458
|
+
}
|