Skip to content

Commit ea69d88

Browse files
committed
remove unused dept, make some params optional, bump ver
1 parent 3df3efd commit ea69d88

File tree

3 files changed

+99
-34
lines changed

3 files changed

+99
-34
lines changed

Cargo.lock

Lines changed: 15 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/protocol/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-protocol"
3-
version = "0.7.3"
3+
version = "0.8.0"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"
@@ -16,7 +16,6 @@ itertools = "0.13.0"
1616
rust_decimal = "1.36.0"
1717
protobuf = "3.7.2"
1818
humantime-serde = "1.1.1"
19-
jsonrpc-types = "0.3.3"
2019

2120
[dev-dependencies]
2221
bincode = "1.3.3"

lazer/sdk/rust/protocol/src/jrpc.rs

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub enum UpdateParams {
3232
#[serde(rename = "price")]
3333
PriceUpdate {
3434
price: Price,
35-
best_bid_price: Price,
36-
best_ask_price: Price,
35+
best_bid_price: Option<Price>,
36+
best_ask_price: Option<Price>,
3737
},
3838
#[serde(rename = "funding_rate")]
39-
FundingRateUpdate { price: Price, rate: Rate },
39+
FundingRateUpdate { price: Option<Price>, rate: Rate },
4040
}
4141

4242
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
@@ -160,8 +160,47 @@ mod tests {
160160
source_timestamp: TimestampUs(124214124124),
161161
update: UpdateParams::PriceUpdate {
162162
price: Price::from_integer(1234567890, 0).unwrap(),
163-
best_bid_price: Price::from_integer(1234567891, 0).unwrap(),
164-
best_ask_price: Price::from_integer(1234567892, 0).unwrap(),
163+
best_bid_price: Some(Price::from_integer(1234567891, 0).unwrap()),
164+
best_ask_price: Some(Price::from_integer(1234567892, 0).unwrap()),
165+
},
166+
}),
167+
id: 1,
168+
};
169+
170+
assert_eq!(
171+
serde_json::from_str::<PythLazerAgentJrpcV1>(json).unwrap(),
172+
expected
173+
);
174+
}
175+
176+
#[test]
177+
fn test_push_update_price_without_bid_ask() {
178+
let json = r#"
179+
{
180+
"jsonrpc": "2.0",
181+
"method": "push_update",
182+
"params": {
183+
"feed_id": 1,
184+
"source_timestamp": 124214124124,
185+
186+
"update": {
187+
"type": "price",
188+
"price": 1234567890
189+
}
190+
},
191+
"id": 1
192+
}
193+
"#;
194+
195+
let expected = PythLazerAgentJrpcV1 {
196+
jsonrpc: JsonRpcVersion::V2,
197+
params: PushUpdate(FeedUpdateParams {
198+
feed_id: PriceFeedId(1),
199+
source_timestamp: TimestampUs(124214124124),
200+
update: UpdateParams::PriceUpdate {
201+
price: Price::from_integer(1234567890, 0).unwrap(),
202+
best_bid_price: None,
203+
best_ask_price: None,
165204
},
166205
}),
167206
id: 1,
@@ -199,7 +238,7 @@ mod tests {
199238
feed_id: PriceFeedId(1),
200239
source_timestamp: TimestampUs(124214124124),
201240
update: UpdateParams::FundingRateUpdate {
202-
price: Price::from_integer(1234567890, 0).unwrap(),
241+
price: Some(Price::from_integer(1234567890, 0).unwrap()),
203242
rate: Rate::from_integer(1234567891, 0).unwrap(),
204243
},
205244
}),
@@ -211,6 +250,44 @@ mod tests {
211250
expected
212251
);
213252
}
253+
#[test]
254+
fn test_push_update_funding_rate_without_price() {
255+
let json = r#"
256+
{
257+
"jsonrpc": "2.0",
258+
"method": "push_update",
259+
"params": {
260+
"feed_id": 1,
261+
"source_timestamp": 124214124124,
262+
263+
"update": {
264+
"type": "funding_rate",
265+
"rate": 1234567891
266+
}
267+
},
268+
"id": 1
269+
}
270+
"#;
271+
272+
let expected = PythLazerAgentJrpcV1 {
273+
jsonrpc: JsonRpcVersion::V2,
274+
params: PushUpdate(FeedUpdateParams {
275+
feed_id: PriceFeedId(1),
276+
source_timestamp: TimestampUs(124214124124),
277+
update: UpdateParams::FundingRateUpdate {
278+
price: None,
279+
rate: Rate::from_integer(1234567891, 0).unwrap(),
280+
},
281+
}),
282+
id: 1,
283+
};
284+
285+
assert_eq!(
286+
serde_json::from_str::<PythLazerAgentJrpcV1>(json).unwrap(),
287+
expected
288+
);
289+
}
290+
214291
#[test]
215292
fn test_send_get_metadata() {
216293
let json = r#"

0 commit comments

Comments
 (0)