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    /// `userState`: the account's own fields.
13    pub user_state: UserState,
14    /// `perpDexStates`: one entry per perp dex, in the order the dexes are listed.
15    pub perp_dex_states: Vec<PerpDexState>,
16}
17
18/// `userState` in `webData3`: the account's own fields.
19#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct UserState {
22    /// The account.
23    pub user: Address,
24    /// `agentAddress`: the agent wallet the frontend signs with; `None` when there is none.
25    #[serde(default)]
26    pub agent_address: Option<Address>,
27    /// Milliseconds.
28    #[serde(default)]
29    pub agent_valid_until: Option<u64>,
30    /// Milliseconds.
31    pub server_time: u64,
32    /// `cumLedger`: the account's cumulative ledger total, USDC.
33    pub cum_ledger: Dec,
34    /// `isVault`: whether the account is a vault.
35    pub is_vault: bool,
36    /// The account mode: `disabled`, `default`, `unifiedAccount`, `portfolioMargin`.
37    #[serde(default)]
38    pub abstraction: Option<String>,
39    /// `dexAbstractionEnabled`: whether dex abstraction is on for the account; false when not sent.
40    #[serde(default)]
41    pub dex_abstraction_enabled: bool,
42    /// `optOutOfSpotDusting`: whether the account opted out of spot dusting, the venue's sweep of
43    /// tiny spot balances; false when not sent.
44    #[serde(default)]
45    pub opt_out_of_spot_dusting: bool,
46}
47
48/// One perp dex, in the order the dexes are listed.
49#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
50#[serde(rename_all = "camelCase")]
51pub struct PerpDexState {
52    /// `totalVaultEquity`: the account's equity in vaults on this dex, USDC.
53    pub total_vault_equity: Dec,
54    /// `perpsAtOpenInterestCap`: the perps on this dex at their open interest cap; empty when not sent.
55    #[serde(default)]
56    pub perps_at_open_interest_cap: Vec<String>,
57    /// `leadingVaults`: the vaults the account leads on this dex; empty when not sent.
58    #[serde(default)]
59    pub leading_vaults: Vec<LeadingVault>,
60}
61
62/// A vault the account leads, in `leadingVaults`.
63#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
64pub struct LeadingVault {
65    /// The vault's address.
66    pub address: Address,
67    /// The vault's name.
68    pub name: String,
69}
70
71#[cfg(test)]
72#[path = "tests/web_data.rs"]
73mod tests;