Skip to content

Commit 438e559

Browse files
committed
fix(apps/hermes/server): add crypto redemption rate asset type
1 parent 1e692e1 commit 438e559

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

apps/hermes/server/Cargo.lock

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

apps/hermes/server/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.7.1"
3+
version = "0.7.2"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

apps/hermes/server/src/api/types.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,70 @@ pub struct PriceFeedMetadata {
326326
}
327327

328328
#[derive(Debug, Serialize, Deserialize, PartialEq, ToSchema)]
329-
#[serde(rename_all = "lowercase")]
329+
#[serde(rename_all = "snake_case")]
330330
pub enum AssetType {
331331
Crypto,
332332
FX,
333333
Equity,
334-
Metals,
334+
Metal,
335335
Rates,
336+
CryptoRedemptionRate,
336337
}
337338

338339
impl Display for AssetType {
339340
fn fmt(&self, f: &mut Formatter) -> FmtResult {
340-
write!(f, "{:?}", self)
341+
match self {
342+
AssetType::Crypto => write!(f, "crypto"),
343+
AssetType::FX => write!(f, "fx"),
344+
AssetType::Equity => write!(f, "equity"),
345+
AssetType::Metal => write!(f, "metal"),
346+
AssetType::Rates => write!(f, "rates"),
347+
AssetType::CryptoRedemptionRate => write!(f, "crypto_redemption_rate"),
348+
}
349+
}
350+
}
351+
352+
#[cfg(test)]
353+
mod tests {
354+
use super::*;
355+
356+
#[test]
357+
fn test_serialize_matches_display() {
358+
assert_eq!(
359+
AssetType::Crypto.to_string(),
360+
serde_json::to_string(&AssetType::Crypto)
361+
.unwrap()
362+
.trim_matches('"')
363+
);
364+
assert_eq!(
365+
AssetType::FX.to_string(),
366+
serde_json::to_string(&AssetType::FX)
367+
.unwrap()
368+
.trim_matches('"')
369+
);
370+
assert_eq!(
371+
AssetType::Equity.to_string(),
372+
serde_json::to_string(&AssetType::Equity)
373+
.unwrap()
374+
.trim_matches('"')
375+
);
376+
assert_eq!(
377+
AssetType::Metal.to_string(),
378+
serde_json::to_string(&AssetType::Metal)
379+
.unwrap()
380+
.trim_matches('"')
381+
);
382+
assert_eq!(
383+
AssetType::Rates.to_string(),
384+
serde_json::to_string(&AssetType::Rates)
385+
.unwrap()
386+
.trim_matches('"')
387+
);
388+
assert_eq!(
389+
AssetType::CryptoRedemptionRate.to_string(),
390+
serde_json::to_string(&AssetType::CryptoRedemptionRate)
391+
.unwrap()
392+
.trim_matches('"')
393+
);
341394
}
342395
}

apps/hermes/server/src/state/price_feeds_metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ where
8383
if let Some(asset_type) = &asset_type {
8484
price_feeds_metadata.retain(|feed| {
8585
feed.attributes.get("asset_type").map_or(false, |type_str| {
86-
type_str.to_lowercase() == asset_type.to_string().to_lowercase()
86+
type_str.to_lowercase().trim().replace(" ", "_")
87+
== asset_type.to_string().to_lowercase()
8788
})
8889
});
8990
}

0 commit comments

Comments
 (0)