@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.
Files changed (138) hide show
  1. package/.turbo/turbo-build.log +275 -248
  2. package/.turbo/turbo-lint.log +52 -58
  3. package/.turbo/turbo-test.log +1224 -1358
  4. package/Cargo.lock +8 -5
  5. package/Cargo.toml +1 -1
  6. package/contracts/ERROR_SPEC.md +1 -1
  7. package/contracts/message-libs/uln-302/src/send_uln.rs +1 -1
  8. package/contracts/oapps/oapp/src/oapp_receiver.rs +1 -1
  9. package/contracts/oapps/oft/Cargo.toml +10 -7
  10. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
  11. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
  12. package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
  13. package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
  14. package/contracts/oapps/oft/integration-tests/setup.rs +28 -127
  15. package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
  16. package/contracts/oapps/oft/src/extensions/oft_fee.rs +5 -6
  17. package/contracts/oapps/oft/src/lib.rs +10 -14
  18. package/contracts/oapps/oft/src/oft.rs +151 -189
  19. package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -11
  20. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +32 -12
  21. package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
  22. package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
  23. package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
  24. package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +126 -29
  25. package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
  26. package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
  27. package/contracts/oapps/oft-core/src/lib.rs +18 -0
  28. package/contracts/oapps/oft-core/src/oft_core.rs +439 -0
  29. package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
  30. package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
  31. package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -4
  32. package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
  33. package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +44 -25
  34. package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
  35. package/contracts/utils/src/errors.rs +5 -1
  36. package/contracts/utils/src/ownable.rs +125 -3
  37. package/contracts/utils/src/tests/option_ext.rs +1 -1
  38. package/contracts/utils/src/tests/ownable.rs +445 -7
  39. package/contracts/utils/src/tests/ttl_configurable.rs +2 -2
  40. package/package.json +4 -5
  41. package/sdk/.turbo/turbo-test.log +216 -206
  42. package/sdk/dist/generated/bml.d.ts +30 -0
  43. package/sdk/dist/generated/bml.js +28 -5
  44. package/sdk/dist/generated/counter.d.ts +122 -2
  45. package/sdk/dist/generated/counter.js +36 -7
  46. package/sdk/dist/generated/dvn.d.ts +30 -0
  47. package/sdk/dist/generated/dvn.js +28 -5
  48. package/sdk/dist/generated/dvn_fee_lib.d.ts +122 -2
  49. package/sdk/dist/generated/dvn_fee_lib.js +36 -7
  50. package/sdk/dist/generated/endpoint.d.ts +122 -2
  51. package/sdk/dist/generated/endpoint.js +36 -7
  52. package/sdk/dist/generated/executor.d.ts +122 -2
  53. package/sdk/dist/generated/executor.js +36 -7
  54. package/sdk/dist/generated/executor_fee_lib.d.ts +122 -2
  55. package/sdk/dist/generated/executor_fee_lib.js +36 -7
  56. package/sdk/dist/generated/executor_helper.d.ts +30 -0
  57. package/sdk/dist/generated/executor_helper.js +28 -5
  58. package/sdk/dist/generated/oft.d.ts +1842 -0
  59. package/sdk/dist/generated/oft.js +345 -0
  60. package/sdk/dist/generated/price_feed.d.ts +122 -2
  61. package/sdk/dist/generated/price_feed.js +36 -7
  62. package/sdk/dist/generated/sml.d.ts +122 -2
  63. package/sdk/dist/generated/sml.js +36 -7
  64. package/sdk/dist/generated/treasury.d.ts +122 -2
  65. package/sdk/dist/generated/treasury.js +36 -7
  66. package/sdk/dist/generated/uln302.d.ts +122 -2
  67. package/sdk/dist/generated/uln302.js +36 -7
  68. package/sdk/dist/generated/upgrader.d.ts +15 -0
  69. package/sdk/dist/generated/upgrader.js +18 -0
  70. package/sdk/dist/index.d.ts +1 -2
  71. package/sdk/dist/index.js +1 -3
  72. package/sdk/package.json +3 -2
  73. package/sdk/src/index.ts +1 -4
  74. package/sdk/test/oft-sml.test.ts +16 -16
  75. package/sdk/turbo.json +8 -0
  76. package/tools/ts-bindings-gen/Cargo.toml +2 -0
  77. package/tools/ts-bindings-gen/src/main.rs +51 -4
  78. package/turbo.json +0 -2
  79. package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
  80. package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
  81. package/contracts/oapps/oft/src/oft_impl.rs +0 -201
  82. package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
  83. package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -917
  84. package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -751
  85. package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -434
  86. package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1080
  87. package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
  88. package/contracts/oapps/oft-std/src/lib.rs +0 -16
  89. package/contracts/oapps/oft-std/src/oft.rs +0 -174
  90. package/sdk/dist/generated/oft_std.d.ts +0 -1722
  91. package/sdk/dist/generated/oft_std.js +0 -316
  92. package/sdk/dist/wasm/blocked-message-lib.d.ts +0 -1
  93. package/sdk/dist/wasm/blocked-message-lib.js +0 -2
  94. package/sdk/dist/wasm/counter.d.ts +0 -1
  95. package/sdk/dist/wasm/counter.js +0 -2
  96. package/sdk/dist/wasm/dvn-fee-lib.d.ts +0 -1
  97. package/sdk/dist/wasm/dvn-fee-lib.js +0 -2
  98. package/sdk/dist/wasm/dvn.d.ts +0 -1
  99. package/sdk/dist/wasm/dvn.js +0 -2
  100. package/sdk/dist/wasm/endpoint-v2.d.ts +0 -1
  101. package/sdk/dist/wasm/endpoint-v2.js +0 -2
  102. package/sdk/dist/wasm/executor-fee-lib.d.ts +0 -1
  103. package/sdk/dist/wasm/executor-fee-lib.js +0 -2
  104. package/sdk/dist/wasm/executor-helper.d.ts +0 -1
  105. package/sdk/dist/wasm/executor-helper.js +0 -2
  106. package/sdk/dist/wasm/executor.d.ts +0 -1
  107. package/sdk/dist/wasm/executor.js +0 -2
  108. package/sdk/dist/wasm/layerzero-views.d.ts +0 -1
  109. package/sdk/dist/wasm/layerzero-views.js +0 -2
  110. package/sdk/dist/wasm/oft-std.d.ts +0 -1
  111. package/sdk/dist/wasm/oft-std.js +0 -2
  112. package/sdk/dist/wasm/price-feed.d.ts +0 -1
  113. package/sdk/dist/wasm/price-feed.js +0 -2
  114. package/sdk/dist/wasm/simple-message-lib.d.ts +0 -1
  115. package/sdk/dist/wasm/simple-message-lib.js +0 -2
  116. package/sdk/dist/wasm/treasury.d.ts +0 -1
  117. package/sdk/dist/wasm/treasury.js +0 -2
  118. package/sdk/dist/wasm/uln302.d.ts +0 -1
  119. package/sdk/dist/wasm/uln302.js +0 -2
  120. package/sdk/dist/wasm/upgrader.d.ts +0 -1
  121. package/sdk/dist/wasm/upgrader.js +0 -2
  122. package/sdk/dist/wasm.d.ts +0 -15
  123. package/sdk/dist/wasm.js +0 -15
  124. /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
  125. /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
  126. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
  127. /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
  128. /package/contracts/oapps/{oft → oft-core}/src/errors.rs +0 -0
  129. /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
  130. /package/contracts/oapps/{oft → oft-core}/src/storage.rs +0 -0
  131. /package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +0 -0
  132. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
  133. /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
  134. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
  135. /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
  136. /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
  137. /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
  138. /package/contracts/oapps/{oft → oft-core}/src/types.rs +0 -0
