Skip to content

feat(perps): sync controller from mobile — balance split + mode-aware spot fold#8678

Merged
michalconsensys merged 4 commits intomainfrom
feat/perps/sync-4-may-2026
May 4, 2026
Merged

feat(perps): sync controller from mobile — balance split + mode-aware spot fold#8678
michalconsensys merged 4 commits intomainfrom
feat/perps/sync-4-may-2026

Conversation

@michalconsensys
Copy link
Copy Markdown
Contributor

@michalconsensys michalconsensys commented May 4, 2026

Explanation

Syncs app/controllers/perps/ from MetaMask Mobile commit 355c9b656b to packages/perps-controller/src/.

Key changes

  • BREAKING: AccountState balance renameavailableBalancespendableBalance, availableToTradeBalancewithdrawableBalance for clearer semantics across HL abstraction modes (Unified, Standard, Portfolio)
  • Mode-aware spot foldaddSpotBalanceToAccountState now folds free spot USDC into both spendableBalance and withdrawableBalance for Unified/Portfolio modes, while Standard/DEX-abstraction modes keep spot separate
  • Throttled WS-driven userAbstraction refresh — HL-web mode flips (Unified ↔ Standard) now propagate back without requiring a restart or account switch

Mobile PRs included

Files changed (12 source files)

  • constants/hyperLiquidConfig.ts — minor config tweak
  • constants/perpsConfig.ts — add ABSTRACTION_MODE_REFRESH_THROTTLE_MS
  • providers/HyperLiquidProvider.ts — balance field renames, mode-aware fold
  • providers/MYXProvider.ts — balance field renames
  • services/HyperLiquidSubscriptionService.ts — per-user abstraction mode maps, throttled WS refresh, balance renames
  • types/hyperliquid-types.ts — new types for abstraction mode handling
  • types/index.tsAccountState field renames with JSDoc
  • utils/accountUtils.tsaddSpotBalanceToAccountState refactor with resolveFoldedBalance helper
  • utils/hyperLiquidAdapter.ts — balance field renames
  • utils/hyperLiquidValidation.ts — balance field renames
  • utils/myxAdapter.ts — balance field renames
  • utils/orderCalculations.ts — balance field renames

Suppressions

1 new ESLint suppression: @typescript-eslint/no-unused-vars in HyperLiquidSubscriptionService.ts — caused by core's no-unnecessary-type-assertion rule removing a as Promise<UserAbstractionResponse> cast that mobile has, leaving the import unused. Total perps suppression count: 9.

References

  • Sync state: .sync-state.json updated to mobile commit 355c9b656b
  • Sync script: scripts/perps/validate-core-sync.sh

Changelog

See packages/perps-controller/CHANGELOG.md — entries added under ## [Unreleased].

Note: CHANGELOG PR links use #NNNN placeholder — will be updated with this PR's number after creation.

Made with Cursor


Note

Medium Risk
Medium risk because it introduces breaking changes to the AccountState contract and adjusts HyperLiquid balance/withdraw validation and spot-collateral folding based on abstraction mode, which can directly affect displayed balances and allowed withdrawals/orders.

Overview
BREAKING: Renames AccountState balance fields to spendableBalance and withdrawableBalance and updates all perps providers/adapters/calculations/validation to use the new semantics (including per-subaccount breakdown and cache hashing).

Makes spot USDC folding mode-aware: addSpotBalanceToAccountState now always impacts totalBalance, and only contributes to spendableBalance/withdrawableBalance when userAbstraction indicates Unified/Portfolio mode; disk cache key is bumped to PERPS_DISK_CACHE_USER_DATA_V2 to avoid stale legacy payloads.

Improves live mode handling by adding a throttled, per-user WS-triggered userAbstraction refresh in HyperLiquidSubscriptionService so HL-web mode flips propagate without restart/account switch, and adds a guard in HyperLiquidProvider.updateIsolatedMargin to ensure spendableBalance covers margin additions.

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

Syncs app/controllers/perps/ from mobile commit 355c9b656b.

Changes:
- Rename AccountState.availableBalance → spendableBalance and
  availableToTradeBalance → withdrawableBalance for clearer semantics
  across HL abstraction modes (Unified, Standard, Portfolio)
- Mode-aware spot fold: addSpotBalanceToAccountState now folds free
  spot USDC into spendableBalance and withdrawableBalance for
  Unified/Portfolio modes; Standard/DEX-abstraction modes keep spot
  separate
- Add throttled WS-driven userAbstraction refresh so HL-web mode
  flips propagate back without restart or account switch
@michalconsensys michalconsensys marked this pull request as ready for review May 4, 2026 14:35
@michalconsensys michalconsensys requested review from a team as code owners May 4, 2026 14:35
Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor things.

Comment thread packages/perps-controller/CHANGELOG.md Outdated
Comment thread packages/perps-controller/CHANGELOG.md Outdated
michalconsensys and others added 2 commits May 4, 2026 17:27
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
@michalconsensys michalconsensys requested a review from mcmire May 4, 2026 16:11
Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@michalconsensys michalconsensys enabled auto-merge May 4, 2026 17:34
@michalconsensys michalconsensys added this pull request to the merge queue May 4, 2026
Merged via the queue into main with commit ea9875b May 4, 2026
366 checks passed
@michalconsensys michalconsensys deleted the feat/perps/sync-4-may-2026 branch May 4, 2026 18:00
@saustrie-consensys saustrie-consensys mentioned this pull request May 5, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants