Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-lazer-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:
- name: Clippy check
run: cargo clippy -p pyth-lazer-protocol -p pyth-lazer-client -p pyth-lazer-publisher-sdk --all-targets -- --deny warnings
if: success() || failure()
- name: Clippy check with mry
run: cargo clippy -F mry -p pyth-lazer-protocol --all-targets -- --deny warnings
if: success() || failure()
- name: test
run: cargo test -p pyth-lazer-protocol -p pyth-lazer-client -p pyth-lazer-publisher-sdk
if: success() || failure()
- name: test with mry
run: cargo test -F mry -p pyth-lazer-protocol
if: success() || failure()
66 changes: 53 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions lazer/contracts/solana/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.8.1" }
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.9.0" }

anchor-lang = "0.30.1"
bytemuck = "1.20.0"
Expand Down
2 changes: 1 addition & 1 deletion lazer/publisher_sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
repository = "https://github.com/pyth-network/pyth-crosschain"

[dependencies]
pyth-lazer-protocol = { version = "0.8.1", path = "../../sdk/rust/protocol" }
pyth-lazer-protocol = { version = "0.9.0", path = "../../sdk/rust/protocol" }
anyhow = "1.0.98"
protobuf = "3.7.2"
serde-value = "0.7.0"
Expand Down
4 changes: 2 additions & 2 deletions lazer/publisher_sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{bail, ensure, Context};
use humantime::format_duration;
use protobuf::dynamic_value::{dynamic_value, DynamicValue};
use pyth_lazer_protocol::jrpc::{FeedUpdateParams, UpdateParams};
use pyth_lazer_protocol::router::TimestampUs;
use pyth_lazer_protocol::time::TimestampUs;

