Skip to content

Commit 0051203

Browse files
authored
fix(apps/hermes/server): add crypto redemption rate asset type (#2112)
Also changes Metals to Metal to match the asset type correctly.
1 parent 0a0257e commit 0051203

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

apps/hermes/server/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.

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: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,71 @@ 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,
332+
#[serde(rename = "fx")]
332333
FX,
333334
Equity,
334-
Metals,
335+
Metal,
335336
Rates,
337+
CryptoRedemptionRate,
336338
}
337339

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

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)