Skip to content

Commit 94bf971

Browse files
committed
fixed get_update_fee function to match other EVM contracts
1 parent e3155fd commit 94bf971

File tree

1 file changed

+14
-14
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+14
-14
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ use pythnet_sdk::{
3939
use structs::{DataSource, DataSourceStorage, PriceInfoReturn, PriceInfoStorage};
4040
use wormhole_vaas::{Readable, Vaa, Writeable};
4141

42-
const ACCUMULATOR_WORMHOLE_MAGIC: u32 = 0x41555756;
43-
4442
sol_interface! {
4543
interface IWormholeContract {
4644
function initialize(address[] memory initial_guardians, uint16 chain_id, uint16 governance_chain_id, address governance_contract) external;
@@ -204,10 +202,10 @@ impl PythReceiver {
204202
return Err(PythReceiverError::InvalidAccumulatorMessage);
205203
}
206204

207-
let update_data = AccumulatorUpdateData::try_from_slice(&update_data_array)
205+
let accumulator_update = AccumulatorUpdateData::try_from_slice(&update_data_array)
208206
.map_err(|_| PythReceiverError::InvalidAccumulatorMessage)?;
209207

210-
match update_data.proof {
208+
match accumulator_update.proof {
211209
Proof::WormholeMerkle { vaa, updates } => {
212210
let wormhole: IWormholeContract = IWormholeContract::new(self.wormhole.get());
213211
let config = Call::new();
@@ -236,10 +234,7 @@ impl PythReceiver {
236234

237235
let root_digest: MerkleRoot<Keccak160> = parse_wormhole_proof(vaa)?;
238236

239-
let num_updates =
240-
u8::try_from(updates.len()).map_err(|_| PythReceiverError::TooManyUpdates)?;
241-
242-
let total_fee = self.get_total_fee(num_updates);
237+
let total_fee = self.get_update_fee(update_data)?;
243238

244239
let value = self.vm().msg_value();
245240

@@ -299,12 +294,17 @@ impl PythReceiver {
299294
Ok(())
300295
}
301296

302-
fn get_total_fee(&self, num_updates: u8) -> U256 {
303-
U256::from(num_updates).saturating_mul(self.single_update_fee_in_wei.get())
304-
}
305-
306-
pub fn get_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
307-
U256::from(0u8)
297+
fn get_update_fee(&self, update_data: Vec<u8>) -> Result<U256, PythReceiverError> {
298+
let update_data_array: &[u8] = &update_data;
299+
let accumulator_update = AccumulatorUpdateData::try_from_slice(&update_data_array)
300+
.map_err(|_| PythReceiverError::InvalidAccumulatorMessage)?;
301+
match accumulator_update.proof {
302+
Proof::WormholeMerkle { vaa: _, updates } => {
303+
let num_updates =
304+
u8::try_from(updates.len()).map_err(|_| PythReceiverError::TooManyUpdates)?;
305+
Ok(U256::from(num_updates).saturating_mul(self.single_update_fee_in_wei.get()))
306+
}
307+
}
308308
}
309309

310310
pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {

0 commit comments

Comments
 (0)