chore: upgrade hyperliquid sdk version#9160
Conversation
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
geositta
left a comment
There was a problem hiding this comment.
This is a good direction. The main thing I think we should tighten is the subscriber contract. The PR currently says includeMarketData: false subscribers remain allMids only, but the implementation stores the fast selected price in shared cached price data and fans it out to every subscriber for the symbol. If the intended behavior is per-subscriber price source selection, the cache/notify path needs to project PriceUpdate per subscriber. If the intended behavior is shared fast price per symbol, the changelog/comments should say that clearly and include mixed subscriber coverage.
There is also one startup edge case where activeAssetCtx can publish '0' before either activeAssetCtx or allMids has a real price. That should be skipped until a usable price exists, since focused screens may feed this value into display and calculations.
…grade Resolves conflict in HyperLiquidSubscriptionService.market-data.test.ts by keeping both the activeAssetCtx price preference tests (HEAD) and the new Market tradability (isTradable) tests (main). Co-authored-by: Cursor <cursoragent@cursor.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
When activeAssetCtx updates #marketDataCache (new oraclePx, funding, openInterest, etc.) without a concurrent allMids price change, the allMids handler's skip-if-unchanged guard leaves #cachedPriceData stale. As a result, list subscribers and the base used by focused-subscriber projection continued to carry the old isTradable, funding, openInterest, volume24h, markPrice, and percentChange24h values. Fix: after updating #marketDataCache, rebuild #cachedPriceData[symbol] via #createPriceUpdate(existingBaseline.price) so derived fields are always fresh. The guard is conditional on an existing baseline to preserve the startup zero-price guard — no '0'/absent-allMids baseline is ever synthesized. Co-authored-by: Cursor <cursoragent@cursor.com>
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 0c9bb73. Configure here.
| "baseUrl": "./", | ||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler" |
There was a problem hiding this comment.
As a follow up, we need to migrate the source to be fully compatible with esm modules. Once that's done we can remove this configuration
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |

Explanation
Two related improvements to
HyperLiquidSubscriptionService:TAT-3334 — Per-subscriber
activeAssetCtxprice projectionHyperliquid throttles the main-DEX
allMidsstream to ~2 s per push. For list/overview screens that's fine, but a focused detail/ticket screen would show a noticeably stale price at that interval.Previous approach (PR 9160 initial draft):
#createPriceUpdateunconditionally baked theactiveAssetCtxfast-stream price into#cachedPriceData, meaning all subscribers — including list/overview — received the fast price, contradicting the per-subscriber contract documented in the code.New approach — per-subscriber projection:
#createPriceUpdateis reverted to a pure allMids-baseline builder;#cachedPriceDataalways holds the rawallMidsprice.#projectPriceUpdate(symbol, base)helper shallow-clones the base withprice/timestampoverridden by the freshactiveAssetCtxvalue (within a 10 s staleness window).#notifyAllPriceSubscribersprojects per callback: focused (includeMarketData: true) callbacks receive the fast-stream price; list/overview (includeMarketData: false) callbacks always receive the rawallMidsbaseline, guaranteed, even when both subscriber types share the same symbol.subscribeToPricesimmediate emit projects for focused new subscribers, and can send a fast-stream-only update even before the firstallMidstick so detail screens aren't blank on first render.activeAssetCtxfires beforeallMidswith nomidPx/markPx, no notification is sent — the old'0'fallback is removed entirely.activeAssetCtxwas already reference-counted underincludeMarketData: true.TAT-3333 — Order book
fastflag + SDK bumpHyperliquid is changing the default
l2Bookcadence (20 levels @ ~2 s). A newfastsubscription mode is available (5 levels @ ~0.5 s).@nktkas/hyperliquidfrom^0.32.2to^0.33.1(addsfastto thel2Bookrequest schema).fast?: booleantoSubscribeOrderBookParamswith JSDoc explaining the 5-level / ~0.5 s tradeoff.fastthroughsubscribeToOrderBookinto the SDKl2Bookcall.#processOrderBookDataor cumulative-total math.Version / consumption note
Because this changes published behavior, it lands as a new release of
@metamask/perps-controller(the entries are in[Unreleased]). Clients pick it up by bumping the dependency. The@nktkas/hyperliquidbump to^0.33.1is transitive — clients that don't import the SDK directly don't need to do anything, but anyone pinning it should be aware.Summary
fastallMidslags ~5s on focused screensactiveAssetCtxmidPx/markPxper-subscriber, with 10s TTL fallback toallMidsfastthrough to SDKl2BookincludeMarketData: true)fast: true, accept ≤5 levelsReferences
Checklist
Note
Medium Risk
Changes live price sourcing and WebSocket client wiring for trading UI; behavior is backward compatible but incorrect staleness or projection could show wrong prices on detail screens.
Overview
Upgrades
@nktkas/hyperliquidto ^0.33.1 and adjusts WebSocket transport setup (close()is synchronous; reconnect no longer injectsglobalThis.WebSocket). Perps package tsconfig now uses ESNext / Bundler module resolution for the SDK.Price subscriptions: For
subscribeToPriceswithincludeMarketData: true, displayedpricenow comes from the existing per-symbolactiveAssetCtxstream (midPx/markPx) when fresh (10 s TTL), withallMidsstill the baseline for derived fields and forincludeMarketData: falselist subscribers.#notifyAllPriceSubscribersprojects per callback; startup avoids emitting'0'when context arrives beforeallMids.assetCtxsbatch updates no longer wipe the fast-stream cache fields.Order book:
SubscribeOrderBookParamsgains optionalfast?: boolean, passed through to SDKl2Book(faster ~0.5 s / 5-level mode vs default).Changelog also documents new Perps Advanced Chart analytics constants (separate from the Hyperliquid work). Minor typing cleanup for Hyperliquid child orders (no
FrontendOrdercast).Reviewed by Cursor Bugbot for commit e12e4a3. Bugbot is set up for automated code reviews on this repo. Configure here.