@metamask-previews/perps-controller 1.3.0-preview-2d89a26 → 1.3.0-preview-afe010990

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/PerpsController-method-action-types.cjs +3 -0
  3. package/dist/PerpsController-method-action-types.cjs.map +1 -0
  4. package/dist/PerpsController-method-action-types.d.cts +147 -0
  5. package/dist/PerpsController-method-action-types.d.cts.map +1 -0
  6. package/dist/PerpsController-method-action-types.d.mts +147 -0
  7. package/dist/PerpsController-method-action-types.d.mts.map +1 -0
  8. package/dist/PerpsController-method-action-types.mjs +2 -0
  9. package/dist/PerpsController-method-action-types.mjs.map +1 -0
  10. package/dist/PerpsController.cjs +488 -183
  11. package/dist/PerpsController.cjs.map +1 -1
  12. package/dist/PerpsController.d.cts +91 -131
  13. package/dist/PerpsController.d.cts.map +1 -1
  14. package/dist/PerpsController.d.mts +91 -131
  15. package/dist/PerpsController.d.mts.map +1 -1
  16. package/dist/PerpsController.mjs +485 -182
  17. package/dist/PerpsController.mjs.map +1 -1
  18. package/dist/constants/eventNames.cjs +26 -0
  19. package/dist/constants/eventNames.cjs.map +1 -1
  20. package/dist/constants/eventNames.d.cts +19 -0
  21. package/dist/constants/eventNames.d.cts.map +1 -1
  22. package/dist/constants/eventNames.d.mts +19 -0
  23. package/dist/constants/eventNames.d.mts.map +1 -1
  24. package/dist/constants/eventNames.mjs +26 -0
  25. package/dist/constants/eventNames.mjs.map +1 -1
  26. package/dist/constants/hyperLiquidConfig.cjs +24 -4
  27. package/dist/constants/hyperLiquidConfig.cjs.map +1 -1
  28. package/dist/constants/hyperLiquidConfig.d.cts +8 -3
  29. package/dist/constants/hyperLiquidConfig.d.cts.map +1 -1
  30. package/dist/constants/hyperLiquidConfig.d.mts +8 -3
  31. package/dist/constants/hyperLiquidConfig.d.mts.map +1 -1
  32. package/dist/constants/hyperLiquidConfig.mjs +23 -3
  33. package/dist/constants/hyperLiquidConfig.mjs.map +1 -1
  34. package/dist/constants/myxConfig.cjs +75 -51
  35. package/dist/constants/myxConfig.cjs.map +1 -1
  36. package/dist/constants/myxConfig.d.cts +58 -19
  37. package/dist/constants/myxConfig.d.cts.map +1 -1
  38. package/dist/constants/myxConfig.d.mts +58 -19
  39. package/dist/constants/myxConfig.d.mts.map +1 -1
  40. package/dist/constants/myxConfig.mjs +74 -50
  41. package/dist/constants/myxConfig.mjs.map +1 -1
  42. package/dist/constants/perpsConfig.cjs +6 -2
  43. package/dist/constants/perpsConfig.cjs.map +1 -1
  44. package/dist/constants/perpsConfig.d.cts +5 -1
  45. package/dist/constants/perpsConfig.d.cts.map +1 -1
  46. package/dist/constants/perpsConfig.d.mts +5 -1
  47. package/dist/constants/perpsConfig.d.mts.map +1 -1
  48. package/dist/constants/perpsConfig.mjs +5 -1
  49. package/dist/constants/perpsConfig.mjs.map +1 -1
  50. package/dist/index.cjs +243 -25
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.d.cts +48 -5
  53. package/dist/index.d.cts.map +1 -1
  54. package/dist/index.d.mts +48 -5
  55. package/dist/index.d.mts.map +1 -1
  56. package/dist/index.mjs +36 -10
  57. package/dist/index.mjs.map +1 -1
  58. package/dist/providers/AggregatedPerpsProvider.cjs +24 -0
  59. package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
  60. package/dist/providers/AggregatedPerpsProvider.d.cts +4 -0
  61. package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
  62. package/dist/providers/AggregatedPerpsProvider.d.mts +4 -0
  63. package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
  64. package/dist/providers/AggregatedPerpsProvider.mjs +24 -0
  65. package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
  66. package/dist/providers/HyperLiquidProvider.cjs +470 -154
  67. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  68. package/dist/providers/HyperLiquidProvider.d.cts +11 -2
  69. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  70. package/dist/providers/HyperLiquidProvider.d.mts +11 -2
  71. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  72. package/dist/providers/HyperLiquidProvider.mjs +471 -155
  73. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  74. package/dist/selectors.cjs +1 -1
  75. package/dist/selectors.cjs.map +1 -1
  76. package/dist/selectors.mjs +1 -1
  77. package/dist/selectors.mjs.map +1 -1
  78. package/dist/services/AccountService.cjs +1 -1
  79. package/dist/services/AccountService.cjs.map +1 -1
  80. package/dist/services/AccountService.d.cts.map +1 -1
  81. package/dist/services/AccountService.d.mts.map +1 -1
  82. package/dist/services/AccountService.mjs +2 -2
  83. package/dist/services/AccountService.mjs.map +1 -1
  84. package/dist/services/DepositService.cjs +2 -1
  85. package/dist/services/DepositService.cjs.map +1 -1
  86. package/dist/services/DepositService.d.cts.map +1 -1
  87. package/dist/services/DepositService.d.mts.map +1 -1
  88. package/dist/services/DepositService.mjs +2 -1
  89. package/dist/services/DepositService.mjs.map +1 -1
  90. package/dist/services/EligibilityService.cjs +8 -103
  91. package/dist/services/EligibilityService.cjs.map +1 -1
  92. package/dist/services/EligibilityService.d.cts +4 -15
  93. package/dist/services/EligibilityService.d.cts.map +1 -1
  94. package/dist/services/EligibilityService.d.mts +4 -15
  95. package/dist/services/EligibilityService.d.mts.map +1 -1
  96. package/dist/services/EligibilityService.mjs +8 -103
  97. package/dist/services/EligibilityService.mjs.map +1 -1
  98. package/dist/services/HyperLiquidSubscriptionService.cjs +252 -46
  99. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  100. package/dist/services/HyperLiquidSubscriptionService.d.cts +1 -0
  101. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  102. package/dist/services/HyperLiquidSubscriptionService.d.mts +1 -0
  103. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  104. package/dist/services/HyperLiquidSubscriptionService.mjs +252 -46
  105. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  106. package/dist/services/MarketDataService.cjs +2 -4
  107. package/dist/services/MarketDataService.cjs.map +1 -1
  108. package/dist/services/MarketDataService.d.cts.map +1 -1
  109. package/dist/services/MarketDataService.d.mts.map +1 -1
  110. package/dist/services/MarketDataService.mjs +2 -4
  111. package/dist/services/MarketDataService.mjs.map +1 -1
  112. package/dist/services/TradingService.cjs +72 -6
  113. package/dist/services/TradingService.cjs.map +1 -1
  114. package/dist/services/TradingService.d.cts.map +1 -1
  115. package/dist/services/TradingService.d.mts.map +1 -1
  116. package/dist/services/TradingService.mjs +72 -6
  117. package/dist/services/TradingService.mjs.map +1 -1
  118. package/dist/types/index.cjs.map +1 -1
  119. package/dist/types/index.d.cts +51 -3
  120. package/dist/types/index.d.cts.map +1 -1
  121. package/dist/types/index.d.mts +51 -3
  122. package/dist/types/index.d.mts.map +1 -1
  123. package/dist/types/index.mjs.map +1 -1
  124. package/dist/types/messenger.cjs.map +1 -1
  125. package/dist/types/messenger.d.cts +2 -1
  126. package/dist/types/messenger.d.cts.map +1 -1
  127. package/dist/types/messenger.d.mts +2 -1
  128. package/dist/types/messenger.d.mts.map +1 -1
  129. package/dist/types/messenger.mjs.map +1 -1
  130. package/dist/types/myx-types.cjs +19 -3
  131. package/dist/types/myx-types.cjs.map +1 -1
  132. package/dist/types/myx-types.d.cts +33 -2
  133. package/dist/types/myx-types.d.cts.map +1 -1
  134. package/dist/types/myx-types.d.mts +33 -2
  135. package/dist/types/myx-types.d.mts.map +1 -1
  136. package/dist/types/myx-types.mjs +6 -2
  137. package/dist/types/myx-types.mjs.map +1 -1
  138. package/dist/types/perps-types.cjs +3 -0
  139. package/dist/types/perps-types.cjs.map +1 -1
  140. package/dist/types/perps-types.d.cts +3 -3
  141. package/dist/types/perps-types.d.cts.map +1 -1
  142. package/dist/types/perps-types.d.mts +3 -3
  143. package/dist/types/perps-types.d.mts.map +1 -1
  144. package/dist/types/perps-types.mjs +3 -0
  145. package/dist/types/perps-types.mjs.map +1 -1
  146. package/dist/utils/accountUtils.cjs.map +1 -1
  147. package/dist/utils/accountUtils.d.cts.map +1 -1
  148. package/dist/utils/accountUtils.d.mts.map +1 -1
  149. package/dist/utils/accountUtils.mjs.map +1 -1
  150. package/dist/utils/myxAdapter.cjs +360 -15
  151. package/dist/utils/myxAdapter.cjs.map +1 -1
  152. package/dist/utils/myxAdapter.d.cts +94 -7
  153. package/dist/utils/myxAdapter.d.cts.map +1 -1
  154. package/dist/utils/myxAdapter.d.mts +94 -7
  155. package/dist/utils/myxAdapter.d.mts.map +1 -1
  156. package/dist/utils/myxAdapter.mjs +351 -16
  157. package/dist/utils/myxAdapter.mjs.map +1 -1
  158. package/package.json +4 -2
