Skip to content

Commit d07579e

Browse files
committed
feat(hermes): only return unique price updates on get_* methods
1 parent 8bee2e8 commit d07579e

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

hermes/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

hermes/src/api/rest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use {
3333
};
3434

3535
pub enum RestError {
36+
BenchmarkPriceNotUnique,
3637
UpdateDataNotFound,
3738
CcipUpdateDataNotFound,
3839
InvalidCCIPInput,
@@ -42,6 +43,9 @@ pub enum RestError {
4243
impl IntoResponse for RestError {
4344
fn into_response(self) -> Response {
4445
match self {
46+
RestError::BenchmarkPriceNotUnique => {
47+
(StatusCode::NOT_FOUND, "Benchmark price is not unique").into_response()
48+
}
4549
RestError::UpdateDataNotFound => {
4650
(StatusCode::NOT_FOUND, "Update data not found").into_response()
4751
}

hermes/src/api/rest/get_price_feed.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ pub async fn get_price_feed(
8989
.next()
9090
.ok_or(RestError::UpdateDataNotFound)?;
9191

92+
// Currently Benchmarks API doesn't support returning the previous publish time. So we
93+
// are assuming that it is doing the same filter as us and returns not found if the
94+
// price update is not unique.
95+
if let Some(prev_publish_time) = price_feed.prev_publish_time {
96+
if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time {
97+
return Err(RestError::BenchmarkPriceNotUnique);
98+
}
99+
}
100+
92101
// Note: This is a hack to get around the fact that Benchmark doesn't give per price feed
93102
// update data. Since we request only for a single feed then the whole prices update data
94103
// is this price feed update data.

hermes/src/api/rest/get_vaa.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,22 @@ pub async fn get_vaa(
9797
.map(|bytes| base64_standard_engine.encode(bytes))
9898
.ok_or(RestError::UpdateDataNotFound)?;
9999

100-
let publish_time = price_feeds_with_update_data
100+
let price_feed = price_feeds_with_update_data
101101
.price_feeds
102-
.get(0)
103-
.ok_or(RestError::UpdateDataNotFound)?
104-
.price_feed
105-
.get_price_unchecked()
106-
.publish_time;
102+
.into_iter()
103+
.next()
104+
.ok_or(RestError::UpdateDataNotFound)?;
105+
106+
let publish_time = price_feed.price_feed.get_price_unchecked().publish_time;
107+
108+
// Currently Benchmarks API doesn't support returning the previous publish time. So we
109+
// are assuming that it is doing the same filter as us and returns not found if the
110+
// price update is not unique.
111+
if let Some(prev_publish_time) = price_feed.prev_publish_time {
112+
if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time {
113+
return Err(RestError::BenchmarkPriceNotUnique);
114+
}
115+
}
107116

108117
Ok(Json(GetVaaResponse { vaa, publish_time }))
109118
}

0 commit comments

Comments
 (0)