Commit fcd05a6
authored
fix: resolve
## **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**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: fix regression to flip position perps
## **Related issues**
Fixes: MetaMask/metamask-extension#42375
## **Manual testing steps**
```gherkin
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**
https://github.com/user-attachments/assets/1a789aff-37e1-4e7f-825b-a4af00f14211
## **Pre-merge author checklist**
<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.
Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### 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](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->
- [ ] 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.
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
106369c. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->ORDER_PRICE_REQUIRED error on perps position flip (#29691)1 parent 95e7280 commit fcd05a6
2 files changed
Lines changed: 101 additions & 43 deletions
Lines changed: 59 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1226 | 1226 | | |
1227 | 1227 | | |
1228 | 1228 | | |
1229 | | - | |
| 1229 | + | |
1230 | 1230 | | |
1231 | 1231 | | |
1232 | 1232 | | |
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
| 1259 | + | |
| 1260 | + | |
1259 | 1261 | | |
1260 | 1262 | | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1261 | 1279 | | |
1262 | 1280 | | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
| 1281 | + | |
1268 | 1282 | | |
1269 | 1283 | | |
1270 | 1284 | | |
1271 | 1285 | | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
1277 | 1291 | | |
1278 | 1292 | | |
1279 | 1293 | | |
| |||
2812 | 2826 | | |
2813 | 2827 | | |
2814 | 2828 | | |
| 2829 | + | |
2815 | 2830 | | |
2816 | 2831 | | |
2817 | 2832 | | |
| |||
2825 | 2840 | | |
2826 | 2841 | | |
2827 | 2842 | | |
| 2843 | + | |
| 2844 | + | |
2828 | 2845 | | |
2829 | | - | |
| 2846 | + | |
2830 | 2847 | | |
2831 | 2848 | | |
2832 | 2849 | | |
| |||
3545 | 3562 | | |
3546 | 3563 | | |
3547 | 3564 | | |
3548 | | - | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
3549 | 3568 | | |
3550 | 3569 | | |
3551 | 3570 | | |
3552 | 3571 | | |
3553 | 3572 | | |
3554 | | - | |
| 3573 | + | |
3555 | 3574 | | |
3556 | 3575 | | |
3557 | 3576 | | |
3558 | 3577 | | |
3559 | | - | |
3560 | | - | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
3561 | 3604 | | |
3562 | 3605 | | |
3563 | 3606 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3543 | 3543 | | |
3544 | 3544 | | |
3545 | 3545 | | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
3546 | 3549 | | |
3547 | 3550 | | |
3548 | 3551 | | |
| |||
3557 | 3560 | | |
3558 | 3561 | | |
3559 | 3562 | | |
3560 | | - | |
3561 | | - | |
3562 | | - | |
3563 | | - | |
3564 | | - | |
3565 | | - | |
3566 | | - | |
3567 | | - | |
3568 | | - | |
3569 | | - | |
3570 | | - | |
3571 | | - | |
3572 | | - | |
3573 | | - | |
3574 | | - | |
3575 | | - | |
3576 | | - | |
3577 | | - | |
3578 | | - | |
3579 | | - | |
3580 | | - | |
3581 | 3563 | | |
3582 | 3564 | | |
3583 | 3565 | | |
3584 | | - | |
| 3566 | + | |
| 3567 | + | |
3585 | 3568 | | |
3586 | 3569 | | |
3587 | 3570 | | |
3588 | 3571 | | |
3589 | 3572 | | |
3590 | | - | |
3591 | | - | |
| 3573 | + | |
| 3574 | + | |
3592 | 3575 | | |
3593 | 3576 | | |
3594 | 3577 | | |
| |||
3601 | 3584 | | |
3602 | 3585 | | |
3603 | 3586 | | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
3604 | 3616 | | |
3605 | 3617 | | |
3606 | 3618 | | |
| |||
3706 | 3718 | | |
3707 | 3719 | | |
3708 | 3720 | | |
3709 | | - | |
3710 | | - | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
3711 | 3726 | | |
3712 | | - | |
| 3727 | + | |
3713 | 3728 | | |
3714 | 3729 | | |
3715 | 3730 | | |
| |||
0 commit comments