@@ -10,10 +10,11 @@ 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_globalBboSubscriptions, _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_cachedFills, _HyperLiquidSubscriptionService_fillsCacheInitialized, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, _HyperLiquidSubscriptionService_dexAssetCtxsCache, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, _HyperLiquidSubscriptionService_openOrdersSubscriptions, _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions, _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions, _HyperLiquidSubscriptionService_dexMetaCache, _HyperLiquidSubscriptionService_orderBookCache, _HyperLiquidSubscriptionService_marketDataCache, _HyperLiquidSubscriptionService_isClearing, _HyperLiquidSubscriptionService_deps, _HyperLiquidSubscriptionService_logErrorUnlessClearing, _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_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_globalBboSubscriptions, _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;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.HyperLiquidSubscriptionService = void 0;
16
16
  const perpsConfig_1 = require("../constants/perpsConfig.cjs");
17
+ const types_1 = require("../types/index.cjs");
17
18
  const accountUtils_1 = require("../utils/accountUtils.cjs");
18
19
  const errorUtils_1 = require("../utils/errorUtils.cjs");
19
20
  const hyperLiquidAdapter_1 = require("../utils/hyperLiquidAdapter.cjs");
@@ -85,6 +86,8 @@ class HyperLiquidSubscriptionService {
85
86
  _HyperLiquidSubscriptionService_oiCapsCacheInitialized.set(this, false);
86
87
  // Global price data cache
87
88
  _HyperLiquidSubscriptionService_cachedPriceData.set(this, null);
89
+ // Raw allMids WS snapshots keyed by DEX ('' for main DEX)
90
+ _HyperLiquidSubscriptionService_allMidsSnapshots.set(this, new Map());
88
91
  // Fills cache for cache-first pattern (similar to price caching)
89
92
  _HyperLiquidSubscriptionService_cachedFills.set(this, null);
90
93
  _HyperLiquidSubscriptionService_fillsCacheInitialized.set(this, false);
@@ -92,6 +95,8 @@ class HyperLiquidSubscriptionService {
92
95
  _HyperLiquidSubscriptionService_assetCtxsSubscriptions.set(this, new Map()); // Key: dex name ('' for main)
93
96
  _HyperLiquidSubscriptionService_dexAssetCtxsCache.set(this, new Map()); // Per-DEX asset contexts
94
97
  _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises.set(this, new Map()); // Track in-progress subscriptions
98
+ _HyperLiquidSubscriptionService_dexAllMidsSubscriptions.set(this, new Map());
99
+ _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises.set(this, new Map());
95
100
  _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions.set(this, new Map()); // Key: dex name ('' for main)
96
101
  _HyperLiquidSubscriptionService_openOrdersSubscriptions.set(this, new Map()); // Key: dex name ('' for main)
97
102
  // Pending subscription promises to prevent race conditions
@@ -109,6 +114,7 @@ class HyperLiquidSubscriptionService {
109
114
  // Flag to suppress error logging during intentional disconnect
110
115
  // Set in clearAll() and never reset (service instance is discarded after disconnect)
111
116
  _HyperLiquidSubscriptionService_isClearing.set(this, false);
117
+ _HyperLiquidSubscriptionService_restoreRetryTimeouts.set(this, new Map());
112
118
  // Platform dependencies for logging
113
119
  _HyperLiquidSubscriptionService_deps.set(this, void 0);
114
120
  // Cache hashes to avoid recomputation
@@ -273,20 +279,30 @@ class HyperLiquidSubscriptionService {
273
279
  }
274
280
  // Ensure global subscriptions are established
275
281
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureGlobalAllMidsSubscription).call(this);
276
- // HIP-3: Establish assetCtxs subscriptions ONLY for DEXs with requested symbols
277
- // Performance: Avoid unnecessary WebSocket connections for unused DEXs
278
- if (includeMarketData) {
279
- // Extract unique DEXs from requested symbols
280
- const dexsNeeded = new Set();
281
- symbols.forEach((symbol) => {
282
- const { dex } = (0, hyperLiquidAdapter_1.parseAssetName)(symbol);
283
- dexsNeeded.add(dex);
282
+ // Extract unique DEXs from requested symbols
283
+ const dexsNeeded = new Set();
284
+ symbols.forEach((symbol) => {
285
+ const { dex } = (0, hyperLiquidAdapter_1.parseAssetName)(symbol);
286
+ dexsNeeded.add(dex);
287
+ });
288
+ // Always ensure assetCtxs subscriptions (1 per DEX, lightweight).
289
+ // Provides prevDayPx for percentChange24h even without includeMarketData
290
+ // (e.g., prewarm after reconnection). Uses incrementRefCount: false when
291
+ // not explicitly requested so lifecycle is managed by component subscriptions.
292
+ dexsNeeded.forEach((dex) => {
293
+ const dexName = dex ?? '';
294
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription).call(this, dexName, {
295
+ incrementRefCount: includeMarketData,
296
+ }).catch((error) => {
297
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToPrices'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToPrices.ensureAssetCtxsSubscription', { dex: dexName }));
284
298
  });
285
- // Only subscribe to DEXs that have requested symbols
299
+ });
300
+ // dexAllMids and activeAssetCtx only when market data explicitly requested
301
+ if (includeMarketData) {
286
302
  dexsNeeded.forEach((dex) => {
287
303
  const dexName = dex ?? '';
288
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription).call(this, dexName).catch((error) => {
289
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToPrices'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToPrices.ensureAssetCtxsSubscription', { dex: dexName }));
304
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription).call(this, dexName).catch((error) => {
305
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.subscribeToPrices'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'subscribeToPrices.ensureDexAllMidsSubscription', { dex: dexName }));
290
306
  });
291
307
  });
292
308
  }
