feat(perps-controller): integrate Terminal API as primary market data source with HyperLiquid fallback#9137
Draft
michalconsensys wants to merge 10 commits into
Draft
feat(perps-controller): integrate Terminal API as primary market data source with HyperLiquid fallback#9137michalconsensys wants to merge 10 commits into
michalconsensys wants to merge 10 commits into
Conversation
… source with HyperLiquid fallback Add TerminalMarketService to fetch market data from the MetaMask Terminal API, gated behind the `perpsTerminalApiMarkets` remote feature flag. When enabled, the Terminal API is used as the primary source for market listings and metadata (name, keywords, tags, categories), with a silent fallback to HyperLiquid on failure. Also enhances market search to index against keyword fields.
…ets path The Terminal API path in getMarkets was returning all markets without respecting params.symbols or params.dex, unlike the provider fallback path which applies those filters. This could cause callers requesting specific symbols to receive the full market list.
…der data The comment stated the two fetches ran in parallel, but the code awaited the terminal metadata before starting the provider fetch. Use Promise.all so both requests fly concurrently, reducing wall-clock latency when the Terminal API flag is enabled.
…ormDependencies Adding a required field to PerpsPlatformDependencies is a breaking change for all existing consumers. Since the Terminal API feature is behind a remote flag, the URL should be optional — when omitted the service is not instantiated and the integration is disabled regardless of the flag.
…known values The #extractMetadata method cast item.marketType to MarketType with an unchecked `as` assertion. If the API returned an unrecognised value (e.g. "derivatives"), it would propagate silently and could cause downstream category filtering or UI issues. Now only values present in MARKET_CATEGORIES are accepted; unknown strings are dropped.
… responses Replace unsafe `as` type cast with per-item superstruct validation in TerminalMarketService. Items that fail validation are filtered out and logged instead of silently accepted. Also fix API path to /v1/perpetuals and add a temporary test script for manual verification.
… getMarkets path" This reverts commit 2e6e684.
…th provider data" This reverts commit 3478db9.
…rpsPlatformDependencies" This reverts commit 48d5c51.
…against known values" This reverts commit 122c8ba.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Integrates the MetaMask Terminal API as the primary market data source for the Perps Controller, with a silent fallback to HyperLiquid. This is gated behind the
perpsTerminalApiMarketsremote feature flag, checked per-fetch so toggling takes effect immediately.What changed:
TerminalMarketService— new service that fetches structured market metadata from{terminalApiBaseUrl}/perpetualswith a 5-minute in-memory cache, response validation, and Sentry error logging.MarketDataService—getMarkets()now attempts the Terminal API first when the flag is enabled; on failure or empty response it falls back silently to the HyperLiquid provider.getMarketDataWithPrices()enriches provider data with Terminal API metadata (name, keywords, tags, categories).PerpsController— wires the new service and readsperpsTerminalApiMarketsfromRemoteFeatureFlagControlleron every call.PerpsPlatformDependenciesgainsterminalApiBaseUrl: string;PerpsMarketDatagains optionalkeywords,tags, andcategoriesfields.transformMarketData()— accepts optionalterminalMetadatato override static name/category maps per symbol.getMarketMatchRankandrankMarketsByQuerynow index thekeywordsfield for richer results.TERMINAL_API_CONFIGadded with environment endpoint references and cache TTL.HYPERLIQUID_ASSET_NAMES,HIP3_ASSET_MARKET_TYPES) remain intact for assets absent from the Terminal API.Changelog
@metamask/perps-controllerperpsTerminalApiMarketsfeature flag, includingTerminalMarketService, enriched metadata fields (keywords,tags,categories), and keyword-aware market search.Related issues
N/A
Manual testing steps
Feature: Terminal API market data integration
Scenario: Markets loaded from Terminal API when flag is enabled
perpsTerminalApiMarketsremote feature flag istruegetMarkets()Scenario: Silent fallback to HyperLiquid when Terminal API fails
perpsTerminalApiMarketsremote feature flag istruegetMarkets()Scenario: HyperLiquid used when flag is disabled
perpsTerminalApiMarketsremote feature flag isfalsegetMarkets()Screenshots/Recordings
N/A — no UI changes.
Pre-merge author checklist
Pre-merge reviewer checklist