Skip to content

Take perpetual balance from spot state for unified accounts - #838

Merged
DRadmir merged 4 commits into
mainfrom
wt3/hypercore-unified-ws-balance
Aug 7, 2026
Merged

Take perpetual balance from spot state for unified accounts#838
DRadmir merged 4 commits into
mainfrom
wt3/hypercore-unified-ws-balance

Conversation

@DRadmir

@DRadmir DRadmir commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Perpetual balance jumped between the real value and zero for wallets with unified account mode enabled. Their trading money lives in the spot balance, while the app read it from the perpetual account, which is empty for such wallets.

Now the balance for those wallets comes from the spot state and the available amount is the one Hyperliquid itself reports. The same money is no longer counted twice in the wallet total, and sending no longer offers the part that backs an open position. Wallets in the standard mode keep working as before.

Closes #675

Unified account and portfolio margin keep the trading balance in the spot
clearinghouse, so the perpetual clearinghouse reports zeros for them and the
socket kept overwriting the balance with those zeros.

Subscribe to spotState for such accounts and take the balance from
tokenToAvailableAfterMaintenance, which is what Hyperliquid reports as
available. The clearinghouse stays the source of the balance for standard
accounts, so their equity keeps updating with position PnL over the socket.
@DRadmir DRadmir self-assigned this Aug 5, 2026
@DRadmir
DRadmir requested review from gemcoder21 and gemdev111 August 5, 2026 09:15
DRadmir added 2 commits August 5, 2026 18:20
For unified accounts the perpetual collateral is the spot balance itself, so
adding it to the wallet total counted the same money twice. Store the account
mode per wallet when the observer resolves it, and skip the perpetual term for
such wallets. Standard accounts keep a separate pot and stay unchanged.
The spot balance reported the full total as available and ignored the held
part, so sending offered funds that back an open position or a resting order.
Take the amount Hyperliquid reports as available after maintenance margin when
it is present, and fall back to total minus hold otherwise.
Comment thread core/gemstone/src/gateway/mod.rs Outdated
Comment thread core/crates/gem_hypercore/src/provider/websocket_mapper.rs Outdated
The account mode gateway call now returns a result instead of silently
falling back to standard, which would drop the spot state subscription
for a unified wallet. Both apps fall back to the mode stored for the
wallet instead.
@DRadmir
DRadmir merged commit 806d5a1 into main Aug 7, 2026
7 checks passed
@DRadmir
DRadmir deleted the wt3/hypercore-unified-ws-balance branch August 7, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Perpetuals balance amount jumps from value to zero

2 participants