From 3e62fdf837193d33b6b4669b81dc8216a52334fd Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 23 Jan 2024 21:02:22 +0000 Subject: [PATCH] Use ParsedVaa from wormhole contract --- target_chains/cosmwasm/Cargo.lock | 17 +++++++ .../cosmwasm/contracts/pyth/Cargo.toml | 3 +- .../cosmwasm/contracts/pyth/src/contract.rs | 18 ++++---- .../cosmwasm/contracts/pyth/src/lib.rs | 1 - .../cosmwasm/contracts/pyth/src/wormhole.rs | 46 ------------------- 5 files changed, 28 insertions(+), 57 deletions(-) delete mode 100644 target_chains/cosmwasm/contracts/pyth/src/wormhole.rs diff --git a/target_chains/cosmwasm/Cargo.lock b/target_chains/cosmwasm/Cargo.lock index 975f236742..5928815ec7 100644 --- a/target_chains/cosmwasm/Cargo.lock +++ b/target_chains/cosmwasm/Cargo.lock @@ -1486,6 +1486,7 @@ dependencies = [ "sha3 0.9.1", "terraswap", "thiserror", + "wormhole-cosmwasm", ] [[package]] @@ -2644,6 +2645,22 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "wormhole-cosmwasm" +version = "0.1.0" +source = "git+https://github.com/wormhole-foundation/wormhole#65abbde534507d3b434119d3f4510a9b9ae969b9" +dependencies = [ + "cosmwasm-std", + "cosmwasm-storage", + "generic-array", + "hex", + "k256", + "schemars", + "serde", + "sha3 0.9.1", + "thiserror", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/target_chains/cosmwasm/contracts/pyth/Cargo.toml b/target_chains/cosmwasm/contracts/pyth/Cargo.toml index 7d716d5e4e..2b61c11c29 100644 --- a/target_chains/cosmwasm/contracts/pyth/Cargo.toml +++ b/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 = [] @@ -40,6 +40,7 @@ cosmwasm-schema = "1.1.9" osmosis-std = "0.15.2" pyth-sdk-cw = { path = "../../sdk/rust" } pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" } +wormhole-cosmwasm = {git = "https://github.com/wormhole-foundation/wormhole"} [dev-dependencies] cosmwasm-vm = { version = "1.0.0", default-features = false } diff --git a/target_chains/cosmwasm/contracts/pyth/src/contract.rs b/target_chains/cosmwasm/contracts/pyth/src/contract.rs index 218ac4b47a..055afa004d 100644 --- a/target_chains/cosmwasm/contracts/pyth/src/contract.rs +++ b/target_chains/cosmwasm/contracts/pyth/src/contract.rs @@ -34,10 +34,6 @@ use { ConfigInfo, PythDataSource, }, - wormhole::{ - ParsedVAA, - WormholeQueryMsg, - }, }, byteorder::BigEndian, cosmwasm_std::{ @@ -60,6 +56,10 @@ use { WasmMsg, WasmQuery, }, + cw_wormhole::{ + msg::QueryMsg as WormholeQueryMsg, + state::ParsedVAA, + }, pyth_sdk::{ Identifier, UnixTimestamp, @@ -1095,28 +1095,28 @@ mod test { #[cfg(feature = "osmosis")] fn check_sufficient_fee(deps: &Deps, data: &[Binary]) { let mut info = mock_info("123", coins(100, "foo").as_slice()); - let result = is_fee_sufficient(&deps, info.clone(), &data); + let result = is_fee_sufficient(deps, info.clone(), data); assert_eq!(result, Ok(true)); // insufficient fee in base denom -> false info.funds = coins(50, "foo"); - let result = is_fee_sufficient(&deps, info.clone(), &data); + let result = is_fee_sufficient(deps, info.clone(), data); assert_eq!(result, Ok(false)); // valid denoms are 'uion' or 'ibc/FF3065989E34457F342D4EFB8692406D49D4E2B5C70F725F127862E22CE6BDCD' // a valid denom other than base denom with sufficient fee info.funds = coins(100, "uion"); - let result = is_fee_sufficient(&deps, info.clone(), &data); + let result = is_fee_sufficient(deps, info.clone(), data); assert_eq!(result, Ok(true)); // insufficient fee in valid denom -> false info.funds = coins(50, "uion"); - let result = is_fee_sufficient(&deps, info.clone(), &data); + let result = is_fee_sufficient(deps, info.clone(), data); assert_eq!(result, Ok(false)); // an invalid denom -> Err invalid fee denom info.funds = coins(100, "invalid_denom"); - let result = is_fee_sufficient(&deps, info, &data); + let result = is_fee_sufficient(deps, info, data); assert_eq!( result, Err(PythContractError::InvalidFeeDenom { diff --git a/target_chains/cosmwasm/contracts/pyth/src/lib.rs b/target_chains/cosmwasm/contracts/pyth/src/lib.rs index 98c98d3937..9d485196b4 100644 --- a/target_chains/cosmwasm/contracts/pyth/src/lib.rs +++ b/target_chains/cosmwasm/contracts/pyth/src/lib.rs @@ -5,7 +5,6 @@ pub mod contract; pub mod governance; pub mod msg; pub mod state; -pub mod wormhole; #[cfg(feature = "injective")] mod injective; diff --git a/target_chains/cosmwasm/contracts/pyth/src/wormhole.rs b/target_chains/cosmwasm/contracts/pyth/src/wormhole.rs deleted file mode 100644 index 41fcfac377..0000000000 --- a/target_chains/cosmwasm/contracts/pyth/src/wormhole.rs +++ /dev/null @@ -1,46 +0,0 @@ -// These types are copied from the Wormhole contract. See the links with each type to see the original code -// The reason to do so was dependency conflict. Wormhole contracts were using a very old version of a dependency -// which is not compatible with the one used by osmosis-sdk. And since we weren't using anything else from -// the Wormhole contract the types are moved here. - -use { - cosmwasm_std::Binary, - schemars::JsonSchema, - serde::{ - Deserialize, - Serialize, - }, -}; - -type HumanAddr = String; - -// This type is copied from -// https://github.com/wormhole-foundation/wormhole/blob/main/cosmwasm/contracts/wormhole/src/state.rs#L75 -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct ParsedVAA { - pub version: u8, - pub guardian_set_index: u32, - pub timestamp: u32, - pub nonce: u32, - pub len_signers: u8, - - pub emitter_chain: u16, - pub emitter_address: Vec, - pub sequence: u64, - pub consistency_level: u8, - pub payload: Vec, - - pub hash: Vec, -} - - -// The type is copied from -// https://github.com/wormhole-foundation/wormhole/blob/main/cosmwasm/contracts/wormhole/src/msg.rs#L37 -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum WormholeQueryMsg { - GuardianSetInfo {}, - VerifyVAA { vaa: Binary, block_time: u64 }, - GetState {}, - QueryAddressHex { address: HumanAddr }, -}