@@ -324,13 +340,6 @@ class HyperLiquidSubscriptionService {
324
340
  });
325
341
  // Cleanup DEX-level assetCtxs subscriptions
326
342
  if (includeMarketData) {
327
- // Extract unique DEXs from requested symbols
328
- const dexsNeeded = new Set();
329
- symbols.forEach((symbol) => {
330
- const { dex } = (0, hyperLiquidAdapter_1.parseAssetName)(symbol);
331
- dexsNeeded.add(dex);
332
- });
333
- // Cleanup assetCtxs subscription for each DEX
334
343
  dexsNeeded.forEach((dex) => {
335
344
  const dexName = dex ?? '';
336
345
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_cleanupAssetCtxsSubscription).call(this, dexName);
@@ -536,6 +545,14 @@ class HyperLiquidSubscriptionService {
536
545
  getCachedPrice(symbol) {
537
546
  return __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedPriceData, "f")?.get(symbol)?.price;
538
547
  }
548
+ getLastAllMidsSnapshot(dex) {
549
+ const dexKey = dex ?? '';
550
+ const snapshot = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").get(dexKey);
551
+ if (!snapshot) {
552
+ return null;
553
+ }
554
+ return { ...snapshot };
555
+ }
539
556
  /**
540
557
  * Get cached fills from WebSocket userFills subscription
541
558
  * OPTIMIZATION: Use this instead of REST userFills() to avoid rate limiting
@@ -708,8 +725,8 @@ class HyperLiquidSubscriptionService {
708
725
  // Clear existing subscriptions (they're dead after reconnection)
709
726
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").clear();
710
727
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").clear();
711
- // Clear reference counts to prevent double-counting after reconnection
712
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").clear();
728
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").clear();
729
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").clear();
713
730
  // Re-establish subscriptions for all DEXs with market data subscribers
714
731
  const dexsNeeded = new Set();
715
732
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_marketDataSubscribers, "f").forEach((_subscribers, symbol) => {
@@ -726,10 +743,46 @@ class HyperLiquidSubscriptionService {
726
743
  if (hasMainDexSubscribers) {
727
744
  dexsNeeded.add('');
728
745
  }
729
- // Re-establish subscriptions
730
- await Promise.all(Array.from(dexsNeeded).map((dex) => __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription).call(this, dex).catch(() => {
731
- // Ignore errors during assetCtxs subscription restoration
732
- })));
746
+ const marketDataRestoreOperations = Array.from(dexsNeeded).flatMap((dex) => {
747
+ const operations = [
748
+ {
749
+ dex,
750
+ kind: 'assetCtxs',
751
+ promise: __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription).call(this, dex, {
752
+ incrementRefCount: false,
753
+ }),
754
+ },
755
+ ];
756
+ if (dex) {
757
+ operations.push({
758
+ dex,
759
+ kind: 'allMids',
760
+ promise: __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription).call(this, dex),
761
+ });
762
+ }
763
+ return operations;
764
+ });
765
+ const marketDataRestoreResults = await Promise.allSettled(marketDataRestoreOperations.map(({ promise }) => promise));
766
+ const marketDataRestoreFailures = marketDataRestoreResults.flatMap((result, index) => {
767
+ if (result.status === 'fulfilled') {
768
+ return [];
769
+ }
770
+ const operation = marketDataRestoreOperations[index];
771
+ return [
772
+ {
773
+ ...operation,
774
+ error: (0, errorUtils_1.ensureError)(result.reason, 'HyperLiquidSubscriptionService.restoreSubscriptions'),
775
+ },
776
+ ];
777
+ });
778
+ if (marketDataRestoreFailures.length > 0) {
779
+ marketDataRestoreFailures.forEach(({ dex, kind }) => {
780
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_scheduleRestoreRetry).call(this, dex, kind);
781
+ });
782
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, new Error(`Failed to restore ${marketDataRestoreFailures.length} market data subscriptions`), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'restoreSubscriptions.marketData', {
783
+ failures: marketDataRestoreFailures.map(({ dex, kind, error }) => `${kind}:${dex || 'main'}:${error.message}`),
784
+ }));
785
+ }
733
786
  }
734
787
  }
735
788
  /**
@@ -757,6 +810,7 @@ class HyperLiquidSubscriptionService {
757
810
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_orderFillSubscriptions, "f").clear();
758
811
  // Clear cached data
759
812
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPriceData, null, "f");
813
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").clear();
760
814
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPositions, null, "f");
761
815
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedOrders, null, "f");
762
816
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccount, null, "f");
@@ -787,6 +841,7 @@ class HyperLiquidSubscriptionService {
787
841
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAssetCtxsCache, "f").clear();
788
842
  // Clear subscription references (actual cleanup handled by client service)
789
843
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_globalAllMidsSubscription, undefined, "f");
844
+ __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_globalAllMidsPromise, undefined, "f");
790
845
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions, "f").clear();
791
846
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_globalBboSubscriptions, "f").clear();
792
847
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_webData3Subscriptions, "f").clear();
@@ -794,6 +849,13 @@ class HyperLiquidSubscriptionService {
794
849
  // HIP-3: Clear assetCtxs subscriptions (clearinghouseState no longer needed with webData3)
795
850
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").clear();
796
851
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").clear();
852
+ // HIP-3: Clear per-DEX allMids subscriptions
853
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").clear();
854
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").clear();
855
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_restoreRetryTimeouts, "f").forEach((timeoutId) => {
856
+ clearTimeout(timeoutId);
857
+ });
858
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_restoreRetryTimeouts, "f").clear();
797
859
  // Cleanup individual subscriptions (clearinghouseState + openOrders)
798
860
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, "f").size > 0) {
799
861
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, "f").forEach((subscription, dexName) => {
@@ -821,11 +883,49 @@ class HyperLiquidSubscriptionService {
821
883
  }
822
884
  }
823
885
  exports.HyperLiquidSubscriptionService = HyperLiquidSubscriptionService;
824
- _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_globalBboSubscriptions = 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_cachedFills = new WeakMap(), _HyperLiquidSubscriptionService_fillsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAssetCtxsCache = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises = 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_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) {
886
+ _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_globalBboSubscriptions = 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) {
825
887
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_isClearing, "f")) {
826
888
  return;
827
889
  }
828
890
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").logger.error(error, context);
891
+ }, _HyperLiquidSubscriptionService_isTransientAssetCtxsError = function _HyperLiquidSubscriptionService_isTransientAssetCtxsError(error) {
892
+ const ensuredError = (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.createAssetCtxsSubscription');
893
+ const connectionState = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getConnectionState?.();
894
+ const messageParts = [
895
+ ensuredError.message,
896
+ error instanceof Error ? error.name : '',
897
+ typeof error === 'string' ? error : '',
898
+ String(error),
899
+ ]
900
+ .join(' ')
901
+ .toLowerCase();
902
+ const isReconnectChurn = connectionState === types_1.WebSocketConnectionState.Connecting ||
903
+ connectionState === types_1.WebSocketConnectionState.Disconnected;
904
+ return (messageParts.includes('websocketrequesterror') ||
905
+ messageParts.includes('unknown error while making a websocket request') ||
906
+ (isReconnectChurn &&
907
+ (messageParts.includes('unknown error (no details provided)') ||
908
+ messageParts.includes('undefined'))));
909
+ }, _HyperLiquidSubscriptionService_scheduleRestoreRetry = function _HyperLiquidSubscriptionService_scheduleRestoreRetry(dex, kind) {
910
+ const retryKey = `${kind}:${dex}`;
911
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_isClearing, "f") || __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_restoreRetryTimeouts, "f").has(retryKey)) {
912
+ return;
913
+ }
914
+ const timeoutId = setTimeout(() => {
915
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_restoreRetryTimeouts, "f").delete(retryKey);
916
+ const retryPromise = kind === 'assetCtxs'
917
+ ? __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription).call(this, dex, {
918
+ incrementRefCount: false,
919
+ })
920
+ : __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription).call(this, dex);
921
+ retryPromise.catch((error) => {
922
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.restoreSubscriptions.retry'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'restoreSubscriptions.retry', {
923
+ dex,
924
+ kind,
925
+ }));
926
+ });
927
+ }, 1000);
928
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_restoreRetryTimeouts, "f").set(retryKey, timeoutId);
829
929
  }, _HyperLiquidSubscriptionService_getErrorContext = function _HyperLiquidSubscriptionService_getErrorContext(method, extra) {
830
930
  return {
831
931
  tags: {
@@ -1774,6 +1874,8 @@ async function _HyperLiquidSubscriptionService_ensureOrderFillISubscription(acco
1774
1874
  wsMetrics.lastMessageTime = Date.now();
1775
1875
  // Initialize cache if needed
1776
1876
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedPriceData, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedPriceData, "f") ?? new Map(), "f");
1877
+ // Store raw snapshot for the main DEX so market fetches can reuse it without REST.
1878
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").set('', data.mids);
1777
1879
  const subscribedSymbols = new Set();
1778
1880
  // Collect all symbols that have subscribers
1779
1881
  for (const [symbol, subscriberSet,] of __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_priceSubscribers, "f").entries()) {
@@ -1921,32 +2023,98 @@ async function _HyperLiquidSubscriptionService_ensureOrderFillISubscription(acco
1921
2023
  * Implements reference counting to track active subscribers per DEX
1922
2024
  *
1923
2025
  * @param dex - The DEX identifier (empty string for main DEX).
2026
+ * @param options - Subscription behavior overrides.
2027
+ * @param options.incrementRefCount - Skip incrementing when restoring existing subscribers after reconnect.
1924
2028
  */
1925
- async function _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription(dex) {
2029
+ async function _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription(dex, options = {}) {
1926
2030
  const dexKey = dex || '';
1927
- // Increment subscriber count for this DEX
1928
- const currentCount = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").get(dexKey) ?? 0;
1929
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").set(dexKey, currentCount + 1);
2031
+ const { incrementRefCount = true } = options;
2032
+ if (incrementRefCount) {
2033
+ const currentCount = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").get(dexKey) ?? 0;
2034
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").set(dexKey, currentCount + 1);
2035
+ }
1930
2036
  // Return if subscription already exists
1931
2037
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").has(dexKey)) {
1932
2038
  return;
1933
2039
  }
1934
- // Await existing promise if subscription is being established
1935
- if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").has(dexKey)) {
1936
- await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").get(dexKey);
2040
+ let promise = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").get(dexKey);
2041
+ if (!promise) {
2042
+ promise = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_createAssetCtxsSubscription).call(this, dex);
2043
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").set(dexKey, promise);
2044
+ }
2045
+ try {
2046
+ await promise;
2047
+ }
2048
+ catch (error) {
2049
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").get(dexKey) === promise) {
2050
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").delete(dexKey);
2051
+ }
2052
+ if (incrementRefCount) {
2053
+ const currentCount = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").get(dexKey) ?? 0;
2054
+ if (currentCount <= 1) {
2055
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").delete(dexKey);
2056
+ }
2057
+ else {
2058
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").set(dexKey, currentCount - 1);
2059
+ }
2060
+ }
2061
+ throw error;
2062
+ }
2063
+ }, _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription =
2064
+ /**
2065
+ * Ensure a per-DEX allMids WS subscription exists (singleton per DEX).
2066
+ * Mirrors the assetCtxs subscription dedup pattern and is used only for HIP-3 DEXs.
2067
+ *
2068
+ * @param dex - The HIP-3 DEX name.
2069
+ */
2070
+ async function _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription(dex) {
2071
+ if (!dex) {
2072
+ return;
2073
+ }
2074
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").has(dex)) {
1937
2075
  return;
1938
2076
  }
1939
- // Create new subscription promise
1940
- const promise = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_createAssetCtxsSubscription).call(this, dex);
1941
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").set(dexKey, promise);
2077
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").has(dex)) {
2078
+ await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").get(dex);
2079
+ return;
2080
+ }
2081
+ const promise = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_createDexAllMidsSubscription).call(this, dex);
2082
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").set(dex, promise);
1942
2083
  try {
1943
2084
  await promise;
1944
2085
  }
1945
2086
  catch (error) {
1946
- // Clear promise on error so it can be retried
1947
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").delete(dexKey);
2087
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").delete(dex);
1948
2088
  throw error;
1949
2089
  }
2090
+ }, _HyperLiquidSubscriptionService_createDexAllMidsSubscription =
2091
+ /**
2092
+ * Create allMids WS subscription for a specific HIP-3 DEX.
2093
+ *
2094
+ * @param dex - The HIP-3 DEX name.
2095
+ */
2096
+ async function _HyperLiquidSubscriptionService_createDexAllMidsSubscription(dex) {
2097
+ await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").ensureSubscriptionClient(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").createWalletAdapter());
2098
+ const subscriptionClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getSubscriptionClient();
2099
+ if (!subscriptionClient) {
2100
+ throw new Error('Subscription client not initialized');
2101
+ }
2102
+ return new Promise((resolve, reject) => {
2103
+ subscriptionClient
2104
+ .allMids({ dex }, (data) => {
2105
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").set(dex, data.mids);
2106
+ })
2107
+ .then((sub) => {
2108
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").set(dex, sub);
2109
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log(`allMids subscription established for DEX: ${dex}`);
2110
+ resolve();
2111
+ return undefined;
2112
+ })
2113
+ .catch((error) => {
2114
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.createDexAllMidsSubscription'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'createDexAllMidsSubscription', { dex }));
2115
+ reject((0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.createDexAllMidsSubscription'));
2116
+ });
2117
+ });
1950
2118
  }, _HyperLiquidSubscriptionService_createAssetCtxsSubscription =
1951
2119
  /**
1952
2120
  * Create assetCtxs subscription for specific DEX
@@ -1990,8 +2158,7 @@ async function _HyperLiquidSubscriptionService_createAssetCtxsSubscription(dex)
1990
2158
  });
1991
2159
  return new Promise((resolve, reject) => {
1992
2160
  const subscriptionParams = dex ? { dex } : {};
1993
- subscriptionClient
1994
- .assetCtxs(subscriptionParams, (data) => {
2161
+ const handleAssetCtxsUpdate = (data) => {
1995
2162
  // Cache asset contexts for this DEX
1996
2163
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAssetCtxsCache, "f").set(dexKey, data.ctxs);
1997
2164
  // Use cached meta to map ctxs array indices to symbols (no REST API call!)
@@ -2030,7 +2197,33 @@ async function _HyperLiquidSubscriptionService_createAssetCtxsSubscription(dex)
2030
2197
  });
2031
2198
  // Notify price subscribers with updated market data
2032
2199
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_notifyAllPriceSubscribers).call(this);
2033
- })
2200
+ };
2201
+ const subscribeWithRetry = async () => {
2202
+ const maxAttempts = 3;
2203
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2204
+ try {
2205
+ return await subscriptionClient.assetCtxs(subscriptionParams, handleAssetCtxsUpdate);
2206
+ }
2207
+ catch (error) {
2208
+ const ensuredError = (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.createAssetCtxsSubscription');
2209
+ const isLastAttempt = attempt === maxAttempts;
2210
+ if (isLastAttempt ||
2211
+ !__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_isTransientAssetCtxsError).call(this, ensuredError)) {
2212
+ throw ensuredError;
2213
+ }
2214
+ const retryDelayMs = attempt * 500;
2215
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log('Transient assetCtxs subscription failure during reconnect, retrying', {
2216
+ dex: dexKey || 'main',
2217
+ attempt,
2218
+ retryDelayMs,
2219
+ error: ensuredError.message,
2220
+ });
2221
+ await new Promise((_resolve) => setTimeout(_resolve, retryDelayMs));
2222
+ }
2223
+ }
2224
+ throw new Error(`Failed to establish assetCtxs subscription for ${dexIdentifier}`);
2225
+ };
2226
+ subscribeWithRetry()
2034
2227
  .then((sub) => {
2035
2228
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").set(dexKey, sub);
2036
2229
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log(`assetCtxs subscription established for ${dex ? `DEX: ${dex}` : 'main DEX'}`);
@@ -2049,16 +2242,29 @@ async function _HyperLiquidSubscriptionService_createAssetCtxsSubscription(dex)
2049
2242
  if (currentCount <= 1) {
2050
2243
  // Last subscriber - cleanup the subscription
2051
2244
  const subscription = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").get(dexKey);
2245
+ const allMidsSubscription = dex
2246
+ ? __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").get(dex)
2247
+ : undefined;
2052
2248
  if (subscription) {
2053
2249
  subscription.unsubscribe().catch((error) => {
2054
2250
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.cleanupAssetCtxsSubscription'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'cleanupAssetCtxsSubscription', { dex }));
2055
2251
  });
2056
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").delete(dexKey);
2057
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAssetCtxsCache, "f").delete(dexKey);
2058
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").delete(dexKey);
2059
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").delete(dexKey);
2060
- __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log(`Cleaned up assetCtxs subscription for ${dex ? `DEX: ${dex}` : 'main DEX'}`);
2061
2252
  }
2253
+ if (allMidsSubscription) {
2254
+ allMidsSubscription.unsubscribe().catch((error) => {
2255
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.cleanupDexAllMidsSubscription'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'cleanupDexAllMidsSubscription', { dex }));
2256
+ });
2257
+ }
2258
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, "f").delete(dexKey);
2259
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAssetCtxsCache, "f").delete(dexKey);
2260
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, "f").delete(dexKey);
2261
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexSubscriberCounts, "f").delete(dexKey);
2262
+ if (dex) {
2263
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, "f").delete(dex);
2264
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, "f").delete(dex);
2265
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_allMidsSnapshots, "f").delete(dex);
2266
+ }
2267
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log(`Cleaned up assetCtxs subscription for ${dex ? `DEX: ${dex}` : 'main DEX'}`);
2062
2268
  }
2063
2269
  else {
2064
2270
  // Still has subscribers - just decrement count