Skip to content

Commit ee557d2

Browse files
devin-ai-integration[bot]Jayant Krishnamurthyjayantk
authored
refactor: move wormhole attester to pythnet_sdk legacy module (#2353)
* refactor: move wormhole attester to pythnet_sdk legacy module - Move wormhole_attester code to pythnet_sdk/legacy - Update downstream dependencies - Delete original wormhole_attester directory Co-Authored-By: Jayant Krishnamurthy <[email protected]> * refactor: update cosmwasm contract to use pythnet_sdk legacy module Co-Authored-By: Jayant Krishnamurthy <[email protected]> * chore: revert dependency version changes in pythnet_sdk Co-Authored-By: Jayant Krishnamurthy <[email protected]> * refactor: update cosmwasm contract to use pythnet_sdk::legacy::Identifier Co-Authored-By: Jayant Krishnamurthy <[email protected]> * chore: bump cosmwasm contract version to 1.3.1 Co-Authored-By: Jayant Krishnamurthy <[email protected]> * Update Cargo.toml * chore: bump near receiver version to 0.1.1 Co-Authored-By: Jayant Krishnamurthy <[email protected]> * style: fix rust formatting Co-Authored-By: Jayant Krishnamurthy <[email protected]> * refactor: update near receiver tests to use pythnet_sdk::legacy Co-Authored-By: Jayant Krishnamurthy <[email protected]> * refactor: remove solana-specific imports from legacy module Co-Authored-By: Jayant Krishnamurthy <[email protected]> * update lockfiles --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jayant Krishnamurthy <[email protected]> Co-authored-by: Jayant Krishnamurthy <[email protected]>
1 parent c7ca8f0 commit ee557d2

File tree

20 files changed

+27
-1463
lines changed

20 files changed

+27
-1463
lines changed

pythnet/pythnet_sdk/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ quickcheck = { version = "1", optional = true}
2828
sha3 = "0.10.4"
2929
slow_primes = "0.1.14"
3030
thiserror = "1.0.40"
31+
pyth-sdk = { version = "0.5.0" }
32+
3133
serde_wormhole = {version ="0.1.0", optional = true}
3234
wormhole-vaas-serde = {version = "0.1.0", optional = true}
3335
libsecp256k1 = {version ="0.7.1", optional = true}

pythnet/pythnet_sdk/src/legacy/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod wormhole_attester;
2+
pub use wormhole_attester::*;

wormhole_attester/sdk/rust/src/lib.rs renamed to pythnet/pythnet_sdk/src/legacy/wormhole_attester.rs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
//! the probable adversarial scenarios.
88
99
pub use pyth_sdk::{Identifier, PriceStatus, UnixTimestamp};
10-
#[cfg(feature = "solana")]
11-
use {
12-
pyth_sdk_solana::state::PriceAccount,
13-
solitaire::{Derive, Info},
14-
};
1510
use {
1611
serde::{Deserialize, Serialize, Serializer},
1712
std::{convert::TryInto, io::Read, iter::Iterator, mem},
@@ -41,10 +36,6 @@ pub const P2W_FORMAT_HDR_SIZE: u16 = 1;
4136

4237
pub const PUBKEY_LEN: usize = 32;
4338

44-
/// Emmitter Address to wormhole is a PDA with seed p2w-emmiter from attestation contract
45-
#[cfg(feature = "solana")]
46-
pub type P2WEmitter<'b> = Derive<Info<'b>, "p2w-emitter">;
47-
4839
/// Decides the format of following bytes
4940
#[repr(u8)]
5041
pub enum PayloadId {
@@ -263,48 +254,6 @@ impl BatchPriceAttestation {
263254
// On-chain data types
264255

265256
impl PriceAttestation {
266-
#[cfg(feature = "solana")]
267-
pub fn from_pyth_price_bytes(
268-
price_id: Identifier,
269-
attestation_time: UnixTimestamp,
270-
last_attested_publish_time: UnixTimestamp,
271-
value: &[u8],
272-
) -> Result<Self, ErrBox> {
273-
let price_struct = pyth_sdk_solana::state::load_price_account(value)?;
274-
Ok(Self::from_pyth_price_struct(
275-
price_id,
276-
attestation_time,
277-
last_attested_publish_time,
278-
price_struct,
279-
))
280-
}
281-
#[cfg(feature = "solana")]
282-
pub fn from_pyth_price_struct(
283-
price_id: Identifier,
284-
attestation_time: UnixTimestamp,
285-
last_attested_publish_time: UnixTimestamp,
286-
price: &PriceAccount,
287-
) -> Self {
288-
PriceAttestation {
289-
product_id: Identifier::new(price.prod.val),
290-
price_id,
291-
price: price.agg.price,
292-
conf: price.agg.conf,
293-
expo: price.expo,
294-
ema_price: price.ema_price.val,
295-
ema_conf: price.ema_conf.val as u64,
296-
status: price.agg.status,
297-
num_publishers: price.num_qt,
298-
max_num_publishers: price.num,
299-
attestation_time,
300-
publish_time: price.timestamp,
301-
prev_publish_time: price.prev_timestamp,
302-
prev_price: price.prev_price,
303-
prev_conf: price.prev_conf,
304-
last_attested_publish_time,
305-
}
306-
}
307-
308257
/// Serialize this attestation according to the Pyth-over-wormhole serialization format
309258
pub fn serialize(&self) -> Vec<u8> {
310259
// A nifty trick to get us yelled at if we forget to serialize a field
@@ -482,7 +431,7 @@ impl PriceAttestation {
482431
/// using `cargo test -- --nocapture`.
483432
#[cfg(test)]
484433
mod tests {
485-
use {super::*, pyth_sdk_solana::state::PriceStatus};
434+
use super::*;
486435

487436
fn mock_attestation(prod: Option<[u8; 32]>, price: Option<[u8; 32]>) -> PriceAttestation {
488437
let product_id_bytes = prod.unwrap_or([21u8; 32]);

pythnet/pythnet_sdk/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod accumulators;
22
pub mod error;
33
pub mod hashers;
4+
pub mod legacy;
45
pub mod messages;
56
pub mod wire;
67
pub mod wormhole;

target_chains/aptos/contracts/sources/batch_price_attestation.move

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module pyth::batch_price_attestation {
1818

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

21+
/// @notice This struct is based on the legacy wormhole attester implementation in pythnet_sdk
2122
struct BatchPriceAttestation {
2223
header: Header,
2324
attestation_size: u64,

target_chains/cosmwasm/Cargo.lock

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

target_chains/cosmwasm/contracts/pyth/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-cosmwasm"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
authors = ["Wormhole Contributors <[email protected]>"]
55
edition = "2018"
66
description = "Pyth price receiver"
@@ -33,18 +33,17 @@ generic-array = { version = "0.14.4" }
3333
hex = "0.4.2"
3434
lazy_static = "1.4.0"
3535
bigint = "4"
36-
pyth-wormhole-attester-sdk = { path = "../../../../wormhole_attester/sdk/rust" }
36+
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
3737
pyth-sdk = "0.7.0"
3838
byteorder = "1.4.3"
3939
cosmwasm-schema = "1.1.9"
4040
osmosis-std = "0.15.2"
4141
pyth-sdk-cw = { path = "../../sdk/rust" }
42-
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
4342
wormhole-cosmwasm = {git = "https://github.com/wormhole-foundation/wormhole", tag="rust-sdk-2024-01-25"}
4443

4544
[dev-dependencies]
4645
cosmwasm-vm = { version = "1.0.0", default-features = false }
47-
serde_json = "1.0"
4846
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk", features = ["test-utils"] }
47+
serde_json = "1.0"
4948
serde_wormhole = "0.1.0"
5049
wormhole-vaas-serde = "0.1.0"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use {
3131
error::PythContractError, ExecuteMsg, Price, PriceFeed, PriceFeedResponse, PriceIdentifier,
3232
QueryMsg,
3333
},
34-
pyth_wormhole_attester_sdk::{BatchPriceAttestation, PriceAttestation, PriceStatus},
34+
pythnet_sdk::legacy::{BatchPriceAttestation, PriceAttestation, PriceStatus},
3535
pythnet_sdk::{
3636
accumulators::merkle::MerkleRoot,
3737
hashers::keccak256_160::Keccak160,
@@ -753,7 +753,7 @@ mod test {
753753
},
754754
pyth_sdk::UnixTimestamp,
755755
pyth_sdk_cw::PriceIdentifier,
756-
pyth_wormhole_attester_sdk::PriceAttestation,
756+
pythnet_sdk::legacy::PriceAttestation,
757757
pythnet_sdk::{
758758
accumulators::{merkle::MerkleTree, Accumulator},
759759
messages::{PriceFeedMessage, TwapMessage},
@@ -1478,7 +1478,7 @@ mod test {
14781478
#[test]
14791479
fn test_create_price_feed_from_price_attestation_status_trading() {
14801480
let price_attestation = PriceAttestation {
1481-
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
1481+
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
14821482
price: 100,
14831483
conf: 100,
14841484
expo: 100,
@@ -1527,7 +1527,7 @@ mod test {
15271527

15281528
fn test_create_price_feed_from_price_attestation_not_trading(status: PriceStatus) {
15291529
let price_attestation = PriceAttestation {
1530-
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
1530+
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
15311531
price: 100,
15321532
conf: 100,
15331533
expo: 100,
@@ -1565,7 +1565,7 @@ mod test {
15651565
let (mut deps, env) = setup_test();
15661566

15671567
let price_attestation = PriceAttestation {
1568-
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
1568+
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
15691569
price: 100,
15701570
conf: 100,
15711571
expo: 100,
@@ -1607,7 +1607,7 @@ mod test {
16071607
let (mut deps, env) = setup_test();
16081608

16091609
let price_attestation = PriceAttestation {
1610-
price_id: pyth_wormhole_attester_sdk::Identifier::new([0u8; 32]),
1610+
price_id: pythnet_sdk::legacy::Identifier::new([0u8; 32]),
16111611
price: 100,
16121612
conf: 100,
16131613
expo: 100,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::state::PythDataSource,
33
byteorder::{BigEndian, ReadBytesExt, WriteBytesExt},
44
cosmwasm_std::Binary,
5-
pyth_wormhole_attester_sdk::ErrBox,
5+
pythnet_sdk::legacy::ErrBox,
66
schemars::JsonSchema,
77
serde::{Deserialize, Serialize},
88
std::{convert::TryFrom, io::Write},

target_chains/near/receiver/Cargo.lock

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

0 commit comments

Comments
 (0)