@layerzerolabs/protocol-stellar-v2 0.2.46 → 0.2.48

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.
@@ -348,4 +348,8 @@ impl IDvnFeeLib for MockFeeLib {
348
348
  params.multiplier_bps as i128
349
349
  }
350
350
  }
351
+
352
+ fn version(_env: &Env) -> (u64, u32) {
353
+ (1, 1)
354
+ }
351
355
  }
@@ -63,6 +63,10 @@ impl IDvnFeeLib for DvnFeeLib {
63
63
  fee_result.native_price_usd,
64
64
  )
65
65
  }
66
+
67
+ fn version(_env: &Env) -> (u64, u32) {
68
+ (1, 1)
69
+ }
66
70
  }
67
71
 
68
72
  // ============================================================================
@@ -73,4 +73,10 @@ pub trait IDvnFeeLib {
73
73
  /// # Returns
74
74
  /// The calculated fee in native token units (stroops for Stellar).
75
75
  fn get_fee(env: &Env, dvn: &Address, params: &DvnFeeParams) -> i128;
76
+
77
+ /// Returns the fee library contract version.
78
+ ///
79
+ /// # Returns
80
+ /// Tuple of (major version, minor version).
81
+ fn version(env: &Env) -> (u64, u32);
76
82
  }
@@ -1,6 +1,7 @@
1
1
  use common_macros::{contract_impl, lz_contract, only_auth};
2
2
  use fee_lib_interfaces::{FeeEstimate, ILayerZeroPriceFeed, Price};
3
- use soroban_sdk::{assert_with_error, panic_with_error, Address, Env, Vec};
3
+ use soroban_sdk::{assert_with_error, Address, Env, Vec};
4
+ use utils::option_ext::OptionExt;
4
5
 
