Skip to content

chore: upgrade hyperliquid sdk version#9160

Merged
gambinish merged 14 commits into
mainfrom
perps/tat-3333_l2Book-sdk-upgrade
Jun 30, 2026
Merged

chore: upgrade hyperliquid sdk version#9160
gambinish merged 14 commits into
mainfrom
perps/tat-3333_l2Book-sdk-upgrade

Conversation

@gambinish

@gambinish gambinish commented Jun 16, 2026

Copy link
Copy Markdown
Member

Explanation

Two related improvements to HyperLiquidSubscriptionService:

TAT-3334 — Per-subscriber activeAssetCtx price projection

Hyperliquid throttles the main-DEX allMids stream 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): #createPriceUpdate unconditionally baked the activeAssetCtx fast-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:

  • #createPriceUpdate is reverted to a pure allMids-baseline builder; #cachedPriceData always holds the raw allMids price.
  • A new #projectPriceUpdate(symbol, base) helper shallow-clones the base with price/timestamp overridden by the fresh activeAssetCtx value (within a 10 s staleness window).
  • #notifyAllPriceSubscribers projects per callback: focused (includeMarketData: true) callbacks receive the fast-stream price; list/overview (includeMarketData: false) callbacks always receive the raw allMids baseline, guaranteed, even when both subscriber types share the same symbol.
  • The subscribeToPrices immediate emit projects for focused new subscribers, and can send a fast-stream-only update even before the first allMids tick so detail screens aren't blank on first render.
  • Startup zero-price guard: if activeAssetCtx fires before allMids with no midPx/markPx, no notification is sent — the old '0' fallback is removed entirely.
  • No new WebSocket subscriptions; activeAssetCtx was already reference-counted under includeMarketData: true.

TAT-3333 — Order book fast flag + SDK bump

Hyperliquid is changing the default l2Book cadence (20 levels @ ~2 s). A new fast subscription mode is available (5 levels @ ~0.5 s).

  • Bumps @nktkas/hyperliquid from ^0.32.2 to ^0.33.1 (adds fast to the l2Book request schema).
  • Adds fast?: boolean to SubscribeOrderBookParams with JSDoc explaining the 5-level / ~0.5 s tradeoff.
  • Threads fast through subscribeToOrderBook into the SDK l2Book call.
  • No change to #processOrderBookData or 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/hyperliquid bump to ^0.33.1 is transitive — clients that don't import the SDK directly don't need to do anything, but anyone pinning it should be aware.

Summary

Price fast-stream Order book fast
Problem allMids lags ~5s on focused screens default l2Book ~2s, 20 levels
Mechanism Route already-subscribed activeAssetCtx midPx/markPx per-subscriber, with 10s TTL fallback to allMids Pass fast through to SDK l2Book
New connections None None
Client integration None (automatic for includeMarketData: true) Opt-in fast: true, accept ≤5 levels
Backward compatible Yes Yes

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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/hyperliquid to ^0.33.1 and adjusts WebSocket transport setup (close() is synchronous; reconnect no longer injects globalThis.WebSocket). Perps package tsconfig now uses ESNext / Bundler module resolution for the SDK.

Price subscriptions: For subscribeToPrices with includeMarketData: true, displayed price now comes from the existing per-symbol activeAssetCtx stream (midPx / markPx) when fresh (10 s TTL), with allMids still the baseline for derived fields and for includeMarketData: false list subscribers. #notifyAllPriceSubscribers projects per callback; startup avoids emitting '0' when context arrives before allMids. assetCtxs batch updates no longer wipe the fast-stream cache fields.

Order book: SubscribeOrderBookParams gains optional fast?: boolean, passed through to SDK l2Book (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 FrontendOrder cast).

Reviewed by Cursor Bugbot for commit e12e4a3. Bugbot is set up for automated code reviews on this repo. Configure here.

@gambinish

Copy link
Copy Markdown
Member Author

