Jelajahi Sumber

figuring out mini-alloc

Ayush Suresh 4 bulan lalu
induk
melakukan
9eef20ae05

+ 1 - 2
target_chains/stylus/Cargo.lock

@@ -3878,12 +3878,11 @@ dependencies = [
  "ethers",
  "eyre",
  "hex",
- "pyth-types",
+ "mini-alloc 0.4.2",
  "pythnet-sdk",
  "serde",
  "stylus-sdk 0.9.0",
  "tokio",
- "wormhole-contract",
  "wormhole-vaas",
 ]
 

+ 2 - 3
target_chains/stylus/contracts/pyth-receiver/Cargo.toml

@@ -13,11 +13,10 @@ alloy-sol-types = "=0.8.20"
 stylus-sdk = "0.9.0"
 byteorder = { version = "1.4.3" }
 hex = { version = "0.4", default-features = false }
+mini-alloc = { workspace = true, default-features = false }
 pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
-pyth-types = { path = "../pyth-types" }
 serde = { version = "1.0", features = ["derive"] }
 wormhole-vaas = "0.1.1"
-wormhole-contract = { path = "../../contracts/wormhole" }
 
 
 [dev-dependencies]
@@ -49,4 +48,4 @@ panic = "abort"
 
 # If you need to reduce the binary size, it is advisable to try other
 # optimization levels, such as "s" and "z"
-opt-level = 3
+opt-level = "s"

+ 2 - 2
target_chains/stylus/contracts/pyth-receiver/src/integration_tests.rs

@@ -27,7 +27,7 @@ mod test {
 
     fn initialize_test_contract(vm: &TestVM) -> PythReceiver {
         let mut contract = PythReceiver::from(vm);
-        let wormhole_address = address!("0x3F38404A2e3Cb949bcDfA19a5C3bDf3fE375fEb0");
+        let wormhole_address = address!("0x395921b642ba511d421ae834fef56ac886735ca2");
         let single_update_fee = U256::from(100u64);
         let valid_time_period = U256::from(3600u64);
 
@@ -130,7 +130,7 @@ mod test {
 
         let test_price_id = TEST_PRICE_ID;
 
-        let update_data = create_valid_update_data();
+        let update_data = test_data::good_update1();
         let _result = contract.update_price_feeds(update_data);
 
 

+ 57 - 60
target_chains/stylus/contracts/pyth-receiver/src/lib.rs

@@ -154,14 +154,14 @@ impl PythReceiver {
         Ok(())
     }
 
-    pub fn update_price_feeds_if_necessary(
-        &mut self,
-        _update_data: Vec<Vec<u8>>,
-        _price_ids: Vec<[u8; 32]>,
-        _publish_times: Vec<u64>,
-    ) {
-        // dummy implementation
-    }
+    // pub fn update_price_feeds_if_necessary(
+    //     &mut self,
+    //     _update_data: Vec<Vec<u8>>,
+    //     _price_ids: Vec<[u8; 32]>,
+    //     _publish_times: Vec<u64>,
+    // ) {
+    //     // dummy implementation
+    // }
 
     // fn update_price_feeds_internal(&mut self, update_data: Vec<u8>, price_ids: Vec<Address>, min_publish_time: u64, max_publish_time: u64, unique: bool) -> Result<(), PythReceiverError> {
     fn update_price_feeds_internal(&mut self, update_data: Vec<u8>) -> Result<(), PythReceiverError> {
@@ -240,60 +240,57 @@ impl PythReceiver {
         Ok(())
     }
 
-    pub fn get_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
-        U256::from(0u8)
-    }
-
-    pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
-        U256::from(0u8)
-    }
-
-    pub fn parse_price_feed_updates(
-        &mut self,
-        _update_data: Vec<Vec<u8>>,
-        _price_ids: Vec<[u8; 32]>,
-        _min_publish_time: u64,
-        _max_publish_time: u64,
-    ) -> Vec<PriceInfoReturn> {
-        Vec::new()
-    }
-
-    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,
-    ) -> (Vec<PriceInfoReturn>, Vec<u64>) {
-        (Vec::new(), Vec::new())
-    }
-
-    pub fn parse_twap_price_feed_updates(
-        &mut self,
-        _update_data: Vec<Vec<u8>>,
-        _price_ids: Vec<[u8; 32]>,
-    ) -> Vec<PriceInfoReturn> {
-        Vec::new()
-    }
-
-    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,
-    ) -> Vec<PriceInfoReturn> {
-        Vec::new()
-    }
+    // pub fn get_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
+    //     U256::from(0u8)
+    // }
+
+    // pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
+    //     U256::from(0u8)
+    // }
+
+    // pub fn parse_price_feed_updates(
+    //     &mut self,
+    //     _update_data: Vec<Vec<u8>>,
+    //     _price_ids: Vec<[u8; 32]>,
+    //     _min_publish_time: u64,
+    //     _max_publish_time: u64,
+    // ) -> Vec<PriceInfoReturn> {
+    //     Vec::new()
+    // }
+
+    // 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,
+    // ) -> (Vec<PriceInfoReturn>, Vec<u64>) {
+    //     (Vec::new(), Vec::new())
+    // }
+
+    // pub fn parse_twap_price_feed_updates(
+    //     &mut self,
+    //     _update_data: Vec<Vec<u8>>,
+    //     _price_ids: Vec<[u8; 32]>,
+    // ) -> Vec<PriceInfoReturn> {
+    //     Vec::new()
+    // }
+
+    // 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,
+    // ) -> Vec<PriceInfoReturn> {
+    //     Vec::new()
+    // }
 
     fn is_no_older_than(&self, publish_time: U64, max_age: u64) -> bool {
-        let current_u64: u64 = self.vm().block_timestamp();
-        let publish_time_u64: u64 = publish_time.to::<u64>();
-
-        current_u64.saturating_sub(publish_time_u64) <= max_age
+        self.vm().block_timestamp().saturating_sub(publish_time.to::<u64>()) <= max_age
     }
 }
 

