Skip to main content

df_hyperliquid_core/live/account/
web_data.rs

1//! `webData3`: the account as Hyperliquid's own frontend reads it, its user state and each perp
2//! dex's. Only the fields the docs list, and the account mode, are read.
3
4use crate::utils::{Address, Dec};
5use serde::Deserialize;
6
7/// `webData3`: the account as Hyperliquid's own frontend reads it. The docs warn that fields they do
8/// not list may go; only the listed ones and `abstraction` are read.
9#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct WebData3 {
12    pub user_state: UserState,
13    pub perp_dex_states: Vec<PerpDexState>,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
17#[serde(rename_all = "camelCase")]
18pub struct UserState {
19    pub user: Address,
20    #[serde(default)]
21    pub agent_address: Option<Address>,
22    /// Milliseconds.
23    #[serde(default)]
24    pub agent_valid_until: Option<u64>,
25    /// Milliseconds.
26    pub server_time: u64,
27    pub cum_ledger: Dec,
28    pub is_vault: bool,
29    /// The account mode: `disabled`, `default`, `unifiedAccount`, `portfolioMargin`.
30    #[serde(default)]
31    pub abstraction: Option<String>,
32    #[serde(default)]
33    pub dex_abstraction_enabled: bool,
34    #[serde(default)]
35    pub opt_out_of_spot_dusting: bool,
36}
37
38/// One perp dex, in the order the dexes are listed.
39#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct PerpDexState {
42    pub total_vault_equity: Dec,
43    #[serde(default)]
44    pub perps_at_open_interest_cap: Vec<String>,
45    #[serde(default)]
46    pub leading_vaults: Vec<LeadingVault>,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
50pub struct LeadingVault {
51    pub address: Address,
52    pub name: String,
53}
54
55#[cfg(test)]
56#[path = "tests/web_data.rs"]
57mod tests;