Skip to content

fix(perps-controller): keep open position margin mode on HyperLiquid orders - #10588

Merged
abretonc7s merged 3 commits into
mainfrom
TAT-3994-flip-preserve-margin-mode
Sep 30, 2026
Merged

abretonc7s merged 3 commits into
mainfrom
TAT-3994-flip-preserve-margin-mode

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

TradingService.flipPosition sends leverage with no marginMode. HyperLiquidProvider.#prepareAssetForTrading then fell back to isolated and called updateLeverage({ isCross: false }). On a Cross position, HyperLiquid rejects that with "Cannot switch leverage type with open position". On Mobile, every one of these failures (64 events from 20 users over 30 days) was a position flip.

When an order omits marginMode, HyperLiquid now uses the open position's mode. It reads positions from the fresh WebSocket cache and falls back to one REST read. With no position, or if the read fails, it keeps the old isolated default. Orders that set marginMode explicitly are unchanged.

The fix is in the HyperLiquid provider, not in flipPosition: Lighter rejects any order that sets marginMode, so passing position.leverage.type from the shared service would break Lighter flips.

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

@abretonc7s
abretonc7s marked this pull request as ready for review September 29, 2026 23:33
@abretonc7s
abretonc7s requested review from a team as code owners September 29, 2026 23:33
@abretonc7s
abretonc7s deployed to default-branch September 29, 2026 23:33 — with GitHub Actions Active
@abretonc7s
abretonc7s added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit 75e2c64 Sep 30, 2026
43 checks passed
@abretonc7s
abretonc7s deleted the TAT-3994-flip-preserve-margin-mode branch September 30, 2026 00:40
@abretonc7s abretonc7s mentioned this pull request Sep 30, 2026
3 of 4 tasks
github-merge-queue Bot pushed a commit that referenced this pull request Sep 30, 2026
## Explanation

- Release major perps-controller 19.0.0

Breaking changes (see changelog):
- `OrderFill.liquidation.liquidatedUser` is now optional
- `FrontendOrder.orderType` union adds `Twap Slice`, `Vault Close`,
`Spot Dust Conversion`
- Removed `LighterPersonalSigner` and the `personalSigner` / `l1Address`
fields of `LighterAuthConfig`

## References

- #10414, #10437, #10464, #10559, #10588, #10589, #10591

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
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.

2 participants