@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +350 -309
- package/.turbo/turbo-lint.log +146 -108
- package/.turbo/turbo-test.log +1423 -1238
- package/Cargo.lock +12 -0
- package/Cargo.toml +3 -0
- package/contracts/ERROR_SPEC.md +44 -0
- package/contracts/common-macros/src/auth.rs +113 -0
- package/contracts/common-macros/src/contract_ttl.rs +84 -0
- package/contracts/common-macros/src/lib.rs +181 -30
- package/contracts/common-macros/src/lz_contract.rs +83 -0
- package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
- package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
- package/contracts/common-macros/src/tests/mod.rs +2 -2
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap → common_macros__tests__auth__snapshot_only_auth_preserves_function_signature.snap} +4 -4
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap → common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap} +3 -3
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
- package/contracts/common-macros/src/ttl_configurable.rs +19 -34
- package/contracts/common-macros/src/ttl_extendable.rs +36 -0
- package/contracts/common-macros/src/upgradeable.rs +5 -5
- package/contracts/common-macros/src/utils.rs +9 -0
- package/contracts/endpoint-v2/src/constants.rs +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +38 -40
- package/contracts/endpoint-v2/src/errors.rs +4 -3
- package/contracts/endpoint-v2/src/events.rs +1 -1
- package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
- package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
- package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
- package/contracts/endpoint-v2/src/storage.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
- package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
- package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
- package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +3 -3
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
- package/contracts/message-libs/treasury/src/errors.rs +2 -2
- package/contracts/message-libs/treasury/src/events.rs +1 -1
- package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
- package/contracts/message-libs/treasury/src/storage.rs +1 -1
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
- package/contracts/message-libs/treasury/src/treasury.rs +14 -16
- package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
- package/contracts/message-libs/uln-302/src/send_uln.rs +23 -3
- package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
- package/contracts/oapps/counter/Cargo.toml +14 -1
- package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
- package/contracts/oapps/counter/integration_tests/{setup.rs → setup_sml.rs} +48 -80
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
- package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
- package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
- package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
- package/contracts/oapps/counter/src/counter.rs +67 -43
- package/contracts/oapps/counter/src/tests/mod.rs +0 -13
- package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
- package/contracts/oapps/oapp/src/errors.rs +5 -1
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +93 -78
- package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
- package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
- package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
- package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
- package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
- package/contracts/oapps/oft/integration-tests/setup.rs +25 -7
- package/contracts/oapps/oft/src/errors.rs +6 -1
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +8 -8
- package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
- package/contracts/oapps/oft/src/lib.rs +4 -2
- package/contracts/oapps/oft/src/oft.rs +24 -64
- package/contracts/oapps/oft/src/oft_impl.rs +201 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -3
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -4
- package/contracts/oapps/oft/src/storage.rs +2 -0
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +36 -22
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +5 -3
- package/contracts/oapps/oft/src/tests/test_decimals.rs +2 -2
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +1 -2
- package/contracts/oapps/oft/src/tests/test_utils.rs +45 -23
- package/contracts/oapps/oft/src/types.rs +20 -0
- package/contracts/oapps/oft-std/integration-tests/setup.rs +4 -2
- package/contracts/oapps/oft-std/src/oft.rs +24 -6
- package/contracts/upgrader/src/lib.rs +4 -4
- package/contracts/utils/src/auth.rs +44 -0
- package/contracts/utils/src/errors.rs +27 -5
- package/contracts/utils/src/lib.rs +3 -0
- package/contracts/utils/src/multisig.rs +211 -0
- package/contracts/utils/src/ownable.rs +12 -10
- package/contracts/utils/src/tests/buffer_reader.rs +6 -6
- package/contracts/utils/src/tests/buffer_writer.rs +6 -6
- package/contracts/utils/src/tests/bytes_ext.rs +2 -4
- package/contracts/utils/src/tests/mod.rs +1 -0
- package/contracts/utils/src/tests/multisig.rs +731 -0
- package/contracts/utils/src/tests/option_ext.rs +2 -5
- package/contracts/utils/src/tests/ownable.rs +16 -5
- package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
- package/contracts/utils/src/tests/upgradeable.rs +4 -2
- package/contracts/utils/src/ttl_configurable.rs +23 -8
- package/contracts/utils/src/ttl_extendable.rs +27 -0
- package/contracts/utils/src/upgradeable.rs +2 -0
- package/contracts/workers/dvn/Cargo.toml +1 -1
- package/contracts/workers/dvn/src/auth.rs +7 -7
- package/contracts/workers/dvn/src/dvn.rs +10 -38
- package/contracts/workers/dvn/src/errors.rs +0 -7
- package/contracts/workers/dvn/src/events.rs +1 -14
- package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
- package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
- package/contracts/workers/dvn/src/storage.rs +3 -13
- package/contracts/workers/dvn/src/tests/auth.rs +4 -4
- package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
- package/contracts/workers/dvn/src/tests/setup.rs +5 -5
- package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
- package/contracts/workers/executor/src/auth.rs +80 -16
- package/contracts/workers/executor/src/executor.rs +5 -31
- package/contracts/workers/executor/src/storage.rs +2 -9
- package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +3 -6
- package/contracts/workers/executor-helper/Cargo.toml +1 -1
- package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
- package/contracts/workers/price-feed/Cargo.toml +1 -1
- package/contracts/workers/price-feed/src/price_feed.rs +7 -10
- package/contracts/workers/worker/src/errors.rs +4 -0
- package/contracts/workers/worker/src/tests/worker.rs +7 -6
- package/contracts/workers/worker/src/worker.rs +20 -16
- package/package.json +8 -5
- package/sdk/.turbo/turbo-build.log +1 -0
- package/sdk/.turbo/turbo-test.log +1009 -0
- package/sdk/dist/generated/bml.d.ts +65 -8
- package/sdk/dist/generated/bml.js +70 -34
- package/sdk/dist/generated/counter.d.ts +167 -42
- package/sdk/dist/generated/counter.js +86 -45
- package/sdk/dist/generated/dvn.d.ts +282 -229
- package/sdk/dist/generated/dvn.js +119 -81
- package/sdk/dist/generated/dvn_fee_lib.d.ts +142 -67
- package/sdk/dist/generated/dvn_fee_lib.js +64 -24
- package/sdk/dist/generated/endpoint.d.ts +97 -22
- package/sdk/dist/generated/endpoint.js +75 -37
- package/sdk/dist/generated/executor.d.ts +117 -85
- package/sdk/dist/generated/executor.js +102 -59
- package/sdk/dist/generated/executor_fee_lib.d.ts +162 -78
- package/sdk/dist/generated/executor_fee_lib.js +104 -57
- package/sdk/dist/generated/executor_helper.d.ts +133 -21
- package/sdk/dist/generated/executor_helper.js +99 -50
- package/sdk/dist/generated/oft_std.d.ts +233 -55
- package/sdk/dist/generated/oft_std.js +99 -54
- package/sdk/dist/generated/price_feed.d.ts +142 -67
- package/sdk/dist/generated/price_feed.js +64 -24
- package/sdk/dist/generated/sml.d.ts +113 -32
- package/sdk/dist/generated/sml.js +93 -49
- package/sdk/dist/generated/treasury.d.ts +896 -0
- package/sdk/dist/generated/treasury.js +219 -0
- package/sdk/dist/generated/uln302.d.ts +113 -32
- package/sdk/dist/generated/uln302.js +93 -49
- package/sdk/dist/generated/upgrader.d.ts +2 -2
- package/sdk/dist/generated/upgrader.js +1 -1
- package/sdk/dist/index.d.ts +2 -0
- package/sdk/dist/index.js +3 -0
- package/sdk/dist/wasm/blocked-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/blocked-message-lib.js +2 -0
- package/sdk/dist/wasm/counter.d.ts +1 -0
- package/sdk/dist/wasm/counter.js +2 -0
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/dvn-fee-lib.js +2 -0
- package/sdk/dist/wasm/dvn.d.ts +1 -0
- package/sdk/dist/wasm/dvn.js +2 -0
- package/sdk/dist/wasm/endpoint-v2.d.ts +1 -0
- package/sdk/dist/wasm/endpoint-v2.js +2 -0
- package/sdk/dist/wasm/executor-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/executor-fee-lib.js +2 -0
- package/sdk/dist/wasm/executor-helper.d.ts +1 -0
- package/sdk/dist/wasm/executor-helper.js +2 -0
- package/sdk/dist/wasm/executor.d.ts +1 -0
- package/sdk/dist/wasm/executor.js +2 -0
- package/sdk/dist/wasm/layerzero-views.d.ts +1 -0
- package/sdk/dist/wasm/layerzero-views.js +2 -0
- package/sdk/dist/wasm/oft-std.d.ts +1 -0
- package/sdk/dist/wasm/oft-std.js +2 -0
- package/sdk/dist/wasm/price-feed.d.ts +1 -0
- package/sdk/dist/wasm/price-feed.js +2 -0
- package/sdk/dist/wasm/simple-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/simple-message-lib.js +2 -0
- package/sdk/dist/wasm/treasury.d.ts +1 -0
- package/sdk/dist/wasm/treasury.js +2 -0
- package/sdk/dist/wasm/uln302.d.ts +1 -0
- package/sdk/dist/wasm/uln302.js +2 -0
- package/sdk/dist/wasm/upgrader.d.ts +1 -0
- package/sdk/dist/wasm/upgrader.js +2 -0
- package/sdk/dist/wasm.d.ts +15 -0
- package/sdk/dist/wasm.js +15 -0
- package/sdk/package.json +4 -2
- package/sdk/src/index.ts +4 -0
- package/sdk/test/counter-sml.test.ts +376 -0
- package/sdk/test/counter-uln.test.ts +493 -0
- package/sdk/test/{oft.test.ts → oft-sml.test.ts} +185 -310
- package/sdk/test/suites/constants.ts +22 -2
- package/sdk/test/suites/globalSetup.ts +450 -0
- package/sdk/test/suites/localnet.ts +23 -6
- package/sdk/test/upgrader.test.ts +7 -16
- package/sdk/test/utils.ts +558 -85
- package/sdk/vitest.config.ts +21 -0
- package/tools/ts-bindings-gen/src/main.rs +1 -0
- package/turbo.json +2 -0
- package/contracts/common-macros/src/contract_impl.rs +0 -52
- package/contracts/common-macros/src/ownable.rs +0 -41
- package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
- package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
- package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
- package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
- package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
- package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
- package/contracts/oapps/oapp-macros/src/util.rs +0 -107
- package/contracts/oapps/oft/src/constants.rs +0 -5
- package/contracts/oapps/oft/src/default_oft_impl.rs +0 -152
- package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
- package/contracts/workers/dvn/src/multisig.rs +0 -157
- package/sdk/test/index.test.ts +0 -375
- /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
//!
|
|
9
9
|
//! ```ignore
|
|
10
10
|
//! use oapp_macros::{oapp, oapp_options_type3};
|
|
11
|
-
//! use oft::oft::{
|
|
11
|
+
//! use oft::oft::{OFTInternal, OFT};
|
|
12
|
+
//! use oft::initialize_oft;
|
|
12
13
|
//!
|
|
13
14
|
//! #[oapp]
|
|
14
15
|
//! pub struct MyOFT;
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
//! #[contractimpl]
|
|
17
18
|
//! impl MyOFT {
|
|
18
19
|
//! pub fn __constructor(env: &Env, token: &Address, owner: &Address, endpoint: &Address, delegate: &Option<Address>) {
|
|
19
|
-
//!
|
|
20
|
+
//! initialize_oft::<Self>(env, owner, token, endpoint, delegate)
|
|
20
21
|
//! }
|
|
21
22
|
//! }
|
|
22
23
|
//!
|
|
@@ -43,41 +44,13 @@
|
|
|
43
44
|
// inside this crate and in external crates implementing the OFT trait.
|
|
44
45
|
extern crate self as oft;
|
|
45
46
|
|
|
46
|
-
use crate::{
|
|
47
|
-
use
|
|
47
|
+
use crate::{oft_impl, storage::OFTStorage, types::OFTReceipt};
|
|
48
|
+
use common_macros::contract_trait;
|
|
48
49
|
use oapp::{
|
|
49
|
-
oapp_core::
|
|
50
|
-
|
|
51
|
-
oapp_receiver::OAppReceiver,
|
|
52
|
-
oapp_sender::OAppSender,
|
|
50
|
+
oapp_core::OAppCore, oapp_options_type3::OAppOptionsType3, oapp_receiver::OAppReceiver,
|
|
51
|
+
oapp_sender::OAppSenderInternal,
|
|
53
52
|
};
|
|
54
|
-
use soroban_sdk::{
|
|
55
|
-
use utils::ownable::OwnableInitializer;
|
|
56
|
-
|
|
57
|
-
// =====================================================
|
|
58
|
-
// OFT Initialization
|
|
59
|
-
// =====================================================
|
|
60
|
-
|
|
61
|
-
/// Initializes the OFT contract with token, endpoint, and decimal configuration.
|
|
62
|
-
/// The `shared_decimals` must be <= token's local decimals.
|
|
63
|
-
pub fn oft_initialize<T: OFT + OwnableInitializer>(
|
|
64
|
-
env: &Env,
|
|
65
|
-
owner: &Address,
|
|
66
|
-
token: &Address,
|
|
67
|
-
endpoint: &Address,
|
|
68
|
-
delegate: &Option<Address>,
|
|
69
|
-
shared_decimals: u32,
|
|
70
|
-
) {
|
|
71
|
-
// Initialize OApp (includes owner initialization)
|
|
72
|
-
oapp_initialize::<T>(env, owner, endpoint, delegate);
|
|
73
|
-
|
|
74
|
-
let local_decimals = TokenClient::new(env, token).decimals();
|
|
75
|
-
assert_with_error!(env, local_decimals >= shared_decimals, OFTError::InvalidLocalDecimals);
|
|
76
|
-
|
|
77
|
-
// Initialize OFT storage
|
|
78
|
-
OFTStorage::set_token(env, token);
|
|
79
|
-
OFTStorage::set_decimal_conversion_rate(env, &10_i128.pow(local_decimals - shared_decimals));
|
|
80
|
-
}
|
|
53
|
+
use soroban_sdk::{Address, Bytes, Env};
|
|
81
54
|
|
|
82
55
|
// =====================================================
|
|
83
56
|
// OFTInternal Trait (NOT exposed as contract endpoints)
|
|
@@ -106,17 +79,17 @@ pub trait OFTInternal: OAppCore {
|
|
|
106
79
|
// Required Methods (no defaults - user MUST implement)
|
|
107
80
|
// =========================================================================
|
|
108
81
|
|
|
109
|
-
/// Debits tokens from
|
|
82
|
+
/// Debits tokens from the specified address for cross-chain transfer.
|
|
110
83
|
///
|
|
111
84
|
/// # Arguments
|
|
112
|
-
/// * `
|
|
113
|
-
/// * `amount_ld` -
|
|
114
|
-
/// * `min_amount_ld` -
|
|
115
|
-
/// * `dst_eid` -
|
|
85
|
+
/// * `from` - The address to debit the tokens from
|
|
86
|
+
/// * `amount_ld` - The amount of tokens to send in local decimals
|
|
87
|
+
/// * `min_amount_ld` - The minimum amount to send in local decimals
|
|
88
|
+
/// * `dst_eid` - The destination chain ID
|
|
116
89
|
///
|
|
117
90
|
/// # Returns
|
|
118
|
-
///
|
|
119
|
-
fn __debit(env: &Env,
|
|
91
|
+
/// `OFTReceipt` containing the amount sent and amount received
|
|
92
|
+
fn __debit(env: &Env, from: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt;
|
|
120
93
|
|
|
121
94
|
/// Credits tokens to recipient after receiving cross-chain transfer.
|
|
122
95
|
///
|
|
@@ -135,33 +108,20 @@ pub trait OFTInternal: OAppCore {
|
|
|
135
108
|
|
|
136
109
|
/// Calculates debit amounts without executing (view function).
|
|
137
110
|
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
138
|
-
|
|
111
|
+
oft_impl::debit_view(env, amount_ld, min_amount_ld, dst_eid)
|
|
139
112
|
}
|
|
140
113
|
|
|
141
114
|
/// Builds OFT message and combines options for cross-chain transfer.
|
|
142
115
|
fn __build_msg_and_options(
|
|
143
116
|
env: &Env,
|
|
144
|
-
|
|
117
|
+
from: &Address,
|
|
145
118
|
send_param: &oft::types::SendParam,
|
|
146
|
-
|
|
119
|
+
receive_amount_ld: i128,
|
|
147
120
|
) -> (Bytes, Bytes)
|
|
148
121
|
where
|
|
149
122
|
Self: OAppOptionsType3,
|
|
150
123
|
{
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/// Handles OFT receive logic.
|
|
155
|
-
fn __lz_receive(
|
|
156
|
-
env: &Env,
|
|
157
|
-
_executor: &Address,
|
|
158
|
-
origin: &Origin,
|
|
159
|
-
guid: &BytesN<32>,
|
|
160
|
-
message: &Bytes,
|
|
161
|
-
_extra_data: &Bytes,
|
|
162
|
-
_value: i128,
|
|
163
|
-
) {
|
|
164
|
-
crate::default_oft_impl::default_lz_receive::<Self>(env, _executor, origin, guid, message, _extra_data, _value)
|
|
124
|
+
oft_impl::build_msg_and_options::<Self>(env, from, send_param, receive_amount_ld)
|
|
165
125
|
}
|
|
166
126
|
}
|
|
167
127
|
|
|
@@ -176,8 +136,8 @@ pub trait OFTInternal: OAppCore {
|
|
|
176
136
|
///
|
|
177
137
|
/// Internal methods like `__debit`, `__credit`, `__debit_view`, and `__build_msg_and_options`
|
|
178
138
|
/// are in the `OFTInternal` trait and are NOT exposed as contract endpoints.
|
|
179
|
-
#[
|
|
180
|
-
pub trait OFT: OFTInternal + OAppReceiver +
|
|
139
|
+
#[contract_trait]
|
|
140
|
+
pub trait OFT: OFTInternal + OAppReceiver + OAppSenderInternal + OAppOptionsType3 {
|
|
181
141
|
/// Retrieves the token address associated with this OFT.
|
|
182
142
|
fn token(env: &Env) -> Address {
|
|
183
143
|
OFTStorage::token(env).unwrap()
|
|
@@ -220,7 +180,7 @@ pub trait OFT: OFTInternal + OAppReceiver + OAppSender + OAppOptionsType3 {
|
|
|
220
180
|
env: &Env,
|
|
221
181
|
send_param: &oft::types::SendParam,
|
|
222
182
|
) -> (oft::types::OFTLimit, soroban_sdk::Vec<oft::types::OFTFeeDetail>, oft::types::OFTReceipt) {
|
|
223
|
-
|
|
183
|
+
oft_impl::quote_oft::<Self>(env, send_param)
|
|
224
184
|
}
|
|
225
185
|
|
|
226
186
|
/// Quotes a send operation including LayerZero messaging fees.
|
|
@@ -230,7 +190,7 @@ pub trait OFT: OFTInternal + OAppReceiver + OAppSender + OAppOptionsType3 {
|
|
|
230
190
|
send_param: &oft::types::SendParam,
|
|
231
191
|
pay_in_zro: bool,
|
|
232
192
|
) -> endpoint_v2::MessagingFee {
|
|
233
|
-
|
|
193
|
+
oft_impl::quote_send::<Self>(env, sender, send_param, pay_in_zro)
|
|
234
194
|
}
|
|
235
195
|
|
|
236
196
|
/// Sends tokens cross-chain to another endpoint.
|
|
@@ -246,6 +206,6 @@ pub trait OFT: OFTInternal + OAppReceiver + OAppSender + OAppOptionsType3 {
|
|
|
246
206
|
fee: &endpoint_v2::MessagingFee,
|
|
247
207
|
refund_address: &Address,
|
|
248
208
|
) -> (endpoint_v2::MessagingReceipt, oft::types::OFTReceipt) {
|
|
249
|
-
|
|
209
|
+
oft_impl::send::<Self>(env, sender, send_param, fee, refund_address)
|
|
250
210
|
}
|
|
251
211
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
//! Default OFT implementations.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides default standalone functions for common OFT operations that can be
|
|
4
|
+
//! reused by trait implementations.
|
|
5
|
+
|
|
6
|
+
use crate::{
|
|
7
|
+
codec::{oft_compose_msg_codec::OFTComposeMsg, oft_msg_codec::OFTMessage},
|
|
8
|
+
errors::OFTError,
|
|
9
|
+
events::{self, OFTSent},
|
|
10
|
+
oft::{OFTInternal, OFT},
|
|
11
|
+
storage::OFTStorage,
|
|
12
|
+
types::{self, OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
13
|
+
utils,
|
|
14
|
+
};
|
|
15
|
+
use ::utils::{option_ext::OptionExt, ownable::OwnableInitializer};
|
|
16
|
+
use endpoint_v2::{MessagingComposerClient, MessagingFee, MessagingReceipt, Origin};
|
|
17
|
+
use oapp::{oapp_core::initialize_oapp, oapp_options_type3::OAppOptionsType3};
|
|
18
|
+
use soroban_sdk::{assert_with_error, token::TokenClient, vec, Address, Bytes, BytesN, Env, Vec};
|
|
19
|
+
|
|
20
|
+
/// Initializes the OFT contract with token, endpoint, and decimal configuration.
|
|
21
|
+
/// The `shared_decimals` must be <= token's local decimals.
|
|
22
|
+
pub fn initialize_oft<T: OFT + OwnableInitializer>(
|
|
23
|
+
env: &Env,
|
|
24
|
+
owner: &Address,
|
|
25
|
+
token: &Address,
|
|
26
|
+
endpoint: &Address,
|
|
27
|
+
delegate: &Option<Address>,
|
|
28
|
+
shared_decimals: u32,
|
|
29
|
+
) {
|
|
30
|
+
// Initialize OApp (includes owner initialization)
|
|
31
|
+
initialize_oapp::<T>(env, owner, endpoint, delegate);
|
|
32
|
+
|
|
33
|
+
let local_decimals = TokenClient::new(env, token).decimals();
|
|
34
|
+
assert_with_error!(env, local_decimals >= shared_decimals, OFTError::InvalidLocalDecimals);
|
|
35
|
+
|
|
36
|
+
// Initialize OFT storage
|
|
37
|
+
OFTStorage::set_token(env, token);
|
|
38
|
+
OFTStorage::set_decimal_conversion_rate(env, &10_i128.pow(local_decimals - shared_decimals));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Simulates a debit operation without executing, used for quoting.
|
|
42
|
+
///
|
|
43
|
+
/// # Arguments
|
|
44
|
+
/// * `amount_ld` - The amount of tokens to send in local decimals
|
|
45
|
+
/// * `min_amount_ld` - The minimum amount to send in local decimals (slippage protection)
|
|
46
|
+
/// * `dst_eid` - The destination chain ID (unused in default implementation)
|
|
47
|
+
///
|
|
48
|
+
/// # Returns
|
|
49
|
+
/// `OFTReceipt` containing the amount sent and amount received after dust removal
|
|
50
|
+
pub fn debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, _dst_eid: u32) -> OFTReceipt {
|
|
51
|
+
let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
|
|
52
|
+
let amount_sent_ld = utils::remove_dust(amount_ld, conversion_rate);
|
|
53
|
+
let amount_received_ld = amount_sent_ld;
|
|
54
|
+
|
|
55
|
+
assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
|
|
56
|
+
|
|
57
|
+
OFTReceipt { amount_sent_ld, amount_received_ld }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Builds the OFT message payload and combines enforced options for cross-chain transfer.
|
|
61
|
+
///
|
|
62
|
+
/// # Arguments
|
|
63
|
+
/// * `from` - The address initiating the transfer
|
|
64
|
+
/// * `send_param` - The send parameters including destination, recipient, and options
|
|
65
|
+
/// * `receive_amount_ld` - The amount to be received in local decimals (after dust removal)
|
|
66
|
+
///
|
|
67
|
+
/// # Returns
|
|
68
|
+
/// A tuple of (encoded message, combined options)
|
|
69
|
+
pub fn build_msg_and_options<T: OAppOptionsType3>(
|
|
70
|
+
env: &Env,
|
|
71
|
+
from: &Address,
|
|
72
|
+
send_param: &SendParam,
|
|
73
|
+
receive_amount_ld: i128,
|
|
74
|
+
) -> (Bytes, Bytes) {
|
|
75
|
+
let has_compose = !send_param.compose_msg.is_empty();
|
|
76
|
+
let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
|
|
77
|
+
let (msg, _) = OFTMessage {
|
|
78
|
+
send_to: send_param.to.clone(),
|
|
79
|
+
amount_sd: utils::to_sd(env, receive_amount_ld, conversion_rate),
|
|
80
|
+
compose_from: if has_compose { Some(utils::address_to_bytes32(from)) } else { None },
|
|
81
|
+
compose_msg: if has_compose { Some(send_param.compose_msg.clone()) } else { None },
|
|
82
|
+
}
|
|
83
|
+
.encode(env);
|
|
84
|
+
let msg_type = if has_compose { types::SEND_AND_CALL } else { types::SEND };
|
|
85
|
+
|
|
86
|
+
(msg, T::combine_options(env, send_param.dst_eid, msg_type, &send_param.extra_options))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// Quotes an OFT transfer without executing.
|
|
90
|
+
///
|
|
91
|
+
/// # Arguments
|
|
92
|
+
/// * `send_param` - The send parameters to quote
|
|
93
|
+
///
|
|
94
|
+
/// # Returns
|
|
95
|
+
/// A tuple of (transfer limits, fee details, estimated receipt)
|
|
96
|
+
pub fn quote_oft<T: OFTInternal>(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
97
|
+
let limit = OFTLimit { min_amount_ld: 0, max_amount_ld: i128::MAX }; // No limits in default implementation
|
|
98
|
+
let fee_details = vec![env]; // No fee details in default implementation
|
|
99
|
+
let oft_receipt = T::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
|
|
100
|
+
(limit, fee_details, oft_receipt)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Quotes the LayerZero messaging fee for a send operation.
|
|
104
|
+
///
|
|
105
|
+
/// # Arguments
|
|
106
|
+
/// * `from` - The address initiating the transfer
|
|
107
|
+
/// * `send_param` - The send parameters to quote
|
|
108
|
+
/// * `pay_in_zro` - Whether to pay the fee in ZRO token
|
|
109
|
+
///
|
|
110
|
+
/// # Returns
|
|
111
|
+
/// The messaging fee required for the transfer
|
|
112
|
+
pub fn quote_send<T: OFT>(env: &Env, from: &Address, send_param: &SendParam, pay_in_zro: bool) -> MessagingFee {
|
|
113
|
+
let OFTReceipt { amount_received_ld, .. } =
|
|
114
|
+
T::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
|
|
115
|
+
|
|
116
|
+
let (msg, options) = build_msg_and_options::<T>(env, from, send_param, amount_received_ld);
|
|
117
|
+
T::__quote(env, send_param.dst_eid, &msg, &options, pay_in_zro)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// Executes a cross-chain token transfer via LayerZero.
|
|
121
|
+
///
|
|
122
|
+
/// Debits tokens from the `from` address, builds the message, and sends via the endpoint.
|
|
123
|
+
/// The `from` address must be authenticated.
|
|
124
|
+
///
|
|
125
|
+
/// # Arguments
|
|
126
|
+
/// * `from` - The address sending tokens (must authorize)
|
|
127
|
+
/// * `send_param` - The send parameters (destination, recipient, amount, options)
|
|
128
|
+
/// * `fee` - The messaging fee to pay
|
|
129
|
+
/// * `refund_address` - The address to refund excess fees to
|
|
130
|
+
///
|
|
131
|
+
/// # Returns
|
|
132
|
+
/// A tuple of (messaging receipt, OFT receipt with amounts)
|
|
133
|
+
pub fn send<T: OFT>(
|
|
134
|
+
env: &Env,
|
|
135
|
+
from: &Address,
|
|
136
|
+
send_param: &SendParam,
|
|
137
|
+
fee: &MessagingFee,
|
|
138
|
+
refund_address: &Address,
|
|
139
|
+
) -> (MessagingReceipt, OFTReceipt) {
|
|
140
|
+
from.require_auth();
|
|
141
|
+
|
|
142
|
+
let oft_receipt = T::__debit(env, from, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
|
|
143
|
+
|
|
144
|
+
let (msg, options) = build_msg_and_options::<T>(env, from, send_param, oft_receipt.amount_received_ld);
|
|
145
|
+
let msg_receipt = T::__lz_send(env, send_param.dst_eid, &msg, &options, from, fee, refund_address);
|
|
146
|
+
|
|
147
|
+
OFTSent {
|
|
148
|
+
guid: msg_receipt.guid.clone(),
|
|
149
|
+
dst_eid: send_param.dst_eid,
|
|
150
|
+
from: from.clone(),
|
|
151
|
+
amount_sent_ld: oft_receipt.amount_sent_ld,
|
|
152
|
+
amount_received_ld: oft_receipt.amount_received_ld,
|
|
153
|
+
}
|
|
154
|
+
.publish(env);
|
|
155
|
+
|
|
156
|
+
(msg_receipt, oft_receipt)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Handles incoming cross-chain OFT transfer from LayerZero endpoint.
|
|
160
|
+
///
|
|
161
|
+
/// Credits tokens to the recipient and optionally queues a compose message.
|
|
162
|
+
///
|
|
163
|
+
/// # Arguments
|
|
164
|
+
/// * `executor` - The address of the executor handling the message (unused in default implementation)
|
|
165
|
+
/// * `origin` - The origin information (source chain, sender, nonce)
|
|
166
|
+
/// * `guid` - The unique message identifier
|
|
167
|
+
/// * `message` - The encoded OFT message payload
|
|
168
|
+
/// * `extra_data` - Additional data (unused in default implementation)
|
|
169
|
+
/// * `value` - The native token value sent with the message (unused in default implementation)
|
|
170
|
+
pub fn lz_receive<T: OFTInternal>(
|
|
171
|
+
env: &Env,
|
|
172
|
+
_executor: &Address,
|
|
173
|
+
origin: &Origin,
|
|
174
|
+
guid: &BytesN<32>,
|
|
175
|
+
message: &Bytes,
|
|
176
|
+
_extra_data: &Bytes,
|
|
177
|
+
_value: i128,
|
|
178
|
+
) {
|
|
179
|
+
let oft_msg = OFTMessage::decode(message);
|
|
180
|
+
let send_to = utils::resolve_address(env, &oft_msg.send_to);
|
|
181
|
+
|
|
182
|
+
let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap_or_panic(env, OFTError::NotInitialized);
|
|
183
|
+
let amount_received_ld =
|
|
184
|
+
T::__credit(env, &send_to, utils::to_ld(oft_msg.amount_sd, conversion_rate), origin.src_eid);
|
|
185
|
+
|
|
186
|
+
if oft_msg.is_composed() {
|
|
187
|
+
let compose_msg = OFTComposeMsg {
|
|
188
|
+
nonce: origin.nonce,
|
|
189
|
+
src_eid: origin.src_eid,
|
|
190
|
+
amount_ld: amount_received_ld,
|
|
191
|
+
compose_from: oft_msg.compose_from.unwrap(),
|
|
192
|
+
compose_msg: oft_msg.compose_msg.unwrap(),
|
|
193
|
+
}
|
|
194
|
+
.encode(env);
|
|
195
|
+
|
|
196
|
+
let endpoint_client = MessagingComposerClient::new(env, &T::endpoint(env));
|
|
197
|
+
endpoint_client.send_compose(&env.current_contract_address(), &send_to, guid, &0, &compose_msg);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
events::OFTReceived { guid: guid.clone(), src_eid: origin.src_eid, to: send_to, amount_received_ld }.publish(env);
|
|
201
|
+
}
|
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
//! tokens from the contract on credit (receive).
|
|
5
5
|
//! Used for OFT adapters that wrap existing tokens.
|
|
6
6
|
|
|
7
|
+
use crate::{oft::OFT, types::OFTReceipt};
|
|
7
8
|
use soroban_sdk::{token::TokenClient, Address, Env};
|
|
8
9
|
|
|
9
|
-
use crate::oft::OFT;
|
|
10
|
-
use crate::types::OFTReceipt;
|
|
11
|
-
|
|
12
10
|
/// Debit tokens using LockUnlock OFT type (locks tokens in contract).
|
|
13
11
|
///
|
|
14
12
|
/// # Parameters
|
|
@@ -3,12 +3,9 @@
|
|
|
3
3
|
//! This OFT type burns tokens on debit (send) and mints tokens on credit (receive).
|
|
4
4
|
//! Used when the OFT contract has mint/burn authority over the token.
|
|
5
5
|
|
|
6
|
+
use crate::{interfaces::MintBurnTokenClient, oft::OFT, types::OFTReceipt};
|
|
6
7
|
use soroban_sdk::{Address, Env};
|
|
7
8
|
|
|
8
|
-
use crate::interfaces::MintBurnTokenClient;
|
|
9
|
-
use crate::oft::OFT;
|
|
10
|
-
use crate::types::OFTReceipt;
|
|
11
|
-
|
|
12
9
|
/// Debit tokens using MintBurn OFT type (burns tokens from sender).
|
|
13
10
|
///
|
|
14
11
|
/// # Parameters
|
|
@@ -3,9 +3,11 @@ use soroban_sdk::Address;
|
|
|
3
3
|
|
|
4
4
|
#[storage]
|
|
5
5
|
pub enum OFTStorage {
|
|
6
|
+
/// The decimal conversion rate used for cross-chain normalization
|
|
6
7
|
#[instance(i128)]
|
|
7
8
|
DecimalConversionRate,
|
|
8
9
|
|
|
10
|
+
/// The address of the underlying token contract
|
|
9
11
|
#[instance(Address)]
|
|
10
12
|
Token,
|
|
11
13
|
}
|
|
@@ -5,21 +5,26 @@
|
|
|
5
5
|
|
|
6
6
|
extern crate self as oft;
|
|
7
7
|
|
|
8
|
-
use crate::
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
use crate::{
|
|
9
|
+
errors::OFTError,
|
|
10
|
+
extensions::{
|
|
11
|
+
oft_fee::{OFTFee, OFTFeeInternal},
|
|
12
|
+
pausable::{OFTPausable, OFTPausableInternal},
|
|
13
|
+
rate_limiter::{Direction, RateLimiter, RateLimiterInternal},
|
|
14
|
+
},
|
|
15
|
+
initialize_oft,
|
|
16
|
+
oft::{OFTInternal, OFT},
|
|
17
|
+
oft_impl::{self, quote_oft, quote_send},
|
|
18
|
+
storage::OFTStorage,
|
|
19
|
+
tests::test_utils::{
|
|
20
|
+
create_recipient_address, DummyToken, MockEndpointWithCompose, MockEndpointWithComposeClient,
|
|
21
|
+
DEFAULT_NATIVE_FEE, DEFAULT_SHARED_DECIMALS, DEFAULT_ZRO_FEE, INITIAL_MINT_AMOUNT,
|
|
22
|
+
},
|
|
23
|
+
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
24
|
+
utils::remove_dust,
|
|
18
25
|
};
|
|
19
|
-
use crate::types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam};
|
|
20
|
-
use crate::utils::remove_dust;
|
|
21
26
|
use endpoint_v2::{LayerZeroReceiverClient, MessagingFee, MessagingReceipt, Origin};
|
|
22
|
-
use oapp::oapp_core::OAppCoreClient;
|
|
27
|
+
use oapp::{oapp_core::OAppCoreClient, oapp_receiver::LzReceiveInternal};
|
|
23
28
|
use soroban_sdk::{
|
|
24
29
|
assert_with_error, bytes, contractimpl, log,
|
|
25
30
|
testutils::{Ledger, MockAuth, MockAuthInvoke},
|
|
@@ -33,6 +38,20 @@ use soroban_sdk::{
|
|
|
33
38
|
#[oapp_macros::oapp]
|
|
34
39
|
pub struct ExtensiveOFT;
|
|
35
40
|
|
|
41
|
+
impl LzReceiveInternal for ExtensiveOFT {
|
|
42
|
+
fn __lz_receive(
|
|
43
|
+
env: &Env,
|
|
44
|
+
origin: &Origin,
|
|
45
|
+
guid: &BytesN<32>,
|
|
46
|
+
message: &Bytes,
|
|
47
|
+
extra_data: &Bytes,
|
|
48
|
+
executor: &Address,
|
|
49
|
+
value: i128,
|
|
50
|
+
) {
|
|
51
|
+
oft_impl::lz_receive::<Self>(env, executor, origin, guid, message, extra_data, value)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
#[contractimpl]
|
|
37
56
|
impl ExtensiveOFT {
|
|
38
57
|
pub fn __constructor(
|
|
@@ -43,7 +62,7 @@ impl ExtensiveOFT {
|
|
|
43
62
|
delegate: &Option<Address>,
|
|
44
63
|
shared_decimals: u32,
|
|
45
64
|
) {
|
|
46
|
-
|
|
65
|
+
initialize_oft::<Self>(env, owner, token, endpoint, delegate, shared_decimals);
|
|
47
66
|
}
|
|
48
67
|
}
|
|
49
68
|
|
|
@@ -55,7 +74,7 @@ impl OFT for ExtensiveOFT {
|
|
|
55
74
|
send_param: &crate::types::SendParam,
|
|
56
75
|
) -> (OFTLimit, soroban_sdk::Vec<OFTFeeDetail>, OFTReceipt) {
|
|
57
76
|
Self::__assert_not_paused(env);
|
|
58
|
-
let (_, fee_details, oft_receipt) =
|
|
77
|
+
let (_, fee_details, oft_receipt) = quote_oft::<Self>(env, send_param);
|
|
59
78
|
let capacity = Self::rate_limit_capacity(env, &Direction::Outbound, send_param.dst_eid);
|
|
60
79
|
let oft_limit = OFTLimit { min_amount_ld: 0, max_amount_ld: capacity };
|
|
61
80
|
(oft_limit, fee_details, oft_receipt)
|
|
@@ -68,7 +87,7 @@ impl OFT for ExtensiveOFT {
|
|
|
68
87
|
pay_in_zro: bool,
|
|
69
88
|
) -> endpoint_v2::MessagingFee {
|
|
70
89
|
Self::__assert_not_paused(env);
|
|
71
|
-
|
|
90
|
+
quote_send::<Self>(env, sender, send_param, pay_in_zro)
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
|
|
@@ -86,12 +105,7 @@ impl OFTInternal for ExtensiveOFT {
|
|
|
86
105
|
Self::__release_rate_limit_capacity(env, &Direction::Inbound, dst_eid, oft_receipt.amount_received_ld);
|
|
87
106
|
|
|
88
107
|
// 4. Charge fee
|
|
89
|
-
Self::__charge_fee(
|
|
90
|
-
env,
|
|
91
|
-
&Self::token(env),
|
|
92
|
-
sender,
|
|
93
|
-
oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld,
|
|
94
|
-
);
|
|
108
|
+
Self::__charge_fee(env, &Self::token(env), sender, oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld);
|
|
95
109
|
|
|
96
110
|
oft_receipt
|
|
97
111
|
}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
//! - Fee deduction and transfer in send
|
|
7
7
|
//! - Fee deposit address configuration
|
|
8
8
|
|
|
9
|
-
use crate::
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
use crate::{
|
|
10
|
+
extensions::oft_fee::OFTFeeError,
|
|
11
|
+
tests::test_utils::{create_origin, create_recipient_address, encode_oft_message},
|
|
12
|
+
utils::address_to_bytes32,
|
|
13
|
+
};
|
|
12
14
|
use endpoint_v2::MessagingFee;
|
|
13
15
|
use soroban_sdk::{testutils::Address as _, Address, Bytes, BytesN, Env, IntoVal};
|
|
14
16
|
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
//! - `quote_send` is blocked
|
|
7
7
|
//! - `quote_oft` works (view function, not blocked)
|
|
8
8
|
|
|
9
|
-
use crate::
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
use crate::{
|
|
10
|
+
extensions::pausable::OFTPausableError,
|
|
11
|
+
tests::test_utils::{create_origin, create_recipient_address, encode_oft_message},
|
|
12
|
+
utils::address_to_bytes32,
|
|
13
|
+
};
|
|
12
14
|
use endpoint_v2::MessagingFee;
|
|
13
15
|
use soroban_sdk::{testutils::Address as _, Address, Bytes, BytesN, Env, IntoVal};
|
|
14
16
|
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
//! - Rate limit enforcement on lz_receive (inbound)
|
|
8
8
|
//! - Capacity release on opposite direction
|
|
9
9
|
|
|
10
|
-
use crate::
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
use crate::{
|
|
11
|
+
extensions::rate_limiter::{Direction, RateLimitError},
|
|
12
|
+
tests::test_utils::{create_origin, create_recipient_address, encode_oft_message},
|
|
13
|
+
utils::address_to_bytes32,
|
|
14
|
+
};
|
|
13
15
|
use endpoint_v2::MessagingFee;
|
|
14
16
|
use soroban_sdk::{
|
|
15
17
|
testutils::{Address as _, Ledger as _},
|
|
@@ -17,7 +17,7 @@ fn test_decimal_conversion_rate() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
#[test]
|
|
20
|
-
#[should_panic(expected = "Error(Contract, #
|
|
20
|
+
#[should_panic(expected = "Error(Contract, #3000)")] // InvalidLocalDecimals
|
|
21
21
|
fn test_invalid_local_decimals() {
|
|
22
22
|
let env = Env::default();
|
|
23
23
|
OFTTestSetupBuilder::new(&env).with_token_decimals(5).with_shared_decimals(6).build();
|
|
@@ -34,7 +34,7 @@ fn test_to_ld_overflow() {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
#[test]
|
|
37
|
-
#[should_panic(expected = "Error(Contract, #
|
|
37
|
+
#[should_panic(expected = "Error(Contract, #3002)")] // Overflow
|
|
38
38
|
fn test_to_sd_overflow() {
|
|
39
39
|
let env = Env::default();
|
|
40
40
|
|