Jelajahi Sumber

fix(apps/hermes/server): add crypto redemption rate asset type (#2112)

Also changes Metals to Metal to match the asset type correctly.
Ali Behjati 1 tahun lalu
induk
melakukan
0051203bc0

+ 1 - 1
apps/hermes/server/Cargo.lock

@@ -1796,7 +1796,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
 
 [[package]]
 name = "hermes"
-version = "0.7.1"
+version = "0.7.2"
 dependencies = [
  "anyhow",
  "async-trait",

+ 1 - 1
apps/hermes/server/Cargo.toml

@@ -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"
 

+ 57 - 3
apps/hermes/server/src/api/types.rs

@@ -326,17 +326,71 @@ pub struct PriceFeedMetadata {
 }
 
 #[derive(Debug, Serialize, Deserialize, PartialEq, ToSchema)]
-#[serde(rename_all = "lowercase")]
+#[serde(rename_all = "snake_case")]
 pub enum AssetType {
     Crypto,
+    #[serde(rename = "fx")]
     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('"')
+        );
     }
 }

+ 2 - 1
apps/hermes/server/src/state/price_feeds_metadata.rs

@@ -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()
                 })
             });
         }