pub mod transaction_envelope {
pub use crate::protobuf::transaction_envelope::*;
Expand Down Expand Up @@ -141,7 +141,7 @@ impl TryFrom<DynamicValue> for serde_value::Value {
}
dynamic_value::Value::TimestampValue(ts) => {
let ts = TimestampUs::try_from(&ts)?;
Ok(serde_value::Value::U64(ts.0))
Ok(serde_value::Value::U64(ts.as_micros()))
}
dynamic_value::Value::List(list) => {
let mut output = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion lazer/sdk/rust/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "A Rust client for Pyth Lazer"
license = "Apache-2.0"

[dependencies]
pyth-lazer-protocol = { path = "../protocol", version = "0.8.1" }
pyth-lazer-protocol = { path = "../protocol", version = "0.9.0" }
tokio = { version = "1", features = ["full"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
futures-util = "0.3"
Expand Down
8 changes: 2 additions & 6 deletions lazer/sdk/rust/client/examples/subscribe_price_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async fn main() -> anyhow::Result<()> {
delivery_format: DeliveryFormat::Json,
json_binary_encoding: JsonBinaryEncoding::Base64,
parsed: true,
channel: Channel::FixedRate(
FixedRate::from_ms(200).expect("unsupported update rate"),
),
channel: Channel::FixedRate(FixedRate::RATE_200_MS),
ignore_invalid_feed_ids: false,
})
.expect("invalid subscription params"),
Expand All @@ -66,9 +64,7 @@ async fn main() -> anyhow::Result<()> {
delivery_format: DeliveryFormat::Binary,
json_binary_encoding: JsonBinaryEncoding::Base64,
parsed: false,
channel: Channel::FixedRate(
FixedRate::from_ms(50).expect("unsupported update rate"),
),
channel: Channel::FixedRate(FixedRate::RATE_50_MS),
ignore_invalid_feed_ids: false,
})
.expect("invalid subscription params"),
Expand Down
4 changes: 3 additions & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.8.1"
version = "0.9.0"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand All @@ -16,6 +16,8 @@ itertools = "0.13.0"
rust_decimal = "1.36.0"
protobuf = "3.7.2"
humantime-serde = "1.1.1"
mry = { version = "0.13.0", features = ["serde"], optional = true }
chrono = "0.4.41"

[dev-dependencies]
bincode = "1.3.3"
Expand Down
5 changes: 3 additions & 2 deletions lazer/sdk/rust/protocol/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};

use crate::router::{
Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty, TimestampUs,
use crate::{
router::{Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty},
time::TimestampUs,
};

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down
11 changes: 6 additions & 5 deletions lazer/sdk/rust/protocol/src/jrpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::router::{Channel, Price, PriceFeedId, Rate, TimestampUs};
use crate::router::{Channel, Price, PriceFeedId, Rate};
use crate::symbol_state::SymbolState;
use crate::time::TimestampUs;
use serde::{Deserialize, Serialize};
use std::time::Duration;

Expand Down Expand Up @@ -157,7 +158,7 @@ mod tests {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs(124214124124),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::PriceUpdate {
price: Price::from_integer(1234567890, 0).unwrap(),
best_bid_price: Some(Price::from_integer(1234567891, 0).unwrap()),
Expand Down Expand Up @@ -196,7 +197,7 @@ mod tests {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs(124214124124),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::PriceUpdate {
price: Price::from_integer(1234567890, 0).unwrap(),
best_bid_price: None,
Expand Down Expand Up @@ -236,7 +237,7 @@ mod tests {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs(124214124124),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::FundingRateUpdate {
price: Some(Price::from_integer(1234567890, 0).unwrap()),
rate: Rate::from_integer(1234567891, 0).unwrap(),
Expand Down Expand Up @@ -273,7 +274,7 @@ mod tests {
jsonrpc: JsonRpcVersion::V2,
params: PushUpdate(FeedUpdateParams {
feed_id: PriceFeedId(1),
source_timestamp: TimestampUs(124214124124),
source_timestamp: TimestampUs::from_micros(124214124124),
update: UpdateParams::FundingRateUpdate {
price: None,
rate: Rate::from_integer(1234567891, 0).unwrap(),
Expand Down
1 change: 1 addition & 0 deletions lazer/sdk/rust/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod serde_price_as_i64;
mod serde_str;
pub mod subscription;
pub mod symbol_state;
pub mod time;

#[test]
fn magics_in_big_endian() {
Expand Down
15 changes: 9 additions & 6 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Types representing binary encoding of signable payloads and signature envelopes.

use {
super::router::{PriceFeedId, PriceFeedProperty, TimestampUs},
crate::router::{ChannelId, Price, Rate},
super::router::{PriceFeedId, PriceFeedProperty},
crate::{
router::{ChannelId, Price, Rate},
time::TimestampUs,
},
anyhow::bail,
byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt, BE, LE},
serde::{Deserialize, Serialize},
Expand Down Expand Up @@ -103,7 +106,7 @@ impl PayloadData {

pub fn serialize<BO: ByteOrder>(&self, mut writer: impl Write) -> anyhow::Result<()> {
writer.write_u32::<BO>(PAYLOAD_FORMAT_MAGIC)?;
writer.write_u64::<BO>(self.timestamp_us.0)?;
writer.write_u64::<BO>(self.timestamp_us.as_micros())?;
writer.write_u8(self.channel_id.0)?;
writer.write_u8(self.feeds.len().try_into()?)?;
for feed in &self.feeds {
Expand Down Expand Up @@ -162,7 +165,7 @@ impl PayloadData {
if magic != PAYLOAD_FORMAT_MAGIC {
bail!("magic mismatch");
}
let timestamp_us = TimestampUs(reader.read_u64::<BO>()?);
let timestamp_us = TimestampUs::from_micros(reader.read_u64::<BO>()?);
let channel_id = ChannelId(reader.read_u8()?);
let num_feeds = reader.read_u8()?;
let mut feeds = Vec::with_capacity(num_feeds.into());
Expand Down Expand Up @@ -252,7 +255,7 @@ fn write_option_timestamp<BO: ByteOrder>(
match value {
Some(value) => {
writer.write_u8(1)?;
writer.write_u64::<BO>(value.0)
writer.write_u64::<BO>(value.as_micros())
}
None => {
writer.write_u8(0)?;
Expand All @@ -266,7 +269,7 @@ fn read_option_timestamp<BO: ByteOrder>(
) -> std::io::Result<Option<TimestampUs>> {
let present = reader.read_u8()? != 0;
if present {
Ok(Some(TimestampUs(reader.read_u64::<BO>()?)))
Ok(Some(TimestampUs::from_micros(reader.read_u64::<BO>()?)))
} else {
Ok(None)
}
Expand Down
Loading