Skip to content

Perps/fix available to trade balance core wt#8534

Draft
geositta wants to merge 2 commits intomainfrom
perps/fix-available-to-trade-balance-core-wt
Draft

Perps/fix available to trade balance core wt#8534
geositta wants to merge 2 commits intomainfrom
perps/fix-available-to-trade-balance-core-wt

Conversation

@geositta
Copy link
Copy Markdown

Explanation

This change fixes a controller gap in @metamask/perps-controller where consumers could not distinguish between withdrawable funds and actual trading buying power for HyperLiquid accounts.

The controller only exposed availableBalance, which maps to HyperLiquid withdrawable, so clients using that field for funded state checks could incorrectly treat spot-funded accounts as unfunded even when HyperLiquid shows usable buying power.

The improvement is a new availableToTradeBalance field on perps account state. For HyperLiquid, it is calculated from perps withdrawable balance plus spot USDC, while availableBalance remains unchanged as the withdrawable only value.

The field is populated in both one-shot account fetches and live streamed account updates, and the shared account aggregation path carries it through consistently.

This gives mobile and extension a dedicated funded-state signal without changing existing withdraw behavior or order-entry calculations.

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

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.

1 participant