fix(perps): handle partial Scale order acceptance - #9989
Conversation
geositta
left a comment
There was a problem hiding this comment.
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.
geositta
left a comment
There was a problem hiding this comment.
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.
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
Validation
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: truewith live orders registered;childOrderIdsstays limited to resting rungs for group cancel, whileacceptedChildren,acceptedSize,filledSize,averagePrice, andweightedAverageLimitPricedescribe the full accepted outcome.The provider unwraps pinned SDK
ApiRequestErrorresponses 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.OrderResultand exports gainScaleOrderChild;TradingServicetrade 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 toeventNames, 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.