@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,199 @@
|
|
|
1
|
+
// ================================================
|
|
2
|
+
// IReceiveUln302 Contract Implementation
|
|
3
|
+
// ================================================
|
|
4
|
+
|
|
5
|
+
#[contractimpl]
|
|
6
|
+
impl IReceiveUln302 for Uln302 {
|
|
7
|
+
/// Called by a DVN to verify a message with a specific number of block confirmations.
|
|
8
|
+
///
|
|
9
|
+
/// Stores the DVN's verification attestation which will be checked during commit_verification.
|
|
10
|
+
fn verify(env: &Env, dvn: &Address, packet_header: &Bytes, payload_hash: &BytesN<32>, confirmations: u64) {
|
|
11
|
+
dvn.require_auth();
|
|
12
|
+
|
|
13
|
+
let header_hash = util::keccak256(env, packet_header);
|
|
14
|
+
UlnStorage::set_confirmations(env, dvn, &header_hash, payload_hash, &confirmations);
|
|
15
|
+
|
|
16
|
+
PayloadVerified {
|
|
17
|
+
dvn: dvn.clone(),
|
|
18
|
+
header: packet_header.clone(),
|
|
19
|
+
proof_hash: payload_hash.clone(),
|
|
20
|
+
confirmations,
|
|
21
|
+
}
|
|
22
|
+
.publish(env);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Permissonless to commit a verified message to the endpoint after sufficient DVN verification.
|
|
26
|
+
///
|
|
27
|
+
/// Validates the packet header and checks that enough DVNs have verified the message
|
|
28
|
+
/// (all required DVNs + optional DVN threshold). Once verified, cleans up DVN confirmation
|
|
29
|
+
/// storage and calls the endpoint to mark the message as verified and executable.
|
|
30
|
+
fn commit_verification(env: &Env, packet_header: &Bytes, payload_hash: &BytesN<32>) {
|
|
31
|
+
let (header, header_hash, uln_config) = Self::validate_and_extract_param(env, packet_header);
|
|
32
|
+
|
|
33
|
+
// check if the message is verifiable
|
|
34
|
+
assert_with_error!(
|
|
35
|
+
env,
|
|
36
|
+
Self::verifiable_internal(env, &uln_config, &header_hash, payload_hash),
|
|
37
|
+
Uln302Error::Verifying
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// clean up confirmations storage for all DVNs
|
|
41
|
+
uln_config.required_dvns.iter().chain(uln_config.optional_dvns.iter()).for_each(|dvn| {
|
|
42
|
+
UlnStorage::remove_confirmations(env, &dvn, &header_hash, payload_hash);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// commit verification to the endpoint
|
|
46
|
+
let send_lib = env.current_contract_address();
|
|
47
|
+
let origin = Origin { src_eid: header.src_eid, sender: header.sender, nonce: header.nonce };
|
|
48
|
+
let receiver = Address::from_payload(env, AddressPayload::ContractIdHash(header.receiver));
|
|
49
|
+
LayerZeroEndpointV2Client::new(env, &Self::endpoint(env)).verify(&send_lib, &origin, &receiver, payload_hash);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// === Owner Set Config Functions ===
|
|
53
|
+
|
|
54
|
+
/// Sets default receive ULN configurations for multiple source endpoints.
|
|
55
|
+
///
|
|
56
|
+
/// Validates each config and stores it as the default for the specified source EID.
|
|
57
|
+
#[only_owner]
|
|
58
|
+
fn set_default_receive_uln_configs(env: &Env, params: &Vec<SetDefaultUlnConfigParam>) {
|
|
59
|
+
for param in params {
|
|
60
|
+
param.config.validate_default_config(env);
|
|
61
|
+
UlnStorage::set_default_receive_uln_configs(env, param.dst_eid, ¶m.config);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
DefaultUlnReceiveConfigSet { params: params.clone() }.publish(env);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// === View Functions ===
|
|
68
|
+
|
|
69
|
+
/// Returns the number of block confirmations a DVN has submitted for a specific message.
|
|
70
|
+
fn confirmations(env: &Env, dvn: &Address, header_hash: &BytesN<32>, payload_hash: &BytesN<32>) -> Option<u64> {
|
|
71
|
+
UlnStorage::confirmations(env, dvn, header_hash, payload_hash)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Checks if a message has been sufficiently verified by DVNs and is ready to commit.
|
|
75
|
+
fn verifiable(env: &Env, packet_header: &Bytes, payload_hash: &BytesN<32>) -> bool {
|
|
76
|
+
let (_, header_hash, uln_config) = Self::validate_and_extract_param(env, packet_header);
|
|
77
|
+
Self::verifiable_internal(env, &uln_config, &header_hash, payload_hash)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Returns the default receive ULN configuration for a source endpoint.
|
|
81
|
+
fn default_receive_uln_config(env: &Env, src_eid: u32) -> Option<UlnConfig> {
|
|
82
|
+
UlnStorage::default_receive_uln_configs(env, src_eid)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Returns the OApp-specific receive ULN configuration override for a source endpoint.
|
|
86
|
+
fn oapp_receive_uln_config(env: &Env, receiver: &Address, src_eid: u32) -> Option<OAppUlnConfig> {
|
|
87
|
+
UlnStorage::oapp_receive_uln_configs(env, receiver, src_eid)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// Returns the effective receive ULN configuration by merging OApp config with defaults.
|
|
91
|
+
fn effective_receive_uln_config(env: &Env, receiver: &Address, src_eid: u32) -> UlnConfig {
|
|
92
|
+
let default_config = Self::expect_default_receive_uln_config(env, src_eid);
|
|
93
|
+
let oapp_config = Self::oapp_receive_uln_config(env, receiver, src_eid).unwrap_or(OAppUlnConfig::default(env));
|
|
94
|
+
|
|
95
|
+
let config = oapp_config.apply_default_config(&default_config);
|
|
96
|
+
config.validate_at_least_one_dvn(env); // validate the final config
|
|
97
|
+
|
|
98
|
+
config
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ================================================
|
|
103
|
+
// Internal Functions
|
|
104
|
+
// ================================================
|
|
105
|
+
|
|
106
|
+
impl Uln302 {
|
|
107
|
+
// === OApp Set Config Functions ===
|
|
108
|
+
|
|
109
|
+
/// Sets OApp-specific receive ULN config.
|
|
110
|
+
///
|
|
111
|
+
/// # Arguments
|
|
112
|
+
/// * `receiver` - The receiver OApp address
|
|
113
|
+
/// * `src_eid` - The source endpoint ID
|
|
114
|
+
/// * `config` - The OApp-specific receive ULN configuration
|
|
115
|
+
///
|
|
116
|
+
/// # Panics
|
|
117
|
+
/// Panics if the final effective config is invalid.
|
|
118
|
+
fn set_receive_uln_config(env: &Env, receiver: &Address, src_eid: u32, config: &OAppUlnConfig) {
|
|
119
|
+
config.validate_oapp_config(env);
|
|
120
|
+
|
|
121
|
+
UlnStorage::set_oapp_receive_uln_configs(env, receiver, src_eid, config);
|
|
122
|
+
// validate the config by getting the effective config
|
|
123
|
+
let _ = Self::effective_receive_uln_config(env, receiver, src_eid);
|
|
124
|
+
|
|
125
|
+
UlnReceiveConfigSet { receiver: receiver.clone(), src_eid, config: config.clone() }.publish(env);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// === Verification Helpers Functions ===
|
|
129
|
+
|
|
130
|
+
/// Validates packet header and extracts header, header hash, and effective ULN config.
|
|
131
|
+
fn validate_and_extract_param(env: &Env, packet_header: &Bytes) -> (PacketHeader, BytesN<32>, UlnConfig) {
|
|
132
|
+
let header = packet_codec_v1::decode_packet_header(env, packet_header);
|
|
133
|
+
assert_with_error!(
|
|
134
|
+
env,
|
|
135
|
+
header.dst_eid == LayerZeroEndpointV2Client::new(env, &Self::endpoint(env)).eid(),
|
|
136
|
+
Uln302Error::InvalidEID
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
let header_hash = util::keccak256(env, packet_header);
|
|
140
|
+
let uln_config = Self::effective_receive_uln_config(
|
|
141
|
+
env,
|
|
142
|
+
&Address::from_payload(env, AddressPayload::ContractIdHash(header.receiver.clone())),
|
|
143
|
+
header.src_eid,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
(header, header_hash, uln_config)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// Checks if all required DVNs verified and optional DVN threshold is met.
|
|
150
|
+
///
|
|
151
|
+
/// # Arguments
|
|
152
|
+
/// * `uln_config` - The effective ULN configuration
|
|
153
|
+
/// * `header_hash` - The hash of the packet header
|
|
154
|
+
/// * `payload_hash` - The hash of the message payload
|
|
155
|
+
///
|
|
156
|
+
/// # Returns
|
|
157
|
+
/// True if the message has been verified by enough DVNs to be committed, false otherwise
|
|
158
|
+
fn verifiable_internal(
|
|
159
|
+
env: &Env,
|
|
160
|
+
uln_config: &UlnConfig,
|
|
161
|
+
header_hash: &BytesN<32>,
|
|
162
|
+
payload_hash: &BytesN<32>,
|
|
163
|
+
) -> bool {
|
|
164
|
+
let threshold = uln_config.optional_dvn_threshold as usize;
|
|
165
|
+
let is_verified = |dvn: &Address| Self::verified(env, dvn, header_hash, payload_hash, uln_config.confirmations);
|
|
166
|
+
|
|
167
|
+
// check if all required DVNs are verified and the optional DVNs threshold is met
|
|
168
|
+
uln_config.required_dvns.iter().all(|dvn| is_verified(&dvn))
|
|
169
|
+
&& uln_config.optional_dvns.iter().filter(is_verified).take(threshold).count() == threshold
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// Checks if a DVN has submitted enough confirmations for the message.
|
|
173
|
+
///
|
|
174
|
+
/// # Arguments
|
|
175
|
+
/// * `dvn` - The DVN address
|
|
176
|
+
/// * `header_hash` - The hash of the packet header
|
|
177
|
+
/// * `payload_hash` - The hash of the message payload
|
|
178
|
+
/// * `confirmations` - The number of block confirmations the DVN has observed
|
|
179
|
+
///
|
|
180
|
+
/// # Returns
|
|
181
|
+
/// True if the DVN has submitted enough confirmations for the message, false otherwise
|
|
182
|
+
fn verified(
|
|
183
|
+
env: &Env,
|
|
184
|
+
dvn: &Address,
|
|
185
|
+
header_hash: &BytesN<32>,
|
|
186
|
+
payload_hash: &BytesN<32>,
|
|
187
|
+
confirmations: u64,
|
|
188
|
+
) -> bool {
|
|
189
|
+
Self::confirmations(env, dvn, header_hash, payload_hash).map(|c| c >= confirmations).unwrap_or(false)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// === Helper Functions ===
|
|
193
|
+
|
|
194
|
+
/// Returns default receive ULN config or panics if not found.
|
|
195
|
+
fn expect_default_receive_uln_config(env: &Env, src_eid: u32) -> UlnConfig {
|
|
196
|
+
Self::default_receive_uln_config(env, src_eid)
|
|
197
|
+
.unwrap_or_panic(env, Uln302Error::DefaultReceiveUlnConfigNotFound)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// ==============================================================================
|
|
2
|
+
// ISendLib Contract Implementation
|
|
3
|
+
// ==============================================================================
|
|
4
|
+
|
|
5
|
+
#[contractimpl]
|
|
6
|
+
impl ISendLib for Uln302 {
|
|
7
|
+
/// Quotes the total fee for sending a cross-chain message.
|
|
8
|
+
///
|
|
9
|
+
/// Calculates fees from: executor (message execution), DVNs (verification), and treasury (protocol fee).
|
|
10
|
+
fn quote(env: &Env, packet: &OutboundPacket, options: &Bytes, pay_in_zro: bool) -> MessagingFee {
|
|
11
|
+
let (executor_options, dvn_options) = worker_options::split_worker_options(env, options);
|
|
12
|
+
|
|
13
|
+
// Executor fee
|
|
14
|
+
let executor_fee =
|
|
15
|
+
Self::quote_executor(env, &packet.sender, packet.dst_eid, packet.message.len(), &executor_options);
|
|
16
|
+
|
|
17
|
+
// DVNs fees
|
|
18
|
+
let packet_header = packet_codec_v1::encode_packet_header(env, packet);
|
|
19
|
+
let payload_hash = packet_codec_v1::payload_hash(env, packet);
|
|
20
|
+
let dvns_fee =
|
|
21
|
+
Self::quote_dvns(env, &packet.sender, packet.dst_eid, &packet_header, &payload_hash, &dvn_options);
|
|
22
|
+
|
|
23
|
+
// Treasury fee
|
|
24
|
+
let workers_fee = executor_fee + dvns_fee;
|
|
25
|
+
let treasury_fee =
|
|
26
|
+
Self::get_treasury_client(env).get_fee(&packet.sender, &packet.dst_eid, &workers_fee, &pay_in_zro);
|
|
27
|
+
|
|
28
|
+
if pay_in_zro {
|
|
29
|
+
MessagingFee { native_fee: workers_fee, zro_fee: treasury_fee }
|
|
30
|
+
} else {
|
|
31
|
+
MessagingFee { native_fee: workers_fee + treasury_fee, zro_fee: 0 }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// Sends a cross-chain message and returns fee recipients for payment.
|
|
36
|
+
///
|
|
37
|
+
/// Assigns executor and DVNs, calculates fees, and encodes the packet for transmission.
|
|
38
|
+
fn send(env: &Env, packet: &OutboundPacket, options: &Bytes, pay_in_zro: bool) -> FeesAndPacket {
|
|
39
|
+
Self::endpoint(env).require_auth();
|
|
40
|
+
|
|
41
|
+
let mut native_fee_recipients = vec![env];
|
|
42
|
+
let mut zro_fee_recipients = vec![env];
|
|
43
|
+
let (executor_options, dvn_options) = worker_options::split_worker_options(env, options);
|
|
44
|
+
|
|
45
|
+
// Executor fee
|
|
46
|
+
let executor_fee_recipient =
|
|
47
|
+
Self::assign_executor(env, &packet.sender, packet.dst_eid, packet.message.len(), &executor_options);
|
|
48
|
+
native_fee_recipients.push_back(executor_fee_recipient);
|
|
49
|
+
|
|
50
|
+
// DVNs fees
|
|
51
|
+
let packet_header = packet_codec_v1::encode_packet_header(env, packet);
|
|
52
|
+
let payload_hash = packet_codec_v1::payload_hash(env, packet);
|
|
53
|
+
let dvns_fee_recipients =
|
|
54
|
+
Self::assign_dvns(env, &packet.sender, packet.dst_eid, &packet_header, &payload_hash, &dvn_options);
|
|
55
|
+
native_fee_recipients.extend(dvns_fee_recipients.iter());
|
|
56
|
+
|
|
57
|
+
// Treasury fee
|
|
58
|
+
let workers_fee = native_fee_recipients.iter().map(|fee| fee.amount).sum();
|
|
59
|
+
let treasury_fee =
|
|
60
|
+
Self::get_treasury_client(env).get_fee(&packet.sender, &packet.dst_eid, &workers_fee, &pay_in_zro);
|
|
61
|
+
if treasury_fee > 0 {
|
|
62
|
+
let treasury_fee_recipient = FeeRecipient { address: Self::treasury(env), amount: treasury_fee };
|
|
63
|
+
if pay_in_zro {
|
|
64
|
+
zro_fee_recipients.push_back(treasury_fee_recipient);
|
|
65
|
+
} else {
|
|
66
|
+
native_fee_recipients.push_back(treasury_fee_recipient);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
FeesAndPacket {
|
|
71
|
+
native_fee_recipients,
|
|
72
|
+
zro_fee_recipients,
|
|
73
|
+
encoded_packet: packet_codec_v1::encode_packet(env, packet),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ==============================================================================
|
|
79
|
+
// ISendUln302 Contract Implementation
|
|
80
|
+
// ==============================================================================
|
|
81
|
+
|
|
82
|
+
#[contractimpl]
|
|
83
|
+
impl ISendUln302 for Uln302 {
|
|
84
|
+
// === Owner Set Config Functions ===
|
|
85
|
+
|
|
86
|
+
/// Sets default executor configurations for multiple destination endpoints.
|
|
87
|
+
#[only_owner]
|
|
88
|
+
fn set_default_executor_configs(env: &Env, params: &Vec<SetDefaultExecutorConfigParam>) {
|
|
89
|
+
for param in params {
|
|
90
|
+
param.config.validate_default_config(env);
|
|
91
|
+
UlnStorage::set_default_executor_configs(env, param.dst_eid, ¶m.config);
|
|
92
|
+
}
|
|
93
|
+
DefaultExecutorConfigSet { params: params.clone() }.publish(env);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// Sets default send ULN configurations for multiple destination endpoints.
|
|
97
|
+
#[only_owner]
|
|
98
|
+
fn set_default_send_uln_configs(env: &Env, params: &Vec<SetDefaultUlnConfigParam>) {
|
|
99
|
+
for param in params {
|
|
100
|
+
param.config.validate_default_config(env);
|
|
101
|
+
UlnStorage::set_default_send_uln_configs(env, param.dst_eid, ¶m.config);
|
|
102
|
+
}
|
|
103
|
+
DefaultUlnSendConfigSet { params: params.clone() }.publish(env);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ===== View Functions =====
|
|
107
|
+
|
|
108
|
+
/// Returns the treasury address for fee collection.
|
|
109
|
+
fn treasury(env: &Env) -> Address {
|
|
110
|
+
UlnStorage::treasury(env).unwrap()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Returns the default executor configuration for a destination endpoint.
|
|
114
|
+
fn default_executor_config(env: &Env, dst_eid: u32) -> Option<ExecutorConfig> {
|
|
115
|
+
UlnStorage::default_executor_configs(env, dst_eid)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Returns the OApp-specific executor configuration for a destination endpoint.
|
|
119
|
+
fn oapp_executor_config(env: &Env, sender: &Address, dst_eid: u32) -> Option<OAppExecutorConfig> {
|
|
120
|
+
UlnStorage::oapp_executor_configs(env, sender, dst_eid)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Returns the effective executor configuration by merging OApp config with default.
|
|
124
|
+
fn effective_executor_config(env: &Env, sender: &Address, dst_eid: u32) -> ExecutorConfig {
|
|
125
|
+
let default_config = Self::expect_default_executor_config(env, dst_eid);
|
|
126
|
+
let oapp_config = Self::oapp_executor_config(env, sender, dst_eid).unwrap_or_default();
|
|
127
|
+
|
|
128
|
+
oapp_config.apply_default_config(&default_config)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// Returns the default send ULN configuration for a destination endpoint.
|
|
132
|
+
fn default_send_uln_config(env: &Env, dst_eid: u32) -> Option<UlnConfig> {
|
|
133
|
+
UlnStorage::default_send_uln_configs(env, dst_eid)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// Returns the OApp-specific send ULN configuration for a destination endpoint.
|
|
137
|
+
fn oapp_send_uln_config(env: &Env, sender: &Address, dst_eid: u32) -> Option<OAppUlnConfig> {
|
|
138
|
+
UlnStorage::oapp_send_uln_configs(env, sender, dst_eid)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Returns the effective send ULN configuration by merging OApp config with default.
|
|
142
|
+
fn effective_send_uln_config(env: &Env, sender: &Address, dst_eid: u32) -> UlnConfig {
|
|
143
|
+
let default_config = Self::expect_default_send_uln_config(env, dst_eid);
|
|
144
|
+
let oapp_config = Self::oapp_send_uln_config(env, sender, dst_eid).unwrap_or(OAppUlnConfig::default(env));
|
|
145
|
+
|
|
146
|
+
let config = oapp_config.apply_default_config(&default_config);
|
|
147
|
+
config.validate_at_least_one_dvn(env); // validate the final config
|
|
148
|
+
|
|
149
|
+
config
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ==============================================================================
|
|
154
|
+
// Internal Functions
|
|
155
|
+
// ==============================================================================
|
|
156
|
+
|
|
157
|
+
impl Uln302 {
|
|
158
|
+
// === OApp Set Config Functions ===
|
|
159
|
+
|
|
160
|
+
/// Sets OApp-specific executor configuration for a destination endpoint.
|
|
161
|
+
///
|
|
162
|
+
/// # Arguments
|
|
163
|
+
/// * `sender` - The sender OApp address
|
|
164
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
165
|
+
/// * `config` - The OApp-specific executor configuration
|
|
166
|
+
fn set_executor_config(env: &Env, sender: &Address, dst_eid: u32, config: &OAppExecutorConfig) {
|
|
167
|
+
UlnStorage::set_oapp_executor_configs(env, sender, dst_eid, config);
|
|
168
|
+
ExecutorConfigSet { sender: sender.clone(), dst_eid, config: config.clone() }.publish(env);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Sets OApp-specific send ULN configuration for a destination endpoint.
|
|
172
|
+
///
|
|
173
|
+
/// # Arguments
|
|
174
|
+
/// * `sender` - The sender OApp address
|
|
175
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
176
|
+
/// * `config` - The OApp-specific send ULN configuration
|
|
177
|
+
///
|
|
178
|
+
/// # Panics
|
|
179
|
+
/// Panics if the final effective config is invalid.
|
|
180
|
+
fn set_send_uln_config(env: &Env, sender: &Address, dst_eid: u32, config: &OAppUlnConfig) {
|
|
181
|
+
config.validate_oapp_config(env);
|
|
182
|
+
|
|
183
|
+
UlnStorage::set_oapp_send_uln_configs(env, sender, dst_eid, config);
|
|
184
|
+
// validate the config by getting the effective config
|
|
185
|
+
let _ = Self::effective_send_uln_config(env, sender, dst_eid);
|
|
186
|
+
|
|
187
|
+
UlnSendConfigSet { sender: sender.clone(), dst_eid, config: config.clone() }.publish(env);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// === Quote Fee Functions ===
|
|
191
|
+
|
|
192
|
+
/// Quotes the executor fee for message execution.
|
|
193
|
+
///
|
|
194
|
+
/// # Arguments
|
|
195
|
+
/// * `sender` - The sender OApp address
|
|
196
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
197
|
+
/// * `message_length` - The length of the message
|
|
198
|
+
/// * `options` - The worker options
|
|
199
|
+
///
|
|
200
|
+
/// # Returns
|
|
201
|
+
/// The executor fee
|
|
202
|
+
fn quote_executor(env: &Env, sender: &Address, dst_eid: u32, message_length: u32, options: &Bytes) -> i128 {
|
|
203
|
+
let executor = Self::get_validated_executor_client(env, sender, dst_eid, message_length);
|
|
204
|
+
executor.get_fee(&env.current_contract_address(), sender, &dst_eid, &message_length, options)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/// Quotes the total DVN fees for message verification.
|
|
208
|
+
///
|
|
209
|
+
/// # Arguments
|
|
210
|
+
/// * `sender` - The sender OApp address
|
|
211
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
212
|
+
/// * `packet_header` - The raw packet header bytes
|
|
213
|
+
/// * `payload_hash` - The hash of the message payload
|
|
214
|
+
/// * `dvn_options` - The worker options for each DVN
|
|
215
|
+
///
|
|
216
|
+
/// # Returns
|
|
217
|
+
/// The total DVN fees
|
|
218
|
+
fn quote_dvns(
|
|
219
|
+
env: &Env,
|
|
220
|
+
sender: &Address,
|
|
221
|
+
dst_eid: u32,
|
|
222
|
+
packet_header: &Bytes,
|
|
223
|
+
payload_hash: &BytesN<32>,
|
|
224
|
+
dvn_options: &Map<u32, Bytes>,
|
|
225
|
+
) -> i128 {
|
|
226
|
+
let uln_config = Self::effective_send_uln_config(env, sender, dst_eid);
|
|
227
|
+
let send_lib = env.current_contract_address();
|
|
228
|
+
let confirmations = uln_config.confirmations;
|
|
229
|
+
|
|
230
|
+
let get_dvn_fee = |idx: usize, dvn_addr: Address| {
|
|
231
|
+
let dvn_client = LayerZeroDVNClient::new(env, &dvn_addr);
|
|
232
|
+
let dvn_opts = dvn_options.get(idx as u32).unwrap_or(bytes!(env));
|
|
233
|
+
dvn_client.get_fee(&send_lib, sender, &dst_eid, packet_header, payload_hash, &confirmations, &dvn_opts)
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
uln_config
|
|
237
|
+
.required_dvns
|
|
238
|
+
.iter()
|
|
239
|
+
.chain(uln_config.optional_dvns.iter())
|
|
240
|
+
.enumerate()
|
|
241
|
+
.fold(0_i128, |total_fee, (idx, dvn_addr)| total_fee + get_dvn_fee(idx, dvn_addr))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// === Assign Job Functions ===
|
|
245
|
+
|
|
246
|
+
/// Assigns an executor job and returns the fee recipient.
|
|
247
|
+
///
|
|
248
|
+
/// # Arguments
|
|
249
|
+
/// * `sender` - The sender OApp address
|
|
250
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
251
|
+
/// * `message_length` - The length of the message
|
|
252
|
+
/// * `options` - The worker options
|
|
253
|
+
///
|
|
254
|
+
/// # Returns
|
|
255
|
+
/// The fee recipient
|
|
256
|
+
fn assign_executor(
|
|
257
|
+
env: &Env,
|
|
258
|
+
sender: &Address,
|
|
259
|
+
dst_eid: u32,
|
|
260
|
+
message_length: u32,
|
|
261
|
+
options: &Bytes,
|
|
262
|
+
) -> FeeRecipient {
|
|
263
|
+
let executor = Self::get_validated_executor_client(env, sender, dst_eid, message_length);
|
|
264
|
+
let recipient =
|
|
265
|
+
executor.assign_job(&env.current_contract_address(), sender, &dst_eid, &message_length, options);
|
|
266
|
+
|
|
267
|
+
ExecutorFeePaid { executor: executor.address.clone(), fee: recipient.clone() }.publish(env);
|
|
268
|
+
recipient
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// Assigns DVN jobs and returns fee recipients for all DVNs.
|
|
272
|
+
///
|
|
273
|
+
/// # Arguments
|
|
274
|
+
/// * `sender` - The sender OApp address
|
|
275
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
276
|
+
/// * `packet_header` - The raw packet header bytes
|
|
277
|
+
/// * `payload_hash` - The hash of the message payload
|
|
278
|
+
/// * `dvn_options` - The worker options for each DVN
|
|
279
|
+
///
|
|
280
|
+
/// # Returns
|
|
281
|
+
/// The fee recipients for all DVNs
|
|
282
|
+
fn assign_dvns(
|
|
283
|
+
env: &Env,
|
|
284
|
+
sender: &Address,
|
|
285
|
+
dst_eid: u32,
|
|
286
|
+
packet_header: &Bytes,
|
|
287
|
+
payload_hash: &BytesN<32>,
|
|
288
|
+
dvn_options: &Map<u32, Bytes>,
|
|
289
|
+
) -> Vec<FeeRecipient> {
|
|
290
|
+
let uln_config = Self::effective_send_uln_config(env, sender, dst_eid);
|
|
291
|
+
let send_lib = env.current_contract_address();
|
|
292
|
+
let confirmations = uln_config.confirmations;
|
|
293
|
+
|
|
294
|
+
let assign_dvn_job = |idx: usize, dvn_addr: &Address| -> FeeRecipient {
|
|
295
|
+
let dvn_client = LayerZeroDVNClient::new(env, dvn_addr);
|
|
296
|
+
let dvn_opts = dvn_options.get(idx as u32).unwrap_or(bytes!(env));
|
|
297
|
+
dvn_client.assign_job(&send_lib, sender, &dst_eid, packet_header, payload_hash, &confirmations, &dvn_opts)
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
let (dvns, fees) = uln_config.required_dvns.iter().chain(uln_config.optional_dvns.iter()).enumerate().fold(
|
|
301
|
+
(vec![env], vec![env]),
|
|
302
|
+
|(mut dvns, mut fees), (idx, dvn_addr)| {
|
|
303
|
+
fees.push_back(assign_dvn_job(idx, &dvn_addr));
|
|
304
|
+
dvns.push_back(dvn_addr);
|
|
305
|
+
(dvns, fees)
|
|
306
|
+
},
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
DVNFeePaid { dvns, fees: fees.clone() }.publish(env);
|
|
310
|
+
fees
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// === Helper Functions ===
|
|
314
|
+
|
|
315
|
+
/// Gets a validated executor client, ensuring message size is within limits.
|
|
316
|
+
///
|
|
317
|
+
/// # Arguments
|
|
318
|
+
/// * `sender` - The sender OApp address
|
|
319
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
320
|
+
/// * `message_length` - The length of the message
|
|
321
|
+
///
|
|
322
|
+
/// # Returns
|
|
323
|
+
/// The executor client
|
|
324
|
+
fn get_validated_executor_client(
|
|
325
|
+
env: &Env,
|
|
326
|
+
sender: &Address,
|
|
327
|
+
dst_eid: u32,
|
|
328
|
+
message_length: u32,
|
|
329
|
+
) -> LayerZeroExecutorClient<'static> {
|
|
330
|
+
let executor_config = Self::effective_executor_config(env, sender, dst_eid);
|
|
331
|
+
assert_with_error!(env, message_length <= executor_config.max_message_size, Uln302Error::InvalidMessageSize);
|
|
332
|
+
LayerZeroExecutorClient::new(env, &executor_config.executor)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/// Returns the treasury client.
|
|
336
|
+
fn get_treasury_client(env: &Env) -> LayerZeroTreasuryClient<'static> {
|
|
337
|
+
LayerZeroTreasuryClient::new(env, &Self::treasury(env))
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/// Returns the default executor config or panics if not found.
|
|
341
|
+
fn expect_default_executor_config(env: &Env, dst_eid: u32) -> ExecutorConfig {
|
|
342
|
+
Self::default_executor_config(env, dst_eid).unwrap_or_panic(env, Uln302Error::DefaultExecutorConfigNotFound)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/// Returns the default send ULN config or panics if not found.
|
|
346
|
+
fn expect_default_send_uln_config(env: &Env, dst_eid: u32) -> UlnConfig {
|
|
347
|
+
Self::default_send_uln_config(env, dst_eid).unwrap_or_panic(env, Uln302Error::DefaultSendUlnConfigNotFound)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
use crate::interfaces::{ExecutorConfig, OAppExecutorConfig, OAppUlnConfig, UlnConfig};
|
|
2
|
+
use common_macros::storage;
|
|
3
|
+
use soroban_sdk::{Address, BytesN};
|
|
4
|
+
use utils::ttl::DefaultTtlConfigProvider;
|
|
5
|
+
|
|
6
|
+
/// Storage for the Uln302 message library.
|
|
7
|
+
#[storage(DefaultTtlConfigProvider)]
|
|
8
|
+
pub enum UlnStorage {
|
|
9
|
+
/// The endpoint address
|
|
10
|
+
#[instance(Address)]
|
|
11
|
+
Endpoint,
|
|
12
|
+
|
|
13
|
+
/// The treasury address
|
|
14
|
+
#[instance(Address)]
|
|
15
|
+
Treasury,
|
|
16
|
+
|
|
17
|
+
/// The default executor configurations for a destination endpoint
|
|
18
|
+
#[persistent(ExecutorConfig)]
|
|
19
|
+
DefaultExecutorConfigs { dst_eid: u32 },
|
|
20
|
+
|
|
21
|
+
/// The default send ULN configurations for a destination endpoint
|
|
22
|
+
#[persistent(UlnConfig)]
|
|
23
|
+
DefaultSendUlnConfigs { dst_eid: u32 },
|
|
24
|
+
|
|
25
|
+
/// The default receive ULN configurations for a source endpoint
|
|
26
|
+
#[persistent(UlnConfig)]
|
|
27
|
+
DefaultReceiveUlnConfigs { src_eid: u32 },
|
|
28
|
+
|
|
29
|
+
/// The OApp-specific send ULN configurations for a sender and destination endpoint
|
|
30
|
+
#[persistent(OAppUlnConfig)]
|
|
31
|
+
#[name("oapp_send_uln_configs")]
|
|
32
|
+
OAppSendUlnConfigs { sender: Address, dst_eid: u32 },
|
|
33
|
+
|
|
34
|
+
/// The OApp-specific receive ULN configurations for a receiver and source endpoint
|
|
35
|
+
#[persistent(OAppUlnConfig)]
|
|
36
|
+
#[name("oapp_receive_uln_configs")]
|
|
37
|
+
OAppReceiveUlnConfigs { receiver: Address, src_eid: u32 },
|
|
38
|
+
|
|
39
|
+
/// The OApp-specific executor configurations for a sender and destination endpoint
|
|
40
|
+
#[persistent(OAppExecutorConfig)]
|
|
41
|
+
#[name("oapp_executor_configs")]
|
|
42
|
+
OAppExecutorConfigs { sender: Address, dst_eid: u32 },
|
|
43
|
+
|
|
44
|
+
/// The confirmations for a DVN for a given header hash and payload hash
|
|
45
|
+
#[persistent(u64)]
|
|
46
|
+
Confirmations { dvn: Address, header_hash: BytesN<32>, payload_hash: BytesN<32> },
|
|
47
|
+
}
|