Skip to content

fix(perps): handle partial Scale order acceptance - #9989

Open
abretonc7s wants to merge 7 commits into
mainfrom
fix/perps-scale-partial-acceptance
Open

fix(perps): handle partial Scale order acceptance#9989
abretonc7s wants to merge 7 commits into
mainfrom
fix/perps-scale-partial-acceptance

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

Upstreams the Scale partial-acceptance behavior temporarily carried by MetaMask Mobile #35176. Accepted Scale rungs remain live, successful results include accepted resting and filled IDs, and returned exposure plus analytics reflect accepted rungs.

Core's pinned @nktkas/hyperliquid 0.33.1 throws mixed bulk responses as ApiRequestError. This PR narrowly recovers only complete, genuinely mixed Scale responses. Malformed, waiting, invalid-ID, hybrid, top-level, unrelated, and all-rejected errors remain on the existing failure path.

Mobile temporarily carries this behavior as a compiled @metamask/perps-controller v13 Yarn patch until the next Core release. This PR does not publish or bump a version.

Changes

  • Keep valid partial Scale placements instead of retracting accepted rungs.
  • Retain only resting IDs for later group cancellation.
  • Recover valid mixed Scale responses thrown by the pinned SDK.
  • Preserve original errors for malformed and all-rejected batches, including multi-sig mapping.
  • Add accepted size, weighted average price, analytics fallbacks, and typed Scale event constants.
  • Preserve stale-generation cleanup and existing failure behavior.

Validation

  • Full perps package: 3,183 passed, 40 skipped.
  • Focused controller, TradingService, and event constants: 449 passed.
  • Root build, focused ESLint, Prettier, changelog validation, and diff checks passed.
  • Retained Claude review: APPROVE on 679a6f0.
  • Retained Codex review: APPROVE on 679a6f0.
  • PR CI: 40 successful checks, 5 skipped, no failures.

Related issues


Note

Medium Risk
Changes live HyperLiquid Scale order placement and success semantics when batches partially reject; incorrect parsing could mis-report success or leave unexpected orders, though behavior is narrowly scoped and heavily tested.

Overview
Scale placement no longer treats a partially rejected ladder as a full failure. When HyperLiquid accepts some rungs and rejects others, accepted resting and filled orders stay on the book and the call returns success with exposure limited to what actually landed.

#placeScaleOrder now unwraps mixed bulk responses that the pinned SDK throws as ApiRequestError, validates them strictly, and only then treats them like a normal ok response. All-rejected, malformed, or unrelated errors still follow the existing failure and error-mapping paths (including multi-sig). Successful results expose all accepted child IDs (resting and filled), while the scale group handle still tracks resting IDs for cancellation. submittedSize and averagePrice reflect the accepted rungs’ total size and value-weighted price.

Trade analytics prefer submittedSize (then filledSize) for order_size and order_value, and typed Scale event property, interaction, and setting constants are added for clients.

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

@abretonc7s
abretonc7s marked this pull request as ready for review August 28, 2026 01:14
@abretonc7s
abretonc7s requested review from a team as code owners August 28, 2026 01:14
@abretonc7s
abretonc7s deployed to default-branch August 28, 2026 01:14 — with GitHub Actions Active
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.

1 participant