@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
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
use crate as utils;
|
|
2
|
+
use crate::errors::TtlError;
|
|
3
|
+
use soroban_sdk::{assert_with_error, contracttype, Env};
|
|
4
|
+
|
|
5
|
+
/// Number of ledgers per day (~5 second ledger close time).
|
|
6
|
+
pub const LEDGERS_PER_DAY: u32 = (24 * 3600) / 5;
|
|
7
|
+
|
|
8
|
+
/// Maximum TTL (1 year) allowed by the protocol.
|
|
9
|
+
/// Note: Stellar's current maximum TTL is 6 months, but this constraint may change
|
|
10
|
+
/// in the future. In order to preserve LayerZero's censorship-resistance and protect
|
|
11
|
+
/// users from abusive parameter changes, a constant upper bound is enforced on the
|
|
12
|
+
/// extend_to value.
|
|
13
|
+
pub const MAX_TTL: u32 = 365 * LEDGERS_PER_DAY;
|
|
14
|
+
|
|
15
|
+
/// Default TTL for instance storage (30 days, extends at 29 days remaining).
|
|
16
|
+
pub const DEFAULT_INSTANCE_TTL: TtlConfig = TtlConfig::new(29 * LEDGERS_PER_DAY, 30 * LEDGERS_PER_DAY);
|
|
17
|
+
/// Default TTL for persistent storage (30 days, extends at 29 days remaining).
|
|
18
|
+
pub const DEFAULT_PERSISTENT_TTL: TtlConfig = TtlConfig::new(29 * LEDGERS_PER_DAY, 30 * LEDGERS_PER_DAY);
|
|
19
|
+
/// Default TTL for temporary storage (7 days, extends at 6 days remaining).
|
|
20
|
+
pub const DEFAULT_TEMPORARY_TTL: TtlConfig = TtlConfig::new(6 * LEDGERS_PER_DAY, 7 * LEDGERS_PER_DAY);
|
|
21
|
+
|
|
22
|
+
/// A pair of TTL values: threshold (when to trigger extension) and extend_to (target TTL).
|
|
23
|
+
#[contracttype]
|
|
24
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
25
|
+
pub struct TtlConfig {
|
|
26
|
+
/// TTL threshold that triggers extension (in ledgers).
|
|
27
|
+
pub threshold: u32,
|
|
28
|
+
/// Target TTL after extension (in ledgers).
|
|
29
|
+
pub extend_to: u32,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl TtlConfig {
|
|
33
|
+
/// Creates a new TTL config.
|
|
34
|
+
pub const fn new(threshold: u32, extend_to: u32) -> Self {
|
|
35
|
+
Self { threshold, extend_to }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Validates that threshold <= extend_to <= max_ttl.
|
|
39
|
+
pub fn is_valid(&self, max_ttl: u32) -> bool {
|
|
40
|
+
self.threshold <= self.extend_to && self.extend_to <= max_ttl
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Storage keys for TTL configuration.
|
|
45
|
+
#[common_macros::storage]
|
|
46
|
+
pub enum TtlConfigData {
|
|
47
|
+
#[instance(bool)]
|
|
48
|
+
#[default(false)]
|
|
49
|
+
Frozen,
|
|
50
|
+
|
|
51
|
+
#[instance(TtlConfig)]
|
|
52
|
+
Instance,
|
|
53
|
+
|
|
54
|
+
#[instance(TtlConfig)]
|
|
55
|
+
Persistent,
|
|
56
|
+
|
|
57
|
+
#[instance(TtlConfig)]
|
|
58
|
+
Temporary,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Trait for providing TTL configurations.
|
|
62
|
+
pub trait TtlConfigProvider {
|
|
63
|
+
fn persistent(env: &Env) -> TtlConfig;
|
|
64
|
+
fn instance(env: &Env) -> TtlConfig;
|
|
65
|
+
fn temporary(env: &Env) -> TtlConfig;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Helper functions used by the `#[storage]` macro to enforce that a user-provided
|
|
69
|
+
/// TTL config provider implements the [`TtlConfigProvider`] trait.
|
|
70
|
+
///
|
|
71
|
+
/// The macro generates code that calls these functions with the provider type as
|
|
72
|
+
/// the generic parameter `T`. If the provider does not implement `TtlConfigProvider`,
|
|
73
|
+
/// the compiler will emit an error at the macro expansion site, ensuring type safety
|
|
74
|
+
/// at compile time.
|
|
75
|
+
pub mod ttl_config {
|
|
76
|
+
use super::{TtlConfig, TtlConfigProvider};
|
|
77
|
+
use soroban_sdk::Env;
|
|
78
|
+
|
|
79
|
+
pub fn instance<T: TtlConfigProvider>(env: &Env) -> TtlConfig {
|
|
80
|
+
T::instance(env)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn persistent<T: TtlConfigProvider>(env: &Env) -> TtlConfig {
|
|
84
|
+
T::persistent(env)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pub fn temporary<T: TtlConfigProvider>(env: &Env) -> TtlConfig {
|
|
88
|
+
T::temporary(env)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Default implementation using TtlConfigData storage.
|
|
93
|
+
pub struct DefaultTtlConfigProvider;
|
|
94
|
+
|
|
95
|
+
impl TtlConfigProvider for DefaultTtlConfigProvider {
|
|
96
|
+
fn instance(env: &Env) -> TtlConfig {
|
|
97
|
+
TtlConfigData::instance(env).unwrap_or(DEFAULT_INSTANCE_TTL)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fn persistent(env: &Env) -> TtlConfig {
|
|
101
|
+
TtlConfigData::persistent(env).unwrap_or(DEFAULT_PERSISTENT_TTL)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fn temporary(env: &Env) -> TtlConfig {
|
|
105
|
+
TtlConfigData::temporary(env).unwrap_or(DEFAULT_TEMPORARY_TTL)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// Trait for contracts that allow TTL configuration management.
|
|
110
|
+
pub trait TtlConfigurable {
|
|
111
|
+
/// Sets TTL configs. None values remove the config (use defaults).
|
|
112
|
+
fn set_ttl_config(
|
|
113
|
+
env: &Env,
|
|
114
|
+
instance: &Option<TtlConfig>,
|
|
115
|
+
persistent: &Option<TtlConfig>,
|
|
116
|
+
temporary: &Option<TtlConfig>,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
/// Returns current TTL configs (instance, persistent, temporary).
|
|
120
|
+
fn ttl_config(env: &Env) -> (Option<TtlConfig>, Option<TtlConfig>, Option<TtlConfig>);
|
|
121
|
+
|
|
122
|
+
/// Permanently freezes TTL config, preventing further changes.
|
|
123
|
+
fn freeze_ttl_config(env: &Env);
|
|
124
|
+
|
|
125
|
+
/// Returns whether TTL config is frozen.
|
|
126
|
+
fn is_ttl_config_frozen(env: &Env) -> bool;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Default implementation of TtlConfigurable.
|
|
130
|
+
pub struct DefaultTtlConfigurable;
|
|
131
|
+
|
|
132
|
+
impl TtlConfigurable for DefaultTtlConfigurable {
|
|
133
|
+
fn set_ttl_config(
|
|
134
|
+
env: &Env,
|
|
135
|
+
instance: &Option<TtlConfig>,
|
|
136
|
+
persistent: &Option<TtlConfig>,
|
|
137
|
+
temporary: &Option<TtlConfig>,
|
|
138
|
+
) {
|
|
139
|
+
assert_with_error!(env, !Self::is_ttl_config_frozen(env), TtlError::TtlConfigFrozen);
|
|
140
|
+
|
|
141
|
+
let max_ttl = u32::min(MAX_TTL, env.storage().max_ttl());
|
|
142
|
+
let all_valid = [instance, persistent, temporary].iter().all(|c| c.is_none_or(|cfg| cfg.is_valid(max_ttl)));
|
|
143
|
+
assert_with_error!(env, all_valid, TtlError::InvalidTtlConfig);
|
|
144
|
+
|
|
145
|
+
TtlConfigData::set_or_remove_instance(env, instance);
|
|
146
|
+
TtlConfigData::set_or_remove_persistent(env, persistent);
|
|
147
|
+
TtlConfigData::set_or_remove_temporary(env, temporary);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
fn ttl_config(env: &Env) -> (Option<TtlConfig>, Option<TtlConfig>, Option<TtlConfig>) {
|
|
151
|
+
(TtlConfigData::instance(env), TtlConfigData::persistent(env), TtlConfigData::temporary(env))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fn freeze_ttl_config(env: &Env) {
|
|
155
|
+
assert_with_error!(env, !Self::is_ttl_config_frozen(env), TtlError::TtlConfigAlreadyFrozen);
|
|
156
|
+
TtlConfigData::set_frozen(env, &true);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fn is_ttl_config_frozen(env: &Env) -> bool {
|
|
160
|
+
TtlConfigData::frozen(env)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// TODO: add events
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "executor"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
publish = false
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
crate-type = ["cdylib"]
|
|
10
|
+
doctest = false
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
soroban-sdk = { workspace = true }
|
|
14
|
+
endpoint-v2 = { workspace = true, features = ["library"] }
|
|
15
|
+
utils = { workspace = true }
|
|
16
|
+
worker-common = { workspace = true }
|
|
17
|
+
stellar-access = { workspace = true }
|
|
18
|
+
stellar-macros = { workspace = true }
|
|
19
|
+
stellar-contract-utils = { workspace = true }
|
|
20
|
+
common-macros = { workspace = true }
|
|
21
|
+
message-lib-common = { workspace = true }
|
|
22
|
+
|
|
23
|
+
[dev-dependencies]
|
|
24
|
+
soroban-sdk = { workspace = true, features = ["testutils"] }
|
|
25
|
+
message-lib-common = { workspace = true, features = ["testutils"] }
|
|
26
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
use endpoint_v2::Origin;
|
|
2
|
+
use soroban_sdk::{contractevent, Address, Vec};
|
|
3
|
+
|
|
4
|
+
use crate::interfaces::{NativeDropParams, SetDstConfigParam};
|
|
5
|
+
|
|
6
|
+
// === Executor Events ===
|
|
7
|
+
|
|
8
|
+
#[contractevent(topics = ["DstConfigSet"])]
|
|
9
|
+
#[derive(Clone, Eq, PartialEq)]
|
|
10
|
+
pub struct DstConfigSet {
|
|
11
|
+
pub params: Vec<SetDstConfigParam>,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[contractevent(topics = ["NativeDropApplied"])]
|
|
15
|
+
#[derive(Clone, Eq, PartialEq)]
|
|
16
|
+
pub struct NativeDropApplied {
|
|
17
|
+
pub origin: Origin,
|
|
18
|
+
pub dst_eid: u32,
|
|
19
|
+
pub oapp: Address,
|
|
20
|
+
pub native_drop_params: Vec<NativeDropParams>,
|
|
21
|
+
pub success: Vec<bool>,
|
|
22
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
use crate::{
|
|
2
|
+
events::{DstConfigSet, NativeDropApplied},
|
|
3
|
+
interfaces::{DstConfig, ExecutionParams, IExecutor, NativeDropParams, SetDstConfigParam},
|
|
4
|
+
storage::ExecutorData,
|
|
5
|
+
ComposeParams,
|
|
6
|
+
};
|
|
7
|
+
use endpoint_v2::{
|
|
8
|
+
FeeRecipient, LayerZeroComposerClient, LayerZeroEndpointV2Client, LayerZeroReceiverClient, MessagingComposerClient,
|
|
9
|
+
};
|
|
10
|
+
use message_lib_common::ILayerZeroExecutor;
|
|
11
|
+
use soroban_sdk::{assert_with_error, bytes, contract, contractimpl, token, vec, Address, Bytes, Env, Vec};
|
|
12
|
+
use stellar_access::access_control::AccessControl;
|
|
13
|
+
use stellar_macros::{default_impl, only_role, when_not_paused};
|
|
14
|
+
use worker_common::{ExecutorFeeLibClient, FeeParams, IWorker, WorkerCommon, WorkerError};
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Executor Contract
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
#[contract]
|
|
21
|
+
pub struct LzExecutor;
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Constructor
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
#[contractimpl()]
|
|
28
|
+
impl LzExecutor {
|
|
29
|
+
/// Constructor - Initialize the executor contract
|
|
30
|
+
/// Follows the EVM pattern: initialize(endpoint, messageLibs, priceFeed, roleAdmin, admins)
|
|
31
|
+
pub fn __constructor(
|
|
32
|
+
env: &Env,
|
|
33
|
+
endpoint: &Address,
|
|
34
|
+
message_libs: &Vec<Address>,
|
|
35
|
+
price_feed: &Address,
|
|
36
|
+
default_multiplier_bps: u32,
|
|
37
|
+
role_admin: &Address,
|
|
38
|
+
admins: &Vec<Address>,
|
|
39
|
+
) {
|
|
40
|
+
// Initialize WorkerCommon (handles access control and basic worker setup)
|
|
41
|
+
WorkerCommon::initialize(env, role_admin, message_libs, price_feed, default_multiplier_bps, admins);
|
|
42
|
+
|
|
43
|
+
// Store executor-specific data
|
|
44
|
+
ExecutorData::set_endpoint(env, endpoint);
|
|
45
|
+
|
|
46
|
+
// Get and store the local EID from the endpoint
|
|
47
|
+
let endpoint_client = LayerZeroEndpointV2Client::new(env, endpoint);
|
|
48
|
+
let local_eid = endpoint_client.eid();
|
|
49
|
+
ExecutorData::set_local_eid(env, &local_eid);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pub(crate) fn endpoint(env: &Env) -> Address {
|
|
53
|
+
ExecutorData::endpoint(env).unwrap()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// IWorker Implementation (delegate to WorkerCommon)
|
|
59
|
+
// ============================================================================
|
|
60
|
+
|
|
61
|
+
#[contractimpl]
|
|
62
|
+
impl IWorker for LzExecutor {
|
|
63
|
+
// ========================================================================
|
|
64
|
+
// Mutable Functions
|
|
65
|
+
// ========================================================================
|
|
66
|
+
|
|
67
|
+
fn set_paused(env: &Env, paused: bool) {
|
|
68
|
+
WorkerCommon::set_paused(env, paused);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn set_default_multiplier_bps(env: &Env, admin: &Address, multiplier_bps: u32) {
|
|
72
|
+
WorkerCommon::set_default_multiplier_bps(env, admin, multiplier_bps);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn set_deposit_address(env: &Env, admin: &Address, deposit_address: &Address) {
|
|
76
|
+
WorkerCommon::set_deposit_address(env, admin, deposit_address);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fn set_price_feed(env: &Env, admin: &Address, price_feed: &Address) {
|
|
80
|
+
WorkerCommon::set_price_feed(env, admin, price_feed);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fn set_supported_option_types(env: &Env, admin: &Address, eid: u32, option_types: Bytes) {
|
|
84
|
+
WorkerCommon::set_supported_option_types(env, admin, eid, option_types);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn set_worker_fee_lib(env: &Env, admin: &Address, worker_fee_lib: &Address) {
|
|
88
|
+
WorkerCommon::set_worker_fee_lib(env, admin, worker_fee_lib);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ========================================================================
|
|
92
|
+
// View Functions
|
|
93
|
+
// ========================================================================
|
|
94
|
+
|
|
95
|
+
fn paused(env: &Env) -> bool {
|
|
96
|
+
WorkerCommon::paused(env)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn default_multiplier_bps(env: &Env) -> u32 {
|
|
100
|
+
WorkerCommon::default_multiplier_bps(env)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn deposit_address(env: &Env) -> Address {
|
|
104
|
+
WorkerCommon::deposit_address(env)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fn price_feed(env: &Env) -> Address {
|
|
108
|
+
WorkerCommon::price_feed(env)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fn get_supported_option_types(env: &Env, eid: u32) -> Bytes {
|
|
112
|
+
WorkerCommon::get_supported_option_types(env, eid)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fn worker_fee_lib(env: &Env) -> Address {
|
|
116
|
+
WorkerCommon::worker_fee_lib(env)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fn has_acl(env: &Env, sender: &Address) -> bool {
|
|
120
|
+
WorkerCommon::has_acl(env, sender)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fn allowlist_size(env: &Env) -> u32 {
|
|
124
|
+
WorkerCommon::allowlist_size(env)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// IExecutor Implementation
|
|
130
|
+
// ============================================================================
|
|
131
|
+
|
|
132
|
+
#[contractimpl]
|
|
133
|
+
impl IExecutor for LzExecutor {
|
|
134
|
+
// === Destination Configuration ===
|
|
135
|
+
|
|
136
|
+
#[only_role(admin, "ADMIN")]
|
|
137
|
+
fn set_dst_config(env: &Env, admin: &Address, params: &Vec<SetDstConfigParam>) {
|
|
138
|
+
for param in params.iter() {
|
|
139
|
+
ExecutorData::set_dst_config(env, param.dst_eid, ¶m.dst_config);
|
|
140
|
+
}
|
|
141
|
+
DstConfigSet { params: params.clone() }.publish(env);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// === Execution Functions ===
|
|
145
|
+
|
|
146
|
+
#[only_role(admin, "ADMIN")]
|
|
147
|
+
fn native_drop(
|
|
148
|
+
env: &Env,
|
|
149
|
+
admin: &Address,
|
|
150
|
+
origin: &endpoint_v2::Origin,
|
|
151
|
+
dst_eid: u32,
|
|
152
|
+
oapp: &Address,
|
|
153
|
+
native_drop_params: &Vec<NativeDropParams>,
|
|
154
|
+
) {
|
|
155
|
+
let endpoint = Self::endpoint(env);
|
|
156
|
+
let native_token_client =
|
|
157
|
+
token::TokenClient::new(env, &LayerZeroEndpointV2Client::new(env, &endpoint).native_token());
|
|
158
|
+
|
|
159
|
+
let mut success = vec![env];
|
|
160
|
+
|
|
161
|
+
for param in native_drop_params.iter() {
|
|
162
|
+
// Attempt to transfer native tokens to the receiver
|
|
163
|
+
// In Stellar, we use the token client to transfer
|
|
164
|
+
let transfer_success = native_token_client
|
|
165
|
+
.try_transfer(&env.current_contract_address(), ¶m.receiver, ¶m.amount)
|
|
166
|
+
.is_ok();
|
|
167
|
+
|
|
168
|
+
success.push_back(transfer_success);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
NativeDropApplied {
|
|
172
|
+
origin: origin.clone(),
|
|
173
|
+
dst_eid,
|
|
174
|
+
oapp: oapp.clone(),
|
|
175
|
+
native_drop_params: native_drop_params.clone(),
|
|
176
|
+
success,
|
|
177
|
+
}
|
|
178
|
+
.publish(env);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#[only_role(admin, "ADMIN")]
|
|
182
|
+
fn execute(env: &Env, admin: &Address, execution_params: &ExecutionParams) {
|
|
183
|
+
let endpoint = Self::endpoint(env);
|
|
184
|
+
let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
|
|
185
|
+
let native_token_client = token::TokenClient::new(env, &endpoint_client.native_token());
|
|
186
|
+
|
|
187
|
+
// Transfer value to receiver if needed (matching EVM pattern)
|
|
188
|
+
if execution_params.value > 0 {
|
|
189
|
+
native_token_client.transfer(admin, env.current_contract_address(), &execution_params.value);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Call lz_receive on the receiver
|
|
193
|
+
let receiver_client = LayerZeroReceiverClient::new(env, &execution_params.receiver);
|
|
194
|
+
|
|
195
|
+
// Try to execute lz_receive (matching EVM try-catch pattern)
|
|
196
|
+
let result = receiver_client.try_lz_receive(
|
|
197
|
+
&env.current_contract_address(),
|
|
198
|
+
&execution_params.origin,
|
|
199
|
+
&execution_params.guid,
|
|
200
|
+
&execution_params.message,
|
|
201
|
+
&execution_params.extra_data,
|
|
202
|
+
&execution_params.value,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// If execution failed, call lz_receive_alert on endpoint (matching EVM catch block)
|
|
206
|
+
if result.is_err() {
|
|
207
|
+
// Get the error reason - in Stellar we just use an empty bytes for simplicity
|
|
208
|
+
let reason = bytes![env];
|
|
209
|
+
endpoint_client.lz_receive_alert(
|
|
210
|
+
&env.current_contract_address(),
|
|
211
|
+
&execution_params.origin,
|
|
212
|
+
&execution_params.receiver,
|
|
213
|
+
&execution_params.guid,
|
|
214
|
+
&execution_params.gas_limit,
|
|
215
|
+
&execution_params.value,
|
|
216
|
+
&execution_params.message,
|
|
217
|
+
&execution_params.extra_data,
|
|
218
|
+
&reason,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#[only_role(admin, "ADMIN")]
|
|
224
|
+
fn compose(env: &Env, admin: &Address, compose_params: &ComposeParams) {
|
|
225
|
+
let endpoint = ExecutorData::endpoint(env).expect("endpoint not set");
|
|
226
|
+
let endpoint_client = LayerZeroEndpointV2Client::new(env, &endpoint);
|
|
227
|
+
let native_token_client = token::TokenClient::new(env, &endpoint_client.native_token());
|
|
228
|
+
|
|
229
|
+
// Transfer value to composer if needed (matching EVM pattern)
|
|
230
|
+
if compose_params.value > 0 {
|
|
231
|
+
native_token_client.transfer(admin, env.current_contract_address(), &compose_params.value);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Call lz_compose on the composer
|
|
235
|
+
let composer_client = LayerZeroComposerClient::new(env, &compose_params.to);
|
|
236
|
+
|
|
237
|
+
// Try to execute lz_compose (matching EVM try-catch pattern)
|
|
238
|
+
let result = composer_client.try_lz_compose(
|
|
239
|
+
&env.current_contract_address(),
|
|
240
|
+
&compose_params.from,
|
|
241
|
+
&compose_params.guid,
|
|
242
|
+
&compose_params.index,
|
|
243
|
+
&compose_params.message,
|
|
244
|
+
&compose_params.extra_data,
|
|
245
|
+
&compose_params.value,
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// If execution failed, call lz_compose_alert on endpoint (matching EVM catch block)
|
|
249
|
+
if result.is_err() {
|
|
250
|
+
// Get the error reason - in Stellar we just use an empty bytes for simplicity
|
|
251
|
+
let reason = bytes![env];
|
|
252
|
+
|
|
253
|
+
// lz_compose_alert is on MessagingComposerClient, not LayerZeroEndpointV2Client
|
|
254
|
+
let composer_client = MessagingComposerClient::new(env, &endpoint);
|
|
255
|
+
composer_client.lz_compose_alert(
|
|
256
|
+
&env.current_contract_address(),
|
|
257
|
+
&compose_params.from,
|
|
258
|
+
&compose_params.to,
|
|
259
|
+
&compose_params.guid,
|
|
260
|
+
&compose_params.index,
|
|
261
|
+
&compose_params.gas_limit,
|
|
262
|
+
&compose_params.value,
|
|
263
|
+
&compose_params.message,
|
|
264
|
+
&compose_params.extra_data,
|
|
265
|
+
&reason,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// View Functions
|
|
271
|
+
|
|
272
|
+
fn dst_config(env: &Env, dst_eid: u32) -> Option<DstConfig> {
|
|
273
|
+
ExecutorData::dst_config(env, dst_eid)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ============================================================================
|
|
278
|
+
// IMsgLibExecutor Implementation (for message libraries)
|
|
279
|
+
// ============================================================================
|
|
280
|
+
|
|
281
|
+
#[contractimpl]
|
|
282
|
+
impl ILayerZeroExecutor for LzExecutor {
|
|
283
|
+
#[only_role(_send_lib, "MSG_LIB")]
|
|
284
|
+
#[when_not_paused()]
|
|
285
|
+
fn assign_job(
|
|
286
|
+
env: &Env,
|
|
287
|
+
_send_lib: &Address,
|
|
288
|
+
sender: &Address,
|
|
289
|
+
dst_eid: u32,
|
|
290
|
+
calldata_size: u32,
|
|
291
|
+
options: &Bytes,
|
|
292
|
+
) -> FeeRecipient {
|
|
293
|
+
let fee = Self::get_fee(env, _send_lib, sender, dst_eid, calldata_size, options);
|
|
294
|
+
let recipient = WorkerCommon::deposit_address(env);
|
|
295
|
+
FeeRecipient { amount: fee, address: recipient }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
#[when_not_paused()]
|
|
299
|
+
fn get_fee(
|
|
300
|
+
env: &Env,
|
|
301
|
+
_send_lib: &Address,
|
|
302
|
+
sender: &Address,
|
|
303
|
+
dst_eid: u32,
|
|
304
|
+
calldata_size: u32,
|
|
305
|
+
options: &Bytes,
|
|
306
|
+
) -> i128 {
|
|
307
|
+
// Check ACL
|
|
308
|
+
assert_with_error!(env, WorkerCommon::has_acl(env, sender), WorkerError::NotAllowed);
|
|
309
|
+
|
|
310
|
+
// Get the dst_config
|
|
311
|
+
let dst_config = Self::dst_config(env, dst_eid).unwrap_or(DstConfig {
|
|
312
|
+
lz_receive_base_gas: 0,
|
|
313
|
+
multiplier_bps: 0,
|
|
314
|
+
floor_margin_usd: 0,
|
|
315
|
+
native_cap: 0,
|
|
316
|
+
lz_compose_base_gas: 0,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Build FeeParams for the executor fee lib
|
|
320
|
+
let fee_params = FeeParams {
|
|
321
|
+
sender: sender.clone(),
|
|
322
|
+
dst_eid,
|
|
323
|
+
calldata_size,
|
|
324
|
+
options: options.clone(),
|
|
325
|
+
price_feed: WorkerCommon::price_feed(env),
|
|
326
|
+
default_multiplier_bps: WorkerCommon::default_multiplier_bps(env),
|
|
327
|
+
lz_receive_base_gas: dst_config.lz_receive_base_gas,
|
|
328
|
+
lz_compose_base_gas: dst_config.lz_compose_base_gas,
|
|
329
|
+
floor_margin_usd: dst_config.floor_margin_usd,
|
|
330
|
+
native_cap: dst_config.native_cap,
|
|
331
|
+
multiplier_bps: dst_config.multiplier_bps,
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// Call the executor fee lib to get the fee
|
|
335
|
+
let fee_lib = WorkerCommon::worker_fee_lib(env);
|
|
336
|
+
let fee_lib_client = ExecutorFeeLibClient::new(env, &fee_lib);
|
|
337
|
+
fee_lib_client.get_fee(&fee_lib, &fee_params)
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// ============================================================================
|
|
342
|
+
// AccessControl Implementation (default from stellar-access)
|
|
343
|
+
// ============================================================================
|
|
344
|
+
|
|
345
|
+
#[default_impl]
|
|
346
|
+
#[contractimpl]
|
|
347
|
+
impl AccessControl for LzExecutor {}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
use endpoint_v2::Origin;
|
|
2
|
+
use message_lib_common::ILayerZeroExecutor;
|
|
3
|
+
use soroban_sdk::{contractclient, Address, Env, Vec};
|
|
4
|
+
use worker_common::IWorker;
|
|
5
|
+
|
|
6
|
+
use crate::{
|
|
7
|
+
interfaces::{DstConfig, ExecutionParams, NativeDropParams, SetDstConfigParam},
|
|
8
|
+
ComposeParams,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/// IExecutor - Main executor interface that combines multiple executor capabilities
|
|
12
|
+
/// Inherits from: IWorker and includes LayerZero execution methods
|
|
13
|
+
#[contractclient(name = "ExecutorClient")]
|
|
14
|
+
pub trait IExecutor: IWorker + ILayerZeroExecutor {
|
|
15
|
+
// === Destination Configuration ===
|
|
16
|
+
|
|
17
|
+
/// Get destination configuration for a specific endpoint
|
|
18
|
+
fn dst_config(env: &Env, dst_eid: u32) -> Option<DstConfig>;
|
|
19
|
+
|
|
20
|
+
/// Set destination configurations (admin only)
|
|
21
|
+
fn set_dst_config(env: &Env, admin: &Address, params: &Vec<SetDstConfigParam>);
|
|
22
|
+
|
|
23
|
+
// === Execution Functions ===
|
|
24
|
+
|
|
25
|
+
/// Execute native token drops
|
|
26
|
+
fn native_drop(
|
|
27
|
+
env: &Env,
|
|
28
|
+
admin: &Address,
|
|
29
|
+
origin: &Origin,
|
|
30
|
+
dst_eid: u32,
|
|
31
|
+
oapp: &Address,
|
|
32
|
+
native_drop_params: &Vec<NativeDropParams>,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/// Execute v2 message
|
|
36
|
+
fn execute(env: &Env, admin: &Address, execution_params: &ExecutionParams);
|
|
37
|
+
|
|
38
|
+
/// Compose v2 message
|
|
39
|
+
fn compose(env: &Env, admin: &Address, compose_params: &ComposeParams);
|
|
40
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
use endpoint_v2::Origin;
|
|
2
|
+
use soroban_sdk::{contracttype, Address, Bytes, BytesN};
|
|
3
|
+
|
|
4
|
+
#[contracttype]
|
|
5
|
+
#[derive(Clone, Debug)]
|
|
6
|
+
pub struct DstConfig {
|
|
7
|
+
pub lz_receive_base_gas: u64,
|
|
8
|
+
pub multiplier_bps: u32,
|
|
9
|
+
pub floor_margin_usd: u128,
|
|
10
|
+
pub native_cap: u128,
|
|
11
|
+
pub lz_compose_base_gas: u64,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[contracttype]
|
|
15
|
+
#[derive(Clone, Debug)]
|
|
16
|
+
pub struct SetDstConfigParam {
|
|
17
|
+
pub dst_eid: u32,
|
|
18
|
+
pub dst_config: DstConfig,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[contracttype]
|
|
22
|
+
#[derive(Clone, Debug)]
|
|
23
|
+
pub struct ExecutionParams {
|
|
24
|
+
pub receiver: Address,
|
|
25
|
+
pub origin: Origin,
|
|
26
|
+
pub guid: BytesN<32>,
|
|
27
|
+
pub message: Bytes,
|
|
28
|
+
pub extra_data: Bytes,
|
|
29
|
+
pub value: i128,
|
|
30
|
+
pub gas_limit: i128,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[contracttype]
|
|
34
|
+
#[derive(Clone, Debug)]
|
|
35
|
+
pub struct NativeDropParams {
|
|
36
|
+
pub receiver: Address,
|
|
37
|
+
pub amount: i128,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[contracttype]
|
|
41
|
+
#[derive(Clone, Debug)]
|
|
42
|
+
pub struct ComposeParams {
|
|
43
|
+
pub from: Address,
|
|
44
|
+
pub to: Address,
|
|
45
|
+
pub guid: BytesN<32>,
|
|
46
|
+
pub index: u32,
|
|
47
|
+
pub message: Bytes,
|
|
48
|
+
pub extra_data: Bytes,
|
|
49
|
+
pub value: i128,
|
|
50
|
+
pub gas_limit: i128,
|
|
51
|
+
}
|