Skip to main content

df_hyperliquid_core/live/account/
state.rs

1//! An account's clearinghouse frames: one dex's, every dex's at once, and its spot balances, each
2//! in the shape the `/info` read answers. What it may trade on one perp (`activeAssetData`) comes
3//! as [`crate::account::ActiveAssetData`].
4
5use crate::account::ClearinghouseState;
6use crate::utils::Address;
7use serde::Deserialize;
8
9/// `clearinghouseState`: one dex's clearinghouse (`dex` empty for the first).
10#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct DexState {
13    pub dex: String,
14    pub user: Address,
15    #[serde(rename = "clearinghouseState")]
16    pub state: ClearinghouseState,
17}
18
19/// `allDexsClearinghouseState`: every dex's clearinghouse, the first named `""`.
20#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct AllDexsState {
23    pub user: Address,
24    #[serde(rename = "clearinghouseStates")]
25    pub states: Vec<(String, ClearinghouseState)>,
26}
27
28/// `spotState`: spot balances, outcome sides among them (`+14720`, with no token).
29#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct SpotState {
32    pub user: Address,
33    /// The shape `spotClearinghouseState` answers.
34    #[serde(rename = "spotState")]
35    pub state: crate::account::SpotState,
36}
37
38#[cfg(test)]
39#[path = "tests/state.rs"]
40mod tests;