feat(hermes): only return unique price updates on get_* methods
This commit is contained in:
parent
8bee2e8e12
commit
d07579e0a6
|
@ -1574,7 +1574,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermes"
|
name = "hermes"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "hermes"
|
name = "hermes"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
|
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub use {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum RestError {
|
pub enum RestError {
|
||||||
|
BenchmarkPriceNotUnique,
|
||||||
UpdateDataNotFound,
|
UpdateDataNotFound,
|
||||||
CcipUpdateDataNotFound,
|
CcipUpdateDataNotFound,
|
||||||
InvalidCCIPInput,
|
InvalidCCIPInput,
|
||||||
|
@ -42,6 +43,9 @@ pub enum RestError {
|
||||||
impl IntoResponse for RestError {
|
impl IntoResponse for RestError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
match self {
|
match self {
|
||||||
|
RestError::BenchmarkPriceNotUnique => {
|
||||||
|
(StatusCode::NOT_FOUND, "Benchmark price is not unique").into_response()
|
||||||
|
}
|
||||||
RestError::UpdateDataNotFound => {
|
RestError::UpdateDataNotFound => {
|
||||||
(StatusCode::NOT_FOUND, "Update data not found").into_response()
|
(StatusCode::NOT_FOUND, "Update data not found").into_response()
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,15 @@ pub async fn get_price_feed(
|
||||||
.next()
|
.next()
|
||||||
.ok_or(RestError::UpdateDataNotFound)?;
|
.ok_or(RestError::UpdateDataNotFound)?;
|
||||||
|
|
||||||
|
// Currently Benchmarks API doesn't support returning the previous publish time. So we
|
||||||
|
// are assuming that it is doing the same filter as us and returns not found if the
|
||||||
|
// price update is not unique.
|
||||||
|
if let Some(prev_publish_time) = price_feed.prev_publish_time {
|
||||||
|
if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time {
|
||||||
|
return Err(RestError::BenchmarkPriceNotUnique);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Note: This is a hack to get around the fact that Benchmark doesn't give per price feed
|
// Note: This is a hack to get around the fact that Benchmark doesn't give per price feed
|
||||||
// update data. Since we request only for a single feed then the whole prices update data
|
// update data. Since we request only for a single feed then the whole prices update data
|
||||||
// is this price feed update data.
|
// is this price feed update data.
|
||||||
|
|
|
@ -97,13 +97,22 @@ pub async fn get_vaa(
|
||||||
.map(|bytes| base64_standard_engine.encode(bytes))
|
.map(|bytes| base64_standard_engine.encode(bytes))
|
||||||
.ok_or(RestError::UpdateDataNotFound)?;
|
.ok_or(RestError::UpdateDataNotFound)?;
|
||||||
|
|
||||||
let publish_time = price_feeds_with_update_data
|
let price_feed = price_feeds_with_update_data
|
||||||
.price_feeds
|
.price_feeds
|
||||||
.get(0)
|
.into_iter()
|
||||||
.ok_or(RestError::UpdateDataNotFound)?
|
.next()
|
||||||
.price_feed
|
.ok_or(RestError::UpdateDataNotFound)?;
|
||||||
.get_price_unchecked()
|
|
||||||
.publish_time;
|
let publish_time = price_feed.price_feed.get_price_unchecked().publish_time;
|
||||||
|
|
||||||
|
// Currently Benchmarks API doesn't support returning the previous publish time. So we
|
||||||
|
// are assuming that it is doing the same filter as us and returns not found if the
|
||||||
|
// price update is not unique.
|
||||||
|
if let Some(prev_publish_time) = price_feed.prev_publish_time {
|
||||||
|
if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time {
|
||||||
|
return Err(RestError::BenchmarkPriceNotUnique);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Json(GetVaaResponse { vaa, publish_time }))
|
Ok(Json(GetVaaResponse { vaa, publish_time }))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue