Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Add debug, eq, .. traits to public structs (#21)
Browse files Browse the repository at this point in the history
* Add debug, eq, .. traits to public apis
* Add serde and borsh to fields that can take it freely + add good traits to price_conf
* Release 0.5.0
  • Loading branch information
ali-bahjati authored Feb 24, 2022
1 parent ea3d18c commit 11b39b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
48 changes: 36 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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, PartialEq, BorshSerialize, BorshDeserialize, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub enum PriceStatus
{
Expand All @@ -59,34 +65,52 @@ 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, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[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, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub enum PriceType
{
Unknown,
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, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub struct AccKey
{
pub val: [u8;32]
}

/// 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
{
Expand Down Expand Up @@ -115,7 +139,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
{
Expand Down Expand Up @@ -147,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)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub struct PriceInfo
{
Expand All @@ -167,7 +191,7 @@ pub struct PriceInfo
}

/// The price and confidence contributed by a specific publisher.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub struct PriceComp
{
Expand All @@ -182,7 +206,7 @@ pub struct PriceComp
}

/// An exponentially-weighted moving average.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
#[repr(C)]
pub struct Ema
{
Expand All @@ -195,7 +219,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
{
Expand Down Expand Up @@ -332,7 +356,7 @@ impl Price {
}
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
struct AccKeyU64
{
pub val: [u64;4]
Expand Down
2 changes: 1 addition & 1 deletion src/price_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 11b39b9

Please sign in to comment.