@metamask-previews/perps-controller 4.0.0-preview-56dd1249f → 4.0.0-preview-c3dc0c91e

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 (64) hide show
  1. package/CHANGELOG.md +0 -16
  2. package/dist/constants/eventNames.cjs +0 -5
  3. package/dist/constants/eventNames.cjs.map +1 -1
  4. package/dist/constants/eventNames.d.cts +0 -4
  5. package/dist/constants/eventNames.d.cts.map +1 -1
  6. package/dist/constants/eventNames.d.mts +0 -4
  7. package/dist/constants/eventNames.d.mts.map +1 -1
  8. package/dist/constants/eventNames.mjs +0 -5
  9. package/dist/constants/eventNames.mjs.map +1 -1
  10. package/dist/providers/HyperLiquidProvider.cjs +57 -230
  11. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  12. package/dist/providers/HyperLiquidProvider.d.cts +1 -1
  13. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  14. package/dist/providers/HyperLiquidProvider.d.mts +1 -1
  15. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  16. package/dist/providers/HyperLiquidProvider.mjs +57 -230
  17. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  18. package/dist/services/HyperLiquidSubscriptionService.cjs +20 -108
  19. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  20. package/dist/services/HyperLiquidSubscriptionService.d.cts +0 -19
  21. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  22. package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -19
  23. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  24. package/dist/services/HyperLiquidSubscriptionService.mjs +20 -108
  25. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  26. package/dist/services/HyperLiquidWalletService.cjs +0 -20
  27. package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
  28. package/dist/services/HyperLiquidWalletService.d.cts +0 -6
  29. package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
  30. package/dist/services/HyperLiquidWalletService.d.mts +0 -6
  31. package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
  32. package/dist/services/HyperLiquidWalletService.mjs +2 -22
  33. package/dist/services/HyperLiquidWalletService.mjs.map +1 -1
  34. package/dist/services/TradingReadinessCache.cjs +16 -16
  35. package/dist/services/TradingReadinessCache.cjs.map +1 -1
  36. package/dist/services/TradingReadinessCache.d.cts +12 -12
  37. package/dist/services/TradingReadinessCache.d.mts +12 -12
  38. package/dist/services/TradingReadinessCache.mjs +16 -16
  39. package/dist/services/TradingReadinessCache.mjs.map +1 -1
  40. package/dist/types/hyperliquid-types.cjs +0 -39
  41. package/dist/types/hyperliquid-types.cjs.map +1 -1
  42. package/dist/types/hyperliquid-types.d.cts +2 -34
  43. package/dist/types/hyperliquid-types.d.cts.map +1 -1
  44. package/dist/types/hyperliquid-types.d.mts +2 -34
  45. package/dist/types/hyperliquid-types.d.mts.map +1 -1
  46. package/dist/types/hyperliquid-types.mjs +1 -37
  47. package/dist/types/hyperliquid-types.mjs.map +1 -1
  48. package/dist/types/index.cjs +0 -1
  49. package/dist/types/index.cjs.map +1 -1
  50. package/dist/types/index.d.cts +1 -2
  51. package/dist/types/index.d.cts.map +1 -1
  52. package/dist/types/index.d.mts +1 -2
  53. package/dist/types/index.d.mts.map +1 -1
  54. package/dist/types/index.mjs +0 -1
  55. package/dist/types/index.mjs.map +1 -1
  56. package/dist/utils/accountUtils.cjs +8 -20
  57. package/dist/utils/accountUtils.cjs.map +1 -1
  58. package/dist/utils/accountUtils.d.cts +5 -9
  59. package/dist/utils/accountUtils.d.cts.map +1 -1
  60. package/dist/utils/accountUtils.d.mts +5 -9
  61. package/dist/utils/accountUtils.d.mts.map +1 -1
  62. package/dist/utils/accountUtils.mjs +8 -20
  63. package/dist/utils/accountUtils.mjs.map +1 -1
  64. package/package.json +3 -3
