@metamask-previews/perps-controller 3.2.0-preview-6ce5d58fa → 4.0.0-preview-1e2fe74a0
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 +29 -1
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +9 -0
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +9 -0
- package/dist/PerpsController-method-action-types.d.mts.map +1 -1
- package/dist/PerpsController-method-action-types.mjs.map +1 -1
- package/dist/PerpsController.cjs +15 -3
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +18 -3
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +18 -3
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +15 -3
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +28 -0
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +3 -0
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +3 -0
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +28 -0
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +16 -6
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +12 -4
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +12 -4
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +16 -6
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +56 -20
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +29 -4
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +29 -4
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +57 -21
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs +131 -60
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts +23 -0
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts +23 -0
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs +132 -61
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +193 -11
- 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 +194 -12
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/MarketDataService.cjs +89 -6
- package/dist/services/MarketDataService.cjs.map +1 -1
- package/dist/services/MarketDataService.d.cts +19 -0
- package/dist/services/MarketDataService.d.cts.map +1 -1
- package/dist/services/MarketDataService.d.mts +19 -0
- package/dist/services/MarketDataService.d.mts.map +1 -1
- package/dist/services/MarketDataService.mjs +89 -6
- package/dist/services/MarketDataService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +21 -3
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +21 -3
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/accountUtils.cjs +74 -1
- package/dist/utils/accountUtils.cjs.map +1 -1
- package/dist/utils/accountUtils.d.cts +4 -0
- package/dist/utils/accountUtils.d.cts.map +1 -1
- package/dist/utils/accountUtils.d.mts +4 -0
- package/dist/utils/accountUtils.d.mts.map +1 -1
- package/dist/utils/accountUtils.mjs +70 -0
- package/dist/utils/accountUtils.mjs.map +1 -1
- package/dist/utils/coalescePerpsRestRequest.cjs +71 -0
- package/dist/utils/coalescePerpsRestRequest.cjs.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.d.cts +32 -0
- package/dist/utils/coalescePerpsRestRequest.d.cts.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.d.mts +32 -0
- package/dist/utils/coalescePerpsRestRequest.d.mts.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.mjs +66 -0
- package/dist/utils/coalescePerpsRestRequest.mjs.map +1 -0
- package/dist/utils/hyperLiquidAdapter.cjs +7 -7
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +2 -2
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +2 -2
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.mjs +7 -7
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
- package/dist/utils/perpsFormatters.cjs +5 -1
- package/dist/utils/perpsFormatters.cjs.map +1 -1
- package/dist/utils/perpsFormatters.d.cts.map +1 -1
- package/dist/utils/perpsFormatters.d.mts.map +1 -1
- package/dist/utils/perpsFormatters.mjs +5 -1
- package/dist/utils/perpsFormatters.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _HyperLiquidSubscriptionService_instances, _HyperLiquidSubscriptionService_clientService, _HyperLiquidSubscriptionService_walletService, _HyperLiquidSubscriptionService_hip3Enabled, _HyperLiquidSubscriptionService_enabledDexs, _HyperLiquidSubscriptionService_allowlistMarkets, _HyperLiquidSubscriptionService_blocklistMarkets, _HyperLiquidSubscriptionService_discoveredDexNames, _HyperLiquidSubscriptionService_dexDiscoveryPromise, _HyperLiquidSubscriptionService_dexDiscoveryResolver, _HyperLiquidSubscriptionService_expectedDexs, _HyperLiquidSubscriptionService_initializedDexs, _HyperLiquidSubscriptionService_priceSubscribers, _HyperLiquidSubscriptionService_positionSubscribers, _HyperLiquidSubscriptionService_orderFillSubscribers, _HyperLiquidSubscriptionService_orderSubscribers, _HyperLiquidSubscriptionService_accountSubscribers, _HyperLiquidSubscriptionService_marketDataSubscribers, _HyperLiquidSubscriptionService_orderBookSubscribers, _HyperLiquidSubscriptionService_globalAllMidsSubscription, _HyperLiquidSubscriptionService_globalAllMidsPromise, _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions, _HyperLiquidSubscriptionService_pendingActiveAssetPromises, _HyperLiquidSubscriptionService_globalBboSubscriptions, _HyperLiquidSubscriptionService_pendingBboPromises, _HyperLiquidSubscriptionService_orderFillSubscriptions, _HyperLiquidSubscriptionService_symbolSubscriberCounts, _HyperLiquidSubscriptionService_dexSubscriberCounts, _HyperLiquidSubscriptionService_webData3Subscriptions, _HyperLiquidSubscriptionService_webData3SubscriptionPromise, _HyperLiquidSubscriptionService_positionSubscriberCount, _HyperLiquidSubscriptionService_orderSubscriberCount, _HyperLiquidSubscriptionService_accountSubscriberCount, _HyperLiquidSubscriptionService_oiCapSubscriberCount, _HyperLiquidSubscriptionService_dexPositionsCache, _HyperLiquidSubscriptionService_dexOrdersCache, _HyperLiquidSubscriptionService_dexAccountCache, _HyperLiquidSubscriptionService_cachedPositions, _HyperLiquidSubscriptionService_cachedOrders, _HyperLiquidSubscriptionService_cachedAccount, _HyperLiquidSubscriptionService_ordersCacheInitialized, _HyperLiquidSubscriptionService_positionsCacheInitialized, _HyperLiquidSubscriptionService_oiCapSubscribers, _HyperLiquidSubscriptionService_cachedOICaps, _HyperLiquidSubscriptionService_cachedOICapsHash, _HyperLiquidSubscriptionService_oiCapsCacheInitialized, _HyperLiquidSubscriptionService_cachedPriceData, _HyperLiquidSubscriptionService_allMidsSnapshots, _HyperLiquidSubscriptionService_cachedFills, _HyperLiquidSubscriptionService_fillsCacheInitialized, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, _HyperLiquidSubscriptionService_dexAssetCtxsCache, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, _HyperLiquidSubscriptionService_openOrdersSubscriptions, _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions, _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions, _HyperLiquidSubscriptionService_dexMetaCache, _HyperLiquidSubscriptionService_orderBookCache, _HyperLiquidSubscriptionService_marketDataCache, _HyperLiquidSubscriptionService_isClearing, _HyperLiquidSubscriptionService_restoreRetryTimeouts, _HyperLiquidSubscriptionService_deps, _HyperLiquidSubscriptionService_logErrorUnlessClearing, _HyperLiquidSubscriptionService_isTransientAssetCtxsError, _HyperLiquidSubscriptionService_scheduleRestoreRetry, _HyperLiquidSubscriptionService_getErrorContext, _HyperLiquidSubscriptionService_isDexEnabled, _HyperLiquidSubscriptionService_waitForDexDiscovery, _HyperLiquidSubscriptionService_hashPositions, _HyperLiquidSubscriptionService_hashOrders, _HyperLiquidSubscriptionService_hashAccountState, _HyperLiquidSubscriptionService_cachedPositionsHash, _HyperLiquidSubscriptionService_cachedOrdersHash, _HyperLiquidSubscriptionService_cachedAccountHash, _HyperLiquidSubscriptionService_extractTPSLFromOrders, _HyperLiquidSubscriptionService_mergeTPSLIntoPositions, _HyperLiquidSubscriptionService_aggregateAccountStates, _HyperLiquidSubscriptionService_ensureSharedWebData3Subscription, _HyperLiquidSubscriptionService_createUserDataSubscription, _HyperLiquidSubscriptionService_ensureClearinghouseStateSubscription, _HyperLiquidSubscriptionService_createClearinghouseSubscription, _HyperLiquidSubscriptionService_ensureOpenOrdersSubscription, _HyperLiquidSubscriptionService_createOpenOrdersSubscription, _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers, _HyperLiquidSubscriptionService_cleanupSharedWebData3ISubscription, _HyperLiquidSubscriptionService_ensureOrderFillISubscription, _HyperLiquidSubscriptionService_createSubscription, _HyperLiquidSubscriptionService_createPriceUpdate, _HyperLiquidSubscriptionService_ensureGlobalAllMidsSubscription, _HyperLiquidSubscriptionService_ensureActiveAssetSubscription, _HyperLiquidSubscriptionService_cleanupActiveAssetSubscription, _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription, _HyperLiquidSubscriptionService_createDexAllMidsSubscription, _HyperLiquidSubscriptionService_createAssetCtxsSubscription, _HyperLiquidSubscriptionService_cleanupAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureBboSubscription, _HyperLiquidSubscriptionService_cleanupBboSubscription, _HyperLiquidSubscriptionService_processOrderBookData, _HyperLiquidSubscriptionService_notifyAllPriceSubscribers;
|
|
13
|
+
var _HyperLiquidSubscriptionService_instances, _HyperLiquidSubscriptionService_clientService, _HyperLiquidSubscriptionService_walletService, _HyperLiquidSubscriptionService_hip3Enabled, _HyperLiquidSubscriptionService_enabledDexs, _HyperLiquidSubscriptionService_allowlistMarkets, _HyperLiquidSubscriptionService_blocklistMarkets, _HyperLiquidSubscriptionService_discoveredDexNames, _HyperLiquidSubscriptionService_dexDiscoveryPromise, _HyperLiquidSubscriptionService_dexDiscoveryResolver, _HyperLiquidSubscriptionService_expectedDexs, _HyperLiquidSubscriptionService_initializedDexs, _HyperLiquidSubscriptionService_priceSubscribers, _HyperLiquidSubscriptionService_positionSubscribers, _HyperLiquidSubscriptionService_orderFillSubscribers, _HyperLiquidSubscriptionService_orderSubscribers, _HyperLiquidSubscriptionService_accountSubscribers, _HyperLiquidSubscriptionService_marketDataSubscribers, _HyperLiquidSubscriptionService_orderBookSubscribers, _HyperLiquidSubscriptionService_globalAllMidsSubscription, _HyperLiquidSubscriptionService_globalAllMidsPromise, _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions, _HyperLiquidSubscriptionService_pendingActiveAssetPromises, _HyperLiquidSubscriptionService_globalBboSubscriptions, _HyperLiquidSubscriptionService_pendingBboPromises, _HyperLiquidSubscriptionService_orderFillSubscriptions, _HyperLiquidSubscriptionService_spotStateSubscriptions, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, _HyperLiquidSubscriptionService_symbolSubscriberCounts, _HyperLiquidSubscriptionService_dexSubscriberCounts, _HyperLiquidSubscriptionService_webData3Subscriptions, _HyperLiquidSubscriptionService_webData3SubscriptionPromise, _HyperLiquidSubscriptionService_positionSubscriberCount, _HyperLiquidSubscriptionService_orderSubscriberCount, _HyperLiquidSubscriptionService_accountSubscriberCount, _HyperLiquidSubscriptionService_oiCapSubscriberCount, _HyperLiquidSubscriptionService_dexPositionsCache, _HyperLiquidSubscriptionService_dexOrdersCache, _HyperLiquidSubscriptionService_dexAccountCache, _HyperLiquidSubscriptionService_cachedSpotState, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, _HyperLiquidSubscriptionService_spotStatePromise, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, _HyperLiquidSubscriptionService_spotStateGeneration, _HyperLiquidSubscriptionService_cachedPositions, _HyperLiquidSubscriptionService_cachedOrders, _HyperLiquidSubscriptionService_cachedAccount, _HyperLiquidSubscriptionService_ordersCacheInitialized, _HyperLiquidSubscriptionService_positionsCacheInitialized, _HyperLiquidSubscriptionService_oiCapSubscribers, _HyperLiquidSubscriptionService_cachedOICaps, _HyperLiquidSubscriptionService_cachedOICapsHash, _HyperLiquidSubscriptionService_oiCapsCacheInitialized, _HyperLiquidSubscriptionService_cachedPriceData, _HyperLiquidSubscriptionService_allMidsSnapshots, _HyperLiquidSubscriptionService_cachedFills, _HyperLiquidSubscriptionService_fillsCacheInitialized, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, _HyperLiquidSubscriptionService_dexAssetCtxsCache, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, _HyperLiquidSubscriptionService_openOrdersSubscriptions, _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions, _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions, _HyperLiquidSubscriptionService_dexMetaCache, _HyperLiquidSubscriptionService_orderBookCache, _HyperLiquidSubscriptionService_marketDataCache, _HyperLiquidSubscriptionService_isClearing, _HyperLiquidSubscriptionService_restoreRetryTimeouts, _HyperLiquidSubscriptionService_deps, _HyperLiquidSubscriptionService_logErrorUnlessClearing, _HyperLiquidSubscriptionService_isTransientAssetCtxsError, _HyperLiquidSubscriptionService_scheduleRestoreRetry, _HyperLiquidSubscriptionService_getErrorContext, _HyperLiquidSubscriptionService_isDexEnabled, _HyperLiquidSubscriptionService_waitForDexDiscovery, _HyperLiquidSubscriptionService_hashPositions, _HyperLiquidSubscriptionService_hashOrders, _HyperLiquidSubscriptionService_hashAccountState, _HyperLiquidSubscriptionService_cachedPositionsHash, _HyperLiquidSubscriptionService_cachedOrdersHash, _HyperLiquidSubscriptionService_cachedAccountHash, _HyperLiquidSubscriptionService_extractTPSLFromOrders, _HyperLiquidSubscriptionService_mergeTPSLIntoPositions, _HyperLiquidSubscriptionService_aggregateAccountStates, _HyperLiquidSubscriptionService_ensureSpotState, _HyperLiquidSubscriptionService_refreshSpotState, _HyperLiquidSubscriptionService_ensureSpotStateSubscription, _HyperLiquidSubscriptionService_ensureSharedWebData3Subscription, _HyperLiquidSubscriptionService_createUserDataSubscription, _HyperLiquidSubscriptionService_ensureClearinghouseStateSubscription, _HyperLiquidSubscriptionService_createClearinghouseSubscription, _HyperLiquidSubscriptionService_ensureOpenOrdersSubscription, _HyperLiquidSubscriptionService_createOpenOrdersSubscription, _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers, _HyperLiquidSubscriptionService_cleanupSharedWebData3ISubscription, _HyperLiquidSubscriptionService_ensureOrderFillISubscription, _HyperLiquidSubscriptionService_createSubscription, _HyperLiquidSubscriptionService_createPriceUpdate, _HyperLiquidSubscriptionService_ensureGlobalAllMidsSubscription, _HyperLiquidSubscriptionService_ensureActiveAssetSubscription, _HyperLiquidSubscriptionService_cleanupActiveAssetSubscription, _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription, _HyperLiquidSubscriptionService_createDexAllMidsSubscription, _HyperLiquidSubscriptionService_createAssetCtxsSubscription, _HyperLiquidSubscriptionService_cleanupAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureBboSubscription, _HyperLiquidSubscriptionService_cleanupBboSubscription, _HyperLiquidSubscriptionService_processOrderBookData, _HyperLiquidSubscriptionService_notifyAllPriceSubscribers;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HyperLiquidSubscriptionService = void 0;
|
|
16
16
|
const utils_1 = require("@metamask/utils");
|
|
@@ -67,6 +67,12 @@ class HyperLiquidSubscriptionService {
|
|
|
67
67
|
_HyperLiquidSubscriptionService_pendingBboPromises.set(this, new Map());
|
|
68
68
|
// Order fill subscriptions keyed by accountId (normalized: undefined -> 'default')
|
|
69
69
|
_HyperLiquidSubscriptionService_orderFillSubscriptions.set(this, new Map());
|
|
70
|
+
_HyperLiquidSubscriptionService_spotStateSubscriptions.set(this, new Map());
|
|
71
|
+
_HyperLiquidSubscriptionService_spotStateSubscriptionPromises.set(this, new Map());
|
|
72
|
+
// Bumped on cleanup so in-flight #ensureSpotStateSubscription
|
|
73
|
+
// continuations discard their subscription instead of rehydrating
|
|
74
|
+
// #spotStateSubscriptions after clearAll/cleanupSharedWebData3.
|
|
75
|
+
_HyperLiquidSubscriptionService_spotStateSubscriptionGeneration.set(this, 0);
|
|
70
76
|
_HyperLiquidSubscriptionService_symbolSubscriberCounts.set(this, new Map());
|
|
71
77
|
_HyperLiquidSubscriptionService_dexSubscriberCounts.set(this, new Map()); // Track subscribers per DEX for assetCtxs
|
|
72
78
|
// Multi-DEX webData3 subscription for all user data (positions, orders, account, OI caps)
|
|
@@ -80,6 +86,15 @@ class HyperLiquidSubscriptionService {
|
|
|
80
86
|
_HyperLiquidSubscriptionService_dexPositionsCache.set(this, new Map()); // Per-DEX positions
|
|
81
87
|
_HyperLiquidSubscriptionService_dexOrdersCache.set(this, new Map()); // Per-DEX orders
|
|
82
88
|
_HyperLiquidSubscriptionService_dexAccountCache.set(this, new Map()); // Per-DEX account state
|
|
89
|
+
_HyperLiquidSubscriptionService_cachedSpotState.set(this, null);
|
|
90
|
+
_HyperLiquidSubscriptionService_cachedSpotStateUserAddress.set(this, null);
|
|
91
|
+
_HyperLiquidSubscriptionService_spotStatePromise.set(this, void 0);
|
|
92
|
+
_HyperLiquidSubscriptionService_spotStatePromiseUserAddress.set(this, void 0);
|
|
93
|
+
// Monotonic token bumped on cleanUp/clearAll and on each new fetch.
|
|
94
|
+
// Any in-flight #refreshSpotState that resolves with a stale token
|
|
95
|
+
// discards its result, preventing cross-account cache contamination
|
|
96
|
+
// when accounts are switched mid-fetch.
|
|
97
|
+
_HyperLiquidSubscriptionService_spotStateGeneration.set(this, 0);
|
|
83
98
|
_HyperLiquidSubscriptionService_cachedPositions.set(this, null); // Aggregated positions
|
|
84
99
|
_HyperLiquidSubscriptionService_cachedOrders.set(this, null); // Aggregated orders
|
|
85
100
|
_HyperLiquidSubscriptionService_cachedAccount.set(this, null); // Aggregated account
|
|
@@ -483,10 +498,20 @@ class HyperLiquidSubscriptionService {
|
|
|
483
498
|
const unsubscribe = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_createSubscription).call(this, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_accountSubscribers, "f"), callback);
|
|
484
499
|
// Increment account subscriber count
|
|
485
500
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_accountSubscriberCount, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_accountSubscriberCount, "f") + 1, "f");
|
|
486
|
-
// Immediately provide cached data if available
|
|
501
|
+
// Immediately provide cached data if available. May be spot-less if the
|
|
502
|
+
// spot fetch has not resolved yet (or permanently failed) — subscribers
|
|
503
|
+
// prefer stale-but-present data over silent starvation; the next
|
|
504
|
+
// aggregation after #ensureSpotState / next WebSocket update pushes the
|
|
505
|
+
// spot-inclusive value.
|
|
487
506
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedAccount, "f")) {
|
|
488
507
|
callback(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedAccount, "f"));
|
|
489
508
|
}
|
|
509
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureSpotState).call(this, accountId).catch((error) => {
|
|
510
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToAccount'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToAccount.ensureSpotState'));
|
|
511
|
+
});
|
|
512
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureSpotStateSubscription).call(this, accountId).catch((error) => {
|
|
513
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToAccount'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToAccount.ensureSpotStateSubscription'));
|
|
514
|
+
});
|
|
490
515
|
// Ensure shared subscription is active (reuses existing connection)
|
|
491
516
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureSharedWebData3Subscription).call(this, accountId).catch((error) => {
|
|
492
517
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToAccount'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToAccount'));
|
|
@@ -816,6 +841,17 @@ class HyperLiquidSubscriptionService {
|
|
|
816
841
|
});
|
|
817
842
|
});
|
|
818
843
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_orderFillSubscriptions, "f").clear();
|
|
844
|
+
// Clear spotState subscriptions. Bump generation + drop in-flight
|
|
845
|
+
// promises so any racing #ensureSpotStateSubscription continuation
|
|
846
|
+
// unsubscribes its fresh sub instead of rehydrating the cleared map.
|
|
847
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, "f") + 1, "f");
|
|
848
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, "f").clear();
|
|
849
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").forEach((subscription) => {
|
|
850
|
+
subscription.unsubscribe().catch(() => {
|
|
851
|
+
// Ignore errors during cleanup
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").clear();
|
|
819
855
|
// Clear cached data
|
|
820
856
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPriceData, null, "f");
|
|
821
857
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").clear();
|
|
@@ -846,6 +882,11 @@ class HyperLiquidSubscriptionService {
|
|
|
846
882
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").clear();
|
|
847
883
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexOrdersCache, "f").clear();
|
|
848
884
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").clear();
|
|
885
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
|
|
886
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
|
|
887
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
888
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, undefined, "f");
|
|
889
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, undefined, "f");
|
|
849
890
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAssetCtxsCache, "f").clear();
|
|
850
891
|
// Unsubscribe all active subscriptions before clearing references.
|
|
851
892
|
// Without this, orphaned subscriptions try to send unsubscribe frames
|
|
@@ -925,7 +966,7 @@ class HyperLiquidSubscriptionService {
|
|
|
925
966
|
}
|
|
926
967
|
}
|
|
927
968
|
exports.HyperLiquidSubscriptionService = HyperLiquidSubscriptionService;
|
|
928
|
-
_HyperLiquidSubscriptionService_clientService = new WeakMap(), _HyperLiquidSubscriptionService_walletService = new WeakMap(), _HyperLiquidSubscriptionService_hip3Enabled = new WeakMap(), _HyperLiquidSubscriptionService_enabledDexs = new WeakMap(), _HyperLiquidSubscriptionService_allowlistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_blocklistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_discoveredDexNames = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryPromise = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryResolver = new WeakMap(), _HyperLiquidSubscriptionService_expectedDexs = new WeakMap(), _HyperLiquidSubscriptionService_initializedDexs = new WeakMap(), _HyperLiquidSubscriptionService_priceSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_marketDataSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderBookSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsSubscription = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsPromise = new WeakMap(), _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingActiveAssetPromises = new WeakMap(), _HyperLiquidSubscriptionService_globalBboSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingBboPromises = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_symbolSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_dexSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_webData3Subscriptions = new WeakMap(), _HyperLiquidSubscriptionService_webData3SubscriptionPromise = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_dexPositionsCache = new WeakMap(), _HyperLiquidSubscriptionService_dexOrdersCache = new WeakMap(), _HyperLiquidSubscriptionService_dexAccountCache = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositions = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrders = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccount = new WeakMap(), _HyperLiquidSubscriptionService_ordersCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_positionsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICaps = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICapsHash = new WeakMap(), _HyperLiquidSubscriptionService_oiCapsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_cachedPriceData = new WeakMap(), _HyperLiquidSubscriptionService_allMidsSnapshots = new WeakMap(), _HyperLiquidSubscriptionService_cachedFills = new WeakMap(), _HyperLiquidSubscriptionService_fillsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAssetCtxsCache = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_openOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexMetaCache = new WeakMap(), _HyperLiquidSubscriptionService_orderBookCache = new WeakMap(), _HyperLiquidSubscriptionService_marketDataCache = new WeakMap(), _HyperLiquidSubscriptionService_isClearing = new WeakMap(), _HyperLiquidSubscriptionService_restoreRetryTimeouts = new WeakMap(), _HyperLiquidSubscriptionService_deps = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositionsHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrdersHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccountHash = new WeakMap(), _HyperLiquidSubscriptionService_instances = new WeakSet(), _HyperLiquidSubscriptionService_logErrorUnlessClearing = function _HyperLiquidSubscriptionService_logErrorUnlessClearing(error, context) {
|
|
969
|
+
_HyperLiquidSubscriptionService_clientService = new WeakMap(), _HyperLiquidSubscriptionService_walletService = new WeakMap(), _HyperLiquidSubscriptionService_hip3Enabled = new WeakMap(), _HyperLiquidSubscriptionService_enabledDexs = new WeakMap(), _HyperLiquidSubscriptionService_allowlistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_blocklistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_discoveredDexNames = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryPromise = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryResolver = new WeakMap(), _HyperLiquidSubscriptionService_expectedDexs = new WeakMap(), _HyperLiquidSubscriptionService_initializedDexs = new WeakMap(), _HyperLiquidSubscriptionService_priceSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_marketDataSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderBookSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsSubscription = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsPromise = new WeakMap(), _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingActiveAssetPromises = new WeakMap(), _HyperLiquidSubscriptionService_globalBboSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingBboPromises = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration = new WeakMap(), _HyperLiquidSubscriptionService_symbolSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_dexSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_webData3Subscriptions = new WeakMap(), _HyperLiquidSubscriptionService_webData3SubscriptionPromise = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_dexPositionsCache = new WeakMap(), _HyperLiquidSubscriptionService_dexOrdersCache = new WeakMap(), _HyperLiquidSubscriptionService_dexAccountCache = new WeakMap(), _HyperLiquidSubscriptionService_cachedSpotState = new WeakMap(), _HyperLiquidSubscriptionService_cachedSpotStateUserAddress = new WeakMap(), _HyperLiquidSubscriptionService_spotStatePromise = new WeakMap(), _HyperLiquidSubscriptionService_spotStatePromiseUserAddress = new WeakMap(), _HyperLiquidSubscriptionService_spotStateGeneration = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositions = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrders = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccount = new WeakMap(), _HyperLiquidSubscriptionService_ordersCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_positionsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICaps = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICapsHash = new WeakMap(), _HyperLiquidSubscriptionService_oiCapsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_cachedPriceData = new WeakMap(), _HyperLiquidSubscriptionService_allMidsSnapshots = new WeakMap(), _HyperLiquidSubscriptionService_cachedFills = new WeakMap(), _HyperLiquidSubscriptionService_fillsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAssetCtxsCache = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_openOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexMetaCache = new WeakMap(), _HyperLiquidSubscriptionService_orderBookCache = new WeakMap(), _HyperLiquidSubscriptionService_marketDataCache = new WeakMap(), _HyperLiquidSubscriptionService_isClearing = new WeakMap(), _HyperLiquidSubscriptionService_restoreRetryTimeouts = new WeakMap(), _HyperLiquidSubscriptionService_deps = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositionsHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrdersHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccountHash = new WeakMap(), _HyperLiquidSubscriptionService_instances = new WeakSet(), _HyperLiquidSubscriptionService_logErrorUnlessClearing = function _HyperLiquidSubscriptionService_logErrorUnlessClearing(error, context) {
|
|
929
970
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_isClearing, "f")) {
|
|
930
971
|
return;
|
|
931
972
|
}
|
|
@@ -1226,7 +1267,7 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1226
1267
|
const firstDexAccount = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").values().next().value ?? {};
|
|
1227
1268
|
// Calculate weighted returnOnEquity across all DEXs
|
|
1228
1269
|
const returnOnEquity = (0, accountUtils_1.calculateWeightedReturnOnEquity)(accountStatesForROE);
|
|
1229
|
-
return {
|
|
1270
|
+
return (0, accountUtils_1.addSpotBalanceToAccountState)({
|
|
1230
1271
|
...firstDexAccount,
|
|
1231
1272
|
availableBalance: totalAvailableBalance.toString(),
|
|
1232
1273
|
totalBalance: totalBalance.toString(),
|
|
@@ -1234,7 +1275,124 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1234
1275
|
unrealizedPnl: totalUnrealizedPnl.toString(),
|
|
1235
1276
|
subAccountBreakdown,
|
|
1236
1277
|
returnOnEquity,
|
|
1237
|
-
};
|
|
1278
|
+
}, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"));
|
|
1279
|
+
}, _HyperLiquidSubscriptionService_ensureSpotState = async function _HyperLiquidSubscriptionService_ensureSpotState(accountId) {
|
|
1280
|
+
const userAddress = await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").getUserAddressWithDefault(accountId);
|
|
1281
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f") &&
|
|
1282
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f") === userAddress) {
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
// Share an in-flight fetch only if it targets the same user.
|
|
1286
|
+
// A pending fetch for a different user is stale after an account switch —
|
|
1287
|
+
// start a fresh fetch; the stale one will self-discard via generation check.
|
|
1288
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStatePromise, "f") &&
|
|
1289
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, "f") === userAddress) {
|
|
1290
|
+
await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStatePromise, "f");
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
1294
|
+
const generation = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f");
|
|
1295
|
+
const promise = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_refreshSpotState).call(this, userAddress, generation);
|
|
1296
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, promise, "f");
|
|
1297
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, userAddress, "f");
|
|
1298
|
+
try {
|
|
1299
|
+
await promise;
|
|
1300
|
+
}
|
|
1301
|
+
finally {
|
|
1302
|
+
// Only clear tracker if we're still the latest in-flight fetch.
|
|
1303
|
+
// A newer fetch may have already replaced us.
|
|
1304
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStatePromise, "f") === promise) {
|
|
1305
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, undefined, "f");
|
|
1306
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, undefined, "f");
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}, _HyperLiquidSubscriptionService_refreshSpotState = async function _HyperLiquidSubscriptionService_refreshSpotState(userAddress, generation) {
|
|
1310
|
+
try {
|
|
1311
|
+
// Cold-start safety: getInfoClient() throws until the SDK has been
|
|
1312
|
+
// initialized via ensureSubscriptionClient. On a fresh service
|
|
1313
|
+
// instance subscribeToAccount can race ahead of the webData3 path,
|
|
1314
|
+
// so initialize here first — subsequent calls are no-ops.
|
|
1315
|
+
await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").ensureSubscriptionClient(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").createWalletAdapter());
|
|
1316
|
+
if (generation !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f")) {
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
const infoClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getInfoClient();
|
|
1320
|
+
const result = await infoClient.spotClearinghouseState({
|
|
1321
|
+
user: userAddress,
|
|
1322
|
+
});
|
|
1323
|
+
// Drop stale results: cleanUp/clearAll or a newer fetch bumped generation.
|
|
1324
|
+
// Writing here would re-populate the cache with a different user's data.
|
|
1325
|
+
if (generation !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f")) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, result, "f");
|
|
1329
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, userAddress, "f");
|
|
1330
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
1331
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
catch (error) {
|
|
1335
|
+
if (generation !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f")) {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.refreshSpotState'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'refreshSpotState'));
|
|
1339
|
+
}
|
|
1340
|
+
}, _HyperLiquidSubscriptionService_ensureSpotStateSubscription = async function _HyperLiquidSubscriptionService_ensureSpotStateSubscription(accountId) {
|
|
1341
|
+
const userAddress = await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").getUserAddressWithDefault(accountId);
|
|
1342
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").has(userAddress)) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
const inFlight = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, "f").get(userAddress);
|
|
1346
|
+
if (inFlight) {
|
|
1347
|
+
await inFlight;
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
const startGeneration = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, "f");
|
|
1351
|
+
const promise = (async () => {
|
|
1352
|
+
await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").ensureSubscriptionClient(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").createWalletAdapter());
|
|
1353
|
+
const subscriptionClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getSubscriptionClient();
|
|
1354
|
+
if (!subscriptionClient) {
|
|
1355
|
+
throw new Error('SubscriptionClient not available');
|
|
1356
|
+
}
|
|
1357
|
+
const subscription = await subscriptionClient.spotState({ user: userAddress }, (event) => {
|
|
1358
|
+
try {
|
|
1359
|
+
if (event.user.toLowerCase() !== userAddress.toLowerCase()) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
// Invalidate any in-flight REST refreshSpotState so it drops
|
|
1363
|
+
// its result instead of overwriting this fresher WS snapshot.
|
|
1364
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
1365
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, event.spotState, "f");
|
|
1366
|
+
// Normalize to match REST path (stores lowercase) so the
|
|
1367
|
+
// #ensureSpotState strict-equal check hits the cache regardless
|
|
1368
|
+
// of whether HL returns a checksummed or lowercase user field.
|
|
1369
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, event.user.toLowerCase(), "f");
|
|
1370
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
1371
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
catch (error) {
|
|
1375
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.ensureSpotStateSubscription'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'spotState callback error', {
|
|
1376
|
+
user: userAddress,
|
|
1377
|
+
}));
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
// Discard if cleanup ran while we were awaiting the subscription
|
|
1381
|
+
// handshake; rehydrating #spotStateSubscriptions here would leave
|
|
1382
|
+
// a stale entry that short-circuits future resubscribe attempts.
|
|
1383
|
+
if (startGeneration !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, "f")) {
|
|
1384
|
+
await subscription.unsubscribe().catch(() => undefined);
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").set(userAddress, subscription);
|
|
1388
|
+
})();
|
|
1389
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, "f").set(userAddress, promise);
|
|
1390
|
+
try {
|
|
1391
|
+
await promise;
|
|
1392
|
+
}
|
|
1393
|
+
finally {
|
|
1394
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, "f").delete(userAddress);
|
|
1395
|
+
}
|
|
1238
1396
|
}, _HyperLiquidSubscriptionService_ensureSharedWebData3Subscription =
|
|
1239
1397
|
/**
|
|
1240
1398
|
* Ensure shared webData3 subscription is active (singleton pattern with multi-DEX support)
|
|
@@ -1413,7 +1571,7 @@ async function _HyperLiquidSubscriptionService_createUserDataSubscription(accoun
|
|
|
1413
1571
|
// Merge TP/SL data into positions
|
|
1414
1572
|
const positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, positions, tpslMap, tpslCountMap);
|
|
1415
1573
|
// Extract account data (webData2 provides clearinghouseState)
|
|
1416
|
-
const accountState = (0, hyperLiquidAdapter_1.adaptAccountStateFromSDK)(data.clearinghouseState
|
|
1574
|
+
const accountState = (0, hyperLiquidAdapter_1.adaptAccountStateFromSDK)(data.clearinghouseState);
|
|
1417
1575
|
// Store in caches (main DEX only)
|
|
1418
1576
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").set(currentDexName, positionsWithTPSL);
|
|
1419
1577
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexOrdersCache, "f").set(currentDexName, orders);
|
|
@@ -1429,10 +1587,13 @@ async function _HyperLiquidSubscriptionService_createUserDataSubscription(accoun
|
|
|
1429
1587
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_oiCapsCacheInitialized, true, "f");
|
|
1430
1588
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_oiCapSubscribers, "f").forEach((callback) => callback(oiCaps));
|
|
1431
1589
|
}
|
|
1432
|
-
// Notify subscribers (no aggregation needed - only main DEX)
|
|
1590
|
+
// Notify subscribers (no aggregation needed - only main DEX).
|
|
1591
|
+
// Apply spot balance so single-DEX accounts see the same
|
|
1592
|
+
// spot-inclusive totalBalance as the HIP-3 aggregation path.
|
|
1593
|
+
const spotAdjustedAccount = (0, accountUtils_1.addSpotBalanceToAccountState)(accountState, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"));
|
|
1433
1594
|
const positionsHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashPositions).call(this, positionsWithTPSL);
|
|
1434
1595
|
const ordersHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashOrders).call(this, orders);
|
|
1435
|
-
const accountHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashAccountState).call(this,
|
|
1596
|
+
const accountHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashAccountState).call(this, spotAdjustedAccount);
|
|
1436
1597
|
if (positionsHash !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedPositionsHash, "f")) {
|
|
1437
1598
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPositions, positionsWithTPSL, "f");
|
|
1438
1599
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPositionsHash, positionsHash, "f");
|
|
@@ -1446,9 +1607,9 @@ async function _HyperLiquidSubscriptionService_createUserDataSubscription(accoun
|
|
|
1446
1607
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_orderSubscribers, "f").forEach((callback) => callback(orders));
|
|
1447
1608
|
}
|
|
1448
1609
|
if (accountHash !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedAccountHash, "f")) {
|
|
1449
|
-
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccount,
|
|
1610
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccount, spotAdjustedAccount, "f");
|
|
1450
1611
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccountHash, accountHash, "f");
|
|
1451
|
-
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_accountSubscribers, "f").forEach((callback) => callback(
|
|
1612
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_accountSubscribers, "f").forEach((callback) => callback(spotAdjustedAccount));
|
|
1452
1613
|
}
|
|
1453
1614
|
}
|
|
1454
1615
|
catch (error) {
|
|
@@ -1544,7 +1705,7 @@ async function _HyperLiquidSubscriptionService_createClearinghouseSubscription(u
|
|
|
1544
1705
|
positionsWithTPSL = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_mergeTPSLIntoPositions).call(this, positions, tpslMap, tpslCountMap);
|
|
1545
1706
|
}
|
|
1546
1707
|
// Update account state
|
|
1547
|
-
const accountState = (0, hyperLiquidAdapter_1.adaptAccountStateFromSDK)(data.clearinghouseState
|
|
1708
|
+
const accountState = (0, hyperLiquidAdapter_1.adaptAccountStateFromSDK)(data.clearinghouseState);
|
|
1548
1709
|
// Update caches
|
|
1549
1710
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexPositionsCache, "f").set(cacheKey, positionsWithTPSL);
|
|
1550
1711
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").set(cacheKey, accountState);
|
|
@@ -1722,6 +1883,20 @@ async function _HyperLiquidSubscriptionService_createOpenOrdersSubscription(user
|
|
|
1722
1883
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_webData3Subscriptions, "f").clear();
|
|
1723
1884
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_webData3SubscriptionPromise, undefined, "f");
|
|
1724
1885
|
}
|
|
1886
|
+
// Cleanup spotState subscriptions (per-user). Bump generation +
|
|
1887
|
+
// drop in-flight promises so a racing #ensureSpotStateSubscription
|
|
1888
|
+
// continuation discards its subscription rather than rehydrating
|
|
1889
|
+
// #spotStateSubscriptions after this clear.
|
|
1890
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, "f") + 1, "f");
|
|
1891
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, "f").clear();
|
|
1892
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").size > 0) {
|
|
1893
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").forEach((subscription, user) => {
|
|
1894
|
+
subscription.unsubscribe().catch((error) => {
|
|
1895
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.cleanupSharedWebData3ISubscription'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'cleanupSharedWebData3ISubscription.spotState', { user }));
|
|
1896
|
+
});
|
|
1897
|
+
});
|
|
1898
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateSubscriptions, "f").clear();
|
|
1899
|
+
}
|
|
1725
1900
|
// Cleanup individual subscriptions (clearinghouseState + openOrders)
|
|
1726
1901
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, "f").size > 0) {
|
|
1727
1902
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, "f").forEach((subscription, dexName) => {
|
|
@@ -1762,6 +1937,13 @@ async function _HyperLiquidSubscriptionService_createOpenOrdersSubscription(user
|
|
|
1762
1937
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPositions, null, "f");
|
|
1763
1938
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedOrders, null, "f");
|
|
1764
1939
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccount, null, "f");
|
|
1940
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
|
|
1941
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
|
|
1942
|
+
// Bump generation so any in-flight spot fetch from a prior user discards
|
|
1943
|
+
// its result instead of re-populating the cache post-cleanup.
|
|
1944
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
1945
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, undefined, "f");
|
|
1946
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, undefined, "f");
|
|
1765
1947
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_ordersCacheInitialized, false, "f"); // Reset cache initialization flag
|
|
1766
1948
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_positionsCacheInitialized, false, "f"); // Reset cache initialization flag
|
|
1767
1949
|
// Clear hash caches
|