fix: resolve ORDER_PRICE_REQUIRED error on perps position flip#29691
Conversation
ORDER_PRICE_REQUIRED error on perps position flip
michalconsensys
left a comment
There was a problem hiding this comment.
@gambinish the PR looks good. I've tested it locally and everything seems to work well, however the unit tests are failing
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 15e9295. Configure here.
…k/metamask-mobile into fix/perps/flip-position-tat-2123
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
These are behavioral changes to the perps order placement flow that directly affect the SmokePerps: Directly affected - the SmokeWalletPlatform: Required per SmokePerps tag description - Perps is a section inside the Trending tab, and changes to Perps views affect Trending. SmokeConfirmations: Required per SmokePerps tag description - Add Funds deposits are on-chain transactions that go through confirmations. No UI components, navigation, shared components, or other feature areas are affected. The changes are purely in the provider layer of the perps controller. Performance Test Selection: |
|




Description
TradingService.flipPosition() deliberately omits currentPrice from the order params it passes to provider.placeOrder() — passing a stale entry price would corrupt IOC slippage calculation. However, placeOrder() was running #validateOrderBeforePlacement before fetching the live price, so the minimum-USD check had no price to work with and threw ORDER_PRICE_REQUIRED on every flip.
Root cause: step ordering in HyperLiquidProvider.placeOrder(). Validation ran at step 1; the live price fetch (#getAssetInfo) ran at step 3.
Fix: reorder placeOrder() so #getAssetInfo runs first, compute effectivePrice (live price, or caller-supplied price if present), then pass it into #validateOrderBeforePlacement. #ensureReadyForTrading stays after validation, so invalid orders never trigger builder-fee / DEX-abstraction signature prompts unnecessarily.
As a follow-on, effectivePrice is hoisted above the try block so the $10-minimum retry path can also use the fetched price when the caller omits currentPrice — without this, a flip order that hit the $10 edge case would fail silently instead of retrying.
No changes to TradingService.flipPosition — the intentional omission of entryPrice is correct and preserved.
Affected tests:
Three HyperLiquidProvider tests updated to reflect the new ordering (the "missing price data" error now surfaces from #getAssetInfo rather than validation; the price-less PUMP retry test now succeeds with two exchange calls)
Two new tests added for the explicit flip-order path
Changelog
CHANGELOG entry: fix regression to flip position perps
Related issues
Fixes: MetaMask/metamask-extension#42375
Manual testing steps
Screenshots/Recordings
Screen.Recording.2026-05-04.at.3.01.17.PM.mov
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Changes the execution order in
HyperLiquidProvider.placeOrder, affecting validation/signing flow and retry behavior for minimum-order errors. Risk is moderate because it touches core order placement logic, but the change is localized and covered by updated/new tests.Overview
Fixes a regression where price-less market orders (notably
flipPosition) failed withORDER_PRICE_REQUIREDby fetching the live price via#getAssetInfobefore provider-level validation and validating against the computedeffectivePrice.Also hoists
effectivePriceso the "$10 minimum order value" retry path can derive an adjustedusdAmountfrom the fetched price whencurrentPriceis omitted. Updates existing tests and adds new coverage to assert success for flip-style params, the $10-minimum retry behavior, and the revised error surfaced when price data is missing.Reviewed by Cursor Bugbot for commit 106369c. Bugbot is set up for automated code reviews on this repo. Configure here.