df_hyperliquid_core/transfer/keeping.rs
1//! How an account keeps its balances, from `userAbstraction`'s word. It decides how a spot token
2//! leaves the account (the venue refuses `spotSend` to a pooled one) and where its USDC is read back.
3
4/// Where an account's balances sit.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum Keeping {
7 /// Standard (`disabled`, `default`, and the discontinued
8 /// `dexAbstraction`): each perp dex and spot hold their own.
9 Apart,
10 /// Unified (`unifiedAccount`) or portfolio margin (`portfolioMargin`): one
11 /// balance a token, in spot. Such an account is refused `spotSend`.
12 Pooled,
13 /// Not read yet, or a word this build does not know.
14 Unknown,
15}
16
17impl Keeping {
18 /// From `userAbstraction`'s answer.
19 #[must_use]
20 pub fn of(mode: &str) -> Keeping {
21 match mode {
22 "unifiedAccount" | "portfolioMargin" => Keeping::Pooled,
23 "disabled" | "default" | "dexAbstraction" => Keeping::Apart,
24 _ => Keeping::Unknown,
25 }
26 }
27
28 /// Whether perps and spot draw on the one balance.
29 #[must_use]
30 pub const fn pools(self) -> bool {
31 matches!(self, Keeping::Pooled)
32 }
33}