5
6
  use crate::{
6
7
  errors::PriceFeedError,
@@ -110,7 +111,7 @@ impl LzPriceFeed {
110
111
 
111
112
  /// Set prices for multiple destinations (price updater or owner)
112
113
  pub fn set_price(env: &Env, price_updater: &Address, prices: &Vec<UpdatePrice>) {
113
- Self::require_price_updater(env, price_updater);
114
+ Self::require_owner_or_price_updater(env, price_updater);
114
115
 
115
116
  prices.iter().for_each(|update| Self::set_price_internal(env, update.eid, &update.price));
116
117
  }
@@ -118,7 +119,7 @@ impl LzPriceFeed {
118
119
  /// Set price for Arbitrum with extension (price updater or owner)
119
120
  /// Corresponds to setPriceForArbitrum in PriceFeed.sol
120
121
  pub fn set_price_for_arbitrum(env: &Env, price_updater: &Address, update: &UpdatePriceExt) {
121
- Self::require_price_updater(env, price_updater);
122
+ Self::require_owner_or_price_updater(env, price_updater);
122
123
 
123
124
  Self::set_price_internal(env, update.eid, &update.price);
124
125
 
@@ -131,7 +132,7 @@ impl LzPriceFeed {
131
132
  ///
132
133
  /// Kept as a standalone contract function (not part of the canonical `fee_lib_interfaces::ILayerZeroPriceFeed` interface).
133
134
  pub fn set_native_token_price_usd(env: &Env, price_updater: &Address, native_token_price_usd: u128) {
134
- Self::require_price_updater(env, price_updater);
135
+ Self::require_owner_or_price_updater(env, price_updater);
135
136
  PriceFeedStorage::set_native_price_usd(env, &native_token_price_usd);
136
137
  }
137
138
 
@@ -171,7 +172,7 @@ impl LzPriceFeed {
171
172
 
172
173
  /// Estimate fee with default model
173
174
  fn estimate_fee_with_default_model(env: &Env, dst_eid: u32, calldata_size: u32, gas: u128) -> (u128, u128) {
174
- let price = Self::get_price(env, dst_eid).unwrap_or_else(|| panic_with_error!(env, PriceFeedError::NoPrice));
175
+ let price = Self::get_price(env, dst_eid).unwrap_or_panic(env, PriceFeedError::NoPrice);
175
176
 
176
177
  // assuming the _gas includes (1) the 21,000 overhead and (2) not the calldata gas
177
178
  let gas_for_calldata = (calldata_size as u128) * (price.gas_per_byte as u128);
@@ -183,17 +184,14 @@ impl LzPriceFeed {
183
184
 
184
185
  /// Estimate fee with Optimism model
185
186
  fn estimate_fee_with_optimism_model(env: &Env, dst_eid: u32, calldata_size: u32, gas: u128) -> (u128, u128) {
186
- let ethereum_id = Self::get_l1_lookup_id_for_optimism_model(env, dst_eid);
187
-
188
187
  // L1 fee (Ethereum)
189
- let ethereum_price =
190
- Self::get_price(env, ethereum_id).unwrap_or_else(|| panic_with_error!(env, PriceFeedError::NoPrice));
188
+ let ethereum_id = Self::get_l1_lookup_id_for_optimism_model(env, dst_eid);
189
+ let ethereum_price = Self::get_price(env, ethereum_id).unwrap_or_panic(env, PriceFeedError::NoPrice);
191
190
  let gas_for_l1_calldata = ((calldata_size as u128) * (ethereum_price.gas_per_byte as u128)) + 3188; // 2100 + 68 * 16
192
191
  let l1_fee = gas_for_l1_calldata * (ethereum_price.gas_price_in_unit as u128);
193
192
 
194
193
  // L2 fee (Optimism)
195
- let optimism_price =
196
- Self::get_price(env, dst_eid).unwrap_or_else(|| panic_with_error!(env, PriceFeedError::NoPrice));
194
+ let optimism_price = Self::get_price(env, dst_eid).unwrap_or_panic(env, PriceFeedError::NoPrice);
197
195
  let gas_for_l2_calldata = (calldata_size as u128) * (optimism_price.gas_per_byte as u128);
198
196
  let l2_fee = (gas_for_l2_calldata + gas) * (optimism_price.gas_price_in_unit as u128);
199
197
 
@@ -207,16 +205,13 @@ impl LzPriceFeed {
207
205
 
208
206
  /// Estimate fee with Arbitrum model
209
207
  fn estimate_fee_with_arbitrum_model(env: &Env, dst_eid: u32, calldata_size: u32, gas: u128) -> (u128, u128) {
210
- let arbitrum_price =
211
- Self::get_price(env, dst_eid).unwrap_or_else(|| panic_with_error!(env, PriceFeedError::NoPrice));
212
-
213
- let arbitrum_price_ext = Self::arbitrum_price_ext(env);
214
-
215
208
  // L1 fee (compressed calldata)
209
+ let arbitrum_price_ext = Self::arbitrum_price_ext(env);
216
210
  let gas_for_l1_calldata = (((calldata_size as u128) * Self::arbitrum_compression_percent(env)) / 100)
217
211
  * (arbitrum_price_ext.gas_per_l1_calldata_byte as u128);
218
212
 
219
213
  // L2 fee
214
+ let arbitrum_price = Self::get_price(env, dst_eid).unwrap_or_panic(env, PriceFeedError::NoPrice);
220
215
  let gas_for_l2_calldata = (calldata_size as u128) * (arbitrum_price.gas_per_byte as u128);
221
216
  let gas_fee = (gas + (arbitrum_price_ext.gas_per_l2_tx as u128) + gas_for_l1_calldata + gas_for_l2_calldata)
222
217
  * (arbitrum_price.gas_price_in_unit as u128);
@@ -251,18 +246,12 @@ impl LzPriceFeed {
251
246
  }
252
247
 
253
248
  /// Check if caller is price updater or owner
254
- fn require_price_updater(env: &Env, caller: &Address) {
249
+ fn require_owner_or_price_updater(env: &Env, caller: &Address) {
255
250
  caller.require_auth();
256
-
257
- // Owner is always approved
258
- if let Some(owner) = Self::owner(env) {
259
- if &owner == caller {
260
- return;
261
- }
262
- }
263
-
264
- // Check if caller is an active price updater
265
- assert_with_error!(env, Self::is_price_updater(env, caller), PriceFeedError::OnlyPriceUpdater);
251
+ assert_with_error!(
252
+ env,
253
+ Self::owner(env).as_ref() == Some(caller) || Self::is_price_updater(env, caller),
254
+ PriceFeedError::OnlyPriceUpdater
255
+ );
266
256
  }
267
257
  }
268
-
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@layerzerolabs/protocol-stellar-v2",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "private": false,
5
5
  "license": "LZBL-1.2",
6
6
  "devDependencies": {
7
7
  "@types/node": "^22.18.6",
8
8
  "tsx": "^4.19.3",
9
9
  "typescript": "^5.8.2",
10
- "@layerzerolabs/common-node-utils": "0.2.46",
11
- "@layerzerolabs/stellar-ts-bindings-gen": "0.2.46",
12
- "@layerzerolabs/vm-tooling-stellar": "0.2.46"
10
+ "@layerzerolabs/stellar-ts-bindings-gen": "0.2.48",
11
+ "@layerzerolabs/common-node-utils": "0.2.48",
12
+ "@layerzerolabs/vm-tooling-stellar": "0.2.48"
13
13
  },
14
14
  "publishConfig": {
15
15
  "access": "restricted",