@@ -39,8 +39,6 @@ use pythnet_sdk::{
39
39
use structs:: { DataSource , DataSourceStorage , PriceInfoReturn , PriceInfoStorage } ;
40
40
use wormhole_vaas:: { Readable , Vaa , Writeable } ;
41
41
42
- const ACCUMULATOR_WORMHOLE_MAGIC : u32 = 0x41555756 ;
43
-
44
42
sol_interface ! {
45
43
interface IWormholeContract {
46
44
function initialize( address[ ] memory initial_guardians, uint16 chain_id, uint16 governance_chain_id, address governance_contract) external;
@@ -204,10 +202,10 @@ impl PythReceiver {
204
202
return Err ( PythReceiverError :: InvalidAccumulatorMessage ) ;
205
203
}
206
204
207
- let update_data = AccumulatorUpdateData :: try_from_slice ( & update_data_array)
205
+ let accumulator_update = AccumulatorUpdateData :: try_from_slice ( & update_data_array)
208
206
. map_err ( |_| PythReceiverError :: InvalidAccumulatorMessage ) ?;
209
207
210
- match update_data . proof {
208
+ match accumulator_update . proof {
211
209
Proof :: WormholeMerkle { vaa, updates } => {
212
210
let wormhole: IWormholeContract = IWormholeContract :: new ( self . wormhole . get ( ) ) ;
213
211
let config = Call :: new ( ) ;
@@ -236,10 +234,7 @@ impl PythReceiver {
236
234
237
235
let root_digest: MerkleRoot < Keccak160 > = parse_wormhole_proof ( vaa) ?;
238
236
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) ?;
243
238
244
239
let value = self . vm ( ) . msg_value ( ) ;
245
240
@@ -299,12 +294,17 @@ impl PythReceiver {
299
294
Ok ( ( ) )
300
295
}
301
296
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
+ }
308
308
}
309
309
310
310
pub fn get_twap_update_fee ( & self , _update_data : Vec < Vec < u8 > > ) -> U256 {
0 commit comments