@@ -10,12 +10,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _HyperLiquidProvider_instances, _HyperLiquidProvider_deps, _HyperLiquidProvider_clientService, _HyperLiquidProvider_walletService, _HyperLiquidProvider_subscriptionService, _HyperLiquidProvider_symbolToAssetId, _HyperLiquidProvider_userFeeCache, _HyperLiquidProvider_maxLeverageCache, _HyperLiquidProvider_cachedMetaByDex, _HyperLiquidProvider_cachedMarketDataWithPrices, _HyperLiquidProvider_cachedSpotMeta, _HyperLiquidProvider_dexDiscoveryCache, _HyperLiquidProvider_referralCheckCache, _HyperLiquidProvider_builderFeeCheckCache, _HyperLiquidProvider_ensureReadyPromise, _HyperLiquidProvider_pendingBuilderFeeApprovals, _HyperLiquidProvider_compiledAllowlistPatterns, _HyperLiquidProvider_compiledBlocklistPatterns, _HyperLiquidProvider_userFeeDiscountBips, _HyperLiquidProvider_hip3Enabled, _HyperLiquidProvider_allowlistMarkets, _HyperLiquidProvider_blocklistMarkets, _HyperLiquidProvider_useUnifiedAccount, _HyperLiquidProvider_dexDiscoveryComplete, _HyperLiquidProvider_unifiedAccountSetupNeedsRetry, _HyperLiquidProvider_pendingValidatedDexsPromise, _HyperLiquidProvider_cachedUsdcTokenId, _HyperLiquidProvider_errorMappings, _HyperLiquidProvider_clientsInitialized, _HyperLiquidProvider_initializationPromise, _HyperLiquidProvider_messenger, _HyperLiquidProvider_builderAddressTestnet, _HyperLiquidProvider_builderAddressMainnet, _HyperLiquidProvider_compilePatternsSafely, _HyperLiquidProvider_ensureClientsInitialized, _HyperLiquidProvider_ensureUnifiedAccountEnabled, _HyperLiquidProvider_ensureReady, _HyperLiquidProvider_tradingSetupPromise, _HyperLiquidProvider_tradingSetupComplete, _HyperLiquidProvider_ensureReadyForTrading, _HyperLiquidProvider_getOrFetchPrice, _HyperLiquidProvider_filterFills, _HyperLiquidProvider_getAllAvailableDexs, _HyperLiquidProvider_getValidatedDexs, _HyperLiquidProvider_fetchValidatedDexsInternal, _HyperLiquidProvider_getCachedMeta, _HyperLiquidProvider_backfillAssetMapForDex, _HyperLiquidProvider_getAssetIdWithRepair, _HyperLiquidProvider_getCachedSpotMeta, _HyperLiquidProvider_getCachedPerpDexs, _HyperLiquidProvider_calculateHip3FeeMultiplier, _HyperLiquidProvider_getCacheKey, _HyperLiquidProvider_fetchMarketsForDex, _HyperLiquidProvider_getUsdcTokenId, _HyperLiquidProvider_isUsdhCollateralDex, _HyperLiquidProvider_getSpotUsdhBalance, _HyperLiquidProvider_getSpotUsdcBalance, _HyperLiquidProvider_transferUsdcToSpot, _HyperLiquidProvider_swapUsdcToUsdh, _HyperLiquidProvider_ensureUsdhCollateralForOrder, _HyperLiquidProvider_buildAssetMapping, _HyperLiquidProvider_queryUserDataAcrossDexs, _HyperLiquidProvider_mapError, _HyperLiquidProvider_getErrorContext, _HyperLiquidProvider_checkBuilderFeeApproval, _HyperLiquidProvider_ensureBuilderFeeApproval, _HyperLiquidProvider_checkBuilderFeeStatus, _HyperLiquidProvider_getBalanceForDex, _HyperLiquidProvider_findSourceDexWithBalance, _HyperLiquidProvider_autoTransferForHip3Order, _HyperLiquidProvider_autoTransferBackAfterClose, _HyperLiquidProvider_calculateHip3RequiredMargin, _HyperLiquidProvider_handleHip3PostOrderRebalance, _HyperLiquidProvider_handleHip3OrderRollback, _HyperLiquidProvider_validateOrderBeforePlacement, _HyperLiquidProvider_getAssetInfo, _HyperLiquidProvider_prepareAssetForTrading, _HyperLiquidProvider_handleHip3PreOrder, _HyperLiquidProvider_submitOrderWithRollback, _HyperLiquidProvider_handleOrderError, _HyperLiquidProvider_getStandaloneValidatedDexs, _HyperLiquidProvider_getAllMids, _HyperLiquidProvider_fetchSingleDexFresh, _HyperLiquidProvider_mergeDexResultsInto, _HyperLiquidProvider_cacheFreshMarketDataSnapshot, _HyperLiquidProvider_getStaleMarketDataSnapshot, _HyperLiquidProvider_isFeeCacheValid, _HyperLiquidProvider_getBuilderAddress, _HyperLiquidProvider_getReferralCode, _HyperLiquidProvider_ensureReferralSet, _HyperLiquidProvider_isReferralCodeReady, _HyperLiquidProvider_checkReferralSet, _HyperLiquidProvider_setReferralCode;
13
+ var _HyperLiquidProvider_instances, _HyperLiquidProvider_deps, _HyperLiquidProvider_clientService, _HyperLiquidProvider_walletService, _HyperLiquidProvider_subscriptionService, _HyperLiquidProvider_symbolToAssetId, _HyperLiquidProvider_userFeeCache, _HyperLiquidProvider_maxLeverageCache, _HyperLiquidProvider_cachedMetaByDex, _HyperLiquidProvider_cachedMarketDataWithPrices, _HyperLiquidProvider_cachedSpotMeta, _HyperLiquidProvider_dexDiscoveryCache, _HyperLiquidProvider_referralCheckCache, _HyperLiquidProvider_builderFeeCheckCache, _HyperLiquidProvider_ensureReadyPromise, _HyperLiquidProvider_pendingBuilderFeeApprovals, _HyperLiquidProvider_compiledAllowlistPatterns, _HyperLiquidProvider_compiledBlocklistPatterns, _HyperLiquidProvider_userFeeDiscountBips, _HyperLiquidProvider_hip3Enabled, _HyperLiquidProvider_allowlistMarkets, _HyperLiquidProvider_blocklistMarkets, _HyperLiquidProvider_useDexAbstraction, _HyperLiquidProvider_dexDiscoveryComplete, _HyperLiquidProvider_pendingValidatedDexsPromise, _HyperLiquidProvider_cachedUsdcTokenId, _HyperLiquidProvider_errorMappings, _HyperLiquidProvider_clientsInitialized, _HyperLiquidProvider_initializationPromise, _HyperLiquidProvider_messenger, _HyperLiquidProvider_builderAddressTestnet, _HyperLiquidProvider_builderAddressMainnet, _HyperLiquidProvider_compilePatternsSafely, _HyperLiquidProvider_ensureClientsInitialized, _HyperLiquidProvider_ensureDexAbstractionEnabled, _HyperLiquidProvider_ensureReady, _HyperLiquidProvider_tradingSetupPromise, _HyperLiquidProvider_tradingSetupComplete, _HyperLiquidProvider_ensureReadyForTrading, _HyperLiquidProvider_getOrFetchPrice, _HyperLiquidProvider_filterFills, _HyperLiquidProvider_getAllAvailableDexs, _HyperLiquidProvider_getValidatedDexs, _HyperLiquidProvider_fetchValidatedDexsInternal, _HyperLiquidProvider_getCachedMeta, _HyperLiquidProvider_backfillAssetMapForDex, _HyperLiquidProvider_getAssetIdWithRepair, _HyperLiquidProvider_getCachedSpotMeta, _HyperLiquidProvider_getCachedPerpDexs, _HyperLiquidProvider_calculateHip3FeeMultiplier, _HyperLiquidProvider_getCacheKey, _HyperLiquidProvider_fetchMarketsForDex, _HyperLiquidProvider_getUsdcTokenId, _HyperLiquidProvider_isUsdhCollateralDex, _HyperLiquidProvider_getSpotUsdhBalance, _HyperLiquidProvider_getSpotUsdcBalance, _HyperLiquidProvider_transferUsdcToSpot, _HyperLiquidProvider_swapUsdcToUsdh, _HyperLiquidProvider_ensureUsdhCollateralForOrder, _HyperLiquidProvider_buildAssetMapping, _HyperLiquidProvider_queryUserDataAcrossDexs, _HyperLiquidProvider_mapError, _HyperLiquidProvider_getErrorContext, _HyperLiquidProvider_checkBuilderFeeApproval, _HyperLiquidProvider_ensureBuilderFeeApproval, _HyperLiquidProvider_checkBuilderFeeStatus, _HyperLiquidProvider_getBalanceForDex, _HyperLiquidProvider_findSourceDexWithBalance, _HyperLiquidProvider_autoTransferForHip3Order, _HyperLiquidProvider_autoTransferBackAfterClose, _HyperLiquidProvider_calculateHip3RequiredMargin, _HyperLiquidProvider_handleHip3PostOrderRebalance, _HyperLiquidProvider_handleHip3OrderRollback, _HyperLiquidProvider_validateOrderBeforePlacement, _HyperLiquidProvider_getAssetInfo, _HyperLiquidProvider_prepareAssetForTrading, _HyperLiquidProvider_handleHip3PreOrder, _HyperLiquidProvider_submitOrderWithRollback, _HyperLiquidProvider_handleOrderError, _HyperLiquidProvider_getStandaloneValidatedDexs, _HyperLiquidProvider_getAllMids, _HyperLiquidProvider_fetchSingleDexFresh, _HyperLiquidProvider_mergeDexResultsInto, _HyperLiquidProvider_cacheFreshMarketDataSnapshot, _HyperLiquidProvider_getStaleMarketDataSnapshot, _HyperLiquidProvider_isFeeCacheValid, _HyperLiquidProvider_getBuilderAddress, _HyperLiquidProvider_getReferralCode, _HyperLiquidProvider_ensureReferralSet, _HyperLiquidProvider_isReferralCodeReady, _HyperLiquidProvider_checkReferralSet, _HyperLiquidProvider_setReferralCode;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.HyperLiquidProvider = void 0;
16
16
  const utils_1 = require("@metamask/utils");
