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