Ayush Suresh преди 4 месеца
родител
ревизия
44431fc0fc

+ 9 - 3
target_chains/stylus/contracts/pyth-receiver/src/governance.rs

@@ -2,7 +2,10 @@ use crate::error::PythReceiverError;
 use crate::governance_structs::{self, GovernancePayload};
 use crate::structs::DataSource;
 use crate::PythReceiver;
-use crate::{DataSourcesSet, FeeSet, GovernanceDataSourceSet, TransactionFeeSet, ValidPeriodSet, FeeWithdrawn};
+use crate::{
+    DataSourcesSet, FeeSet, FeeWithdrawn, GovernanceDataSourceSet, TransactionFeeSet,
+    ValidPeriodSet,
+};
 
 use alloc::vec::Vec;
 use stylus_sdk::{
@@ -12,7 +15,7 @@ use stylus_sdk::{
 };
 use wormhole_vaas::{Readable, Vaa, Writeable};
 
-use crate::{IWormholeContract, log};
+use crate::{log, IWormholeContract};
 
 impl PythReceiver {
     pub(crate) fn execute_governance_instruction_internal(
@@ -253,7 +256,10 @@ impl PythReceiver {
     }
 }
 
-pub(crate) fn verify_governance_vm(receiver: &mut PythReceiver, vm: Vaa) -> Result<(), PythReceiverError> {
+pub(crate) fn verify_governance_vm(
+    receiver: &mut PythReceiver,
+    vm: Vaa,
+) -> Result<(), PythReceiverError> {
     if vm.body.emitter_chain != receiver.governance_data_source_chain_id.get().to::<u16>() {
         return Err(PythReceiverError::InvalidGovernanceMessage);
     }

+ 91 - 19
target_chains/stylus/contracts/pyth-receiver/src/lib.rs

@@ -10,9 +10,9 @@ mod governance;
 mod governance_structs;
 #[cfg(test)]
 mod integration_tests;
-mod pyth_operations;
 #[cfg(test)]
 mod pyth_governance_test;
+mod pyth_operations;
 mod structs;
 #[cfg(test)]
 mod test_data;
@@ -111,7 +111,6 @@ impl PythReceiver {
         }
     }
 
-
     fn is_no_older_than(&self, publish_time: U64, max_age: u64) -> bool {
         self.get_current_timestamp()
             .saturating_sub(publish_time.to::<u64>())
@@ -135,36 +134,64 @@ impl PythReceiver {
         self.price_feed_exists_internal(id)
     }
 
-    pub fn query_price_feed(&self, id: [u8; 32]) -> Result<structs::PriceFeedReturn, error::PythReceiverError> {
+    pub fn query_price_feed(
+        &self,
+        id: [u8; 32],
+    ) -> Result<structs::PriceFeedReturn, error::PythReceiverError> {
         self.query_price_feed_internal(id)
     }
 
-    pub fn get_price_unsafe(&self, id: [u8; 32]) -> Result<structs::PriceReturn, error::PythReceiverError> {
+    pub fn get_price_unsafe(
+        &self,
+        id: [u8; 32],
+    ) -> Result<structs::PriceReturn, error::PythReceiverError> {
         self.get_price_unsafe_internal(id)
     }
 
-    pub fn get_price_no_older_than(&self, id: [u8; 32], age: u64) -> Result<structs::PriceReturn, error::PythReceiverError> {
+    pub fn get_price_no_older_than(
+        &self,
+        id: [u8; 32],
+        age: u64,
+    ) -> Result<structs::PriceReturn, error::PythReceiverError> {
         self.get_price_no_older_than_internal(id, age)
     }
 
-    pub fn get_ema_price_unsafe(&self, id: [u8; 32]) -> Result<structs::PriceReturn, error::PythReceiverError> {
+    pub fn get_ema_price_unsafe(
+        &self,
+        id: [u8; 32],
+    ) -> Result<structs::PriceReturn, error::PythReceiverError> {
         self.get_ema_price_unsafe_internal(id)
     }
 
-    pub fn get_ema_price_no_older_than(&self, id: [u8; 32], age: u64) -> Result<structs::PriceReturn, error::PythReceiverError> {
+    pub fn get_ema_price_no_older_than(
+        &self,
+        id: [u8; 32],
+        age: u64,
+    ) -> Result<structs::PriceReturn, error::PythReceiverError> {
         self.get_ema_price_no_older_than_internal(id, age)
     }
 
     #[payable]
-    pub fn update_price_feeds(&mut self, update_data: Vec<Vec<u8>>) -> Result<(), error::PythReceiverError> {
+    pub fn update_price_feeds(
+        &mut self,
+        update_data: Vec<Vec<u8>>,
+    ) -> Result<(), error::PythReceiverError> {
         self.update_price_feeds_internal(update_data)
     }
 
-    pub fn update_price_feeds_if_necessary(&mut self, update_data: Vec<Vec<u8>>, price_ids: Vec<[u8; 32]>, publish_times: Vec<u64>) -> Result<(), error::PythReceiverError> {
+    pub fn update_price_feeds_if_necessary(
+        &mut self,
+        update_data: Vec<Vec<u8>>,
+        price_ids: Vec<[u8; 32]>,
+        publish_times: Vec<u64>,
+    ) -> Result<(), error::PythReceiverError> {
         self.update_price_feeds_if_necessary_internal(update_data, price_ids, publish_times)
     }
 
-    pub fn get_update_fee(&self, update_data: Vec<Vec<u8>>) -> Result<U256, error::PythReceiverError> {
+    pub fn get_update_fee(
+        &self,
+        update_data: Vec<Vec<u8>>,
+    ) -> Result<U256, error::PythReceiverError> {
         self.get_update_fee_internal(update_data)
     }
 
@@ -172,24 +199,69 @@ impl PythReceiver {
         self.get_twap_update_fee_internal(update_data)
     }
 
-    pub fn parse_price_feed_updates(&mut self, update_data: Vec<u8>, price_ids: Vec<[u8; 32]>, min_publish_time: u64, max_publish_time: u64) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
-        self.parse_price_feed_updates_internal_wrapper(update_data, price_ids, min_publish_time, max_publish_time)
+    pub fn parse_price_feed_updates(
+        &mut self,
+        update_data: Vec<u8>,
+        price_ids: Vec<[u8; 32]>,
+        min_publish_time: u64,
+        max_publish_time: u64,
+    ) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
+        self.parse_price_feed_updates_internal_wrapper(
+            update_data,
+            price_ids,
+            min_publish_time,
+            max_publish_time,
+        )
     }
 
-    pub fn parse_price_feed_updates_with_config(&mut self, update_data: Vec<Vec<u8>>, price_ids: Vec<[u8; 32]>, min_allowed_publish_time: u64, max_allowed_publish_time: u64, check_uniqueness: bool, check_update_data_is_minimal: bool, store_updates_if_fresh: bool) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
-        self.parse_price_feed_updates_with_config_internal(update_data, price_ids, min_allowed_publish_time, max_allowed_publish_time, check_uniqueness, check_update_data_is_minimal, store_updates_if_fresh)
+    pub fn parse_price_feed_updates_with_config(
+        &mut self,
+        update_data: Vec<Vec<u8>>,
+        price_ids: Vec<[u8; 32]>,
+        min_allowed_publish_time: u64,
+        max_allowed_publish_time: u64,
+        check_uniqueness: bool,
+        check_update_data_is_minimal: bool,
+        store_updates_if_fresh: bool,
+    ) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
+        self.parse_price_feed_updates_with_config_internal(
+            update_data,
+            price_ids,
+            min_allowed_publish_time,
+            max_allowed_publish_time,
+            check_uniqueness,
+            check_update_data_is_minimal,
+            store_updates_if_fresh,
+        )
     }
 
-    pub fn parse_twap_price_feed_updates(&mut self, update_data: Vec<Vec<u8>>, price_ids: Vec<[u8; 32]>) -> Vec<structs::PriceFeedReturn> {
+    pub fn parse_twap_price_feed_updates(
+        &mut self,
+        update_data: Vec<Vec<u8>>,
+        price_ids: Vec<[u8; 32]>,
+    ) -> Vec<structs::PriceFeedReturn> {
         self.parse_twap_price_feed_updates_internal(update_data, price_ids)
     }
 
-    pub fn parse_price_feed_updates_unique(&mut self, update_data: Vec<Vec<u8>>, price_ids: Vec<[u8; 32]>, min_publish_time: u64, max_publish_time: u64) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
-        self.parse_price_feed_updates_unique_internal(update_data, price_ids, min_publish_time, max_publish_time)
+    pub fn parse_price_feed_updates_unique(
+        &mut self,
+        update_data: Vec<Vec<u8>>,
+        price_ids: Vec<[u8; 32]>,
+        min_publish_time: u64,
+        max_publish_time: u64,
+    ) -> Result<Vec<structs::PriceFeedReturn>, error::PythReceiverError> {
+        self.parse_price_feed_updates_unique_internal(
+            update_data,
+            price_ids,
+            min_publish_time,
+            max_publish_time,
+        )
     }
 
-    pub fn execute_governance_instruction(&mut self, encoded_vaa: Vec<u8>) -> Result<(), error::PythReceiverError> {
+    pub fn execute_governance_instruction(
+        &mut self,
+        encoded_vaa: Vec<u8>,
+    ) -> Result<(), error::PythReceiverError> {
         self.execute_governance_instruction_internal(encoded_vaa)
     }
-
 }

+ 21 - 9
target_chains/stylus/contracts/pyth-receiver/src/pyth_operations.rs

@@ -3,11 +3,6 @@ use crate::structs::{DataSource, PriceFeedReturn, PriceReturn};
 use crate::PythReceiver;
 
 use alloc::vec::Vec;
-use stylus_sdk::{
-    alloy_primitives::{FixedBytes, I32, I64, U16, U256, U64},
-    call::Call,
-    prelude::*,
-};
 use pythnet_sdk::{
     accumulators::merkle::{MerklePath, MerkleRoot},
     hashers::keccak256_160::Keccak160,
@@ -20,6 +15,11 @@ use pythnet_sdk::{
         },
     },
 };
+use stylus_sdk::{
+    alloy_primitives::{FixedBytes, I32, I64, U16, U256, U64},
+    call::Call,
+    prelude::*,
+};
 use wormhole_vaas::{Readable, Vaa, Writeable};
 
 use crate::IWormholeContract;
@@ -31,7 +31,10 @@ impl PythReceiver {
         return price_info.publish_time.get() != U64::ZERO;
     }
 
-    pub(crate) fn query_price_feed_internal(&self, id: [u8; 32]) -> Result<PriceFeedReturn, PythReceiverError> {
+    pub(crate) fn query_price_feed_internal(
+        &self,
+        id: [u8; 32],
+    ) -> Result<PriceFeedReturn, PythReceiverError> {
         let id_fb = FixedBytes::<32>::from(id);
 
         let price_info = self.latest_price_info.get(id_fb);
@@ -51,7 +54,10 @@ impl PythReceiver {
         ))
     }
 
-    pub(crate) fn get_price_unsafe_internal(&self, id: [u8; 32]) -> Result<PriceReturn, PythReceiverError> {
+    pub(crate) fn get_price_unsafe_internal(
+        &self,
+        id: [u8; 32],
+    ) -> Result<PriceReturn, PythReceiverError> {
         let id_fb = FixedBytes::<32>::from(id);
 
         let price_info = self.latest_price_info.get(id_fb);
@@ -80,7 +86,10 @@ impl PythReceiver {
         Ok(price_info)
     }
 
-    pub(crate) fn get_ema_price_unsafe_internal(&self, id: [u8; 32]) -> Result<PriceReturn, PythReceiverError> {
+    pub(crate) fn get_ema_price_unsafe_internal(
+        &self,
+        id: [u8; 32],
+    ) -> Result<PriceReturn, PythReceiverError> {
         let id_fb = FixedBytes::<32>::from(id);
         let price_info = self.latest_price_info.get(id_fb);
 
@@ -190,7 +199,10 @@ impl PythReceiver {
         Ok(price_pairs)
     }
 
-    pub(crate) fn get_update_fee_internal(&self, update_data: Vec<Vec<u8>>) -> Result<U256, PythReceiverError> {
+    pub(crate) fn get_update_fee_internal(
+        &self,
+        update_data: Vec<Vec<u8>>,
+    ) -> Result<U256, PythReceiverError> {
         let mut total_num_updates: u64 = 0;
         for data in &update_data {
             let update_data_array: &[u8] = &data;