Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/perps-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add hardcoded market collections registry with 175 perps markets and 27 collection tags ([#9106](https://github.com/MetaMask/core/pull/9106))
- New `PerpsMarketCollectionTag` enum, `PerpsMarketDefinition` type, `PERPS_MARKET_DEFINITIONS` and `PERPS_MARKET_COLLECTION_TAGS` constants
- New utility functions `getMarketDefinitionByTicker` and `getMarketDefinitionsByCollection`
- New controller methods `getMarketCollections()`, `getMarketDefinitions()`, `getMarketDefinitionByTicker()`, and `getMarketDefinitionsByCollection()`

### Changed

- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,49 @@ export type PerpsControllerGetMarketCategoriesAction = {
handler: PerpsController['getMarketCategories'];
};

/**
* Get the ordered list of all market collection tags.
* Used by the UI to render collection filter pills.
*
* @returns Ordered array of {@link PerpsMarketCollectionTag} values.
*/
export type PerpsControllerGetMarketCollectionsAction = {
type: `PerpsController:getMarketCollections`;
handler: PerpsController['getMarketCollections'];
};

/**
* Get the full list of hardcoded perps market definitions.
*
* @returns Array of all {@link PerpsMarketDefinition} entries.
*/
export type PerpsControllerGetMarketDefinitionsAction = {
type: `PerpsController:getMarketDefinitions`;
handler: PerpsController['getMarketDefinitions'];
};

/**
* Look up a single market definition by its ticker symbol.
*
* @param ticker - The ticker to look up (e.g. 'BTC', 'ETH').
* @returns The matching definition, or `undefined` if not found.
*/
export type PerpsControllerGetMarketDefinitionByTickerAction = {
type: `PerpsController:getMarketDefinitionByTicker`;
handler: PerpsController['getMarketDefinitionByTicker'];
};

/**
* Return all market definitions that belong to a given collection tag.
*
* @param collection - The collection tag to filter by.
* @returns Array of matching market definitions (may be empty).
*/
export type PerpsControllerGetMarketDefinitionsByCollectionAction = {
type: `PerpsController:getMarketDefinitionsByCollection`;
handler: PerpsController['getMarketDefinitionsByCollection'];
};

/**
* Get the current WebSocket connection state from the active provider.
* Used by the UI to monitor connection health and show notifications.
Expand Down Expand Up @@ -1068,6 +1111,10 @@ export type PerpsControllerMethodActions =
| PerpsControllerSwitchProviderAction
| PerpsControllerGetCurrentNetworkAction
| PerpsControllerGetMarketCategoriesAction
| PerpsControllerGetMarketCollectionsAction
| PerpsControllerGetMarketDefinitionsAction
| PerpsControllerGetMarketDefinitionByTickerAction
| PerpsControllerGetMarketDefinitionsByCollectionAction
| PerpsControllerGetWebSocketConnectionStateAction
| PerpsControllerSubscribeToConnectionStateAction
| PerpsControllerReconnectAction
Expand Down
55 changes: 55 additions & 0 deletions packages/perps-controller/src/PerpsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import {
PERPS_EVENT_VALUE,
} from './constants/eventNames';
import { USDC_SYMBOL } from './constants/hyperLiquidConfig';
import {
PERPS_MARKET_COLLECTION_TAGS,
PERPS_MARKET_DEFINITIONS,
getMarketDefinitionByTicker as getMarketDefinitionByTickerUtil,
getMarketDefinitionsByCollection as getMarketDefinitionsByCollectionUtil,
} from './constants/marketCollections';
import { PerpsMeasurementName } from './constants/performanceMetrics';
import type { SortOptionId } from './constants/perpsConfig';
import {
Expand Down Expand Up @@ -107,6 +113,8 @@ import type {
PerpsLogger,
PerpsActiveProviderMode,
PerpsProviderType,
PerpsMarketCollectionTag,
PerpsMarketDefinition,
PerpsSelectedPaymentToken,
PerpsRemoteFeatureFlagState,
PerpsTransactionParams,
Expand Down Expand Up @@ -726,7 +734,11 @@ const MESSENGER_EXPOSED_METHODS = [
'getFunding',
'getHistoricalPortfolio',
'getMarketCategories',
'getMarketCollections',
'getMarketDataWithPrices',
'getMarketDefinitionByTicker',
'getMarketDefinitions',
'getMarketDefinitionsByCollection',
'getMarketFilterPreferences',
'getMarkets',
'getMaxLeverage',
Expand Down Expand Up @@ -3987,6 +3999,49 @@ export class PerpsController extends BaseController<
return MARKET_CATEGORIES;
}

/**
* Get the ordered list of all market collection tags.
* Used by the UI to render collection filter pills.
*
* @returns Ordered array of {@link PerpsMarketCollectionTag} values.
*/
getMarketCollections(): PerpsMarketCollectionTag[] {
return [...PERPS_MARKET_COLLECTION_TAGS];
}

/**
* Get the full list of hardcoded perps market definitions.
*
* @returns Array of all {@link PerpsMarketDefinition} entries.
*/
getMarketDefinitions(): PerpsMarketDefinition[] {
return [...PERPS_MARKET_DEFINITIONS];
}

/**
* Look up a single market definition by its ticker symbol.
*
* @param ticker - The ticker to look up (e.g. 'BTC', 'ETH').
* @returns The matching definition, or `undefined` if not found.
*/
getMarketDefinitionByTicker(
ticker: string,
): PerpsMarketDefinition | undefined {
return getMarketDefinitionByTickerUtil(ticker);
}

/**
* Return all market definitions that belong to a given collection tag.
*
* @param collection - The collection tag to filter by.
* @returns Array of matching market definitions (may be empty).
*/
getMarketDefinitionsByCollection(
collection: PerpsMarketCollectionTag,
): PerpsMarketDefinition[] {
return getMarketDefinitionsByCollectionUtil(collection);
}

/**
* Get the current WebSocket connection state from the active provider.
* Used by the UI to monitor connection health and show notifications.
Expand Down
1 change: 1 addition & 0 deletions packages/perps-controller/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './perpsConfig';
export * from './transactionsHistoryConfig';
export * from './performanceMetrics';
export * from './myxConfig';
export * from './marketCollections';
Loading
Loading