fix: Withdrawal broken for Hyperliquid Unified Account Mode users#29537
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8589c97. Configure here.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag selection rationale:
The changes are medium risk - they fix a balance calculation bug for a specific user mode (Unified Account), but the logic change (preferring Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/unified-account #29537 +/- ##
=======================================================
Coverage ? 82.18%
=======================================================
Files ? 5177
Lines ? 137318
Branches ? 31046
=======================================================
Hits ? 112859
Misses ? 16818
Partials ? 7641 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
abretonc7s
left a comment
There was a problem hiding this comment.
LGTM. fixed a small bugbot




Description
Users who had enabled Unified Account Mode in Hyperliquid were seeing $0 available balance in the withdrawal flow, with the withdraw button disabled due to "Insufficient funds." This made it impossible to withdraw.
The root cause: in Unified Account Mode, USDC collateral lives in the spot clearinghouse rather than the perps clearinghouse. Our existing balance fields only read the perps-side withdrawable (which is $0 in unified mode), leaving the real balance invisible.
This PR fixes it across the full withdrawal stack:
Balance aggregation (accountUtils.ts) — folds free spot USDC into availableToTradeBalance when unified mode is active. Adds a fallback for accounts where USDC is held as perps equity rather than explicit spot (common after migrating from Standard mode).
Cache correctness (HyperLiquidSubscriptionService) — adds invalidateUserAbstractionCache so stale pre-migration mode data can't block the fold from applying.
Migration wiring (HyperLiquidProvider) — calls the invalidation after both the "already unified" and "just migrated" success paths, ensuring the WebSocket re-aggregates immediately.
Confirmation flow (useInsufficientPerpsBalanceAlert, useTransactionCustomAmount) — alert and percentage-button calculations now use availableToTradeBalance ?? availableBalance instead of reading only the perps-side balance.
Changelog
CHANGELOG entry: Fix withdrawable balance for unified account
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Screen.Recording.2026-04-29.at.5.48.21.PM.mov
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Touches perps withdrawal balance computation/validation and subscription cache behavior; a mistake could incorrectly block withdrawals or overstate withdrawable funds, but the change is localized and covered by new tests.
Overview
Fixes HyperLiquid perps withdrawal UX for Unified Account/Portfolio Margin users by consistently using
availableToTradeBalance ?? availableBalancefor the displayed withdrawable balance, insufficient-funds blocking alert, and percentage-based amount calculations.Adds
HyperLiquidSubscriptionService.invalidateUserAbstractionCache()and wiresHyperLiquidProviderto call it on successful “already enabled” and “migrated to unified” paths so the streamed account aggregation immediately re-computes with the correct fold behavior instead of serving stale pre-migration balances.Tightens spot-folding semantics in
addSpotBalanceToAccountStateso folding intoavailableToTradeBalanceis strictly gated by abstraction mode (preventing Standard/DEX-abstraction users from seeing spot USDC as perps-withdrawable), with expanded unit tests covering cache invalidation and standard-mode balance separation.Reviewed by Cursor Bugbot for commit 06e3561. Bugbot is set up for automated code reviews on this repo. Configure here.