@metamask-previews/perps-controller 2.0.0-preview-a37be9342 → 2.0.0-preview-26cb9fc
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 +10 -0
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/eventNames.cjs +1 -0
- package/dist/constants/eventNames.cjs.map +1 -1
- package/dist/constants/eventNames.d.cts +1 -0
- package/dist/constants/eventNames.d.cts.map +1 -1
- package/dist/constants/eventNames.d.mts +1 -0
- package/dist/constants/eventNames.d.mts.map +1 -1
- package/dist/constants/eventNames.mjs +1 -0
- package/dist/constants/eventNames.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +3 -0
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +1 -0
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +1 -0
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +3 -0
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/index.cjs +50 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +18 -6
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +18 -6
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs +39 -16
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts +2 -0
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts +2 -0
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs +39 -16
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +78 -13
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +78 -13
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/TradingService.cjs +0 -1
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +0 -1
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/types/index.cjs +3 -2
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +3 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/transactionTypes.cjs +5 -4
- package/dist/types/transactionTypes.cjs.map +1 -1
- package/dist/types/transactionTypes.d.cts +0 -4
- package/dist/types/transactionTypes.d.cts.map +1 -1
- package/dist/types/transactionTypes.d.mts +0 -4
- package/dist/types/transactionTypes.d.mts.map +1 -1
- package/dist/types/transactionTypes.mjs +3 -2
- package/dist/types/transactionTypes.mjs.map +1 -1
- package/dist/utils/errorUtils.cjs +4 -3
- package/dist/utils/errorUtils.cjs.map +1 -1
- package/dist/utils/errorUtils.d.cts +0 -4
- package/dist/utils/errorUtils.d.cts.map +1 -1
- package/dist/utils/errorUtils.d.mts +0 -4
- package/dist/utils/errorUtils.d.mts.map +1 -1
- package/dist/utils/errorUtils.mjs +2 -1
- package/dist/utils/errorUtils.mjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.cjs +3 -2
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.mjs +4 -3
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
- package/dist/utils/hyperLiquidValidation.cjs +4 -0
- package/dist/utils/hyperLiquidValidation.cjs.map +1 -1
- package/dist/utils/hyperLiquidValidation.d.cts.map +1 -1
- package/dist/utils/hyperLiquidValidation.d.mts.map +1 -1
- package/dist/utils/hyperLiquidValidation.mjs +4 -0
- package/dist/utils/hyperLiquidValidation.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +0 -1
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +0 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/marketDataTransform.cjs +2 -1
- package/dist/utils/marketDataTransform.cjs.map +1 -1
- package/dist/utils/marketDataTransform.d.cts.map +1 -1
- package/dist/utils/marketDataTransform.d.mts.map +1 -1
- package/dist/utils/marketDataTransform.mjs +2 -1
- package/dist/utils/marketDataTransform.mjs.map +1 -1
- package/dist/utils/perpsConnectionAttemptContext.cjs +20 -0
- package/dist/utils/perpsConnectionAttemptContext.cjs.map +1 -0
- package/dist/utils/perpsConnectionAttemptContext.d.cts +7 -0
- package/dist/utils/perpsConnectionAttemptContext.d.cts.map +1 -0
- package/dist/utils/perpsConnectionAttemptContext.d.mts +7 -0
- package/dist/utils/perpsConnectionAttemptContext.d.mts.map +1 -0
- package/dist/utils/perpsConnectionAttemptContext.mjs +15 -0
- package/dist/utils/perpsConnectionAttemptContext.mjs.map +1 -0
- package/package.json +4 -2
|
@@ -20,6 +20,7 @@ const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
|
20
20
|
const perpsErrorCodes_1 = require("../perpsErrorCodes.cjs");
|
|
21
21
|
const types_1 = require("../types/index.cjs");
|
|
22
22
|
const errorUtils_1 = require("../utils/errorUtils.cjs");
|
|
23
|
+
const perpsConnectionAttemptContext_1 = require("../utils/perpsConnectionAttemptContext.cjs");
|
|
23
24
|
/**
|
|
24
25
|
* Maximum number of reconnection attempts before giving up.
|
|
25
26
|
*/
|
|
@@ -71,6 +72,8 @@ class HyperLiquidClientService {
|
|
|
71
72
|
* @param wallet - The wallet parameters for signing typed data.
|
|
72
73
|
*/
|
|
73
74
|
async initialize(wallet) {
|
|
75
|
+
const network = __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
|
|
76
|
+
const attemptContext = (0, perpsConnectionAttemptContext_1.getPerpsConnectionAttemptContext)();
|
|
74
77
|
try {
|
|
75
78
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, types_1.WebSocketConnectionState.Connecting);
|
|
76
79
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
|
|
@@ -123,21 +126,30 @@ class HyperLiquidClientService {
|
|
|
123
126
|
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
|
|
124
127
|
const errorInstance = (0, errorUtils_1.ensureError)(error, 'HyperLiquidClientService.initialize');
|
|
125
128
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, types_1.WebSocketConnectionState.Disconnected);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
if (attemptContext?.suppressError) {
|
|
130
|
+
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid initialize failed during suppressed startup attempt', {
|
|
131
|
+
error: errorInstance.message,
|
|
132
|
+
network,
|
|
133
|
+
source: attemptContext.source,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
138
|
+
tags: {
|
|
139
|
+
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
140
|
+
service: 'HyperLiquidClientService',
|
|
141
|
+
network,
|
|
138
142
|
},
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
context: {
|
|
144
|
+
name: 'sdk_initialization',
|
|
145
|
+
data: {
|
|
146
|
+
operation: 'initialize',
|
|
147
|
+
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
148
|
+
source: attemptContext?.source ?? 'unspecified',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
141
153
|
throw error;
|
|
142
154
|
}
|
|
143
155
|
}
|
|
@@ -292,10 +304,11 @@ class HyperLiquidClientService {
|
|
|
292
304
|
* @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
|
|
293
305
|
* @param options.limit - Number of candles to fetch (default: 100).
|
|
294
306
|
* @param options.endTime - End timestamp in milliseconds (default: now).
|
|
307
|
+
* @param options.signal - Optional AbortSignal to cancel the fetch.
|
|
295
308
|
* @returns The historical candle data, or null if no data is available.
|
|
296
309
|
*/
|
|
297
310
|
async fetchHistoricalCandles(options) {
|
|
298
|
-
const { symbol, interval, limit = 100, endTime } = options;
|
|
311
|
+
const { symbol, interval, limit = 100, endTime, signal } = options;
|
|
299
312
|
this.ensureInitialized();
|
|
300
313
|
try {
|
|
301
314
|
// Calculate start and end times based on interval and limit
|
|
@@ -310,7 +323,7 @@ class HyperLiquidClientService {
|
|
|
310
323
|
interval,
|
|
311
324
|
startTime,
|
|
312
325
|
endTime: now,
|
|
313
|
-
});
|
|
326
|
+
}, signal);
|
|
314
327
|
// Transform API response to match expected format
|
|
315
328
|
if (Array.isArray(data) && data.length > 0) {
|
|
316
329
|
const candles = data.map((candle) => ({
|
|
@@ -379,6 +392,9 @@ class HyperLiquidClientService {
|
|
|
379
392
|
// Store the subscription promise to enable cleanup even when pending
|
|
380
393
|
// This fixes a race condition where component unmounts before subscription resolves
|
|
381
394
|
let subscriptionPromise = null;
|
|
395
|
+
// AbortController to cancel in-flight REST calls (candleSnapshot) on cleanup.
|
|
396
|
+
// Prevents rate limit exhaustion when rapidly switching markets (#28141).
|
|
397
|
+
const abortController = new AbortController();
|
|
382
398
|
// Calculate initial fetch size dynamically based on duration and interval
|
|
383
399
|
// Match main branch behavior: up to 500 candles initially
|
|
384
400
|
const initialLimit = duration
|
|
@@ -392,6 +408,7 @@ class HyperLiquidClientService {
|
|
|
392
408
|
symbol,
|
|
393
409
|
interval,
|
|
394
410
|
limit: initialLimit,
|
|
411
|
+
signal: abortController.signal,
|
|
395
412
|
});
|
|
396
413
|
// Don't proceed if already unsubscribed
|
|
397
414
|
if (isUnsubscribed) {
|
|
@@ -483,6 +500,10 @@ class HyperLiquidClientService {
|
|
|
483
500
|
}
|
|
484
501
|
}
|
|
485
502
|
catch (error) {
|
|
503
|
+
// Skip logging and notification for intentional abort (user navigated away)
|
|
504
|
+
if (abortController.signal.aborted) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
486
507
|
const errorInstance = (0, errorUtils_1.ensureError)(error, 'HyperLiquidClientService.subscribeToCandles');
|
|
487
508
|
// Log to Sentry: initial fetch failure blocks chart completely
|
|
488
509
|
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
@@ -513,6 +534,8 @@ class HyperLiquidClientService {
|
|
|
513
534
|
// Return cleanup function
|
|
514
535
|
return () => {
|
|
515
536
|
isUnsubscribed = true;
|
|
537
|
+
// Cancel any in-flight REST calls (candleSnapshot) to conserve rate limit budget (#28141)
|
|
538
|
+
abortController.abort();
|
|
516
539
|
if (wsUnsubscribe) {
|
|
517
540
|
// Subscription already resolved - unsubscribe directly
|
|
518
541
|
wsUnsubscribe();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidClientService.cjs","sourceRoot":"","sources":["../../src/services/HyperLiquidClientService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qDAM6B;AAE7B,8DAA8E;AAC9E,0EAA8E;AAC9E,8DAA2D;AAC3D,4DAAuD;AACvD,8CAAoD;AAOpD,wDAAkD;AAElD;;GAEG;AACH,MAAM,uBAAuB,GAAG,EAAE,CAAC;AA6BnC,kEAAkE;AAClE,+DAA+D;AAC/D,4CAAoD;AAA3C,iHAAA,wBAAwB,OAAA;AAEjC;;;GAGG;AACH,MAAa,wBAAwB;IAyCnC,YACE,IAA+B,EAC/B,UAAmC,EAAE;;QA1CvC,2DAAiC;QAEjC,uDAAyB,CAAC,gCAAgC;QAE1D,2DAA6B,CAAC,4BAA4B;QAE1D,+DAEG;QAEH,wDAAkC;QAElC,0DAA+B;QAE/B,sDAAoB;QAEpB,oDACE,gCAAwB,CAAC,YAAY,EAAC;QAExC,yDAA8C,IAAI,EAAC;QAEnD,oFAAoF;QACpF,wDAAwD,IAAI,EAAC;QAE7D,gEAA2C;QAE3C,+BAA+B;QAC/B,wDAAuB,CAAC,EAAC;QAEzB,kEAAkE;QACzD,6DAEL,IAAI,GAAG,EAAE,EAAC;QAEd,yFAAyF;QACzF,6DAAkE,IAAI,EAAC;QAEvE,oCAAoC;QAC3B,iDAAiC;QAy3B1C,mDAAmD;QACnD,mDAAkB,KAAK,EAAC;QAp3BtB,uBAAA,IAAI,kCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,uCAAc,OAAO,CAAC,SAAS,IAAI,KAAK,MAAA,CAAC;IAC/C,CAAC;IAED;;;;;;;;;OASG;IACI,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,4CAAmB,KAAK,MAAA,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,qEAAqE;QACrE,uBAAA,IAAI,4CAAmB,KAAK,MAAA,CAAC;QAE7B,6CAA6C;QAC7C,IAAI,uBAAA,IAAI,qDAAqB,IAAI,uBAAuB,EAAE,CAAC;YACzD,uBAAA,IAAI,4FAAuB,MAA3B,IAAI,EAAwB,gCAAwB,CAAC,YAAY,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAED,uDAAuD;QACvD,2EAA2E;QAC3E,uBAAA,IAAI,sDAA6B,UAAU,CAAC,GAAG,EAAE;YAC/C,uBAAA,IAAI,sDAA6B,IAAI,MAAA,CAAC,CAAC,kCAAkC;YACzE,2DAA2D;YAC3D,mDAAmD;YACnD,4FAA4F;YAC5F,IACE,CAAC,uBAAA,IAAI,iDAAiB,KAAK,gCAAwB,CAAC,UAAU;gBAC5D,uBAAA,IAAI,iDAAiB,KAAK,gCAAwB,CAAC,YAAY,CAAC;gBAClE,CAAC,uBAAA,IAAI,sDAAsB;gBAC3B,CAAC,uBAAA,IAAI,gDAAgB,EACrB,CAAC;gBACD,uBAAA,IAAI,2FAAsB,MAA1B,IAAI,CAAwB,CAAC,KAAK,CAAC,GAAG,EAAE;oBACtC,qDAAqD;gBACvD,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,EAAE,6BAAe,CAAC,wBAAwB,CAAC,MAAA,CAAC;IAC/C,CAAC;AACH,CAAC","sourcesContent":["import { Hex } from '@metamask/utils';\nimport {\n ExchangeClient,\n HttpTransport,\n InfoClient,\n SubscriptionClient,\n WebSocketTransport,\n} from '@nktkas/hyperliquid';\n\nimport { CandlePeriod, calculateCandleCount } from '../constants/chartConfig';\nimport { HYPERLIQUID_TRANSPORT_CONFIG } from '../constants/hyperLiquidConfig';\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport { WebSocketConnectionState } from '../types';\nimport type {\n SubscribeCandlesParams,\n PerpsPlatformDependencies,\n} from '../types';\nimport type { HyperLiquidNetwork } from '../types/config';\nimport type { CandleData } from '../types/perps-types';\nimport { ensureError } from '../utils/errorUtils';\n\n/**\n * Maximum number of reconnection attempts before giving up.\n */\nconst maxReconnectionAttempts = 10;\n\n/**\n * Valid time intervals for historical candle data\n * Uses CandlePeriod enum for type safety\n */\nexport type ValidCandleInterval = CandlePeriod;\n\n/**\n * Wallet interface for HyperLiquid SDK operations.\n * Extracted for reuse across initialize(), toggleTestnet(), and ensureSubscriptionClient() methods.\n */\nexport type HyperLiquidWalletParams = {\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n};\n\n// WebSocketConnectionState is now imported from controllers/types\n// Re-export for backward compatibility with existing consumers\nexport { WebSocketConnectionState } from '../types';\n\n/**\n * Service for managing HyperLiquid SDK clients\n * Handles initialization, transport creation, and client lifecycle\n */\nexport class HyperLiquidClientService {\n #exchangeClient?: ExchangeClient;\n\n #infoClient?: InfoClient; // WebSocket transport (default)\n\n #infoClientHttp?: InfoClient; // HTTP transport (fallback)\n\n #subscriptionClient?: SubscriptionClient<{\n transport: WebSocketTransport;\n }>;\n\n #wsTransport?: WebSocketTransport;\n\n #httpTransport?: HttpTransport;\n\n #isTestnet: boolean;\n\n #connectionState: WebSocketConnectionState =\n WebSocketConnectionState.Disconnected;\n\n #disconnectionPromise: Promise<void> | null = null;\n\n // Callback for SDK terminate event (fired when all reconnection attempts exhausted)\n #onTerminateCallback: ((error: Error) => void) | null = null;\n\n #onReconnectCallback?: () => Promise<void>;\n\n // Reconnection attempt counter\n #reconnectionAttempt = 0;\n\n // Connection state change listeners for event-based notifications\n readonly #connectionStateListeners: Set<\n (state: WebSocketConnectionState, reconnectionAttempt: number) => void\n > = new Set();\n\n // Timeout reference for reconnection retry, tracked to enable cancellation on disconnect\n #reconnectionRetryTimeout: ReturnType<typeof setTimeout> | null = null;\n\n // Platform dependencies for logging\n readonly #deps: PerpsPlatformDependencies;\n\n constructor(\n deps: PerpsPlatformDependencies,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Initialize all HyperLiquid SDK clients\n *\n * IMPORTANT: This method awaits transport.ready() to ensure the WebSocket is\n * in OPEN state before marking initialization complete. This prevents race\n * conditions where subscriptions are attempted before the WebSocket handshake\n * completes (which would cause \"subscribe error: undefined\" errors).\n *\n * @param wallet - The wallet parameters for signing typed data.\n */\n public async initialize(wallet: HyperLiquidWalletParams): Promise<void> {\n try {\n this.#updateConnectionState(WebSocketConnectionState.Connecting);\n this.#createTransports();\n\n // Ensure transports are created\n if (!this.#httpTransport || !this.#wsTransport) {\n throw new Error('Failed to create transports');\n }\n\n // Wallet adapter implements AbstractViemJsonRpcAccount interface with signTypedData method\n // ExchangeClient uses HTTP transport for write operations (orders, approvals, etc.)\n this.#exchangeClient = new ExchangeClient({\n wallet: wallet as any, // eslint-disable-line @typescript-eslint/no-explicit-any -- Type widening for SDK compatibility\n transport: this.#httpTransport,\n });\n\n // InfoClient with WebSocket transport (default) - multiplexed requests over single connection\n this.#infoClient = new InfoClient({ transport: this.#wsTransport });\n\n // InfoClient with HTTP transport (fallback) - for specific calls if WebSocket has issues\n this.#infoClientHttp = new InfoClient({ transport: this.#httpTransport });\n\n // SubscriptionClient uses WebSocket transport for real-time pub/sub (price feeds, position updates)\n this.#subscriptionClient = new SubscriptionClient({\n transport: this.#wsTransport,\n });\n\n // Wait for WebSocket to actually be ready before setting CONNECTED\n // This ensures we have a real connection, not just client objects\n await this.#wsTransport.ready();\n\n this.#updateConnectionState(WebSocketConnectionState.Connected);\n\n this.#deps.debugLogger.log('HyperLiquid SDK clients initialized', {\n testnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n note: 'Using WebSocket for InfoClient (default), HTTP fallback available',\n });\n } catch (error) {\n // Cleanup on failure to prevent leaks and ensure isInitialized() returns false\n // Clear clients first, then transports\n this.#subscriptionClient = undefined;\n this.#infoClient = undefined;\n this.#infoClientHttp = undefined;\n this.#exchangeClient = undefined;\n\n // Close WebSocket transport to release resources and event listeners\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n } catch {\n // Ignore cleanup errors\n }\n this.#wsTransport = undefined;\n }\n this.#httpTransport = undefined;\n\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.initialize',\n );\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n // Log to Sentry: initialization failure blocks all Perps functionality\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'sdk_initialization',\n data: {\n operation: 'initialize',\n isTestnet: this.#isTestnet,\n },\n },\n });\n\n throw error;\n }\n }\n\n /**\n * Create HTTP and WebSocket transports\n * - HTTP for InfoClient and ExchangeClient (request/response operations)\n * - WebSocket for SubscriptionClient (real-time pub/sub)\n *\n * Both transports use SDK's built-in endpoint resolution via isTestnet flag\n *\n * @returns The created WebSocket transport instance.\n */\n #createTransports(): WebSocketTransport {\n // Prevent duplicate transport creation and listener accumulation\n // This guards against re-entry if initialize() is called multiple times\n // (e.g., after a failed initialization attempt that didn't properly clean up)\n if (this.#wsTransport && this.#httpTransport) {\n this.#deps.debugLogger.log(\n 'HyperLiquid: Transports already exist, skipping creation',\n );\n return this.#wsTransport;\n }\n\n this.#deps.debugLogger.log('HyperLiquid: Creating transports', {\n isTestnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n note: 'SDK will auto-select endpoints based on isTestnet flag',\n });\n\n // HTTP transport for request/response operations (InfoClient, ExchangeClient)\n // SDK automatically selects: mainnet (https://api.hyperliquid.xyz) or testnet (https://api.hyperliquid-testnet.xyz)\n this.#httpTransport = new HttpTransport({\n isTestnet: this.#isTestnet,\n timeout: HYPERLIQUID_TRANSPORT_CONFIG.timeout,\n });\n\n // WebSocket transport for real-time subscriptions (SubscriptionClient)\n // SDK automatically selects: mainnet (wss://api.hyperliquid.xyz/ws) or testnet (wss://api.hyperliquid-testnet.xyz/ws)\n this.#wsTransport = new WebSocketTransport({\n isTestnet: this.#isTestnet,\n ...HYPERLIQUID_TRANSPORT_CONFIG,\n reconnect: {\n ...HYPERLIQUID_TRANSPORT_CONFIG.reconnect,\n WebSocket: globalThis.WebSocket, // Use React Native's global WebSocket\n },\n });\n\n // Listen for WebSocket termination (fired when SDK exhausts all reconnection attempts)\n this.#wsTransport.socket.addEventListener('terminate', (event: Event) => {\n const customEvent = event as CustomEvent;\n this.#deps.debugLogger.log('HyperLiquid: WebSocket terminated', {\n reason: customEvent.detail?.code,\n timestamp: new Date().toISOString(),\n });\n\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n if (this.#onTerminateCallback) {\n const error =\n customEvent.detail instanceof Error\n ? customEvent.detail\n : new Error(\n `WebSocket terminated: ${customEvent.detail?.code ?? 'unknown'}`,\n );\n this.#onTerminateCallback(error);\n }\n });\n\n return this.#wsTransport;\n }\n\n /**\n * Toggle testnet mode and reinitialize clients\n *\n * @param wallet - The wallet parameters for signing typed data.\n * @returns The new network name after toggling.\n */\n public async toggleTestnet(\n wallet: HyperLiquidWalletParams,\n ): Promise<HyperLiquidNetwork> {\n this.#isTestnet = !this.#isTestnet;\n await this.initialize(wallet);\n return this.#isTestnet ? 'testnet' : 'mainnet';\n }\n\n /**\n * Check if clients are properly initialized\n *\n * @returns True if all SDK clients are initialized.\n */\n public isInitialized(): boolean {\n return Boolean(\n this.#exchangeClient &&\n this.#infoClient &&\n this.#infoClientHttp &&\n this.#subscriptionClient,\n );\n }\n\n /**\n * Ensure clients are initialized, throw if not\n */\n public ensureInitialized(): void {\n if (!this.isInitialized()) {\n throw new Error(PERPS_ERROR_CODES.CLIENT_NOT_INITIALIZED);\n }\n }\n\n /**\n * Recreate subscription client if needed (for reconnection scenarios)\n *\n * @param wallet - The wallet parameters for signing typed data.\n */\n public async ensureSubscriptionClient(\n wallet: HyperLiquidWalletParams,\n ): Promise<void> {\n if (!this.#subscriptionClient) {\n this.#deps.debugLogger.log(\n 'HyperLiquid: Recreating subscription client after disconnect',\n );\n await this.initialize(wallet);\n }\n }\n\n /**\n * Get the exchange client\n *\n * @returns The initialized ExchangeClient instance.\n */\n public getExchangeClient(): ExchangeClient {\n this.ensureInitialized();\n if (!this.#exchangeClient) {\n throw new Error(PERPS_ERROR_CODES.EXCHANGE_CLIENT_NOT_AVAILABLE);\n }\n return this.#exchangeClient;\n }\n\n /**\n * Get the info client\n *\n * @param options - The options for selecting the transport.\n * @param options.useHttp - Force HTTP transport instead of WebSocket (default: false).\n * @returns InfoClient instance with the selected transport.\n */\n public getInfoClient(options?: { useHttp?: boolean }): InfoClient {\n this.ensureInitialized();\n\n if (options?.useHttp) {\n if (!this.#infoClientHttp) {\n throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);\n }\n return this.#infoClientHttp;\n }\n\n if (!this.#infoClient) {\n throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);\n }\n return this.#infoClient;\n }\n\n /**\n * Get the subscription client\n *\n * @returns The SubscriptionClient instance, or undefined if not initialized.\n */\n public getSubscriptionClient():\n | SubscriptionClient<{ transport: WebSocketTransport }>\n | undefined {\n if (!this.#subscriptionClient) {\n this.#deps.debugLogger.log('SubscriptionClient not initialized');\n return undefined;\n }\n return this.#subscriptionClient;\n }\n\n /**\n * Ensures the WebSocket transport is in OPEN state and ready for subscriptions.\n * This MUST be called before any subscription operations to prevent race conditions.\n *\n * The SDK's `transport.ready()` method:\n * - Returns immediately if WebSocket is already in OPEN state\n * - Waits for the \"open\" event if WebSocket is in CONNECTING state\n * - Supports AbortSignal for timeout/cancellation\n *\n * @param options - The options for transport readiness check.\n * @param options.timeoutMs - Maximum time to wait for transport ready (default 5000ms).\n * @throws Error if transport not ready within timeout or subscription client unavailable.\n */\n public async ensureTransportReady(\n options: { timeoutMs?: number } = {},\n ): Promise<void> {\n const { timeoutMs = 5000 } = options;\n const subscriptionClient = this.getSubscriptionClient();\n if (!subscriptionClient) {\n throw new Error('Subscription client not initialized');\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () =>\n controller.abort(\n new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`),\n ),\n timeoutMs,\n );\n\n try {\n await subscriptionClient.config_.transport.ready(controller.signal);\n } catch (error) {\n if (controller.signal.aborted) {\n throw new Error(\n `WebSocket transport ready timeout after ${timeoutMs}ms`,\n );\n }\n throw ensureError(error, 'HyperLiquidClientService.ensureTransportReady');\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n /**\n * Get current network state\n *\n * @returns The current HyperLiquid network (mainnet or testnet).\n */\n public getNetwork(): HyperLiquidNetwork {\n return this.#isTestnet ? 'testnet' : 'mainnet';\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Fetch historical candle data using the HyperLiquid SDK\n *\n * @param options - The candle fetch configuration.\n * @param options.symbol - The asset symbol (e.g., \"BTC\", \"ETH\").\n * @param options.interval - The candle interval (e.g., \"1m\", \"5m\", \"15m\", \"1h\", \"1d\").\n * @param options.limit - Number of candles to fetch (default: 100).\n * @param options.endTime - End timestamp in milliseconds (default: now).\n * @returns The historical candle data, or null if no data is available.\n */\n public async fetchHistoricalCandles(options: {\n symbol: string;\n interval: ValidCandleInterval;\n limit?: number;\n endTime?: number;\n }): Promise<CandleData | null> {\n const { symbol, interval, limit = 100, endTime } = options;\n this.ensureInitialized();\n\n try {\n // Calculate start and end times based on interval and limit\n const now = endTime ?? Date.now();\n const intervalMs = this.#getIntervalMilliseconds(interval);\n const startTime = now - limit * intervalMs;\n\n // Use the SDK's InfoClient to fetch candle data\n // HyperLiquid SDK uses 'coin' terminology\n const infoClient = this.getInfoClient();\n const data = await infoClient.candleSnapshot({\n coin: symbol, // Map to HyperLiquid SDK's 'coin' parameter\n interval,\n startTime,\n endTime: now,\n });\n\n // Transform API response to match expected format\n if (Array.isArray(data) && data.length > 0) {\n const candles = data.map((candle) => ({\n time: candle.t, // open time\n open: candle.o.toString(),\n high: candle.h.toString(),\n low: candle.l.toString(),\n close: candle.c.toString(),\n volume: candle.v.toString(),\n }));\n\n return {\n symbol,\n interval,\n candles,\n };\n }\n\n return {\n symbol,\n interval,\n candles: [],\n };\n } catch (error) {\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.fetchHistoricalCandles',\n );\n\n // Log to Sentry: prevents initial chart data load\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'historical_candles_api',\n data: {\n operation: 'fetchHistoricalCandles',\n symbol,\n interval,\n limit,\n hasEndTime: endTime !== undefined,\n },\n },\n });\n\n throw error;\n }\n }\n\n /**\n * Subscribe to candle updates via WebSocket\n *\n * @param root0 - The subscription parameters.\n * @param root0.symbol - The asset symbol (e.g., \"BTC\", \"ETH\").\n * @param root0.interval - The candle interval (e.g., \"1m\", \"5m\", \"15m\").\n * @param root0.duration - Optional time duration for calculating initial fetch size.\n * @param root0.callback - Function called with updated candle data.\n * @param root0.onError - Optional function called if subscription initialization fails.\n * @returns Cleanup function to unsubscribe.\n */\n public subscribeToCandles({\n symbol,\n interval,\n duration,\n callback,\n onError,\n }: SubscribeCandlesParams): () => void {\n this.ensureInitialized();\n\n const subscriptionClient = this.getSubscriptionClient();\n if (!subscriptionClient) {\n throw new Error(PERPS_ERROR_CODES.SUBSCRIPTION_CLIENT_NOT_AVAILABLE);\n }\n\n let currentCandleData: CandleData | null = null;\n let wsUnsubscribe: (() => void) | null = null;\n let isUnsubscribed = false;\n // Store the subscription promise to enable cleanup even when pending\n // This fixes a race condition where component unmounts before subscription resolves\n let subscriptionPromise: Promise<{ unsubscribe: () => void }> | null = null;\n\n // Calculate initial fetch size dynamically based on duration and interval\n // Match main branch behavior: up to 500 candles initially\n const initialLimit = duration\n ? Math.min(calculateCandleCount(duration, interval), 500)\n : 100; // Default to 100 if no duration provided\n\n // 1. Fetch initial historical data, then subscribe to WebSocket updates\n // Using an async IIFE to avoid nested promises and callback-in-promise issues\n const initAndSubscribe = async (): Promise<void> => {\n try {\n const initialData = await this.fetchHistoricalCandles({\n symbol,\n interval,\n limit: initialLimit,\n });\n\n // Don't proceed if already unsubscribed\n if (isUnsubscribed) {\n return;\n }\n\n currentCandleData = initialData;\n if (currentCandleData) {\n callback(currentCandleData);\n }\n\n // 2. Subscribe to WebSocket for new candles\n // HyperLiquid SDK uses 'coin' terminology\n // Store the promise so cleanup can wait for it if needed\n subscriptionPromise = subscriptionClient.candle(\n { coin: symbol, interval }, // Map to HyperLiquid SDK's 'coin' parameter\n (candleEvent) => {\n // Don't process events if already unsubscribed\n if (isUnsubscribed) {\n return;\n }\n\n // Transform SDK CandleEvent to our Candle format\n const newCandle = {\n time: candleEvent.t,\n open: candleEvent.o.toString(),\n high: candleEvent.h.toString(),\n low: candleEvent.l.toString(),\n close: candleEvent.c.toString(),\n volume: candleEvent.v.toString(),\n };\n\n if (currentCandleData) {\n // Check if this is an update to the last candle or a new candle\n const { candles } = currentCandleData;\n const lastCandle = candles[candles.length - 1];\n\n if (lastCandle?.time === newCandle.time) {\n // Update existing candle (live candle update)\n // Create new array with updated last element to trigger React re-render\n currentCandleData = {\n ...currentCandleData,\n candles: [...candles.slice(0, -1), newCandle],\n };\n } else {\n // New candle (completed candle)\n // Create new array with added element to trigger React re-render\n currentCandleData = {\n ...currentCandleData,\n candles: [...candles, newCandle],\n };\n }\n } else {\n currentCandleData = {\n symbol,\n interval,\n candles: [newCandle],\n };\n }\n\n callback(currentCandleData);\n },\n );\n\n // Store cleanup function when subscription resolves\n try {\n const sub = await subscriptionPromise;\n wsUnsubscribe = (): void => sub.unsubscribe();\n // If already unsubscribed while waiting, clean up immediately\n if (isUnsubscribed) {\n wsUnsubscribe();\n wsUnsubscribe = null;\n }\n } catch (error) {\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.subscribeToCandles',\n );\n\n // Log to Sentry: WebSocket subscription failure prevents live updates\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'websocket_subscription',\n data: {\n operation: 'subscribeToCandles',\n symbol,\n interval,\n phase: 'ws_subscription',\n },\n },\n });\n\n // Notify caller of error\n onError?.(errorInstance);\n }\n } catch (error) {\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.subscribeToCandles',\n );\n\n // Log to Sentry: initial fetch failure blocks chart completely\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'initial_candles_fetch',\n data: {\n operation: 'subscribeToCandles',\n symbol,\n interval,\n phase: 'initial_fetch',\n initialLimit,\n },\n },\n });\n\n // Notify caller of error\n onError?.(errorInstance);\n }\n };\n\n // Fire-and-forget the async initialization\n initAndSubscribe().catch(() => {\n // Error already handled inside initAndSubscribe\n });\n\n // Return cleanup function\n return () => {\n isUnsubscribed = true;\n if (wsUnsubscribe) {\n // Subscription already resolved - unsubscribe directly\n wsUnsubscribe();\n wsUnsubscribe = null;\n } else if (subscriptionPromise) {\n // Subscription promise still pending - wait for it and clean up\n // This prevents WebSocket subscription leaks when component unmounts\n // before the subscription promise resolves\n subscriptionPromise\n .then((sub) => sub.unsubscribe())\n .catch(() => {\n // Ignore errors during cleanup - subscription may have failed\n });\n subscriptionPromise = null;\n }\n };\n }\n\n /**\n * Convert interval string to milliseconds\n *\n * @param interval - The candle period interval to convert.\n * @returns The interval duration in milliseconds.\n */\n #getIntervalMilliseconds(interval: CandlePeriod): number {\n const intervalMap: Record<CandlePeriod, number> = {\n [CandlePeriod.OneMinute]: 1 * 60 * 1000,\n [CandlePeriod.ThreeMinutes]: 3 * 60 * 1000,\n [CandlePeriod.FiveMinutes]: 5 * 60 * 1000,\n [CandlePeriod.FifteenMinutes]: 15 * 60 * 1000,\n [CandlePeriod.ThirtyMinutes]: 30 * 60 * 1000,\n [CandlePeriod.OneHour]: 60 * 60 * 1000,\n [CandlePeriod.TwoHours]: 2 * 60 * 60 * 1000,\n [CandlePeriod.FourHours]: 4 * 60 * 60 * 1000,\n [CandlePeriod.EightHours]: 8 * 60 * 60 * 1000,\n [CandlePeriod.TwelveHours]: 12 * 60 * 60 * 1000,\n [CandlePeriod.OneDay]: 24 * 60 * 60 * 1000,\n [CandlePeriod.ThreeDays]: 3 * 24 * 60 * 60 * 1000,\n [CandlePeriod.OneWeek]: 7 * 24 * 60 * 60 * 1000,\n [CandlePeriod.OneMonth]: 30 * 24 * 60 * 60 * 1000, // Approximate\n };\n\n return intervalMap[interval];\n }\n\n /**\n * Disconnect and cleanup all clients\n *\n * @returns A promise that resolves when disconnection is complete.\n */\n public async disconnect(): Promise<void> {\n // Await existing promise if already disconnecting\n if (this.#disconnectionPromise) {\n await this.#disconnectionPromise;\n return;\n }\n\n // If already disconnected, return immediately\n if (this.#connectionState === WebSocketConnectionState.Disconnected) {\n return;\n }\n\n // Create and store the disconnection promise\n this.#disconnectionPromise = this.#performDisconnection();\n\n try {\n await this.#disconnectionPromise;\n } finally {\n this.#disconnectionPromise = null;\n }\n }\n\n async #performDisconnection(): Promise<void> {\n try {\n this.#updateConnectionState(WebSocketConnectionState.Disconnecting);\n\n this.#deps.debugLogger.log('HyperLiquid: Disconnecting SDK clients', {\n isTestnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n });\n\n // Clear callbacks\n this.#onReconnectCallback = undefined;\n this.#onTerminateCallback = null;\n\n // Cancel any pending reconnection retry timeout\n if (this.#reconnectionRetryTimeout) {\n clearTimeout(this.#reconnectionRetryTimeout);\n this.#reconnectionRetryTimeout = null;\n }\n\n // Clear connection state listeners to prevent stale callbacks\n this.#connectionStateListeners.clear();\n\n // Reset reconnection flag to allow future manual retries\n // This prevents a race condition where disconnecting during an active\n // reconnection attempt could leave the flag stuck, blocking subsequent retries\n this.#isReconnecting = false;\n\n // Close WebSocket transport only (HTTP is stateless)\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n this.#deps.debugLogger.log(\n 'HyperLiquid: Closed WebSocket transport',\n {\n timestamp: new Date().toISOString(),\n },\n );\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'HyperLiquidClientService.performDisconnection'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'HyperLiquidClientService.performDisconnection',\n data: { action: 'close_transport' },\n },\n },\n );\n }\n }\n\n // Clear client references\n this.#subscriptionClient = undefined;\n this.#exchangeClient = undefined;\n this.#infoClient = undefined;\n this.#infoClientHttp = undefined;\n this.#wsTransport = undefined;\n this.#httpTransport = undefined;\n\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n this.#deps.debugLogger.log(\n 'HyperLiquid: SDK clients fully disconnected',\n {\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n },\n );\n } catch (error) {\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n this.#deps.logger.error(\n ensureError(error, 'HyperLiquidClientService.performDisconnection'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'HyperLiquidClientService.performDisconnection',\n data: { action: 'outer_catch' },\n },\n },\n );\n throw error;\n }\n }\n\n /**\n * Get current WebSocket connection state\n *\n * @returns The current WebSocket connection state.\n */\n public getConnectionState(): WebSocketConnectionState {\n return this.#connectionState;\n }\n\n /**\n * Check if WebSocket is fully disconnected\n *\n * @returns True if the WebSocket is in disconnected state.\n */\n public isDisconnected(): boolean {\n return this.#connectionState === WebSocketConnectionState.Disconnected;\n }\n\n /**\n * Set callback to be invoked when reconnection is needed\n * This allows the service to notify external components (like PerpsConnectionManager)\n * when a connection drop is detected\n *\n * @param callback - The async callback to invoke when reconnection is needed.\n */\n public setOnReconnectCallback(callback: () => Promise<void>): void {\n this.#onReconnectCallback = callback;\n }\n\n /**\n * Set callback for WebSocket termination events\n * Called when the SDK exhausts all reconnection attempts\n *\n * @param callback - The callback to invoke on termination, or null to clear.\n */\n public setOnTerminateCallback(\n callback: ((error: Error) => void) | null,\n ): void {\n this.#onTerminateCallback = callback;\n }\n\n /**\n * Subscribe to connection state changes.\n * The listener will be called immediately with the current state and whenever the state changes.\n *\n * @param listener - Callback function that receives the new connection state and reconnection attempt\n * @returns Unsubscribe function to remove the listener\n */\n public subscribeToConnectionState(\n listener: (\n state: WebSocketConnectionState,\n reconnectionAttempt: number,\n ) => void,\n ): () => void {\n this.#connectionStateListeners.add(listener);\n\n // Immediately notify with current state\n // Wrap in try-catch to match notifyConnectionStateListeners behavior\n // This ensures the unsubscribe function is always returned even if listener throws\n try {\n listener(this.#connectionState, this.#reconnectionAttempt);\n } catch {\n // Ignore errors in listeners to prevent breaking subscription mechanism\n // If listener throws, it will be removed when unsubscribe is called\n }\n\n // Return unsubscribe function\n return () => {\n this.#connectionStateListeners.delete(listener);\n };\n }\n\n /**\n * Update connection state and notify all listeners\n * Always notifies if state changes OR if we're in CONNECTING state (to update attempt count)\n *\n * @param newState - The new WebSocket connection state.\n */\n #updateConnectionState(newState: WebSocketConnectionState): void {\n const previousState = this.#connectionState;\n const stateChanged = previousState !== newState;\n const isReconnectionAttempt =\n newState === WebSocketConnectionState.Connecting &&\n this.#reconnectionAttempt > 0;\n\n this.#connectionState = newState;\n\n // Reset reconnection attempt counter when successfully connected\n if (newState === WebSocketConnectionState.Connected) {\n this.#reconnectionAttempt = 0;\n }\n\n // Notify if state changed OR if this is a reconnection attempt (to update attempt count)\n if (stateChanged || isReconnectionAttempt) {\n this.#notifyConnectionStateListeners();\n }\n }\n\n /**\n * Notify all connection state listeners of the current state\n */\n #notifyConnectionStateListeners(): void {\n this.#connectionStateListeners.forEach((listener) => {\n try {\n listener(this.#connectionState, this.#reconnectionAttempt);\n } catch {\n // Ignore errors in listeners to prevent breaking other listeners\n }\n });\n }\n\n // Flag to prevent concurrent reconnection attempts\n #isReconnecting = false;\n\n /**\n * Manually trigger a reconnection attempt.\n * This is exposed for UI retry buttons when user wants to force reconnection.\n * Resets the reconnection attempt counter to allow retrying after max attempts.\n */\n public async reconnect(): Promise<void> {\n this.#deps.debugLogger.log(\n '[HyperLiquidClientService] reconnect() called',\n {\n previousAttempt: this.#reconnectionAttempt,\n currentState: this.#connectionState,\n },\n );\n // Reset attempt counter when user manually triggers retry\n this.#reconnectionAttempt = 0;\n await this.#handleConnectionDrop();\n this.#deps.debugLogger.log(\n '[HyperLiquidClientService] reconnect() completed',\n {\n newState: this.#connectionState,\n },\n );\n }\n\n /**\n * Handle detected connection drop\n * Recreates WebSocket transport and notifies callback to restore subscriptions\n * Will give up after maxReconnectionAttempts and mark status as disconnected\n */\n async #handleConnectionDrop(): Promise<void> {\n // Prevent multiple simultaneous reconnection attempts\n if (this.#isReconnecting) {\n return;\n }\n\n this.#isReconnecting = true;\n\n // Increment reconnection attempt counter\n this.#reconnectionAttempt += 1;\n\n // Check if we've exceeded max retry attempts\n if (this.#reconnectionAttempt > maxReconnectionAttempts) {\n this.#isReconnecting = false;\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n return;\n }\n\n try {\n this.#updateConnectionState(WebSocketConnectionState.Connecting);\n\n // Close existing WebSocket transport and clear references\n // so createTransports() will create fresh ones\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n } catch {\n // Ignore errors during close - transport may already be dead\n }\n }\n this.#wsTransport = undefined;\n this.#httpTransport = undefined;\n\n // Recreate WebSocket transport - returns the new transport for type safety\n const newWsTransport = this.#createTransports();\n\n // Recreate clients that use WebSocket transport\n this.#infoClient = new InfoClient({ transport: newWsTransport });\n this.#subscriptionClient = new SubscriptionClient({\n transport: newWsTransport,\n });\n\n await newWsTransport.ready();\n\n this.#deps.debugLogger.log(\n 'HyperLiquid: Transport ready, restoring subscriptions',\n { timestamp: new Date().toISOString() },\n );\n\n // NOW safe to restore subscriptions\n if (this.#onReconnectCallback) {\n await this.#onReconnectCallback();\n }\n\n // Cancel any pending retry timeout from previous failed attempts\n if (this.#reconnectionRetryTimeout) {\n clearTimeout(this.#reconnectionRetryTimeout);\n this.#reconnectionRetryTimeout = null;\n }\n\n this.#updateConnectionState(WebSocketConnectionState.Connected);\n this.#isReconnecting = false;\n } catch {\n // Reset flag before scheduling retry so the next attempt can proceed\n this.#isReconnecting = false;\n\n // Check if we've exceeded max retry attempts\n if (this.#reconnectionAttempt >= maxReconnectionAttempts) {\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n return;\n }\n\n // Reconnection failed - schedule a retry after a delay\n // Store timeout reference so it can be cancelled on intentional disconnect\n this.#reconnectionRetryTimeout = setTimeout(() => {\n this.#reconnectionRetryTimeout = null; // Clear reference after execution\n // Only retry if we haven't been intentionally disconnected\n // and no manual reconnect() is already in progress\n // Note: State may be CONNECTING or DISCONNECTED (if terminate event fired during reconnect)\n if (\n (this.#connectionState === WebSocketConnectionState.Connecting ||\n this.#connectionState === WebSocketConnectionState.Disconnected) &&\n !this.#disconnectionPromise &&\n !this.#isReconnecting\n ) {\n this.#handleConnectionDrop().catch(() => {\n // Error already handled inside #handleConnectionDrop\n });\n }\n }, PERPS_CONSTANTS.ReconnectionRetryDelayMs);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HyperLiquidClientService.cjs","sourceRoot":"","sources":["../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CAAC,CAAC;YACL,CAAC;QACH,CAAC,EAAE,6BAAe,CAAC,wBAAwB,CAAC,MAAA,CAAC;IAC/C,CAAC;AACH,CAAC","sourcesContent":["import { Hex } from '@metamask/utils';\nimport {\n ExchangeClient,\n HttpTransport,\n InfoClient,\n SubscriptionClient,\n WebSocketTransport,\n} from '@nktkas/hyperliquid';\n\nimport { CandlePeriod, calculateCandleCount } from '../constants/chartConfig';\nimport { HYPERLIQUID_TRANSPORT_CONFIG } from '../constants/hyperLiquidConfig';\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport { WebSocketConnectionState } from '../types';\nimport type {\n SubscribeCandlesParams,\n PerpsPlatformDependencies,\n} from '../types';\nimport type { HyperLiquidNetwork } from '../types/config';\nimport type { CandleData } from '../types/perps-types';\nimport { ensureError } from '../utils/errorUtils';\nimport { getPerpsConnectionAttemptContext } from '../utils/perpsConnectionAttemptContext';\n\n/**\n * Maximum number of reconnection attempts before giving up.\n */\nconst maxReconnectionAttempts = 10;\n\n/**\n * Valid time intervals for historical candle data\n * Uses CandlePeriod enum for type safety\n */\nexport type ValidCandleInterval = CandlePeriod;\n\n/**\n * Wallet interface for HyperLiquid SDK operations.\n * Extracted for reuse across initialize(), toggleTestnet(), and ensureSubscriptionClient() methods.\n */\nexport type HyperLiquidWalletParams = {\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n};\n\n// WebSocketConnectionState is now imported from controllers/types\n// Re-export for backward compatibility with existing consumers\nexport { WebSocketConnectionState } from '../types';\n\n/**\n * Service for managing HyperLiquid SDK clients\n * Handles initialization, transport creation, and client lifecycle\n */\nexport class HyperLiquidClientService {\n #exchangeClient?: ExchangeClient;\n\n #infoClient?: InfoClient; // WebSocket transport (default)\n\n #infoClientHttp?: InfoClient; // HTTP transport (fallback)\n\n #subscriptionClient?: SubscriptionClient<{\n transport: WebSocketTransport;\n }>;\n\n #wsTransport?: WebSocketTransport;\n\n #httpTransport?: HttpTransport;\n\n #isTestnet: boolean;\n\n #connectionState: WebSocketConnectionState =\n WebSocketConnectionState.Disconnected;\n\n #disconnectionPromise: Promise<void> | null = null;\n\n // Callback for SDK terminate event (fired when all reconnection attempts exhausted)\n #onTerminateCallback: ((error: Error) => void) | null = null;\n\n #onReconnectCallback?: () => Promise<void>;\n\n // Reconnection attempt counter\n #reconnectionAttempt = 0;\n\n // Connection state change listeners for event-based notifications\n readonly #connectionStateListeners: Set<\n (state: WebSocketConnectionState, reconnectionAttempt: number) => void\n > = new Set();\n\n // Timeout reference for reconnection retry, tracked to enable cancellation on disconnect\n #reconnectionRetryTimeout: ReturnType<typeof setTimeout> | null = null;\n\n // Platform dependencies for logging\n readonly #deps: PerpsPlatformDependencies;\n\n constructor(\n deps: PerpsPlatformDependencies,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Initialize all HyperLiquid SDK clients\n *\n * IMPORTANT: This method awaits transport.ready() to ensure the WebSocket is\n * in OPEN state before marking initialization complete. This prevents race\n * conditions where subscriptions are attempted before the WebSocket handshake\n * completes (which would cause \"subscribe error: undefined\" errors).\n *\n * @param wallet - The wallet parameters for signing typed data.\n */\n public async initialize(wallet: HyperLiquidWalletParams): Promise<void> {\n const network = this.#isTestnet ? 'testnet' : 'mainnet';\n const attemptContext = getPerpsConnectionAttemptContext();\n\n try {\n this.#updateConnectionState(WebSocketConnectionState.Connecting);\n this.#createTransports();\n\n // Ensure transports are created\n if (!this.#httpTransport || !this.#wsTransport) {\n throw new Error('Failed to create transports');\n }\n\n // Wallet adapter implements AbstractViemJsonRpcAccount interface with signTypedData method\n // ExchangeClient uses HTTP transport for write operations (orders, approvals, etc.)\n this.#exchangeClient = new ExchangeClient({\n wallet: wallet as any, // eslint-disable-line @typescript-eslint/no-explicit-any -- Type widening for SDK compatibility\n transport: this.#httpTransport,\n });\n\n // InfoClient with WebSocket transport (default) - multiplexed requests over single connection\n this.#infoClient = new InfoClient({ transport: this.#wsTransport });\n\n // InfoClient with HTTP transport (fallback) - for specific calls if WebSocket has issues\n this.#infoClientHttp = new InfoClient({ transport: this.#httpTransport });\n\n // SubscriptionClient uses WebSocket transport for real-time pub/sub (price feeds, position updates)\n this.#subscriptionClient = new SubscriptionClient({\n transport: this.#wsTransport,\n });\n\n // Wait for WebSocket to actually be ready before setting CONNECTED\n // This ensures we have a real connection, not just client objects\n await this.#wsTransport.ready();\n\n this.#updateConnectionState(WebSocketConnectionState.Connected);\n\n this.#deps.debugLogger.log('HyperLiquid SDK clients initialized', {\n testnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n note: 'Using WebSocket for InfoClient (default), HTTP fallback available',\n });\n } catch (error) {\n // Cleanup on failure to prevent leaks and ensure isInitialized() returns false\n // Clear clients first, then transports\n this.#subscriptionClient = undefined;\n this.#infoClient = undefined;\n this.#infoClientHttp = undefined;\n this.#exchangeClient = undefined;\n\n // Close WebSocket transport to release resources and event listeners\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n } catch {\n // Ignore cleanup errors\n }\n this.#wsTransport = undefined;\n }\n this.#httpTransport = undefined;\n\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.initialize',\n );\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n if (attemptContext?.suppressError) {\n this.#deps.debugLogger.log(\n 'HyperLiquid initialize failed during suppressed startup attempt',\n {\n error: errorInstance.message,\n network,\n source: attemptContext.source,\n },\n );\n } else {\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network,\n },\n context: {\n name: 'sdk_initialization',\n data: {\n operation: 'initialize',\n isTestnet: this.#isTestnet,\n source: attemptContext?.source ?? 'unspecified',\n },\n },\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Create HTTP and WebSocket transports\n * - HTTP for InfoClient and ExchangeClient (request/response operations)\n * - WebSocket for SubscriptionClient (real-time pub/sub)\n *\n * Both transports use SDK's built-in endpoint resolution via isTestnet flag\n *\n * @returns The created WebSocket transport instance.\n */\n #createTransports(): WebSocketTransport {\n // Prevent duplicate transport creation and listener accumulation\n // This guards against re-entry if initialize() is called multiple times\n // (e.g., after a failed initialization attempt that didn't properly clean up)\n if (this.#wsTransport && this.#httpTransport) {\n this.#deps.debugLogger.log(\n 'HyperLiquid: Transports already exist, skipping creation',\n );\n return this.#wsTransport;\n }\n\n this.#deps.debugLogger.log('HyperLiquid: Creating transports', {\n isTestnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n note: 'SDK will auto-select endpoints based on isTestnet flag',\n });\n\n // HTTP transport for request/response operations (InfoClient, ExchangeClient)\n // SDK automatically selects: mainnet (https://api.hyperliquid.xyz) or testnet (https://api.hyperliquid-testnet.xyz)\n this.#httpTransport = new HttpTransport({\n isTestnet: this.#isTestnet,\n timeout: HYPERLIQUID_TRANSPORT_CONFIG.timeout,\n });\n\n // WebSocket transport for real-time subscriptions (SubscriptionClient)\n // SDK automatically selects: mainnet (wss://api.hyperliquid.xyz/ws) or testnet (wss://api.hyperliquid-testnet.xyz/ws)\n this.#wsTransport = new WebSocketTransport({\n isTestnet: this.#isTestnet,\n ...HYPERLIQUID_TRANSPORT_CONFIG,\n reconnect: {\n ...HYPERLIQUID_TRANSPORT_CONFIG.reconnect,\n WebSocket: globalThis.WebSocket, // Use React Native's global WebSocket\n },\n });\n\n // Listen for WebSocket termination (fired when SDK exhausts all reconnection attempts)\n this.#wsTransport.socket.addEventListener('terminate', (event: Event) => {\n const customEvent = event as CustomEvent;\n this.#deps.debugLogger.log('HyperLiquid: WebSocket terminated', {\n reason: customEvent.detail?.code,\n timestamp: new Date().toISOString(),\n });\n\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n if (this.#onTerminateCallback) {\n const error =\n customEvent.detail instanceof Error\n ? customEvent.detail\n : new Error(\n `WebSocket terminated: ${customEvent.detail?.code ?? 'unknown'}`,\n );\n this.#onTerminateCallback(error);\n }\n });\n\n return this.#wsTransport;\n }\n\n /**\n * Toggle testnet mode and reinitialize clients\n *\n * @param wallet - The wallet parameters for signing typed data.\n * @returns The new network name after toggling.\n */\n public async toggleTestnet(\n wallet: HyperLiquidWalletParams,\n ): Promise<HyperLiquidNetwork> {\n this.#isTestnet = !this.#isTestnet;\n await this.initialize(wallet);\n return this.#isTestnet ? 'testnet' : 'mainnet';\n }\n\n /**\n * Check if clients are properly initialized\n *\n * @returns True if all SDK clients are initialized.\n */\n public isInitialized(): boolean {\n return Boolean(\n this.#exchangeClient &&\n this.#infoClient &&\n this.#infoClientHttp &&\n this.#subscriptionClient,\n );\n }\n\n /**\n * Ensure clients are initialized, throw if not\n */\n public ensureInitialized(): void {\n if (!this.isInitialized()) {\n throw new Error(PERPS_ERROR_CODES.CLIENT_NOT_INITIALIZED);\n }\n }\n\n /**\n * Recreate subscription client if needed (for reconnection scenarios)\n *\n * @param wallet - The wallet parameters for signing typed data.\n */\n public async ensureSubscriptionClient(\n wallet: HyperLiquidWalletParams,\n ): Promise<void> {\n if (!this.#subscriptionClient) {\n this.#deps.debugLogger.log(\n 'HyperLiquid: Recreating subscription client after disconnect',\n );\n await this.initialize(wallet);\n }\n }\n\n /**\n * Get the exchange client\n *\n * @returns The initialized ExchangeClient instance.\n */\n public getExchangeClient(): ExchangeClient {\n this.ensureInitialized();\n if (!this.#exchangeClient) {\n throw new Error(PERPS_ERROR_CODES.EXCHANGE_CLIENT_NOT_AVAILABLE);\n }\n return this.#exchangeClient;\n }\n\n /**\n * Get the info client\n *\n * @param options - The options for selecting the transport.\n * @param options.useHttp - Force HTTP transport instead of WebSocket (default: false).\n * @returns InfoClient instance with the selected transport.\n */\n public getInfoClient(options?: { useHttp?: boolean }): InfoClient {\n this.ensureInitialized();\n\n if (options?.useHttp) {\n if (!this.#infoClientHttp) {\n throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);\n }\n return this.#infoClientHttp;\n }\n\n if (!this.#infoClient) {\n throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);\n }\n return this.#infoClient;\n }\n\n /**\n * Get the subscription client\n *\n * @returns The SubscriptionClient instance, or undefined if not initialized.\n */\n public getSubscriptionClient():\n | SubscriptionClient<{ transport: WebSocketTransport }>\n | undefined {\n if (!this.#subscriptionClient) {\n this.#deps.debugLogger.log('SubscriptionClient not initialized');\n return undefined;\n }\n return this.#subscriptionClient;\n }\n\n /**\n * Ensures the WebSocket transport is in OPEN state and ready for subscriptions.\n * This MUST be called before any subscription operations to prevent race conditions.\n *\n * The SDK's `transport.ready()` method:\n * - Returns immediately if WebSocket is already in OPEN state\n * - Waits for the \"open\" event if WebSocket is in CONNECTING state\n * - Supports AbortSignal for timeout/cancellation\n *\n * @param options - The options for transport readiness check.\n * @param options.timeoutMs - Maximum time to wait for transport ready (default 5000ms).\n * @throws Error if transport not ready within timeout or subscription client unavailable.\n */\n public async ensureTransportReady(\n options: { timeoutMs?: number } = {},\n ): Promise<void> {\n const { timeoutMs = 5000 } = options;\n const subscriptionClient = this.getSubscriptionClient();\n if (!subscriptionClient) {\n throw new Error('Subscription client not initialized');\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () =>\n controller.abort(\n new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`),\n ),\n timeoutMs,\n );\n\n try {\n await subscriptionClient.config_.transport.ready(controller.signal);\n } catch (error) {\n if (controller.signal.aborted) {\n throw new Error(\n `WebSocket transport ready timeout after ${timeoutMs}ms`,\n );\n }\n throw ensureError(error, 'HyperLiquidClientService.ensureTransportReady');\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n /**\n * Get current network state\n *\n * @returns The current HyperLiquid network (mainnet or testnet).\n */\n public getNetwork(): HyperLiquidNetwork {\n return this.#isTestnet ? 'testnet' : 'mainnet';\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Fetch historical candle data using the HyperLiquid SDK\n *\n * @param options - The candle fetch configuration.\n * @param options.symbol - The asset symbol (e.g., \"BTC\", \"ETH\").\n * @param options.interval - The candle interval (e.g., \"1m\", \"5m\", \"15m\", \"1h\", \"1d\").\n * @param options.limit - Number of candles to fetch (default: 100).\n * @param options.endTime - End timestamp in milliseconds (default: now).\n * @param options.signal - Optional AbortSignal to cancel the fetch.\n * @returns The historical candle data, or null if no data is available.\n */\n public async fetchHistoricalCandles(options: {\n symbol: string;\n interval: ValidCandleInterval;\n limit?: number;\n endTime?: number;\n signal?: AbortSignal;\n }): Promise<CandleData | null> {\n const { symbol, interval, limit = 100, endTime, signal } = options;\n this.ensureInitialized();\n\n try {\n // Calculate start and end times based on interval and limit\n const now = endTime ?? Date.now();\n const intervalMs = this.#getIntervalMilliseconds(interval);\n const startTime = now - limit * intervalMs;\n\n // Use the SDK's InfoClient to fetch candle data\n // HyperLiquid SDK uses 'coin' terminology\n const infoClient = this.getInfoClient();\n const data = await infoClient.candleSnapshot(\n {\n coin: symbol, // Map to HyperLiquid SDK's 'coin' parameter\n interval,\n startTime,\n endTime: now,\n },\n signal,\n );\n\n // Transform API response to match expected format\n if (Array.isArray(data) && data.length > 0) {\n const candles = data.map((candle) => ({\n time: candle.t, // open time\n open: candle.o.toString(),\n high: candle.h.toString(),\n low: candle.l.toString(),\n close: candle.c.toString(),\n volume: candle.v.toString(),\n }));\n\n return {\n symbol,\n interval,\n candles,\n };\n }\n\n return {\n symbol,\n interval,\n candles: [],\n };\n } catch (error) {\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.fetchHistoricalCandles',\n );\n\n // Log to Sentry: prevents initial chart data load\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'historical_candles_api',\n data: {\n operation: 'fetchHistoricalCandles',\n symbol,\n interval,\n limit,\n hasEndTime: endTime !== undefined,\n },\n },\n });\n\n throw error;\n }\n }\n\n /**\n * Subscribe to candle updates via WebSocket\n *\n * @param root0 - The subscription parameters.\n * @param root0.symbol - The asset symbol (e.g., \"BTC\", \"ETH\").\n * @param root0.interval - The candle interval (e.g., \"1m\", \"5m\", \"15m\").\n * @param root0.duration - Optional time duration for calculating initial fetch size.\n * @param root0.callback - Function called with updated candle data.\n * @param root0.onError - Optional function called if subscription initialization fails.\n * @returns Cleanup function to unsubscribe.\n */\n public subscribeToCandles({\n symbol,\n interval,\n duration,\n callback,\n onError,\n }: SubscribeCandlesParams): () => void {\n this.ensureInitialized();\n\n const subscriptionClient = this.getSubscriptionClient();\n if (!subscriptionClient) {\n throw new Error(PERPS_ERROR_CODES.SUBSCRIPTION_CLIENT_NOT_AVAILABLE);\n }\n\n let currentCandleData: CandleData | null = null;\n let wsUnsubscribe: (() => void) | null = null;\n let isUnsubscribed = false;\n // Store the subscription promise to enable cleanup even when pending\n // This fixes a race condition where component unmounts before subscription resolves\n let subscriptionPromise: Promise<{ unsubscribe: () => void }> | null = null;\n\n // AbortController to cancel in-flight REST calls (candleSnapshot) on cleanup.\n // Prevents rate limit exhaustion when rapidly switching markets (#28141).\n const abortController = new AbortController();\n\n // Calculate initial fetch size dynamically based on duration and interval\n // Match main branch behavior: up to 500 candles initially\n const initialLimit = duration\n ? Math.min(calculateCandleCount(duration, interval), 500)\n : 100; // Default to 100 if no duration provided\n\n // 1. Fetch initial historical data, then subscribe to WebSocket updates\n // Using an async IIFE to avoid nested promises and callback-in-promise issues\n const initAndSubscribe = async (): Promise<void> => {\n try {\n const initialData = await this.fetchHistoricalCandles({\n symbol,\n interval,\n limit: initialLimit,\n signal: abortController.signal,\n });\n\n // Don't proceed if already unsubscribed\n if (isUnsubscribed) {\n return;\n }\n\n currentCandleData = initialData;\n if (currentCandleData) {\n callback(currentCandleData);\n }\n\n // 2. Subscribe to WebSocket for new candles\n // HyperLiquid SDK uses 'coin' terminology\n // Store the promise so cleanup can wait for it if needed\n subscriptionPromise = subscriptionClient.candle(\n { coin: symbol, interval }, // Map to HyperLiquid SDK's 'coin' parameter\n (candleEvent) => {\n // Don't process events if already unsubscribed\n if (isUnsubscribed) {\n return;\n }\n\n // Transform SDK CandleEvent to our Candle format\n const newCandle = {\n time: candleEvent.t,\n open: candleEvent.o.toString(),\n high: candleEvent.h.toString(),\n low: candleEvent.l.toString(),\n close: candleEvent.c.toString(),\n volume: candleEvent.v.toString(),\n };\n\n if (currentCandleData) {\n // Check if this is an update to the last candle or a new candle\n const { candles } = currentCandleData;\n const lastCandle = candles[candles.length - 1];\n\n if (lastCandle?.time === newCandle.time) {\n // Update existing candle (live candle update)\n // Create new array with updated last element to trigger React re-render\n currentCandleData = {\n ...currentCandleData,\n candles: [...candles.slice(0, -1), newCandle],\n };\n } else {\n // New candle (completed candle)\n // Create new array with added element to trigger React re-render\n currentCandleData = {\n ...currentCandleData,\n candles: [...candles, newCandle],\n };\n }\n } else {\n currentCandleData = {\n symbol,\n interval,\n candles: [newCandle],\n };\n }\n\n callback(currentCandleData);\n },\n );\n\n // Store cleanup function when subscription resolves\n try {\n const sub = await subscriptionPromise;\n wsUnsubscribe = (): void => sub.unsubscribe();\n // If already unsubscribed while waiting, clean up immediately\n if (isUnsubscribed) {\n wsUnsubscribe();\n wsUnsubscribe = null;\n }\n } catch (error) {\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.subscribeToCandles',\n );\n\n // Log to Sentry: WebSocket subscription failure prevents live updates\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'websocket_subscription',\n data: {\n operation: 'subscribeToCandles',\n symbol,\n interval,\n phase: 'ws_subscription',\n },\n },\n });\n\n // Notify caller of error\n onError?.(errorInstance);\n }\n } catch (error) {\n // Skip logging and notification for intentional abort (user navigated away)\n if (abortController.signal.aborted) {\n return;\n }\n\n const errorInstance = ensureError(\n error,\n 'HyperLiquidClientService.subscribeToCandles',\n );\n\n // Log to Sentry: initial fetch failure blocks chart completely\n this.#deps.logger.error(errorInstance, {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'HyperLiquidClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: 'initial_candles_fetch',\n data: {\n operation: 'subscribeToCandles',\n symbol,\n interval,\n phase: 'initial_fetch',\n initialLimit,\n },\n },\n });\n\n // Notify caller of error\n onError?.(errorInstance);\n }\n };\n\n // Fire-and-forget the async initialization\n initAndSubscribe().catch(() => {\n // Error already handled inside initAndSubscribe\n });\n\n // Return cleanup function\n return () => {\n isUnsubscribed = true;\n // Cancel any in-flight REST calls (candleSnapshot) to conserve rate limit budget (#28141)\n abortController.abort();\n if (wsUnsubscribe) {\n // Subscription already resolved - unsubscribe directly\n wsUnsubscribe();\n wsUnsubscribe = null;\n } else if (subscriptionPromise) {\n // Subscription promise still pending - wait for it and clean up\n // This prevents WebSocket subscription leaks when component unmounts\n // before the subscription promise resolves\n subscriptionPromise\n .then((sub) => sub.unsubscribe())\n .catch(() => {\n // Ignore errors during cleanup - subscription may have failed\n });\n subscriptionPromise = null;\n }\n };\n }\n\n /**\n * Convert interval string to milliseconds\n *\n * @param interval - The candle period interval to convert.\n * @returns The interval duration in milliseconds.\n */\n #getIntervalMilliseconds(interval: CandlePeriod): number {\n const intervalMap: Record<CandlePeriod, number> = {\n [CandlePeriod.OneMinute]: 1 * 60 * 1000,\n [CandlePeriod.ThreeMinutes]: 3 * 60 * 1000,\n [CandlePeriod.FiveMinutes]: 5 * 60 * 1000,\n [CandlePeriod.FifteenMinutes]: 15 * 60 * 1000,\n [CandlePeriod.ThirtyMinutes]: 30 * 60 * 1000,\n [CandlePeriod.OneHour]: 60 * 60 * 1000,\n [CandlePeriod.TwoHours]: 2 * 60 * 60 * 1000,\n [CandlePeriod.FourHours]: 4 * 60 * 60 * 1000,\n [CandlePeriod.EightHours]: 8 * 60 * 60 * 1000,\n [CandlePeriod.TwelveHours]: 12 * 60 * 60 * 1000,\n [CandlePeriod.OneDay]: 24 * 60 * 60 * 1000,\n [CandlePeriod.ThreeDays]: 3 * 24 * 60 * 60 * 1000,\n [CandlePeriod.OneWeek]: 7 * 24 * 60 * 60 * 1000,\n [CandlePeriod.OneMonth]: 30 * 24 * 60 * 60 * 1000, // Approximate\n };\n\n return intervalMap[interval];\n }\n\n /**\n * Disconnect and cleanup all clients\n *\n * @returns A promise that resolves when disconnection is complete.\n */\n public async disconnect(): Promise<void> {\n // Await existing promise if already disconnecting\n if (this.#disconnectionPromise) {\n await this.#disconnectionPromise;\n return;\n }\n\n // If already disconnected, return immediately\n if (this.#connectionState === WebSocketConnectionState.Disconnected) {\n return;\n }\n\n // Create and store the disconnection promise\n this.#disconnectionPromise = this.#performDisconnection();\n\n try {\n await this.#disconnectionPromise;\n } finally {\n this.#disconnectionPromise = null;\n }\n }\n\n async #performDisconnection(): Promise<void> {\n try {\n this.#updateConnectionState(WebSocketConnectionState.Disconnecting);\n\n this.#deps.debugLogger.log('HyperLiquid: Disconnecting SDK clients', {\n isTestnet: this.#isTestnet,\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n });\n\n // Clear callbacks\n this.#onReconnectCallback = undefined;\n this.#onTerminateCallback = null;\n\n // Cancel any pending reconnection retry timeout\n if (this.#reconnectionRetryTimeout) {\n clearTimeout(this.#reconnectionRetryTimeout);\n this.#reconnectionRetryTimeout = null;\n }\n\n // Clear connection state listeners to prevent stale callbacks\n this.#connectionStateListeners.clear();\n\n // Reset reconnection flag to allow future manual retries\n // This prevents a race condition where disconnecting during an active\n // reconnection attempt could leave the flag stuck, blocking subsequent retries\n this.#isReconnecting = false;\n\n // Close WebSocket transport only (HTTP is stateless)\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n this.#deps.debugLogger.log(\n 'HyperLiquid: Closed WebSocket transport',\n {\n timestamp: new Date().toISOString(),\n },\n );\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'HyperLiquidClientService.performDisconnection'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'HyperLiquidClientService.performDisconnection',\n data: { action: 'close_transport' },\n },\n },\n );\n }\n }\n\n // Clear client references\n this.#subscriptionClient = undefined;\n this.#exchangeClient = undefined;\n this.#infoClient = undefined;\n this.#infoClientHttp = undefined;\n this.#wsTransport = undefined;\n this.#httpTransport = undefined;\n\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n\n this.#deps.debugLogger.log(\n 'HyperLiquid: SDK clients fully disconnected',\n {\n timestamp: new Date().toISOString(),\n connectionState: this.#connectionState,\n },\n );\n } catch (error) {\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n this.#deps.logger.error(\n ensureError(error, 'HyperLiquidClientService.performDisconnection'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'HyperLiquidClientService.performDisconnection',\n data: { action: 'outer_catch' },\n },\n },\n );\n throw error;\n }\n }\n\n /**\n * Get current WebSocket connection state\n *\n * @returns The current WebSocket connection state.\n */\n public getConnectionState(): WebSocketConnectionState {\n return this.#connectionState;\n }\n\n /**\n * Check if WebSocket is fully disconnected\n *\n * @returns True if the WebSocket is in disconnected state.\n */\n public isDisconnected(): boolean {\n return this.#connectionState === WebSocketConnectionState.Disconnected;\n }\n\n /**\n * Set callback to be invoked when reconnection is needed\n * This allows the service to notify external components (like PerpsConnectionManager)\n * when a connection drop is detected\n *\n * @param callback - The async callback to invoke when reconnection is needed.\n */\n public setOnReconnectCallback(callback: () => Promise<void>): void {\n this.#onReconnectCallback = callback;\n }\n\n /**\n * Set callback for WebSocket termination events\n * Called when the SDK exhausts all reconnection attempts\n *\n * @param callback - The callback to invoke on termination, or null to clear.\n */\n public setOnTerminateCallback(\n callback: ((error: Error) => void) | null,\n ): void {\n this.#onTerminateCallback = callback;\n }\n\n /**\n * Subscribe to connection state changes.\n * The listener will be called immediately with the current state and whenever the state changes.\n *\n * @param listener - Callback function that receives the new connection state and reconnection attempt\n * @returns Unsubscribe function to remove the listener\n */\n public subscribeToConnectionState(\n listener: (\n state: WebSocketConnectionState,\n reconnectionAttempt: number,\n ) => void,\n ): () => void {\n this.#connectionStateListeners.add(listener);\n\n // Immediately notify with current state\n // Wrap in try-catch to match notifyConnectionStateListeners behavior\n // This ensures the unsubscribe function is always returned even if listener throws\n try {\n listener(this.#connectionState, this.#reconnectionAttempt);\n } catch {\n // Ignore errors in listeners to prevent breaking subscription mechanism\n // If listener throws, it will be removed when unsubscribe is called\n }\n\n // Return unsubscribe function\n return () => {\n this.#connectionStateListeners.delete(listener);\n };\n }\n\n /**\n * Update connection state and notify all listeners\n * Always notifies if state changes OR if we're in CONNECTING state (to update attempt count)\n *\n * @param newState - The new WebSocket connection state.\n */\n #updateConnectionState(newState: WebSocketConnectionState): void {\n const previousState = this.#connectionState;\n const stateChanged = previousState !== newState;\n const isReconnectionAttempt =\n newState === WebSocketConnectionState.Connecting &&\n this.#reconnectionAttempt > 0;\n\n this.#connectionState = newState;\n\n // Reset reconnection attempt counter when successfully connected\n if (newState === WebSocketConnectionState.Connected) {\n this.#reconnectionAttempt = 0;\n }\n\n // Notify if state changed OR if this is a reconnection attempt (to update attempt count)\n if (stateChanged || isReconnectionAttempt) {\n this.#notifyConnectionStateListeners();\n }\n }\n\n /**\n * Notify all connection state listeners of the current state\n */\n #notifyConnectionStateListeners(): void {\n this.#connectionStateListeners.forEach((listener) => {\n try {\n listener(this.#connectionState, this.#reconnectionAttempt);\n } catch {\n // Ignore errors in listeners to prevent breaking other listeners\n }\n });\n }\n\n // Flag to prevent concurrent reconnection attempts\n #isReconnecting = false;\n\n /**\n * Manually trigger a reconnection attempt.\n * This is exposed for UI retry buttons when user wants to force reconnection.\n * Resets the reconnection attempt counter to allow retrying after max attempts.\n */\n public async reconnect(): Promise<void> {\n this.#deps.debugLogger.log(\n '[HyperLiquidClientService] reconnect() called',\n {\n previousAttempt: this.#reconnectionAttempt,\n currentState: this.#connectionState,\n },\n );\n // Reset attempt counter when user manually triggers retry\n this.#reconnectionAttempt = 0;\n await this.#handleConnectionDrop();\n this.#deps.debugLogger.log(\n '[HyperLiquidClientService] reconnect() completed',\n {\n newState: this.#connectionState,\n },\n );\n }\n\n /**\n * Handle detected connection drop\n * Recreates WebSocket transport and notifies callback to restore subscriptions\n * Will give up after maxReconnectionAttempts and mark status as disconnected\n */\n async #handleConnectionDrop(): Promise<void> {\n // Prevent multiple simultaneous reconnection attempts\n if (this.#isReconnecting) {\n return;\n }\n\n this.#isReconnecting = true;\n\n // Increment reconnection attempt counter\n this.#reconnectionAttempt += 1;\n\n // Check if we've exceeded max retry attempts\n if (this.#reconnectionAttempt > maxReconnectionAttempts) {\n this.#isReconnecting = false;\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n return;\n }\n\n try {\n this.#updateConnectionState(WebSocketConnectionState.Connecting);\n\n // Close existing WebSocket transport and clear references\n // so createTransports() will create fresh ones\n if (this.#wsTransport) {\n try {\n await this.#wsTransport.close();\n } catch {\n // Ignore errors during close - transport may already be dead\n }\n }\n this.#wsTransport = undefined;\n this.#httpTransport = undefined;\n\n // Recreate WebSocket transport - returns the new transport for type safety\n const newWsTransport = this.#createTransports();\n\n // Recreate clients that use WebSocket transport\n this.#infoClient = new InfoClient({ transport: newWsTransport });\n this.#subscriptionClient = new SubscriptionClient({\n transport: newWsTransport,\n });\n\n await newWsTransport.ready();\n\n this.#deps.debugLogger.log(\n 'HyperLiquid: Transport ready, restoring subscriptions',\n { timestamp: new Date().toISOString() },\n );\n\n // NOW safe to restore subscriptions\n if (this.#onReconnectCallback) {\n await this.#onReconnectCallback();\n }\n\n // Cancel any pending retry timeout from previous failed attempts\n if (this.#reconnectionRetryTimeout) {\n clearTimeout(this.#reconnectionRetryTimeout);\n this.#reconnectionRetryTimeout = null;\n }\n\n this.#updateConnectionState(WebSocketConnectionState.Connected);\n this.#isReconnecting = false;\n } catch {\n // Reset flag before scheduling retry so the next attempt can proceed\n this.#isReconnecting = false;\n\n // Check if we've exceeded max retry attempts\n if (this.#reconnectionAttempt >= maxReconnectionAttempts) {\n this.#updateConnectionState(WebSocketConnectionState.Disconnected);\n return;\n }\n\n // Reconnection failed - schedule a retry after a delay\n // Store timeout reference so it can be cancelled on intentional disconnect\n this.#reconnectionRetryTimeout = setTimeout(() => {\n this.#reconnectionRetryTimeout = null; // Clear reference after execution\n // Only retry if we haven't been intentionally disconnected\n // and no manual reconnect() is already in progress\n // Note: State may be CONNECTING or DISCONNECTED (if terminate event fired during reconnect)\n if (\n (this.#connectionState === WebSocketConnectionState.Connecting ||\n this.#connectionState === WebSocketConnectionState.Disconnected) &&\n !this.#disconnectionPromise &&\n !this.#isReconnecting\n ) {\n this.#handleConnectionDrop().catch(() => {\n // Error already handled inside #handleConnectionDrop\n });\n }\n }, PERPS_CONSTANTS.ReconnectionRetryDelayMs);\n }\n }\n}\n"]}
|
|
@@ -143,6 +143,7 @@ export declare class HyperLiquidClientService {
|
|
|
143
143
|
* @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
|
|
144
144
|
* @param options.limit - Number of candles to fetch (default: 100).
|
|
145
145
|
* @param options.endTime - End timestamp in milliseconds (default: now).
|
|
146
|
+
* @param options.signal - Optional AbortSignal to cancel the fetch.
|
|
146
147
|
* @returns The historical candle data, or null if no data is available.
|
|
147
148
|
*/
|
|
148
149
|
fetchHistoricalCandles(options: {
|
|
@@ -150,6 +151,7 @@ export declare class HyperLiquidClientService {
|
|
|
150
151
|
interval: ValidCandleInterval;
|
|
151
152
|
limit?: number;
|
|
152
153
|
endTime?: number;
|
|
154
|
+
signal?: AbortSignal;
|
|
153
155
|
}): Promise<CandleData | null>;
|
|
154
156
|
/**
|
|
155
157
|
* Subscribe to candle updates via WebSocket
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidClientService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidClientService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;AACtC,OAAO,EACL,cAAc,EAEd,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,YAAY,EAAwB,qCAAiC;AAI9E,OAAO,EAAE,wBAAwB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EAC1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAAwB;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,iCAA6B;
|
|
1
|
+
{"version":3,"file":"HyperLiquidClientService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidClientService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;AACtC,OAAO,EACL,cAAc,EAEd,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,YAAY,EAAwB,qCAAiC;AAI9E,OAAO,EAAE,wBAAwB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EAC1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAAwB;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,iCAA6B;AASvD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,CAAC,M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M,IAAI;IA6Db;;;;OAIG;IACU,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAoHxC"}
|
|
@@ -143,6 +143,7 @@ export declare class HyperLiquidClientService {
|
|
|
143
143
|
* @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
|
|
144
144
|
* @param options.limit - Number of candles to fetch (default: 100).
|
|
145
145
|
* @param options.endTime - End timestamp in milliseconds (default: now).
|
|
146
|
+
* @param options.signal - Optional AbortSignal to cancel the fetch.
|
|
146
147
|
* @returns The historical candle data, or null if no data is available.
|
|
147
148
|
*/
|
|
148
149
|
fetchHistoricalCandles(options: {
|
|
@@ -150,6 +151,7 @@ export declare class HyperLiquidClientService {
|
|
|
150
151
|
interval: ValidCandleInterval;
|
|
151
152
|
limit?: number;
|
|
152
153
|
endTime?: number;
|
|
154
|
+
signal?: AbortSignal;
|
|
153
155
|
}): Promise<CandleData | null>;
|
|
154
156
|
/**
|
|
155
157
|
* Subscribe to candle updates via WebSocket
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidClientService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidClientService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;AACtC,OAAO,EACL,cAAc,EAEd,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,YAAY,EAAwB,qCAAiC;AAI9E,OAAO,EAAE,wBAAwB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EAC1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAAwB;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,iCAA6B;
|
|
1
|
+
{"version":3,"file":"HyperLiquidClientService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidClientService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;AACtC,O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I,CAAC;IA2GxC;;;;OAIG;IACI,kBAAkB,IAAI,wBAAwB;IAIrD;;;;OAIG;IACI,cAAc,IAAI,OAAO;IAIhC;;;;;;OAMG;IACI,sBAAsB,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIlE;;;;;OAKG;IACI,sBAAsB,CAC3B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,GACxC,IAAI;IAIP;;;;;;OAMG;IACI,0BAA0B,CAC/B,QAAQ,EAAE,CACR,KAAK,EAAE,wBAAwB,EAC/B,mBAAmB,EAAE,MAAM,KACxB,IAAI,GACR,MAAM,IAAI;IA6Db;;;;OAIG;IACU,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAoHxC"}
|
|
@@ -17,6 +17,7 @@ import { PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
|
|
|
17
17
|
import { PERPS_ERROR_CODES } from "../perpsErrorCodes.mjs";
|
|
18
18
|
import { WebSocketConnectionState } from "../types/index.mjs";
|
|
19
19
|
import { ensureError } from "../utils/errorUtils.mjs";
|
|
20
|
+
import { getPerpsConnectionAttemptContext } from "../utils/perpsConnectionAttemptContext.mjs";
|
|
20
21
|
/**
|
|
21
22
|
* Maximum number of reconnection attempts before giving up.
|
|
22
23
|
*/
|
|
@@ -67,6 +68,8 @@ export class HyperLiquidClientService {
|
|
|
67
68
|
* @param wallet - The wallet parameters for signing typed data.
|
|
68
69
|
*/
|
|
69
70
|
async initialize(wallet) {
|
|
71
|
+
const network = __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
|
|
72
|
+
const attemptContext = getPerpsConnectionAttemptContext();
|
|
70
73
|
try {
|
|
71
74
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connecting);
|
|
72
75
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
|
|
@@ -119,21 +122,30 @@ export class HyperLiquidClientService {
|
|
|
119
122
|
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
|
|
120
123
|
const errorInstance = ensureError(error, 'HyperLiquidClientService.initialize');
|
|
121
124
|
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
125
|
+
if (attemptContext?.suppressError) {
|
|
126
|
+
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid initialize failed during suppressed startup attempt', {
|
|
127
|
+
error: errorInstance.message,
|
|
128
|
+
network,
|
|
129
|
+
source: attemptContext.source,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
134
|
+
tags: {
|
|
135
|
+
feature: PERPS_CONSTANTS.FeatureName,
|
|
136
|
+
service: 'HyperLiquidClientService',
|
|
137
|
+
network,
|
|
134
138
|
},
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
context: {
|
|
140
|
+
name: 'sdk_initialization',
|
|
141
|
+
data: {
|
|
142
|
+
operation: 'initialize',
|
|
143
|
+
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
144
|
+
source: attemptContext?.source ?? 'unspecified',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
137
149
|
throw error;
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -288,10 +300,11 @@ export class HyperLiquidClientService {
|
|
|
288
300
|
* @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
|
|
289
301
|
* @param options.limit - Number of candles to fetch (default: 100).
|
|
290
302
|
* @param options.endTime - End timestamp in milliseconds (default: now).
|
|
303
|
+
* @param options.signal - Optional AbortSignal to cancel the fetch.
|
|
291
304
|
* @returns The historical candle data, or null if no data is available.
|
|
292
305
|
*/
|
|
293
306
|
async fetchHistoricalCandles(options) {
|
|
294
|
-
const { symbol, interval, limit = 100, endTime } = options;
|
|
307
|
+
const { symbol, interval, limit = 100, endTime, signal } = options;
|
|
295
308
|
this.ensureInitialized();
|
|
296
309
|
try {
|
|
297
310
|
// Calculate start and end times based on interval and limit
|
|
@@ -306,7 +319,7 @@ export class HyperLiquidClientService {
|
|
|
306
319
|
interval,
|
|
307
320
|
startTime,
|
|
308
321
|
endTime: now,
|
|
309
|
-
});
|
|
322
|
+
}, signal);
|
|
310
323
|
// Transform API response to match expected format
|
|
311
324
|
if (Array.isArray(data) && data.length > 0) {
|
|
312
325
|
const candles = data.map((candle) => ({
|
|
@@ -375,6 +388,9 @@ export class HyperLiquidClientService {
|
|
|
375
388
|
// Store the subscription promise to enable cleanup even when pending
|
|
376
389
|
// This fixes a race condition where component unmounts before subscription resolves
|
|
377
390
|
let subscriptionPromise = null;
|
|
391
|
+
// AbortController to cancel in-flight REST calls (candleSnapshot) on cleanup.
|
|
392
|
+
// Prevents rate limit exhaustion when rapidly switching markets (#28141).
|
|
393
|
+
const abortController = new AbortController();
|
|
378
394
|
// Calculate initial fetch size dynamically based on duration and interval
|
|
379
395
|
// Match main branch behavior: up to 500 candles initially
|
|
380
396
|
const initialLimit = duration
|
|
@@ -388,6 +404,7 @@ export class HyperLiquidClientService {
|
|
|
388
404
|
symbol,
|
|
389
405
|
interval,
|
|
390
406
|
limit: initialLimit,
|
|
407
|
+
signal: abortController.signal,
|
|
391
408
|
});
|
|
392
409
|
// Don't proceed if already unsubscribed
|
|
393
410
|
if (isUnsubscribed) {
|
|
@@ -479,6 +496,10 @@ export class HyperLiquidClientService {
|
|
|
479
496
|
}
|
|
480
497
|
}
|
|
481
498
|
catch (error) {
|
|
499
|
+
// Skip logging and notification for intentional abort (user navigated away)
|
|
500
|
+
if (abortController.signal.aborted) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
482
503
|
const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
|
|
483
504
|
// Log to Sentry: initial fetch failure blocks chart completely
|
|
484
505
|
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
@@ -509,6 +530,8 @@ export class HyperLiquidClientService {
|
|
|
509
530
|
// Return cleanup function
|
|
510
531
|
return () => {
|
|
511
532
|
isUnsubscribed = true;
|
|
533
|
+
// Cancel any in-flight REST calls (candleSnapshot) to conserve rate limit budget (#28141)
|
|
534
|
+
abortController.abort();
|
|
512
535
|
if (wsUnsubscribe) {
|
|
513
536
|
// Subscription already resolved - unsubscribe directly
|
|
514
537
|
wsUnsubscribe();
|