Skip to content

Commit 939b1e5

Browse files
Bump Pyth SDK, support JSON-RPC batch requests (#69)
* Fix the memory issue by bumping pyth_sdk * adapter, api: Implement JSON RPC batch requests * api.rs: Remove unused send_result() * test_integration.py: Remove debug prints * api.rs: shorten unit test expected result * api.rs: Apply review advice * changed re-serialization comment * restored full error messages * used explicit serde_json::json! for expected product schema --------- Co-authored-by: Ali Behjati <[email protected]>
1 parent 9a46ec3 commit 939b1e5

File tree

7 files changed

+386
-133
lines changed

7 files changed

+386
-133
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ serde_json = "1.0.79"
2222
tracing = "0.1.31"
2323
chrono = "0.4.19"
2424
parking_lot = "0.12.1"
25-
pyth-sdk = "0.6.0"
26-
pyth-sdk-solana = "0.6.0"
25+
pyth-sdk = "0.7.0"
26+
pyth-sdk-solana = "0.7.1"
2727
solana-client = "1.10.24"
2828
solana-sdk = "1.10.24"
2929
bincode = "1.3.3"

integration-tests/tests/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ async def test_update_price_simple(self, client: PythAgentClient):
523523
assert price == 42
524524
assert conf == 2
525525

526+
526527
@pytest.mark.asyncio
527528
async def test_update_price_simple_with_keypair_hotload(self, client_hotload: PythAgentClient):
528529

src/agent/pythd/adapter.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ use {
2727
Result,
2828
},
2929
chrono::Utc,
30-
pyth_sdk::{
31-
Identifier,
30+
pyth_sdk::Identifier,
31+
pyth_sdk_solana::state::{
32+
PriceComp,
3233
PriceStatus,
3334
},
34-
pyth_sdk_solana::state::PriceComp,
3535
serde::{
3636
Deserialize,
3737
Serialize,
@@ -431,13 +431,14 @@ impl Adapter {
431431
}
432432
}
433433

434-
// TODO: implement Display on pyth_sdk::PriceStatus and then just call pyth_sdk::PriceStatus::to_string
434+
// TODO: implement Display on PriceStatus and then just call PriceStatus::to_string
435435
fn price_status_to_str(price_status: PriceStatus) -> String {
436436
match price_status {
437437
PriceStatus::Unknown => "unknown",
438438
PriceStatus::Trading => "trading",
439439
PriceStatus::Halted => "halted",
440440
PriceStatus::Auction => "auction",
441+
PriceStatus::Ignored => "ignored",
441442
}
442443
.to_string()
443444
}
@@ -549,6 +550,7 @@ impl Adapter {
549550
"trading" => Ok(PriceStatus::Trading),
550551
"halted" => Ok(PriceStatus::Halted),
551552
"auction" => Ok(PriceStatus::Auction),
553+
"ignored" => Ok(PriceStatus::Ignored),
552554
_ => Err(anyhow!("invalid price status: {:#?}", status)),
553555
}
554556
}
@@ -619,14 +621,12 @@ mod tests {
619621
},
620622
},
621623
iobuffer::IoBuffer,
622-
pyth_sdk::{
623-
Identifier,
624-
PriceStatus,
625-
},
624+
pyth_sdk::Identifier,
626625
pyth_sdk_solana::state::{
627626
PriceAccount,
628627
PriceComp,
629628
PriceInfo,
629+
PriceStatus,
630630
PriceType,
631631
Rational,
632632
},
@@ -1108,7 +1108,7 @@ mod tests {
11081108
agg: PriceInfo {
11091109
price: 736382,
11101110
conf: 85623946,
1111-
status: pyth_sdk::PriceStatus::Unknown,
1111+
status: pyth_sdk_solana::state::PriceStatus::Unknown,
11121112
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
11131113
pub_slot: 7262746,
11141114
},
@@ -1161,7 +1161,7 @@ mod tests {
11611161
agg: PriceInfo {
11621162
price: 8474837,
11631163
conf: 27468478,
1164-
status: pyth_sdk::PriceStatus::Unknown,
1164+
status: PriceStatus::Unknown,
11651165
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
11661166
pub_slot: 2736478,
11671167
},
@@ -1173,14 +1173,14 @@ mod tests {
11731173
agg: PriceInfo {
11741174
price: 85698,
11751175
conf: 23645,
1176-
status: pyth_sdk::PriceStatus::Trading,
1176+
status: PriceStatus::Trading,
11771177
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
11781178
pub_slot: 14765,
11791179
},
11801180
latest: PriceInfo {
11811181
price: 46985,
11821182
conf: 32565,
1183-
status: pyth_sdk::PriceStatus::Trading,
1183+
status: PriceStatus::Trading,
11841184
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
11851185
pub_slot: 4368,
11861186
},
@@ -1233,7 +1233,7 @@ mod tests {
12331233
agg: PriceInfo {
12341234
price: 8254826,
12351235
conf: 6385638,
1236-
status: pyth_sdk::PriceStatus::Trading,
1236+
status: PriceStatus::Trading,
12371237
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
12381238
pub_slot: 58462846,
12391239
},
@@ -1246,14 +1246,14 @@ mod tests {
12461246
agg: PriceInfo {
12471247
price: 8251,
12481248
conf: 7653,
1249-
status: pyth_sdk::PriceStatus::Trading,
1249+
status: PriceStatus::Trading,
12501250
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
12511251
pub_slot: 365545,
12521252
},
12531253
latest: PriceInfo {
12541254
price: 65465,
12551255
conf: 451,
1256-
status: pyth_sdk::PriceStatus::Trading,
1256+
status: PriceStatus::Trading,
12571257
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
12581258
pub_slot: 886562,
12591259
},
@@ -1266,14 +1266,14 @@ mod tests {
12661266
agg: PriceInfo {
12671267
price: 39865,
12681268
conf: 7456,
1269-
status: pyth_sdk::PriceStatus::Unknown,
1269+
status: PriceStatus::Unknown,
12701270
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
12711271
pub_slot: 865,
12721272
},
12731273
latest: PriceInfo {
12741274
price: 5846,
12751275
conf: 32468,
1276-
status: pyth_sdk::PriceStatus::Unknown,
1276+
status: PriceStatus::Unknown,
12771277
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
12781278
pub_slot: 7158,
12791279
},
@@ -1324,7 +1324,7 @@ mod tests {
13241324
agg: PriceInfo {
13251325
price: 876384,
13261326
conf: 1349364,
1327-
status: pyth_sdk::PriceStatus::Trading,
1327+
status: PriceStatus::Trading,
13281328
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
13291329
pub_slot: 987236484,
13301330
},
@@ -1337,14 +1337,14 @@ mod tests {
13371337
agg: PriceInfo {
13381338
price: 54842,
13391339
conf: 599755,
1340-
status: pyth_sdk::PriceStatus::Trading,
1340+
status: PriceStatus::Trading,
13411341
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
13421342
pub_slot: 1976465,
13431343
},
13441344
latest: PriceInfo {
13451345
price: 394764,
13461346
conf: 26485,
1347-
status: pyth_sdk::PriceStatus::Trading,
1347+
status: PriceStatus::Trading,
13481348
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
13491349
pub_slot: 369454,
13501350
},
@@ -1357,14 +1357,14 @@ mod tests {
13571357
agg: PriceInfo {
13581358
price: 65649,
13591359
conf: 55896,
1360-
status: pyth_sdk::PriceStatus::Unknown,
1360+
status: PriceStatus::Unknown,
13611361
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
13621362
pub_slot: 32976,
13631363
},
13641364
latest: PriceInfo {
13651365
price: 18616,
13661366
conf: 254458,
1367-
status: pyth_sdk::PriceStatus::Trading,
1367+
status: PriceStatus::Trading,
13681368
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
13691369
pub_slot: 3126545,
13701370
},
@@ -1418,7 +1418,7 @@ mod tests {
14181418
agg: PriceInfo {
14191419
price: 397492,
14201420
conf: 33487,
1421-
status: pyth_sdk::PriceStatus::Trading,
1421+
status: PriceStatus::Trading,
14221422
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
14231423
pub_slot: 529857382,
14241424
},
@@ -1431,14 +1431,14 @@ mod tests {
14311431
agg: PriceInfo {
14321432
price: 69854,
14331433
conf: 732565,
1434-
status: pyth_sdk::PriceStatus::Unknown,
1434+
status: PriceStatus::Unknown,
14351435
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
14361436
pub_slot: 213654,
14371437
},
14381438
latest: PriceInfo {
14391439
price: 79556,
14401440
conf: 565461,
1441-
status: pyth_sdk::PriceStatus::Trading,
1441+
status: PriceStatus::Trading,
14421442
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
14431443
pub_slot: 863125,
14441444
},
@@ -1451,14 +1451,14 @@ mod tests {
14511451
agg: PriceInfo {
14521452
price: 3265,
14531453
conf: 8962196,
1454-
status: pyth_sdk::PriceStatus::Trading,
1454+
status: PriceStatus::Trading,
14551455
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
14561456
pub_slot: 301541,
14571457
},
14581458
latest: PriceInfo {
14591459
price: 465132,
14601460
conf: 8476531,
1461-
status: pyth_sdk::PriceStatus::Unknown,
1461+
status: PriceStatus::Unknown,
14621462
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
14631463
pub_slot: 78964,
14641464
},
@@ -1509,7 +1509,7 @@ mod tests {
15091509
agg: PriceInfo {
15101510
price: 836489,
15111511
conf: 6769467,
1512-
status: pyth_sdk::PriceStatus::Trading,
1512+
status: PriceStatus::Trading,
15131513
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
15141514
pub_slot: 6863892,
15151515
},
@@ -1521,14 +1521,14 @@ mod tests {
15211521
agg: PriceInfo {
15221522
price: 61478,
15231523
conf: 312545,
1524-
status: pyth_sdk::PriceStatus::Trading,
1524+
status: PriceStatus::Trading,
15251525
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
15261526
pub_slot: 302156,
15271527
},
15281528
latest: PriceInfo {
15291529
price: 85315,
15301530
conf: 754256,
1531-
status: pyth_sdk::PriceStatus::Unknown,
1531+
status: PriceStatus::Unknown,
15321532
corp_act: pyth_sdk_solana::state::CorpAction::NoCorpAct,
15331533
pub_slot: 7101326,
15341534
},

0 commit comments

Comments
 (0)