@layerzerolabs/protocol-stellar-v2 0.2.19 → 0.2.21
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 +795 -791
- package/.turbo/turbo-lint.log +325 -155
- package/.turbo/turbo-test.log +1398 -1277
- package/Cargo.lock +122 -111
- package/Cargo.toml +32 -16
- package/contracts/common-macros/Cargo.toml +7 -7
- package/contracts/common-macros/src/auth.rs +18 -37
- package/contracts/common-macros/src/contract_ttl.rs +18 -7
- package/contracts/common-macros/src/lib.rs +31 -14
- package/contracts/common-macros/src/lz_contract.rs +38 -7
- package/contracts/common-macros/src/storage.rs +251 -292
- package/contracts/common-macros/src/tests/contract_ttl.rs +1 -1
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +6 -12
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +12 -17
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap +2 -1
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +2 -7
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +20 -14
- package/contracts/common-macros/src/tests/upgradeable.rs +26 -4
- package/contracts/common-macros/src/ttl_configurable.rs +2 -10
- package/contracts/common-macros/src/ttl_extendable.rs +2 -10
- package/contracts/common-macros/src/upgradeable.rs +61 -26
- package/contracts/common-macros/src/utils.rs +0 -9
- package/contracts/endpoint-v2/src/lib.rs +3 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +17 -5
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +2 -2
- package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +2 -2
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +6 -6
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +67 -37
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +5 -5
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +44 -54
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +7 -7
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +8 -8
- package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +2 -2
- package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +2 -2
- package/contracts/layerzero-views/Cargo.toml +0 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +1 -13
- package/contracts/macro-integration-tests/Cargo.toml +5 -15
- package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +48 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/oapp_core.rs +170 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +154 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +338 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +435 -0
- package/contracts/macro-integration-tests/tests/runtime.rs +1 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.stderr +71 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.rs +10 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_all.rs +38 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_single_trait.rs +96 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/minimal_contract.rs +64 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/struct_with_fields.rs +46 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.stderr +8 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_auth_env_param_variants.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui_oapp.rs +11 -0
- package/contracts/message-libs/message-lib-common/Cargo.toml +0 -1
- package/contracts/message-libs/message-lib-common/src/errors.rs +1 -1
- package/contracts/message-libs/treasury/Cargo.toml +0 -2
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +2 -2
- package/contracts/message-libs/uln-302/src/events.rs +4 -0
- package/contracts/message-libs/uln-302/src/send_uln.rs +22 -6
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +21 -67
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +2 -2
- package/contracts/oapps/counter/Cargo.toml +5 -6
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +1 -1
- package/contracts/oapps/counter/integration_tests/utils.rs +19 -12
- package/contracts/oapps/oapp/src/errors.rs +1 -1
- package/contracts/oapps/oapp/src/interfaces/mod.rs +3 -0
- package/contracts/oapps/oapp/src/interfaces/oapp_msg_inspector.rs +47 -0
- package/contracts/oapps/oapp/src/lib.rs +1 -0
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +4 -4
- package/contracts/oapps/oapp/src/oapp_core.rs +5 -5
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +12 -4
- package/contracts/oapps/oapp/src/oapp_receiver.rs +14 -9
- package/contracts/oapps/oapp/src/tests/mod.rs +4 -4
- package/contracts/oapps/oapp/src/tests/oapp_core.rs +223 -0
- package/contracts/oapps/oapp/src/tests/oapp_options_type3.rs +240 -0
- package/contracts/oapps/oapp/src/tests/oapp_receiver.rs +381 -0
- package/contracts/oapps/oapp/src/tests/oapp_sender.rs +569 -0
- package/contracts/oapps/oapp-macros/Cargo.toml +8 -4
- package/contracts/oapps/oapp-macros/src/generators.rs +9 -34
- package/contracts/oapps/oapp-macros/src/lib.rs +3 -0
- package/contracts/oapps/oapp-macros/src/tests/mod.rs +2 -0
- package/contracts/oapps/oapp-macros/src/tests/oapp.rs +88 -0
- package/contracts/oapps/oapp-macros/src/tests/parse_custom_impls.rs +86 -0
- package/contracts/oapps/oapp-macros/src/tests/snapshots/oapp_macros__tests__oapp__snapshot_generate_oapp.snap +103 -0
- package/contracts/oapps/oft/integration-tests/utils.rs +28 -8
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +153 -75
- package/contracts/oapps/oft/src/extensions/pausable.rs +61 -12
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +198 -134
- package/contracts/oapps/oft/src/oft.rs +45 -50
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -1
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +4 -26
- package/contracts/oapps/oft-core/Cargo.toml +1 -4
- package/contracts/oapps/oft-core/integration-tests/setup.rs +3 -3
- package/contracts/oapps/oft-core/integration-tests/utils.rs +21 -3
- package/contracts/oapps/oft-core/src/errors.rs +3 -2
- package/contracts/oapps/oft-core/src/events.rs +6 -0
- package/contracts/oapps/oft-core/src/lib.rs +1 -1
- package/contracts/oapps/oft-core/src/oft_core.rs +341 -246
- package/contracts/oapps/oft-core/src/storage.rs +7 -3
- package/contracts/oapps/oft-core/src/tests/mod.rs +1 -0
- package/contracts/oapps/oft-core/src/tests/test_decimals.rs +37 -2
- package/contracts/oapps/oft-core/src/tests/test_lz_receive.rs +2 -2
- package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +323 -0
- package/contracts/oapps/oft-core/src/tests/test_send.rs +2 -2
- package/contracts/oapps/oft-core/src/tests/test_utils.rs +61 -16
- package/contracts/upgrader/src/lib.rs +30 -57
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract1.wasm +0 -0
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract2.wasm +0 -0
- package/contracts/upgrader/src/tests/test_upgrader.rs +44 -35
- package/contracts/utils/Cargo.toml +0 -1
- package/contracts/utils/src/buffer_reader.rs +1 -0
- package/contracts/utils/src/errors.rs +4 -2
- package/contracts/utils/src/multisig.rs +17 -8
- package/contracts/utils/src/ownable.rs +6 -6
- package/contracts/utils/src/testing_utils.rs +124 -54
- package/contracts/utils/src/tests/multisig.rs +12 -12
- package/contracts/utils/src/tests/ownable.rs +6 -6
- package/contracts/utils/src/tests/testing_utils.rs +50 -167
- package/contracts/utils/src/tests/ttl_configurable.rs +5 -5
- package/contracts/utils/src/tests/upgradeable.rs +372 -175
- package/contracts/utils/src/ttl_configurable.rs +13 -7
- package/contracts/utils/src/upgradeable.rs +48 -23
- package/contracts/workers/dvn/Cargo.toml +6 -6
- package/contracts/workers/dvn/src/auth.rs +12 -42
- package/contracts/workers/dvn/src/dvn.rs +15 -40
- package/contracts/workers/dvn/src/errors.rs +0 -1
- package/contracts/workers/dvn/src/interfaces/dvn.rs +35 -0
- package/contracts/workers/dvn/src/lib.rs +4 -3
- package/contracts/workers/dvn/src/tests/auth.rs +1 -1
- package/contracts/workers/dvn/src/tests/dvn.rs +19 -15
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +2 -4
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +1 -3
- package/contracts/workers/dvn/src/tests/setup.rs +5 -9
- package/contracts/workers/dvn-fee-lib/Cargo.toml +2 -2
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +38 -22
- package/contracts/workers/dvn-fee-lib/src/lib.rs +12 -2
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +17 -16
- package/contracts/workers/executor/Cargo.toml +4 -0
- package/contracts/workers/executor/src/executor.rs +15 -36
- package/contracts/workers/executor/src/lib.rs +2 -2
- package/contracts/workers/executor/src/tests/auth.rs +394 -0
- package/contracts/workers/executor/src/tests/executor.rs +410 -0
- package/contracts/workers/executor/src/tests/mod.rs +3 -0
- package/contracts/workers/executor/src/tests/setup.rs +250 -0
- package/contracts/workers/executor-fee-lib/Cargo.toml +7 -1
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +62 -15
- package/contracts/workers/executor-fee-lib/src/executor_option.rs +28 -1
- package/contracts/workers/executor-fee-lib/src/lib.rs +11 -2
- package/contracts/workers/executor-fee-lib/src/tests/executor_fee_lib.rs +701 -0
- package/contracts/workers/executor-fee-lib/src/tests/executor_option.rs +370 -0
- package/contracts/workers/executor-fee-lib/src/tests/mod.rs +4 -0
- package/contracts/workers/executor-fee-lib/src/tests/setup.rs +60 -0
- package/contracts/workers/executor-helper/Cargo.toml +0 -1
- package/contracts/workers/executor-helper/src/lib.rs +3 -0
- package/contracts/workers/executor-helper/src/tests/executor_helper.rs +184 -0
- package/contracts/workers/executor-helper/src/tests/mod.rs +2 -0
- package/contracts/workers/executor-helper/src/tests/setup.rs +366 -0
- package/contracts/workers/fee-lib-interfaces/Cargo.toml +14 -0
- package/contracts/workers/{worker/src/interfaces/mod.rs → fee-lib-interfaces/src/lib.rs} +4 -3
- package/contracts/workers/price-feed/Cargo.toml +7 -1
- package/contracts/workers/price-feed/src/events.rs +1 -1
- package/contracts/workers/price-feed/src/lib.rs +12 -4
- package/contracts/workers/price-feed/src/price_feed.rs +5 -21
- package/contracts/workers/price-feed/src/storage.rs +1 -1
- package/contracts/workers/price-feed/src/tests/mod.rs +2 -0
- package/contracts/workers/price-feed/src/tests/price_feed.rs +869 -0
- package/contracts/workers/price-feed/src/tests/setup.rs +70 -0
- package/contracts/workers/price-feed/src/types.rs +1 -1
- package/contracts/workers/worker/src/errors.rs +1 -4
- package/contracts/workers/worker/src/lib.rs +0 -2
- package/contracts/workers/worker/src/storage.rs +32 -29
- package/contracts/workers/worker/src/tests/setup.rs +2 -8
- package/contracts/workers/worker/src/tests/worker.rs +96 -74
- package/contracts/workers/worker/src/worker.rs +75 -75
- package/docs/error-spec.md +55 -0
- package/docs/layerzero-v2-on-stellar.md +447 -0
- package/docs/oapp-guide.md +212 -0
- package/docs/oft-guide.md +314 -0
- package/package.json +3 -3
- package/sdk/.turbo/turbo-test.log +268 -263
- package/sdk/dist/generated/bml.d.ts +12 -4
- package/sdk/dist/generated/bml.js +9 -7
- package/sdk/dist/generated/counter.d.ts +306 -298
- package/sdk/dist/generated/counter.js +48 -46
- package/sdk/dist/generated/dvn.d.ts +450 -411
- package/sdk/dist/generated/dvn.js +66 -64
- package/sdk/dist/generated/dvn_fee_lib.d.ts +294 -338
- package/sdk/dist/generated/dvn_fee_lib.js +33 -64
- package/sdk/dist/generated/endpoint.d.ts +108 -100
- package/sdk/dist/generated/endpoint.js +21 -19
- package/sdk/dist/generated/executor.d.ts +414 -370
- package/sdk/dist/generated/executor.js +58 -55
- package/sdk/dist/generated/executor_fee_lib.d.ts +333 -377
- package/sdk/dist/generated/executor_fee_lib.js +34 -65
- package/sdk/dist/generated/executor_helper.d.ts +26 -190
- package/sdk/dist/generated/executor_helper.js +23 -28
- package/sdk/dist/generated/layerzero_view.d.ts +1271 -0
- package/sdk/dist/generated/layerzero_view.js +294 -0
- package/sdk/dist/generated/oft.d.ts +408 -385
- package/sdk/dist/generated/oft.js +89 -92
- package/sdk/dist/generated/price_feed.d.ts +385 -429
- package/sdk/dist/generated/price_feed.js +50 -81
- package/sdk/dist/generated/sml.d.ts +108 -100
- package/sdk/dist/generated/sml.js +21 -19
- package/sdk/dist/generated/treasury.d.ts +108 -100
- package/sdk/dist/generated/treasury.js +21 -19
- package/sdk/dist/generated/uln302.d.ts +108 -100
- package/sdk/dist/generated/uln302.js +23 -21
- package/sdk/dist/generated/upgrader.d.ts +189 -18
- package/sdk/dist/generated/upgrader.js +84 -4
- package/sdk/dist/index.d.ts +1 -0
- package/sdk/dist/index.js +2 -0
- package/sdk/package.json +1 -1
- package/sdk/src/index.ts +3 -0
- package/sdk/test/oft-sml.test.ts +4 -4
- package/sdk/test/suites/localnet.ts +84 -20
- package/sdk/test/upgrader.test.ts +2 -3
- package/tools/ts-bindings-gen/src/main.rs +2 -1
- package/contracts/ERROR_SPEC.md +0 -44
- package/contracts/endpoint-v2/ARCHITECTURE.md +0 -233
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +0 -175
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +0 -212
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +0 -153
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +0 -294
- /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/dvn_fee_lib.rs +0 -0
- /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/executor_fee_lib.rs +0 -0
- /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/price_feed.rs +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use crate::{
|
|
2
|
+
self as oft,
|
|
2
3
|
extensions::{
|
|
3
4
|
oft_fee::{OFTFee, OFTFeeInternal},
|
|
4
5
|
pausable::{OFTPausable, OFTPausableInternal},
|
|
@@ -7,15 +8,18 @@ use crate::{
|
|
|
7
8
|
oft_types::{lock_unlock, mint_burn, OftType},
|
|
8
9
|
};
|
|
9
10
|
use common_macros::{contract_impl, storage};
|
|
10
|
-
use endpoint_v2::{MessagingFee, Origin};
|
|
11
|
-
use oapp::oapp_receiver::LzReceiveInternal;
|
|
12
11
|
use oapp_macros::oapp;
|
|
13
12
|
use oft_core::{
|
|
14
13
|
errors::OFTError,
|
|
14
|
+
impl_oft_lz_receive,
|
|
15
15
|
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
16
16
|
utils as oft_utils, OFTCore, OFTInternal,
|
|
17
17
|
};
|
|
18
|
-
use soroban_sdk::{assert_with_error, vec, Address, Bytes,
|
|
18
|
+
use soroban_sdk::{assert_with_error, vec, Address, Bytes, Env, Vec};
|
|
19
|
+
|
|
20
|
+
// =========================================================================
|
|
21
|
+
// Storage
|
|
22
|
+
// =========================================================================
|
|
19
23
|
|
|
20
24
|
#[storage]
|
|
21
25
|
enum OFTStorage {
|
|
@@ -23,9 +27,16 @@ enum OFTStorage {
|
|
|
23
27
|
OftType,
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
// =========================================================================
|
|
31
|
+
// OFT Contract
|
|
32
|
+
// =========================================================================
|
|
33
|
+
|
|
26
34
|
#[oapp]
|
|
27
35
|
pub struct OFT;
|
|
28
36
|
|
|
37
|
+
// LzReceiveInternal implementation using default OFT receive logic
|
|
38
|
+
impl_oft_lz_receive!(OFT);
|
|
39
|
+
|
|
29
40
|
#[contract_impl]
|
|
30
41
|
impl OFT {
|
|
31
42
|
pub fn __constructor(
|
|
@@ -37,7 +48,7 @@ impl OFT {
|
|
|
37
48
|
shared_decimals: u32,
|
|
38
49
|
oft_type: OftType,
|
|
39
50
|
) {
|
|
40
|
-
|
|
51
|
+
Self::__initialize_oft(env, owner, token, endpoint, delegate, shared_decimals);
|
|
41
52
|
OFTStorage::set_oft_type(env, &oft_type);
|
|
42
53
|
}
|
|
43
54
|
|
|
@@ -51,9 +62,7 @@ impl OFT {
|
|
|
51
62
|
#[contract_impl(contracttrait)]
|
|
52
63
|
impl OFTCore for OFT {
|
|
53
64
|
fn quote_oft(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
54
|
-
Self::
|
|
55
|
-
|
|
56
|
-
let oft_receipt = Self::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
|
|
65
|
+
let (_, _, oft_receipt) = Self::__quote_oft(env, send_param);
|
|
57
66
|
|
|
58
67
|
// fee details (only include if there's an actual fee)
|
|
59
68
|
let fee_amount_ld = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
@@ -69,26 +78,31 @@ impl OFTCore for OFT {
|
|
|
69
78
|
|
|
70
79
|
(oft_limit, fee_details, oft_receipt)
|
|
71
80
|
}
|
|
72
|
-
|
|
73
|
-
fn quote_send(env: &Env, sender: &Address, send_param: &SendParam, pay_in_zro: bool) -> MessagingFee {
|
|
74
|
-
Self::__assert_not_paused(env);
|
|
75
|
-
oft_core::quote_send::<Self>(env, sender, send_param, pay_in_zro)
|
|
76
|
-
}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
/// OFT behavior for standard OFT with extension hooks
|
|
80
84
|
impl OFTInternal for OFT {
|
|
85
|
+
/// Overrides default to add pausable check and fee calculation.
|
|
86
|
+
///
|
|
87
|
+
/// Dust handling (consistent with EVM):
|
|
88
|
+
/// - fee = 0: dust stays with sender
|
|
89
|
+
/// - fee > 0: dust goes to fee recipient (included in charged fee)
|
|
81
90
|
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
82
|
-
|
|
91
|
+
Self::__assert_not_paused(env);
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
let conversion_rate = Self::__decimal_conversion_rate(env);
|
|
85
94
|
let fee = Self::__fee_view(env, dst_eid, amount_ld);
|
|
86
|
-
let amount_after_fee = amount_ld - fee;
|
|
87
|
-
let amount_received_ld = oft_utils::remove_dust(amount_after_fee, conversion_rate);
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
let (amount_sent_ld, amount_received_ld) = if fee == 0 {
|
|
97
|
+
// No fee: dust stays with sender (default OFT behavior)
|
|
98
|
+
let amount_sent_ld = oft_utils::remove_dust(amount_ld, conversion_rate);
|
|
99
|
+
(amount_sent_ld, amount_sent_ld)
|
|
100
|
+
} else {
|
|
101
|
+
// With fee: match EVM OFTFee behavior
|
|
102
|
+
// - dust is included in charged fee (goes to fee recipient)
|
|
103
|
+
let amount_received_ld = oft_utils::remove_dust(amount_ld - fee, conversion_rate);
|
|
104
|
+
(amount_ld, amount_received_ld)
|
|
105
|
+
};
|
|
92
106
|
|
|
93
107
|
assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
|
|
94
108
|
|
|
@@ -96,78 +110,59 @@ impl OFTInternal for OFT {
|
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
99
|
-
//
|
|
100
|
-
Self::__assert_not_paused(env);
|
|
101
|
-
|
|
102
|
-
// 2. Core debit logic (based on oft_type)
|
|
113
|
+
// Core debit logic (based on oft_type)
|
|
103
114
|
let oft_receipt = match Self::oft_type(env) {
|
|
104
115
|
OftType::LockUnlock => lock_unlock::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
105
116
|
OftType::MintBurn => mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
106
117
|
};
|
|
107
118
|
|
|
108
|
-
//
|
|
119
|
+
// Rate limit checks (using amount_received_ld - the actual cross-chain amount)
|
|
109
120
|
Self::__consume_rate_limit_capacity(env, &Direction::Outbound, dst_eid, oft_receipt.amount_received_ld);
|
|
110
121
|
Self::__release_rate_limit_capacity(env, &Direction::Inbound, dst_eid, oft_receipt.amount_received_ld);
|
|
111
122
|
|
|
112
|
-
//
|
|
123
|
+
// Charge fee
|
|
113
124
|
let fee = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
114
|
-
Self::__charge_fee(env, &Self::
|
|
125
|
+
Self::__charge_fee(env, &Self::__token(env), sender, fee);
|
|
115
126
|
|
|
116
127
|
oft_receipt
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
120
|
-
//
|
|
131
|
+
// Pausable check
|
|
121
132
|
Self::__assert_not_paused(env);
|
|
122
133
|
|
|
123
|
-
//
|
|
134
|
+
// Core credit logic (based on mode)
|
|
124
135
|
let amount_credited = match Self::oft_type(env) {
|
|
125
136
|
OftType::LockUnlock => lock_unlock::credit::<Self>(env, to, amount_ld, src_eid),
|
|
126
137
|
OftType::MintBurn => mint_burn::credit::<Self>(env, to, amount_ld, src_eid),
|
|
127
138
|
};
|
|
128
139
|
|
|
129
|
-
//
|
|
130
|
-
Self::__consume_rate_limit_capacity(env, &Direction::Inbound, src_eid,
|
|
131
|
-
Self::__release_rate_limit_capacity(env, &Direction::Outbound, src_eid,
|
|
140
|
+
// Rate limit checks
|
|
141
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Inbound, src_eid, amount_ld);
|
|
142
|
+
Self::__release_rate_limit_capacity(env, &Direction::Outbound, src_eid, amount_ld);
|
|
132
143
|
|
|
133
144
|
amount_credited
|
|
134
145
|
}
|
|
135
146
|
}
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
env: &Env,
|
|
141
|
-
origin: &Origin,
|
|
142
|
-
guid: &BytesN<32>,
|
|
143
|
-
message: &Bytes,
|
|
144
|
-
extra_data: &Bytes,
|
|
145
|
-
executor: &Address,
|
|
146
|
-
value: i128,
|
|
147
|
-
) {
|
|
148
|
-
oft_core::lz_receive::<Self>(env, executor, origin, guid, message, extra_data, value)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ==================== Extension Trait Implementations ====================
|
|
148
|
+
// =========================================================================
|
|
149
|
+
// Extension Trait Implementations
|
|
150
|
+
// =========================================================================
|
|
153
151
|
|
|
154
152
|
/// Pausable extension - allows pausing/unpausing the OFT
|
|
155
153
|
/// Default state: unpaused (all operations allowed)
|
|
156
154
|
#[contract_impl(contracttrait)]
|
|
157
155
|
impl OFTPausable for OFT {}
|
|
158
|
-
|
|
159
156
|
impl OFTPausableInternal for OFT {}
|
|
160
157
|
|
|
161
158
|
/// OFT Fee extension - allows collecting fees on transfers
|
|
162
159
|
/// Default state: 0 BPS (no fee collected)
|
|
163
160
|
#[contract_impl(contracttrait)]
|
|
164
161
|
impl OFTFee for OFT {}
|
|
165
|
-
|
|
166
162
|
impl OFTFeeInternal for OFT {}
|
|
167
163
|
|
|
168
164
|
/// Rate Limiter extension - allows rate limiting transfers
|
|
169
165
|
/// Default state: not set (rate_limit_capacity returns i128::MAX)
|
|
170
166
|
#[contract_impl(contracttrait)]
|
|
171
167
|
impl RateLimiter for OFT {}
|
|
172
|
-
|
|
173
168
|
impl RateLimiterInternal for OFT {}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//! tokens from the contract on credit (receive).
|
|
5
5
|
//! Used for OFT adapters that wrap existing tokens.
|
|
6
6
|
|
|
7
|
-
use oft_core::{
|
|
7
|
+
use oft_core::{types::OFTReceipt, OFTCore};
|
|
8
8
|
use soroban_sdk::{token::TokenClient, Address, Env};
|
|
9
9
|
|
|
10
10
|
/// Debit tokens using LockUnlock OFT type (locks tokens in contract).
|
|
@@ -3,30 +3,8 @@
|
|
|
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 oft_core::{
|
|
7
|
-
use soroban_sdk::{
|
|
8
|
-
|
|
9
|
-
/// Contract interface for mint and burn token operations.
|
|
10
|
-
///
|
|
11
|
-
/// This interface abstracts the token mint/burn functionality, allowing different
|
|
12
|
-
/// token implementations (e.g., StellarAssetContract, custom tokens) to be used
|
|
13
|
-
/// with the MintBurn OFT.
|
|
14
|
-
#[contractclient(name = "MintBurnTokenClient")]
|
|
15
|
-
pub trait MintBurnToken {
|
|
16
|
-
/// Mints tokens to the specified address.
|
|
17
|
-
///
|
|
18
|
-
/// # Parameters
|
|
19
|
-
/// * `to` - The address to mint tokens to
|
|
20
|
-
/// * `amount` - The amount of tokens to mint (must be non-negative)
|
|
21
|
-
fn mint(env: Env, to: Address, amount: i128);
|
|
22
|
-
|
|
23
|
-
/// Burns tokens from the specified address.
|
|
24
|
-
///
|
|
25
|
-
/// # Parameters
|
|
26
|
-
/// * `from` - The address to burn tokens from
|
|
27
|
-
/// * `amount` - The amount of tokens to burn (must be non-negative)
|
|
28
|
-
fn burn(env: Env, from: Address, amount: i128);
|
|
29
|
-
}
|
|
6
|
+
use oft_core::{types::OFTReceipt, OFTCore};
|
|
7
|
+
use soroban_sdk::{token::StellarAssetClient, Address, Env};
|
|
30
8
|
|
|
31
9
|
/// Debit tokens using MintBurn OFT type (burns tokens from sender).
|
|
32
10
|
///
|
|
@@ -47,7 +25,7 @@ pub fn debit<T: OFTCore>(
|
|
|
47
25
|
dst_eid: u32,
|
|
48
26
|
) -> OFTReceipt {
|
|
49
27
|
let receipt = T::__debit_view(env, amount_ld, min_amount_ld, dst_eid);
|
|
50
|
-
|
|
28
|
+
StellarAssetClient::new(env, &T::token(env)).burn(sender, &receipt.amount_received_ld);
|
|
51
29
|
receipt
|
|
52
30
|
}
|
|
53
31
|
|
|
@@ -62,6 +40,6 @@ pub fn debit<T: OFTCore>(
|
|
|
62
40
|
/// # Returns
|
|
63
41
|
/// The amount credited
|
|
64
42
|
pub fn credit<T: OFTCore>(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
|
|
65
|
-
|
|
43
|
+
StellarAssetClient::new(env, &T::token(env)).mint(to, &amount_ld);
|
|
66
44
|
amount_ld
|
|
67
45
|
}
|
|
@@ -21,7 +21,4 @@ simple-message-lib = { workspace = true }
|
|
|
21
21
|
message-lib-common = { workspace = true, features = ["testutils"] }
|
|
22
22
|
endpoint-v2 = { workspace = true, features = ["testutils"] }
|
|
23
23
|
utils = { workspace = true, features = ["testutils"] }
|
|
24
|
-
|
|
25
|
-
oapp-macros = { workspace = true }
|
|
26
|
-
stellar-macros = { workspace = true }
|
|
27
|
-
stellar-tokens = { workspace = true }
|
|
24
|
+
oapp-macros = { workspace = true }
|
|
@@ -7,7 +7,7 @@ extern crate std;
|
|
|
7
7
|
use crate::{
|
|
8
8
|
self as oft_core,
|
|
9
9
|
integration_tests::utils::{address_to_peer_bytes32, peer_bytes32_to_address},
|
|
10
|
-
oft_core::{
|
|
10
|
+
oft_core::{OFTClient, OFTCore, OFTInternal},
|
|
11
11
|
storage::OFTStorage,
|
|
12
12
|
types::OFTReceipt,
|
|
13
13
|
};
|
|
@@ -39,7 +39,7 @@ impl LzReceiveInternal for TestOFT {
|
|
|
39
39
|
executor: &Address,
|
|
40
40
|
value: i128,
|
|
41
41
|
) {
|
|
42
|
-
|
|
42
|
+
<Self as OFTInternal>::__receive(env, origin, guid, message, extra_data, executor, value)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -53,7 +53,7 @@ impl TestOFT {
|
|
|
53
53
|
delegate: &Option<Address>,
|
|
54
54
|
shared_decimals: u32,
|
|
55
55
|
) {
|
|
56
|
-
|
|
56
|
+
Self::__initialize_oft(env, owner, token, endpoint, delegate, shared_decimals)
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -155,10 +155,28 @@ pub fn lz_compose(
|
|
|
155
155
|
|
|
156
156
|
// returns (encoded_payload, options, send_library)
|
|
157
157
|
pub fn scan_packet_sent_event(env: &Env, endpoint: &Address) -> Option<(Bytes, Bytes, Address)> {
|
|
158
|
+
use soroban_sdk::TryFromVal;
|
|
159
|
+
|
|
158
160
|
let mut packet = None;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
let events = env.events().all().filter_by_contract(endpoint);
|
|
162
|
+
for event in events.events().iter() {
|
|
163
|
+
let v0 = match &event.body {
|
|
164
|
+
soroban_sdk::xdr::ContractEventBody::V0(v0) => v0,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Check if this is a packet_sent event by looking at topics
|
|
168
|
+
let mut is_packet_sent = false;
|
|
169
|
+
for topic in v0.topics.iter() {
|
|
170
|
+
if let Ok(sym) = Symbol::try_from_val(env, topic) {
|
|
171
|
+
if sym == Symbol::new(env, "packet_sent") {
|
|
172
|
+
is_packet_sent = true;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if is_packet_sent {
|
|
179
|
+
let data: Val = Val::try_from_val(env, &v0.data).unwrap();
|
|
162
180
|
let map: Map<Symbol, Val> = data.into_val(env);
|
|
163
181
|
|
|
164
182
|
let encoded_payload: Bytes = map.get(Symbol::new(env, "encoded_packet")).unwrap().into_val(env);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
use common_macros::contract_error;
|
|
2
2
|
|
|
3
3
|
// OFT library error codes: 3000-3099
|
|
4
|
-
// See
|
|
4
|
+
// See docs/error-spec.md for allocation rules
|
|
5
5
|
|
|
6
6
|
/// OFTError: 3000-3099
|
|
7
7
|
#[contract_error]
|
|
8
8
|
pub enum OFTError {
|
|
9
|
-
|
|
9
|
+
InvalidAmount = 3000,
|
|
10
|
+
InvalidLocalDecimals,
|
|
10
11
|
NotInitialized,
|
|
11
12
|
Overflow,
|
|
12
13
|
SlippageExceeded,
|