@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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//! Code generators for OApp trait implementations.
|
|
2
|
+
|
|
3
|
+
use crate::CustomImpls;
|
|
4
|
+
use heck::ToSnakeCase;
|
|
5
|
+
use proc_macro2::TokenStream;
|
|
6
|
+
use quote::quote;
|
|
7
|
+
use syn::{Ident, ItemStruct};
|
|
8
|
+
|
|
9
|
+
/// Generates a complete OApp implementation with contract attributes and trait implementations.
|
|
10
|
+
///
|
|
11
|
+
/// This function creates:
|
|
12
|
+
/// - `#[common_macros::lz_contract]` - Wrapper macro that combines:
|
|
13
|
+
/// - `#[soroban_sdk::contract]` - Makes the struct a Soroban contract
|
|
14
|
+
/// - `#[common_macros::ttl_configurable]` - Adds TTL configuration with auth
|
|
15
|
+
/// - `#[common_macros::ttl_extendable]` - Adds manual TTL extension support
|
|
16
|
+
/// - `#[common_macros::ownable]` - Adds single-owner access control
|
|
17
|
+
/// - OAppCore, OAppSenderInternal, OAppReceiver, and OAppOptionsType3 trait implementations
|
|
18
|
+
///
|
|
19
|
+
/// The `custom` parameter controls which trait implementations are generated vs.
|
|
20
|
+
/// expected to be provided by the user.
|
|
21
|
+
pub fn generate_oapp(item: ItemStruct, custom: CustomImpls) -> TokenStream {
|
|
22
|
+
let core_impl = generate_oapp_core(&item.ident, custom.core);
|
|
23
|
+
let sender_impl = generate_oapp_sender(&item.ident, custom.sender);
|
|
24
|
+
let receiver_impl = generate_oapp_receiver(&item.ident, custom.receiver);
|
|
25
|
+
let options_type3_impl = generate_oapp_options_type3(&item.ident, custom.options_type3);
|
|
26
|
+
quote! {
|
|
27
|
+
#[common_macros::lz_contract]
|
|
28
|
+
#item
|
|
29
|
+
|
|
30
|
+
#core_impl
|
|
31
|
+
#sender_impl
|
|
32
|
+
#receiver_impl
|
|
33
|
+
#options_type3_impl
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Generates the `OAppCore` trait implementation.
|
|
38
|
+
///
|
|
39
|
+
/// When `custom` is false, generates an empty `impl OAppCore` that uses the trait's
|
|
40
|
+
/// default implementations for peer management and endpoint access.
|
|
41
|
+
fn generate_oapp_core(name: &Ident, custom: bool) -> TokenStream {
|
|
42
|
+
if custom {
|
|
43
|
+
return TokenStream::new();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let impl_mod = impl_mod_ident(name, "core");
|
|
47
|
+
|
|
48
|
+
quote! {
|
|
49
|
+
#[doc(hidden)]
|
|
50
|
+
mod #impl_mod {
|
|
51
|
+
use super::*;
|
|
52
|
+
use oapp::oapp_core::OAppCore;
|
|
53
|
+
|
|
54
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
55
|
+
impl OAppCore for #name {}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Generates the `OAppSenderInternal` trait implementation.
|
|
61
|
+
///
|
|
62
|
+
/// When `custom` is false, generates an empty `impl OAppSenderInternal` that uses the
|
|
63
|
+
/// trait's default implementations for `__lz_quote` and `__lz_send`.
|
|
64
|
+
fn generate_oapp_sender(name: &Ident, custom: bool) -> TokenStream {
|
|
65
|
+
if custom {
|
|
66
|
+
TokenStream::new()
|
|
67
|
+
} else {
|
|
68
|
+
quote! {
|
|
69
|
+
use oapp::oapp_sender::OAppSenderInternal as _;
|
|
70
|
+
|
|
71
|
+
impl oapp::oapp_sender::OAppSenderInternal for #name {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Generates the `OAppReceiver` trait implementation.
|
|
77
|
+
///
|
|
78
|
+
/// When `custom` is false, generates an empty `impl OAppReceiver` that uses the trait's default
|
|
79
|
+
/// `lz_receive` implementation (which calls `clear_payload_and_transfer` then `__lz_receive`).
|
|
80
|
+
///
|
|
81
|
+
/// Users must implement `LzReceiveInternal` themselves to provide the `__lz_receive` method.
|
|
82
|
+
fn generate_oapp_receiver(name: &Ident, custom: bool) -> TokenStream {
|
|
83
|
+
if custom {
|
|
84
|
+
return TokenStream::new();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let impl_mod = impl_mod_ident(name, "receiver");
|
|
88
|
+
|
|
89
|
+
quote! {
|
|
90
|
+
#[doc(hidden)]
|
|
91
|
+
mod #impl_mod {
|
|
92
|
+
use super::*;
|
|
93
|
+
use oapp::oapp_receiver::OAppReceiver;
|
|
94
|
+
|
|
95
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
96
|
+
impl OAppReceiver for #name {}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Generates the `OAppOptionsType3` trait implementation.
|
|
102
|
+
///
|
|
103
|
+
/// When `custom` is false, generates an empty `impl OAppOptionsType3` that uses the
|
|
104
|
+
/// trait's default implementations for enforced options management.
|
|
105
|
+
fn generate_oapp_options_type3(name: &Ident, custom: bool) -> TokenStream {
|
|
106
|
+
if custom {
|
|
107
|
+
return TokenStream::new();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let impl_mod = impl_mod_ident(name, "options_type3");
|
|
111
|
+
|
|
112
|
+
quote! {
|
|
113
|
+
#[doc(hidden)]
|
|
114
|
+
mod #impl_mod {
|
|
115
|
+
use super::*;
|
|
116
|
+
use soroban_sdk::Vec;
|
|
117
|
+
use oapp::oapp_options_type3::{EnforcedOptionParam, OAppOptionsType3};
|
|
118
|
+
|
|
119
|
+
#[soroban_sdk::contractimpl(contracttrait)]
|
|
120
|
+
impl OAppOptionsType3 for #name {}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// Creates a unique hidden module identifier for trait implementations.
|
|
126
|
+
fn impl_mod_ident(struct_name: &Ident, trait_name: &str) -> Ident {
|
|
127
|
+
Ident::new(&format!("__oapp_{}_impl_{}", trait_name, struct_name.to_string().to_snake_case()), struct_name.span())
|
|
128
|
+
}
|
|
@@ -8,53 +8,51 @@
|
|
|
8
8
|
//! The OApp framework provides full bidirectional cross-chain communication:
|
|
9
9
|
//!
|
|
10
10
|
//! - **OAppCore**: Foundation for all OApp functionality (peer management, endpoint access)
|
|
11
|
-
//! - **
|
|
12
|
-
//! - **
|
|
11
|
+
//! - **OAppSenderInternal**: Enables sending cross-chain messages through LayerZero
|
|
12
|
+
//! - **LzReceiveInternal**: Internal trait for message handling logic
|
|
13
|
+
//! - **OAppReceiver**: Handles incoming cross-chain messages (has default `lz_receive` impl)
|
|
13
14
|
//! - **OAppOptionsType3**: Manages enforced options for message execution parameters
|
|
14
15
|
//!
|
|
15
|
-
//! ##
|
|
16
|
+
//! ## Usage
|
|
16
17
|
//!
|
|
17
18
|
//! ### `#[oapp]`
|
|
18
19
|
//! The main macro that provides Core + Sender + Receiver + OptionsType3 functionality.
|
|
19
20
|
//! This is the only macro you need for cross-chain communication.
|
|
20
21
|
//!
|
|
21
|
-
//! ###
|
|
22
|
-
//! A marker attribute to indicate which trait implementations should be manually provided
|
|
23
|
-
//! by the user instead of using default implementations.
|
|
22
|
+
//! ### Custom Implementations
|
|
24
23
|
//!
|
|
25
|
-
//!
|
|
26
|
-
//!
|
|
27
|
-
//! By default, `#[oapp]` generates default trait implementations. Use `#[oapp_manual_impl(...)]`
|
|
28
|
-
//! to customize specific behaviors:
|
|
24
|
+
//! By default, `#[oapp]` generates default trait implementations. Use `#[oapp(custom = [...])]`
|
|
25
|
+
//! to provide your own custom implementations for specific traits:
|
|
29
26
|
//!
|
|
30
27
|
//! Supported options:
|
|
31
|
-
//! - `core` -
|
|
32
|
-
//! - `sender` -
|
|
33
|
-
//! - `receiver` -
|
|
34
|
-
//! - `options_type3` -
|
|
28
|
+
//! - `core` - Custom implement `OAppCore`
|
|
29
|
+
//! - `sender` - Custom implement `OAppSenderInternal`
|
|
30
|
+
//! - `receiver` - Custom implement `OAppReceiver` (useful for custom `next_nonce`, etc.)
|
|
31
|
+
//! - `options_type3` - Custom implement `OAppOptionsType3`
|
|
35
32
|
//!
|
|
36
33
|
//! ## Examples
|
|
37
34
|
//!
|
|
38
35
|
//! ### Full OApp with Default Implementations
|
|
39
36
|
//!
|
|
40
37
|
//! ```ignore
|
|
38
|
+
//! use oapp::oapp_receiver::LzReceiveInternal;
|
|
41
39
|
//! use oapp_macros::oapp;
|
|
42
40
|
//!
|
|
43
41
|
//! #[oapp]
|
|
44
42
|
//! struct MyOApp;
|
|
45
43
|
//!
|
|
46
|
-
//! //
|
|
47
|
-
//! impl MyOApp {
|
|
44
|
+
//! // Implement LzReceiveInternal to handle incoming messages
|
|
45
|
+
//! impl LzReceiveInternal for MyOApp {
|
|
48
46
|
//! fn __lz_receive(
|
|
49
47
|
//! env: &Env,
|
|
50
|
-
//! executor: &Address,
|
|
51
48
|
//! origin: &Origin,
|
|
52
49
|
//! guid: &BytesN<32>,
|
|
53
50
|
//! message: &Bytes,
|
|
54
51
|
//! extra_data: &Bytes,
|
|
52
|
+
//! executor: &Address,
|
|
55
53
|
//! value: i128,
|
|
56
54
|
//! ) {
|
|
57
|
-
//! // Your message handling logic (
|
|
55
|
+
//! // Your message handling logic (clear_payload_and_transfer already called)
|
|
58
56
|
//! }
|
|
59
57
|
//! }
|
|
60
58
|
//! ```
|
|
@@ -62,8 +60,9 @@
|
|
|
62
60
|
//! ### OApp with Custom Core Version
|
|
63
61
|
//!
|
|
64
62
|
//! ```ignore
|
|
65
|
-
//!
|
|
66
|
-
//!
|
|
63
|
+
//! use oapp::oapp_receiver::LzReceiveInternal;
|
|
64
|
+
//!
|
|
65
|
+
//! #[oapp(custom = [core])]
|
|
67
66
|
//! struct MyOApp;
|
|
68
67
|
//!
|
|
69
68
|
//! #[contractimpl(contracttrait)]
|
|
@@ -74,7 +73,7 @@
|
|
|
74
73
|
//! }
|
|
75
74
|
//! }
|
|
76
75
|
//!
|
|
77
|
-
//! impl MyOApp {
|
|
76
|
+
//! impl LzReceiveInternal for MyOApp {
|
|
78
77
|
//! fn __lz_receive(...) { /* ... */ }
|
|
79
78
|
//! }
|
|
80
79
|
//! ```
|
|
@@ -82,73 +81,131 @@
|
|
|
82
81
|
//! ### OApp with Custom Receiver (e.g., ordered delivery)
|
|
83
82
|
//!
|
|
84
83
|
//! ```ignore
|
|
85
|
-
//! use oapp::oapp_receiver::{
|
|
84
|
+
//! use oapp::oapp_receiver::{LzReceiveInternal, OAppReceiver};
|
|
86
85
|
//!
|
|
87
|
-
//! #[oapp]
|
|
88
|
-
//! #[oapp_manual_impl(receiver)]
|
|
86
|
+
//! #[oapp(custom = [receiver])]
|
|
89
87
|
//! struct MyOrderedOApp;
|
|
90
88
|
//!
|
|
89
|
+
//! impl LzReceiveInternal for MyOrderedOApp {
|
|
90
|
+
//! fn __lz_receive(env: &Env, origin: &Origin, guid: &BytesN<32>, ...) {
|
|
91
|
+
//! // Your message handling logic
|
|
92
|
+
//! }
|
|
93
|
+
//! }
|
|
94
|
+
//!
|
|
91
95
|
//! #[contractimpl(contracttrait)]
|
|
92
96
|
//! impl OAppReceiver for MyOrderedOApp {
|
|
93
97
|
//! fn next_nonce(env: &Env, src_eid: u32, sender: &BytesN<32>) -> u64 {
|
|
94
98
|
//! // Custom nonce logic for ordered delivery
|
|
95
99
|
//! Storage::max_received_nonce(env, src_eid, sender) + 1
|
|
96
100
|
//! }
|
|
97
|
-
//!
|
|
98
|
-
//! verify_and_clear_payload::<Self>(env, executor, origin, guid, message, value);
|
|
99
|
-
//! // Your message handling logic
|
|
100
|
-
//! }
|
|
101
|
+
//! // lz_receive uses default impl which calls clear_payload_and_transfer then __lz_receive
|
|
101
102
|
//! }
|
|
102
103
|
//! ```
|
|
103
104
|
//!
|
|
104
|
-
//! ### OApp with Multiple
|
|
105
|
+
//! ### OApp with Multiple Custom Implementations
|
|
105
106
|
//!
|
|
106
107
|
//! ```ignore
|
|
107
|
-
//!
|
|
108
|
-
//!
|
|
108
|
+
//! use oapp::oapp_receiver::LzReceiveInternal;
|
|
109
|
+
//!
|
|
110
|
+
//! #[oapp(custom = [core, sender, options_type3])]
|
|
109
111
|
//! struct MyCustomOApp;
|
|
110
112
|
//!
|
|
111
113
|
//! #[contractimpl(contracttrait)]
|
|
112
114
|
//! #[common_macros::ownable]
|
|
113
115
|
//! impl OAppCore for MyCustomOApp { /* ... */ }
|
|
114
|
-
//! impl
|
|
116
|
+
//! impl OAppSenderInternal for MyCustomOApp { /* ... */ }
|
|
115
117
|
//! #[contractimpl(contracttrait)]
|
|
116
118
|
//! impl OAppOptionsType3 for MyCustomOApp { /* ... */ }
|
|
117
119
|
//!
|
|
118
|
-
//! impl MyCustomOApp {
|
|
120
|
+
//! impl LzReceiveInternal for MyCustomOApp {
|
|
119
121
|
//! fn __lz_receive(...) { /* ... */ }
|
|
120
122
|
//! }
|
|
121
123
|
//! ```
|
|
122
124
|
|
|
123
|
-
|
|
124
|
-
use proc_macro::TokenStream;
|
|
125
|
+
mod generators;
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
use proc_macro::TokenStream;
|
|
128
|
+
use syn::{
|
|
129
|
+
bracketed,
|
|
130
|
+
parse::{Parse, ParseStream},
|
|
131
|
+
punctuated::Punctuated,
|
|
132
|
+
Error, Ident, ItemStruct, Token,
|
|
133
|
+
};
|
|
132
134
|
|
|
133
135
|
/// Derives a complete OApp: `#[contract]` + `#[ownable]` + Core + Sender + Receiver + OptionsType3.
|
|
134
136
|
///
|
|
135
|
-
///
|
|
137
|
+
/// ## Usage
|
|
138
|
+
///
|
|
139
|
+
/// ```ignore
|
|
140
|
+
/// // Default: generates all trait implementations
|
|
141
|
+
/// #[oapp]
|
|
142
|
+
/// struct MyOApp;
|
|
143
|
+
///
|
|
144
|
+
/// // Provide custom implementations for specific traits
|
|
145
|
+
/// #[oapp(custom = [core, receiver])]
|
|
146
|
+
/// struct MyCustomOApp;
|
|
147
|
+
/// ```
|
|
148
|
+
///
|
|
149
|
+
/// ## Custom Options
|
|
150
|
+
/// - `core` - Manually implement `OAppCore`
|
|
151
|
+
/// - `sender` - Manually implement `OAppSenderInternal`
|
|
152
|
+
/// - `receiver` - Manually implement `OAppReceiver`
|
|
153
|
+
/// - `options_type3` - Manually implement `OAppOptionsType3`
|
|
154
|
+
///
|
|
155
|
+
/// You must implement `LzReceiveInternal` for your struct. See module docs for examples.
|
|
136
156
|
#[proc_macro_attribute]
|
|
137
|
-
pub fn oapp(
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
oapp_full::generate_impl(&name, item, disable_config).into()
|
|
157
|
+
pub fn oapp(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
158
|
+
let custom = syn::parse_macro_input!(attr as CustomImpls);
|
|
159
|
+
let item_struct = syn::parse_macro_input!(item as ItemStruct);
|
|
160
|
+
generators::generate_oapp(item_struct, custom).into()
|
|
143
161
|
}
|
|
144
162
|
|
|
145
|
-
///
|
|
146
|
-
///
|
|
147
|
-
/// Supported options: `core`, `sender`, `receiver`, `options_type3`
|
|
163
|
+
/// Specifies which OApp trait implementations the user will provide themselves.
|
|
148
164
|
///
|
|
149
|
-
///
|
|
150
|
-
///
|
|
151
|
-
#[
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
/// Parsed from `#[oapp(custom = [...])]`. When a field is `true`, the macro skips
|
|
166
|
+
/// generating that trait implementation, allowing the user to provide their own.
|
|
167
|
+
#[derive(Debug, Clone, Copy, Default)]
|
|
168
|
+
struct CustomImpls {
|
|
169
|
+
pub core: bool,
|
|
170
|
+
pub sender: bool,
|
|
171
|
+
pub receiver: bool,
|
|
172
|
+
pub options_type3: bool,
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
impl Parse for CustomImpls {
|
|
176
|
+
fn parse(input: ParseStream) -> syn::Result<Self> {
|
|
177
|
+
if input.is_empty() {
|
|
178
|
+
return Ok(Self::default());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let key: Ident = input.parse()?;
|
|
182
|
+
if key != "custom" {
|
|
183
|
+
return Err(Error::new(key.span(), "expected `custom`"));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
input.parse::<Token![=]>()?;
|
|
187
|
+
|
|
188
|
+
let content;
|
|
189
|
+
bracketed!(content in input);
|
|
190
|
+
|
|
191
|
+
let idents = Punctuated::<Ident, Token![,]>::parse_terminated(&content)?;
|
|
192
|
+
let mut custom_impls = Self::default();
|
|
193
|
+
|
|
194
|
+
for ident in idents {
|
|
195
|
+
match ident.to_string().as_str() {
|
|
196
|
+
"core" => custom_impls.core = true,
|
|
197
|
+
"sender" => custom_impls.sender = true,
|
|
198
|
+
"receiver" => custom_impls.receiver = true,
|
|
199
|
+
"options_type3" => custom_impls.options_type3 = true,
|
|
200
|
+
_ => {
|
|
201
|
+
return Err(Error::new(
|
|
202
|
+
ident.span(),
|
|
203
|
+
"expected one of `core`, `sender`, `receiver`, `options_type3`",
|
|
204
|
+
));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Ok(custom_impls)
|
|
210
|
+
}
|
|
154
211
|
}
|
|
@@ -7,14 +7,18 @@ extern crate std;
|
|
|
7
7
|
|
|
8
8
|
use crate::integration_tests::utils::{address_to_peer_bytes32, peer_bytes32_to_address};
|
|
9
9
|
use common_macros::contract_impl;
|
|
10
|
-
use endpoint_v2::{EndpointV2, EndpointV2Client, ILayerZeroComposer};
|
|
11
|
-
use
|
|
12
|
-
use oft::
|
|
13
|
-
|
|
10
|
+
use endpoint_v2::{EndpointV2, EndpointV2Client, ILayerZeroComposer, Origin};
|
|
11
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
12
|
+
use oft::{
|
|
13
|
+
initialize_oft,
|
|
14
|
+
oft::{OFTClient, OFTInternal, OFT},
|
|
15
|
+
oft_impl,
|
|
16
|
+
storage::OFTStorage,
|
|
17
|
+
types::OFTReceipt,
|
|
18
|
+
};
|
|
14
19
|
use simple_message_lib::{SimpleMessageLib, SimpleMessageLibClient};
|
|
15
|
-
use soroban_sdk::contractimpl;
|
|
16
20
|
use soroban_sdk::{
|
|
17
|
-
contract, contracttype, log, symbol_short,
|
|
21
|
+
contract, contractimpl, contracttype, log, symbol_short,
|
|
18
22
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
19
23
|
token::{StellarAssetClient, TokenClient},
|
|
20
24
|
Address, Bytes, BytesN, Env, IntoVal,
|
|
@@ -27,6 +31,20 @@ use soroban_sdk::{
|
|
|
27
31
|
#[oapp_macros::oapp]
|
|
28
32
|
pub struct TestOFT;
|
|
29
33
|
|
|
34
|
+
impl LzReceiveInternal for TestOFT {
|
|
35
|
+
fn __lz_receive(
|
|
36
|
+
env: &Env,
|
|
37
|
+
origin: &Origin,
|
|
38
|
+
guid: &BytesN<32>,
|
|
39
|
+
message: &Bytes,
|
|
40
|
+
extra_data: &Bytes,
|
|
41
|
+
executor: &Address,
|
|
42
|
+
value: i128,
|
|
43
|
+
) {
|
|
44
|
+
oft_impl::lz_receive::<Self>(env, executor, origin, guid, message, extra_data, value)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
30
48
|
#[contract_impl]
|
|
31
49
|
impl TestOFT {
|
|
32
50
|
pub fn __constructor(
|
|
@@ -37,7 +55,7 @@ impl TestOFT {
|
|
|
37
55
|
delegate: &Option<Address>,
|
|
38
56
|
shared_decimals: u32,
|
|
39
57
|
) {
|
|
40
|
-
|
|
58
|
+
initialize_oft::<Self>(env, owner, token, endpoint, delegate, shared_decimals)
|
|
41
59
|
}
|
|
42
60
|
}
|
|
43
61
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
use common_macros::contract_error;
|
|
2
2
|
|
|
3
|
+
// OFT library error codes: 3000-3099
|
|
4
|
+
// See ERROR_SPEC.md for allocation rules
|
|
5
|
+
|
|
6
|
+
/// OFTError: 3000-3099
|
|
3
7
|
#[contract_error]
|
|
4
8
|
pub enum OFTError {
|
|
5
|
-
InvalidLocalDecimals =
|
|
9
|
+
InvalidLocalDecimals = 3000,
|
|
10
|
+
NotInitialized,
|
|
6
11
|
Overflow,
|
|
7
12
|
SlippageExceeded,
|
|
8
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
use common_macros::{contract_error,
|
|
2
|
-
use soroban_sdk::{assert_with_error, contractevent,
|
|
1
|
+
use common_macros::{contract_error, contract_trait, only_auth, storage};
|
|
2
|
+
use soroban_sdk::{assert_with_error, contractevent, token::TokenClient, Address, Env};
|
|
3
3
|
use utils::{option_ext::OptionExt, ownable::Ownable};
|
|
4
4
|
|
|
5
5
|
/// Base fee in basis points (10,000 BPS = 100%)
|
|
@@ -52,9 +52,9 @@ pub struct FeeDepositAddressSet {
|
|
|
52
52
|
pub fee_deposit_address: Address,
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
#[
|
|
55
|
+
#[contract_trait]
|
|
56
56
|
pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
|
|
57
|
-
#[
|
|
57
|
+
#[only_auth]
|
|
58
58
|
fn set_default_fee_bps(env: &Env, default_fee_bps: u64) {
|
|
59
59
|
assert_with_error!(env, default_fee_bps <= BASE_FEE_BPS, OFTFeeError::InvalidFeeBps);
|
|
60
60
|
let current_default = OFTFeeStorage::default_fee_bps(env);
|
|
@@ -63,7 +63,7 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
|
|
|
63
63
|
DefaultFeeBpsSet { fee_bps: default_fee_bps }.publish(env);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
#[
|
|
66
|
+
#[only_auth]
|
|
67
67
|
fn set_fee_bps(env: &Env, dst_eid: u32, fee_bps: u64) {
|
|
68
68
|
assert_with_error!(env, fee_bps <= BASE_FEE_BPS, OFTFeeError::InvalidFeeBps);
|
|
69
69
|
if OFTFeeStorage::has_fee_bps(env, dst_eid) {
|
|
@@ -74,14 +74,14 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
|
|
|
74
74
|
FeeBpsSet { dst_eid, fee_bps }.publish(env);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
#[
|
|
77
|
+
#[only_auth]
|
|
78
78
|
fn unset_fee_bps(env: &Env, dst_eid: u32) {
|
|
79
79
|
assert_with_error!(env, OFTFeeStorage::has_fee_bps(env, dst_eid), OFTFeeError::NotFound);
|
|
80
80
|
OFTFeeStorage::remove_fee_bps(env, dst_eid);
|
|
81
81
|
FeeBpsUnset { dst_eid }.publish(env);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
#[
|
|
84
|
+
#[only_auth]
|
|
85
85
|
fn set_fee_deposit_address(env: &Env, fee_deposit_address: Address) {
|
|
86
86
|
if let Some(current_address) = OFTFeeStorage::fee_deposit_address(env) {
|
|
87
87
|
assert_with_error!(env, current_address != fee_deposit_address, OFTFeeError::SameValue);
|
|
@@ -155,7 +155,7 @@ pub trait OFTFeeInternal {
|
|
|
155
155
|
/// * `sender` - The sender address to transfer fee from
|
|
156
156
|
/// * `fee_amount` - The fee amount to transfer
|
|
157
157
|
fn __charge_fee(env: &Env, token: &Address, sender: &Address, fee_amount: i128) {
|
|
158
|
-
if fee_amount
|
|
158
|
+
if fee_amount != 0 {
|
|
159
159
|
assert_with_error!(
|
|
160
160
|
env,
|
|
161
161
|
OFTFeeStorage::fee_deposit_address(env).is_some(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
use common_macros::{contract_error,
|
|
2
|
-
use soroban_sdk::{assert_with_error, contractevent,
|
|
1
|
+
use common_macros::{contract_error, contract_trait, only_auth, storage};
|
|
2
|
+
use soroban_sdk::{assert_with_error, contractevent, Env};
|
|
3
3
|
use utils::ownable::Ownable;
|
|
4
4
|
|
|
5
5
|
#[storage]
|
|
@@ -21,9 +21,9 @@ pub struct PausedSet {
|
|
|
21
21
|
pub paused: bool,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
#[
|
|
24
|
+
#[contract_trait]
|
|
25
25
|
pub trait OFTPausable: OFTPausableInternal + Ownable + Sized {
|
|
26
|
-
#[
|
|
26
|
+
#[only_auth]
|
|
27
27
|
fn set_paused(env: &Env, paused: bool) {
|
|
28
28
|
let current_paused = OFTPausableStorage::paused(env);
|
|
29
29
|
assert_with_error!(env, current_paused != paused, OFTPausableError::PauseStatusUnchanged);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
use common_macros::{contract_error,
|
|
2
|
-
use soroban_sdk::{assert_with_error, contractevent,
|
|
1
|
+
use common_macros::{contract_error, contract_trait, only_auth, storage};
|
|
2
|
+
use soroban_sdk::{assert_with_error, contractevent, contracttype, panic_with_error, Env};
|
|
3
3
|
use utils::ownable::Ownable;
|
|
4
4
|
|
|
5
5
|
#[contracttype]
|
|
@@ -87,9 +87,9 @@ fn checkpoint_rate_limit_in_flight(env: &Env, direction: &Direction, eid: u32) {
|
|
|
87
87
|
RateLimitStorage::set_rate_limit(env, direction, eid, &rate_limit);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
#[
|
|
90
|
+
#[contract_trait]
|
|
91
91
|
pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
|
|
92
|
-
#[
|
|
92
|
+
#[only_auth]
|
|
93
93
|
fn set_rate_limit(env: &Env, direction: &Direction, eid: u32, limit: i128, window_seconds: u64) {
|
|
94
94
|
assert_with_error!(env, limit > 0, RateLimitError::InvalidLimit);
|
|
95
95
|
assert_with_error!(env, window_seconds > 0, RateLimitError::InvalidWindowSeconds);
|
|
@@ -122,7 +122,7 @@ pub trait RateLimiter: RateLimiterInternal + Ownable + Sized {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
#[
|
|
125
|
+
#[only_auth]
|
|
126
126
|
fn unset_rate_limit(env: &Env, direction: &Direction, eid: u32) {
|
|
127
127
|
assert_with_error!(env, RateLimitStorage::has_rate_limit(env, direction, eid), RateLimitError::SameValue);
|
|
128
128
|
RateLimitStorage::remove_rate_limit(env, direction, eid);
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
#![no_std]
|
|
2
2
|
|
|
3
3
|
pub mod codec;
|
|
4
|
-
pub mod constants;
|
|
5
|
-
pub mod default_oft_impl;
|
|
6
4
|
pub mod errors;
|
|
7
5
|
pub mod events;
|
|
8
6
|
pub mod extensions;
|
|
9
7
|
pub mod interfaces;
|
|
10
8
|
pub mod oft;
|
|
9
|
+
pub mod oft_impl;
|
|
11
10
|
pub mod oft_types;
|
|
12
11
|
pub mod storage;
|
|
13
12
|
pub mod types;
|
|
14
13
|
pub mod utils;
|
|
15
14
|
|
|
15
|
+
// Re-export commonly used items
|
|
16
|
+
pub use oft_impl::initialize_oft;
|
|
17
|
+
|
|
16
18
|
#[cfg(test)]
|
|
17
19
|
#[path = "../integration-tests/mod.rs"]
|
|
18
20
|
pub mod integration_tests;
|