Skip to content

[perps-controller] Make Hyperliquid max withdrawable decimal-safe - #11253

Open
geositta wants to merge 3 commits into
mainfrom
TAT-4345-hl-max-withdrawable-decimal-safe
Open

geositta wants to merge 3 commits into
mainfrom
TAT-4345-hl-max-withdrawable-decimal-safe

Conversation

@geositta

@geositta geositta commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Hyperliquid unified-account balances were aggregated with native JavaScript numbers. Equivalent six-decimal spot.total - spot.hold inputs could therefore emit different strings and differ by one atomic USDC unit after conversion.

This change:

  • performs spot collateral subtraction and multi-DEX balance aggregation with BigNumber;
  • retains the exact perps subtotal until spot collateral has been included, then canonicalizes once to the supported six-decimal precision;
  • reuses the decimal-safe account aggregator for streamed account updates;
  • preserves genuine one-micro-USDC changes and existing sentinel behavior.

Focused regressions cover both reported operand pairs, fractional perps plus fractional spot collateral, final-only rounding across DEXs, a genuine one-micro-USDC change, streamed values, and the public Hyperliquid account-state path with isolated positions on main and HIP-3 DEXs.

Contract impact

Surface Impact
State shape None; existing balance fields remain decimal strings
Methods None
Events None
Exports None
Constants None; existing USDC_DECIMALS is reused

Consumer compatibility

MetaMask Mobile at eb837f5316d was checked at the transaction-pay balance consumers. They already convert withdrawableBalance with BigNumber, so canonical six-decimal strings require no migration. No Extension checkout was available in this workspace; the published type and API shape are unchanged.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
Open in Web Open in Cursor 

Note

Medium Risk
Changes how withdrawable and related balance strings are computed and formatted for Hyperliquid unified accounts, which can affect display and pay/withdraw validation even though the public shape is unchanged.

Reviewed by Cursor Bugbot for commit 036e491. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-authored-by: Matt D. <geositta@users.noreply.github.com>
@geositta
geositta requested a review from a team as a code owner November 3, 2026 04:30
Co-authored-by: Matt D. <geositta@users.noreply.github.com>
@cursor
cursor Bot requested a review from a team as a code owner November 3, 2026 04:30
Copilot stopped work on behalf of geositta due to an error November 3, 2026 04:42
@geositta

geositta commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-changelogs

@metamask-ci

metamask-ci Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✅ No changelog changes needed.

Co-authored-by: Matt D. <geositta@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants