@metamask-previews/perps-controller 5.0.0-preview-4e0ae1bc9 → 5.0.0-preview-bd0d4d2e9

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 (76) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/constants/hyperLiquidConfig.cjs +1 -1
  3. package/dist/constants/hyperLiquidConfig.cjs.map +1 -1
  4. package/dist/constants/hyperLiquidConfig.d.cts +1 -1
  5. package/dist/constants/hyperLiquidConfig.d.mts +1 -1
  6. package/dist/constants/hyperLiquidConfig.mjs +1 -1
  7. package/dist/constants/hyperLiquidConfig.mjs.map +1 -1
  8. package/dist/constants/perpsConfig.cjs +15 -3
  9. package/dist/constants/perpsConfig.cjs.map +1 -1
  10. package/dist/constants/perpsConfig.d.cts +8 -1
  11. package/dist/constants/perpsConfig.d.cts.map +1 -1
  12. package/dist/constants/perpsConfig.d.mts +8 -1
  13. package/dist/constants/perpsConfig.d.mts.map +1 -1
  14. package/dist/constants/perpsConfig.mjs +14 -2
  15. package/dist/constants/perpsConfig.mjs.map +1 -1
  16. package/dist/providers/HyperLiquidProvider.cjs +33 -21
  17. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  18. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  19. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  20. package/dist/providers/HyperLiquidProvider.mjs +33 -21
  21. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  22. package/dist/services/HyperLiquidSubscriptionService.cjs +127 -27
  23. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  24. package/dist/services/HyperLiquidSubscriptionService.d.cts +4 -12
  25. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  26. package/dist/services/HyperLiquidSubscriptionService.d.mts +4 -12
  27. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  28. package/dist/services/HyperLiquidSubscriptionService.mjs +128 -28
  29. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  30. package/dist/types/hyperliquid-types.cjs +11 -8
  31. package/dist/types/hyperliquid-types.cjs.map +1 -1
  32. package/dist/types/hyperliquid-types.d.cts +24 -9
  33. package/dist/types/hyperliquid-types.d.cts.map +1 -1
  34. package/dist/types/hyperliquid-types.d.mts +24 -9
  35. package/dist/types/hyperliquid-types.d.mts.map +1 -1
  36. package/dist/types/hyperliquid-types.mjs +11 -8
  37. package/dist/types/hyperliquid-types.mjs.map +1 -1
  38. package/dist/types/index.cjs.map +1 -1
  39. package/dist/types/index.d.cts +26 -3
  40. package/dist/types/index.d.cts.map +1 -1
  41. package/dist/types/index.d.mts +26 -3
  42. package/dist/types/index.d.mts.map +1 -1
  43. package/dist/types/index.mjs.map +1 -1
  44. package/dist/utils/accountUtils.cjs +49 -35
  45. package/dist/utils/accountUtils.cjs.map +1 -1
  46. package/dist/utils/accountUtils.d.cts +30 -4
  47. package/dist/utils/accountUtils.d.cts.map +1 -1
  48. package/dist/utils/accountUtils.d.mts +30 -4
  49. package/dist/utils/accountUtils.d.mts.map +1 -1
  50. package/dist/utils/accountUtils.mjs +49 -35
  51. package/dist/utils/accountUtils.mjs.map +1 -1
  52. package/dist/utils/hyperLiquidAdapter.cjs +3 -2
  53. package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
  54. package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
  55. package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
  56. package/dist/utils/hyperLiquidAdapter.mjs +3 -2
  57. package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
  58. package/dist/utils/hyperLiquidValidation.cjs +11 -11
  59. package/dist/utils/hyperLiquidValidation.cjs.map +1 -1
  60. package/dist/utils/hyperLiquidValidation.d.cts +2 -2
  61. package/dist/utils/hyperLiquidValidation.d.cts.map +1 -1
  62. package/dist/utils/hyperLiquidValidation.d.mts +2 -2
  63. package/dist/utils/hyperLiquidValidation.d.mts.map +1 -1
  64. package/dist/utils/hyperLiquidValidation.mjs +11 -11
  65. package/dist/utils/hyperLiquidValidation.mjs.map +1 -1
  66. package/dist/utils/myxAdapter.cjs +2 -2
  67. package/dist/utils/myxAdapter.cjs.map +1 -1
  68. package/dist/utils/myxAdapter.mjs +2 -2
  69. package/dist/utils/myxAdapter.mjs.map +1 -1
  70. package/dist/utils/orderCalculations.cjs +5 -5
  71. package/dist/utils/orderCalculations.cjs.map +1 -1
  72. package/dist/utils/orderCalculations.d.cts +1 -1
  73. package/dist/utils/orderCalculations.d.mts +1 -1
  74. package/dist/utils/orderCalculations.mjs +5 -5
  75. package/dist/utils/orderCalculations.mjs.map +1 -1
  76. 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_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_abstractionModeByUser, _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_getAbstractionModeForUser, _HyperLiquidSubscriptionService_getSpotBalanceOptions, _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;
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_abstractionModeByUser, _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, _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_getAbstractionModeForUser, _HyperLiquidSubscriptionService_getSpotBalanceOptions, _HyperLiquidSubscriptionService_refreshAbstractionModeThrottled, _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");
@@ -88,8 +88,21 @@ class HyperLiquidSubscriptionService {
88
88
  _HyperLiquidSubscriptionService_dexOrdersCache.set(this, new Map()); // Per-DEX orders
89
89
  _HyperLiquidSubscriptionService_dexAccountCache.set(this, new Map()); // Per-DEX account state
90
90
  _HyperLiquidSubscriptionService_cachedSpotState.set(this, null);
91
- _HyperLiquidSubscriptionService_cachedSpotStateUserAddress.set(this, null);
91
+ // HL abstraction mode (Unified / Standard / Portfolio / DEX-abstraction).
92
+ // Gates spot→perps folding in addSpotBalanceToAccountState. Keyed by user
93
+ // address so an in-flight refresh or late response for one wallet cannot
94
+ // overwrite another wallet's fold semantics after an account switch.
92
95
  _HyperLiquidSubscriptionService_abstractionModeByUser.set(this, new Map());
96
+ // Timestamp of the last successful WS-driven userAbstraction refresh per
97
+ // user. This throttle intentionally does not count the initial bootstrap
98
+ // fetch so the first spot tick after app launch can still detect an HL-web
99
+ // mode flip immediately.
100
+ _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser.set(this, new Map());
101
+ // In-flight promises for WS-triggered refreshes, keyed by user so concurrent
102
+ // ticks for the same wallet share one fetch while account switches can start
103
+ // their own refresh immediately.
104
+ _HyperLiquidSubscriptionService_abstractionModeInflightByUser.set(this, new Map());
105
+ _HyperLiquidSubscriptionService_cachedSpotStateUserAddress.set(this, null);
93
106
  _HyperLiquidSubscriptionService_spotStatePromise.set(this, void 0);
94
107
  _HyperLiquidSubscriptionService_spotStatePromiseUserAddress.set(this, void 0);
95
108
  // Monotonic token bumped on cleanUp/clearAll and on each new fetch.
@@ -276,16 +289,8 @@ class HyperLiquidSubscriptionService {
276
289
  /**
277
290
  * Record a user's resolved abstraction mode and immediately re-aggregate.
278
291
  * Call after the provider has confirmed the on-chain mode (already-enabled
279
- * or just-migrated). Setting the mode (rather than deleting it) ensures
280
- * `hyperLiquidModeFoldsSpot` returns the correct fold decision on the next
281
- * aggregation — a delete would leave the user pinned to fail-closed
282
- * (no fold) until the next refresh, under-reporting balance for Unified
283
- * and Portfolio Margin users.
284
- *
285
- * Seals `#cachedSpotStateUserAddress` if spot is already cached for this
286
- * user (fast-path optimization for the next `#ensureSpotState`). Skips the
287
- * seal if spot belongs to a different user — the next refresh will sort
288
- * everything out.
292
+ * or just-migrated) so the WS-driven aggregator picks up the correct fold
293
+ * decision on the next tick.
289
294
  *
290
295
  * @param userAddress - The EVM address whose mode is being recorded.
291
296
  * @param mode - The current abstraction mode for this user.
@@ -293,10 +298,6 @@ class HyperLiquidSubscriptionService {
293
298
  setUserAbstractionMode(userAddress, mode) {
294
299
  const lower = userAddress.toLowerCase();
295
300
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").set(lower, mode);
296
- // No need to seal #cachedSpotStateUserAddress here — the WS handler and
297
- // #refreshSpotState success path always set it to the spot owner. The
298
- // re-aggregation below will pick up the new mode via the now-populated
299
- // #abstractionModeByUser entry.
300
301
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
301
302
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
302
303
  }
@@ -915,6 +916,8 @@ class HyperLiquidSubscriptionService {
915
916
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
916
917
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
917
918
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").clear();
919
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser, "f").clear();
920
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").clear();
918
921
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
919
922
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, undefined, "f");
920
923
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, undefined, "f");
@@ -997,7 +1000,7 @@ class HyperLiquidSubscriptionService {
997
1000
  }
998
1001
  }
999
1002
  exports.HyperLiquidSubscriptionService = HyperLiquidSubscriptionService;
1000
- _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_abstractionModeByUser = 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) {
1003
+ _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_abstractionModeByUser = new WeakMap(), _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser = new WeakMap(), _HyperLiquidSubscriptionService_abstractionModeInflightByUser = 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) {
1001
1004
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_isClearing, "f")) {
1002
1005
  return;
1003
1006
  }
@@ -1113,7 +1116,7 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1113
1116
  .map((ord) => `${ord.symbol}:${ord.side}:${ord.size}:${ord.price}:${ord.orderType}`)
1114
1117
  .join('|');
1115
1118
  }, _HyperLiquidSubscriptionService_hashAccountState = function _HyperLiquidSubscriptionService_hashAccountState(account) {
1116
- return `${account.availableBalance}:${account.availableToTradeBalance ?? ''}:${account.totalBalance}:${account.marginUsed}:${account.unrealizedPnl}`;
1119
+ return `${account.spendableBalance}:${account.withdrawableBalance}:${account.totalBalance}:${account.marginUsed}:${account.unrealizedPnl}`;
1117
1120
  }, _HyperLiquidSubscriptionService_extractTPSLFromOrders = function _HyperLiquidSubscriptionService_extractTPSLFromOrders(orders, positions, cachedProcessedOrders) {
1118
1121
  const tpslMap = new Map();
1119
1122
  const tpslCountMap = new Map();
@@ -1271,7 +1274,8 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1271
1274
  });
1272
1275
  }, _HyperLiquidSubscriptionService_aggregateAccountStates = function _HyperLiquidSubscriptionService_aggregateAccountStates() {
1273
1276
  const subAccountBreakdown = {};
1274
- let totalAvailableBalance = 0;
1277
+ let totalSpendableBalance = 0;
1278
+ let totalWithdrawableBalance = 0;
1275
1279
  let totalBalance = 0;
1276
1280
  let totalMarginUsed = 0;
1277
1281
  let totalUnrealizedPnl = 0;
@@ -1281,10 +1285,12 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1281
1285
  Array.from(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").entries()).forEach(([currentDex, state]) => {
1282
1286
  const dexKey = currentDex === '' ? 'main' : currentDex;
1283
1287
  subAccountBreakdown[dexKey] = {
1284
- availableBalance: state.availableBalance,
1288
+ spendableBalance: state.spendableBalance,
1289
+ withdrawableBalance: state.withdrawableBalance,
1285
1290
  totalBalance: state.totalBalance,
1286
1291
  };
1287
- totalAvailableBalance += parseFloat(state.availableBalance);
1292
+ totalSpendableBalance += parseFloat(state.spendableBalance);
1293
+ totalWithdrawableBalance += parseFloat(state.withdrawableBalance);
1288
1294
  totalBalance += parseFloat(state.totalBalance);
1289
1295
  totalMarginUsed += parseFloat(state.marginUsed);
1290
1296
  totalUnrealizedPnl += parseFloat(state.unrealizedPnl);
@@ -1300,7 +1306,8 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1300
1306
  const returnOnEquity = (0, accountUtils_1.calculateWeightedReturnOnEquity)(accountStatesForROE);
1301
1307
  return (0, accountUtils_1.addSpotBalanceToAccountState)({
1302
1308
  ...firstDexAccount,
1303
- availableBalance: totalAvailableBalance.toString(),
1309
+ spendableBalance: totalSpendableBalance.toString(),
1310
+ withdrawableBalance: totalWithdrawableBalance.toString(),
1304
1311
  totalBalance: totalBalance.toString(),
1305
1312
  marginUsed: totalMarginUsed.toString(),
1306
1313
  unrealizedPnl: totalUnrealizedPnl.toString(),
@@ -1316,6 +1323,75 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1316
1323
  return {
1317
1324
  foldIntoCollateral: (0, hyperliquid_types_1.hyperLiquidModeFoldsSpot)(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getAbstractionModeForUser).call(this, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f"))),
1318
1325
  };
1326
+ }, _HyperLiquidSubscriptionService_refreshAbstractionModeThrottled =
1327
+ /**
1328
+ * Fetch userAbstraction and update the cache, throttled so the long-lived
1329
+ * spotState WebSocket can trigger a background refresh on every tick
1330
+ * without burning REST quota. Handles HL-web mode flips propagating back
1331
+ * to mobile without requiring a restart or account switch.
1332
+ *
1333
+ * Concurrent callers share the same in-flight promise so an in-flight
1334
+ * fetch (especially a slow-failing one) doesn't ratchet the throttle
1335
+ * forward on every WS tick and leave mode stale during a network hang.
1336
+ *
1337
+ * @param userAddress - Current user address to refresh the cache for.
1338
+ * @returns Promise that resolves once the refresh completes (or immediately when throttled).
1339
+ */
1340
+ async function _HyperLiquidSubscriptionService_refreshAbstractionModeThrottled(userAddress) {
1341
+ const normalizedUser = userAddress.toLowerCase();
1342
+ const existing = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").get(normalizedUser);
1343
+ if (existing) {
1344
+ await existing;
1345
+ return undefined;
1346
+ }
1347
+ const now = Date.now();
1348
+ const lastWsRefreshAt = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser, "f").get(normalizedUser) ?? 0;
1349
+ if (now - lastWsRefreshAt < perpsConfig_1.ABSTRACTION_MODE_REFRESH_THROTTLE_MS) {
1350
+ return undefined;
1351
+ }
1352
+ const inflight = (async () => {
1353
+ try {
1354
+ const infoClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getInfoClient();
1355
+ const mode = await infoClient.userAbstraction({ user: userAddress });
1356
+ const previousMode = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").get(normalizedUser) ?? null;
1357
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").set(normalizedUser, mode);
1358
+ // Set timestamp only on success; a hanging/failed fetch must not
1359
+ // ratchet the throttle window forward (which would silence every
1360
+ // subsequent spot WS tick for the full throttle duration).
1361
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser, "f").set(normalizedUser, Date.now());
1362
+ // If the fold semantics actually changed for this user, trigger a
1363
+ // re-aggregation so balance-dependent UI (withdraw cap, order-entry
1364
+ // validation) picks up the new mode immediately — otherwise a
1365
+ // Unified→Standard flip can stay folded with old semantics until the
1366
+ // next spot/account event happens to arrive.
1367
+ const foldChanged = (0, hyperliquid_types_1.hyperLiquidModeFoldsSpot)(previousMode) !==
1368
+ (0, hyperliquid_types_1.hyperLiquidModeFoldsSpot)(mode);
1369
+ if (foldChanged && __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
1370
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
1371
+ }
1372
+ }
1373
+ catch (error) {
1374
+ // Non-fatal — preserve the last known mode for this user. Leave
1375
+ // timestamp at its previous value so a genuine retry on the next
1376
+ // WS tick is allowed (no forward ratchet on slow failures). Route
1377
+ // through the shared Sentry helper so repeated failures become
1378
+ // visible on the perps ops dashboard (consistent with other async
1379
+ // boundary errors in this file, e.g. #refreshSpotState).
1380
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_logErrorUnlessClearing).call(this, (0, errorUtils_1.ensureError)(error, 'HyperLiquidSubscriptionService.refreshAbstractionModeThrottled'), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getErrorContext).call(this, 'refreshAbstractionModeThrottled', {
1381
+ user: normalizedUser,
1382
+ }));
1383
+ }
1384
+ })();
1385
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").set(normalizedUser, inflight);
1386
+ try {
1387
+ await inflight;
1388
+ }
1389
+ finally {
1390
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").get(normalizedUser) === inflight) {
1391
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").delete(normalizedUser);
1392
+ }
1393
+ }
1394
+ return undefined;
1319
1395
  }, _HyperLiquidSubscriptionService_ensureSpotState = async function _HyperLiquidSubscriptionService_ensureSpotState(accountId) {
1320
1396
  const userAddress = await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").getUserAddressWithDefault(accountId);
1321
1397
  const lowerUserAddress = userAddress.toLowerCase();
@@ -1366,13 +1442,25 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1366
1442
  // correctly handles the generation-changed case (seal + re-aggregate
1367
1443
  // instead of overwriting WS spot).
1368
1444
  const infoClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getInfoClient();
1445
+ const lowerUserAddress = userAddress.toLowerCase();
1446
+ // Fetch spot state + abstraction mode in parallel — mode decides
1447
+ // whether the spot fold applies in addSpotBalanceToAccountState.
1448
+ // Register the userAbstraction call in `#abstractionModeInflightByUser`
1449
+ // so a concurrent WS-driven `#refreshAbstractionModeThrottled` awaits
1450
+ // this fetch instead of duplicating the REST round-trip.
1451
+ const abstractionFetch = infoClient.userAbstraction({
1452
+ user: userAddress,
1453
+ });
1454
+ const trackedAbstraction = abstractionFetch.then(() => undefined, () => undefined);
1455
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").set(lowerUserAddress, trackedAbstraction);
1369
1456
  const [spotResult, abstractionResult] = await Promise.allSettled([
1370
- infoClient.spotClearinghouseState({
1371
- user: userAddress,
1372
- }),
1373
- infoClient.userAbstraction({ user: userAddress }),
1457
+ infoClient.spotClearinghouseState({ user: userAddress }),
1458
+ abstractionFetch,
1374
1459
  ]);
1375
- const lowerUserAddress = userAddress.toLowerCase();
1460
+ if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").get(lowerUserAddress) ===
1461
+ trackedAbstraction) {
1462
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").delete(lowerUserAddress);
1463
+ }
1376
1464
  // Record the abstraction mode regardless of generation. The mode is
1377
1465
  // user-keyed (independent of the spot snapshot generation) so a WS
1378
1466
  // push that bumped generation while we awaited cannot make this
@@ -1454,6 +1542,14 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
1454
1542
  // Fast-path eligibility is gated separately in #ensureSpotState
1455
1543
  // by checking #abstractionModeByUser.has(...).
1456
1544
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, userAddress.toLowerCase(), "f");
1545
+ // Kick a throttled userAbstraction refresh so HL-web mode
1546
+ // flips (Unified → Standard or vice versa) propagate back to
1547
+ // mobile while the app stays open. Fire-and-forget: the
1548
+ // refresh updates the per-user abstraction-mode cache and the next
1549
+ // fold picks up the new value.
1550
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_refreshAbstractionModeThrottled).call(this, event.user.toLowerCase()).catch(() => {
1551
+ // Errors are logged inside the throttled refresh helper.
1552
+ });
1457
1553
  if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
1458
1554
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
1459
1555
  }
@@ -2027,6 +2123,10 @@ async function _HyperLiquidSubscriptionService_createOpenOrdersSubscription(user
2027
2123
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
2028
2124
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
2029
2125
  __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").clear();
2126
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeLastWsRefreshAtByUser, "f").clear();
2127
+ // Drop in-flight refresh handles so stale hanging userAbstraction
2128
+ // requests from the prior connection can't be awaited by future calls.
2129
+ __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeInflightByUser, "f").clear();
2030
2130
  // Bump generation so any in-flight spot fetch from a prior user discards
2031
2131
  // its result instead of re-populating the cache post-cleanup.
2032
2132
  __classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");