@layerzerolabs/protocol-stellar-v2 0.2.18 → 0.2.19
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 +275 -248
- package/.turbo/turbo-lint.log +52 -58
- package/.turbo/turbo-test.log +1224 -1358
- package/Cargo.lock +8 -5
- package/Cargo.toml +1 -1
- package/contracts/ERROR_SPEC.md +1 -1
- package/contracts/message-libs/uln-302/src/send_uln.rs +1 -1
- package/contracts/oapps/oapp/src/oapp_receiver.rs +1 -1
- 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 +5 -6
- package/contracts/oapps/oft/src/lib.rs +10 -14
- package/contracts/oapps/oft/src/oft.rs +151 -189
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -11
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +32 -12
- 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 +439 -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 +44 -25
- package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
- package/contracts/utils/src/errors.rs +5 -1
- 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/package.json +4 -5
- package/sdk/.turbo/turbo-test.log +216 -206
- package/sdk/dist/generated/bml.d.ts +30 -0
- package/sdk/dist/generated/bml.js +28 -5
- package/sdk/dist/generated/counter.d.ts +122 -2
- package/sdk/dist/generated/counter.js +36 -7
- package/sdk/dist/generated/dvn.d.ts +30 -0
- package/sdk/dist/generated/dvn.js +28 -5
- package/sdk/dist/generated/dvn_fee_lib.d.ts +122 -2
- package/sdk/dist/generated/dvn_fee_lib.js +36 -7
- package/sdk/dist/generated/endpoint.d.ts +122 -2
- package/sdk/dist/generated/endpoint.js +36 -7
- package/sdk/dist/generated/executor.d.ts +122 -2
- package/sdk/dist/generated/executor.js +36 -7
- package/sdk/dist/generated/executor_fee_lib.d.ts +122 -2
- package/sdk/dist/generated/executor_fee_lib.js +36 -7
- package/sdk/dist/generated/executor_helper.d.ts +30 -0
- package/sdk/dist/generated/executor_helper.js +28 -5
- package/sdk/dist/generated/oft.d.ts +1842 -0
- package/sdk/dist/generated/oft.js +345 -0
- package/sdk/dist/generated/price_feed.d.ts +122 -2
- package/sdk/dist/generated/price_feed.js +36 -7
- package/sdk/dist/generated/sml.d.ts +122 -2
- package/sdk/dist/generated/sml.js +36 -7
- package/sdk/dist/generated/treasury.d.ts +122 -2
- package/sdk/dist/generated/treasury.js +36 -7
- package/sdk/dist/generated/uln302.d.ts +122 -2
- package/sdk/dist/generated/uln302.js +36 -7
- package/sdk/dist/generated/upgrader.d.ts +15 -0
- package/sdk/dist/generated/upgrader.js +18 -0
- package/sdk/dist/index.d.ts +1 -2
- package/sdk/dist/index.js +1 -3
- package/sdk/package.json +3 -2
- package/sdk/src/index.ts +1 -4
- package/sdk/test/oft-sml.test.ts +16 -16
- package/sdk/turbo.json +8 -0
- package/tools/ts-bindings-gen/Cargo.toml +2 -0
- package/tools/ts-bindings-gen/src/main.rs +51 -4
- 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
|
@@ -1,211 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//!
|
|
9
|
-
//! ```ignore
|
|
10
|
-
//! use oapp_macros::{oapp, oapp_options_type3};
|
|
11
|
-
//! use oft::oft::{OFTInternal, OFT};
|
|
12
|
-
//! use oft::initialize_oft;
|
|
13
|
-
//!
|
|
14
|
-
//! #[oapp]
|
|
15
|
-
//! pub struct MyOFT;
|
|
16
|
-
//!
|
|
17
|
-
//! #[contractimpl]
|
|
18
|
-
//! impl MyOFT {
|
|
19
|
-
//! pub fn __constructor(env: &Env, token: &Address, owner: &Address, endpoint: &Address, delegate: &Option<Address>) {
|
|
20
|
-
//! initialize_oft::<Self>(env, owner, token, endpoint, delegate)
|
|
21
|
-
//! }
|
|
22
|
-
//! }
|
|
23
|
-
//!
|
|
24
|
-
//! // Public methods - exposed as contract endpoints
|
|
25
|
-
//! #[contractimpl(contracttrait)]
|
|
26
|
-
//! impl OFT for MyOFT {}
|
|
27
|
-
//!
|
|
28
|
-
//! // Internal methods - NOT exposed as contract endpoints
|
|
29
|
-
//! // IMPORTANT: Do NOT use #[contractimpl] here to keep methods internal
|
|
30
|
-
//! impl OFTInternal for MyOFT {
|
|
31
|
-
//! fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
32
|
-
//! // Your debit logic (e.g., burn or lock tokens)
|
|
33
|
-
//! oft::oft_types::mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid)
|
|
34
|
-
//! }
|
|
35
|
-
//!
|
|
36
|
-
//! fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
37
|
-
//! // Your credit logic (e.g., mint or unlock tokens)
|
|
38
|
-
//! oft::oft_types::mint_burn::credit::<Self>(env, to, amount_ld, src_eid)
|
|
39
|
-
//! }
|
|
40
|
-
//! }
|
|
41
|
-
//! ```
|
|
42
|
-
|
|
43
|
-
// Alias for the current crate, allowing `oft::types::SendParam` paths to work both
|
|
44
|
-
// inside this crate and in external crates implementing the OFT trait.
|
|
45
|
-
extern crate self as oft;
|
|
46
|
-
|
|
47
|
-
use crate::{oft_impl, storage::OFTStorage, types::OFTReceipt};
|
|
48
|
-
use common_macros::contract_trait;
|
|
49
|
-
use oapp::{
|
|
50
|
-
oapp_core::OAppCore, oapp_options_type3::OAppOptionsType3, oapp_receiver::OAppReceiver,
|
|
51
|
-
oapp_sender::OAppSenderInternal,
|
|
1
|
+
use crate::{
|
|
2
|
+
extensions::{
|
|
3
|
+
oft_fee::{OFTFee, OFTFeeInternal},
|
|
4
|
+
pausable::{OFTPausable, OFTPausableInternal},
|
|
5
|
+
rate_limiter::{Direction, RateLimiter, RateLimiterInternal},
|
|
6
|
+
},
|
|
7
|
+
oft_types::{lock_unlock, mint_burn, OftType},
|
|
52
8
|
};
|
|
53
|
-
use
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/// #[contractimpl]
|
|
70
|
-
/// impl OFTInternal for MyOFT { ... }
|
|
71
|
-
/// ```
|
|
72
|
-
///
|
|
73
|
-
/// Internal OFT trait for token debit/credit operations.
|
|
74
|
-
///
|
|
75
|
-
/// This trait contains only the internal token operations. The OApp supertraits
|
|
76
|
-
/// are on `OFT` instead, keeping this trait focused on token logic.
|
|
77
|
-
pub trait OFTInternal: OAppCore {
|
|
78
|
-
// =========================================================================
|
|
79
|
-
// Required Methods (no defaults - user MUST implement)
|
|
80
|
-
// =========================================================================
|
|
81
|
-
|
|
82
|
-
/// Debits tokens from the specified address for cross-chain transfer.
|
|
83
|
-
///
|
|
84
|
-
/// # Arguments
|
|
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
|
|
89
|
-
///
|
|
90
|
-
/// # Returns
|
|
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;
|
|
93
|
-
|
|
94
|
-
/// Credits tokens to recipient after receiving cross-chain transfer.
|
|
95
|
-
///
|
|
96
|
-
/// # Arguments
|
|
97
|
-
/// * `to` - The address to credit tokens to
|
|
98
|
-
/// * `amount_ld` - Amount in local decimals to credit
|
|
99
|
-
/// * `src_eid` - Source endpoint ID
|
|
100
|
-
///
|
|
101
|
-
/// # Returns
|
|
102
|
-
/// The amount actually credited
|
|
103
|
-
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128;
|
|
104
|
-
|
|
105
|
-
// =========================================================================
|
|
106
|
-
// Optional Methods (have defaults - override as needed)
|
|
107
|
-
// =========================================================================
|
|
108
|
-
|
|
109
|
-
/// Calculates debit amounts without executing (view function).
|
|
110
|
-
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
111
|
-
oft_impl::debit_view(env, amount_ld, min_amount_ld, dst_eid)
|
|
112
|
-
}
|
|
9
|
+
use common_macros::{contract_impl, storage};
|
|
10
|
+
use endpoint_v2::{MessagingFee, Origin};
|
|
11
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
12
|
+
use oapp_macros::oapp;
|
|
13
|
+
use oft_core::{
|
|
14
|
+
errors::OFTError,
|
|
15
|
+
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
16
|
+
utils as oft_utils, OFTCore, OFTInternal,
|
|
17
|
+
};
|
|
18
|
+
use soroban_sdk::{assert_with_error, vec, Address, Bytes, BytesN, Env, Vec};
|
|
19
|
+
|
|
20
|
+
#[storage]
|
|
21
|
+
enum OFTStorage {
|
|
22
|
+
#[instance(OftType)]
|
|
23
|
+
OftType,
|
|
24
|
+
}
|
|
113
25
|
|
|
114
|
-
|
|
115
|
-
|
|
26
|
+
#[oapp]
|
|
27
|
+
pub struct OFT;
|
|
28
|
+
|
|
29
|
+
#[contract_impl]
|
|
30
|
+
impl OFT {
|
|
31
|
+
pub fn __constructor(
|
|
116
32
|
env: &Env,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
{
|
|
124
|
-
|
|
33
|
+
token: &Address,
|
|
34
|
+
owner: &Address,
|
|
35
|
+
endpoint: &Address,
|
|
36
|
+
delegate: &Option<Address>,
|
|
37
|
+
shared_decimals: u32,
|
|
38
|
+
oft_type: OftType,
|
|
39
|
+
) {
|
|
40
|
+
oft_core::initialize_oft::<Self>(env, owner, token, endpoint, delegate, shared_decimals);
|
|
41
|
+
OFTStorage::set_oft_type(env, &oft_type);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Returns the type of operation for this OFT (LockUnlock or MintBurn)
|
|
45
|
+
pub fn oft_type(env: &Env) -> OftType {
|
|
46
|
+
OFTStorage::oft_type(env).unwrap()
|
|
125
47
|
}
|
|
126
48
|
}
|
|
127
49
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
50
|
+
/// OFTCore trait implementation for standard OFT with extensions
|
|
51
|
+
#[contract_impl(contracttrait)]
|
|
52
|
+
impl OFTCore for OFT {
|
|
53
|
+
fn quote_oft(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
54
|
+
Self::__assert_not_paused(env);
|
|
55
|
+
|
|
56
|
+
let oft_receipt = Self::__debit_view(env, send_param.amount_ld, send_param.min_amount_ld, send_param.dst_eid);
|
|
57
|
+
|
|
58
|
+
// fee details (only include if there's an actual fee)
|
|
59
|
+
let fee_amount_ld = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
60
|
+
let fee_details = if fee_amount_ld > 0 {
|
|
61
|
+
vec![env, OFTFeeDetail { fee_amount_ld, description: Bytes::from_slice(env, b"OFT Fee") }]
|
|
62
|
+
} else {
|
|
63
|
+
vec![env]
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// rate limit capacity
|
|
67
|
+
let capacity = Self::rate_limit_capacity(env, &Direction::Outbound, send_param.dst_eid);
|
|
68
|
+
let oft_limit = OFTLimit { min_amount_ld: 0, max_amount_ld: capacity };
|
|
69
|
+
|
|
70
|
+
(oft_limit, fee_details, oft_receipt)
|
|
144
71
|
}
|
|
145
72
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(
|
|
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)
|
|
149
76
|
}
|
|
77
|
+
}
|
|
150
78
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let local_decimals = soroban_sdk::token::TokenClient::new(env, &token).decimals();
|
|
79
|
+
/// OFT behavior for standard OFT with extension hooks
|
|
80
|
+
impl OFTInternal for OFT {
|
|
81
|
+
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
155
82
|
let conversion_rate = Self::decimal_conversion_rate(env);
|
|
156
|
-
local_decimals - conversion_rate.ilog10()
|
|
157
|
-
}
|
|
158
83
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
84
|
+
// Apply the fee before dust removal to ensure the fee is calculated on the full amount and dust is not transferred
|
|
85
|
+
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
|
+
|
|
89
|
+
// amount_sent_ld = what recipient receives + fee charged
|
|
90
|
+
// Dust is excluded (stays with sender)
|
|
91
|
+
let amount_sent_ld = amount_received_ld + fee;
|
|
92
|
+
|
|
93
|
+
assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
|
|
163
94
|
|
|
164
|
-
|
|
165
|
-
///
|
|
166
|
-
/// Helps wallet implementers determine integration requirements.
|
|
167
|
-
///
|
|
168
|
-
/// # Returns
|
|
169
|
-
/// - `true` if a separate token approval step is required
|
|
170
|
-
/// - `false` if no separate approval is needed
|
|
171
|
-
fn approval_required(_env: &Env) -> bool {
|
|
172
|
-
false
|
|
95
|
+
OFTReceipt { amount_sent_ld, amount_received_ld }
|
|
173
96
|
}
|
|
174
97
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
env
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
98
|
+
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
99
|
+
// 1. Pausable check
|
|
100
|
+
Self::__assert_not_paused(env);
|
|
101
|
+
|
|
102
|
+
// 2. Core debit logic (based on oft_type)
|
|
103
|
+
let oft_receipt = match Self::oft_type(env) {
|
|
104
|
+
OftType::LockUnlock => lock_unlock::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
105
|
+
OftType::MintBurn => mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// 3. Rate limit checks (using amount_received_ld - the actual cross-chain amount)
|
|
109
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Outbound, dst_eid, oft_receipt.amount_received_ld);
|
|
110
|
+
Self::__release_rate_limit_capacity(env, &Direction::Inbound, dst_eid, oft_receipt.amount_received_ld);
|
|
111
|
+
|
|
112
|
+
// 4. Charge fee
|
|
113
|
+
let fee = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
114
|
+
Self::__charge_fee(env, &Self::token(env), sender, fee);
|
|
115
|
+
|
|
116
|
+
oft_receipt
|
|
184
117
|
}
|
|
185
118
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
env
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
119
|
+
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
120
|
+
// 1. Pausable check
|
|
121
|
+
Self::__assert_not_paused(env);
|
|
122
|
+
|
|
123
|
+
// 2. Core credit logic (based on mode)
|
|
124
|
+
let amount_credited = match Self::oft_type(env) {
|
|
125
|
+
OftType::LockUnlock => lock_unlock::credit::<Self>(env, to, amount_ld, src_eid),
|
|
126
|
+
OftType::MintBurn => mint_burn::credit::<Self>(env, to, amount_ld, src_eid),
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// 3. Rate limit checks (using amount_credited - the actual credited amount)
|
|
130
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Inbound, src_eid, amount_credited);
|
|
131
|
+
Self::__release_rate_limit_capacity(env, &Direction::Outbound, src_eid, amount_credited);
|
|
132
|
+
|
|
133
|
+
amount_credited
|
|
194
134
|
}
|
|
135
|
+
}
|
|
195
136
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
///
|
|
200
|
-
/// # Returns
|
|
201
|
-
/// (MessagingReceipt, OFTReceipt)
|
|
202
|
-
fn send(
|
|
137
|
+
/// LzReceiveInternal implementation using default OFT receive logic
|
|
138
|
+
impl LzReceiveInternal for OFT {
|
|
139
|
+
fn __lz_receive(
|
|
203
140
|
env: &Env,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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)
|
|
210
149
|
}
|
|
211
150
|
}
|
|
151
|
+
|
|
152
|
+
// ==================== Extension Trait Implementations ====================
|
|
153
|
+
|
|
154
|
+
/// Pausable extension - allows pausing/unpausing the OFT
|
|
155
|
+
/// Default state: unpaused (all operations allowed)
|
|
156
|
+
#[contract_impl(contracttrait)]
|
|
157
|
+
impl OFTPausable for OFT {}
|
|
158
|
+
|
|
159
|
+
impl OFTPausableInternal for OFT {}
|
|
160
|
+
|
|
161
|
+
/// OFT Fee extension - allows collecting fees on transfers
|
|
162
|
+
/// Default state: 0 BPS (no fee collected)
|
|
163
|
+
#[contract_impl(contracttrait)]
|
|
164
|
+
impl OFTFee for OFT {}
|
|
165
|
+
|
|
166
|
+
impl OFTFeeInternal for OFT {}
|
|
167
|
+
|
|
168
|
+
/// Rate Limiter extension - allows rate limiting transfers
|
|
169
|
+
/// Default state: not set (rate_limit_capacity returns i128::MAX)
|
|
170
|
+
#[contract_impl(contracttrait)]
|
|
171
|
+
impl RateLimiter for OFT {}
|
|
172
|
+
|
|
173
|
+
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
|
|
7
|
+
use oft_core::{oft_core::OFTCore, types::OFTReceipt};
|
|
8
8
|
use soroban_sdk::{token::TokenClient, Address, Env};
|
|
9
9
|
|
|
10
10
|
/// Debit tokens using LockUnlock OFT type (locks tokens in contract).
|
|
@@ -18,7 +18,13 @@ use soroban_sdk::{token::TokenClient, Address, Env};
|
|
|
18
18
|
///
|
|
19
19
|
/// # Returns
|
|
20
20
|
/// `OFTReceipt` containing the amount sent and amount received
|
|
21
|
-
pub fn debit<T:
|
|
21
|
+
pub fn debit<T: OFTCore>(
|
|
22
|
+
env: &Env,
|
|
23
|
+
sender: &Address,
|
|
24
|
+
amount_ld: i128,
|
|
25
|
+
min_amount_ld: i128,
|
|
26
|
+
dst_eid: u32,
|
|
27
|
+
) -> OFTReceipt {
|
|
22
28
|
let receipt: OFTReceipt = T::__debit_view(env, amount_ld, min_amount_ld, dst_eid);
|
|
23
29
|
TokenClient::new(env, &T::token(env)).transfer(sender, env.current_contract_address(), &receipt.amount_received_ld);
|
|
24
30
|
receipt
|
|
@@ -34,15 +40,7 @@ pub fn debit<T: OFT>(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld
|
|
|
34
40
|
///
|
|
35
41
|
/// # Returns
|
|
36
42
|
/// The amount credited
|
|
37
|
-
pub fn credit<T:
|
|
43
|
+
pub fn credit<T: OFTCore>(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
|
|
38
44
|
TokenClient::new(env, &T::token(env)).transfer(&env.current_contract_address(), to, &amount_ld);
|
|
39
45
|
amount_ld
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
/// Returns whether approval is required for LockUnlock OFT type.
|
|
43
|
-
///
|
|
44
|
-
/// # Returns
|
|
45
|
-
/// Always `false` - approval not needed for transfer operations
|
|
46
|
-
pub fn approval_required() -> bool {
|
|
47
|
-
false
|
|
48
|
-
}
|
|
@@ -3,8 +3,30 @@
|
|
|
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
|
|
7
|
-
use soroban_sdk::{Address, Env};
|
|
6
|
+
use oft_core::{oft_core::OFTCore, types::OFTReceipt};
|
|
7
|
+
use soroban_sdk::{contractclient, Address, Env};
|
|
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
|
+
}
|
|
8
30
|
|
|
9
31
|
/// Debit tokens using MintBurn OFT type (burns tokens from sender).
|
|
10
32
|
///
|
|
@@ -17,7 +39,13 @@ use soroban_sdk::{Address, Env};
|
|
|
17
39
|
///
|
|
18
40
|
/// # Returns
|
|
19
41
|
/// `OFTReceipt` containing the amount sent and amount received
|
|
20
|
-
pub fn debit<T:
|
|
42
|
+
pub fn debit<T: OFTCore>(
|
|
43
|
+
env: &Env,
|
|
44
|
+
sender: &Address,
|
|
45
|
+
amount_ld: i128,
|
|
46
|
+
min_amount_ld: i128,
|
|
47
|
+
dst_eid: u32,
|
|
48
|
+
) -> OFTReceipt {
|
|
21
49
|
let receipt = T::__debit_view(env, amount_ld, min_amount_ld, dst_eid);
|
|
22
50
|
MintBurnTokenClient::new(env, &T::token(env)).burn(sender, &receipt.amount_received_ld);
|
|
23
51
|
receipt
|
|
@@ -33,15 +61,7 @@ pub fn debit<T: OFT>(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld
|
|
|
33
61
|
///
|
|
34
62
|
/// # Returns
|
|
35
63
|
/// The amount credited
|
|
36
|
-
pub fn credit<T:
|
|
64
|
+
pub fn credit<T: OFTCore>(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
|
|
37
65
|
MintBurnTokenClient::new(env, &T::token(env)).mint(to, &amount_ld);
|
|
38
66
|
amount_ld
|
|
39
67
|
}
|
|
40
|
-
|
|
41
|
-
/// Returns whether approval is required for MintBurn OFT type.
|
|
42
|
-
///
|
|
43
|
-
/// # Returns
|
|
44
|
-
/// Always `false` - approval not needed for mint/burn operations.
|
|
45
|
-
pub fn approval_required() -> bool {
|
|
46
|
-
false
|
|
47
|
-
}
|
|
@@ -6,5 +6,18 @@
|
|
|
6
6
|
//! - **LockUnlock**: Locks tokens on send, unlocks on receive. Approval not required.
|
|
7
7
|
//!
|
|
8
8
|
|
|
9
|
+
use soroban_sdk::contracttype;
|
|
10
|
+
|
|
9
11
|
pub mod lock_unlock;
|
|
10
12
|
pub mod mint_burn;
|
|
13
|
+
|
|
14
|
+
/// The type of OFT operation mode
|
|
15
|
+
#[contracttype]
|
|
16
|
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
17
|
+
#[repr(u8)]
|
|
18
|
+
pub enum OftType {
|
|
19
|
+
/// Lock tokens on send, unlock on receive
|
|
20
|
+
LockUnlock = 0,
|
|
21
|
+
/// Burn tokens on send, mint on receive
|
|
22
|
+
MintBurn = 1,
|
|
23
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "oft-
|
|
2
|
+
name = "oft-core"
|
|
3
3
|
version.workspace = true
|
|
4
4
|
edition.workspace = true
|
|
5
5
|
license.workspace = true
|
|
6
6
|
|
|
7
7
|
[lib]
|
|
8
|
-
crate-type = ["
|
|
8
|
+
crate-type = ["rlib"]
|
|
9
9
|
doctest = false
|
|
10
10
|
|
|
11
11
|
[dependencies]
|
|
@@ -14,8 +14,6 @@ endpoint-v2 = { workspace = true, features = ["library"] }
|
|
|
14
14
|
utils = { workspace = true }
|
|
15
15
|
oapp = { workspace = true }
|
|
16
16
|
common-macros = { workspace = true }
|
|
17
|
-
oapp-macros = { workspace = true }
|
|
18
|
-
oft = { workspace = true }
|
|
19
17
|
|
|
20
18
|
[dev-dependencies]
|
|
21
19
|
soroban-sdk = { workspace = true, features = ["testutils"] }
|
|
@@ -23,3 +21,7 @@ simple-message-lib = { workspace = true }
|
|
|
23
21
|
message-lib-common = { workspace = true, features = ["testutils"] }
|
|
24
22
|
endpoint-v2 = { workspace = true, features = ["testutils"] }
|
|
25
23
|
utils = { workspace = true, features = ["testutils"] }
|
|
24
|
+
insta = { workspace = true }
|
|
25
|
+
oapp-macros = { workspace = true }
|
|
26
|
+
stellar-macros = { workspace = true }
|
|
27
|
+
stellar-tokens = { workspace = true }
|