@metamaskbot publish-previews

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.2-preview-1968d6ea0
@metamask-previews/accounts-controller@39.0.1-preview-1968d6ea0
@metamask-previews/address-book-controller@7.1.2-preview-1968d6ea0
@metamask-previews/ai-controllers@0.7.0-preview-1968d6ea0
@metamask-previews/analytics-controller@1.1.1-preview-1968d6ea0
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-1968d6ea0
@metamask-previews/announcement-controller@8.1.0-preview-1968d6ea0
@metamask-previews/app-metadata-controller@2.0.1-preview-1968d6ea0
@metamask-previews/approval-controller@9.0.2-preview-1968d6ea0
@metamask-previews/assets-controller@9.0.1-preview-1968d6ea0
@metamask-previews/assets-controllers@109.1.0-preview-1968d6ea0
@metamask-previews/authenticated-user-storage@2.0.0-preview-1968d6ea0
@metamask-previews/base-controller@9.1.0-preview-1968d6ea0
@metamask-previews/base-data-service@0.1.3-preview-1968d6ea0
@metamask-previews/bridge-controller@75.1.1-preview-1968d6ea0
@metamask-previews/bridge-status-controller@72.1.0-preview-1968d6ea0
@metamask-previews/build-utils@3.0.4-preview-1968d6ea0
@metamask-previews/chain-agnostic-permission@1.6.2-preview-1968d6ea0
@metamask-previews/chomp-api-service@3.1.0-preview-1968d6ea0
@metamask-previews/claims-controller@0.5.3-preview-1968d6ea0
@metamask-previews/client-controller@1.0.1-preview-1968d6ea0
@metamask-previews/compliance-controller@2.1.0-preview-1968d6ea0
@metamask-previews/composable-controller@12.0.1-preview-1968d6ea0
@metamask-previews/config-registry-controller@0.4.1-preview-1968d6ea0
@metamask-previews/connectivity-controller@0.2.0-preview-1968d6ea0
@metamask-previews/controller-utils@12.2.0-preview-1968d6ea0
@metamask-previews/core-backend@6.3.3-preview-1968d6ea0
@metamask-previews/delegation-controller@3.0.2-preview-1968d6ea0
@metamask-previews/earn-controller@12.2.0-preview-1968d6ea0
@metamask-previews/eip-5792-middleware@3.0.4-preview-1968d6ea0
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-1968d6ea0
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-1968d6ea0
@metamask-previews/ens-controller@19.1.3-preview-1968d6ea0
@metamask-previews/eth-block-tracker@15.0.1-preview-1968d6ea0
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-1968d6ea0
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-1968d6ea0
@metamask-previews/foundryup@1.0.1-preview-1968d6ea0
@metamask-previews/gas-fee-controller@26.2.2-preview-1968d6ea0
@metamask-previews/gator-permissions-controller@4.2.0-preview-1968d6ea0
@metamask-previews/geolocation-controller@0.1.3-preview-1968d6ea0
@metamask-previews/json-rpc-engine@10.5.0-preview-1968d6ea0
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-1968d6ea0
@metamask-previews/keyring-controller@27.1.0-preview-1968d6ea0
@metamask-previews/logging-controller@8.0.2-preview-1968d6ea0
@metamask-previews/message-manager@14.1.2-preview-1968d6ea0
@metamask-previews/messenger@1.2.0-preview-1968d6ea0
@metamask-previews/messenger-cli@0.2.0-preview-1968d6ea0
@metamask-previews/money-account-balance-service@2.0.0-preview-1968d6ea0
@metamask-previews/money-account-controller@0.3.3-preview-1968d6ea0
@metamask-previews/money-account-upgrade-controller@2.0.5-preview-1968d6ea0
@metamask-previews/multichain-account-service@10.0.3-preview-1968d6ea0
@metamask-previews/multichain-api-middleware@3.1.4-preview-1968d6ea0
@metamask-previews/multichain-network-controller@3.1.3-preview-1968d6ea0
@metamask-previews/multichain-transactions-controller@7.1.1-preview-1968d6ea0
@metamask-previews/name-controller@9.1.2-preview-1968d6ea0
@metamask-previews/network-controller@32.0.0-preview-1968d6ea0
@metamask-previews/network-enablement-controller@5.3.0-preview-1968d6ea0
@metamask-previews/notification-services-controller@24.1.3-preview-1968d6ea0
@metamask-previews/passkey-controller@2.0.1-preview-1968d6ea0
@metamask-previews/permission-controller@13.1.1-preview-1968d6ea0
@metamask-previews/permission-log-controller@5.1.0-preview-1968d6ea0
@metamask-previews/perps-controller@8.1.0-preview-1968d6ea0
@metamask-previews/phishing-controller@17.2.0-preview-1968d6ea0
@metamask-previews/polling-controller@16.0.6-preview-1968d6ea0
@metamask-previews/preferences-controller@23.1.0-preview-1968d6ea0
@metamask-previews/profile-metrics-controller@3.2.0-preview-1968d6ea0
@metamask-previews/profile-sync-controller@28.2.0-preview-1968d6ea0
@metamask-previews/ramps-controller@14.2.0-preview-1968d6ea0
@metamask-previews/rate-limit-controller@7.0.1-preview-1968d6ea0
@metamask-previews/react-data-query@0.2.1-preview-1968d6ea0
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-1968d6ea0
@metamask-previews/sample-controllers@5.0.1-preview-1968d6ea0
@metamask-previews/seedless-onboarding-controller@10.0.2-preview-1968d6ea0
@metamask-previews/selected-network-controller@26.1.3-preview-1968d6ea0
@metamask-previews/shield-controller@5.1.2-preview-1968d6ea0
@metamask-previews/signature-controller@39.2.5-preview-1968d6ea0
@metamask-previews/smart-transactions-controller@24.2.1-preview-1968d6ea0
@metamask-previews/snap-account-service@0.3.1-preview-1968d6ea0
@metamask-previews/social-controllers@2.3.0-preview-1968d6ea0
@metamask-previews/storage-service@1.0.2-preview-1968d6ea0
@metamask-previews/subscription-controller@6.2.0-preview-1968d6ea0
@metamask-previews/transaction-controller@68.0.0-preview-1968d6ea0
@metamask-previews/transaction-pay-controller@23.8.0-preview-1968d6ea0
@metamask-previews/user-operation-controller@41.2.4-preview-1968d6ea0
@metamask-previews/wallet@3.0.0-preview-1968d6ea0
@metamask-previews/wallet-cli@0.0.0-preview-1968d6ea0

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread packages/perps-controller/src/services/HyperLiquidSubscriptionService.ts Outdated
Comment thread packages/perps-controller/src/services/HyperLiquidSubscriptionService.ts Outdated
gambinish and others added 2 commits June 25, 2026 16:27
…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>
@socket-security

