@layerzerolabs/protocol-stellar-v2 0.2.65 → 0.2.66

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 (48) hide show
  1. package/.turbo/turbo-build.log +218 -299
  2. package/.turbo/turbo-lint.log +225 -98
  3. package/.turbo/turbo-test.log +2010 -1924
  4. package/Cargo.lock +0 -16
  5. package/Cargo.toml +0 -1
  6. package/contracts/oapps/oft/integration-tests/extensions/test_oft_fee.rs +22 -0
  7. package/contracts/oapps/oft/integration-tests/extensions/test_pausable.rs +9 -2
  8. package/contracts/oapps/oft/integration-tests/extensions/test_rate_limiter.rs +27 -2
  9. package/contracts/oapps/oft/integration-tests/setup.rs +22 -18
  10. package/contracts/oapps/oft/integration-tests/utils.rs +81 -34
  11. package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -0
  12. package/contracts/oapps/oft/src/oft.rs +10 -2
  13. package/package.json +4 -4
  14. package/sdk/.turbo/turbo-test.log +299 -307
  15. package/sdk/dist/generated/oft.d.ts +3 -3
  16. package/sdk/dist/generated/oft.js +3 -3
  17. package/sdk/node_modules/.bin/vitest +2 -2
  18. package/sdk/package.json +1 -1
  19. package/contracts/oapps/console-oft/Cargo.toml +0 -30
  20. package/contracts/oapps/console-oft/integration-tests/extensions/mod.rs +0 -5
  21. package/contracts/oapps/console-oft/integration-tests/extensions/test_combined.rs +0 -90
  22. package/contracts/oapps/console-oft/integration-tests/extensions/test_oft_fee.rs +0 -186
  23. package/contracts/oapps/console-oft/integration-tests/extensions/test_ownership.rs +0 -161
  24. package/contracts/oapps/console-oft/integration-tests/extensions/test_pausable.rs +0 -154
  25. package/contracts/oapps/console-oft/integration-tests/extensions/test_rate_limiter.rs +0 -479
  26. package/contracts/oapps/console-oft/integration-tests/mod.rs +0 -3
  27. package/contracts/oapps/console-oft/integration-tests/setup.rs +0 -303
  28. package/contracts/oapps/console-oft/integration-tests/utils.rs +0 -685
  29. package/contracts/oapps/console-oft/src/errors.rs +0 -7
  30. package/contracts/oapps/console-oft/src/extensions/mod.rs +0 -3
  31. package/contracts/oapps/console-oft/src/extensions/oft_fee.rs +0 -239
  32. package/contracts/oapps/console-oft/src/extensions/pausable.rs +0 -185
  33. package/contracts/oapps/console-oft/src/extensions/rate_limiter.rs +0 -478
  34. package/contracts/oapps/console-oft/src/interfaces/mintable.rs +0 -14
  35. package/contracts/oapps/console-oft/src/interfaces/mod.rs +0 -3
  36. package/contracts/oapps/console-oft/src/lib.rs +0 -26
  37. package/contracts/oapps/console-oft/src/oft.rs +0 -208
  38. package/contracts/oapps/console-oft/src/oft_access_control.rs +0 -93
  39. package/contracts/oapps/console-oft/src/oft_types/lock_unlock.rs +0 -50
  40. package/contracts/oapps/console-oft/src/oft_types/mint_burn.rs +0 -50
  41. package/contracts/oapps/console-oft/src/oft_types/mod.rs +0 -24
  42. package/contracts/oapps/console-oft/src/tests/extensions/mod.rs +0 -3
  43. package/contracts/oapps/console-oft/src/tests/extensions/oft_fee.rs +0 -255
  44. package/contracts/oapps/console-oft/src/tests/extensions/pausable.rs +0 -212
  45. package/contracts/oapps/console-oft/src/tests/extensions/rate_limiter.rs +0 -992
  46. package/contracts/oapps/console-oft/src/tests/mod.rs +0 -2
  47. package/contracts/oapps/console-oft/src/tests/oft_types/lock_unlock.rs +0 -185
  48. package/contracts/oapps/console-oft/src/tests/oft_types/mod.rs +0 -1
