Skip to content

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

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

fix(perps): handle partial Scale order acceptance#9989
abretonc7s wants to merge 11 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 exchange exposure when batches partially reject; behavior is heavily tested but mistakes could leave unintended resting orders or mis-report fills.

Overview
Scale placement no longer rolls back every rung when HyperLiquid accepts only part of a ladder. Valid mixed batches (some resting/filled, some rejected) return success: true with live orders registered; childOrderIds stays limited to resting rungs for group cancel, while acceptedChildren, acceptedSize, filledSize, averagePrice, and weightedAverageLimitPrice describe the full accepted outcome.

The provider unwraps pinned SDK ApiRequestError responses only when the bulk payload is a complete, genuinely mixed Scale result; malformed, all-waiting, unclassified, or all-rejected batches still fail and trigger cleanup. Cleanup now cancels resting orders by OID and waiting/unclassified rungs by CLOID, with cancel-batch helpers parsing partial cancel errors the same way.

OrderResult and exports gain ScaleOrderChild; TradingService trade analytics and partial-fill events key off accepted size and scale limit pricing so rejected rungs are not counted as unfilled exposure. Scale UI analytics constants are added to eventNames, and the changelog records the fix.

Reviewed by Cursor Bugbot for commit 0ebb349. 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

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am requesting changes before merge. The Hyperliquid mixed-response recovery follows the documented non-atomic batch model, but the current result contract can leave status entries untracked and changes the established meanings of childOrderIds, averagePrice, and submittedSize. Please use one discriminated status parser for thrown and resolved responses, preserve cancellable-only child IDs or introduce typed child states, and add explicit fields for accepted size and weighted limit price. This will keep the API contract precise and give Pro traders accurate partial-placement information.

Validation completed: 449 focused tests passed, the root monorepo build passed, changelog validation passed, git diff --check passed, and all current PR checks pass.

Comment thread packages/perps-controller/src/providers/HyperLiquidProvider.ts
Comment thread packages/perps-controller/src/types/index.ts Outdated
Comment thread packages/perps-controller/src/providers/HyperLiquidProvider.ts Outdated
Comment thread packages/perps-controller/src/providers/HyperLiquidProvider.ts Outdated

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for addressing the previous result-contract findings. submittedSize, averagePrice, childOrderIds, and the new typed accepted-result fields now have clear, compatible meanings.

I am requesting changes for one lifecycle-safety gap and two reporting inconsistencies. Waiting children need cancellation recovery across provider disconnects, mixed filled/resting analytics need internally consistent size and notional dimensions, and the released 13.0.0 changelog must not advertise fields introduced by this unreleased change.

Validation completed: 468 focused tests passed, changelog validation and diff checks passed, and current PR CI is green. No React or React Native code changed.

Comment thread packages/perps-controller/src/providers/HyperLiquidProvider.ts Outdated
Comment thread packages/perps-controller/src/services/TradingService.ts
Comment thread packages/perps-controller/CHANGELOG.md Outdated
@abretonc7s
abretonc7s enabled auto-merge August 29, 2026 02:47
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.

2 participants