socket-security Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​nktkas/​hyperliquid@​0.32.2 ⏵ 0.33.110010010094 +1100

View full report

@gambinish gambinish changed the title chore: init activeAssetCtxPrice price resolution chore: upgrade hyperliquid sdk version Jun 26, 2026
gambinish and others added 9 commits June 26, 2026 09:06
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>
@gambinish gambinish marked this pull request as ready for review June 26, 2026 20:45
@gambinish gambinish requested review from a team as code owners June 26, 2026 20:45

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 0c9bb73. Configure here.

@gambinish gambinish requested a review from geositta June 26, 2026 21:24
Comment on lines +4 to +6
"baseUrl": "./",
"module": "ESNext",
"moduleResolution": "Bundler"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

@gambinish

Copy link
Copy Markdown
Member Author

@metamaskbot publish-previews

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.3-preview-e12e4a38f
@metamask-previews/accounts-controller@39.0.3-preview-e12e4a38f
@metamask-previews/address-book-controller@7.1.2-preview-e12e4a38f
@metamask-previews/ai-controllers@0.7.0-preview-e12e4a38f
@metamask-previews/analytics-controller@1.2.1-preview-e12e4a38f
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-e12e4a38f
@metamask-previews/announcement-controller@8.1.0-preview-e12e4a38f
@metamask-previews/app-metadata-controller@2.0.1-preview-e12e4a38f
@metamask-previews/approval-controller@9.0.2-preview-e12e4a38f
@metamask-previews/assets-controller@9.1.0-preview-e12e4a38f
@metamask-previews/assets-controllers@109.2.2-preview-e12e4a38f
@metamask-previews/authenticated-user-storage@2.1.0-preview-e12e4a38f
@metamask-previews/base-controller@9.1.0-preview-e12e4a38f
@metamask-previews/base-data-service@0.1.3-preview-e12e4a38f
@metamask-previews/bitcoin-regtest-up@0.0.0-preview-e12e4a38f
@metamask-previews/bridge-controller@77.1.0-preview-e12e4a38f
@metamask-previews/bridge-status-controller@73.1.0-preview-e12e4a38f
@metamask-previews/build-utils@3.0.4-preview-e12e4a38f
@metamask-previews/chain-agnostic-permission@1.6.2-preview-e12e4a38f
@metamask-previews/chomp-api-service@3.1.0-preview-e12e4a38f
@metamask-previews/claims-controller@0.5.3-preview-e12e4a38f
@metamask-previews/client-controller@1.0.1-preview-e12e4a38f
@metamask-previews/compliance-controller@2.1.0-preview-e12e4a38f
@metamask-previews/composable-controller@12.0.1-preview-e12e4a38f
@metamask-previews/config-registry-controller@0.4.1-preview-e12e4a38f
@metamask-previews/connectivity-controller@0.2.0-preview-e12e4a38f
@metamask-previews/controller-utils@12.3.0-preview-e12e4a38f
@metamask-previews/core-backend@6.3.3-preview-e12e4a38f
@metamask-previews/delegation-controller@3.0.2-preview-e12e4a38f
@metamask-previews/earn-controller@12.2.1-preview-e12e4a38f
@metamask-previews/eip-5792-middleware@3.0.4-preview-e12e4a38f
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-e12e4a38f
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-e12e4a38f
@metamask-previews/ens-controller@19.1.4-preview-e12e4a38f
@metamask-previews/eth-block-tracker@15.0.1-preview-e12e4a38f
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-e12e4a38f
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-e12e4a38f
@metamask-previews/foundryup@1.0.1-preview-e12e4a38f
@metamask-previews/gas-fee-controller@26.2.3-preview-e12e4a38f
@metamask-previews/gator-permissions-controller@4.2.1-preview-e12e4a38f
@metamask-previews/geolocation-controller@0.1.3-preview-e12e4a38f
@metamask-previews/java-tron-up@0.0.0-preview-e12e4a38f
@metamask-previews/json-rpc-engine@10.5.0-preview-e12e4a38f
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-e12e4a38f
@metamask-previews/keyring-controller@27.1.0-preview-e12e4a38f
@metamask-previews/local-node-utils@0.0.0-preview-e12e4a38f
@metamask-previews/logging-controller@8.0.2-preview-e12e4a38f
@metamask-previews/message-manager@14.1.2-preview-e12e4a38f
@metamask-previews/messenger@1.2.0-preview-e12e4a38f
@metamask-previews/messenger-cli@0.2.0-preview-e12e4a38f
@metamask-previews/money-account-balance-service@2.1.1-preview-e12e4a38f
@metamask-previews/money-account-controller@0.3.3-preview-e12e4a38f
@metamask-previews/money-account-upgrade-controller@2.1.0-preview-e12e4a38f
@metamask-previews/multichain-account-service@11.1.0-preview-e12e4a38f
@metamask-previews/multichain-api-middleware@3.1.5-preview-e12e4a38f
@metamask-previews/multichain-network-controller@3.2.0-preview-e12e4a38f
@metamask-previews/multichain-transactions-controller@7.1.1-preview-e12e4a38f
@metamask-previews/name-controller@9.1.2-preview-e12e4a38f
@metamask-previews/network-controller@33.0.0-preview-e12e4a38f
@metamask-previews/network-enablement-controller@5.4.0-preview-e12e4a38f
@metamask-previews/notification-services-controller@24.2.0-preview-e12e4a38f
@metamask-previews/passkey-controller@2.0.1-preview-e12e4a38f
@metamask-previews/permission-controller@13.1.1-preview-e12e4a38f
@metamask-previews/permission-log-controller@5.1.0-preview-e12e4a38f
@metamask-previews/perps-controller@9.0.0-preview-e12e4a38f
@metamask-previews/phishing-controller@17.2.0-preview-e12e4a38f
@metamask-previews/polling-controller@16.0.7-preview-e12e4a38f
@metamask-previews/preferences-controller@23.1.0-preview-e12e4a38f
@metamask-previews/profile-metrics-controller@4.0.0-preview-e12e4a38f
@metamask-previews/profile-sync-controller@28.2.0-preview-e12e4a38f
@metamask-previews/ramps-controller@15.0.0-preview-e12e4a38f
@metamask-previews/rate-limit-controller@7.0.1-preview-e12e4a38f
@metamask-previews/react-data-query@0.2.1-preview-e12e4a38f
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-e12e4a38f
@metamask-previews/sample-controllers@5.0.2-preview-e12e4a38f
@metamask-previews/seedless-onboarding-controller@10.0.3-preview-e12e4a38f
@metamask-previews/selected-network-controller@26.1.4-preview-e12e4a38f
@metamask-previews/shield-controller@5.1.2-preview-e12e4a38f
@metamask-previews/signature-controller@39.2.6-preview-e12e4a38f
@metamask-previews/smart-transactions-controller@24.2.3-preview-e12e4a38f
@metamask-previews/snap-account-service@1.0.0-preview-e12e4a38f
@metamask-previews/social-controllers@2.3.1-preview-e12e4a38f
@metamask-previews/solana-test-validator-up@0.0.0-preview-e12e4a38f
@metamask-previews/stellar-quickstart-up@0.0.0-preview-e12e4a38f
@metamask-previews/storage-service@1.0.2-preview-e12e4a38f
@metamask-previews/subscription-controller@6.2.0-preview-e12e4a38f
@metamask-previews/transaction-controller@68.2.0-preview-e12e4a38f
@metamask-previews/transaction-pay-controller@23.17.1-preview-e12e4a38f
@metamask-previews/user-operation-controller@41.2.5-preview-e12e4a38f
@metamask-previews/wallet@5.0.0-preview-e12e4a38f
@metamask-previews/wallet-cli@0.0.0-preview-e12e4a38f

@gambinish gambinish added this pull request to the merge queue Jun 30, 2026
Merged via the queue into main with commit 86e38d1 Jun 30, 2026
400 checks passed
@gambinish gambinish deleted the perps/tat-3333_l2Book-sdk-upgrade branch June 30, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants