From ce81a5e480771ce42c40dd4f7467a051b20a9f72 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Wed, 23 Feb 2022 16:43:06 +0000 Subject: [PATCH 1/3] Add debug, eq, .. traits to public apis --- src/lib.rs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 057f3ea..1512dc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ pub enum AccountType } /// The current status of a price feed. -#[derive(Copy, Clone, PartialEq, BorshSerialize, BorshDeserialize, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize)] #[repr(C)] pub enum PriceStatus { @@ -59,17 +59,29 @@ pub enum PriceStatus Auction } +impl Default for PriceStatus { + fn default() -> Self { + PriceStatus::Unknown + } +} + /// Status of any ongoing corporate actions. /// (still undergoing dev) -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub enum CorpAction { NoCorpAct } +impl Default for CorpAction { + fn default() -> Self { + CorpAction::NoCorpAct + } +} + /// The type of prices associated with a product -- each product may have multiple price feeds of different types. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub enum PriceType { @@ -77,8 +89,14 @@ pub enum PriceType Price } +impl Default for PriceType { + fn default() -> Self { + PriceType::Unknown + } +} + /// Public key of a Solana account -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[repr(C)] pub struct AccKey { @@ -86,7 +104,7 @@ pub struct AccKey } /// Mapping accounts form a linked-list containing the listing of all products on Pyth. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct Mapping { @@ -115,7 +133,7 @@ unsafe impl Pod for Mapping {} /// Product accounts contain metadata for a single product, such as its symbol ("Crypto.BTC/USD") /// and its base/quote currencies. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct Product { @@ -147,7 +165,7 @@ unsafe impl Pod for Product {} /// A price and confidence at a specific slot. This struct can represent either a /// publisher's contribution or the outcome of price aggregation. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[repr(C)] pub struct PriceInfo { @@ -167,7 +185,7 @@ pub struct PriceInfo } /// The price and confidence contributed by a specific publisher. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[repr(C)] pub struct PriceComp { @@ -182,7 +200,7 @@ pub struct PriceComp } /// An exponentially-weighted moving average. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[repr(C)] pub struct Ema { @@ -195,7 +213,7 @@ pub struct Ema } /// Price accounts represent a continuously-updating price feed for a product. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[repr(C)] pub struct Price { @@ -332,7 +350,7 @@ impl Price { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] struct AccKeyU64 { pub val: [u64;4] From cd82a510202b1a0828dc1b3c123e17030e98d999 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Thu, 24 Feb 2022 14:12:26 +0000 Subject: [PATCH 2/3] Add serde and borhs to fields that can take it freely + add to price_conf --- Cargo.toml | 1 + src/lib.rs | 24 +++++++++++++++--------- src/price_conf.rs | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf22fd3..0192e1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ bytemuck = "1.7.2" num-derive = "0.3" num-traits = "0.2" thiserror = "1.0" +serde = { version = "1.0.136", features = ["derive"] } [dev-dependencies] solana-program-test = "1.8.1" diff --git a/src/lib.rs b/src/lib.rs index 1512dc2..402a241 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub const PROD_ATTR_SIZE : usize = PROD_ACCT_SIZE - PROD_HDR_SIZE; pub const MAX_SLOT_DIFFERENCE : u64 = 25; /// The type of Pyth account determines what data it contains -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub enum AccountType { @@ -44,8 +44,14 @@ pub enum AccountType Price } +impl Default for AccountType { + fn default() -> Self { + AccountType::Unknown + } +} + /// The current status of a price feed. -#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub enum PriceStatus { @@ -67,7 +73,7 @@ impl Default for PriceStatus { /// Status of any ongoing corporate actions. /// (still undergoing dev) -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub enum CorpAction { @@ -81,7 +87,7 @@ impl Default for CorpAction { } /// The type of prices associated with a product -- each product may have multiple price feeds of different types. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub enum PriceType { @@ -96,7 +102,7 @@ impl Default for PriceType { } /// Public key of a Solana account -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub struct AccKey { @@ -165,7 +171,7 @@ unsafe impl Pod for Product {} /// A price and confidence at a specific slot. This struct can represent either a /// publisher's contribution or the outcome of price aggregation. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub struct PriceInfo { @@ -185,7 +191,7 @@ pub struct PriceInfo } /// The price and confidence contributed by a specific publisher. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub struct PriceComp { @@ -200,7 +206,7 @@ pub struct PriceComp } /// An exponentially-weighted moving average. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] #[repr(C)] pub struct Ema { @@ -350,7 +356,7 @@ impl Price { } } -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] struct AccKeyU64 { pub val: [u64;4] diff --git a/src/price_conf.rs b/src/price_conf.rs index 04af6f5..d4c58c9 100644 --- a/src/price_conf.rs +++ b/src/price_conf.rs @@ -27,7 +27,7 @@ const MAX_PD_V_U64: u64 = (1 << 28) - 1; * small that the price does not fit into an i64). Users of these methods should (1) select * their exponents to avoid this problem, and (2) handle the `None` case gracefully. */ -#[derive(PartialEq, Debug, BorshSerialize, BorshDeserialize, Clone)] +#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)] pub struct PriceConf { pub price: i64, pub conf: u64, From 7b52edd998f67fd76e5c5af5eb54782f61336e0f Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Thu, 24 Feb 2022 18:29:22 +0000 Subject: [PATCH 3/3] Release 0.5.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0192e1e..50db23f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyth-client" -version = "0.4.0" +version = "0.5.0" authors = ["Pyth Data Foundation"] edition = "2018" license = "Apache-2.0"