Skip to content

refactor: move wormhole attester to pythnet_sdk legacy module #2353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions pythnet/pythnet_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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}
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,10 +36,6 @@ 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)]
pub enum PayloadId {
Expand Down Expand Up @@ -263,48 +254,6 @@ 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> {
// A nifty trick to get us yelled at if we forget to serialize a field
Expand Down Expand Up @@ -482,7 +431,7 @@ impl PriceAttestation {
/// using `cargo test -- --nocapture`.
#[cfg(test)]
mod tests {
use {super::*, pyth_sdk_solana::state::PriceStatus};
use super::*;

fn mock_attestation(prod: Option<[u8; 32]>, price: Option<[u8; 32]>) -> PriceAttestation {
let product_id_bytes = prod.unwrap_or([21u8; 32]);
Expand Down
1 change: 1 addition & 0 deletions pythnet/pythnet_sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod accumulators;
pub mod error;
pub mod hashers;
pub mod legacy;
pub mod messages;
pub mod wire;
pub mod wormhole;
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
13 changes: 2 additions & 11 deletions target_chains/cosmwasm/Cargo.lock

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

7 changes: 3 additions & 4 deletions target_chains/cosmwasm/contracts/pyth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-cosmwasm"
version = "1.3.0"
version = "1.3.1"
authors = ["Wormhole Contributors <contact@certus.one>"]
edition = "2018"
description = "Pyth price receiver"
Expand Down Expand Up @@ -33,18 +33,17 @@ 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" }
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_json = "1.0"
serde_wormhole = "0.1.0"
wormhole-vaas-serde = "0.1.0"
12 changes: 6 additions & 6 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 Expand Up @@ -1478,7 +1478,7 @@ mod test {
#[test]
fn test_create_price_feed_from_price_attestation_status_trading() {
let price_attestation = PriceAttestation {
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
price: 100,
conf: 100,
expo: 100,
Expand Down Expand Up @@ -1527,7 +1527,7 @@ mod test {

fn test_create_price_feed_from_price_attestation_not_trading(status: PriceStatus) {
let price_attestation = PriceAttestation {
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
price: 100,
conf: 100,
expo: 100,
Expand Down Expand Up @@ -1565,7 +1565,7 @@ mod test {
let (mut deps, env) = setup_test();

let price_attestation = PriceAttestation {
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
price: 100,
conf: 100,
expo: 100,
Expand Down Expand Up @@ -1607,7 +1607,7 @@ mod test {
let (mut deps, env) = setup_test();

let price_attestation = PriceAttestation {
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
price: 100,
conf: 100,
expo: 100,
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
13 changes: 2 additions & 11 deletions target_chains/near/receiver/Cargo.lock

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

5 changes: 2 additions & 3 deletions target_chains/near/receiver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-near"
version = "0.1.0"
version = "0.1.1"
authors = ["Pyth Data Association"]
edition = "2021"
description = "A Pyth Receiver for Near"
Expand All @@ -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
2 changes: 1 addition & 1 deletion target_chains/near/receiver/tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
governance::{GovernanceAction, GovernanceInstruction, GovernanceModule},
state::{Chain, Price, PriceIdentifier, Source},
},
pyth_wormhole_attester_sdk::{
pythnet_sdk::legacy::{
BatchPriceAttestation, Identifier, PriceAttestation, PriceStatus,
},
pythnet_sdk::test_utils::{
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