hyperliquid_rust_sdk_abrkn/
meta.rs1use std::collections::HashMap;
2
3use ethers::abi::ethereum_types::H128;
4use serde::Deserialize;
5
6#[derive(Deserialize, Debug, Clone)]
7pub struct Meta {
8 pub universe: Vec<AssetMeta>,
9}
10
11#[derive(Deserialize, Debug, Clone)]
12pub struct SpotMeta {
13 pub universe: Vec<SpotAssetMeta>,
14 pub tokens: Vec<TokenInfo>,
15}
16
17impl SpotMeta {
18 pub fn add_pair_and_name_to_index_map(
19 &self,
20 mut coin_to_asset: HashMap<String, u32>,
21 ) -> HashMap<String, u32> {
22 let index_to_name: HashMap<usize, &str> = self
23 .tokens
24 .iter()
25 .map(|info| (info.index, info.name.as_str()))
26 .collect();
27
28 for asset in self.universe.iter() {
29 let spot_ind: u32 = 10000 + asset.index as u32;
30 let name_to_ind = (asset.name.clone(), spot_ind);
31
32 let Some(token_1_name) = index_to_name.get(&asset.tokens[0]) else {
33 continue;
34 };
35
36 let Some(token_2_name) = index_to_name.get(&asset.tokens[1]) else {
37 continue;
38 };
39
40 coin_to_asset.insert(format!("{}/{}", token_1_name, token_2_name), spot_ind);
41 coin_to_asset.insert(name_to_ind.0, name_to_ind.1);
42 }
43
44 coin_to_asset
45 }
46}
47
48#[derive(Deserialize, Debug, Clone)]
49#[serde(untagged)]
50pub enum SpotMetaAndAssetCtxs {
51 SpotMeta(SpotMeta),
52 Context(Vec<SpotAssetContext>),
53}
54
55#[derive(Deserialize, Debug, Clone)]
56#[serde(rename_all = "camelCase")]
57pub struct SpotAssetContext {
58 pub day_ntl_vlm: String,
59 pub mark_px: String,
60 pub mid_px: Option<String>,
61 pub prev_day_px: String,
62 pub circulating_supply: String,
63 pub coin: String,
64}
65
66#[derive(Deserialize, Debug, Clone)]
67#[serde(rename_all = "camelCase")]
68pub struct AssetMeta {
69 pub name: String,
70 pub sz_decimals: u32,
71}
72
73#[derive(Deserialize, Debug, Clone)]
74#[serde(rename_all = "camelCase")]
75pub struct SpotAssetMeta {
76 pub tokens: [usize; 2],
77 pub name: String,
78 pub index: usize,
79 pub is_canonical: bool,
80}
81
82#[derive(Debug, Deserialize, Clone)]
83#[serde(rename_all = "camelCase")]
84pub struct TokenInfo {
85 pub name: String,
86 pub sz_decimals: u8,
87 pub wei_decimals: u8,
88 pub index: usize,
89 pub token_id: H128,
90 pub is_canonical: bool,
91}