perf(perps-controller): use Terminal API price/trend data instead of HyperLiquid - #9808
perf(perps-controller): use Terminal API price/trend data instead of HyperLiquid#9808juanmigdr wants to merge 2 commits into
Conversation
…HyperLiquid TerminalMarketService already fetched a Terminal API response containing live price, change, funding, volume, open interest, and hourly trend data per market, but only the taxonomy fields were extracted. MarketDataService then re-fetched pricing from HyperLiquid on every call, even when Terminal had just returned it. Now TerminalMarketService pulls the price/trend fields out of the validated response, and MarketDataService builds market data straight from that when it's usable, skipping the HyperLiquid call entirely. Falls back to the existing provider + enrich behavior when Terminal has no price data. Also fixes the Terminal category field being read as `categories`/ `marketType`, when the API actually sends singular `category` - it was silently going unused, which broke market type filtering and the "new market" badge for HIP-3 assets whenever the Terminal price path kicked in. Companion mobile PR: MetaMask/metamask-mobile#34511
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 1155522. Configure here.
| enriched = terminalMetadata | ||
| ? this.#enrichWithTerminalMetadata(markets, terminalMetadata) | ||
| : markets; | ||
| } |
There was a problem hiding this comment.
Terminal path skips market filters
High Severity
When Terminal metadata has any usable price, getMarketDataWithPrices returns Terminal-built markets and never calls the provider. That skips the eligibility rules HyperLiquidProvider.getMarketDataWithPrices applies via shouldIncludeMarket and #excludeNonUsdcCollateralResults (HIP-3 feature flag, allowlist/blocklist, USDC-only collateral). getMarkets already re-applies isMarketAllowed on its Terminal path for this reason, so blocklisted or non-USDC HIP-3 markets can surface as tradeable while order placement still rejects them.
Reviewed by Cursor Bugbot for commit 1155522. Configure here.
oxfmt flagged the Map<string, TerminalAssetMetadata> constructor call in MarketDataService.test.ts from the earlier ZERO-price fixture addition. Also adds the missing Unreleased changelog entries for the Terminal pricing change and the category/marketType fix.


Summary
TerminalMarketServicealready fetches a Terminal API response that includes liveprice,change24h,changePercent24h,funding,volume24h,openInterest, and an hourlytrendseries per market - but it only ever extracted the taxonomy fields (name, keywords, tags, category).MarketDataServicethen always fell back to HyperLiquid for pricing, even when the Terminal response it had just fetched already contained everything needed.TerminalMarketService: declares the price/trend fields on the validation struct and copies them into the per-symbol metadata map alongside the existing taxonomy fields.MarketDataService.getMarketDataWithPrices: when Terminal metadata has a usable price, buildsPerpsMarketData[]directly from it (through the same injectable formatters used by the HyperLiquid path, so formatting is identical either way) and skips the HyperLiquid provider call. Falls back to the existing provider + enrich behavior otherwise.categoryfield, notcategories(array) ormarketType. The struct was validating against field names the API never sends, soPerpsMarketData.marketTypesilently stayedundefinedfor Terminal-sourced markets, breaking category filtering and the "new market" badge for HIP-3 assets.Companion mobile PR (updates the homepage Perpetuals section to consume this instead of subscribing to per-symbol candle streams): MetaMask/metamask-mobile#34511
Ticket: ASSETS-3858
Test plan
TerminalMarketService.test.tsandMarketDataService.test.tsupdated with new fixtures/assertions, plus new tests for the price/trend extraction, the price"0"edge case, and rejecting malformedtrendpayloadsperps-controllerpackage test suite passestsc --noEmitandeslintclean on touched filesNote
Medium Risk
Changes the primary market-overview data path when Terminal pricing is available; incorrect Terminal data or the all-symbols-dropped edge case could affect displayed markets, and removing
PerpsMarketData.categoriesmay break consumers that still read it.Overview
When
useTerminalApiis on and Terminal returns at least one market with a valid price,getMarketDataWithPricesnow buildsPerpsMarketDatafrom Terminal metadata (same injectable formatters as the HyperLiquid path) and does not call the provider for pricing. Symbols without a usable price are omitted on that path; if nothing qualifies, behavior falls back to provider fetch plus Terminal enrichment.TerminalMarketServicenow validates and copies live fields from the API (price, 24h change, funding, volume, open interest,trend, etc.) and maps the singularcategorystring tomarketTypeinstead of the oldcategories/marketTypefields that never matched the payload—restoring category filters and the HIP-3 “new market” badge.PerpsMarketDatagains optionaltrendand drops the unusedcategoriesfield from enrichment/types.Reviewed by Cursor Bugbot for commit 735b3d4. Bugbot is set up for automated code reviews on this repo. Configure here.