@layerzerolabs/protocol-stellar-v2 0.2.18 → 0.2.20
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 +303 -253
- package/.turbo/turbo-lint.log +66 -65
- package/.turbo/turbo-test.log +1312 -1282
- package/Cargo.lock +21 -8
- package/Cargo.toml +2 -0
- package/contracts/ERROR_SPEC.md +9 -2
- package/contracts/common-macros/src/contract_ttl.rs +18 -7
- package/contracts/common-macros/src/lib.rs +4 -4
- package/contracts/common-macros/src/tests/contract_ttl.rs +1 -1
- 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__upgradeable__snapshot_generated_upgradeable_code.snap +7 -12
- package/contracts/common-macros/src/upgradeable.rs +15 -21
- package/contracts/message-libs/uln-302/src/events.rs +4 -0
- package/contracts/message-libs/uln-302/src/send_uln.rs +23 -7
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +38 -64
- package/contracts/oapps/counter/Cargo.toml +1 -0
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +1 -1
- package/contracts/oapps/oapp/src/oapp_receiver.rs +1 -1
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +113 -65
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +111 -82
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +293 -65
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +331 -56
- package/contracts/oapps/oft/Cargo.toml +10 -7
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
- package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
- package/contracts/oapps/oft/integration-tests/setup.rs +28 -127
- package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +23 -8
- package/contracts/oapps/oft/src/extensions/pausable.rs +19 -4
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +52 -28
- package/contracts/oapps/oft/src/lib.rs +10 -14
- package/contracts/oapps/oft/src/oft.rs +143 -193
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -11
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +12 -14
- package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
- package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +126 -29
- package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
- package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
- package/contracts/oapps/oft-core/src/lib.rs +18 -0
- package/contracts/oapps/oft-core/src/oft_core.rs +479 -0
- package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
- package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
- package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -4
- package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
- package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +46 -27
- package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
- 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/src/buffer_reader.rs +1 -0
- package/contracts/utils/src/errors.rs +8 -2
- package/contracts/utils/src/ownable.rs +125 -3
- package/contracts/utils/src/tests/option_ext.rs +1 -1
- package/contracts/utils/src/tests/ownable.rs +445 -7
- package/contracts/utils/src/tests/ttl_configurable.rs +2 -2
- package/contracts/utils/src/tests/upgradeable.rs +372 -175
- package/contracts/utils/src/ttl_configurable.rs +3 -3
- package/contracts/utils/src/upgradeable.rs +48 -23
- package/contracts/workers/dvn/Cargo.toml +1 -0
- package/contracts/workers/dvn/src/auth.rs +12 -42
- package/contracts/workers/dvn/src/dvn.rs +16 -31
- 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 +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -5
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +2 -3
- package/contracts/workers/executor/Cargo.toml +1 -0
- package/contracts/workers/executor/src/executor.rs +15 -26
- package/contracts/workers/executor-fee-lib/Cargo.toml +2 -1
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +63 -5
- package/contracts/workers/executor-fee-lib/src/executor_option.rs +28 -1
- package/contracts/workers/executor-fee-lib/src/lib.rs +3 -0
- 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/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 +2 -1
- package/contracts/workers/price-feed/src/events.rs +1 -1
- package/contracts/workers/price-feed/src/lib.rs +3 -0
- package/contracts/workers/price-feed/src/price_feed.rs +6 -12
- 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 +0 -3
- 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 +1 -7
- package/contracts/workers/worker/src/tests/worker.rs +50 -42
- package/contracts/workers/worker/src/worker.rs +49 -58
- package/package.json +4 -5
- package/sdk/.turbo/turbo-test.log +229 -217
- package/sdk/dist/generated/bml.d.ts +39 -1
- package/sdk/dist/generated/bml.js +33 -8
- package/sdk/dist/generated/counter.d.ts +131 -3
- package/sdk/dist/generated/counter.js +41 -10
- package/sdk/dist/generated/dvn.d.ts +431 -362
- package/sdk/dist/generated/dvn.js +80 -55
- package/sdk/dist/generated/dvn_fee_lib.d.ts +327 -251
- package/sdk/dist/generated/dvn_fee_lib.js +55 -57
- package/sdk/dist/generated/endpoint.d.ts +131 -3
- package/sdk/dist/generated/endpoint.js +41 -10
- package/sdk/dist/generated/executor.d.ts +503 -339
- package/sdk/dist/generated/executor.js +80 -48
- package/sdk/dist/generated/executor_fee_lib.d.ts +395 -319
- package/sdk/dist/generated/executor_fee_lib.js +54 -56
- package/sdk/dist/generated/executor_helper.d.ts +53 -187
- package/sdk/dist/generated/executor_helper.js +47 -29
- 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 +1851 -0
- package/sdk/dist/generated/oft.js +347 -0
- package/sdk/dist/generated/price_feed.d.ts +329 -253
- package/sdk/dist/generated/price_feed.js +55 -57
- package/sdk/dist/generated/sml.d.ts +131 -3
- package/sdk/dist/generated/sml.js +41 -10
- package/sdk/dist/generated/treasury.d.ts +131 -3
- package/sdk/dist/generated/treasury.js +41 -10
- package/sdk/dist/generated/uln302.d.ts +131 -3
- package/sdk/dist/generated/uln302.js +43 -12
- package/sdk/dist/generated/upgrader.d.ts +201 -15
- package/sdk/dist/generated/upgrader.js +99 -1
- package/sdk/dist/index.d.ts +2 -2
- package/sdk/dist/index.js +3 -3
- package/sdk/package.json +3 -2
- package/sdk/src/index.ts +3 -3
- package/sdk/test/oft-sml.test.ts +20 -20
- package/sdk/test/upgrader.test.ts +2 -3
- package/sdk/turbo.json +8 -0
- package/tools/ts-bindings-gen/Cargo.toml +2 -0
- package/tools/ts-bindings-gen/src/main.rs +53 -5
- package/turbo.json +0 -2
- package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
- package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
- package/contracts/oapps/oft/src/oft_impl.rs +0 -201
- package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -917
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -751
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -434
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1080
- package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
- package/contracts/oapps/oft-std/src/lib.rs +0 -16
- package/contracts/oapps/oft-std/src/oft.rs +0 -174
- package/sdk/dist/generated/oft_std.d.ts +0 -1722
- package/sdk/dist/generated/oft_std.js +0 -316
- package/sdk/dist/wasm/blocked-message-lib.d.ts +0 -1
- package/sdk/dist/wasm/blocked-message-lib.js +0 -2
- package/sdk/dist/wasm/counter.d.ts +0 -1
- package/sdk/dist/wasm/counter.js +0 -2
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +0 -1
- package/sdk/dist/wasm/dvn-fee-lib.js +0 -2
- package/sdk/dist/wasm/dvn.d.ts +0 -1
- package/sdk/dist/wasm/dvn.js +0 -2
- package/sdk/dist/wasm/endpoint-v2.d.ts +0 -1
- package/sdk/dist/wasm/endpoint-v2.js +0 -2
- package/sdk/dist/wasm/executor-fee-lib.d.ts +0 -1
- package/sdk/dist/wasm/executor-fee-lib.js +0 -2
- package/sdk/dist/wasm/executor-helper.d.ts +0 -1
- package/sdk/dist/wasm/executor-helper.js +0 -2
- package/sdk/dist/wasm/executor.d.ts +0 -1
- package/sdk/dist/wasm/executor.js +0 -2
- package/sdk/dist/wasm/layerzero-views.d.ts +0 -1
- package/sdk/dist/wasm/layerzero-views.js +0 -2
- package/sdk/dist/wasm/oft-std.d.ts +0 -1
- package/sdk/dist/wasm/oft-std.js +0 -2
- package/sdk/dist/wasm/price-feed.d.ts +0 -1
- package/sdk/dist/wasm/price-feed.js +0 -2
- package/sdk/dist/wasm/simple-message-lib.d.ts +0 -1
- package/sdk/dist/wasm/simple-message-lib.js +0 -2
- package/sdk/dist/wasm/treasury.d.ts +0 -1
- package/sdk/dist/wasm/treasury.js +0 -2
- package/sdk/dist/wasm/uln302.d.ts +0 -1
- package/sdk/dist/wasm/uln302.js +0 -2
- package/sdk/dist/wasm/upgrader.d.ts +0 -1
- package/sdk/dist/wasm/upgrader.js +0 -2
- package/sdk/dist/wasm.d.ts +0 -15
- package/sdk/dist/wasm.js +0 -15
- /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/errors.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/storage.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/types.rs +0 -0
- /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,201 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//! Extension tests module.
|
|
2
|
-
//!
|
|
3
|
-
//! This module contains tests for OFT extensions (pausable, oft_fee, rate_limiter).
|
|
4
|
-
|
|
5
|
-
pub mod setup;
|
|
6
|
-
pub mod test_oft_fee;
|
|
7
|
-
pub mod test_pausable;
|
|
8
|
-
pub mod test_rate_limiter;
|
|
9
|
-
|
|
10
|
-
// Re-export commonly used items for convenience
|
|
11
|
-
pub use setup::{ExtensiveOFT, ExtensiveOFTClient, ExtensiveOFTTestSetup};
|