Skip to content

feat(perps): extend market categories#8892

Open
aganglada wants to merge 10 commits into
mainfrom
TAT-3182-core-expand-product-categories
Open

feat(perps): extend market categories#8892
aganglada wants to merge 10 commits into
mainfrom
TAT-3182-core-expand-product-categories

Conversation

@aganglada
Copy link
Copy Markdown
Contributor

@aganglada aganglada commented May 25, 2026

Explanation

Implements TAT-3182 — expands market categories in @metamask/perps-controller with a new enum, static array, and filtering/sorting support on getMarketDataWithPrices.

What changed

New types and constants

  • MarketCategory enum (crypto, stock, pre-ipo, index, etf, commodity, forex) — replaces ad-hoc string literals in HIP3_ASSET_MARKET_TYPES
  • MarketType type alias kept for backward compatibility
  • MARKET_CATEGORIES constant (readonly MarketTypeFilter[]) — 7 ordered category pills, enforced via satisfies; does not include 'all'/'new' sentinels (those are separate UI controls)
  • SortField and SortDirection moved to types/index.ts (re-exported from utils/sortMarkets) to avoid circular imports

New controller method

  • getMarketCategories() — returns MARKET_CATEGORIES so clients can enumerate pills at runtime without hardcoding the list

Extended params

  • GetMarketsParams gains four optional fields: categories, sortBy, direction, limit
  • PerpsProvider.getMarketDataWithPrices() accepts the same fields via Pick<GetMarketsParams, ...>

Filtering / sorting / pagination (in MarketDataService, not PerpsController)

  • matchesCategory() — pure function mapping MarketTypeFilter | 'watchlist' to a PerpsMarketData predicate
  • applyMarketFilters() — applies category filter (OR logic) → sort → slice in order
  • MarketDataService.getMarketDataWithPrices() — new service method with tracing and error handling that fetches from the provider then applies filters

Breaking change

  • 'equity' market type replaced by 'stock', 'pre-ipo', 'index', 'etf'

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
Breaking MarketType values require consumer updates; market-list filtering changes behavior for any code that assumed unfiltered provider output from getMarketDataWithPrices.

Overview
This PR extends HIP-3 market taxonomy and list APIs in @metamask/perps-controller so clients can render category pills and fetch filtered market lists without duplicating logic.

MarketCategory replaces loose 'equity' strings with stock, pre-ipo, index, etf, plus existing commodity, forex, and crypto. HIP3_ASSET_MARKET_TYPES is updated accordingly (many new xyz symbols; indices/ETFs split out from the old equity bucket). MARKET_CATEGORIES exposes a fixed order of seven UI pill keys, and getMarketCategories() (new messenger action) returns that list.

getMarketDataWithPrices now accepts GetMarketDataWithPricesParams (categories, sortBy, direction, limit, excludeSymbols, standalone) and routes through MarketDataService, which fetches from the provider then applies matchesCategory / applyMarketFilters (OR across categories, then exclude, sort, slice). SortField / SortDirection move to shared types and are re-exported from the package entry.

Breaking: consumers comparing marketType === 'equity' must switch to the granular types. Changelog and tests cover categories, filtering, sorting, limits, and config classification.

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

@aganglada aganglada self-assigned this May 25, 2026
@aganglada aganglada requested review from a team as code owners May 25, 2026 14:03
@aganglada aganglada temporarily deployed to default-branch May 25, 2026 14:03 — with GitHub Actions Inactive
Comment thread packages/perps-controller/src/index.ts Outdated
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

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

Category filtering currently accepts valid inputs that return empty or incomplete results. Watchlist filtering needs implementation or removal from the accepted API, and explicit crypto categorization should be honored.

Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Comment thread packages/perps-controller/src/services/MarketDataService.ts
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

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

One more API-surface issue: GetMarketsParams now exposes filters that getMarkets does not apply.

Comment thread packages/perps-controller/src/types/index.ts
Comment thread packages/perps-controller/src/types/index.ts Outdated
Comment thread packages/perps-controller/src/types/index.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 46c4f27. Configure here.

Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

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

One TypeScript API compatibility issue remains.

Comment thread packages/perps-controller/src/types/index.ts Outdated
@aganglada aganglada enabled auto-merge May 26, 2026 15:29
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.

3 participants