Commit d52e9e9
chore(runway): cherry-pick fix: compute spread from HL bbo top-of-book feed cp-7.63.0 (#25164)
- fix: compute spread from HL bbo top-of-book feed cp-7.63.0 (#25145)
<!--
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**
### Summary
- Fixes incorrect spread display in Perps order book that changed when
users change the aggregate dropdown
- Spread now uses BBO (best bid/offer) feed instead of aggregated
L2Book, matching Hyperliquid UI
behavior
- Adds missing test coverage for `subscribeToOrderBook` L2Book
subscriptions
https://consensyssoftware.atlassian.net/browse/TAT-2425
### Problem
The spread displayed under the order book depth chart was incorrect and
would change when the use changed the aggregation dropdown. This
diverged from Hyperliquid's UI where spread remains stable regardless of
grouping selection.
Root cause: Spread was derived from aggregated orderbook levels. When
requesting an aggregated book, the best bid/ask are bucketed/rounded
prices, causing the spread to inflate to increments resembling the
grouping step.
### Solution
Split the data sources:
- Depth/table display: `subscribeToOrderBook` -> `l2Book` with
aggregation params (existing)
- Spread display: `subscribeToPrices(includeOrderBook: true)` -> bbo
feed (new)
The L2Book -> BBO change only affects `subscribeToPrices({
includeOrderBook: true })`, which feeds `usePerpsTopOfBook`. All 5
consumers only need best bid/ask:
- Fee calculation (3 views) - compares limit price to best bid/ask for
maker/taker determination
- Bid/Ask presets - single best prices for quick buttons
- Spread display - bestAsk - bestBid
Full L2Book depth is still used via separate `subscribeToOrderBook()`
path for the order book table/chart.
This matches Hyperliquid's frontend: grouping affects the book display,
spread is based on actual top-of-book.
### Test plan
- Unit tests for processBboData
- Unit tests for BBO subscription lifecycle
- Unit tests for subscribeToOrderBook (L2Book) - 10 new tests
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
AI agent: Be specific about what you changed and why. Include context
about the fix/feature, not generic descriptions.
-->
## **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)
AI agent: Use format `CHANGELOG entry: [fix/feat/chore]: [User-facing
description in past tense]`.
Examples: `fix: resolved token name display issue`, `feat: added dark
mode toggle`, `chore: updated dependencies`.
For non-user-facing changes, use `CHANGELOG entry: null`.
-->
CHANGELOG entry: Fixed incorrect spread displayed below Perps orderbook
depth chart
## **Related issues**
<!--
AI agent: Replace with `Fixes: #[ISSUE_NUMBER]` using the actual issue
number you're implementing.
-->
Fixes: #25162
## **Manual testing steps**
- Verify spread matches Hyperliquid UI across all grouping values
- Verify changing grouping doesn't affect spread display
<!--
AI agent: Write specific, contextual Gherkin steps based on what you
actually implemented.
Do NOT use generic placeholders like "my feature name". Be concrete
about the feature, scenario, and 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**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/43c6c40c-162c-4809-9295-1acaf684d64d
## **Pre-merge author checklist**
<!--
AI agent: Check ALL boxes in this section (mark all as [x]).
-->
- [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**
<!--
AI agent: Leave ALL boxes unchecked ([ ]) - these are for reviewers to
check, not the author.
-->
- [ ] 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]
> **Fix spread to match Hyperliquid UI**
>
> - Switch spread display in `PerpsOrderBookView` to `usePerpsTopOfBook`
(BBO), independent of order book grouping; format via `formatPerpsFiat`
> - Update `HyperLiquidSubscriptionService`: replace `l2Book`-based
top-of-book with singleton `bbo` subscriptions
(`ensureBboSubscription`/`cleanupBboSubscription`), reconnection restore
logic, and cache updates via new `processBboData`
> - Keep full depth via existing `subscribeToOrderBook` (L2Book); add
comprehensive tests for this path plus new BBO lifecycle and processor
tests
> - Adjust tests to mock `usePerpsTopOfBook` and verify spread rendering
and subscription params
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
33d5529. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[6ca25dd](6ca25dd)
Co-authored-by: Matt D. <85914066+geositta@users.noreply.github.com>1 parent 526aa42 commit d52e9e9
6 files changed
Lines changed: 755 additions & 72 deletions
File tree
- app/components/UI/Perps
- Views/PerpsOrderBookView
- services
- utils
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
178 | 189 | | |
179 | 190 | | |
180 | 191 | | |
| |||
285 | 296 | | |
286 | 297 | | |
287 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
288 | 304 | | |
289 | 305 | | |
290 | 306 | | |
| |||
Lines changed: 41 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
| |||
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
190 | 226 | | |
191 | 227 | | |
192 | 228 | | |
| |||
215 | 251 | | |
216 | 252 | | |
217 | 253 | | |
218 | | - | |
219 | | - | |
220 | 254 | | |
221 | 255 | | |
222 | 256 | | |
| |||
506 | 540 | | |
507 | 541 | | |
508 | 542 | | |
509 | | - | |
| 543 | + | |
510 | 544 | | |
511 | 545 | | |
512 | 546 | | |
513 | 547 | | |
514 | 548 | | |
515 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
516 | 552 | | |
517 | 553 | | |
518 | | - | |
| 554 | + | |
519 | 555 | | |
520 | 556 | | |
521 | 557 | | |
| |||
0 commit comments