@metamask-previews/perps-controller 4.0.0-preview-e0eba6dbb → 4.0.0-preview-56dd1249f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/constants/eventNames.cjs +5 -0
- package/dist/constants/eventNames.cjs.map +1 -1
- package/dist/constants/eventNames.d.cts +4 -0
- package/dist/constants/eventNames.d.cts.map +1 -1
- package/dist/constants/eventNames.d.mts +4 -0
- package/dist/constants/eventNames.d.mts.map +1 -1
- package/dist/constants/eventNames.mjs +5 -0
- package/dist/constants/eventNames.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +230 -57
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +230 -57
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +108 -20
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts +19 -0
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts +19 -0
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +108 -20
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.cjs +20 -0
- package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.cts +6 -0
- package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.mts +6 -0
- package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
- package/dist/services/HyperLiquidWalletService.mjs +22 -2
- package/dist/services/HyperLiquidWalletService.mjs.map +1 -1
- package/dist/services/TradingReadinessCache.cjs +16 -16
- package/dist/services/TradingReadinessCache.cjs.map +1 -1
- package/dist/services/TradingReadinessCache.d.cts +12 -12
- package/dist/services/TradingReadinessCache.d.mts +12 -12
- package/dist/services/TradingReadinessCache.mjs +16 -16
- package/dist/services/TradingReadinessCache.mjs.map +1 -1
- package/dist/types/hyperliquid-types.cjs +39 -0
- package/dist/types/hyperliquid-types.cjs.map +1 -1
- package/dist/types/hyperliquid-types.d.cts +34 -2
- package/dist/types/hyperliquid-types.d.cts.map +1 -1
- package/dist/types/hyperliquid-types.d.mts +34 -2
- package/dist/types/hyperliquid-types.d.mts.map +1 -1
- package/dist/types/hyperliquid-types.mjs +37 -1
- package/dist/types/hyperliquid-types.mjs.map +1 -1
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +2 -1
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/accountUtils.cjs +20 -8
- package/dist/utils/accountUtils.cjs.map +1 -1
- package/dist/utils/accountUtils.d.cts +9 -5
- package/dist/utils/accountUtils.d.cts.map +1 -1
- package/dist/utils/accountUtils.d.mts +9 -5
- package/dist/utils/accountUtils.d.mts.map +1 -1
- package/dist/utils/accountUtils.mjs +20 -8
- package/dist/utils/accountUtils.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AssetCtxsWsEvent } from "@nktkas/hyperliquid";
|
|
2
2
|
import type { Position, OrderFill, Order, SubscribePricesParams, SubscribePositionsParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeAccountParams, SubscribeOICapsParams, SubscribeOrderBookParams, PerpsPlatformDependencies } from "../types/index.cjs";
|
|
3
|
+
import type { UserAbstractionResponse } from "../types/hyperliquid-types.cjs";
|
|
3
4
|
import type { HyperLiquidClientService } from "./HyperLiquidClientService.cjs";
|
|
4
5
|
import type { HyperLiquidWalletService } from "./HyperLiquidWalletService.cjs";
|
|
5
6
|
/**
|
|
@@ -52,6 +53,24 @@ export declare class HyperLiquidSubscriptionService {
|
|
|
52
53
|
* @param blocklistMarkets - The array of blocked market patterns.
|
|
53
54
|
*/
|
|
54
55
|
updateFeatureFlags(hip3Enabled: boolean, enabledDexs: string[], allowlistMarkets: string[], blocklistMarkets: string[]): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Record a user's resolved abstraction mode and immediately re-aggregate.
|
|
58
|
+
* Call after the provider has confirmed the on-chain mode (already-enabled
|
|
59
|
+
* or just-migrated). Setting the mode (rather than deleting it) ensures
|
|
60
|
+
* `hyperLiquidModeFoldsSpot` returns the correct fold decision on the next
|
|
61
|
+
* aggregation — a delete would leave the user pinned to fail-closed
|
|
62
|
+
* (no fold) until the next refresh, under-reporting balance for Unified
|
|
63
|
+
* and Portfolio Margin users.
|
|
64
|
+
*
|
|
65
|
+
* Seals `#cachedSpotStateUserAddress` if spot is already cached for this
|
|
66
|
+
* user (fast-path optimization for the next `#ensureSpotState`). Skips the
|
|
67
|
+
* seal if spot belongs to a different user — the next refresh will sort
|
|
68
|
+
* everything out.
|
|
69
|
+
*
|
|
70
|
+
* @param userAddress - The EVM address whose mode is being recorded.
|
|
71
|
+
* @param mode - The current abstraction mode for this user.
|
|
72
|
+
*/
|
|
73
|
+
setUserAbstractionMode(userAddress: string, mode: UserAbstractionResponse): void;
|
|
55
74
|
/**
|
|
56
75
|
* Subscribe to live price updates with singleton subscription architecture
|
|
57
76
|
* Uses allMids for fast price updates and predictedFundings for accurate funding rates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidSubscriptionService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAUV,gBAAgB,EAKjB,4BAA4B;AAI7B,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAE1B,2BAAiB;
|
|
1
|
+
{"version":3,"file":"HyperLiquidSubscriptionService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAUV,gBAAgB,EAKjB,4BAA4B;AAI7B,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAE1B,2BAAiB;AAElB,OAAO,KAAK,EAEV,uBAAuB,EACxB,uCAAmC;AAepC,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAE3E;;;GAGG;AACH,qBAAa,8BAA8B;;gBA0OvC,aAAa,EAAE,wBAAwB,EACvC,aAAa,EAAE,wBAAwB,EACvC,oBAAoB,EAAE,yBAAyB,EAC/C,WAAW,CAAC,EAAE,OAAO,EACrB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE;IA2I7B;;;;;;;;OAQG;IACI,eAAe,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,UAAU,EAAE,MAAM,CAAC;YACnB,WAAW,EAAE,MAAM,CAAC;SACrB,EAAE,CAAC;KACL,GACA,IAAI;IAWP;;;;;;OAMG;I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;;;;;OAKG;IACI,2BAA2B,IAAI,KAAK,EAAE,GAAG,IAAI;IAOpD;;;;;;OAMG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIlD,sBAAsB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAS1E;;;;;OAKG;IACI,cAAc,IAAI,SAAS,EAAE,GAAG,IAAI;IAI3C;;;;;;;;OAQG;IACI,0BAA0B,IAAI,SAAS,EAAE,GAAG,IAAI;IAs0BvD;;;;;;;OAOG;IACI,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,IAAI;IAmNzE;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsMlD;;OAEG;IACI,QAAQ,IAAI,IAAI;CA+LxB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AssetCtxsWsEvent } from "@nktkas/hyperliquid";
|
|
2
2
|
import type { Position, OrderFill, Order, SubscribePricesParams, SubscribePositionsParams, SubscribeOrderFillsParams, SubscribeOrdersParams, SubscribeAccountParams, SubscribeOICapsParams, SubscribeOrderBookParams, PerpsPlatformDependencies } from "../types/index.mjs";
|
|
3
|
+
import type { UserAbstractionResponse } from "../types/hyperliquid-types.mjs";
|
|
3
4
|
import type { HyperLiquidClientService } from "./HyperLiquidClientService.mjs";
|
|
4
5
|
import type { HyperLiquidWalletService } from "./HyperLiquidWalletService.mjs";
|
|
5
6
|
/**
|
|
@@ -52,6 +53,24 @@ export declare class HyperLiquidSubscriptionService {
|
|
|
52
53
|
* @param blocklistMarkets - The array of blocked market patterns.
|
|
53
54
|
*/
|
|
54
55
|
updateFeatureFlags(hip3Enabled: boolean, enabledDexs: string[], allowlistMarkets: string[], blocklistMarkets: string[]): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Record a user's resolved abstraction mode and immediately re-aggregate.
|
|
58
|
+
* Call after the provider has confirmed the on-chain mode (already-enabled
|
|
59
|
+
* or just-migrated). Setting the mode (rather than deleting it) ensures
|
|
60
|
+
* `hyperLiquidModeFoldsSpot` returns the correct fold decision on the next
|
|
61
|
+
* aggregation — a delete would leave the user pinned to fail-closed
|
|
62
|
+
* (no fold) until the next refresh, under-reporting balance for Unified
|
|
63
|
+
* and Portfolio Margin users.
|
|
64
|
+
*
|
|
65
|
+
* Seals `#cachedSpotStateUserAddress` if spot is already cached for this
|
|
66
|
+
* user (fast-path optimization for the next `#ensureSpotState`). Skips the
|
|
67
|
+
* seal if spot belongs to a different user — the next refresh will sort
|
|
68
|
+
* everything out.
|
|
69
|
+
*
|
|
70
|
+
* @param userAddress - The EVM address whose mode is being recorded.
|
|
71
|
+
* @param mode - The current abstraction mode for this user.
|
|
72
|
+
*/
|
|
73
|
+
setUserAbstractionMode(userAddress: string, mode: UserAbstractionResponse): void;
|
|
55
74
|
/**
|
|
56
75
|
* Subscribe to live price updates with singleton subscription architecture
|
|
57
76
|
* Uses allMids for fast price updates and predictedFundings for accurate funding rates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidSubscriptionService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAUV,gBAAgB,EAKjB,4BAA4B;AAI7B,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAE1B,2BAAiB;
|
|
1
|
+
{"version":3,"file":"HyperLiquidSubscriptionService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAUV,gBAAgB,EAKjB,4BAA4B;AAI7B,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EAC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;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsMlD;;OAEG;IACI,QAAQ,IAAI,IAAI;CA+LxB"}
|
|
@@ -9,10 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _HyperLiquidSubscriptionService_instances, _HyperLiquidSubscriptionService_clientService, _HyperLiquidSubscriptionService_walletService, _HyperLiquidSubscriptionService_hip3Enabled, _HyperLiquidSubscriptionService_enabledDexs, _HyperLiquidSubscriptionService_allowlistMarkets, _HyperLiquidSubscriptionService_blocklistMarkets, _HyperLiquidSubscriptionService_discoveredDexNames, _HyperLiquidSubscriptionService_dexDiscoveryPromise, _HyperLiquidSubscriptionService_dexDiscoveryResolver, _HyperLiquidSubscriptionService_expectedDexs, _HyperLiquidSubscriptionService_initializedDexs, _HyperLiquidSubscriptionService_priceSubscribers, _HyperLiquidSubscriptionService_positionSubscribers, _HyperLiquidSubscriptionService_orderFillSubscribers, _HyperLiquidSubscriptionService_orderSubscribers, _HyperLiquidSubscriptionService_accountSubscribers, _HyperLiquidSubscriptionService_marketDataSubscribers, _HyperLiquidSubscriptionService_orderBookSubscribers, _HyperLiquidSubscriptionService_globalAllMidsSubscription, _HyperLiquidSubscriptionService_globalAllMidsPromise, _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions, _HyperLiquidSubscriptionService_pendingActiveAssetPromises, _HyperLiquidSubscriptionService_globalBboSubscriptions, _HyperLiquidSubscriptionService_pendingBboPromises, _HyperLiquidSubscriptionService_orderFillSubscriptions, _HyperLiquidSubscriptionService_spotStateSubscriptions, _HyperLiquidSubscriptionService_spotStateSubscriptionPromises, _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration, _HyperLiquidSubscriptionService_symbolSubscriberCounts, _HyperLiquidSubscriptionService_dexSubscriberCounts, _HyperLiquidSubscriptionService_webData3Subscriptions, _HyperLiquidSubscriptionService_webData3SubscriptionPromise, _HyperLiquidSubscriptionService_positionSubscriberCount, _HyperLiquidSubscriptionService_orderSubscriberCount, _HyperLiquidSubscriptionService_accountSubscriberCount, _HyperLiquidSubscriptionService_oiCapSubscriberCount, _HyperLiquidSubscriptionService_dexPositionsCache, _HyperLiquidSubscriptionService_dexOrdersCache, _HyperLiquidSubscriptionService_dexAccountCache, _HyperLiquidSubscriptionService_cachedSpotState, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, _HyperLiquidSubscriptionService_spotStatePromise, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, _HyperLiquidSubscriptionService_spotStateGeneration, _HyperLiquidSubscriptionService_cachedPositions, _HyperLiquidSubscriptionService_cachedOrders, _HyperLiquidSubscriptionService_cachedAccount, _HyperLiquidSubscriptionService_ordersCacheInitialized, _HyperLiquidSubscriptionService_positionsCacheInitialized, _HyperLiquidSubscriptionService_oiCapSubscribers, _HyperLiquidSubscriptionService_cachedOICaps, _HyperLiquidSubscriptionService_cachedOICapsHash, _HyperLiquidSubscriptionService_oiCapsCacheInitialized, _HyperLiquidSubscriptionService_cachedPriceData, _HyperLiquidSubscriptionService_allMidsSnapshots, _HyperLiquidSubscriptionService_cachedFills, _HyperLiquidSubscriptionService_fillsCacheInitialized, _HyperLiquidSubscriptionService_assetCtxsSubscriptions, _HyperLiquidSubscriptionService_dexAssetCtxsCache, _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises, _HyperLiquidSubscriptionService_dexAllMidsSubscriptions, _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises, _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions, _HyperLiquidSubscriptionService_openOrdersSubscriptions, _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions, _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions, _HyperLiquidSubscriptionService_dexMetaCache, _HyperLiquidSubscriptionService_orderBookCache, _HyperLiquidSubscriptionService_marketDataCache, _HyperLiquidSubscriptionService_isClearing, _HyperLiquidSubscriptionService_restoreRetryTimeouts, _HyperLiquidSubscriptionService_deps, _HyperLiquidSubscriptionService_logErrorUnlessClearing, _HyperLiquidSubscriptionService_isTransientAssetCtxsError, _HyperLiquidSubscriptionService_scheduleRestoreRetry, _HyperLiquidSubscriptionService_getErrorContext, _HyperLiquidSubscriptionService_isDexEnabled, _HyperLiquidSubscriptionService_waitForDexDiscovery, _HyperLiquidSubscriptionService_hashPositions, _HyperLiquidSubscriptionService_hashOrders, _HyperLiquidSubscriptionService_hashAccountState, _HyperLiquidSubscriptionService_cachedPositionsHash, _HyperLiquidSubscriptionService_cachedOrdersHash, _HyperLiquidSubscriptionService_cachedAccountHash, _HyperLiquidSubscriptionService_extractTPSLFromOrders, _HyperLiquidSubscriptionService_mergeTPSLIntoPositions, _HyperLiquidSubscriptionService_aggregateAccountStates, _HyperLiquidSubscriptionService_ensureSpotState, _HyperLiquidSubscriptionService_refreshSpotState, _HyperLiquidSubscriptionService_ensureSpotStateSubscription, _HyperLiquidSubscriptionService_ensureSharedWebData3Subscription, _HyperLiquidSubscriptionService_createUserDataSubscription, _HyperLiquidSubscriptionService_ensureClearinghouseStateSubscription, _HyperLiquidSubscriptionService_createClearinghouseSubscription, _HyperLiquidSubscriptionService_ensureOpenOrdersSubscription, _HyperLiquidSubscriptionService_createOpenOrdersSubscription, _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers, _HyperLiquidSubscriptionService_cleanupSharedWebData3ISubscription, _HyperLiquidSubscriptionService_ensureOrderFillISubscription, _HyperLiquidSubscriptionService_createSubscription, _HyperLiquidSubscriptionService_createPriceUpdate, _HyperLiquidSubscriptionService_ensureGlobalAllMidsSubscription, _HyperLiquidSubscriptionService_ensureActiveAssetSubscription, _HyperLiquidSubscriptionService_cleanupActiveAssetSubscription, _HyperLiquidSubscriptionService_ensureAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureDexAllMidsSubscription, _HyperLiquidSubscriptionService_createDexAllMidsSubscription, _HyperLiquidSubscriptionService_createAssetCtxsSubscription, _HyperLiquidSubscriptionService_cleanupAssetCtxsSubscription, _HyperLiquidSubscriptionService_ensureBboSubscription, _HyperLiquidSubscriptionService_cleanupBboSubscription, _HyperLiquidSubscriptionService_processOrderBookData, _HyperLiquidSubscriptionService_notifyAllPriceSubscribers;
|
|
12
|
+
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
13
|
import { hasProperty } from "@metamask/utils";
|
|
14
14
|
import { TP_SL_CONFIG, PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
|
|
15
15
|
import { WebSocketConnectionState } from "../types/index.mjs";
|
|
16
|
+
import { hyperLiquidModeFoldsSpot } from "../types/hyperliquid-types.mjs";
|
|
16
17
|
import { addSpotBalanceToAccountState, calculateWeightedReturnOnEquity } from "../utils/accountUtils.mjs";
|
|
17
18
|
import { ensureError } from "../utils/errorUtils.mjs";
|
|
18
19
|
import { adaptPositionFromSDK, adaptOrderFromSDK, adaptAccountStateFromSDK, parseAssetName } from "../utils/hyperLiquidAdapter.mjs";
|
|
@@ -85,6 +86,7 @@ export class HyperLiquidSubscriptionService {
|
|
|
85
86
|
_HyperLiquidSubscriptionService_dexAccountCache.set(this, new Map()); // Per-DEX account state
|
|
86
87
|
_HyperLiquidSubscriptionService_cachedSpotState.set(this, null);
|
|
87
88
|
_HyperLiquidSubscriptionService_cachedSpotStateUserAddress.set(this, null);
|
|
89
|
+
_HyperLiquidSubscriptionService_abstractionModeByUser.set(this, new Map());
|
|
88
90
|
_HyperLiquidSubscriptionService_spotStatePromise.set(this, void 0);
|
|
89
91
|
_HyperLiquidSubscriptionService_spotStatePromiseUserAddress.set(this, void 0);
|
|
90
92
|
// Monotonic token bumped on cleanUp/clearAll and on each new fetch.
|
|
@@ -268,6 +270,34 @@ export class HyperLiquidSubscriptionService {
|
|
|
268
270
|
}
|
|
269
271
|
}
|
|
270
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Record a user's resolved abstraction mode and immediately re-aggregate.
|
|
275
|
+
* Call after the provider has confirmed the on-chain mode (already-enabled
|
|
276
|
+
* or just-migrated). Setting the mode (rather than deleting it) ensures
|
|
277
|
+
* `hyperLiquidModeFoldsSpot` returns the correct fold decision on the next
|
|
278
|
+
* aggregation — a delete would leave the user pinned to fail-closed
|
|
279
|
+
* (no fold) until the next refresh, under-reporting balance for Unified
|
|
280
|
+
* and Portfolio Margin users.
|
|
281
|
+
*
|
|
282
|
+
* Seals `#cachedSpotStateUserAddress` if spot is already cached for this
|
|
283
|
+
* user (fast-path optimization for the next `#ensureSpotState`). Skips the
|
|
284
|
+
* seal if spot belongs to a different user — the next refresh will sort
|
|
285
|
+
* everything out.
|
|
286
|
+
*
|
|
287
|
+
* @param userAddress - The EVM address whose mode is being recorded.
|
|
288
|
+
* @param mode - The current abstraction mode for this user.
|
|
289
|
+
*/
|
|
290
|
+
setUserAbstractionMode(userAddress, mode) {
|
|
291
|
+
const lower = userAddress.toLowerCase();
|
|
292
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").set(lower, mode);
|
|
293
|
+
// No need to seal #cachedSpotStateUserAddress here — the WS handler and
|
|
294
|
+
// #refreshSpotState success path always set it to the spot owner. The
|
|
295
|
+
// re-aggregation below will pick up the new mode via the now-populated
|
|
296
|
+
// #abstractionModeByUser entry.
|
|
297
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
298
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
271
301
|
/**
|
|
272
302
|
* Subscribe to live price updates with singleton subscription architecture
|
|
273
303
|
* Uses allMids for fast price updates and predictedFundings for accurate funding rates
|
|
@@ -881,6 +911,7 @@ export class HyperLiquidSubscriptionService {
|
|
|
881
911
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").clear();
|
|
882
912
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
|
|
883
913
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
|
|
914
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").clear();
|
|
884
915
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
885
916
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromise, undefined, "f");
|
|
886
917
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStatePromiseUserAddress, undefined, "f");
|
|
@@ -962,7 +993,7 @@ export class HyperLiquidSubscriptionService {
|
|
|
962
993
|
});
|
|
963
994
|
}
|
|
964
995
|
}
|
|
965
|
-
_HyperLiquidSubscriptionService_clientService = new WeakMap(), _HyperLiquidSubscriptionService_walletService = new WeakMap(), _HyperLiquidSubscriptionService_hip3Enabled = new WeakMap(), _HyperLiquidSubscriptionService_enabledDexs = new WeakMap(), _HyperLiquidSubscriptionService_allowlistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_blocklistMarkets = new WeakMap(), _HyperLiquidSubscriptionService_discoveredDexNames = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryPromise = new WeakMap(), _HyperLiquidSubscriptionService_dexDiscoveryResolver = new WeakMap(), _HyperLiquidSubscriptionService_expectedDexs = new WeakMap(), _HyperLiquidSubscriptionService_initializedDexs = new WeakMap(), _HyperLiquidSubscriptionService_priceSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_marketDataSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_orderBookSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsSubscription = new WeakMap(), _HyperLiquidSubscriptionService_globalAllMidsPromise = new WeakMap(), _HyperLiquidSubscriptionService_globalActiveAssetSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingActiveAssetPromises = new WeakMap(), _HyperLiquidSubscriptionService_globalBboSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingBboPromises = new WeakMap(), _HyperLiquidSubscriptionService_orderFillSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_spotStateSubscriptionGeneration = new WeakMap(), _HyperLiquidSubscriptionService_symbolSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_dexSubscriberCounts = new WeakMap(), _HyperLiquidSubscriptionService_webData3Subscriptions = new WeakMap(), _HyperLiquidSubscriptionService_webData3SubscriptionPromise = new WeakMap(), _HyperLiquidSubscriptionService_positionSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_orderSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_accountSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscriberCount = new WeakMap(), _HyperLiquidSubscriptionService_dexPositionsCache = new WeakMap(), _HyperLiquidSubscriptionService_dexOrdersCache = new WeakMap(), _HyperLiquidSubscriptionService_dexAccountCache = new WeakMap(), _HyperLiquidSubscriptionService_cachedSpotState = new WeakMap(), _HyperLiquidSubscriptionService_cachedSpotStateUserAddress = new WeakMap(), _HyperLiquidSubscriptionService_spotStatePromise = new WeakMap(), _HyperLiquidSubscriptionService_spotStatePromiseUserAddress = new WeakMap(), _HyperLiquidSubscriptionService_spotStateGeneration = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositions = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrders = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccount = new WeakMap(), _HyperLiquidSubscriptionService_ordersCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_positionsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_oiCapSubscribers = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICaps = new WeakMap(), _HyperLiquidSubscriptionService_cachedOICapsHash = new WeakMap(), _HyperLiquidSubscriptionService_oiCapsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_cachedPriceData = new WeakMap(), _HyperLiquidSubscriptionService_allMidsSnapshots = new WeakMap(), _HyperLiquidSubscriptionService_cachedFills = new WeakMap(), _HyperLiquidSubscriptionService_fillsCacheInitialized = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAssetCtxsCache = new WeakMap(), _HyperLiquidSubscriptionService_assetCtxsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexAllMidsSubscriptionPromises = new WeakMap(), _HyperLiquidSubscriptionService_clearinghouseStateSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_openOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingClearinghouseSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_pendingOpenOrdersSubscriptions = new WeakMap(), _HyperLiquidSubscriptionService_dexMetaCache = new WeakMap(), _HyperLiquidSubscriptionService_orderBookCache = new WeakMap(), _HyperLiquidSubscriptionService_marketDataCache = new WeakMap(), _HyperLiquidSubscriptionService_isClearing = new WeakMap(), _HyperLiquidSubscriptionService_restoreRetryTimeouts = new WeakMap(), _HyperLiquidSubscriptionService_deps = new WeakMap(), _HyperLiquidSubscriptionService_cachedPositionsHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedOrdersHash = new WeakMap(), _HyperLiquidSubscriptionService_cachedAccountHash = new WeakMap(), _HyperLiquidSubscriptionService_instances = new WeakSet(), _HyperLiquidSubscriptionService_logErrorUnlessClearing = function _HyperLiquidSubscriptionService_logErrorUnlessClearing(error, context) {
|
|
996
|
+
_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) {
|
|
966
997
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_isClearing, "f")) {
|
|
967
998
|
return;
|
|
968
999
|
}
|
|
@@ -1078,7 +1109,7 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1078
1109
|
.map((ord) => `${ord.symbol}:${ord.side}:${ord.size}:${ord.price}:${ord.orderType}`)
|
|
1079
1110
|
.join('|');
|
|
1080
1111
|
}, _HyperLiquidSubscriptionService_hashAccountState = function _HyperLiquidSubscriptionService_hashAccountState(account) {
|
|
1081
|
-
return `${account.availableBalance}:${account.totalBalance}:${account.marginUsed}:${account.unrealizedPnl}`;
|
|
1112
|
+
return `${account.availableBalance}:${account.availableToTradeBalance ?? ''}:${account.totalBalance}:${account.marginUsed}:${account.unrealizedPnl}`;
|
|
1082
1113
|
}, _HyperLiquidSubscriptionService_extractTPSLFromOrders = function _HyperLiquidSubscriptionService_extractTPSLFromOrders(orders, positions, cachedProcessedOrders) {
|
|
1083
1114
|
const tpslMap = new Map();
|
|
1084
1115
|
const tpslCountMap = new Map();
|
|
@@ -1271,11 +1302,26 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1271
1302
|
unrealizedPnl: totalUnrealizedPnl.toString(),
|
|
1272
1303
|
subAccountBreakdown,
|
|
1273
1304
|
returnOnEquity,
|
|
1274
|
-
}, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"));
|
|
1305
|
+
}, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getSpotBalanceOptions).call(this));
|
|
1306
|
+
}, _HyperLiquidSubscriptionService_getAbstractionModeForUser = function _HyperLiquidSubscriptionService_getAbstractionModeForUser(userAddress) {
|
|
1307
|
+
if (!userAddress) {
|
|
1308
|
+
return null;
|
|
1309
|
+
}
|
|
1310
|
+
return __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").get(userAddress.toLowerCase()) ?? null;
|
|
1311
|
+
}, _HyperLiquidSubscriptionService_getSpotBalanceOptions = function _HyperLiquidSubscriptionService_getSpotBalanceOptions() {
|
|
1312
|
+
return {
|
|
1313
|
+
foldIntoCollateral: hyperLiquidModeFoldsSpot(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getAbstractionModeForUser).call(this, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f"))),
|
|
1314
|
+
};
|
|
1275
1315
|
}, _HyperLiquidSubscriptionService_ensureSpotState = async function _HyperLiquidSubscriptionService_ensureSpotState(accountId) {
|
|
1276
1316
|
const userAddress = await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").getUserAddressWithDefault(accountId);
|
|
1317
|
+
const lowerUserAddress = userAddress.toLowerCase();
|
|
1318
|
+
// Fast-path only when we have spot for this user AND a resolved
|
|
1319
|
+
// abstraction mode. Without the mode, `#getSpotBalanceOptions` would
|
|
1320
|
+
// fall back to fail-closed (no fold), under-reporting Unified /
|
|
1321
|
+
// Portfolio Margin balances — force a refresh instead.
|
|
1277
1322
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f") &&
|
|
1278
|
-
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f") ===
|
|
1323
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f") === lowerUserAddress &&
|
|
1324
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").has(lowerUserAddress)) {
|
|
1279
1325
|
return;
|
|
1280
1326
|
}
|
|
1281
1327
|
// Share an in-flight fetch only if it targets the same user.
|
|
@@ -1309,20 +1355,60 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1309
1355
|
// instance subscribeToAccount can race ahead of the webData3 path,
|
|
1310
1356
|
// so initialize here first — subsequent calls are no-ops.
|
|
1311
1357
|
await __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").ensureSubscriptionClient(__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_walletService, "f").createWalletAdapter());
|
|
1312
|
-
if
|
|
1313
|
-
|
|
1314
|
-
|
|
1358
|
+
// Don't bail here even if generation has bumped (e.g. WS spot snapshot
|
|
1359
|
+
// arrived while we awaited the subscription client). We still need to
|
|
1360
|
+
// resolve `userAbstraction` for this user — the mode is user-keyed,
|
|
1361
|
+
// independent of the spot generation, and the post-fetch path below
|
|
1362
|
+
// correctly handles the generation-changed case (seal + re-aggregate
|
|
1363
|
+
// instead of overwriting WS spot).
|
|
1315
1364
|
const infoClient = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_clientService, "f").getInfoClient();
|
|
1316
|
-
const
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1365
|
+
const [spotResult, abstractionResult] = await Promise.allSettled([
|
|
1366
|
+
infoClient.spotClearinghouseState({
|
|
1367
|
+
user: userAddress,
|
|
1368
|
+
}),
|
|
1369
|
+
infoClient.userAbstraction({ user: userAddress }),
|
|
1370
|
+
]);
|
|
1371
|
+
const lowerUserAddress = userAddress.toLowerCase();
|
|
1372
|
+
// Record the abstraction mode regardless of generation. The mode is
|
|
1373
|
+
// user-keyed (independent of the spot snapshot generation) so a WS
|
|
1374
|
+
// push that bumped generation while we awaited cannot make this
|
|
1375
|
+
// result wrong for this user. Discarding it would strand
|
|
1376
|
+
// Unified / Portfolio Margin users at fail-closed until another
|
|
1377
|
+
// subscribe runs — exactly the race the WS-vs-REST guard creates.
|
|
1378
|
+
if (abstractionResult.status === 'fulfilled') {
|
|
1379
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").set(lowerUserAddress, abstractionResult.value);
|
|
1380
|
+
}
|
|
1381
|
+
else {
|
|
1382
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_deps, "f").debugLogger.log('User abstraction fetch failed during spot refresh; spot fold disabled until the mode resolves', {
|
|
1383
|
+
error: ensureError(abstractionResult.reason, 'HyperLiquidSubscriptionService.refreshSpotState.abstraction').message,
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1321
1386
|
if (generation !== __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f")) {
|
|
1387
|
+
// A WS push superseded our spot snapshot. The earlier WS-driven
|
|
1388
|
+
// aggregation ran with a null mode (fail-closed), so subscribers
|
|
1389
|
+
// may currently be under-reported. If we just resolved the mode
|
|
1390
|
+
// for the user whose spot is cached (strict match — null cache
|
|
1391
|
+
// owner could mean cleanUp ran for a different user), re-aggregate
|
|
1392
|
+
// now so the active subscribers immediately see the correct fold.
|
|
1393
|
+
if (abstractionResult.status === 'fulfilled' &&
|
|
1394
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f") &&
|
|
1395
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, "f") === lowerUserAddress) {
|
|
1396
|
+
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
1397
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1322
1400
|
return;
|
|
1323
1401
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1402
|
+
if (spotResult.status === 'rejected') {
|
|
1403
|
+
throw spotResult.reason;
|
|
1404
|
+
}
|
|
1405
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, spotResult.value, "f");
|
|
1406
|
+
// Always record the spot owner so subsequent #ensureSpotState calls
|
|
1407
|
+
// and recovery branches can identify whose data is cached. Fast-path
|
|
1408
|
+
// eligibility is gated separately by #abstractionModeByUser.has(...);
|
|
1409
|
+
// a transient abstraction failure leaves the user out of the map and
|
|
1410
|
+
// the next #ensureSpotState retries both fetches.
|
|
1411
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, lowerUserAddress, "f");
|
|
1326
1412
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
1327
1413
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
1328
1414
|
}
|
|
@@ -1359,10 +1445,11 @@ async function _HyperLiquidSubscriptionService_waitForDexDiscovery(timeoutMs = 5
|
|
|
1359
1445
|
// its result instead of overwriting this fresher WS snapshot.
|
|
1360
1446
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|
|
1361
1447
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, event.spotState, "f");
|
|
1362
|
-
//
|
|
1363
|
-
//
|
|
1364
|
-
//
|
|
1365
|
-
|
|
1448
|
+
// Always record the spot owner so subsequent generation guards
|
|
1449
|
+
// and recovery branches can identify whose data is cached.
|
|
1450
|
+
// Fast-path eligibility is gated separately in #ensureSpotState
|
|
1451
|
+
// by checking #abstractionModeByUser.has(...).
|
|
1452
|
+
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, userAddress.toLowerCase(), "f");
|
|
1366
1453
|
if (__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_dexAccountCache, "f").size > 0) {
|
|
1367
1454
|
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_aggregateAndNotifySubscribers).call(this);
|
|
1368
1455
|
}
|
|
@@ -1586,7 +1673,7 @@ async function _HyperLiquidSubscriptionService_createUserDataSubscription(accoun
|
|
|
1586
1673
|
// Notify subscribers (no aggregation needed - only main DEX).
|
|
1587
1674
|
// Apply spot balance so single-DEX accounts see the same
|
|
1588
1675
|
// spot-inclusive totalBalance as the HIP-3 aggregation path.
|
|
1589
|
-
const spotAdjustedAccount = addSpotBalanceToAccountState(accountState, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"));
|
|
1676
|
+
const spotAdjustedAccount = addSpotBalanceToAccountState(accountState, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_cachedSpotState, "f"), __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_getSpotBalanceOptions).call(this));
|
|
1590
1677
|
const positionsHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashPositions).call(this, positionsWithTPSL);
|
|
1591
1678
|
const ordersHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashOrders).call(this, orders);
|
|
1592
1679
|
const accountHash = __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_instances, "m", _HyperLiquidSubscriptionService_hashAccountState).call(this, spotAdjustedAccount);
|
|
@@ -1935,6 +2022,7 @@ async function _HyperLiquidSubscriptionService_createOpenOrdersSubscription(user
|
|
|
1935
2022
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedAccount, null, "f");
|
|
1936
2023
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotState, null, "f");
|
|
1937
2024
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_cachedSpotStateUserAddress, null, "f");
|
|
2025
|
+
__classPrivateFieldGet(this, _HyperLiquidSubscriptionService_abstractionModeByUser, "f").clear();
|
|
1938
2026
|
// Bump generation so any in-flight spot fetch from a prior user discards
|
|
1939
2027
|
// its result instead of re-populating the cache post-cleanup.
|
|
1940
2028
|
__classPrivateFieldSet(this, _HyperLiquidSubscriptionService_spotStateGeneration, __classPrivateFieldGet(this, _HyperLiquidSubscriptionService_spotStateGeneration, "f") + 1, "f");
|