@metamask-previews/perps-controller 25.0.0-preview-a7bdec3 → 25.0.0-preview-2a2b320ba
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -15
- package/dist/PerpsController-method-action-types.d.ts +17 -7
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +20 -10
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +160 -97
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/lighterConfig.js +2 -2
- package/dist/constants/lighterConfig.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +14 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +46 -6
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +60 -35
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/services/HyperLiquidClientService.d.ts.map +1 -1
- package/dist/services/HyperLiquidClientService.js +5 -4
- package/dist/services/HyperLiquidClientService.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts +13 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +296 -50
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/services/MarketDataService.d.ts +5 -2
- package/dist/services/MarketDataService.d.ts.map +1 -1
- package/dist/services/MarketDataService.js +211 -55
- package/dist/services/MarketDataService.js.map +1 -1
- package/dist/services/ServiceContext.d.ts +12 -7
- package/dist/services/ServiceContext.d.ts.map +1 -1
- package/dist/services/ServiceContext.js.map +1 -1
- package/dist/services/TerminalMarketService.d.ts.map +1 -1
- package/dist/services/TerminalMarketService.js +64 -22
- package/dist/services/TerminalMarketService.js.map +1 -1
- package/dist/types/index.d.ts +36 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/marketUtils.d.ts +60 -1
- package/dist/utils/marketUtils.d.ts.map +1 -1
- package/dist/utils/marketUtils.js +151 -3
- package/dist/utils/marketUtils.js.map +1 -1
- package/docs/architecture.md +9 -1
- package/docs/contracts/feature-flags.md +5 -5
- package/docs/venues/hyperliquid/init-flow.md +25 -8
- package/docs/venues/lighter/capabilities.md +4 -0
- package/docs/venues/lighter/signer-provenance.md +52 -0
- package/package.json +1 -1
package/dist/PerpsController.js
CHANGED
|
@@ -40,7 +40,7 @@ import { PERPS_ERROR_ACTION, PERPS_ERROR_COMPONENT, PERPS_ERROR_OPERATION, creat
|
|
|
40
40
|
import { ensureError } from './utils/errorUtils.js';
|
|
41
41
|
import { parseAssetName } from './utils/hyperLiquidAdapter.js';
|
|
42
42
|
import { captureScaleOrderParams } from './utils/lighterScaleOrders.js';
|
|
43
|
-
import { clonePerpsMarketData, compileMarketPattern, shouldIncludeMarket, } from './utils/marketUtils.js';
|
|
43
|
+
import { clonePerpsMarketData, compileMarketPattern, getPerpsWatchlistReferences, shouldIncludeMarket, } from './utils/marketUtils.js';
|
|
44
44
|
import { isStrategyOrderType } from './utils/orderTypes.js';
|
|
45
45
|
import { hydrateFromDiskSync, persistMarketEntriesToDisk, persistUserEntriesToDisk, } from './utils/perpsDiskPersistence.js';
|
|
46
46
|
import { getProviderHealthOf, subscribeToProviderHealthOf, } from './utils/providerHealth.js';
|
|
@@ -744,9 +744,8 @@ export class PerpsController extends BaseController {
|
|
|
744
744
|
// Live chase lists waiting to hear which chase cancels succeeded.
|
|
745
745
|
#chaseCancellationListeners = new Set();
|
|
746
746
|
/**
|
|
747
|
-
* Latest toggle
|
|
748
|
-
*
|
|
749
|
-
* has superseded it.
|
|
747
|
+
* Latest toggle per network and saved reference whose write is pending.
|
|
748
|
+
* Grouped and symbol-only calls can overlap on a legacy reference.
|
|
750
749
|
*/
|
|
751
750
|
#pendingWatchlistToggles = new Map();
|
|
752
751
|
#userDiskWrite = Promise.resolve();
|
|
@@ -953,23 +952,8 @@ export class PerpsController extends BaseController {
|
|
|
953
952
|
const { activeProvider } = this.state;
|
|
954
953
|
const cache = this.state.cachedMarketDataByProvider;
|
|
955
954
|
if (activeProvider === 'aggregated') {
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
for (const providerId of this.#getAggregatedCacheProviderIds(Object.keys(cache))) {
|
|
959
|
-
const key = buildProviderCacheKey(providerId, this.state.isTestnet);
|
|
960
|
-
const entry = cache[key];
|
|
961
|
-
if (!entry || entry.data.length === 0) {
|
|
962
|
-
continue;
|
|
963
|
-
}
|
|
964
|
-
if (!this.#isMarketCacheEntryCurrent(providerId, entry, options)) {
|
|
965
|
-
continue;
|
|
966
|
-
}
|
|
967
|
-
assembled.push(...clonePerpsMarketData(entry.data));
|
|
968
|
-
}
|
|
969
|
-
if (assembled.length === 0) {
|
|
970
|
-
return null;
|
|
971
|
-
}
|
|
972
|
-
return assembled;
|
|
955
|
+
const rows = this.#getCachedAggregateMarketRows(options);
|
|
956
|
+
return rows ? clonePerpsMarketData(rows) : null;
|
|
973
957
|
}
|
|
974
958
|
// Single provider mode
|
|
975
959
|
const key = buildProviderCacheKey(activeProvider, this.state.isTestnet);
|
|
@@ -982,6 +966,30 @@ export class PerpsController extends BaseController {
|
|
|
982
966
|
}
|
|
983
967
|
return clonePerpsMarketData(entry.data);
|
|
984
968
|
}
|
|
969
|
+
#getCachedAggregateMarketRows(options) {
|
|
970
|
+
const { cachedMarketDataByProvider: cache, isTestnet } = this.state;
|
|
971
|
+
const snapshotConfigured = this.#isGlobalSnapshotConfigured();
|
|
972
|
+
const providerIds = new Set(this.#getAggregatedCacheProviderIds(Object.keys(cache)));
|
|
973
|
+
if (snapshotConfigured) {
|
|
974
|
+
providerIds.add('hyperliquid');
|
|
975
|
+
if (this.#isLighterProviderEnabled()) {
|
|
976
|
+
providerIds.add('lighter');
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
const assembled = [];
|
|
980
|
+
for (const providerId of providerIds) {
|
|
981
|
+
const entry = cache[buildProviderCacheKey(providerId, isTestnet)];
|
|
982
|
+
if (entry?.data.length &&
|
|
983
|
+
this.#isMarketCacheEntryCurrent(providerId, entry, options)) {
|
|
984
|
+
assembled.push(...entry.data);
|
|
985
|
+
}
|
|
986
|
+
else if (snapshotConfigured || entry?.sourceExpiresAt !== undefined) {
|
|
987
|
+
// Clients treat a nonempty aggregate preload as fresh for every venue.
|
|
988
|
+
return null;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return assembled.length > 0 ? assembled : null;
|
|
992
|
+
}
|
|
985
993
|
#isMarketCacheEntryCurrent(providerId, entry, options) {
|
|
986
994
|
if (entry.sourceExpiresAt !== undefined) {
|
|
987
995
|
const expectedDexes = this.#getStaticSnapshotDexes();
|
|
@@ -4140,9 +4148,9 @@ export class PerpsController extends BaseController {
|
|
|
4140
4148
|
* @returns Service context for `MarketDataService.getMarkets`.
|
|
4141
4149
|
*/
|
|
4142
4150
|
#createGetMarketsContext() {
|
|
4143
|
-
const
|
|
4151
|
+
const globalSnapshots = this.#buildGlobalSnapshotContexts();
|
|
4144
4152
|
return this.#createServiceContext('getMarkets', {
|
|
4145
|
-
...(
|
|
4153
|
+
...(globalSnapshots && { globalSnapshots }),
|
|
4146
4154
|
});
|
|
4147
4155
|
}
|
|
4148
4156
|
/**
|
|
@@ -4161,9 +4169,9 @@ export class PerpsController extends BaseController {
|
|
|
4161
4169
|
* @returns A promise that resolves to the market data.
|
|
4162
4170
|
*/
|
|
4163
4171
|
async getMarketDataWithPrices(params) {
|
|
4164
|
-
const
|
|
4172
|
+
const globalSnapshots = this.#buildGlobalSnapshotContexts();
|
|
4165
4173
|
const context = this.#createServiceContext('getMarketDataWithPrices', {
|
|
4166
|
-
...(
|
|
4174
|
+
...(globalSnapshots && { globalSnapshots }),
|
|
4167
4175
|
});
|
|
4168
4176
|
if (params?.standalone) {
|
|
4169
4177
|
const provider = this.activeProviderInstance ?? this.#getOrCreateStandaloneProvider();
|
|
@@ -4184,35 +4192,60 @@ export class PerpsController extends BaseController {
|
|
|
4184
4192
|
});
|
|
4185
4193
|
}
|
|
4186
4194
|
/**
|
|
4187
|
-
* Capture the exact static identity
|
|
4188
|
-
*
|
|
4189
|
-
*
|
|
4195
|
+
* Capture the exact static identity each active provider needs to adopt its
|
|
4196
|
+
* atomic snapshot: the direct provider, or every registered venue in
|
|
4197
|
+
* aggregated mode. HyperLiquid with dynamic DEX discovery opts out and
|
|
4198
|
+
* keeps the provider path.
|
|
4190
4199
|
*
|
|
4191
|
-
* @returns
|
|
4200
|
+
* @returns One snapshot identity with its race guard per provider, or
|
|
4201
|
+
* undefined when none applies.
|
|
4192
4202
|
*/
|
|
4193
|
-
#
|
|
4194
|
-
|
|
4195
|
-
typeof this.#options.infrastructure.terminalMarketService
|
|
4196
|
-
?.fetchGlobalSnapshot === 'function';
|
|
4197
|
-
if (!snapshotConfigured || this.state.activeProvider !== 'hyperliquid') {
|
|
4203
|
+
#buildGlobalSnapshotContexts() {
|
|
4204
|
+
if (!this.#isGlobalSnapshotConfigured()) {
|
|
4198
4205
|
return undefined;
|
|
4199
4206
|
}
|
|
4200
|
-
const
|
|
4201
|
-
|
|
4202
|
-
|
|
4207
|
+
const { activeProvider, isTestnet, hip3ConfigVersion } = this.state;
|
|
4208
|
+
const isActive = (providerId) => activeProvider === providerId ||
|
|
4209
|
+
(activeProvider === 'aggregated' && this.providers.has(providerId));
|
|
4210
|
+
const contexts = {};
|
|
4211
|
+
const hyperLiquidDexes = isActive('hyperliquid')
|
|
4212
|
+
? this.#getStaticSnapshotDexes()
|
|
4213
|
+
: undefined;
|
|
4214
|
+
if (hyperLiquidDexes) {
|
|
4215
|
+
contexts.hyperliquid = {
|
|
4216
|
+
request: {
|
|
4217
|
+
provider: 'hyperliquid',
|
|
4218
|
+
network: isTestnet ? 'testnet' : 'mainnet',
|
|
4219
|
+
enabledDexes: hyperLiquidDexes,
|
|
4220
|
+
},
|
|
4221
|
+
isCurrent: () => this.state.activeProvider === activeProvider &&
|
|
4222
|
+
this.state.isTestnet === isTestnet &&
|
|
4223
|
+
this.state.hip3ConfigVersion === hip3ConfigVersion,
|
|
4224
|
+
isMarketAllowed: this.#buildMarketAllowedFilter(),
|
|
4225
|
+
};
|
|
4203
4226
|
}
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
this.state.
|
|
4214
|
-
|
|
4215
|
-
|
|
4227
|
+
if (isActive('lighter')) {
|
|
4228
|
+
contexts.lighter = {
|
|
4229
|
+
request: {
|
|
4230
|
+
provider: 'lighter',
|
|
4231
|
+
network: isProviderOnTestnet('lighter', isTestnet)
|
|
4232
|
+
? 'testnet'
|
|
4233
|
+
: 'mainnet',
|
|
4234
|
+
enabledDexes: ['main'],
|
|
4235
|
+
},
|
|
4236
|
+
isCurrent: () => this.state.activeProvider === activeProvider &&
|
|
4237
|
+
this.state.isTestnet === isTestnet,
|
|
4238
|
+
// Lighter keeps its provider's market list; the snapshot only adds
|
|
4239
|
+
// metadata to it, so there is no snapshot row to filter.
|
|
4240
|
+
isMarketAllowed: () => true,
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
return contexts.hyperliquid || contexts.lighter ? contexts : undefined;
|
|
4244
|
+
}
|
|
4245
|
+
#isGlobalSnapshotConfigured() {
|
|
4246
|
+
const { terminalApi, terminalMarketService } = this.#options.infrastructure;
|
|
4247
|
+
return (Boolean(terminalApi?.globalSnapshotUrl) ||
|
|
4248
|
+
typeof terminalMarketService?.fetchGlobalSnapshot === 'function');
|
|
4216
4249
|
}
|
|
4217
4250
|
#getStaticSnapshotDexes() {
|
|
4218
4251
|
if (!this.#hip3Enabled) {
|
|
@@ -4485,7 +4518,9 @@ export class PerpsController extends BaseController {
|
|
|
4485
4518
|
const existingEntry = this.state.cachedMarketDataByProvider[cacheKey];
|
|
4486
4519
|
if (existingEntry &&
|
|
4487
4520
|
this.#isMarketCacheEntryCurrent(actualProviderId, existingEntry) &&
|
|
4488
|
-
now - existingEntry.timestamp < _a.#preloadGuardMs
|
|
4521
|
+
now - existingEntry.timestamp < _a.#preloadGuardMs &&
|
|
4522
|
+
(actualProviderId !== 'aggregated' ||
|
|
4523
|
+
this.#getCachedAggregateMarketRows() !== null)) {
|
|
4489
4524
|
return;
|
|
4490
4525
|
}
|
|
4491
4526
|
this.#isPreloading = true;
|
|
@@ -4519,20 +4554,23 @@ export class PerpsController extends BaseController {
|
|
|
4519
4554
|
}
|
|
4520
4555
|
// Store under per-provider key(s)
|
|
4521
4556
|
const ts = Date.now();
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4557
|
+
// A slice made only of snapshot rows expires with its snapshot.
|
|
4558
|
+
const snapshotCacheIdentity = (rows) => {
|
|
4559
|
+
const sourceExpiries = rows.flatMap((market) => market.dataSource === 'terminal-global-snapshot-mark' &&
|
|
4560
|
+
typeof market.sourceExpiresAt === 'number'
|
|
4561
|
+
? [market.sourceExpiresAt]
|
|
4562
|
+
: []);
|
|
4563
|
+
if (rows.length === 0 ||
|
|
4564
|
+
sourceExpiries.length !== rows.length ||
|
|
4565
|
+
!staticSnapshotDexes) {
|
|
4566
|
+
return {};
|
|
4567
|
+
}
|
|
4568
|
+
return {
|
|
4569
|
+
sourceExpiresAt: Math.min(...sourceExpiries),
|
|
4532
4570
|
hip3ConfigVersion: preloadContext.hip3ConfigVersion,
|
|
4533
4571
|
dexes: staticSnapshotDexes,
|
|
4534
|
-
}
|
|
4535
|
-
|
|
4572
|
+
};
|
|
4573
|
+
};
|
|
4536
4574
|
const marketDiskEntries = [];
|
|
4537
4575
|
if (!isCurrent()) {
|
|
4538
4576
|
traceData = {
|
|
@@ -4567,6 +4605,7 @@ export class PerpsController extends BaseController {
|
|
|
4567
4605
|
state.cachedMarketDataByProvider[key] = {
|
|
4568
4606
|
data: slice,
|
|
4569
4607
|
timestamp: ts,
|
|
4608
|
+
...snapshotCacheIdentity(slice),
|
|
4570
4609
|
};
|
|
4571
4610
|
}
|
|
4572
4611
|
// Write aggregated sentinel so the staleness guard sees it
|
|
@@ -4586,7 +4625,7 @@ export class PerpsController extends BaseController {
|
|
|
4586
4625
|
state.cachedMarketDataByProvider[cacheKey] = {
|
|
4587
4626
|
data,
|
|
4588
4627
|
timestamp: ts,
|
|
4589
|
-
...snapshotCacheIdentity,
|
|
4628
|
+
...snapshotCacheIdentity(data),
|
|
4590
4629
|
};
|
|
4591
4630
|
});
|
|
4592
4631
|
}
|
|
@@ -7332,11 +7371,16 @@ export class PerpsController extends BaseController {
|
|
|
7332
7371
|
* Watchlist markets are stored per network (testnet/mainnet).
|
|
7333
7372
|
*
|
|
7334
7373
|
* @param symbol - The trading pair symbol.
|
|
7374
|
+
* @param marketKey - Optional cross-venue key for a grouped market.
|
|
7375
|
+
* @param venues - Original rows from the group, used to match a legacy favorite.
|
|
7376
|
+
* @param legacyProvider - Venue that owned saved symbols before grouping.
|
|
7335
7377
|
*/
|
|
7336
|
-
async toggleWatchlistMarket(symbol) {
|
|
7378
|
+
async toggleWatchlistMarket(symbol, marketKey, venues, legacyProvider) {
|
|
7379
|
+
const references = getPerpsWatchlistReferences(symbol, marketKey, venues, legacyProvider);
|
|
7380
|
+
const [reference] = references;
|
|
7337
7381
|
const currentNetwork = this.state.isTestnet ? 'testnet' : 'mainnet';
|
|
7338
7382
|
const currentWatchlist = this.state.watchlistMarkets[currentNetwork];
|
|
7339
|
-
const isWatchlisted = currentWatchlist.includes(
|
|
7383
|
+
const isWatchlisted = references.some((entry) => currentWatchlist.includes(entry));
|
|
7340
7384
|
this.#debugLog('PerpsController: Toggling watchlist market', {
|
|
7341
7385
|
timestamp: new Date().toISOString(),
|
|
7342
7386
|
network: currentNetwork,
|
|
@@ -7346,19 +7390,30 @@ export class PerpsController extends BaseController {
|
|
|
7346
7390
|
// Step 1: Optimistic local state update — UI reflects change immediately.
|
|
7347
7391
|
this.update((state) => {
|
|
7348
7392
|
if (isWatchlisted) {
|
|
7349
|
-
state.watchlistMarkets[currentNetwork] = currentWatchlist.filter((marketSymbol) => marketSymbol
|
|
7393
|
+
state.watchlistMarkets[currentNetwork] = currentWatchlist.filter((marketSymbol) => !references.includes(marketSymbol));
|
|
7350
7394
|
}
|
|
7351
7395
|
else {
|
|
7352
|
-
state.watchlistMarkets[currentNetwork] = [
|
|
7396
|
+
state.watchlistMarkets[currentNetwork] = [
|
|
7397
|
+
...currentWatchlist,
|
|
7398
|
+
reference,
|
|
7399
|
+
];
|
|
7353
7400
|
}
|
|
7354
7401
|
});
|
|
7355
7402
|
for (const edits of this.#watchlistEditsDuringHydration) {
|
|
7356
|
-
|
|
7403
|
+
for (const entry of references) {
|
|
7404
|
+
edits.push({
|
|
7405
|
+
network: currentNetwork,
|
|
7406
|
+
symbol: entry,
|
|
7407
|
+
add: !isWatchlisted && entry === reference,
|
|
7408
|
+
});
|
|
7409
|
+
}
|
|
7410
|
+
}
|
|
7411
|
+
const toggle = Symbol(reference);
|
|
7412
|
+
const toggleKey = (entry) => `${currentNetwork}:${entry}`;
|
|
7413
|
+
for (const entry of references) {
|
|
7414
|
+
this.#pendingWatchlistToggles.set(toggleKey(entry), toggle);
|
|
7357
7415
|
}
|
|
7358
|
-
const
|
|
7359
|
-
const toggleNumber = (this.#pendingWatchlistToggles.get(toggleKey) ?? 0) + 1;
|
|
7360
|
-
this.#pendingWatchlistToggles.set(toggleKey, toggleNumber);
|
|
7361
|
-
const isLatestToggle = () => this.#pendingWatchlistToggles.get(toggleKey) === toggleNumber;
|
|
7416
|
+
const isLatestToggle = (entry) => this.#pendingWatchlistToggles.get(toggleKey(entry)) === toggle;
|
|
7362
7417
|
this.#getMetrics().trackPerpsEvent(PerpsAnalyticsEvent.UiInteraction, {
|
|
7363
7418
|
[PERPS_EVENT_PROPERTY.INTERACTION_TYPE]: PERPS_EVENT_VALUE.INTERACTION_TYPE.FAVORITE_TOGGLED,
|
|
7364
7419
|
[PERPS_EVENT_PROPERTY.ASSET]: symbol,
|
|
@@ -7386,31 +7441,30 @@ export class PerpsController extends BaseController {
|
|
|
7386
7441
|
network: currentNetwork,
|
|
7387
7442
|
action: isWatchlisted ? 'remove' : 'add',
|
|
7388
7443
|
}));
|
|
7389
|
-
// A later toggle of the same market decides its state; its own write
|
|
7390
|
-
// persists it.
|
|
7391
|
-
if (!isLatestToggle()) {
|
|
7392
|
-
return;
|
|
7393
|
-
}
|
|
7394
7444
|
// Undo only this toggle. The list may have changed since it was made
|
|
7395
7445
|
// (hydration, other toggles), so restoring the earlier snapshot would
|
|
7396
7446
|
// discard those changes.
|
|
7397
7447
|
this.update((state) => {
|
|
7398
7448
|
const watchlist = state.watchlistMarkets[currentNetwork];
|
|
7399
7449
|
if (isWatchlisted) {
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7450
|
+
for (const [index, entry] of currentWatchlist.entries()) {
|
|
7451
|
+
if (references.includes(entry) &&
|
|
7452
|
+
isLatestToggle(entry) &&
|
|
7453
|
+
!watchlist.includes(entry)) {
|
|
7454
|
+
watchlist.splice(Math.min(index, watchlist.length), 0, entry);
|
|
7455
|
+
}
|
|
7404
7456
|
}
|
|
7405
7457
|
}
|
|
7406
|
-
else {
|
|
7407
|
-
state.watchlistMarkets[currentNetwork] = watchlist.filter((marketSymbol) => marketSymbol !==
|
|
7458
|
+
else if (isLatestToggle(reference)) {
|
|
7459
|
+
state.watchlistMarkets[currentNetwork] = watchlist.filter((marketSymbol) => marketSymbol !== reference);
|
|
7408
7460
|
}
|
|
7409
7461
|
});
|
|
7410
7462
|
}
|
|
7411
7463
|
finally {
|
|
7412
|
-
|
|
7413
|
-
|
|
7464
|
+
for (const entry of references) {
|
|
7465
|
+
if (isLatestToggle(entry)) {
|
|
7466
|
+
this.#pendingWatchlistToggles.delete(toggleKey(entry));
|
|
7467
|
+
}
|
|
7414
7468
|
}
|
|
7415
7469
|
}
|
|
7416
7470
|
}
|
|
@@ -7418,16 +7472,19 @@ export class PerpsController extends BaseController {
|
|
|
7418
7472
|
* Check if a market is in the watchlist on the current network
|
|
7419
7473
|
*
|
|
7420
7474
|
* @param symbol - The trading pair symbol.
|
|
7421
|
-
* @
|
|
7475
|
+
* @param marketKey - Optional cross-venue key for a grouped market.
|
|
7476
|
+
* @param venues - Original rows from the group, used to match a legacy favorite.
|
|
7477
|
+
* @param legacyProvider - Venue that owned saved symbols before grouping.
|
|
7478
|
+
* @returns Whether the reference is saved.
|
|
7422
7479
|
*/
|
|
7423
|
-
isWatchlistMarket(symbol) {
|
|
7480
|
+
isWatchlistMarket(symbol, marketKey, venues, legacyProvider) {
|
|
7424
7481
|
const currentNetwork = this.state.isTestnet ? 'testnet' : 'mainnet';
|
|
7425
|
-
return this.state.watchlistMarkets[currentNetwork].includes(
|
|
7482
|
+
return getPerpsWatchlistReferences(symbol, marketKey, venues, legacyProvider).some((reference) => this.state.watchlistMarkets[currentNetwork].includes(reference));
|
|
7426
7483
|
}
|
|
7427
7484
|
/**
|
|
7428
7485
|
* Get all watchlist markets for the current network
|
|
7429
7486
|
*
|
|
7430
|
-
* @returns
|
|
7487
|
+
* @returns Saved market references for the current network.
|
|
7431
7488
|
*/
|
|
7432
7489
|
getWatchlistMarkets() {
|
|
7433
7490
|
const currentNetwork = this.state.isTestnet ? 'testnet' : 'mainnet';
|
|
@@ -7436,19 +7493,25 @@ export class PerpsController extends BaseController {
|
|
|
7436
7493
|
/**
|
|
7437
7494
|
* Record that the user viewed a market.
|
|
7438
7495
|
*
|
|
7439
|
-
* The
|
|
7440
|
-
* Any existing entry for the same
|
|
7441
|
-
* duplicates. The list is then capped at
|
|
7496
|
+
* The market reference is prepended to the per-network recently-viewed list (newest-first).
|
|
7497
|
+
* Any existing entry for the same reference, or for its legacy alias, is
|
|
7498
|
+
* removed first so there are no duplicates. The list is then capped at
|
|
7499
|
+
* PERPS_CONSTANTS.RecentlyViewedMarketsLimit.
|
|
7442
7500
|
*
|
|
7443
7501
|
* @param symbol - The trading pair symbol (e.g. 'BTC', 'ETH', 'xyz:TSLA').
|
|
7502
|
+
* @param marketKey - Optional cross-venue key for a grouped market.
|
|
7503
|
+
* @param venues - Original rows from the group, used to match a legacy entry.
|
|
7504
|
+
* @param legacyProvider - Venue that owned saved symbols before grouping.
|
|
7444
7505
|
*/
|
|
7445
|
-
recordMarketViewed(symbol) {
|
|
7506
|
+
recordMarketViewed(symbol, marketKey, venues, legacyProvider) {
|
|
7507
|
+
const references = getPerpsWatchlistReferences(symbol, marketKey, venues, legacyProvider);
|
|
7508
|
+
const [reference] = references;
|
|
7446
7509
|
const currentNetwork = this.state.isTestnet ? 'testnet' : 'mainnet';
|
|
7447
7510
|
const now = Date.now();
|
|
7448
7511
|
this.update((state) => {
|
|
7449
|
-
const current = state.recentlyViewedMarkets[currentNetwork].filter((entry) => entry.symbol
|
|
7512
|
+
const current = state.recentlyViewedMarkets[currentNetwork].filter((entry) => !references.includes(entry.symbol));
|
|
7450
7513
|
state.recentlyViewedMarkets[currentNetwork] = [
|
|
7451
|
-
{ symbol, viewedAt: now },
|
|
7514
|
+
{ symbol: reference, viewedAt: now },
|
|
7452
7515
|
...current,
|
|
7453
7516
|
].slice(0, PERPS_CONSTANTS.RecentlyViewedMarketsLimit);
|
|
7454
7517
|
});
|
|
@@ -7456,12 +7519,12 @@ export class PerpsController extends BaseController {
|
|
|
7456
7519
|
/**
|
|
7457
7520
|
* Get recently viewed markets for the current network.
|
|
7458
7521
|
*
|
|
7459
|
-
* Returns up to PERPS_CONSTANTS.RecentlyViewedMarketsLimit
|
|
7522
|
+
* Returns up to PERPS_CONSTANTS.RecentlyViewedMarketsLimit references, ordered
|
|
7460
7523
|
* newest-first, filtered to entries within the last
|
|
7461
7524
|
* PERPS_CONSTANTS.RecentlyViewedMarketsTtlMs (24 hours). Returns an empty
|
|
7462
7525
|
* array when no qualifying entries exist.
|
|
7463
7526
|
*
|
|
7464
|
-
* @returns Ordered array of market
|
|
7527
|
+
* @returns Ordered array of saved market references.
|
|
7465
7528
|
*/
|
|
7466
7529
|
getRecentlyViewedMarkets() {
|
|
7467
7530
|
const currentNetwork = this.state.isTestnet ? 'testnet' : 'mainnet';
|