Skip to content

fix: resolve ORDER_PRICE_REQUIRED error on perps position flip#29691

Merged
gambinish merged 5 commits into
mainfrom
fix/perps/flip-position-tat-2123
May 5, 2026
Merged

fix: resolve ORDER_PRICE_REQUIRED error on perps position flip#29691
gambinish merged 5 commits into
mainfrom
fix/perps/flip-position-tat-2123

Conversation

@gambinish
Copy link
Copy Markdown
Member

@gambinish gambinish commented May 4, 2026

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

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Screen.Recording.2026-05-04.at.3.01.17.PM.mov

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

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 with ORDER_PRICE_REQUIRED by fetching the live price via #getAssetInfo before provider-level validation and validating against the computed effectivePrice.

Also hoists effectivePrice so the "$10 minimum order value" retry path can derive an adjusted usdAmount from the fetched price when currentPrice is 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.

@metamaskbotv2 metamaskbotv2 Bot added the team-perps Perps team label May 4, 2026
@github-actions github-actions Bot added the size-M label May 4, 2026
@gambinish gambinish changed the title fix: flip position fix: resolve ORDER_PRICE_REQUIRED error on perps position flip May 4, 2026
@gambinish gambinish marked this pull request as ready for review May 4, 2026 22:02
@gambinish gambinish requested a review from a team as a code owner May 4, 2026 22:02
Copy link
Copy Markdown
Contributor

@michalconsensys michalconsensys left a comment

Choose a reason for hiding this comment

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

@gambinish the PR looks good. I've tested it locally and everything seems to work well, however the unit tests are failing

abretonc7s
abretonc7s previously approved these changes May 5, 2026
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

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

.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread app/controllers/perps/providers/HyperLiquidProvider.test.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are isolated to HyperLiquidProvider.ts and its test file. The modifications refactor the placeOrder method to:

  1. Fetch asset info/live price BEFORE validation (instead of after), so price-less callers like flipPosition can validate against the live fetched price
  2. Hoist effectivePrice variable so the $10 minimum retry path can use the fetched price even when params.currentPrice is absent
  3. Move #ensureReadyForTrading() after validation to avoid triggering signature prompts for invalid orders

These are behavioral changes to the perps order placement flow that directly affect the flipPosition path. The fix changes when validation occurs and what price is used for validation/retry logic.

SmokePerps: Directly affected - the placeOrder method is the core of perps trading. The flipPosition flow (which omits currentPrice) now works correctly. E2E tests should validate the Add Funds flow and position management.

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:
The changes modify the order placement flow in HyperLiquidProvider, specifically reordering operations (price fetch before validation) and fixing the flipPosition path. While these are logic fixes rather than rendering changes, the reordering of async operations (price fetch → validation → ensureReadyForTrading) could affect the timing/performance of the perps Add Funds flow and order execution. @PerformancePreps covers perps market loading, position management, add funds flow, and order execution - all directly relevant to these changes.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@gambinish gambinish enabled auto-merge May 5, 2026 17:49
@gambinish gambinish added this pull request to the merge queue May 5, 2026
Merged via the queue into main with commit fcd05a6 May 5, 2026
176 of 178 checks passed
@gambinish gambinish deleted the fix/perps/flip-position-tat-2123 branch May 5, 2026 19:55
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RELEASE BLOCKER] [Bug]: Perps: Reverse position: Order could not be placed. Try again

4 participants