+ 29 - 29
target_chains/stylus/contracts/pyth-receiver/src/structs.rs

@@ -46,17 +46,17 @@ pub struct DataSource {
     pub emitter_address: FixedBytes<32>,
 }
 
-impl StorageKey for DataSourceStorage {
-    fn to_slot(&self, root: B256) -> U256 {
-        let chain_id: u16 = self.chain_id.get().to::<u16>();
-        let emitter_address = self.emitter_address.get();
+// impl StorageKey for DataSourceStorage {
+//     fn to_slot(&self, root: B256) -> U256 {
+//         let chain_id: u16 = self.chain_id.get().to::<u16>();
+//         let emitter_address = self.emitter_address.get();
 
-        let bytes = serialize_data_source_to_bytes(chain_id, emitter_address.as_slice().try_into().unwrap())
-            .expect("Failed to serialize DataSource");
+//         let bytes = serialize_data_source_to_bytes(chain_id, emitter_address.as_slice().try_into().unwrap())
+//             .expect("Failed to serialize DataSource");
 
-        keccak256(bytes).to_slot(root)
-    }
-}
+//         keccak256(bytes).to_slot(root)
+//     }
+// }
 
 impl StorageKey for DataSource {
     fn to_slot(&self, root: B256) -> U256 {
@@ -97,27 +97,27 @@ pub struct PriceInfoStorage {
     pub ema_conf: StorageU64,
 }
 
-pub struct PriceInfo {
-    pub publish_time: U64,
-    pub expo: I32,
-    pub price: I64,
-    pub conf: U64,
-    pub ema_price: I64,
-    pub ema_conf: U64,
-}
+// pub struct PriceInfo {
+//     pub publish_time: U64,
+//     pub expo: I32,
+//     pub price: I64,
+//     pub conf: U64,
+//     pub ema_price: I64,
+//     pub ema_conf: U64,
+// }
 
-impl From<&PriceFeedMessage> for PriceInfo {
-    fn from(price_feed_message: &PriceFeedMessage) -> Self {
-        Self {
-            publish_time: U64::from(price_feed_message.publish_time),
-            expo: I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
-            price: I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
-            conf: U64::from(price_feed_message.conf),
-            ema_price: I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
-            ema_conf: U64::from(price_feed_message.ema_conf),
-        }
-    }
-}
+// impl From<&PriceFeedMessage> for PriceInfo {
+//     fn from(price_feed_message: &PriceFeedMessage) -> Self {
+//         Self {
+//             publish_time: U64::from(price_feed_message.publish_time),
+//             expo: I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
+//             price: I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
+//             conf: U64::from(price_feed_message.conf),
+//             ema_price: I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
+//             ema_conf: U64::from(price_feed_message.ema_conf),
+//         }
+//     }
+// }
 
 // PriceInfo struct storing price information
 pub type PriceInfoReturn = (U64, I32, I64, U64, I64, U64);

+ 1 - 1
target_chains/stylus/contracts/wormhole/src/lib.rs

@@ -5,7 +5,7 @@ extern crate alloc;
 #[global_allocator]
 static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT;
 
-#[cfg(all(not(any(feature = "std", feature = "export-abi")), feature = "main"))]
+#[cfg(all(not(any(feature = "std", feature = "export-abi"))))]
 #[panic_handler]
 fn panic(_info: &core::panic::PanicInfo) -> ! {
     loop {}