Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pythnet/pythnet_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ bytemuck = { version = "1.11.0", features = ["derive"] }
byteorder = "1.4.3"
fast-math = "0.1"
hex = { version = "0.4.3", features = ["serde"] }
serde = { version = "1.0.144", features = ["derive"] }
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
strum = { version = "0.24.1", features = ["derive"], optional = true }
quickcheck = { version = "1", optional = true}
sha3 = "0.10.4"
slow_primes = "0.1.14"
thiserror = "1.0.40"
pyth-sdk = { version = "0.5.0" }

serde_wormhole = {version ="0.1.0", optional = true}
wormhole-vaas-serde = {version = "0.1.0", optional = true}
libsecp256k1 = {version ="0.7.1", optional = true}
rand = {version = "0.8.5", optional = true}
solana-program = {version = ">=1.13.6", optional = true}
solana-program = { version = ">=1.14.6", optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the versions of these dependencies.

anchor-lang = {version = ">=0.28.0", optional = true}

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions pythnet/pythnet_sdk/src/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod wormhole_attester;
pub use wormhole_attester::*;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
//! the probable adversarial scenarios.

pub use pyth_sdk::{Identifier, PriceStatus, UnixTimestamp};
#[cfg(feature = "solana")]
use {
pyth_sdk_solana::state::PriceAccount,
solitaire::{Derive, Info},
};
use {
serde::{Deserialize, Serialize, Serializer},
std::{convert::TryInto, io::Read, iter::Iterator, mem},
Expand Down Expand Up @@ -41,9 +36,7 @@ pub const P2W_FORMAT_HDR_SIZE: u16 = 1;

pub const PUBKEY_LEN: usize = 32;

/// Emmitter Address to wormhole is a PDA with seed p2w-emmiter from attestation contract
#[cfg(feature = "solana")]
pub type P2WEmitter<'b> = Derive<Info<'b>, "p2w-emitter">;


/// Decides the format of following bytes
#[repr(u8)]
Expand Down Expand Up @@ -263,47 +256,7 @@ impl BatchPriceAttestation {
// On-chain data types

impl PriceAttestation {
#[cfg(feature = "solana")]
pub fn from_pyth_price_bytes(
price_id: Identifier,
attestation_time: UnixTimestamp,
last_attested_publish_time: UnixTimestamp,
value: &[u8],
) -> Result<Self, ErrBox> {
let price_struct = pyth_sdk_solana::state::load_price_account(value)?;
Ok(Self::from_pyth_price_struct(
price_id,
attestation_time,
last_attested_publish_time,
price_struct,
))
}
#[cfg(feature = "solana")]
pub fn from_pyth_price_struct(
price_id: Identifier,
attestation_time: UnixTimestamp,
last_attested_publish_time: UnixTimestamp,
price: &PriceAccount,
) -> Self {
PriceAttestation {
product_id: Identifier::new(price.prod.val),
price_id,
price: price.agg.price,
conf: price.agg.conf,
expo: price.expo,
ema_price: price.ema_price.val,
ema_conf: price.ema_conf.val as u64,
status: price.agg.status,
num_publishers: price.num_qt,
max_num_publishers: price.num,
attestation_time,
publish_time: price.timestamp,
prev_publish_time: price.prev_timestamp,
prev_price: price.prev_price,
prev_conf: price.prev_conf,
last_attested_publish_time,
}
}


/// Serialize this attestation according to the Pyth-over-wormhole serialization format
pub fn serialize(&self) -> Vec<u8> {
Expand Down
1 change: 1 addition & 0 deletions pythnet/pythnet_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod hashers;
pub mod messages;
pub mod wire;
pub mod wormhole;
pub mod legacy;

#[cfg(feature = "test-utils")]
pub mod test_utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module pyth::batch_price_attestation {

const MAGIC: u64 = 0x50325748; // "P2WH" (Pyth2Wormhole) raw ASCII bytes

/// @notice This struct is based on the legacy wormhole attester implementation in pythnet_sdk
struct BatchPriceAttestation {
header: Header,
attestation_size: u64,
Expand Down
4 changes: 1 addition & 3 deletions target_chains/cosmwasm/contracts/pyth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ generic-array = { version = "0.14.4" }
hex = "0.4.2"
lazy_static = "1.4.0"
bigint = "4"
pyth-wormhole-attester-sdk = { path = "../../../../wormhole_attester/sdk/rust" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump the patch version of this file.

pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk", features = ["test-utils"] }
pyth-sdk = "0.7.0"
byteorder = "1.4.3"
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", tag="rust-sdk-2024-01-25"}

[dev-dependencies]
cosmwasm-vm = { version = "1.0.0", default-features = false }
serde_json = "1.0"
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk", features = ["test-utils"] }
serde_wormhole = "0.1.0"
wormhole-vaas-serde = "0.1.0"
4 changes: 2 additions & 2 deletions target_chains/cosmwasm/contracts/pyth/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use {
error::PythContractError, ExecuteMsg, Price, PriceFeed, PriceFeedResponse, PriceIdentifier,
QueryMsg,
},
pyth_wormhole_attester_sdk::{BatchPriceAttestation, PriceAttestation, PriceStatus},
pythnet_sdk::legacy::{BatchPriceAttestation, PriceAttestation, PriceStatus},
pythnet_sdk::{
accumulators::merkle::MerkleRoot,
hashers::keccak256_160::Keccak160,
Expand Down Expand Up @@ -753,7 +753,7 @@ mod test {
},
pyth_sdk::UnixTimestamp,
pyth_sdk_cw::PriceIdentifier,
pyth_wormhole_attester_sdk::PriceAttestation,
pythnet_sdk::legacy::PriceAttestation,
pythnet_sdk::{
accumulators::{merkle::MerkleTree, Accumulator},
messages::{PriceFeedMessage, TwapMessage},
Expand Down
2 changes: 1 addition & 1 deletion target_chains/cosmwasm/contracts/pyth/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
crate::state::PythDataSource,
byteorder::{BigEndian, ReadBytesExt, WriteBytesExt},
cosmwasm_std::Binary,
pyth_wormhole_attester_sdk::ErrBox,
pythnet_sdk::legacy::ErrBox,
schemars::JsonSchema,
serde::{Deserialize, Serialize},
std::{convert::TryFrom, io::Write},
Expand Down
11 changes: 1 addition & 10 deletions target_chains/near/receiver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions target_chains/near/receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ near-sdk = { version = "5.5.0", features = ["legacy"] }
nom = { version = "7.1.2" }
num-traits = { version = "0.2.15" }
num-derive = { version = "0.3.3" }
pyth-wormhole-attester-sdk = { path = "../../../wormhole_attester/sdk/rust" }
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" }
pyth-sdk = { version = "0.7.0" }
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" }
schemars = { version = "0.8.21" }
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", tag="rust-sdk-2024-01-25" }
strum = { version = "0.24.1", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion target_chains/near/receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
log, near_bindgen, AccountId, BorshStorageKey, Duration, Gas, NearToken, PanicOnDefault,
Promise, StorageUsage,
},
pyth_wormhole_attester_sdk::{BatchPriceAttestation, P2W_MAGIC},
pythnet_sdk::legacy::{BatchPriceAttestation, P2W_MAGIC},
pythnet_sdk::{
accumulators::merkle::MerkleRoot,
hashers::keccak256_160::Keccak160,
Expand Down
2 changes: 1 addition & 1 deletion target_chains/near/receiver/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
json_types::{I64, U64},
serde::{Deserialize, Serialize},
},
pyth_wormhole_attester_sdk::PriceAttestation,
pythnet_sdk::legacy::PriceAttestation,
pythnet_sdk::messages::PriceFeedMessage,
schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema},
wormhole_sdk::Chain as WormholeChain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module pyth::batch_price_attestation {
const E_INVALID_ATTESTATION_MAGIC_VALUE: u64 = 0;
const E_INVALID_BATCH_ATTESTATION_HEADER_SIZE: u64 = 1;

/// @notice This struct is based on the legacy wormhole attester implementation in pythnet_sdk
struct BatchPriceAttestation {
header: Header,
attestation_size: u64,
Expand Down
Loading
Loading