Skip to content

Commit 2d09312

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andcommitted
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]>
1 parent e0af12d commit 2d09312

File tree

15 files changed

+15
-1437
lines changed

15 files changed

+15
-1437
lines changed

pythnet/pythnet_sdk/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ bytemuck = { version = "1.11.0", features = ["derive"] }
2222
byteorder = "1.4.3"
2323
fast-math = "0.1"
2424
hex = { version = "0.4.3", features = ["serde"] }
25-
serde = { version = "1.0.144", features = ["derive"] }
25+
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
2626
strum = { version = "0.24.1", features = ["derive"], optional = true }
2727
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}
3436
rand = {version = "0.8.5", optional = true}
35-
solana-program = {version = ">=1.13.6", optional = true}
37+
solana-program = { version = ">=1.14.6", optional = true }
3638
anchor-lang = {version = ">=0.28.0", optional = true}
3739

3840
[dev-dependencies]
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: 2 additions & 49 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,9 +36,7 @@ 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">;
39+
4740

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

265258
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-
}
259+
307260

308261
/// Serialize this attestation according to the Pyth-over-wormhole serialization format
309262
pub fn serialize(&self) -> Vec<u8> {

pythnet/pythnet_sdk/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod hashers;
44
pub mod messages;
55
pub mod wire;
66
pub mod wormhole;
7+
pub mod legacy;
78

89
#[cfg(feature = "test-utils")]
910
pub mod test_utils;

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/near/receiver/Cargo.lock

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

target_chains/near/receiver/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ near-sdk = { version = "5.5.0", features = ["legacy"] }
2020
nom = { version = "7.1.2" }
2121
num-traits = { version = "0.2.15" }
2222
num-derive = { version = "0.3.3" }
23-
pyth-wormhole-attester-sdk = { path = "../../../wormhole_attester/sdk/rust" }
23+
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" }
2424
pyth-sdk = { version = "0.7.0" }
25-
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" }
2625
schemars = { version = "0.8.21" }
2726
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", tag="rust-sdk-2024-01-25" }
2827
strum = { version = "0.24.1", features = ["derive"] }

target_chains/near/receiver/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use {
1111
log, near_bindgen, AccountId, BorshStorageKey, Duration, Gas, NearToken, PanicOnDefault,
1212
Promise, StorageUsage,
1313
},
14-
pyth_wormhole_attester_sdk::{BatchPriceAttestation, P2W_MAGIC},
14+
pythnet_sdk::legacy::{BatchPriceAttestation, P2W_MAGIC},
1515
pythnet_sdk::{
1616
accumulators::merkle::MerkleRoot,
1717
hashers::keccak256_160::Keccak160,

target_chains/near/receiver/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use {
44
json_types::{I64, U64},
55
serde::{Deserialize, Serialize},
66
},
7-
pyth_wormhole_attester_sdk::PriceAttestation,
7+
pythnet_sdk::legacy::PriceAttestation,
88
pythnet_sdk::messages::PriceFeedMessage,
99
schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema},
1010
wormhole_sdk::Chain as WormholeChain,

target_chains/sui/contracts/sources/batch_price_attestation.move

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module pyth::batch_price_attestation {
2020
const E_INVALID_ATTESTATION_MAGIC_VALUE: u64 = 0;
2121
const E_INVALID_BATCH_ATTESTATION_HEADER_SIZE: u64 = 1;
2222

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

0 commit comments

Comments
 (0)