Skip to content

Commit 7f991bb

Browse files
author
Dev Kalra
authored
[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
1 parent a478d9f commit 7f991bb

File tree

10 files changed

+76
-44
lines changed

10 files changed

+76
-44
lines changed

target_chains/cosmwasm/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target_chains/cosmwasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["contracts/pyth"]
2+
members = ["contracts/pyth", "pyth-sdk-cw"]
33
exclude = ["examples/cw-contract"]
44

55
[profile.release]

target_chains/cosmwasm/contracts/pyth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pyth-wormhole-attester-sdk = { path = "../../../../wormhole_attester/sdk/rust" }
3232
pyth-sdk = "0.7.0"
3333
byteorder = "1.4.3"
3434
cosmwasm-schema = "1.1.9"
35+
pyth-sdk-cw = { path = "../../pyth-sdk-cw" }
3536

3637
[dev-dependencies]
3738
cosmwasm-vm = { version = "1.0.0", default-features = false }

target_chains/cosmwasm/contracts/pyth/src/contract.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use {
1616
ExecuteMsg,
1717
InstantiateMsg,
1818
MigrateMsg,
19-
PriceFeedResponse,
2019
QueryMsg,
2120
},
2221
state::{
@@ -29,8 +28,6 @@ use {
2928
PythDataSource,
3029
},
3130
Price,
32-
PriceFeed,
33-
PriceIdentifier,
3431
},
3532
cosmwasm_std::{
3633
coin,
@@ -54,6 +51,11 @@ use {
5451
WasmMsg,
5552
WasmQuery,
5653
},
54+
pyth_sdk_cw::{
55+
PriceFeed,
56+
PriceFeedResponse,
57+
PriceIdentifier,
58+
},
5759
pyth_wormhole_attester_sdk::{
5860
BatchPriceAttestation,
5961
PriceAttestation,
@@ -487,12 +489,9 @@ pub fn get_valid_time_period(deps: &Deps) -> StdResult<Duration> {
487489
mod test {
488490
use {
489491
super::*,
490-
crate::{
491-
governance::GovernanceModule::{
492-
Executor,
493-
Target,
494-
},
495-
PriceIdentifier,
492+
crate::governance::GovernanceModule::{
493+
Executor,
494+
Target,
496495
},
497496
cosmwasm_std::{
498497
coins,
@@ -513,6 +512,7 @@ mod test {
513512
SystemResult,
514513
Uint128,
515514
},
515+
pyth_sdk_cw::PriceIdentifier,
516516
pyth_wormhole_attester_sdk::PriceAttestation,
517517
std::time::Duration,
518518
};

target_chains/cosmwasm/contracts/pyth/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,4 @@ pub mod governance;
77
pub mod msg;
88
pub mod state;
99

10-
pub use pyth_sdk::{
11-
Price,
12-
PriceFeed,
13-
PriceIdentifier,
14-
ProductIdentifier,
15-
};
10+
pub use pyth_sdk::Price;
Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1+
pub use pyth_sdk_cw::QueryMsg;
12
use {
2-
crate::{
3-
state::PythDataSource,
4-
PriceFeed,
5-
PriceIdentifier,
6-
},
7-
cosmwasm_schema::{
8-
cw_serde,
9-
QueryResponses,
10-
},
3+
crate::state::PythDataSource,
4+
cosmwasm_schema::cw_serde,
115
cosmwasm_std::{
126
Binary,
137
Coin,
148
},
15-
std::time::Duration,
169
};
1710

1811
// cw_serde attribute is equivalent to
@@ -47,20 +40,3 @@ pub enum ExecuteMsg {
4740
#[derive(Eq)]
4841
#[cw_serde]
4942
pub struct MigrateMsg {}
50-
51-
52-
#[cw_serde]
53-
#[derive(QueryResponses)]
54-
pub enum QueryMsg {
55-
#[returns(PriceFeedResponse)]
56-
PriceFeed { id: PriceIdentifier },
57-
#[returns(Coin)]
58-
GetUpdateFee { vaas: Vec<Binary> },
59-
#[returns(Duration)]
60-
GetValidTimePeriod,
61-
}
62-
63-
#[cw_serde]
64-
pub struct PriceFeedResponse {
65-
pub price_feed: PriceFeed,
66-
}

target_chains/cosmwasm/contracts/pyth/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use {
2-
crate::PriceFeed,
32
cosmwasm_std::{
43
Addr,
54
Binary,
@@ -17,6 +16,7 @@ use {
1716
ReadonlySingleton,
1817
Singleton,
1918
},
19+
pyth_sdk_cw::PriceFeed,
2020
schemars::JsonSchema,
2121
serde::{
2222
Deserialize,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "pyth-sdk-cw"
3+
version = "0.1.0"
4+
authors = ["Pyth Data Foundation"]
5+
edition = "2018"
6+
license = "Apache-2.0"
7+
homepage = "https://pyth.network"
8+
repository = "https://github.com/pyth-network/pyth-crosschain"
9+
description = "Data structures and utilites for the Pyth price oracle"
10+
keywords = [ "pyth", "oracle", "cosmwasm" ]
11+
12+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
14+
[dependencies]
15+
pyth-sdk = "0.7.0"
16+
cosmwasm-std = { version = "1.0.0" }
17+
cosmwasm-schema = "1.1.9"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pub use pyth_sdk::{
2+
PriceFeed,
3+
PriceIdentifier,
4+
};
5+
use {
6+
cosmwasm_schema::{
7+
cw_serde,
8+
QueryResponses,
9+
},
10+
cosmwasm_std::{
11+
Binary,
12+
Coin,
13+
},
14+
std::time::Duration,
15+
};
16+
17+
18+
#[cw_serde]
19+
#[derive(QueryResponses)]
20+
pub enum QueryMsg {
21+
#[returns(PriceFeedResponse)]
22+
PriceFeed { id: PriceIdentifier },
23+
#[returns(Coin)]
24+
GetUpdateFee { vaas: Vec<Binary> },
25+
#[returns(Duration)]
26+
GetValidTimePeriod,
27+
}
28+
29+
#[cw_serde]
30+
pub struct PriceFeedResponse {
31+
pub price_feed: PriceFeed,
32+
}

tilt_devnet/docker_images/Dockerfile.cosmwasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FROM cosmwasm/workspace-optimizer:0.12.11@sha256:b6b0b1d5ed76dafd0ec0d3812a1e7a2
2020
COPY target_chains/cosmwasm/Cargo.lock /code/
2121
COPY target_chains/cosmwasm/Cargo.toml /code/
2222
COPY target_chains/cosmwasm/contracts /code/contracts
23+
COPY target_chains/cosmwasm/pyth-sdk-cw /code/pyth-sdk-cw
2324
COPY wormhole_attester/sdk/rust /wormhole_attester/sdk/rust
2425
RUN --mount=type=cache,target=/code/target,id=cosmwasm_pyth_target --mount=type=cache,target=/usr/local/cargo/registry optimize_workspace.sh
2526

0 commit comments

Comments
 (0)