From b167683a7565ef4a4cff6aed11c56e4a48835c27 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 23 Jan 2024 21:02:22 +0000 Subject: [PATCH 1/7] 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 }, -} From f99482be22ade157e3517e9cf549a840513bfb3d Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 23 Jan 2024 21:04:51 +0000 Subject: [PATCH 2/7] Cleanup --- target_chains/cosmwasm/contracts/pyth/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/cosmwasm/contracts/pyth/Cargo.toml b/target_chains/cosmwasm/contracts/pyth/Cargo.toml index 2b61c11c29..d7cceb4d95 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 = [] From 6b877b9733232ac3bc53a9efe0e4ff430026b2be Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Wed, 24 Jan 2024 15:58:10 +0000 Subject: [PATCH 3/7] Pin it --- target_chains/cosmwasm/Cargo.lock | 4 ++-- target_chains/cosmwasm/Cargo.toml | 2 +- target_chains/cosmwasm/contracts/pyth/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target_chains/cosmwasm/Cargo.lock b/target_chains/cosmwasm/Cargo.lock index 5928815ec7..e4ef0835bb 100644 --- a/target_chains/cosmwasm/Cargo.lock +++ b/target_chains/cosmwasm/Cargo.lock @@ -2648,7 +2648,7 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "wormhole-cosmwasm" version = "0.1.0" -source = "git+https://github.com/wormhole-foundation/wormhole#65abbde534507d3b434119d3f4510a9b9ae969b9" +source = "git+https://github.com/wormhole-foundation/wormhole?rev=a2cb2a1226d00bada5679dc34f9d4393c9b0795d#a2cb2a1226d00bada5679dc34f9d4393c9b0795d" dependencies = [ "cosmwasm-std", "cosmwasm-storage", @@ -2670,4 +2670,4 @@ checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" [[patch.unused]] name = "cw20-wrapped-2" version = "0.1.0" -source = "git+https://github.com/wormhole-foundation/wormhole?tag=v2.14.8#7e982cb03264cf1cccfbb5d947c00d6ad3e2f8f1" +source = "git+https://github.com/wormhole-foundation/wormhole?rev=a2cb2a1226d00bada5679dc34f9d4393c9b0795d#a2cb2a1226d00bada5679dc34f9d4393c9b0795d" diff --git a/target_chains/cosmwasm/Cargo.toml b/target_chains/cosmwasm/Cargo.toml index c2b1345f50..9f9f38e127 100644 --- a/target_chains/cosmwasm/Cargo.toml +++ b/target_chains/cosmwasm/Cargo.toml @@ -14,4 +14,4 @@ incremental = false overflow-checks = true [patch.crates-io] -cw20-wrapped-2 = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.14.8"} +cw20-wrapped-2 = { git = "https://github.com/wormhole-foundation/wormhole", rev = "a2cb2a1226d00bada5679dc34f9d4393c9b0795d"} diff --git a/target_chains/cosmwasm/contracts/pyth/Cargo.toml b/target_chains/cosmwasm/contracts/pyth/Cargo.toml index d7cceb4d95..89cba92eaa 100644 --- a/target_chains/cosmwasm/contracts/pyth/Cargo.toml +++ b/target_chains/cosmwasm/contracts/pyth/Cargo.toml @@ -40,7 +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"} +wormhole-cosmwasm = {git = "https://github.com/wormhole-foundation/wormhole", rev="a2cb2a1226d00bada5679dc34f9d4393c9b0795d"} [dev-dependencies] cosmwasm-vm = { version = "1.0.0", default-features = false } From 0cb2caedd3d3f7d49d7f53cd0d67fc12be092c2f Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Wed, 24 Jan 2024 16:00:58 +0000 Subject: [PATCH 4/7] Test this CI --- .../release-pyth-cosmwasm-contract.yml | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release-pyth-cosmwasm-contract.yml b/.github/workflows/release-pyth-cosmwasm-contract.yml index 1422baa4b3..ad52df77e5 100644 --- a/.github/workflows/release-pyth-cosmwasm-contract.yml +++ b/.github/workflows/release-pyth-cosmwasm-contract.yml @@ -1,9 +1,6 @@ name: Release Pyth Cosmwasm Contract -on: - push: - tags: - - pyth-cosmwasm-contract-v* +on: pull_request jobs: release-contract: name: Build and Release cosmwasm contract @@ -36,19 +33,19 @@ jobs: PREFIX="refs/tags/pyth-cosmwasm-contract-" echo "VERSION=${GITHUB_REF:${#PREFIX}}" >> $GITHUB_ENV - - name: Release - uses: softprops/action-gh-release@v1 - with: - files: | - target_chains/cosmwasm/tools/cosmwasm.zip - target_chains/cosmwasm/tools/injective.zip - target_chains/cosmwasm/tools/osmosis.zip - body: | - Contracts - - cosmwasm.zip contains the generic cosmwasm contract for most Cosmos SDK chains. - - injective.zip contains injective specific contract. - - osmosis.zip contains osmosis specific contract. - draft: false - # Setting VERSION in set env step and hence it will be available - name: Pyth Cosmwasm Contract ${{ env.VERSION }} - tag_name: ${{ github.ref_name }} + # - name: Release + # uses: softprops/action-gh-release@v1 + # with: + # files: | + # target_chains/cosmwasm/tools/cosmwasm.zip + # target_chains/cosmwasm/tools/injective.zip + # target_chains/cosmwasm/tools/osmosis.zip + # body: | + # Contracts + # - cosmwasm.zip contains the generic cosmwasm contract for most Cosmos SDK chains. + # - injective.zip contains injective specific contract. + # - osmosis.zip contains osmosis specific contract. + # draft: false + # # Setting VERSION in set env step and hence it will be available + # name: Pyth Cosmwasm Contract ${{ env.VERSION }} + # tag_name: ${{ github.ref_name }} From dbcd6f45a20ded1a40f43a46f10809992c88ae1c Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Wed, 24 Jan 2024 16:46:12 +0000 Subject: [PATCH 5/7] Cleanup --- target_chains/cosmwasm/Cargo.lock | 5 ----- target_chains/cosmwasm/Cargo.toml | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/target_chains/cosmwasm/Cargo.lock b/target_chains/cosmwasm/Cargo.lock index e4ef0835bb..24e82fc5f3 100644 --- a/target_chains/cosmwasm/Cargo.lock +++ b/target_chains/cosmwasm/Cargo.lock @@ -2666,8 +2666,3 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" - -[[patch.unused]] -name = "cw20-wrapped-2" -version = "0.1.0" -source = "git+https://github.com/wormhole-foundation/wormhole?rev=a2cb2a1226d00bada5679dc34f9d4393c9b0795d#a2cb2a1226d00bada5679dc34f9d4393c9b0795d" diff --git a/target_chains/cosmwasm/Cargo.toml b/target_chains/cosmwasm/Cargo.toml index 9f9f38e127..969a48011f 100644 --- a/target_chains/cosmwasm/Cargo.toml +++ b/target_chains/cosmwasm/Cargo.toml @@ -2,6 +2,8 @@ members = ["contracts/pyth", "sdk/rust"] exclude = ["examples/cw-contract"] +resolver = "2" + [profile.release] opt-level = 3 debug = false @@ -12,6 +14,3 @@ codegen-units = 1 panic = 'abort' incremental = false overflow-checks = true - -[patch.crates-io] -cw20-wrapped-2 = { git = "https://github.com/wormhole-foundation/wormhole", rev = "a2cb2a1226d00bada5679dc34f9d4393c9b0795d"} From ee096f5f5fa3f4b82c16a1e0a85ad824ba1574d6 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Wed, 24 Jan 2024 16:56:37 +0000 Subject: [PATCH 6/7] Revert "Test this CI" This reverts commit 0cb2caedd3d3f7d49d7f53cd0d67fc12be092c2f. --- .../release-pyth-cosmwasm-contract.yml | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release-pyth-cosmwasm-contract.yml b/.github/workflows/release-pyth-cosmwasm-contract.yml index ad52df77e5..1422baa4b3 100644 --- a/.github/workflows/release-pyth-cosmwasm-contract.yml +++ b/.github/workflows/release-pyth-cosmwasm-contract.yml @@ -1,6 +1,9 @@ name: Release Pyth Cosmwasm Contract -on: pull_request +on: + push: + tags: + - pyth-cosmwasm-contract-v* jobs: release-contract: name: Build and Release cosmwasm contract @@ -33,19 +36,19 @@ jobs: PREFIX="refs/tags/pyth-cosmwasm-contract-" echo "VERSION=${GITHUB_REF:${#PREFIX}}" >> $GITHUB_ENV - # - name: Release - # uses: softprops/action-gh-release@v1 - # with: - # files: | - # target_chains/cosmwasm/tools/cosmwasm.zip - # target_chains/cosmwasm/tools/injective.zip - # target_chains/cosmwasm/tools/osmosis.zip - # body: | - # Contracts - # - cosmwasm.zip contains the generic cosmwasm contract for most Cosmos SDK chains. - # - injective.zip contains injective specific contract. - # - osmosis.zip contains osmosis specific contract. - # draft: false - # # Setting VERSION in set env step and hence it will be available - # name: Pyth Cosmwasm Contract ${{ env.VERSION }} - # tag_name: ${{ github.ref_name }} + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: | + target_chains/cosmwasm/tools/cosmwasm.zip + target_chains/cosmwasm/tools/injective.zip + target_chains/cosmwasm/tools/osmosis.zip + body: | + Contracts + - cosmwasm.zip contains the generic cosmwasm contract for most Cosmos SDK chains. + - injective.zip contains injective specific contract. + - osmosis.zip contains osmosis specific contract. + draft: false + # Setting VERSION in set env step and hence it will be available + name: Pyth Cosmwasm Contract ${{ env.VERSION }} + tag_name: ${{ github.ref_name }} From 57f8b5452164cebcf810f5797d4b8f168bc6cf2d Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Wed, 24 Jan 2024 16:59:05 +0000 Subject: [PATCH 7/7] Use tag --- target_chains/cosmwasm/Cargo.lock | 2 +- target_chains/cosmwasm/contracts/pyth/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target_chains/cosmwasm/Cargo.lock b/target_chains/cosmwasm/Cargo.lock index 24e82fc5f3..716fc00067 100644 --- a/target_chains/cosmwasm/Cargo.lock +++ b/target_chains/cosmwasm/Cargo.lock @@ -2648,7 +2648,7 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "wormhole-cosmwasm" version = "0.1.0" -source = "git+https://github.com/wormhole-foundation/wormhole?rev=a2cb2a1226d00bada5679dc34f9d4393c9b0795d#a2cb2a1226d00bada5679dc34f9d4393c9b0795d" +source = "git+https://github.com/wormhole-foundation/wormhole?tag=v2.23.37#846c2e9c9dce18a48745e79ba2ee7eaa5acaf1f4" dependencies = [ "cosmwasm-std", "cosmwasm-storage", diff --git a/target_chains/cosmwasm/contracts/pyth/Cargo.toml b/target_chains/cosmwasm/contracts/pyth/Cargo.toml index 89cba92eaa..0ea3b0418e 100644 --- a/target_chains/cosmwasm/contracts/pyth/Cargo.toml +++ b/target_chains/cosmwasm/contracts/pyth/Cargo.toml @@ -40,7 +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", rev="a2cb2a1226d00bada5679dc34f9d4393c9b0795d"} +wormhole-cosmwasm = {git = "https://github.com/wormhole-foundation/wormhole", tag="v2.23.37"} [dev-dependencies] cosmwasm-vm = { version = "1.0.0", default-features = false }