Skip to content

Commit

Permalink
fix(apps/hermes/server): add crypto redemption rate asset type
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Nov 12, 2024
1 parent 1e692e1 commit 438e559
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/hermes/server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/hermes/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hermes"
version = "0.7.1"
version = "0.7.2"
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
edition = "2021"

Expand Down
59 changes: 56 additions & 3 deletions apps/hermes/server/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,70 @@ pub struct PriceFeedMetadata {
}

#[derive(Debug, Serialize, Deserialize, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "snake_case")]
pub enum AssetType {
Crypto,
FX,
Equity,
Metals,
Metal,
Rates,
CryptoRedemptionRate,
}

impl Display for AssetType {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{:?}", self)
match self {
AssetType::Crypto => write!(f, "crypto"),
AssetType::FX => write!(f, "fx"),
AssetType::Equity => write!(f, "equity"),
AssetType::Metal => write!(f, "metal"),
AssetType::Rates => write!(f, "rates"),
AssetType::CryptoRedemptionRate => write!(f, "crypto_redemption_rate"),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_serialize_matches_display() {
assert_eq!(
AssetType::Crypto.to_string(),
serde_json::to_string(&AssetType::Crypto)
.unwrap()
.trim_matches('"')
);
assert_eq!(
AssetType::FX.to_string(),
serde_json::to_string(&AssetType::FX)
.unwrap()
.trim_matches('"')
);
assert_eq!(
AssetType::Equity.to_string(),
serde_json::to_string(&AssetType::Equity)
.unwrap()
.trim_matches('"')
);
assert_eq!(
AssetType::Metal.to_string(),
serde_json::to_string(&AssetType::Metal)
.unwrap()
.trim_matches('"')
);
assert_eq!(
AssetType::Rates.to_string(),
serde_json::to_string(&AssetType::Rates)
.unwrap()
.trim_matches('"')
);
assert_eq!(
AssetType::CryptoRedemptionRate.to_string(),
serde_json::to_string(&AssetType::CryptoRedemptionRate)
.unwrap()
.trim_matches('"')
);
}
}
3 changes: 2 additions & 1 deletion apps/hermes/server/src/state/price_feeds_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ where
if let Some(asset_type) = &asset_type {
price_feeds_metadata.retain(|feed| {
feed.attributes.get("asset_type").map_or(false, |type_str| {
type_str.to_lowercase() == asset_type.to_string().to_lowercase()
type_str.to_lowercase().trim().replace(" ", "_")
== asset_type.to_string().to_lowercase()
})
});
}
Expand Down

0 comments on commit 438e559

Please sign in to comment.