Skip to content

Commit 1360d25

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andcommitted
refactor: remove wormhole-attester directory
The wormhole-attester functionality has been consolidated into pythnet-sdk to simplify the codebase and reduce duplication. This change: - Moves protocol constants to pythnet-sdk - Updates Near and Cosmwasm contracts to use pythnet-sdk directly - Removes the deprecated wormhole-attester package Co-Authored-By: Jayant Krishnamurthy <[email protected]>
1 parent 5602f4b commit 1360d25

File tree

17 files changed

+203
-2122
lines changed

17 files changed

+203
-2122
lines changed

pythnet/pythnet_sdk/src/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ pub enum Error {
1010

1111
#[error("Deserialization error")]
1212
DeserializationError,
13+
14+
#[error("Invalid Input")]
15+
InvalidInput,
16+
}
17+
18+
impl From<std::io::Error> for Error {
19+
fn from(_: std::io::Error) -> Self {
20+
Error::InvalidInput
21+
}
22+
}
23+
24+
impl From<String> for Error {
25+
fn from(_: String) -> Self {
26+
Error::InvalidInput
27+
}
28+
}
29+
30+
impl From<&str> for Error {
31+
fn from(_: &str) -> Self {
32+
Error::InvalidInput
33+
}
34+
}
35+
36+
impl From<std::num::TryFromIntError> for Error {
37+
fn from(_: std::num::TryFromIntError) -> Self {
38+
Error::InvalidInput
39+
}
1340
}
1441

1542
#[macro_export]

pythnet/pythnet_sdk/src/messages.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub enum Message {
4949
/// we can't associate it with a specific feed, so we use a feed id that is not used by any price feed
5050
pub const PUBLISHER_STAKE_CAPS_MESSAGE_FEED_ID: FeedId = [1u8; 32];
5151

52+
/// Magic bytes used to identify price feed messages in the protocol
53+
pub const P2W_MAGIC: &[u8; 4] = b"P2WH";
54+
5255
impl Message {
5356
pub fn publish_time(&self) -> i64 {
5457
match self {
@@ -82,6 +85,28 @@ impl Arbitrary for Message {
8285
pub type FeedId = [u8; 32];
8386
pub type Pubkey = [u8; 32];
8487

88+
#[derive(
89+
Debug,
90+
Copy,
91+
Clone,
92+
PartialEq,
93+
Eq,
94+
Serialize,
95+
Deserialize,
96+
BorshSerialize,
97+
BorshDeserialize,
98+
BorshSchema,
99+
Default,
100+
)]
101+
#[serde(rename_all = "snake_case")]
102+
pub enum PriceStatus {
103+
Trading = 1,
104+
#[default]
105+
Unknown = 2,
106+
Halted = 3,
107+
Auction = 4,
108+
}
109+
85110
#[repr(C)]
86111
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, BorshSchema)]
87112
#[cfg_attr(feature = "solana-program", derive(AnchorSerialize, AnchorDeserialize))]
@@ -113,6 +138,23 @@ pub struct PriceFeedMessage {
113138
pub prev_publish_time: i64,
114139
pub ema_price: i64,
115140
pub ema_conf: u64,
141+
pub status: PriceStatus,
142+
}
143+
144+
impl Default for PriceFeedMessage {
145+
fn default() -> Self {
146+
Self {
147+
feed_id: [0u8; 32],
148+
price: 0,
149+
conf: 0,
150+
exponent: 0,
151+
publish_time: 0,
152+
prev_publish_time: 0,
153+
ema_price: 0,
154+
ema_conf: 0,
155+
status: PriceStatus::Unknown,
156+
}
157+
}
116158
}
117159

118160
#[cfg(feature = "quickcheck")]
@@ -134,6 +176,7 @@ impl Arbitrary for PriceFeedMessage {
134176
prev_publish_time: publish_time.saturating_sub(i64::arbitrary(g)),
135177
ema_price: i64::arbitrary(g),
136178
ema_conf: u64::arbitrary(g),
179+
status: PriceStatus::Unknown,
137180
}
138181
}
139182
}
@@ -222,7 +265,7 @@ impl Arbitrary for PublisherStakeCap {
222265
mod tests {
223266

224267
use crate::{
225-
messages::{Message, PriceFeedMessage},
268+
messages::{Message, PriceFeedMessage, PriceStatus},
226269
wire::Serializer,
227270
};
228271

@@ -239,6 +282,7 @@ mod tests {
239282
prev_publish_time: 1,
240283
ema_price: 1,
241284
ema_conf: 1,
285+
status: PriceStatus::Unknown,
242286
});
243287
let mut buffer = Vec::new();
244288
let mut cursor = std::io::Cursor::new(&mut buffer);

pythnet/pythnet_sdk/src/test_utils/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
accumulators::{merkle::MerkleTree, Accumulator},
44
hashers::{keccak256::Keccak256, keccak256_160::Keccak160, Hasher},
5-
messages::{FeedId, Message, PriceFeedMessage, TwapMessage},
5+
messages::{FeedId, Message, PriceFeedMessage, PriceStatus, TwapMessage},
66
wire::{
77
to_vec,
88
v1::{
@@ -92,6 +92,7 @@ pub fn create_dummy_feed_id(value: i64) -> FeedId {
9292

9393
pub fn create_dummy_price_feed_message_with_feed_id(value: i64, feed_id: FeedId) -> Message {
9494
let msg = PriceFeedMessage {
95+
status: PriceStatus::Unknown,
9596
feed_id,
9697
price: value,
9798
conf: value as u64,

target_chains/cosmwasm/Cargo.lock

Lines changed: 2 additions & 25 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ 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" }
3736
pyth-sdk = "0.7.0"
37+
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
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]

0 commit comments

Comments
 (0)