17
17
  const uuid_1 = require("uuid");
18
- const eventNames_1 = require("../constants/eventNames.cjs");
19
18
  const hyperLiquidConfig_1 = require("../constants/hyperLiquidConfig.cjs");
20
19
  const perpsConfig_1 = require("../constants/perpsConfig.cjs");
21
20
  const transactionsHistoryConfig_1 = require("../constants/transactionsHistoryConfig.cjs");
@@ -25,8 +24,6 @@ const HyperLiquidClientService_1 = require("../services/HyperLiquidClientService
25
24
  const HyperLiquidSubscriptionService_1 = require("../services/HyperLiquidSubscriptionService.cjs");
26
25
  const HyperLiquidWalletService_1 = require("../services/HyperLiquidWalletService.cjs");
27
26
  const TradingReadinessCache_1 = require("../services/TradingReadinessCache.cjs");
28
- const types_1 = require("../types/index.cjs");
29
- const hyperliquid_types_1 = require("../types/hyperliquid-types.cjs");
30
27
  const accountUtils_1 = require("../utils/accountUtils.cjs");
31
28
  const errorUtils_1 = require("../utils/errorUtils.cjs");
32
29
  const hyperLiquidAdapter_1 = require("../utils/hyperLiquidAdapter.cjs");
@@ -102,23 +99,11 @@ class HyperLiquidProvider {
102
99
  _HyperLiquidProvider_hip3Enabled.set(this, void 0);
103
100
  _HyperLiquidProvider_allowlistMarkets.set(this, void 0);
104
101
  _HyperLiquidProvider_blocklistMarkets.set(this, void 0);
105
- // Emergency kill-switch for the Unified Account migration flow. Defaults
106
- // to true and is the expected production state after HL's DEX Abstraction
107
- // deprecation. Kept as a constructor option (not removed) so we can
108
- // disable the migration via a hot-fix release if a regression surfaces
109
- // in the wild — flipping this to false reverts to the legacy programmatic
110
- // HIP-3 transfer path that already lives in the codebase.
111
- _HyperLiquidProvider_useUnifiedAccount.set(this, void 0);
102
+ _HyperLiquidProvider_useDexAbstraction.set(this, void 0);
112
103
  // True once DEX discovery has succeeded with real data (not a fallback).
113
104
  // When false, #ensureReadyPromise is reset after each init so the next
114
105
  // caller retries DEX discovery instead of reusing a degraded mapping.
115
106
  _HyperLiquidProvider_dexDiscoveryComplete.set(this, false);
116
- // True when the most recent #ensureUnifiedAccountEnabled run ended in a
117
- // transient state that warrants retry (silent agent-key failure, REST
118
- // userAbstraction lookup failure, or keyring locked). #ensureReady resets
119
- // its memoized promise when this is set so the next entry retries the
120
- // migration instead of returning the cached resolved promise.
121
- _HyperLiquidProvider_unifiedAccountSetupNeedsRetry.set(this, false);
122
107
  // Pending promise to deduplicate concurrent getValidatedDexs() calls
123
108
  _HyperLiquidProvider_pendingValidatedDexsPromise.set(this, null);
124
109
  // Cache for USDC token ID from spot metadata
@@ -159,8 +144,8 @@ class HyperLiquidProvider {
159
144
  __classPrivateFieldSet(this, _HyperLiquidProvider_hip3Enabled, options.hip3Enabled ?? false, "f");
160
145
  __classPrivateFieldSet(this, _HyperLiquidProvider_allowlistMarkets, options.allowlistMarkets ?? [], "f");
161
146
  __classPrivateFieldSet(this, _HyperLiquidProvider_blocklistMarkets, options.blocklistMarkets ?? [], "f");
162
- // Attempt unified account mode, fallback to programmatic transfer if unsupported
163
- __classPrivateFieldSet(this, _HyperLiquidProvider_useUnifiedAccount, options.useUnifiedAccount ?? true, "f");
147
+ // Attempt native balance abstraction, fallback to programmatic transfer if unsupported
148
+ __classPrivateFieldSet(this, _HyperLiquidProvider_useDexAbstraction, options.useDexAbstraction ?? true, "f");
164
149
  // Initialize services with injected platform dependencies
165
150
  __classPrivateFieldSet(this, _HyperLiquidProvider_clientService, new HyperLiquidClientService_1.HyperLiquidClientService(__classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f"), {
166
151
  isTestnet,
@@ -759,7 +744,7 @@ class HyperLiquidProvider {
759
744
  const closeSize = Math.abs(positionSize);
760
745
  const totalMarginUsed = parseFloat(position.marginUsed);
761
746
  // Track HIP-3 transfers (full position close means all margin is freed)
762
- if (isHip3Position && dexName && !__classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
747
+ if (isHip3Position && dexName && !__classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
763
748
  hip3Transfers.push({
764
749
  sourceDex: dexName,
765
750
  freedMargin: totalMarginUsed,
@@ -813,7 +798,7 @@ class HyperLiquidProvider {
813
798
  ((0, utils_1.hasProperty)(stat, 'filled') || (0, utils_1.hasProperty)(stat, 'resting'))).length;
814
799
  const failureCount = statuses.length - successCount;
815
800
  // Handle HIP-3 margin transfers for successful closes
816
- if (!__classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
801
+ if (!__classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
817
802
  for (let i = 0; i < statuses.length; i++) {
818
803
  const status = statuses[i];
819
804
  const isSuccess = isStatusObject(status) &&
@@ -1181,7 +1166,7 @@ class HyperLiquidProvider {
1181
1166
  if (result.success &&
1182
1167
  isHip3Position &&
1183
1168
  hip3Dex &&
1184
- !__classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
1169
+ !__classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
1185
1170
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Position closed successfully, initiating manual auto-transfer back');
1186
1171
  // Non-blocking: Transfer freed margin back to main DEX
1187
1172
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_autoTransferBackAfterClose).call(this, {
@@ -1192,8 +1177,8 @@ class HyperLiquidProvider {
1192
1177
  else if (result.success &&
1193
1178
  isHip3Position &&
1194
1179
  hip3Dex &&
1195
- __classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
1196
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Position closed - Unified Account will auto-return freed margin', {
1180
+ __classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
1181
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Position closed - DEX abstraction will auto-return freed margin', {
1197
1182
  coin: params.symbol,
1198
1183
  dex: hip3Dex,
1199
1184
  note: 'HyperLiquid handles return automatically',
@@ -1950,7 +1935,7 @@ class HyperLiquidProvider {
1950
1935
  isTestnet: __classPrivateFieldGet(this, _HyperLiquidProvider_clientService, "f").isTestnetMode(),
1951
1936
  });
1952
1937
  const dexs = await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_getStandaloneValidatedDexs).call(this);
1953
- const [standaloneSpotStateResult, standalonePerpsResults, standaloneAbstractionResult,] = await Promise.all([
1938
+ const [standaloneSpotStateResult, standalonePerpsResults] = await Promise.all([
1954
1939
  standaloneInfoClient
1955
1940
  .spotClearinghouseState({ user: userAddress })
1956
1941
  .catch((error) => {
@@ -1960,21 +1945,11 @@ class HyperLiquidProvider {
1960
1945
  return null;
1961
1946
  }),
1962
1947
  (0, standaloneInfoClient_1.queryStandaloneClearinghouseStates)(standaloneInfoClient, userAddress, dexs),
1963
- standaloneInfoClient
1964
- .userAbstraction({ user: userAddress })
1965
- .catch((error) => {
1966
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Standalone userAbstraction fetch failed; spot fold disabled until the mode resolves', {
1967
- error: (0, errorUtils_1.ensureError)(error, 'HyperLiquidProvider.getAccountState.standalone.abstraction').message,
1968
- });
1969
- return null;
1970
- }),
1971
1948
  ]);
1972
1949
  // Aggregate account states across all DEXs, then apply spot-backed
1973
1950
  // adjustments so streamed/standalone/full paths report the same totals.
1974
1951
  const dexAccountStates = standalonePerpsResults.map((perpsState) => (0, hyperLiquidAdapter_1.adaptAccountStateFromSDK)(perpsState));
1975
- const aggregatedAccountState = (0, accountUtils_1.addSpotBalanceToAccountState)((0, accountUtils_1.aggregateAccountStates)(dexAccountStates), standaloneSpotStateResult, {
1976
- foldIntoCollateral: (0, hyperliquid_types_1.hyperLiquidModeFoldsSpot)(standaloneAbstractionResult),
1977
- });
1952
+ const aggregatedAccountState = (0, accountUtils_1.addSpotBalanceToAccountState)((0, accountUtils_1.aggregateAccountStates)(dexAccountStates), standaloneSpotStateResult);
1978
1953
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: standalone account state fetched', { totalBalance: aggregatedAccountState.totalBalance });
1979
1954
  return aggregatedAccountState;
1980
1955
  }
@@ -1988,20 +1963,11 @@ class HyperLiquidProvider {
1988
1963
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Network mode:', __classPrivateFieldGet(this, _HyperLiquidProvider_clientService, "f").isTestnetMode() ? 'TESTNET' : 'MAINNET');
1989
1964
  // Get Spot balance (global, not DEX-specific) and Perps states across all DEXs.
1990
1965
  // One transient DEX failure should not blank the entire account state.
1991
- const [spotStateResult, perpsStateResult, abstractionResult] = await Promise.allSettled([
1966
+ const [spotStateResult, perpsStateResult] = await Promise.allSettled([
1992
1967
  infoClient.spotClearinghouseState({ user: userAddress }),
1993
1968
  __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_queryUserDataAcrossDexs).call(this, { user: userAddress }, (userParam) => infoClient.clearinghouseState(userParam)),
1994
- infoClient.userAbstraction({ user: userAddress }),
1995
1969
  ]);
1996
1970
  const spotState = spotStateResult.status === 'fulfilled' ? spotStateResult.value : null;
1997
- const abstractionMode = abstractionResult.status === 'fulfilled'
1998
- ? abstractionResult.value
1999
- : null;
2000
- if (abstractionResult.status === 'rejected') {
2001
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('User abstraction fetch failed; spot fold disabled until the mode resolves', {
2002
- error: (0, errorUtils_1.ensureError)(abstractionResult.reason, 'HyperLiquidProvider.getAccountState.abstraction').message,
2003
- });
2004
- }
2005
1971
  const perpsResponse = perpsStateResult.status === 'fulfilled'
2006
1972
  ? perpsStateResult.value
2007
1973
  : {
@@ -2048,9 +2014,7 @@ class HyperLiquidProvider {
2048
2014
  });
2049
2015
  return dexAccountState;
2050
2016
  });
2051
- const aggregatedAccountState = (0, accountUtils_1.addSpotBalanceToAccountState)((0, accountUtils_1.aggregateAccountStates)(dexAccountStates), spotState, {
2052
- foldIntoCollateral: (0, hyperliquid_types_1.hyperLiquidModeFoldsSpot)(abstractionMode),
2053
- });
2017
+ const aggregatedAccountState = (0, accountUtils_1.addSpotBalanceToAccountState)((0, accountUtils_1.aggregateAccountStates)(dexAccountStates), spotState);
2054
2018
  // Build per-sub-account breakdown (HIP-3 DEXs map to sub-accounts)
2055
2019
  const subAccountBreakdown = {};
2056
2020
  perpsStateResults.forEach((result) => {
@@ -2724,20 +2688,14 @@ class HyperLiquidProvider {
2724
2688
  // Step 4: Ensure client is ready
2725
2689
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: ENSURING CLIENT READY');
2726
2690
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureReady).call(this);
2727
- await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureUnifiedAccountEnabled).call(this, { allowUserSigning: true });
2728
2691
  const exchangeClient = __classPrivateFieldGet(this, _HyperLiquidProvider_clientService, "f").getExchangeClient();
2729
2692
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: CLIENT READY');
2730
2693
  // Step 5: Validate amount against account balance
2731
2694
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: CHECKING ACCOUNT BALANCE');
2732
2695
  const accountState = await this.getAccountState();
2733
- // Release-branch bridge for Unified Account: availableToTradeBalance
2734
- // includes collateral HL can draw in target mode. The larger balance
2735
- // contract will replace this with an explicit withdrawableBalance field.
2736
- const availableBalance = parseFloat(accountState.availableToTradeBalance ?? accountState.availableBalance);
2696
+ const availableBalance = parseFloat(accountState.availableBalance);
2737
2697
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: ACCOUNT BALANCE', {
2738
2698
  availableBalance,
2739
- clearinghouseAvailableBalance: accountState.availableBalance,
2740
- availableToTradeBalance: accountState.availableToTradeBalance,
2741
2699
  totalBalance: accountState.totalBalance,
2742
2700
  marginUsed: accountState.marginUsed,
2743
2701
  unrealizedPnl: accountState.unrealizedPnl,
@@ -3550,7 +3508,7 @@ class HyperLiquidProvider {
3550
3508
  // Clear session caches (ensures fresh state on reconnect/account switch)
3551
3509
  __classPrivateFieldGet(this, _HyperLiquidProvider_referralCheckCache, "f").clear();
3552
3510
  __classPrivateFieldGet(this, _HyperLiquidProvider_builderFeeCheckCache, "f").clear();
3553
- // NOTE: UnifiedAccountCache is global and NOT cleared on disconnect
3511
+ // NOTE: DexAbstractionCache is global and NOT cleared on disconnect
3554
3512
  // to prevent repeated signing requests across reconnections
3555
3513
  __classPrivateFieldGet(this, _HyperLiquidProvider_cachedMetaByDex, "f").clear();
3556
3514
  __classPrivateFieldSet(this, _HyperLiquidProvider_cachedSpotMeta, null, "f");
@@ -3731,7 +3689,7 @@ class HyperLiquidProvider {
3731
3689
  }
3732
3690
  }
3733
3691
  exports.HyperLiquidProvider = HyperLiquidProvider;
3734
- _HyperLiquidProvider_deps = new WeakMap(), _HyperLiquidProvider_clientService = new WeakMap(), _HyperLiquidProvider_walletService = new WeakMap(), _HyperLiquidProvider_subscriptionService = new WeakMap(), _HyperLiquidProvider_symbolToAssetId = new WeakMap(), _HyperLiquidProvider_userFeeCache = new WeakMap(), _HyperLiquidProvider_maxLeverageCache = new WeakMap(), _HyperLiquidProvider_cachedMetaByDex = new WeakMap(), _HyperLiquidProvider_cachedMarketDataWithPrices = new WeakMap(), _HyperLiquidProvider_cachedSpotMeta = new WeakMap(), _HyperLiquidProvider_dexDiscoveryCache = new WeakMap(), _HyperLiquidProvider_referralCheckCache = new WeakMap(), _HyperLiquidProvider_builderFeeCheckCache = new WeakMap(), _HyperLiquidProvider_ensureReadyPromise = new WeakMap(), _HyperLiquidProvider_pendingBuilderFeeApprovals = new WeakMap(), _HyperLiquidProvider_compiledAllowlistPatterns = new WeakMap(), _HyperLiquidProvider_compiledBlocklistPatterns = new WeakMap(), _HyperLiquidProvider_userFeeDiscountBips = new WeakMap(), _HyperLiquidProvider_hip3Enabled = new WeakMap(), _HyperLiquidProvider_allowlistMarkets = new WeakMap(), _HyperLiquidProvider_blocklistMarkets = new WeakMap(), _HyperLiquidProvider_useUnifiedAccount = new WeakMap(), _HyperLiquidProvider_dexDiscoveryComplete = new WeakMap(), _HyperLiquidProvider_unifiedAccountSetupNeedsRetry = new WeakMap(), _HyperLiquidProvider_pendingValidatedDexsPromise = new WeakMap(), _HyperLiquidProvider_cachedUsdcTokenId = new WeakMap(), _HyperLiquidProvider_errorMappings = new WeakMap(), _HyperLiquidProvider_clientsInitialized = new WeakMap(), _HyperLiquidProvider_initializationPromise = new WeakMap(), _HyperLiquidProvider_messenger = new WeakMap(), _HyperLiquidProvider_builderAddressTestnet = new WeakMap(), _HyperLiquidProvider_builderAddressMainnet = new WeakMap(), _HyperLiquidProvider_tradingSetupPromise = new WeakMap(), _HyperLiquidProvider_tradingSetupComplete = new WeakMap(), _HyperLiquidProvider_instances = new WeakSet(), _HyperLiquidProvider_compilePatternsSafely = function _HyperLiquidProvider_compilePatternsSafely(patterns, listName) {
3692
+ _HyperLiquidProvider_deps = new WeakMap(), _HyperLiquidProvider_clientService = new WeakMap(), _HyperLiquidProvider_walletService = new WeakMap(), _HyperLiquidProvider_subscriptionService = new WeakMap(), _HyperLiquidProvider_symbolToAssetId = new WeakMap(), _HyperLiquidProvider_userFeeCache = new WeakMap(), _HyperLiquidProvider_maxLeverageCache = new WeakMap(), _HyperLiquidProvider_cachedMetaByDex = new WeakMap(), _HyperLiquidProvider_cachedMarketDataWithPrices = new WeakMap(), _HyperLiquidProvider_cachedSpotMeta = new WeakMap(), _HyperLiquidProvider_dexDiscoveryCache = new WeakMap(), _HyperLiquidProvider_referralCheckCache = new WeakMap(), _HyperLiquidProvider_builderFeeCheckCache = new WeakMap(), _HyperLiquidProvider_ensureReadyPromise = new WeakMap(), _HyperLiquidProvider_pendingBuilderFeeApprovals = new WeakMap(), _HyperLiquidProvider_compiledAllowlistPatterns = new WeakMap(), _HyperLiquidProvider_compiledBlocklistPatterns = new WeakMap(), _HyperLiquidProvider_userFeeDiscountBips = new WeakMap(), _HyperLiquidProvider_hip3Enabled = new WeakMap(), _HyperLiquidProvider_allowlistMarkets = new WeakMap(), _HyperLiquidProvider_blocklistMarkets = new WeakMap(), _HyperLiquidProvider_useDexAbstraction = new WeakMap(), _HyperLiquidProvider_dexDiscoveryComplete = new WeakMap(), _HyperLiquidProvider_pendingValidatedDexsPromise = new WeakMap(), _HyperLiquidProvider_cachedUsdcTokenId = new WeakMap(), _HyperLiquidProvider_errorMappings = new WeakMap(), _HyperLiquidProvider_clientsInitialized = new WeakMap(), _HyperLiquidProvider_initializationPromise = new WeakMap(), _HyperLiquidProvider_messenger = new WeakMap(), _HyperLiquidProvider_builderAddressTestnet = new WeakMap(), _HyperLiquidProvider_builderAddressMainnet = new WeakMap(), _HyperLiquidProvider_tradingSetupPromise = new WeakMap(), _HyperLiquidProvider_tradingSetupComplete = new WeakMap(), _HyperLiquidProvider_instances = new WeakSet(), _HyperLiquidProvider_compilePatternsSafely = function _HyperLiquidProvider_compilePatternsSafely(patterns, listName) {
3735
3693
  const compiled = [];
3736
3694
  for (const pattern of patterns) {
3737
3695
  try {
@@ -3802,9 +3760,9 @@ async function _HyperLiquidProvider_ensureClientsInitialized() {
3802
3760
  // so future calls can retry if needed
3803
3761
  __classPrivateFieldSet(this, _HyperLiquidProvider_initializationPromise, null, "f");
3804
3762
  }
3805
- }, _HyperLiquidProvider_ensureUnifiedAccountEnabled =
3763
+ }, _HyperLiquidProvider_ensureDexAbstractionEnabled =
3806
3764
  /**
3807
- * Attempt to enable HyperLiquid Unified Account mode for HIP-3 orders
3765
+ * Attempt to enable HIP-3 native balance abstraction
3808
3766
  *
3809
3767
  * If successful, HyperLiquid automatically manages collateral transfers for HIP-3 orders.
3810
3768
  * If not supported, disables the flag to trigger programmatic transfer fallback.
@@ -3812,24 +3770,10 @@ async function _HyperLiquidProvider_ensureClientsInitialized() {
3812
3770
  * IMPORTANT: Uses global singleton cache to prevent repeated signing requests
3813
3771
  * across provider reconnections (critical for hardware wallets).
3814
3772
  *
3815
- * @param options - Optional configuration.
3816
- * @param options.allowUserSigning - When true, runs the EIP-712 user-signed migration for `dexAbstraction` accounts. Defaults to false so init does not surface a signing prompt; action-time entry points (trading, withdraw) pass true.
3817
3773
  * @private
3818
3774
  */
3819
- async function _HyperLiquidProvider_ensureUnifiedAccountEnabled(options) {
3820
- // dexAbstraction unifiedAccount requires an EIP-712 prompt (HL blocks
3821
- // the agent path for that transition). Init calls with allowUserSigning=false so
3822
- // viewing the Perps section never surfaces a signing dialog. Trading and
3823
- // withdraw entry points pass allowUserSigning=true to drive the migration when
3824
- // the user actually intends to act.
3825
- const allowUserSigning = options?.allowUserSigning ?? false;
3826
- // Optimistic reset — set true below only at the failure points that
3827
- // warrant retry (silent agent failure, REST lookup failure, keyring
3828
- // locked). Final-state outcomes (success, prompted-failure cached,
3829
- // already-on-compatible, defer, unknown mode, feature off) leave it
3830
- // false so #ensureReady can keep the memoized promise.
3831
- __classPrivateFieldSet(this, _HyperLiquidProvider_unifiedAccountSetupNeedsRetry, false, "f");
3832
- if (!__classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
3775
+ async function _HyperLiquidProvider_ensureDexAbstractionEnabled() {
3776
+ if (!__classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
3833
3777
  return; // Feature disabled
3834
3778
  }
3835
3779
  const userAddress = await __classPrivateFieldGet(this, _HyperLiquidProvider_walletService, "f").getUserAddressWithDefault();
@@ -3838,7 +3782,7 @@ async function _HyperLiquidProvider_ensureUnifiedAccountEnabled(options) {
3838
3782
  // This is CRITICAL for hardware wallets to prevent QR popup spam
3839
3783
  const cachedStatus = TradingReadinessCache_1.TradingReadinessCache.get(network, userAddress);
3840
3784
  if (cachedStatus?.attempted) {
3841
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Unified Account setup already attempted (from global cache)', {
3785
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: DEX abstraction already attempted (from global cache)', {
3842
3786
  user: userAddress,
3843
3787
  network,
3844
3788
  enabled: cachedStatus.enabled,
@@ -3848,178 +3792,75 @@ async function _HyperLiquidProvider_ensureUnifiedAccountEnabled(options) {
3848
3792
  }
3849
3793
  // Check if another provider instance is currently attempting this operation
3850
3794
  // This prevents concurrent signing attempts across providers during reconnection
3851
- const inFlightPromise = TradingReadinessCache_1.PerpsSigningCache.isInFlight('unifiedAccount', network, userAddress);
3795
+ const inFlightPromise = TradingReadinessCache_1.PerpsSigningCache.isInFlight('dexAbstraction', network, userAddress);
3852
3796
  if (inFlightPromise) {
3853
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Unified Account setup in-flight, waiting...', { network, userAddress });
3797
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: DEX abstraction in-flight, waiting...', { network, userAddress });
3854
3798
  await inFlightPromise;
3855
- // The other instance may have finished without writing the cache (e.g.
3856
- // an init-time call deferred a dexAbstraction migration). If the cache
3857
- // is still empty and we are an action-time caller (allowUserSigning=true),
3858
- // we must run our own attempt — otherwise the trade/withdraw would
3859
- // proceed in the deprecated mode.
3860
- const postWaitCache = TradingReadinessCache_1.TradingReadinessCache.get(network, userAddress);
3861
- if (postWaitCache?.attempted) {
3862
- return;
3863
- }
3864
- // Fall through to acquire our own lock and retry.
3799
+ return; // After waiting, the cache should be set by the other provider
3865
3800
  }
3866
3801
  // Set in-flight lock to prevent concurrent attempts
3867
- const completeInFlight = TradingReadinessCache_1.PerpsSigningCache.setInFlight('unifiedAccount', network, userAddress);
3868
- let currentMode;
3802
+ const completeInFlight = TradingReadinessCache_1.PerpsSigningCache.setInFlight('dexAbstraction', network, userAddress);
3869
3803
  try {
3870
3804
  // Re-check cache after acquiring lock (another provider might have finished)
3871
3805
  const recheckCache = TradingReadinessCache_1.TradingReadinessCache.get(network, userAddress);
3872
3806
  if (recheckCache?.attempted) {
3873
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Unified Account setup completed by another provider', { network, userAddress });
3807
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: DEX abstraction completed by another provider', { network, userAddress });
3874
3808
  completeInFlight();
3875
3809
  return;
3876
3810
  }
3877
3811
  const infoClient = __classPrivateFieldGet(this, _HyperLiquidProvider_clientService, "f").getInfoClient();
3878
- // Check current abstraction mode on-chain
3879
- currentMode = await infoClient.userAbstraction({
3812
+ // Check if already enabled on-chain (returns boolean | null)
3813
+ const isEnabled = await infoClient.userDexAbstraction({
3880
3814
  user: userAddress,
3881
3815
  });
3882
- if (currentMode === 'unifiedAccount' ||
3883
- currentMode === 'portfolioMargin') {
3884
- // portfolioMargin is a superset of unifiedAccount it already supports
3885
- // auto-collateral management for HIP-3 orders and is more capital-efficient.
3886
- // Downgrading portfolio margin users to unifiedAccount would be harmful,
3887
- // so we treat both modes as already-enabled and skip migration.
3888
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Account already in a compatible mode, skipping migration', { user: userAddress, network, mode: currentMode });
3889
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.AccountSetup, {
3890
- [eventNames_1.PERPS_EVENT_PROPERTY.ABSTRACTION_MODE]: currentMode,
3891
- [eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.ALREADY_ENABLED,
3892
- });
3816
+ if (isEnabled === true) {
3817
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: DEX abstraction already enabled on-chain', { user: userAddress, network });
3818
+ // Cache the enabled status to skip future checks
3893
3819
  TradingReadinessCache_1.TradingReadinessCache.set(network, userAddress, {
3894
3820
  attempted: true,
3895
3821
  enabled: true,
3896
3822
  });
3897
- // Record the resolved mode in the subscription service so the next
3898
- // aggregation folds spot correctly without waiting for #refreshSpotState.
3899
- __classPrivateFieldGet(this, _HyperLiquidProvider_subscriptionService, "f").setUserAbstractionMode(userAddress, currentMode);
3900
- completeInFlight();
3901
- return;
3902
- }
3903
- // Defer the user-signed transition until the user attempts an action.
3904
- // Cache is intentionally left untouched so the next entry re-evaluates;
3905
- // the read-only userAbstraction call is cheap and gated by the in-flight
3906
- // lock, preventing concurrent prompts.
3907
- if (currentMode === 'dexAbstraction' && !allowUserSigning) {
3908
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Deferring dexAbstraction → unifiedAccount migration to action time', { user: userAddress, network });
3909
3823
  completeInFlight();
3910
3824
  return;
3911
3825
  }
3912
- // Bail on unknown modes BEFORE firing analytics or attempting dispatch.
3913
- // Keeps `migration_required` actionable (only fires for modes we can
3914
- // actually migrate) and avoids re-emitting on every reconnection.
3915
- if (currentMode !== 'dexAbstraction' &&
3916
- currentMode !== 'default' &&
3917
- currentMode !== 'disabled') {
3918
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Unknown abstraction mode, skipping Unified Account migration', { user: userAddress, network, mode: currentMode });
3919
- completeInFlight();
3920
- return;
3921
- }
3922
- // Track which mode users are currently on before we attempt migration.
3923
- // This tells us the distribution of legacy modes across our user base.
3924
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.AccountSetup, {
3925
- [eventNames_1.PERPS_EVENT_PROPERTY.ABSTRACTION_MODE]: currentMode,
3926
- [eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.MIGRATION_REQUIRED,
3927
- });
3928
- // Enable Unified Account mode.
3929
- // - default / disabled: agent wallet can do this silently (no prompt)
3930
- // - dexAbstraction: HL blocks the agent transition — requires the user's main
3931
- // wallet to sign an EIP-712 action via userSetAbstraction (one-time prompt)
3932
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Enabling Unified Account mode', {
3826
+ // Enable DEX abstraction (one-time, irreversible, requires signature)
3827
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Enabling DEX abstraction (requires signature)', {
3933
3828
  user: userAddress,
3934
3829
  network,
3935
- previousMode: currentMode,
3936
3830
  note: 'HyperLiquid will auto-manage collateral for HIP-3 orders',
3937
3831
  });
3938
3832
  const exchangeClient = __classPrivateFieldGet(this, _HyperLiquidProvider_clientService, "f").getExchangeClient();
3939
- if (currentMode === 'dexAbstraction') {
3940
- // Requires EIP-712 signature from the user's main wallet (one-time migration).
3941
- // HL blocks the dexAbstraction unifiedAccount transition via the agent wallet,
3942
- // so userSetAbstraction (user-signed) is the only path for legacy users.
3943
- await exchangeClient.userSetAbstraction({
3944
- user: userAddress,
3945
- abstraction: hyperliquid_types_1.HL_UNIFIED_ACCOUNT_MODE,
3946
- });
3947
- }
3948
- else {
3949
- // default / disabled — silent agent transition, no user prompt
3950
- await exchangeClient.agentSetAbstraction({
3951
- abstraction: hyperliquid_types_1.HL_ABSTRACTION_WIRE.unifiedAccount,
3952
- });
3953
- }
3954
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('✅ HyperLiquidProvider: Unified Account enabled successfully');
3955
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.AccountSetup, {
3956
- [eventNames_1.PERPS_EVENT_PROPERTY.PREVIOUS_ABSTRACTION_MODE]: currentMode,
3957
- [eventNames_1.PERPS_EVENT_PROPERTY.ABSTRACTION_MODE]: hyperliquid_types_1.HL_UNIFIED_ACCOUNT_MODE,
3958
- [eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.SUCCESS,
3959
- });
3833
+ await exchangeClient.agentEnableDexAbstraction();
3834
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('✅ HyperLiquidProvider: DEX abstraction enabled successfully');
3835
+ // Cache success to prevent re-attempts on reconnection
3960
3836
  TradingReadinessCache_1.TradingReadinessCache.set(network, userAddress, {
3961
3837
  attempted: true,
3962
3838
  enabled: true,
3963
3839
  });
3964
- // Record the post-migration mode in the subscription service so it
3965
- // immediately re-aggregates with fold=true and surfaces the unified
3966
- // balance rather than waiting for the next #refreshSpotState.
3967
- __classPrivateFieldGet(this, _HyperLiquidProvider_subscriptionService, "f").setUserAbstractionMode(userAddress, hyperliquid_types_1.HL_UNIFIED_ACCOUNT_MODE);
3968
3840
  completeInFlight();
3969
3841
  }
3970
3842
  catch (error) {
3971
3843
  // If keyring is locked, don't cache so it retries when unlocked
3972
3844
  if ((0, errorUtils_1.ensureError)(error).message === perpsErrorCodes_1.PERPS_ERROR_CODES.KEYRING_LOCKED) {
3973
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('[ensureUnifiedAccountEnabled] Keyring locked, will retry later');
3974
- __classPrivateFieldSet(this, _HyperLiquidProvider_unifiedAccountSetupNeedsRetry, true, "f");
3845
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('[ensureDexAbstractionEnabled] Keyring locked, will retry later');
3975
3846
  completeInFlight();
3976
3847
  return;
3977
3848
  }
3978
- // Cache failure ONLY for the user-prompted path
3979
- // (`dexAbstraction unifiedAccount` via `userSetAbstraction`). The
3980
- // rationale for caching is "don't re-prompt a user who already saw the
3981
- // signature dialog and rejected it" — that doesn't apply to:
3982
- // - Read-only userAbstraction lookup failures (no prompt; transient).
3983
- // - Silent agent-key paths (`default`/`disabled` → `agentSetAbstraction`
3984
- // does not show a UI prompt; failures are typically transient HL
3985
- // outages and pinning them would leave users stuck in the
3986
- // deprecated mode for the rest of the session).
3987
- // Action-time retries pick up the unmigrated state and try again.
3988
- if (currentMode === 'dexAbstraction') {
3989
- TradingReadinessCache_1.TradingReadinessCache.set(network, userAddress, {
3990
- attempted: true,
3991
- enabled: false,
3992
- });
3993
- }
3994
- else {
3995
- // Silent agent-key failure (default/disabled) or read-only
3996
- // userAbstraction lookup failure — neither is a final state, so
3997
- // signal #ensureReady to drop its memoized promise and retry on
3998
- // the next entry instead of pinning the user in the deprecated
3999
- // mode for the provider's lifetime.
4000
- __classPrivateFieldSet(this, _HyperLiquidProvider_unifiedAccountSetupNeedsRetry, true, "f");
4001
- }
4002
- const errorMessage = (0, errorUtils_1.ensureError)(error, 'HyperLiquidProvider.ensureUnifiedAccountEnabled').message;
4003
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: Unified Account setup failed', {
3849
+ // Cache the attempt (even on failure) to prevent repeated signing requests
3850
+ // This is CRITICAL for hardware wallets - if user rejects, don't ask again
3851
+ TradingReadinessCache_1.TradingReadinessCache.set(network, userAddress, {
3852
+ attempted: true,
3853
+ enabled: false,
3854
+ });
3855
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('HyperLiquidProvider: DEX abstraction failed, cached to prevent retries', {
4004
3856
  user: userAddress,
4005
3857
  network,
4006
- error: errorMessage,
4007
- // Cache writes only happen on the user-prompted dexAbstraction
4008
- // path (see P2-B logic above). Reflect that here so retry
4009
- // behaviour is debuggable from the log alone.
4010
- cached: currentMode === 'dexAbstraction',
4011
- });
4012
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").metrics.trackPerpsEvent(types_1.PerpsAnalyticsEvent.AccountSetup, {
4013
- ...(currentMode && {
4014
- [eventNames_1.PERPS_EVENT_PROPERTY.PREVIOUS_ABSTRACTION_MODE]: currentMode,
4015
- [eventNames_1.PERPS_EVENT_PROPERTY.ABSTRACTION_MODE]: hyperliquid_types_1.HL_UNIFIED_ACCOUNT_MODE,
4016
- }),
4017
- [eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.FAILED,
4018
- [eventNames_1.PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: errorMessage,
3858
+ error: (0, errorUtils_1.ensureError)(error, 'HyperLiquidProvider.ensureDexAbstractionEnabled').message,
4019
3859
  });
4020
3860
  completeInFlight();
4021
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'HyperLiquidProvider.ensureUnifiedAccountEnabled'), __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_getErrorContext).call(this, 'ensureUnifiedAccountEnabled', {
4022
- note: 'Could not enable Unified Account (user rejected, or network error)',
3861
+ // Don't blindly disable the flag on any error
3862
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'HyperLiquidProvider.ensureDexAbstractionEnabled'), __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_getErrorContext).call(this, 'ensureDexAbstractionEnabled', {
3863
+ note: 'Could not enable DEX abstraction (may already be enabled, user rejected, or network error)',
4023
3864
  }));
4024
3865
  }
4025
3866
  }, _HyperLiquidProvider_ensureReady =
@@ -4053,14 +3894,9 @@ async function _HyperLiquidProvider_ensureReady() {
4053
3894
  });
4054
3895
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_buildAssetMapping).call(this);
4055
3896
  }
4056
- // Attempt Unified Account migration as early as possible so users aren't
4057
- // blocked when they try to trade. Software-wallet dexAbstraction users can
4058
- // complete the one-time EIP-712 migration during initial setup so the first
4059
- // trade sees the unified balance. Hardware wallets remain deferred to
4060
- // action time to avoid QR / Ledger prompt spam while browsing.
4061
- await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureUnifiedAccountEnabled).call(this, {
4062
- allowUserSigning: !__classPrivateFieldGet(this, _HyperLiquidProvider_walletService, "f").isSelectedHardwareWallet(),
4063
- });
3897
+ // NOTE: Signing operations (DEX abstraction, builder fee, referral) are now DEFERRED
3898
+ // They are called on-demand in ensureReadyForTrading() when user attempts to trade
3899
+ // This prevents QR popups when just viewing the Perps section (critical for hardware wallets)
4064
3900
  })(), "f");
4065
3901
  // Await initialization - keep the promise so subsequent calls resolve immediately
4066
3902
  // The promise is only reset in disconnect() for clean reconnection,
@@ -4072,21 +3908,10 @@ async function _HyperLiquidProvider_ensureReady() {
4072
3908
  // will be re-discovered on the next #ensureReady() call.
4073
3909
  __classPrivateFieldSet(this, _HyperLiquidProvider_ensureReadyPromise, null, "f");
4074
3910
  }
4075
- else if (__classPrivateFieldGet(this, _HyperLiquidProvider_unifiedAccountSetupNeedsRetry, "f")) {
4076
- // Silent migration / lookup / keyring-locked failure left the cache
4077
- // empty. Without resetting the memoized promise, subsequent
4078
- // #ensureReady calls would skip retry and the user would be stuck
4079
- // in the deprecated mode for the provider's lifetime.
4080
- __classPrivateFieldSet(this, _HyperLiquidProvider_ensureReadyPromise, null, "f");
4081
- }
4082
3911
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('[ensureReady] Initialization complete');
4083
3912
  }, _HyperLiquidProvider_ensureReadyForTrading = async function _HyperLiquidProvider_ensureReadyForTrading() {
4084
3913
  // First ensure basic initialization is complete
4085
3914
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureReady).call(this);
4086
- // dexAbstraction users were deferred during init to avoid an EIP-712 prompt
4087
- // on Perps section open. Drive the migration here, gated by its own cache so
4088
- // already-migrated or already-rejected users are not re-prompted.
4089
- await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureUnifiedAccountEnabled).call(this, { allowUserSigning: true });
4090
3915
  // If trading setup already complete, return immediately
4091
3916
  if (__classPrivateFieldGet(this, _HyperLiquidProvider_tradingSetupComplete, "f")) {
4092
3917
  return;
@@ -4110,6 +3935,8 @@ async function _HyperLiquidProvider_ensureReady() {
4110
3935
  // Don't throw - spotMeta will be fetched on-demand if needed
4111
3936
  }
4112
3937
  }
3938
+ // Attempt to enable native balance abstraction
3939
+ await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureDexAbstractionEnabled).call(this);
4113
3940
  // Set up builder fee approval
4114
3941
  try {
4115
3942
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureBuilderFeeApproval).call(this);
@@ -5732,11 +5559,11 @@ async function _HyperLiquidProvider_handleHip3PreOrder(params) {
5732
5559
  isBuy,
5733
5560
  });
5734
5561
  await __classPrivateFieldGet(this, _HyperLiquidProvider_instances, "m", _HyperLiquidProvider_ensureUsdhCollateralForOrder).call(this, dexName, requiredMargin);
5735
- // Unified Account will pull USDH from spot automatically
5562
+ // DEX abstraction will pull USDH from spot automatically
5736
5563
  return { transferInfo: null };
5737
5564
  }
5738
- if (__classPrivateFieldGet(this, _HyperLiquidProvider_useUnifiedAccount, "f")) {
5739
- __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Using Unified Account (no manual transfer)', {
5565
+ if (__classPrivateFieldGet(this, _HyperLiquidProvider_useDexAbstraction, "f")) {
5566
+ __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Using DEX abstraction (no manual transfer)', {
5740
5567
  symbol,
5741
5568
  dex: dexName,
5742
5569
  });
@@ -5765,7 +5592,7 @@ async function _HyperLiquidProvider_handleHip3PreOrder(params) {
5765
5592
  const errorMsg = transferError?.message || '';
5766
5593
  if (errorMsg.includes('Cannot transfer with DEX abstraction enabled')) {
5767
5594
  __classPrivateFieldGet(this, _HyperLiquidProvider_deps, "f").debugLogger.log('Detected DEX abstraction is enabled, switching mode');
5768
- __classPrivateFieldSet(this, _HyperLiquidProvider_useUnifiedAccount, true, "f");
5595
+ __classPrivateFieldSet(this, _HyperLiquidProvider_useDexAbstraction, true, "f");
5769
5596
  return { transferInfo: null };
5770
5597
  }
5771
5598
  throw transferError;