@@ -1,239 +0,0 @@
1
- use common_macros::{contract_error, contract_trait, only_role, storage};
2
- use soroban_sdk::{assert_with_error, contractevent, token::TokenClient, Address, Env};
3
- use utils::rbac::{RoleBasedAccessControl, AUTHORIZER};
4
-
5
- /// Role for fee configuration (set_default_fee_bps, set_fee_bps).
6
- pub const FEE_CONFIG_MANAGER_ROLE: &str = "FEE_CONFIG_MANAGER_ROLE";
7
-
8
- /// Base fee in basis points (10,000 BPS = 100%)
9
- /// Used as denominator in fee calculations
10
- pub const BASE_FEE_BPS: u32 = 10_000;
11
-
12
- // =========================================================================
13
- // Storage
14
- // =========================================================================
15
-
16
- #[storage]
17
- pub enum OFTFeeStorage {
18
- /// Default fee rate in basis points (0-10,000, where 10,000 = 100%)
19
- #[instance(u32)]
20
- #[default(0)]
21
- DefaultFeeBps,
22
-
23
- /// Destination-specific fee rates mapped by Destination ID
24
- #[persistent(u32)]
25
- FeeBps { id: u128 },
26
-
27
- /// Address where collected fees will be deposited
28
- #[instance(Address)]
29
- FeeDeposit,
30
- }
31
-
32
- // =========================================================================
33
- // Errors
34
- // =========================================================================
35
-
36
- #[contract_error]
37
- pub enum OFTFeeError {
38
- InvalidBps = 3100,
39
- SameValue,
40
- }
41
-
42
- // =========================================================================
43
- // Events
44
- // =========================================================================
45
-
46
- #[contractevent]
47
- #[derive(Clone, Debug, Eq, PartialEq)]
48
- pub struct DefaultFeeBpsSet {
49
- pub fee_bps: u32,
50
- }
51
-
52
- #[contractevent]
53
- #[derive(Clone, Debug, Eq, PartialEq)]
54
- pub struct FeeBpsSet {
55
- pub id: u128,
56
- /// The fee rate in basis points, or None if the fee is removed
57
- pub fee_bps: Option<u32>,
58
- }
59
-
60
- #[contractevent]
61
- #[derive(Clone, Debug, Eq, PartialEq)]
62
- pub struct FeeDepositSet {
63
- #[topic]
64
- pub fee_deposit: Address,
65
- }
66
-
67
- // =========================================================================
68
- // Trait With Default Implementations
69
- // =========================================================================
70
-
71
- #[contract_trait]
72
- pub trait OFTFee: OFTFeeInternal + RoleBasedAccessControl {
73
- // =========================================================================
74
- // Management Functions
75
- // =========================================================================
76
-
77
- /// Sets the default fee rate in basis points (0-10,000, where 10,000 = 100%).
78
- ///
79
- /// Setting to 0 removes the default fee from storage (effective rate becomes 0).
80
- ///
81
- /// * `operator` - The address that must have FEE_CONFIG_MANAGER_ROLE
82
- #[only_role(operator, FEE_CONFIG_MANAGER_ROLE)]
83
- fn set_default_fee_bps(env: &soroban_sdk::Env, default_fee_bps: u32, operator: &soroban_sdk::Address) {
84
- Self::__set_default_fee_bps(env, default_fee_bps);
85
- }
86
-
87
- /// Sets or removes the fee rate for a specific Destination ID.
88
- ///
89
- /// - `Some(0)`: explicitly sets zero fee for this Destination ID, overriding the default fee.
90
- /// - `None`: removes the per-Destination ID override; falls back to the default fee.
91
- ///
92
- /// # Arguments
93
- /// * `id` - The Destination ID
94
- /// * `fee_bps` - The fee rate (0-10,000), or None to remove the fee configuration
95
- /// * `operator` - The address that must have FEE_CONFIG_MANAGER_ROLE
96
- #[only_role(operator, FEE_CONFIG_MANAGER_ROLE)]
97
- fn set_fee_bps(env: &soroban_sdk::Env, id: u128, fee_bps: &Option<u32>, operator: &soroban_sdk::Address) {
98
- Self::__set_fee_bps(env, id, fee_bps);
99
- }
100
-
101
- /// Sets the address where collected fees will be deposited.
102
- ///
103
- /// # Arguments
104
- /// * `fee_deposit` - The address to deposit fees to
105
- /// * `operator` - The authorizer address
106
- #[only_role(operator, AUTHORIZER)]
107
- fn set_fee_deposit(env: &soroban_sdk::Env, fee_deposit: &soroban_sdk::Address, operator: &soroban_sdk::Address) {
108
- Self::__set_fee_deposit(env, fee_deposit);
109
- }
110
-
111
- // =========================================================================
112
- // View Functions
113
- // =========================================================================
114
-
115
- /// Calculates the fee for a given amount and Destination ID.
116
- /// Returns `(amount * fee_bps) / 10,000`, rounded down.
117
- fn get_fee(env: &soroban_sdk::Env, id: u128, amount: i128) -> i128 {
118
- Self::__get_fee(env, id, amount)
119
- }
120
-
121
- /// Given an amount after fee deduction, calculates the original amount before the fee.
122
- /// Inverse of `get_fee`: if `fee = get_fee(id, original)` and `after = original - fee`,
123
- /// then `get_amount_before_fee(id, after)` returns `original`.
124
- fn get_amount_before_fee(env: &soroban_sdk::Env, id: u128, amount_after_fee: i128) -> i128 {
125
- let fee_bps = Self::__effective_fee_bps(env, id);
126
- if fee_bps == BASE_FEE_BPS {
127
- return 0;
128
- }
129
- (amount_after_fee * BASE_FEE_BPS as i128) / (BASE_FEE_BPS - fee_bps) as i128
130
- }
131
-
132
- /// Returns the default fee rate in basis points (0 if unset).
133
- fn default_fee_bps(env: &soroban_sdk::Env) -> u32 {
134
- Self::__default_fee_bps(env)
135
- }
136
-
137
- /// Returns the fee rate for a specific Destination ID, if set.
138
- fn fee_bps(env: &soroban_sdk::Env, id: u128) -> Option<u32> {
139
- Self::__fee_bps(env, id)
140
- }
141
-
142
- /// Returns the fee deposit address.
143
- fn fee_deposit(env: &soroban_sdk::Env) -> soroban_sdk::Address {
144
- Self::__fee_deposit(env)
145
- }
146
- }
147
-
148
- /// Internal trait for OFT fee operations used by OFT hooks.
149
- /// Contains only truly internal methods that are called from OFTFee implementations.
150
- pub trait OFTFeeInternal {
151
- // =========================================================================
152
- // OFT Hooks
153
- // =========================================================================
154
-
155
- /// Charges the fee by transferring the fee amount from the sender to the fee deposit address.
156
- /// Used internally by `__debit` to collect the fee.
157
- ///
158
- /// # Arguments
159
- /// * `token` - The token address to transfer
160
- /// * `from` - The address to transfer fee from
161
- /// * `fee_amount` - The fee amount to transfer
162
- fn __charge_fee(env: &Env, token: &Address, from: &Address, fee_amount: i128) {
163
- if fee_amount != 0 {
164
- TokenClient::new(env, token).transfer(from, Self::__fee_deposit(env), &fee_amount);
165
- }
166
- }
167
-
168
- // =========================================================================
169
- // Management Functions
170
- // =========================================================================
171
-
172
- /// Sets the default fee rate in basis points.
173
- ///
174
- /// # Arguments
175
- /// * `default_fee_bps` - The default fee rate (0-10,000, where 10,000 = 100%). 0 removes the entry from storage.
176
- fn __set_default_fee_bps(env: &Env, default_fee_bps: u32) {
177
- assert_with_error!(env, default_fee_bps <= BASE_FEE_BPS, OFTFeeError::InvalidBps);
178
- if default_fee_bps == 0 {
179
- OFTFeeStorage::remove_default_fee_bps(env);
180
- } else {
181
- OFTFeeStorage::set_default_fee_bps(env, &default_fee_bps);
182
- }
183
- DefaultFeeBpsSet { fee_bps: default_fee_bps }.publish(env);
184
- }
185
-
186
- /// Sets or removes the fee rate for a specific Destination ID.
187
- ///
188
- /// - `Some(0)`: explicitly sets zero fee for this Destination ID, overriding the default fee.
189
- /// - `None`: removes the per-Destination ID override; falls back to the default fee.
190
- ///
191
- /// # Arguments
192
- /// * `id` - The Destination ID
193
- /// * `fee_bps` - The fee rate (0-10,000), or None to remove the fee configuration
194
- fn __set_fee_bps(env: &Env, id: u128, fee_bps: &Option<u32>) {
195
- assert_with_error!(env, fee_bps.is_none_or(|bps| bps <= BASE_FEE_BPS), OFTFeeError::InvalidBps);
196
- OFTFeeStorage::set_or_remove_fee_bps(env, id, fee_bps);
197
- FeeBpsSet { id, fee_bps: *fee_bps }.publish(env);
198
- }
199
-
200
- /// Sets the address where collected fees will be deposited.
201
- /// Called during construction to ensure the fee deposit is always initialized.
202
- ///
203
- /// # Arguments
204
- /// * `fee_deposit` - The address to deposit fees to
205
- fn __set_fee_deposit(env: &Env, fee_deposit: &Address) {
206
- assert_with_error!(env, OFTFeeStorage::fee_deposit(env).as_ref() != Some(fee_deposit), OFTFeeError::SameValue);
207
- OFTFeeStorage::set_fee_deposit(env, fee_deposit);
208
- FeeDepositSet { fee_deposit: fee_deposit.clone() }.publish(env);
209
- }
210
-
211
- // =========================================================================
212
- // View Functions
213
- // =========================================================================
214
-
215
- fn __get_fee(env: &Env, id: u128, amount: i128) -> i128 {
216
- let fee_bps = Self::__effective_fee_bps(env, id);
217
- (amount * fee_bps as i128) / BASE_FEE_BPS as i128
218
- }
219
-
220
- /// Returns the effective fee rate for a Destination ID (Destination ID-specific or default).
221
- fn __effective_fee_bps(env: &Env, id: u128) -> u32 {
222
- Self::__fee_bps(env, id).unwrap_or_else(|| Self::__default_fee_bps(env))
223
- }
224
-
225
- /// Returns the default fee rate in basis points (0 if unset).
226
- fn __default_fee_bps(env: &Env) -> u32 {
227
- OFTFeeStorage::default_fee_bps(env)
228
- }
229
-
230
- /// Returns the fee rate for a specific Destination ID, if set.
231
- fn __fee_bps(env: &Env, id: u128) -> Option<u32> {
232
- OFTFeeStorage::fee_bps(env, id)
233
- }
234
-
235
- /// Returns the fee deposit address
236
- fn __fee_deposit(env: &Env) -> Address {
237
- OFTFeeStorage::fee_deposit(env).unwrap()
238
- }
239
- }
@@ -1,185 +0,0 @@
1
- use common_macros::{contract_error, contract_trait, storage};
2
- use soroban_sdk::{assert_with_error, contractevent, Env, Symbol};
3
- use utils::rbac::{ensure_role, RoleBasedAccessControl};
4
-
5
- /// Role for pausing the contract.
6
- pub const PAUSER_ROLE: &str = "PAUSER_ROLE";
7
-
8
- /// Role for unpausing the contract.
9
- pub const UNPAUSER_ROLE: &str = "UNPAUSER_ROLE";
10
-
11
- // =========================================================================
12
- // Storage
13
- // =========================================================================
14
-
15
- #[storage]
16
- pub enum OFTPausableStorage {
17
- #[instance(bool)]
18
- #[default(false)]
19
- DefaultPaused,
20
-
21
- #[persistent(bool)]
22
- PauseConfigs { id: u128 },
23
- }
24
-
25
- // =========================================================================
26
- // Errors
27
- // =========================================================================
28
-
29
- #[contract_error]
30
- pub enum OFTPausableError {
31
- Paused = 3110,
32
- PauseStateIdempotent,
33
- }
34
-
35
- // =========================================================================
36
- // Events
37
- // =========================================================================
38
-
39
- #[contractevent]
40
- #[derive(Clone, Debug, Eq, PartialEq)]
41
- pub struct DefaultPauseSet {
42
- pub paused: bool,
43
- }
44
-
45
- #[contractevent]
46
- #[derive(Clone, Debug, Eq, PartialEq)]
47
- pub struct PauseSet {
48
- pub id: u128,
49
- pub paused: Option<bool>,
50
- }
51
-
52
- // =========================================================================
53
- // Trait With Default Implementations
54
- // =========================================================================
55
-
56
- #[contract_trait]
57
- pub trait OFTPausable: OFTPausableInternal + RoleBasedAccessControl {
58
- // =========================================================================
59
- // Management Functions
60
- // =========================================================================
61
-
62
- /// Sets the global default pause state.
63
- ///
64
- /// Destinations without a per-Destination ID override will inherit this default.
65
- /// Requires `PAUSER_ROLE` if pausing, `UNPAUSER_ROLE` if unpausing.
66
- ///
67
- /// # Arguments
68
- /// * `paused` - `true` to pause, `false` to unpause
69
- /// * `operator` - The address that must have PAUSER_ROLE or UNPAUSER_ROLE
70
- fn set_default_paused(env: &soroban_sdk::Env, paused: bool, operator: &soroban_sdk::Address) {
71
- operator.require_auth();
72
- match paused {
73
- true => ensure_role::<Self>(env, &Symbol::new(env, PAUSER_ROLE), operator),
74
- false => ensure_role::<Self>(env, &Symbol::new(env, UNPAUSER_ROLE), operator),
75
- };
76
- Self::__set_default_paused(env, paused);
77
- }
78
-
79
- /// Sets the paused state for a single Destination ID.
80
- ///
81
- /// - `Some(true)` — set per-Destination ID override to paused
82
- /// - `Some(false)` — set per-Destination ID override to unpaused
83
- /// - `None` — remove the per-Destination ID override, fall back to global default
84
- ///
85
- /// Caller must have `PAUSER_ROLE` if the effective state resolves to paused,
86
- /// or `UNPAUSER_ROLE` if it resolves to unpaused.
87
- ///
88
- /// # Arguments
89
- /// * `id` - The Destination ID
90
- /// * `paused` - The pause override, or None to remove the override
91
- /// * `operator` - The address that must have the required role(s)
92
- fn set_paused(env: &soroban_sdk::Env, id: u128, paused: Option<bool>, operator: &soroban_sdk::Address) {
93
- operator.require_auth();
94
-
95
- let default_paused = Self::default_paused(env);
96
- let effective_paused = paused.unwrap_or(default_paused);
97
-
98
- if effective_paused {
99
- ensure_role::<Self>(env, &Symbol::new(env, PAUSER_ROLE), operator);
100
- } else {
101
- ensure_role::<Self>(env, &Symbol::new(env, UNPAUSER_ROLE), operator);
102
- }
103
-
104
- Self::__set_paused(env, id, paused);
105
- }
106
-
107
- // =========================================================================
108
- // View Functions
109
- // =========================================================================
110
-
111
- /// Returns the effective paused state for the given Destination ID.
112
- ///
113
- /// Resolves per-Destination ID override if set, otherwise returns the global default.
114
- fn is_paused(env: &soroban_sdk::Env, id: u128) -> bool {
115
- Self::__is_paused(env, id)
116
- }
117
-
118
- /// Returns the global default pause state (used when no per-Destination ID override is set).
119
- fn default_paused(env: &soroban_sdk::Env) -> bool {
120
- OFTPausableStorage::default_paused(env)
121
- }
122
-
123
- /// Returns the raw per-Destination ID pause override, or `None` if no override is set.
124
- fn pause_config(env: &soroban_sdk::Env, id: u128) -> Option<bool> {
125
- OFTPausableStorage::pause_configs(env, id)
126
- }
127
- }
128
-
129
- /// Internal trait for pausable operations used by OFT hooks.
130
- /// Contains only truly internal methods that are called from OFTPausable implementations.
131
- pub trait OFTPausableInternal {
132
- // =========================================================================
133
- // OFT Hooks
134
- // =========================================================================
135
-
136
- /// Asserts that the OFT is not paused for the given Destination ID, panics otherwise.
137
- /// Used internally by `__debit` (send path) to enforce pause state.
138
- ///
139
- /// # Errors
140
- /// * `Paused` - If the OFT is currently paused for the given Destination ID.
141
- fn __assert_not_paused(env: &Env, id: u128) {
142
- assert_with_error!(env, !Self::__is_paused(env, id), OFTPausableError::Paused);
143
- }
144
-
145
- // =========================================================================
146
- // Management Functions
147
- // =========================================================================
148
-
149
- /// Sets the global default pause state. Reverts if already in the requested state.
150
- ///
151
- /// # Arguments
152
- /// * `paused` - `true` to pause, `false` to unpause
153
- fn __set_default_paused(env: &Env, paused: bool) {
154
- assert_with_error!(
155
- env,
156
- OFTPausableStorage::default_paused(env) != paused,
157
- OFTPausableError::PauseStateIdempotent
158
- );
159
- if paused {
160
- OFTPausableStorage::set_default_paused(env, &true);
161
- } else {
162
- OFTPausableStorage::remove_default_paused(env);
163
- }
164
- DefaultPauseSet { paused }.publish(env);
165
- }
166
-
167
- /// Sets the paused state for a single Destination ID.
168
- ///
169
- /// # Arguments
170
- /// * `id` - The Destination ID
171
- /// * `paused` - The pause override, or None to remove the override
172
- fn __set_paused(env: &Env, id: u128, paused: Option<bool>) {
173
- OFTPausableStorage::set_or_remove_pause_configs(env, id, &paused);
174
- PauseSet { id, paused }.publish(env);
175
- }
176
-
177
- // =========================================================================
178
- // View Functions
179
- // =========================================================================
180
-
181
- /// Returns the effective paused state for the given Destination ID (per-Destination ID override or global default).
182
- fn __is_paused(env: &Env, id: u128) -> bool {
183
- OFTPausableStorage::pause_configs(env, id).unwrap_or_else(|| OFTPausableStorage::default_paused(env))
184
- }
185
- }