瀏覽代碼

Debug commit

m30m 2 年之前
父節點
當前提交
ee67301166

+ 7 - 2
pythnet/pythnet_sdk/src/wire.rs

@@ -87,11 +87,16 @@ pub mod v1 {
     // A hash of some data.
     pub type Hash = [u8; 20];
 
+    #[derive(Clone, Debug, Hash, PartialEq, Serialize, Deserialize)]
+    pub struct Poof {
+        pub dummy: u64,
+    }
+
     #[derive(Clone, Debug, Hash, PartialEq, Serialize, Deserialize)]
     pub enum Proof {
         WormholeMerkle {
-            vaa:     PrefixedVec<u16, u8>,
-            updates: Vec<MerklePriceUpdate>,
+            vaa:     u8,
+            updates: u8,
         },
     }
 

+ 1 - 1
pythnet/pythnet_sdk/src/wire/de.rs

@@ -73,7 +73,7 @@ pub enum DeserializerError {
     Unsupported,
 
     #[error("sequence too large ({0} elements), max supported is 255")]
-    SequenceTooLarge(usize),
+    SequenceTooLarge(u16),
 
     #[error("message: {0}")]
     Message(Box<str>),

+ 1 - 1
target_chains/cosmwasm/contracts/pyth/Cargo.toml

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 # IMPORTANT: if you want to build for injective or osmosis, enable injective default feature for injective
 # and osmosis default feature for osmosis
 # default=["injective"]
-# default=["osmosis"]
+default=["osmosis"]
 backtraces = ["cosmwasm-std/backtraces"]
 # use library feature to disable all init/handle/query exports
 library = []

+ 68 - 66
target_chains/cosmwasm/contracts/pyth/src/contract.rs

@@ -505,63 +505,65 @@ fn process_accumulator(
     env: &Env,
     data: &[u8],
 ) -> StdResult<(usize, Vec<PriceFeed>)> {
+    
     let update_data = AccumulatorUpdateData::try_from_slice(data)
         .map_err(|_| PythContractError::InvalidAccumulatorPayload)?;
-    match update_data.proof {
-        Proof::WormholeMerkle { vaa, updates } => {
-            let parsed_vaa = parse_and_verify_vaa(
-                deps.branch(),
-                env.block.time.seconds(),
-                &Binary::from(Vec::from(vaa)),
-            )?;
-            let state = config_read(deps.storage).load()?;
-            verify_vaa_from_data_source(&state, &parsed_vaa)?;
-
-            let msg = WormholeMessage::try_from_bytes(parsed_vaa.payload)
-                .map_err(|_| PythContractError::InvalidWormholeMessage)?;
-
-            let root: MerkleRoot<Keccak160> = MerkleRoot::new(match msg.payload {
-                WormholePayload::Merkle(merkle_root) => merkle_root.root,
-            });
-            let update_len = updates.len();
-            let mut new_feeds = vec![];
-            for update in updates {
-                let message_vec = Vec::from(update.message);
-                if !root.check(update.proof, &message_vec) {
-                    return Err(PythContractError::InvalidMerkleProof)?;
-                }
-
-                let msg = from_slice::<BigEndian, Message>(&message_vec)
-                    .map_err(|_| PythContractError::InvalidAccumulatorMessage)?;
-
-                match msg {
-                    Message::PriceFeedMessage(price_feed_message) => {
-                        let price_feed = PriceFeed::new(
-                            PriceIdentifier::new(price_feed_message.id),
-                            Price {
-                                price:        price_feed_message.price,
-                                conf:         price_feed_message.conf,
-                                expo:         price_feed_message.exponent,
-                                publish_time: price_feed_message.publish_time,
-                            },
-                            Price {
-                                price:        price_feed_message.ema_price,
-                                conf:         price_feed_message.ema_conf,
-                                expo:         price_feed_message.exponent,
-                                publish_time: price_feed_message.publish_time,
-                            },
-                        );
-
-                        if update_price_feed_if_new(deps, env, price_feed)? {
-                            new_feeds.push(price_feed);
-                        }
-                    }
-                    _ => return Err(PythContractError::InvalidAccumulatorMessageType)?,
-                }
-            }
-            Ok((update_len, new_feeds))
-        }
-    }
+    return Ok((0, vec![]));
+    // match update_data.proof {
+    //     Proof::WormholeMerkle { vaa, updates } => {
+    //         let parsed_vaa = parse_and_verify_vaa(
+    //             deps.branch(),
+    //             env.block.time.seconds(),
+    //             &Binary::from(Vec::from(vaa)),
+    //         )?;
+    //         let state = config_read(deps.storage).load()?;
+    //         verify_vaa_from_data_source(&state, &parsed_vaa)?;
+
+    //         let msg = WormholeMessage::try_from_bytes(parsed_vaa.payload)
+    //             .map_err(|_| PythContractError::InvalidWormholeMessage)?;
+
+    //         let root: MerkleRoot<Keccak160> = MerkleRoot::new(match msg.payload {
+    //             WormholePayload::Merkle(merkle_root) => merkle_root.root,
+    //         });
+    //         let update_len = updates.len();
+    //         let mut new_feeds = vec![];
+    //         for update in updates {
+    //             let message_vec = Vec::from(update.message);
+    //             if !root.check(update.proof, &message_vec) {
+    //                 return Err(PythContractError::InvalidMerkleProof)?;
+    //             }
+
+    //             let msg = from_slice::<BigEndian, Message>(&message_vec)
+    //                 .map_err(|_| PythContractError::InvalidAccumulatorMessage)?;
+
+    //             match msg {
+    //                 Message::PriceFeedMessage(price_feed_message) => {
+    //                     let price_feed = PriceFeed::new(
+    //                         PriceIdentifier::new(price_feed_message.id),
+    //                         Price {
+    //                             price:        price_feed_message.price,
+    //                             conf:         price_feed_message.conf,
+    //                             expo:         price_feed_message.exponent,
+    //                             publish_time: price_feed_message.publish_time,
+    //                         },
+    //                         Price {
+    //                             price:        price_feed_message.ema_price,
+    //                             conf:         price_feed_message.ema_conf,
+    //                             expo:         price_feed_message.exponent,
+    //                             publish_time: price_feed_message.publish_time,
+    //                         },
+    //                     );
+
+    //                     if update_price_feed_if_new(deps, env, price_feed)? {
+    //                         new_feeds.push(price_feed);
+    //                     }
+    //                 }
+    //                 _ => return Err(PythContractError::InvalidAccumulatorMessageType)?,
+    //             }
+    //         }
+    //         Ok((update_len, new_feeds))
+    //     }
+    // }
 }
 
 /// Update the on-chain storage for any new price updates provided in `batch_attestation`.
@@ -680,18 +682,18 @@ pub fn get_update_fee_amount(deps: &Deps, vaas: &[Binary]) -> StdResult<u128> {
 
     let mut total_updates: u128 = 0;
     for datum in vaas {
-        let header = datum.get(0..4);
-        if header == Some(PYTHNET_ACCUMULATOR_UPDATE_MAGIC.as_slice()) {
-            let update_data = AccumulatorUpdateData::try_from_slice(datum)
-                .map_err(|_| PythContractError::InvalidAccumulatorPayload)?;
-            match update_data.proof {
-                Proof::WormholeMerkle { vaa: _, updates } => {
-                    total_updates += updates.len() as u128;
-                }
-            }
-        } else {
+        // let header = datum.get(0..4);
+        // if header == Some(PYTHNET_ACCUMULATOR_UPDATE_MAGIC.as_slice()) {
+        //     let update_data = AccumulatorUpdateData::try_from_slice(datum)
+        //         .map_err(|_| PythContractError::InvalidAccumulatorPayload)?;
+        //     match update_data.proof {
+        //         Proof::WormholeMerkle { vaa: _, updates } => {
+        //             total_updates += updates.len() as u128;
+        //         }
+        //     }
+        // } else {
             total_updates += 1;
-        }
+        // }
     }
 
     Ok(config

+ 1 - 0
target_chains/cosmwasm/contracts/pyth/src/lib.rs

@@ -6,6 +6,7 @@ pub mod governance;
 pub mod msg;
 pub mod state;
 pub mod wormhole;
+pub use pythnet_sdk::wire::v1::Proof;
 
 #[cfg(feature = "injective")]
 mod injective;

+ 6 - 0
target_chains/cosmwasm/tools/Dockerfile

@@ -0,0 +1,6 @@
+FROM cosmwasm/workspace-optimizer:0.12.11
+
+ADD target_chains/cosmwasm/ /code
+ADD wormhole_attester /wormhole_attester
+ADD pythnet /pythnet
+RUN optimize_workspace.sh

+ 1 - 0
target_chains/cosmwasm/tools/src/build-contract.ts

@@ -80,6 +80,7 @@ function build() {
 
   const buildCommand = `
           docker run --rm -v "$(cd ..; pwd)":/code \
+          -v "$(cd ../../../pythnet; pwd)":/pythnet \
           -v "$(cd ../../../wormhole_attester; pwd)":/wormhole_attester \
           --mount type=volume,source="$(basename "$(cd ..; pwd)")_cache",target=/code/target \
           --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \

+ 6 - 0
target_chains/cosmwasm/tools/src/deployer/config.ts

@@ -53,6 +53,12 @@ export const CONFIG: Config = {
       endpoint: "https://rpc-test.osmosis.zone:443",
     },
   },
+  [NETWORKS.OSMOSIS_TESTNET_5]: {
+    type: CONFIG_TYPE.OSMOSIS,
+    host: {
+      endpoint: "https://rpc.osmotest5.osmosis.zone:443",
+    },
+  },
   [NETWORKS.OSMOSIS_LOCAL]: {
     type: CONFIG_TYPE.OSMOSIS,
     host: {

+ 1 - 0
target_chains/cosmwasm/tools/src/network.ts

@@ -5,6 +5,7 @@ export enum NETWORKS {
   INJECTIVE_MAINNET = "injective_mainnet",
   INJECTIVE_TESTNET = "injective_testnet",
   OSMOSIS_TESTNET = "osmosis_testnet",
+  OSMOSIS_TESTNET_5 = "osmosis_testnet_5",
   OSMOSIS_LOCAL = "osmosis_local",
 }
 

+ 13 - 0
target_chains/cosmwasm/tools/src/pyth_config.ts

@@ -154,6 +154,19 @@ export const CONFIG: Config = {
     },
     ...PYTH_SOURCES_TESTNET,
   },
+  [NETWORKS.OSMOSIS_TESTNET_5]: {
+    wormhole_contract:
+      "osmo1hggkxr0hpw83f8vuft7ruvmmamsxmwk2hzz6nytdkzyup9krt0dq27sgyx",
+    governance_source_index: 0,
+    governance_sequence_number: 0,
+    chain_id: 20,
+    valid_time_period_secs: 60,
+    fee: {
+      amount: "1",
+      denom: "uosmo",
+    },
+    ...PYTH_SOURCES_TESTNET,
+  },
   // this details below are invalid and random
   // they are to be used only for for testing purposes
   [NETWORKS.OSMOSIS_LOCAL]: {