@@ -1,211 +1,173 @@
1
- //! OFT traits - the main interface for OFT contracts.
2
- //!
3
- //! This module provides two traits:
4
- //! - `OFTInternal`: Internal methods NOT exposed as contract endpoints (`__debit`, `__credit`, etc.)
5
- //! - `OFT`: Public methods exposed as contract endpoints (using `#[contracttrait]`)
6
- //!
7
- //! ## Usage
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 soroban_sdk::{Address, Bytes, Env};
54
-
55
- // =====================================================
56
- // OFTInternal Trait (NOT exposed as contract endpoints)
57
- // =====================================================
58
-
59
- /// Internal OFT trait containing methods that should NOT be exposed as contract endpoints.
60
- ///
61
- /// **IMPORTANT**: Implement this trait WITHOUT the `#[contractimpl]` macro to keep
62
- /// `__debit`, `__credit`, and other internal methods private to the contract.
63
- ///
64
- /// ```ignore
65
- /// // Correct - methods stay internal
66
- /// impl OFTInternal for MyOFT { ... }
67
- ///
68
- /// // WRONG - would expose methods as endpoints
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
- /// Builds OFT message and combines options for cross-chain transfer.
115
- fn __build_msg_and_options(
26
+ #[oapp]
27
+ pub struct OFT;
28
+
29
+ #[contract_impl]
30
+ impl OFT {
31
+ pub fn __constructor(
116
32
  env: &Env,
117
- from: &Address,
118
- send_param: &oft::types::SendParam,
119
- receive_amount_ld: i128,
120
- ) -> (Bytes, Bytes)
121
- where
122
- Self: OAppOptionsType3,
123
- {
124
- oft_impl::build_msg_and_options::<Self>(env, from, send_param, receive_amount_ld)
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
- // OFT Trait (exposed as contract endpoints)
130
- // =====================================================
131
-
132
- /// The public OFT trait defining the cross-chain token transfer interface.
133
- ///
134
- /// This trait is marked with `#[contracttrait]` so all its methods are exposed as
135
- /// contract endpoints. Users implement this with `#[contractimpl(contracttrait)]`.
136
- ///
137
- /// Internal methods like `__debit`, `__credit`, `__debit_view`, and `__build_msg_and_options`
138
- /// are in the `OFTInternal` trait and are NOT exposed as contract endpoints.
139
- #[contract_trait]
140
- pub trait OFT: OFTInternal + OAppReceiver + OAppSenderInternal + OAppOptionsType3 {
141
- /// Retrieves the token address associated with this OFT.
142
- fn token(env: &Env) -> Address {
143
- OFTStorage::token(env).unwrap()
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
- /// Returns OFT version as (major, minor).
147
- fn oft_version(_env: &Env) -> (u64, u64) {
148
- (1, 1)
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
- /// Retrieves the shared decimals used for cross-chain normalization.
152
- fn shared_decimals(env: &Env) -> u32 {
153
- let token = Self::token(env);
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
- /// Retrieves the decimal conversion rate used for cross-chain normalization.
160
- fn decimal_conversion_rate(env: &Env) -> i128 {
161
- OFTStorage::decimal_conversion_rate(env).unwrap()
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
- /// Whether a separate token approval is required before sending.
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
- /// Quotes an OFT transfer without executing.
176
- ///
177
- /// # Returns
178
- /// (OFTLimit, fee details, receipt with estimated amounts)
179
- fn quote_oft(
180
- env: &Env,
181
- send_param: &oft::types::SendParam,
182
- ) -> (oft::types::OFTLimit, soroban_sdk::Vec<oft::types::OFTFeeDetail>, oft::types::OFTReceipt) {
183
- oft_impl::quote_oft::<Self>(env, send_param)
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
- /// Quotes a send operation including LayerZero messaging fees.
187
- fn quote_send(
188
- env: &Env,
189
- sender: &Address,
190
- send_param: &oft::types::SendParam,
191
- pay_in_zro: bool,
192
- ) -> endpoint_v2::MessagingFee {
193
- oft_impl::quote_send::<Self>(env, sender, send_param, pay_in_zro)
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
- /// Sends tokens cross-chain to another endpoint.
197
- ///
198
- /// Sender must be authenticated.
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
- sender: &Address,
205
- send_param: &oft::types::SendParam,
206
- fee: &endpoint_v2::MessagingFee,
207
- refund_address: &Address,
208
- ) -> (endpoint_v2::MessagingReceipt, oft::types::OFTReceipt) {
209
- oft_impl::send::<Self>(env, sender, send_param, fee, refund_address)
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 crate::{oft::OFT, types::OFTReceipt};
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: OFT>(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
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: OFT>(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
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 crate::{interfaces::MintBurnTokenClient, oft::OFT, types::OFTReceipt};
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: OFT>(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
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: OFT>(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
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-std"
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 = ["cdylib"]
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 }
@@ -1,3 +1,3 @@
1
- pub mod extensions;
2
1
  pub mod setup;
2
+ pub mod test_with_sml;
3
3
  pub mod utils;