chore(perps): Refactor HL subscription service (#24015)#24274
Conversation
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR refactors the HyperLiquid subscription service to drop subscription fallbacks. This refactor was raised during the offsite, as it is needed as a result of the hotfix we had to deploy to address Perps loading issue during the weekend. The initial PR #23753 introduced a fallback mechanism that would create new subscriptions when the properties in the data coming from the old subscriptions were missing. Given that these properties will be always missing, this PR uses the new subscriptions as a default. ## **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: null ## **Related issues** Fixes: ## **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** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** No visible change ### **After** No visible change ## **Pre-merge author checklist** - [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. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Replaces HIP‑3 webData3 fallback with per‑DEX clearinghouseState/openOrders subscriptions, adds `triggerPrice` to orders, and hardens TP/SL extraction with price-based fallback and cache re-use; tests updated accordingly. > > - **Perps Subscription Service (HIP‑3)**: > - Switch to individual subscriptions: `clearinghouseState` (positions/account) and `openOrders` (orders); use `webData3` only for OI caps. > - Remove fallback caches/handlers; centralize aggregation and cache updates; update cleanup/restore logic to handle new subs. > - Re-extract TP/SL from cached orders on `clearinghouseState` updates to prevent flicker. > - Update hashing/change-detection and notify paths; broaden reconnection restoration across subtypes. > - **TP/SL Processing**: > - New shared helper to extract TP/SL from orders; adds price-based fallback for ambiguous `Trigger` types (long/short aware) and counts TP/SL. > - **Order Model & Adapter**: > - Extend `Order` with `triggerPrice`. > - `adaptOrderFromSDK` sets `triggerPrice` (uses `triggerPx`) and prioritizes `limitPx` for price; child TP/SL preserved. > - **Tests**: > - Overhaul to reflect new HIP‑3 flow: assert `clearinghouseState`/`openOrders` usage; OI caps via `webData3`. > - Replace timeouts with `jest.runAllTimersAsync()`; add coverage for TP/SL classification, cache re-use, short/long logic, L2 book handling, and feature-flag updates. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit cd9bbb0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: abretonc7s <107169956+abretonc7s@users.noreply.github.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe changes are entirely isolated to the Perps (Perpetuals) trading feature, specifically:
The changes don't affect any other wallet features, so only SmokePerps should be run if such tests exist. |
|
| isTrigger: false, | ||
| reduceOnly: false, | ||
| isTrigger: order.isTrigger ?? false, | ||
| reduceOnly: order.reduceOnly ?? false, |
There was a problem hiding this comment.
Mock missing triggerPrice masks TP/SL test coverage (Bugbot Rules)
Low Severity
Violates the testing rule "Use realistic mock data that reflects real usage." The adaptOrderFromSDK mock doesn't include triggerPrice, but the real implementation sets order.triggerPrice = rawOrder.triggerPx when triggerPx exists. The production code at line 390 uses order.triggerPrice || order.price for TP/SL extraction from cached orders. Tests pass coincidentally because test data uses identical limitPx and triggerPx values, making the fallback to price produce correct results. If test data had limitPx != triggerPx (as real Take Profit Limit orders do), the mock would return wrong TP/SL prices. The mock should include triggerPrice: order.triggerPx || undefined to match the real adapter behavior.
|
No release label on PR. Adding release label release-7.61.6 on PR, as PR was added to branch 7.61.6 when release was cut. |



Description
This PR refactors the HyperLiquid subscription service to drop subscription fallbacks.
This refactor was raised during the offsite, as it is needed as a result of the hotfix we had to deploy to address Perps loading issue during the weekend. The initial PR
#23753 introduced a fallback mechanism that would create new subscriptions when the properties in the data coming from the old subscriptions were missing. Given that these properties will be always missing, this PR uses the new subscriptions as a default.
Source PR: #24015
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
No visible change
After
No visible change
Pre-merge author checklist
Standards.
Pre-merge reviewer checklist
Note
Refactors HyperLiquid live data flow and improves TP/SL processing.
clearinghouseState(positions/account) andopenOrders(orders); useswebData3only for OI cap updates; removes fallback caches/subscriptions and updates cleanup/restore logicextractTPSLFromOrdersto accept cached orders and classify ambiguousTriggerorders via price vs entry; re-extracts TP/SL onclearinghouseStateupdates to preserve UI statetriggerPricetoOrderand sets it inadaptOrderFromSDK; price now falls back totriggerPxwhenlimitPxis absentrunAllTimersAsync), add mocks for new per-DEX subscriptions, and extend cases for TP/SL counts, cached rehydration, L2 book ref counting, reconnection, and error handlingWritten by Cursor Bugbot for commit c58a7b1. This will update automatically on new commits. Configure here.
Description
Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist