Bläddra i källkod

[cosmwasm] pyth-sdk-cw (#575)

* pyth-sdk-cw

* update contract to use pyth-sdk-cw

* update schema

* update tilt config

* pre commit hooks

* remove raw schema
Dev Kalra 2 år sedan
förälder
incheckning
7f991bbdbc

+ 10 - 0
target_chains/cosmwasm/Cargo.lock

@@ -1264,6 +1264,7 @@ dependencies = [
  "k256 0.9.6",
  "lazy_static",
  "pyth-sdk 0.7.0",
+ "pyth-sdk-cw",
  "pyth-wormhole-attester-sdk",
  "schemars",
  "serde",
@@ -1301,6 +1302,15 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "pyth-sdk-cw"
+version = "0.1.0"
+dependencies = [
+ "cosmwasm-schema",
+ "cosmwasm-std",
+ "pyth-sdk 0.7.0",
+]
+
 [[package]]
 name = "pyth-wormhole-attester-sdk"
 version = "0.1.1"

+ 1 - 1
target_chains/cosmwasm/Cargo.toml

@@ -1,5 +1,5 @@
 [workspace]
-members = ["contracts/pyth"]
+members = ["contracts/pyth", "pyth-sdk-cw"]
 exclude = ["examples/cw-contract"]
 
 [profile.release]

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

@@ -32,6 +32,7 @@ pyth-wormhole-attester-sdk = { path = "../../../../wormhole_attester/sdk/rust" }
 pyth-sdk = "0.7.0"
 byteorder = "1.4.3"
 cosmwasm-schema = "1.1.9"
+pyth-sdk-cw = { path = "../../pyth-sdk-cw" }
 
 [dev-dependencies]
 cosmwasm-vm = { version = "1.0.0", default-features = false }

+ 9 - 9
target_chains/cosmwasm/contracts/pyth/src/contract.rs

@@ -16,7 +16,6 @@ use {
             ExecuteMsg,
             InstantiateMsg,
             MigrateMsg,
-            PriceFeedResponse,
             QueryMsg,
         },
         state::{
@@ -29,8 +28,6 @@ use {
             PythDataSource,
         },
         Price,
-        PriceFeed,
-        PriceIdentifier,
     },
     cosmwasm_std::{
         coin,
@@ -54,6 +51,11 @@ use {
         WasmMsg,
         WasmQuery,
     },
+    pyth_sdk_cw::{
+        PriceFeed,
+        PriceFeedResponse,
+        PriceIdentifier,
+    },
     pyth_wormhole_attester_sdk::{
         BatchPriceAttestation,
         PriceAttestation,
@@ -487,12 +489,9 @@ pub fn get_valid_time_period(deps: &Deps) -> StdResult<Duration> {
 mod test {
     use {
         super::*,
-        crate::{
-            governance::GovernanceModule::{
-                Executor,
-                Target,
-            },
-            PriceIdentifier,
+        crate::governance::GovernanceModule::{
+            Executor,
+            Target,
         },
         cosmwasm_std::{
             coins,
@@ -513,6 +512,7 @@ mod test {
             SystemResult,
             Uint128,
         },
+        pyth_sdk_cw::PriceIdentifier,
         pyth_wormhole_attester_sdk::PriceAttestation,
         std::time::Duration,
     };

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

@@ -7,9 +7,4 @@ pub mod governance;
 pub mod msg;
 pub mod state;
 
-pub use pyth_sdk::{
-    Price,
-    PriceFeed,
-    PriceIdentifier,
-    ProductIdentifier,
-};
+pub use pyth_sdk::Price;

+ 3 - 27
target_chains/cosmwasm/contracts/pyth/src/msg.rs

@@ -1,18 +1,11 @@
+pub use pyth_sdk_cw::QueryMsg;
 use {
-    crate::{
-        state::PythDataSource,
-        PriceFeed,
-        PriceIdentifier,
-    },
-    cosmwasm_schema::{
-        cw_serde,
-        QueryResponses,
-    },
+    crate::state::PythDataSource,
+    cosmwasm_schema::cw_serde,
     cosmwasm_std::{
         Binary,
         Coin,
     },
-    std::time::Duration,
 };
 
 // cw_serde attribute is equivalent to
@@ -47,20 +40,3 @@ pub enum ExecuteMsg {
 #[derive(Eq)]
 #[cw_serde]
 pub struct MigrateMsg {}
-
-
-#[cw_serde]
-#[derive(QueryResponses)]
-pub enum QueryMsg {
-    #[returns(PriceFeedResponse)]
-    PriceFeed { id: PriceIdentifier },
-    #[returns(Coin)]
-    GetUpdateFee { vaas: Vec<Binary> },
-    #[returns(Duration)]
-    GetValidTimePeriod,
-}
-
-#[cw_serde]
-pub struct PriceFeedResponse {
-    pub price_feed: PriceFeed,
-}

+ 1 - 1
target_chains/cosmwasm/contracts/pyth/src/state.rs

@@ -1,5 +1,4 @@
 use {
-    crate::PriceFeed,
     cosmwasm_std::{
         Addr,
         Binary,
@@ -17,6 +16,7 @@ use {
         ReadonlySingleton,
         Singleton,
     },
+    pyth_sdk_cw::PriceFeed,
     schemars::JsonSchema,
     serde::{
         Deserialize,

+ 17 - 0
target_chains/cosmwasm/pyth-sdk-cw/Cargo.toml

@@ -0,0 +1,17 @@
+[package]
+name = "pyth-sdk-cw"
+version = "0.1.0"
+authors = ["Pyth Data Foundation"]
+edition = "2018"
+license = "Apache-2.0"
+homepage = "https://pyth.network"
+repository = "https://github.com/pyth-network/pyth-crosschain"
+description = "Data structures and utilites for the Pyth price oracle"
+keywords = [ "pyth", "oracle", "cosmwasm" ]
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+pyth-sdk = "0.7.0"
+cosmwasm-std = { version = "1.0.0" }
+cosmwasm-schema = "1.1.9"

+ 32 - 0
target_chains/cosmwasm/pyth-sdk-cw/src/lib.rs

@@ -0,0 +1,32 @@
+pub use pyth_sdk::{
+    PriceFeed,
+    PriceIdentifier,
+};
+use {
+    cosmwasm_schema::{
+        cw_serde,
+        QueryResponses,
+    },
+    cosmwasm_std::{
+        Binary,
+        Coin,
+    },
+    std::time::Duration,
+};
+
+
+#[cw_serde]
+#[derive(QueryResponses)]
+pub enum QueryMsg {
+    #[returns(PriceFeedResponse)]
+    PriceFeed { id: PriceIdentifier },
+    #[returns(Coin)]
+    GetUpdateFee { vaas: Vec<Binary> },
+    #[returns(Duration)]
+    GetValidTimePeriod,
+}
+
+#[cw_serde]
+pub struct PriceFeedResponse {
+    pub price_feed: PriceFeed,
+}

+ 1 - 0
tilt_devnet/docker_images/Dockerfile.cosmwasm

@@ -20,6 +20,7 @@ FROM cosmwasm/workspace-optimizer:0.12.11@sha256:b6b0b1d5ed76dafd0ec0d3812a1e7a2
 COPY target_chains/cosmwasm/Cargo.lock /code/
 COPY target_chains/cosmwasm/Cargo.toml /code/
 COPY target_chains/cosmwasm/contracts /code/contracts
+COPY target_chains/cosmwasm/pyth-sdk-cw /code/pyth-sdk-cw
 COPY wormhole_attester/sdk/rust /wormhole_attester/sdk/rust
 RUN --mount=type=cache,target=/code/target,id=cosmwasm_pyth_target --mount=type=cache,target=/usr/local/cargo/registry optimize_workspace.sh