@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,117 @@
|
|
|
1
|
+
use crate::{
|
|
2
|
+
errors::Uln302Error,
|
|
3
|
+
events::{
|
|
4
|
+
DVNFeePaid, DefaultExecutorConfigSet, DefaultUlnReceiveConfigSet, DefaultUlnSendConfigSet, ExecutorConfigSet,
|
|
5
|
+
ExecutorFeePaid, PayloadVerified, UlnReceiveConfigSet, UlnSendConfigSet,
|
|
6
|
+
},
|
|
7
|
+
interfaces::{
|
|
8
|
+
ExecutorConfig, IReceiveUln302, ISendUln302, OAppExecutorConfig, OAppUlnConfig, SetDefaultExecutorConfigParam,
|
|
9
|
+
SetDefaultUlnConfigParam, UlnConfig,
|
|
10
|
+
},
|
|
11
|
+
storage::UlnStorage,
|
|
12
|
+
};
|
|
13
|
+
use common_macros::{only_owner, ttl_configurable};
|
|
14
|
+
use endpoint_v2::{
|
|
15
|
+
util, FeeRecipient, FeesAndPacket, IMessageLib, ISendLib, LayerZeroEndpointV2Client, MessageLibType,
|
|
16
|
+
MessageLibVersion, MessagingFee, Origin, OutboundPacket, SetConfigParam,
|
|
17
|
+
};
|
|
18
|
+
use message_lib_common::{
|
|
19
|
+
packet_codec_v1::{self, PacketHeader},
|
|
20
|
+
worker_options, LayerZeroDVNClient, LayerZeroExecutorClient, LayerZeroTreasuryClient,
|
|
21
|
+
};
|
|
22
|
+
use soroban_sdk::{
|
|
23
|
+
address_payload::AddressPayload,
|
|
24
|
+
assert_with_error, bytes, contract, contractimpl, panic_with_error, vec,
|
|
25
|
+
xdr::{FromXdr, ToXdr},
|
|
26
|
+
Address, Bytes, BytesN, Env, Map, Vec,
|
|
27
|
+
};
|
|
28
|
+
use utils::option_ext::OptionExt;
|
|
29
|
+
|
|
30
|
+
pub const CONFIG_TYPE_EXECUTOR: u32 = 1;
|
|
31
|
+
pub const CONFIG_TYPE_SEND_ULN: u32 = 2;
|
|
32
|
+
pub const CONFIG_TYPE_RECEIVE_ULN: u32 = 3;
|
|
33
|
+
|
|
34
|
+
#[contract]
|
|
35
|
+
#[ttl_configurable]
|
|
36
|
+
pub struct Uln302;
|
|
37
|
+
|
|
38
|
+
#[contractimpl]
|
|
39
|
+
impl Uln302 {
|
|
40
|
+
pub fn __constructor(env: &Env, owner: &Address, endpoint: &Address, treasury: &Address) {
|
|
41
|
+
Self::__init_owner(env, owner);
|
|
42
|
+
UlnStorage::set_endpoint(env, endpoint);
|
|
43
|
+
UlnStorage::set_treasury(env, treasury);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// === View Functions ===
|
|
47
|
+
|
|
48
|
+
/// Returns the LayerZero endpoint contract address.
|
|
49
|
+
pub fn endpoint(env: &Env) -> Address {
|
|
50
|
+
UlnStorage::endpoint(env).unwrap()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[contractimpl]
|
|
55
|
+
impl IMessageLib for Uln302 {
|
|
56
|
+
/// Sets OApp-specific configuration parameters for the message library.
|
|
57
|
+
///
|
|
58
|
+
/// Called by the endpoint on behalf of the OApp to configure executor and ULN settings.
|
|
59
|
+
/// Supports three config types: EXECUTOR, SEND_ULN, and RECEIVE_ULN.
|
|
60
|
+
fn set_config(env: &Env, oapp: &Address, params: &Vec<SetConfigParam>) {
|
|
61
|
+
Self::endpoint(env).require_auth();
|
|
62
|
+
|
|
63
|
+
for param in params {
|
|
64
|
+
assert_with_error!(env, Self::is_supported_eid(env, param.eid), Uln302Error::UnsupportedEid);
|
|
65
|
+
|
|
66
|
+
match param.config_type {
|
|
67
|
+
CONFIG_TYPE_EXECUTOR => {
|
|
68
|
+
Self::set_executor_config(env, oapp, param.eid, &parse_config(env, ¶m.config));
|
|
69
|
+
}
|
|
70
|
+
CONFIG_TYPE_SEND_ULN => {
|
|
71
|
+
Self::set_send_uln_config(env, oapp, param.eid, &parse_config(env, ¶m.config));
|
|
72
|
+
}
|
|
73
|
+
CONFIG_TYPE_RECEIVE_ULN => {
|
|
74
|
+
Self::set_receive_uln_config(env, oapp, param.eid, &parse_config(env, ¶m.config));
|
|
75
|
+
}
|
|
76
|
+
_ => panic_with_error!(env, Uln302Error::InvalidConfigType),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Returns the XDR-encoded effective configuration bytes.
|
|
82
|
+
fn get_config(env: &Env, eid: u32, oapp: &Address, config_type: u32) -> Bytes {
|
|
83
|
+
match config_type {
|
|
84
|
+
CONFIG_TYPE_EXECUTOR => Self::effective_executor_config(env, oapp, eid).to_xdr(env),
|
|
85
|
+
CONFIG_TYPE_SEND_ULN => Self::effective_send_uln_config(env, oapp, eid).to_xdr(env),
|
|
86
|
+
CONFIG_TYPE_RECEIVE_ULN => Self::effective_receive_uln_config(env, oapp, eid).to_xdr(env),
|
|
87
|
+
_ => panic_with_error!(env, Uln302Error::InvalidConfigType),
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Returns true if the message library has default send and receive ULN configurations for the endpoint ID.
|
|
92
|
+
fn is_supported_eid(env: &Env, eid: u32) -> bool {
|
|
93
|
+
UlnStorage::has_default_send_uln_configs(env, eid) && UlnStorage::has_default_receive_uln_configs(env, eid)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// Returns the version of the message library.
|
|
97
|
+
fn version(_env: &Env) -> MessageLibVersion {
|
|
98
|
+
MessageLibVersion { major: 3, minor: 0, endpoint_version: 2 }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Returns the type of the message library.
|
|
102
|
+
fn message_lib_type(_env: &Env) -> MessageLibType {
|
|
103
|
+
MessageLibType::SendAndReceive
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ================================================
|
|
108
|
+
// Helper Functions
|
|
109
|
+
// ================================================
|
|
110
|
+
|
|
111
|
+
/// Parse a config from XDR bytes, panicking with InvalidConfig error if parsing fails
|
|
112
|
+
fn parse_config<T: FromXdr>(env: &Env, config_bytes: &Bytes) -> T {
|
|
113
|
+
T::from_xdr(env, config_bytes).ok().unwrap_or_panic(env, Uln302Error::InvalidConfig)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
include!("send.rs");
|
|
117
|
+
include!("receive.rs");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "oapp-macros"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
publish = false
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
proc-macro = true
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
proc-macro2 = "1.0"
|
|
13
|
+
quote = "1.0"
|
|
14
|
+
syn = { version = "2.0", features = ["full", "extra-traits"] }
|
|
15
|
+
|
|
16
|
+
[dev-dependencies]
|
|
17
|
+
oapp = { workspace = true }
|
|
18
|
+
soroban-sdk = { workspace = true, features = ["testutils"] }
|
|
19
|
+
common-macros = { workspace = true }
|
|
20
|
+
utils = { workspace = true }
|
|
21
|
+
endpoint-v2 = { workspace = true , features = ["library"]}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
//! # OApp Procedural Macros
|
|
2
|
+
//!
|
|
3
|
+
//! This crate provides procedural macros for implementing LayerZero OApp (Omnichain Application)
|
|
4
|
+
//! functionality on Soroban smart contracts. These macros simplify the process of creating
|
|
5
|
+
//! cross-chain applications by automatically generating the necessary trait implementations.
|
|
6
|
+
//!
|
|
7
|
+
//! ## Overview
|
|
8
|
+
//!
|
|
9
|
+
//! The OApp framework consists of several core components:
|
|
10
|
+
//!
|
|
11
|
+
//! - **OAppCore**: Foundation for all OApp functionality, providing peer management and endpoint access
|
|
12
|
+
//! - **OAppSender**: Enables sending cross-chain messages through LayerZero
|
|
13
|
+
//! - **OAppReceiver**: Handles incoming cross-chain messages
|
|
14
|
+
//! - **OAppOptionsType3**: Manages enforced options for message execution parameters
|
|
15
|
+
//!
|
|
16
|
+
//! ## Available Macros
|
|
17
|
+
//!
|
|
18
|
+
//! ### `#[oapp]`
|
|
19
|
+
//! A convenience macro that combines Core + Sender + Receiver functionality. This is the most
|
|
20
|
+
//! common choice for cross-chain communication.
|
|
21
|
+
//!
|
|
22
|
+
//! ### `#[oapp_core]`
|
|
23
|
+
//! Derives only the core OApp functionality (peer management, endpoint access).
|
|
24
|
+
//!
|
|
25
|
+
//! ### `#[oapp_sender]`
|
|
26
|
+
//! Derives Core + Sender functionality for applications that only need to send messages.
|
|
27
|
+
//!
|
|
28
|
+
//! ### `#[oapp_receiver]`
|
|
29
|
+
//! Derives Core + Receiver functionality for applications that only need to receive messages.
|
|
30
|
+
//!
|
|
31
|
+
//! ### `#[oapp_options_type3]`
|
|
32
|
+
//! Derives the Options Type 3 functionality for managing enforced message options.
|
|
33
|
+
//! Can be combined with other macros.
|
|
34
|
+
//!
|
|
35
|
+
//! ### `#[oapp_manual_impl(...)]`
|
|
36
|
+
//! A marker attribute to indicate which trait implementations should be manually provided
|
|
37
|
+
//! by the user instead of using default implementations.
|
|
38
|
+
//!
|
|
39
|
+
//! ## Manual Implementation Control
|
|
40
|
+
//!
|
|
41
|
+
//! By default, macros generate default trait implementations. Use `#[oapp_manual_impl(...)]`
|
|
42
|
+
//! to customize specific behaviors:
|
|
43
|
+
//!
|
|
44
|
+
//! ```ignore
|
|
45
|
+
//! #[oapp_core]
|
|
46
|
+
//! #[oapp_manual_impl(core)]
|
|
47
|
+
//! struct MyOApp;
|
|
48
|
+
//!
|
|
49
|
+
//! impl OAppCoreOverrides for MyOApp {
|
|
50
|
+
//! fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
51
|
+
//! (1, 1) // Custom version
|
|
52
|
+
//! }
|
|
53
|
+
//! }
|
|
54
|
+
//! ```
|
|
55
|
+
//!
|
|
56
|
+
//! Supported options:
|
|
57
|
+
//! - `core` - Manually implement `OAppCoreOverrides`
|
|
58
|
+
//! - `sender` - Manually implement `OAppSenderOverrides`
|
|
59
|
+
//! - `options_type3` - Manually implement `OAppOptionsType3Overrides`
|
|
60
|
+
//!
|
|
61
|
+
//! **Note**: There is no `receiver` option because `OAppReceiverOverrides::__lz_receive`
|
|
62
|
+
//! **must always** be manually implemented by the user to define custom message handling logic.
|
|
63
|
+
//!
|
|
64
|
+
//! ## Examples
|
|
65
|
+
//!
|
|
66
|
+
//! ### Full OApp with Default Implementations
|
|
67
|
+
//!
|
|
68
|
+
//! ```ignore
|
|
69
|
+
//! use oapp_macros::oapp;
|
|
70
|
+
//! use oapp::oapp_receiver::OAppReceiverOverrides;
|
|
71
|
+
//!
|
|
72
|
+
//! #[oapp]
|
|
73
|
+
//! struct MyOApp;
|
|
74
|
+
//!
|
|
75
|
+
//! // Only __lz_receive must be implemented
|
|
76
|
+
//! impl OAppReceiverOverrides for MyOApp {
|
|
77
|
+
//! fn __lz_receive(
|
|
78
|
+
//! env: &Env,
|
|
79
|
+
//! executor: &Address,
|
|
80
|
+
//! origin: &Origin,
|
|
81
|
+
//! guid: &BytesN<32>,
|
|
82
|
+
//! message: &Bytes,
|
|
83
|
+
//! extra_data: &Bytes,
|
|
84
|
+
//! value: i128,
|
|
85
|
+
//! ) {
|
|
86
|
+
//! // Your custom message handling logic
|
|
87
|
+
//! }
|
|
88
|
+
//! }
|
|
89
|
+
//! ```
|
|
90
|
+
//!
|
|
91
|
+
//! ### Full OApp with Custom Core Implementation
|
|
92
|
+
//!
|
|
93
|
+
//! ```ignore
|
|
94
|
+
//! #[oapp]
|
|
95
|
+
//! #[oapp_manual_impl(core)]
|
|
96
|
+
//! struct MyCustomOApp;
|
|
97
|
+
//!
|
|
98
|
+
//! impl OAppCoreOverrides for MyCustomOApp {
|
|
99
|
+
//! fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
100
|
+
//! (2, 1) // Custom version
|
|
101
|
+
//! }
|
|
102
|
+
//! // Other methods use defaults
|
|
103
|
+
//! }
|
|
104
|
+
//!
|
|
105
|
+
//! impl OAppReceiverOverrides for MyCustomOApp {
|
|
106
|
+
//! fn __lz_receive(...) { /* ... */ }
|
|
107
|
+
//! }
|
|
108
|
+
//! ```
|
|
109
|
+
//!
|
|
110
|
+
//! ### Sender-Only OApp
|
|
111
|
+
//!
|
|
112
|
+
//! ```ignore
|
|
113
|
+
//! #[oapp_sender]
|
|
114
|
+
//! struct MySenderOApp;
|
|
115
|
+
//! // Uses all defaults, no manual implementation needed
|
|
116
|
+
//! ```
|
|
117
|
+
//!
|
|
118
|
+
//! ### OApp with Options Type 3
|
|
119
|
+
//!
|
|
120
|
+
//! ```ignore
|
|
121
|
+
//! #[oapp]
|
|
122
|
+
//! #[oapp_options_type3]
|
|
123
|
+
//! struct MyOAppWithOptions;
|
|
124
|
+
//!
|
|
125
|
+
//! impl OAppReceiverOverrides for MyOAppWithOptions {
|
|
126
|
+
//! fn __lz_receive(...) { /* ... */ }
|
|
127
|
+
//! }
|
|
128
|
+
//! // OAppOptionsType3Overrides uses defaults
|
|
129
|
+
//! ```
|
|
130
|
+
|
|
131
|
+
use crate::util::parse_struct;
|
|
132
|
+
use proc_macro::TokenStream;
|
|
133
|
+
|
|
134
|
+
mod oapp_core;
|
|
135
|
+
mod oapp_full;
|
|
136
|
+
mod oapp_options_type3;
|
|
137
|
+
mod oapp_receiver;
|
|
138
|
+
mod oapp_sender;
|
|
139
|
+
mod util;
|
|
140
|
+
|
|
141
|
+
/// Derives OAppCore implementation, providing the foundation for OApp functionality.
|
|
142
|
+
///
|
|
143
|
+
/// This macro generates:
|
|
144
|
+
/// - `#[soroban_sdk::contract]` attribute
|
|
145
|
+
/// - `#[common_macros::ownable]` attribute for ownership management
|
|
146
|
+
/// - Implementation of `OAppCore` trait with methods delegating to `OAppCoreOverrides`
|
|
147
|
+
///
|
|
148
|
+
/// By default, an empty `OAppCoreOverrides` implementation is generated. Use
|
|
149
|
+
/// `#[oapp_manual_impl(core)]` to provide custom implementations.
|
|
150
|
+
///
|
|
151
|
+
/// # Example
|
|
152
|
+
///
|
|
153
|
+
/// ```ignore
|
|
154
|
+
/// #[oapp_core]
|
|
155
|
+
/// struct MyOApp;
|
|
156
|
+
/// // Uses default OAppCore implementation
|
|
157
|
+
/// ```
|
|
158
|
+
///
|
|
159
|
+
/// # Example with Manual Implementation
|
|
160
|
+
///
|
|
161
|
+
/// ```ignore
|
|
162
|
+
/// #[oapp_core]
|
|
163
|
+
/// #[oapp_manual_impl(core)]
|
|
164
|
+
/// struct MyCustomOApp;
|
|
165
|
+
///
|
|
166
|
+
/// impl OAppCoreOverrides for MyCustomOApp {
|
|
167
|
+
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
168
|
+
/// (1, 2)
|
|
169
|
+
/// }
|
|
170
|
+
/// }
|
|
171
|
+
/// ```
|
|
172
|
+
#[proc_macro_attribute]
|
|
173
|
+
pub fn oapp_core(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
174
|
+
let (name, item, disable_config) = match parse_struct(item) {
|
|
175
|
+
Ok(result) => result,
|
|
176
|
+
Err(e) => return e,
|
|
177
|
+
};
|
|
178
|
+
oapp_core::generate_impl(&name, item, disable_config.core).into()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/// Derives OAppSender implementation, providing cross-chain message sending capabilities.
|
|
182
|
+
///
|
|
183
|
+
/// This macro automatically includes `#[oapp_core]` functionality, generating both
|
|
184
|
+
/// Core and Sender implementations. By default, an empty `OAppSenderOverrides`
|
|
185
|
+
/// implementation is generated. Use `#[oapp_manual_impl(sender)]` or
|
|
186
|
+
/// `#[oapp_manual_impl(core, sender)]` for custom implementations.
|
|
187
|
+
///
|
|
188
|
+
/// # Example
|
|
189
|
+
///
|
|
190
|
+
/// ```ignore
|
|
191
|
+
/// #[oapp_sender]
|
|
192
|
+
/// struct MySender;
|
|
193
|
+
/// // Can now send cross-chain messages using default implementations
|
|
194
|
+
/// ```
|
|
195
|
+
///
|
|
196
|
+
/// # Example with Manual Sender Implementation
|
|
197
|
+
///
|
|
198
|
+
/// ```ignore
|
|
199
|
+
/// #[oapp_sender]
|
|
200
|
+
/// #[oapp_manual_impl(sender)]
|
|
201
|
+
/// struct MyCustomSender;
|
|
202
|
+
///
|
|
203
|
+
/// impl OAppSenderOverrides for MyCustomSender {
|
|
204
|
+
/// // Custom sender logic
|
|
205
|
+
/// }
|
|
206
|
+
/// ```
|
|
207
|
+
#[proc_macro_attribute]
|
|
208
|
+
pub fn oapp_sender(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
209
|
+
let (name, item, disable_config) = match parse_struct(item) {
|
|
210
|
+
Ok(result) => result,
|
|
211
|
+
Err(e) => return e,
|
|
212
|
+
};
|
|
213
|
+
oapp_sender::generate_impl_with_core(&name, item, disable_config).into()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// Derives OAppReceiver implementation, providing receive capabilities
|
|
217
|
+
///
|
|
218
|
+
/// **Important**: Unlike other OApp macros, this macro does NOT support `manual_impl`
|
|
219
|
+
/// configuration because the `__lz_receive` method in `OAppReceiverOverrides` trait
|
|
220
|
+
/// has no default implementation. Users **MUST** always manually implement
|
|
221
|
+
/// `OAppReceiverOverrides::__lz_receive` to define their custom message handling logic.
|
|
222
|
+
///
|
|
223
|
+
/// # Example
|
|
224
|
+
/// ```ignore
|
|
225
|
+
/// #[oapp_receiver]
|
|
226
|
+
/// struct MyReceiver;
|
|
227
|
+
///
|
|
228
|
+
/// impl OAppReceiverOverrides for MyReceiver {
|
|
229
|
+
/// fn __lz_receive(
|
|
230
|
+
/// env: &Env,
|
|
231
|
+
/// executor: &Address,
|
|
232
|
+
/// origin: &Origin,
|
|
233
|
+
/// guid: &BytesN<32>,
|
|
234
|
+
/// message: &Bytes,
|
|
235
|
+
/// extra_data: &Bytes,
|
|
236
|
+
/// value: i128,
|
|
237
|
+
/// ) {
|
|
238
|
+
/// // Your custom message handling logic here
|
|
239
|
+
/// }
|
|
240
|
+
/// }
|
|
241
|
+
/// ```
|
|
242
|
+
#[proc_macro_attribute]
|
|
243
|
+
pub fn oapp_receiver(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
244
|
+
let (name, item, disable_config) = match parse_struct(item) {
|
|
245
|
+
Ok(result) => result,
|
|
246
|
+
Err(e) => return e,
|
|
247
|
+
};
|
|
248
|
+
oapp_receiver::generate_impl_with_core(&name, item, disable_config).into()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/// Derives a complete OApp implementation with Core + Sender + Receiver functionality.
|
|
252
|
+
///
|
|
253
|
+
/// This is a convenience macro that combines all three core OApp components. It's the
|
|
254
|
+
/// most common choice for applications that need full bidirectional cross-chain communication.
|
|
255
|
+
///
|
|
256
|
+
/// **Important**: You **must** always implement `OAppReceiverOverrides::__lz_receive` to
|
|
257
|
+
/// define your custom message handling logic, as it has no default implementation.
|
|
258
|
+
///
|
|
259
|
+
/// # Example
|
|
260
|
+
///
|
|
261
|
+
/// ```ignore
|
|
262
|
+
/// #[oapp]
|
|
263
|
+
/// struct MyFullOApp;
|
|
264
|
+
///
|
|
265
|
+
/// impl OAppReceiverOverrides for MyFullOApp {
|
|
266
|
+
/// fn __lz_receive(
|
|
267
|
+
/// env: &Env,
|
|
268
|
+
/// executor: &Address,
|
|
269
|
+
/// origin: &Origin,
|
|
270
|
+
/// guid: &BytesN<32>,
|
|
271
|
+
/// message: &Bytes,
|
|
272
|
+
/// extra_data: &Bytes,
|
|
273
|
+
/// value: i128,
|
|
274
|
+
/// ) {
|
|
275
|
+
/// // Your message handling logic here
|
|
276
|
+
/// }
|
|
277
|
+
/// }
|
|
278
|
+
/// ```
|
|
279
|
+
///
|
|
280
|
+
/// # Example with Manual Core Implementation
|
|
281
|
+
///
|
|
282
|
+
/// ```ignore
|
|
283
|
+
/// #[oapp]
|
|
284
|
+
/// #[oapp_manual_impl(core)]
|
|
285
|
+
/// struct MyCustomFullOApp;
|
|
286
|
+
///
|
|
287
|
+
/// impl OAppCoreOverrides for MyCustomFullOApp {
|
|
288
|
+
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
289
|
+
/// (2, 0)
|
|
290
|
+
/// }
|
|
291
|
+
/// }
|
|
292
|
+
///
|
|
293
|
+
/// impl OAppReceiverOverrides for MyCustomFullOApp {
|
|
294
|
+
/// fn __lz_receive(...) { /* ... */ }
|
|
295
|
+
/// }
|
|
296
|
+
/// ```
|
|
297
|
+
#[proc_macro_attribute]
|
|
298
|
+
pub fn oapp(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
299
|
+
let (name, item, disable_config) = match parse_struct(item) {
|
|
300
|
+
Ok(result) => result,
|
|
301
|
+
Err(e) => return e,
|
|
302
|
+
};
|
|
303
|
+
oapp_full::generate_impl(&name, item, disable_config).into()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/// Derives OAppOptionsType3 implementation for managing enforced message options.
|
|
307
|
+
///
|
|
308
|
+
/// This macro provides fine-grained control over message execution parameters per endpoint
|
|
309
|
+
/// and message type. Unlike other OApp macros, this does **not** automatically add the
|
|
310
|
+
/// `#[soroban_sdk::contract]` attribute, so it can be used standalone or combined with
|
|
311
|
+
/// other OApp macros.
|
|
312
|
+
///
|
|
313
|
+
/// By default, an empty `OAppOptionsType3Overrides` implementation is generated. Use
|
|
314
|
+
/// `#[oapp_manual_impl(options_type3)]` for custom implementations.
|
|
315
|
+
///
|
|
316
|
+
/// # Example - Standalone
|
|
317
|
+
///
|
|
318
|
+
/// ```ignore
|
|
319
|
+
/// #[contract]
|
|
320
|
+
/// #[ownable]
|
|
321
|
+
/// #[oapp_options_type3]
|
|
322
|
+
/// struct MyOptions;
|
|
323
|
+
/// // Uses default options implementation
|
|
324
|
+
/// ```
|
|
325
|
+
///
|
|
326
|
+
/// # Example - Combined with Full OApp
|
|
327
|
+
///
|
|
328
|
+
/// ```ignore
|
|
329
|
+
/// #[oapp]
|
|
330
|
+
/// #[oapp_options_type3]
|
|
331
|
+
/// struct MyOAppWithOptions;
|
|
332
|
+
///
|
|
333
|
+
/// impl OAppReceiverOverrides for MyOAppWithOptions {
|
|
334
|
+
/// fn __lz_receive(...) { /* ... */ }
|
|
335
|
+
/// }
|
|
336
|
+
/// ```
|
|
337
|
+
///
|
|
338
|
+
/// # Example with Manual Implementation
|
|
339
|
+
///
|
|
340
|
+
/// ```ignore
|
|
341
|
+
/// #[contract]
|
|
342
|
+
/// #[ownable]
|
|
343
|
+
/// #[oapp_options_type3]
|
|
344
|
+
/// #[oapp_manual_impl(options_type3)]
|
|
345
|
+
/// struct MyCustomOptions;
|
|
346
|
+
///
|
|
347
|
+
/// impl OAppOptionsType3Overrides for MyCustomOptions {
|
|
348
|
+
/// fn __enforced_options(env: &Env, eid: u32, msg_type: u32) -> Bytes {
|
|
349
|
+
/// // Custom enforced options logic
|
|
350
|
+
/// }
|
|
351
|
+
/// }
|
|
352
|
+
/// ```
|
|
353
|
+
#[proc_macro_attribute]
|
|
354
|
+
pub fn oapp_options_type3(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
355
|
+
let (name, item, disable_config) = match parse_struct(item) {
|
|
356
|
+
Ok(result) => result,
|
|
357
|
+
Err(e) => return e,
|
|
358
|
+
};
|
|
359
|
+
oapp_options_type3::generate_impl(&name, item, disable_config.options_type3).into()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/// Marker attribute to specify which trait implementations should be manually provided.
|
|
363
|
+
///
|
|
364
|
+
/// Use this attribute together with OApp macros to indicate that you will provide
|
|
365
|
+
/// custom implementations instead of using the default ones.
|
|
366
|
+
///
|
|
367
|
+
/// # Supported Options
|
|
368
|
+
///
|
|
369
|
+
/// - `core` - Manually implement `OAppCoreOverrides`
|
|
370
|
+
/// - `sender` - Manually implement `OAppSenderOverrides`
|
|
371
|
+
/// - `options_type3` - Manually implement `OAppOptionsType3Overrides`
|
|
372
|
+
///
|
|
373
|
+
/// **Note**: There is no `receiver` option because `OAppReceiverOverrides::__lz_receive`
|
|
374
|
+
/// must **always** be manually implemented (it has no default implementation).
|
|
375
|
+
///
|
|
376
|
+
/// # Examples
|
|
377
|
+
///
|
|
378
|
+
/// ```ignore
|
|
379
|
+
/// // Manual core implementation
|
|
380
|
+
/// #[oapp_core]
|
|
381
|
+
/// #[oapp_manual_impl(core)]
|
|
382
|
+
/// struct MyOApp;
|
|
383
|
+
///
|
|
384
|
+
/// impl OAppCoreOverrides for MyOApp {
|
|
385
|
+
/// fn __oapp_version(_env: &Env) -> (u64, u64) {
|
|
386
|
+
/// (1, 1)
|
|
387
|
+
/// }
|
|
388
|
+
/// }
|
|
389
|
+
/// ```
|
|
390
|
+
///
|
|
391
|
+
/// ```ignore
|
|
392
|
+
/// // Multiple manual implementations
|
|
393
|
+
/// #[oapp]
|
|
394
|
+
/// #[oapp_options_type3]
|
|
395
|
+
/// #[oapp_manual_impl(core, sender, options_type3)]
|
|
396
|
+
/// struct MyFullCustomOApp;
|
|
397
|
+
///
|
|
398
|
+
/// impl OAppCoreOverrides for MyFullCustomOApp { /* ... */ }
|
|
399
|
+
/// impl OAppSenderOverrides for MyFullCustomOApp { /* ... */ }
|
|
400
|
+
/// impl OAppReceiverOverrides for MyFullCustomOApp {
|
|
401
|
+
/// fn __lz_receive(...) { /* required */ }
|
|
402
|
+
/// }
|
|
403
|
+
/// impl OAppOptionsType3Overrides for MyFullCustomOApp { /* ... */ }
|
|
404
|
+
/// ```
|
|
405
|
+
#[proc_macro_attribute]
|
|
406
|
+
pub fn oapp_manual_impl(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
407
|
+
item
|
|
408
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
use proc_macro2::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{Ident, ItemStruct};
|
|
4
|
+
|
|
5
|
+
pub fn generate_impl(name: &Ident, item_struct: ItemStruct, manual_impl_core: bool) -> TokenStream {
|
|
6
|
+
let manual_impl = (!manual_impl_core).then(|| {
|
|
7
|
+
quote! {
|
|
8
|
+
use oapp::oapp_core::OAppCoreOverrides as _;
|
|
9
|
+
|
|
10
|
+
impl oapp::oapp_core::OAppCoreOverrides for #name {}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
quote! {
|
|
15
|
+
use oapp::oapp_core::OAppCore as _;
|
|
16
|
+
|
|
17
|
+
#[soroban_sdk::contract]
|
|
18
|
+
#[common_macros::ownable]
|
|
19
|
+
#item_struct
|
|
20
|
+
|
|
21
|
+
#[soroban_sdk::contractimpl]
|
|
22
|
+
impl oapp::oapp_core::OAppCore for #name {
|
|
23
|
+
#[common_macros::only_owner]
|
|
24
|
+
fn set_peer(env: &soroban_sdk::Env, eid: u32, peer: &Option<soroban_sdk::BytesN<32>>) {
|
|
25
|
+
<Self as oapp::oapp_core::OAppCoreOverrides>::__set_peer(env, eid, peer)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#[common_macros::only_owner]
|
|
29
|
+
fn set_delegate(env: &soroban_sdk::Env, delegate: &Option<soroban_sdk::Address>) {
|
|
30
|
+
<Self as oapp::oapp_core::OAppCoreOverrides>::__set_delegate(env, delegate)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn peer(env: &soroban_sdk::Env, eid: u32) -> Option<soroban_sdk::BytesN<32>> {
|
|
34
|
+
<Self as oapp::oapp_core::OAppCoreOverrides>::__peer(env, eid)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn oapp_version(env: &soroban_sdk::Env) -> (u64, u64) {
|
|
38
|
+
<Self as oapp::oapp_core::OAppCoreOverrides>::__oapp_version(env)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn endpoint(env: &soroban_sdk::Env) -> soroban_sdk::Address {
|
|
42
|
+
<Self as oapp::oapp_core::OAppCoreOverrides>::__endpoint(env)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#manual_impl
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
use crate::{oapp_core, oapp_receiver, oapp_sender, util::ManualImplConfig};
|
|
2
|
+
use proc_macro2::TokenStream;
|
|
3
|
+
use quote::quote;
|
|
4
|
+
use syn::{Ident, ItemStruct};
|
|
5
|
+
|
|
6
|
+
pub fn generate_impl(name: &Ident, item: ItemStruct, manual_impl_config: ManualImplConfig) -> TokenStream {
|
|
7
|
+
let core_impl = oapp_core::generate_impl(name, item, manual_impl_config.core);
|
|
8
|
+
let sender_impl = oapp_sender::generate_impl(name, manual_impl_config.sender);
|
|
9
|
+
let receiver_impl = oapp_receiver::generate_impl(name);
|
|
10
|
+
quote! {
|
|
11
|
+
#core_impl
|
|
12
|
+
#sender_impl
|
|
13
|
+
#receiver_impl
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
use proc_macro2::TokenStream;
|
|
2
|
+
use quote::quote;
|
|
3
|
+
use syn::{Ident, ItemStruct};
|
|
4
|
+
|
|
5
|
+
pub fn generate_impl(name: &Ident, item_struct: ItemStruct, manual_impl_options_type3: bool) -> TokenStream {
|
|
6
|
+
let manual_impl = (!manual_impl_options_type3).then(|| {
|
|
7
|
+
quote! {
|
|
8
|
+
use oapp::oapp_options_type3::OAppOptionsType3Overrides as _;
|
|
9
|
+
|
|
10
|
+
impl oapp::oapp_options_type3::OAppOptionsType3Overrides for #name {}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
quote! {
|
|
15
|
+
use oapp::oapp_options_type3::OAppOptionsType3 as _;
|
|
16
|
+
|
|
17
|
+
#item_struct
|
|
18
|
+
|
|
19
|
+
#[soroban_sdk::contractimpl]
|
|
20
|
+
impl oapp::oapp_options_type3::OAppOptionsType3 for #name
|
|
21
|
+
{
|
|
22
|
+
#[common_macros::only_owner]
|
|
23
|
+
fn set_enforced_options(
|
|
24
|
+
env: &soroban_sdk::Env,
|
|
25
|
+
options: soroban_sdk::Vec<oapp::oapp_options_type3::EnforcedOptionParam>,
|
|
26
|
+
) {
|
|
27
|
+
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__set_enforced_options(env, options)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fn combine_options(
|
|
31
|
+
env: &soroban_sdk::Env,
|
|
32
|
+
eid: u32,
|
|
33
|
+
msg_type: u32,
|
|
34
|
+
extra_options: &soroban_sdk::Bytes,
|
|
35
|
+
) -> soroban_sdk::Bytes {
|
|
36
|
+
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__combine_options(env, eid, msg_type, extra_options)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fn enforced_options(env: &soroban_sdk::Env, eid: u32, msg_type: u32) -> soroban_sdk::Bytes {
|
|
40
|
+
<Self as oapp::oapp_options_type3::OAppOptionsType3Overrides>::__enforced_options(env, eid, msg_type)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#manual_impl
|
|
45
|
+
}
|
|
46
|
+
}
|