@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.
Files changed (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/constants/eventNames.cjs +5 -0
  3. package/dist/constants/eventNames.cjs.map +1 -1
  4. package/dist/constants/eventNames.d.cts +4 -0
  5. package/dist/constants/eventNames.d.cts.map +1 -1
  6. package/dist/constants/eventNames.d.mts +4 -0
  7. package/dist/constants/eventNames.d.mts.map +1 -1
  8. package/dist/constants/eventNames.mjs +5 -0
  9. package/dist/constants/eventNames.mjs.map +1 -1
  10. package/dist/providers/HyperLiquidProvider.cjs +230 -57
  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 +230 -57
  17. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  18. package/dist/services/HyperLiquidSubscriptionService.cjs +108 -20
  19. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  20. package/dist/services/HyperLiquidSubscriptionService.d.cts +19 -0
  21. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  22. package/dist/services/HyperLiquidSubscriptionService.d.mts +19 -0
  23. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  24. package/dist/services/HyperLiquidSubscriptionService.mjs +108 -20
  25. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  26. package/dist/services/HyperLiquidWalletService.cjs +20 -0
  27. package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
  28. package/dist/services/HyperLiquidWalletService.d.cts +6 -0
  29. package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
  30. package/dist/services/HyperLiquidWalletService.d.mts +6 -0
  31. package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
  32. package/dist/services/HyperLiquidWalletService.mjs +22 -2
  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 +39 -0
  41. package/dist/types/hyperliquid-types.cjs.map +1 -1
  42. package/dist/types/hyperliquid-types.d.cts +34 -2
  43. package/dist/types/hyperliquid-types.d.cts.map +1 -1
  44. package/dist/types/hyperliquid-types.d.mts +34 -2
  45. package/dist/types/hyperliquid-types.d.mts.map +1 -1
  46. package/dist/types/hyperliquid-types.mjs +37 -1
  47. package/dist/types/hyperliquid-types.mjs.map +1 -1
  48. package/dist/types/index.cjs +1 -0
  49. package/dist/types/index.cjs.map +1 -1
  50. package/dist/types/index.d.cts +2 -1
  51. package/dist/types/index.d.cts.map +1 -1
  52. package/dist/types/index.d.mts +2 -1
  53. package/dist/types/index.d.mts.map +1 -1
  54. package/dist/types/index.mjs +1 -0
  55. package/dist/types/index.mjs.map +1 -1
  56. package/dist/utils/accountUtils.cjs +20 -8
  57. package/dist/utils/accountUtils.cjs.map +1 -1
  58. package/dist/utils/accountUtils.d.cts +9 -5
  59. package/dist/utils/accountUtils.d.cts.map +1 -1
  60. package/dist/utils/accountUtils.d.mts +9 -5
  61. package/dist/utils/accountUtils.d.mts.map +1 -1
  62. package/dist/utils/accountUtils.mjs +20 -8
  63. package/dist/utils/accountUtils.mjs.map +1 -1
  64. package/package.json +3 -3
@@ -8,13 +8,13 @@
8
8
  * are recreated on account/network changes, which would reset instance-level caches.
9
9
  *
10
10
  * Tracks three signing operations:
11
- * 1. DEX Abstraction enablement (one-time, irreversible)
11
+ * 1. Unified Account enablement (one-time, replaces deprecated DEX abstraction)
12
12
  * 2. Builder Fee approval (required for trading)
13
13
  * 3. Referral code setup (one-time per account)
14
14
  *
15
15
  * Cache Structure:
16
16
  * - Key: `network:userAddress` (e.g., "mainnet:0x123...")
17
- * - Value: { dexAbstraction, builderFee, referral, timestamp }
17
+ * - Value: { unifiedAccount, builderFee, referral, timestamp }
18
18
  *
19
19
  * Lifecycle:
20
20
  * - Cache persists throughout app session
@@ -82,9 +82,9 @@ class PerpsSigningCacheManager {
82
82
  resolvePromise();
83
83
  };
84
84
  }
85
- // ===== DEX Abstraction Methods =====
85
+ // ===== Unified Account Methods =====
86
86
  /**
87
- * Get DEX abstraction cache entry (legacy compatibility)
87
+ * Get unified account cache entry (legacy compatibility)
88
88
  *
89
89
  * @param network - The network environment.
90
90
  * @param userAddress - The user's wallet address.
@@ -97,13 +97,13 @@ class PerpsSigningCacheManager {
97
97
  return undefined;
98
98
  }
99
99
  return {
100
- attempted: entry.dexAbstraction.attempted,
101
- enabled: entry.dexAbstraction.success,
100
+ attempted: entry.unifiedAccount.attempted,
101
+ enabled: entry.unifiedAccount.success,
102
102
  timestamp: entry.timestamp,
103
103
  };
104
104
  }
105
105
  /**
106
- * Set DEX abstraction cache entry (legacy compatibility)
106
+ * Set unified account cache entry (legacy compatibility)
107
107
  *
108
108
  * @param network - The network environment.
109
109
  * @param userAddress - The user's wallet address.
@@ -113,7 +113,7 @@ class PerpsSigningCacheManager {
113
113
  */
114
114
  set(network, userAddress, data) {
115
115
  const entry = __classPrivateFieldGet(this, _PerpsSigningCacheManager_instances, "m", _PerpsSigningCacheManager_getOrCreateEntry).call(this, network, userAddress);
116
- entry.dexAbstraction = { attempted: data.attempted, success: data.enabled };
116
+ entry.unifiedAccount = { attempted: data.attempted, success: data.enabled };
117
117
  entry.timestamp = Date.now();
118
118
  }
119
119
  // ===== Builder Fee Methods =====
@@ -168,23 +168,23 @@ class PerpsSigningCacheManager {
168
168
  }
169
169
  // ===== General Methods =====
170
170
  /**
171
- * Clear only DEX abstraction state for a specific network and user address
171
+ * Clear only unified account state for a specific network and user address
172
172
  * This preserves builder fee and referral states
173
173
  *
174
174
  * @param network - The network environment.
175
175
  * @param userAddress - The user's wallet address.
176
176
  */
177
- clearDexAbstraction(network, userAddress) {
177
+ clearUnifiedAccount(network, userAddress) {
178
178
  const key = __classPrivateFieldGet(this, _PerpsSigningCacheManager_instances, "m", _PerpsSigningCacheManager_getCacheKey).call(this, network, userAddress);
179
179
  const entry = __classPrivateFieldGet(this, _PerpsSigningCacheManager_cache, "f").get(key);
180
180
  if (entry) {
181
- entry.dexAbstraction = { attempted: false, success: false };
181
+ entry.unifiedAccount = { attempted: false, success: false };
182
182
  entry.timestamp = Date.now();
183
183
  }
184
184
  }
185
185
  /**
186
186
  * Clear only builder fee state for a specific network and user address
187
- * This preserves DEX abstraction and referral states
187
+ * This preserves unified account and referral states
188
188
  *
189
189
  * @param network - The network environment.
190
190
  * @param userAddress - The user's wallet address.
@@ -199,7 +199,7 @@ class PerpsSigningCacheManager {
199
199
  }
200
200
  /**
201
201
  * Clear only referral state for a specific network and user address
202
- * This preserves DEX abstraction and builder fee states
202
+ * This preserves unified account and builder fee states
203
203
  *
204
204
  * @param network - The network environment.
205
205
  * @param userAddress - The user's wallet address.
@@ -214,7 +214,7 @@ class PerpsSigningCacheManager {
214
214
  }
215
215
  /**
216
216
  * Clear entire cache entry for a specific network and user address
217
- * WARNING: This clears ALL signing operation states (dexAbstraction, builderFee, referral)
217
+ * WARNING: This clears ALL signing operation states (unifiedAccount, builderFee, referral)
218
218
  *
219
219
  * @param network - The network environment.
220
220
  * @param userAddress - The user's wallet address.
@@ -254,7 +254,7 @@ class PerpsSigningCacheManager {
254
254
  debugState() {
255
255
  const entries = [];
256
256
  __classPrivateFieldGet(this, _PerpsSigningCacheManager_cache, "f").forEach((entry, key) => {
257
- entries.push(`${key}: dex=${entry.dexAbstraction.attempted}/${entry.dexAbstraction.success}, ` +
257
+ entries.push(`${key}: unified=${entry.unifiedAccount.attempted}/${entry.unifiedAccount.success}, ` +
258
258
  `builder=${entry.builderFee.attempted}/${entry.builderFee.success}, ` +
259
259
  `referral=${entry.referral.attempted}/${entry.referral.success}`);
260
260
  });
@@ -268,7 +268,7 @@ _a = PerpsSigningCacheManager, _PerpsSigningCacheManager_cache = new WeakMap(),
268
268
  let entry = __classPrivateFieldGet(this, _PerpsSigningCacheManager_cache, "f").get(key);
269
269
  if (!entry) {
270
270
  entry = {
271
- dexAbstraction: { attempted: false, success: false },
271
+ unifiedAccount: { attempted: false, success: false },
272
272
  builderFee: { attempted: false, success: false },
273
273
  referral: { attempted: false, success: false },
274
274
  timestamp: Date.now(),
@@ -1 +1 @@
1
- {"version":3,"file":"TradingReadinessCache.mjs","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;AAqBH,MAAM,wBAAwB;IAS5B,8CAA8C;IAC9C;;QAPS,0CAA8C,IAAI,GAAG,EAAE,EAAC;QAEjE,iFAAiF;QACjF,gGAAgG;QACvF,uDAAkD,IAAI,GAAG,EAAE,EAAC;QAInE,sCAAsC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;;QACvB,+GAAuC,IAAI,EAAwB,EAAE,0CAAA,CAAC;QACtE,OAAO,uBAAA,EAAwB,8CAAU,CAAC;IAC5C,CAAC;IAED,qCAAqC;IAErC;;;;;;;OAOG;IACI,UAAU,CACf,aAA2D,EAC3D,OAA8B,EAC9B,WAAmB;QAEnB,MAAM,GAAG,GAAG,GAAG,aAAa,IAAI,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;QACvE,OAAO,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACI,WA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OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;AACnD,CAAC,mGAGC,OAA8B,EAC9B,WAAmB;IAEnB,MAAM,GAAG,GAAG,uBAAA,IAAI,kFAAa,MAAjB,IAAI,EAAc,OAAO,EAAE,WAAW,CAAC,CAAC;IACpD,IAAI,KAAK,GAAG,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG;YACN,cAAc,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YACpD,UAAU,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAChD,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAC9C,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAnFM,sDAAS,CAA2B;AA0T7C,0DAA0D;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC;AAE5E,mCAAmC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["/**\n * Global singleton cache for Perps signing operations\n *\n * This cache persists across provider reconnections to prevent repeated\n * signing requests for hardware wallets. Critical for preventing QR popup spam.\n *\n * Cache is intentionally kept separate from provider instances because providers\n * are recreated on account/network changes, which would reset instance-level caches.\n *\n * Tracks three signing operations:\n * 1. DEX Abstraction enablement (one-time, irreversible)\n * 2. Builder Fee approval (required for trading)\n * 3. Referral code setup (one-time per account)\n *\n * Cache Structure:\n * - Key: `network:userAddress` (e.g., \"mainnet:0x123...\")\n * - Value: { dexAbstraction, builderFee, referral, timestamp }\n *\n * Lifecycle:\n * - Cache persists throughout app session\n * - Individual entries can be cleared per user/network\n * - Full cache can be cleared on app restart or explicit user action\n */\n\ntype SigningOperationState = {\n attempted: boolean; // Whether we've attempted this operation\n success: boolean; // Whether it succeeded (only valid if attempted=true)\n};\n\ntype PerpsSigningCacheEntry = {\n dexAbstraction: SigningOperationState;\n builderFee: SigningOperationState;\n referral: SigningOperationState;\n timestamp: number; // When this entry was last updated\n};\n\n// Legacy interface for backward compatibility\ntype TradingReadinessCacheEntry = {\n attempted: boolean;\n enabled: boolean;\n timestamp: number;\n};\n\nclass PerpsSigningCacheManager {\n static #instance: PerpsSigningCacheManager;\n\n readonly #cache: Map<string, PerpsSigningCacheEntry> = new Map();\n\n // Global in-flight locks to prevent concurrent signing attempts across providers\n // Key: operationType:network:userAddress, Value: Promise that resolves when operation completes\n readonly #inFlightOperations: Map<string, Promise<void>> = new Map();\n\n // Singleton: use getInstance() instead of new\n protected constructor() {\n // Protected constructor for singleton\n }\n\n public static getInstance(): PerpsSigningCacheManager {\n PerpsSigningCacheManager.#instance ??= new PerpsSigningCacheManager();\n return PerpsSigningCacheManager.#instance;\n }\n\n // ===== In-Flight Lock Methods =====\n\n /**\n * Check if an operation is currently in-flight for this user/network\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public isInFlight(\n operationType: 'dexAbstraction' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): Promise<void> | undefined {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n return this.#inFlightOperations.get(key);\n }\n\n /**\n * Set an operation as in-flight\n * Returns a function to call when operation completes\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public setInFlight(\n operationType: 'dexAbstraction' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): () => void {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n let resolvePromise: () => void;\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n this.#inFlightOperations.set(key, promise);\n return () => {\n this.#inFlightOperations.delete(key);\n resolvePromise();\n };\n }\n\n #getCacheKey(network: 'mainnet' | 'testnet', userAddress: string): string {\n return `${network}:${userAddress.toLowerCase()}`;\n }\n\n #getOrCreateEntry(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): PerpsSigningCacheEntry {\n const key = this.#getCacheKey(network, userAddress);\n let entry = this.#cache.get(key);\n if (!entry) {\n entry = {\n dexAbstraction: { attempted: false, success: false },\n builderFee: { attempted: false, success: false },\n referral: { attempted: false, success: false },\n timestamp: Date.now(),\n };\n this.#cache.set(key, entry);\n }\n return entry;\n }\n\n // ===== DEX Abstraction Methods =====\n\n /**\n * Get DEX abstraction cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public get(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): TradingReadinessCacheEntry | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (!entry) {\n return undefined;\n }\n return {\n attempted: entry.dexAbstraction.attempted,\n enabled: entry.dexAbstraction.success,\n timestamp: entry.timestamp,\n };\n }\n\n /**\n * Set DEX abstraction cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param data - The transaction data payload.\n * @param data.attempted - Whether the operation was attempted.\n * @param data.enabled - Whether the feature is enabled.\n */\n public set(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n data: { attempted: boolean; enabled: boolean },\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.dexAbstraction = { attempted: data.attempted, success: data.enabled };\n entry.timestamp = Date.now();\n }\n\n // ===== Builder Fee Methods =====\n\n /**\n * Check if builder fee approval was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.builderFee;\n }\n\n /**\n * Set builder fee approval state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.builderFee = state;\n entry.timestamp = Date.now();\n }\n\n // ===== Referral Methods =====\n\n /**\n * Check if referral setup was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.referral;\n }\n\n /**\n * Set referral setup state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.referral = state;\n entry.timestamp = Date.now();\n }\n\n // ===== General Methods =====\n\n /**\n * Clear only DEX abstraction state for a specific network and user address\n * This preserves builder fee and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearDexAbstraction(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.dexAbstraction = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only builder fee state for a specific network and user address\n * This preserves DEX abstraction and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.builderFee = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only referral state for a specific network and user address\n * This preserves DEX abstraction and builder fee states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.referral = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear entire cache entry for a specific network and user address\n * WARNING: This clears ALL signing operation states (dexAbstraction, builderFee, referral)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clear(network: 'mainnet' | 'testnet', userAddress: string): void {\n const key = this.#getCacheKey(network, userAddress);\n this.#cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n * WARNING: This clears ALL signing operation states for ALL users\n */\n public clearAll(): void {\n this.#cache.clear();\n }\n\n /**\n * Get all cache entries (for debugging)\n *\n * @returns The result of the operation.\n */\n public getAll(): Map<string, PerpsSigningCacheEntry> {\n return new Map(this.#cache);\n }\n\n /**\n * Get cache size (for debugging)\n *\n * @returns The resulting numeric value.\n */\n public size(): number {\n return this.#cache.size;\n }\n\n /**\n * Get full cache state for debugging\n *\n * @returns The resulting string value.\n */\n public debugState(): string {\n const entries: string[] = [];\n this.#cache.forEach((entry, key) => {\n entries.push(\n `${key}: dex=${entry.dexAbstraction.attempted}/${entry.dexAbstraction.success}, ` +\n `builder=${entry.builderFee.attempted}/${entry.builderFee.success}, ` +\n `referral=${entry.referral.attempted}/${entry.referral.success}`,\n );\n });\n return entries.join('\\n') || '(empty)';\n }\n}\n\n// Export singleton instance with backward-compatible name\nexport const TradingReadinessCache = PerpsSigningCacheManager.getInstance();\n\n// Export with new name for clarity\nexport const PerpsSigningCache = PerpsSigningCacheManager.getInstance();\n"]}
1
+ {"version":3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,EAAE,KAAK,EAAE;YAC9C,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAnFM,sDAAS,CAA2B;AA0T7C,0DAA0D;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC;AAE5E,mCAAmC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["/**\n * Global singleton cache for Perps signing operations\n *\n * This cache persists across provider reconnections to prevent repeated\n * signing requests for hardware wallets. Critical for preventing QR popup spam.\n *\n * Cache is intentionally kept separate from provider instances because providers\n * are recreated on account/network changes, which would reset instance-level caches.\n *\n * Tracks three signing operations:\n * 1. Unified Account enablement (one-time, replaces deprecated DEX abstraction)\n * 2. Builder Fee approval (required for trading)\n * 3. Referral code setup (one-time per account)\n *\n * Cache Structure:\n * - Key: `network:userAddress` (e.g., \"mainnet:0x123...\")\n * - Value: { unifiedAccount, builderFee, referral, timestamp }\n *\n * Lifecycle:\n * - Cache persists throughout app session\n * - Individual entries can be cleared per user/network\n * - Full cache can be cleared on app restart or explicit user action\n */\n\ntype SigningOperationState = {\n attempted: boolean; // Whether we've attempted this operation\n success: boolean; // Whether it succeeded (only valid if attempted=true)\n};\n\ntype PerpsSigningCacheEntry = {\n unifiedAccount: SigningOperationState;\n builderFee: SigningOperationState;\n referral: SigningOperationState;\n timestamp: number; // When this entry was last updated\n};\n\n// Legacy interface for backward compatibility\ntype TradingReadinessCacheEntry = {\n attempted: boolean;\n enabled: boolean;\n timestamp: number;\n};\n\nclass PerpsSigningCacheManager {\n static #instance: PerpsSigningCacheManager;\n\n readonly #cache: Map<string, PerpsSigningCacheEntry> = new Map();\n\n // Global in-flight locks to prevent concurrent signing attempts across providers\n // Key: operationType:network:userAddress, Value: Promise that resolves when operation completes\n readonly #inFlightOperations: Map<string, Promise<void>> = new Map();\n\n // Singleton: use getInstance() instead of new\n protected constructor() {\n // Protected constructor for singleton\n }\n\n public static getInstance(): PerpsSigningCacheManager {\n PerpsSigningCacheManager.#instance ??= new PerpsSigningCacheManager();\n return PerpsSigningCacheManager.#instance;\n }\n\n // ===== In-Flight Lock Methods =====\n\n /**\n * Check if an operation is currently in-flight for this user/network\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public isInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): Promise<void> | undefined {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n return this.#inFlightOperations.get(key);\n }\n\n /**\n * Set an operation as in-flight\n * Returns a function to call when operation completes\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public setInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): () => void {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n let resolvePromise: () => void;\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n this.#inFlightOperations.set(key, promise);\n return () => {\n this.#inFlightOperations.delete(key);\n resolvePromise();\n };\n }\n\n #getCacheKey(network: 'mainnet' | 'testnet', userAddress: string): string {\n return `${network}:${userAddress.toLowerCase()}`;\n }\n\n #getOrCreateEntry(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): PerpsSigningCacheEntry {\n const key = this.#getCacheKey(network, userAddress);\n let entry = this.#cache.get(key);\n if (!entry) {\n entry = {\n unifiedAccount: { attempted: false, success: false },\n builderFee: { attempted: false, success: false },\n referral: { attempted: false, success: false },\n timestamp: Date.now(),\n };\n this.#cache.set(key, entry);\n }\n return entry;\n }\n\n // ===== Unified Account Methods =====\n\n /**\n * Get unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public get(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): TradingReadinessCacheEntry | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (!entry) {\n return undefined;\n }\n return {\n attempted: entry.unifiedAccount.attempted,\n enabled: entry.unifiedAccount.success,\n timestamp: entry.timestamp,\n };\n }\n\n /**\n * Set unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param data - The transaction data payload.\n * @param data.attempted - Whether the operation was attempted.\n * @param data.enabled - Whether the feature is enabled.\n */\n public set(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n data: { attempted: boolean; enabled: boolean },\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.unifiedAccount = { attempted: data.attempted, success: data.enabled };\n entry.timestamp = Date.now();\n }\n\n // ===== Builder Fee Methods =====\n\n /**\n * Check if builder fee approval was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.builderFee;\n }\n\n /**\n * Set builder fee approval state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.builderFee = state;\n entry.timestamp = Date.now();\n }\n\n // ===== Referral Methods =====\n\n /**\n * Check if referral setup was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.referral;\n }\n\n /**\n * Set referral setup state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.referral = state;\n entry.timestamp = Date.now();\n }\n\n // ===== General Methods =====\n\n /**\n * Clear only unified account state for a specific network and user address\n * This preserves builder fee and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearUnifiedAccount(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.unifiedAccount = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only builder fee state for a specific network and user address\n * This preserves unified account and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.builderFee = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only referral state for a specific network and user address\n * This preserves unified account and builder fee states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.referral = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear entire cache entry for a specific network and user address\n * WARNING: This clears ALL signing operation states (unifiedAccount, builderFee, referral)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clear(network: 'mainnet' | 'testnet', userAddress: string): void {\n const key = this.#getCacheKey(network, userAddress);\n this.#cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n * WARNING: This clears ALL signing operation states for ALL users\n */\n public clearAll(): void {\n this.#cache.clear();\n }\n\n /**\n * Get all cache entries (for debugging)\n *\n * @returns The result of the operation.\n */\n public getAll(): Map<string, PerpsSigningCacheEntry> {\n return new Map(this.#cache);\n }\n\n /**\n * Get cache size (for debugging)\n *\n * @returns The resulting numeric value.\n */\n public size(): number {\n return this.#cache.size;\n }\n\n /**\n * Get full cache state for debugging\n *\n * @returns The resulting string value.\n */\n public debugState(): string {\n const entries: string[] = [];\n this.#cache.forEach((entry, key) => {\n entries.push(\n `${key}: unified=${entry.unifiedAccount.attempted}/${entry.unifiedAccount.success}, ` +\n `builder=${entry.builderFee.attempted}/${entry.builderFee.success}, ` +\n `referral=${entry.referral.attempted}/${entry.referral.success}`,\n );\n });\n return entries.join('\\n') || '(empty)';\n }\n}\n\n// Export singleton instance with backward-compatible name\nexport const TradingReadinessCache = PerpsSigningCacheManager.getInstance();\n\n// Export with new name for clarity\nexport const PerpsSigningCache = PerpsSigningCacheManager.getInstance();\n"]}
@@ -1,3 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hyperLiquidModeFoldsSpot = exports.HL_UNIFIED_ACCOUNT_MODE = exports.HL_ABSTRACTION_WIRE = void 0;
4
+ /**
5
+ * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK
6
+ * types these as a `"i" | "u" | "p"` literal union with no exported constant.
7
+ *
8
+ * Only `unifiedAccount` is referenced by the current migration flow; the
9
+ * other entries document the full SDK wire format so a future caller
10
+ * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)
11
+ * does not have to re-discover the codes.
12
+ */
13
+ exports.HL_ABSTRACTION_WIRE = {
14
+ disabled: 'i',
15
+ unifiedAccount: 'u',
16
+ portfolioMargin: 'p',
17
+ };
18
+ /**
19
+ * Long-form abstraction-mode value targeted by the migration. Used as the
20
+ * `abstraction` parameter for `userSetAbstraction` and as the success / target
21
+ * value reported by Account Setup analytics.
22
+ */
23
+ exports.HL_UNIFIED_ACCOUNT_MODE = 'unifiedAccount';
24
+ /**
25
+ * True when the given HL abstraction mode treats spot balances as perps
26
+ * collateral. Fail-CLOSED on missing mode: until userAbstraction has been
27
+ * resolved we do not fold spot, because over-reporting withdrawable funds
28
+ * for Standard / dexAbstraction users (which `withdraw3` cannot actually
29
+ * draw) is worse than briefly under-reporting for Unified users during the
30
+ * initial subscription window or a transient REST outage.
31
+ *
32
+ * @param mode - Abstraction mode returned by HyperLiquid.
33
+ * @returns Whether spot balances should fold into perps collateral.
34
+ */
35
+ function hyperLiquidModeFoldsSpot(mode) {
36
+ if (mode === null || mode === undefined) {
37
+ return false;
38
+ }
39
+ return mode === 'unifiedAccount' || mode === 'portfolioMargin';
40
+ }
41
+ exports.hyperLiquidModeFoldsSpot = hyperLiquidModeFoldsSpot;
3
42
  //# sourceMappingURL=hyperliquid-types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperliquid-types.cjs","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * HyperLiquid SDK Type Aliases\n *\n * The @nktkas/hyperliquid SDK only exports Response types (e.g., ClearinghouseStateResponse).\n * We extract commonly-used nested types here to avoid repetitive type extraction syntax.\n *\n * Pattern: Import Response types, extract nested types using TypeScript index access.\n * This is the SDK's intentional design - not bad practice!\n */\nimport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n MetaAndAssetCtxsResponse,\n AllMidsResponse,\n PredictedFundingsResponse,\n OrderParameters,\n SpotMetaResponse,\n} from '@nktkas/hyperliquid';\n\n// Clearinghouse (Account) Types\nexport type AssetPosition =\n ClearinghouseStateResponse['assetPositions'][number];\nexport type SpotBalance = SpotClearinghouseStateResponse['balances'][number];\n\n// Market/Asset Types\nexport type PerpsUniverse = MetaResponse['universe'][number];\nexport type PerpsAssetCtx = MetaAndAssetCtxsResponse[1][number];\nexport type PredictedFunding = PredictedFundingsResponse[number];\n\n// Order Types\nexport type FrontendOrder = FrontendOpenOrdersResponse[number];\nexport type SDKOrderParams = OrderParameters['orders'][number];\nexport type OrderType = FrontendOrder['orderType'];\n\n// Re-export Response types for convenience\nexport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n AllMidsResponse,\n MetaAndAssetCtxsResponse,\n PredictedFundingsResponse,\n SpotMetaResponse,\n};\n"]}
1
+ {"version":3,"file":"hyperliquid-types.cjs","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":";;;AAsBA;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAG;IACjC,QAAQ,EAAE,GAAG;IACb,cAAc,EAAE,GAAG;IACnB,eAAe,EAAE,GAAG;CACZ,CAAC;AAEX;;;;GAIG;AACU,QAAA,uBAAuB,GAAG,gBAAyB,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,SAAgB,wBAAwB,CACtC,IAAqC;IAErC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,iBAAiB,CAAC;AACjE,CAAC;AARD,4DAQC","sourcesContent":["/**\n * HyperLiquid SDK Type Aliases\n *\n * The @nktkas/hyperliquid SDK only exports Response types (e.g., ClearinghouseStateResponse).\n * We extract commonly-used nested types here to avoid repetitive type extraction syntax.\n *\n * Pattern: Import Response types, extract nested types using TypeScript index access.\n * This is the SDK's intentional design - not bad practice!\n */\nimport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n MetaAndAssetCtxsResponse,\n AllMidsResponse,\n PredictedFundingsResponse,\n OrderParameters,\n SpotMetaResponse,\n UserAbstractionResponse,\n} from '@nktkas/hyperliquid';\n\n/**\n * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK\n * types these as a `\"i\" | \"u\" | \"p\"` literal union with no exported constant.\n *\n * Only `unifiedAccount` is referenced by the current migration flow; the\n * other entries document the full SDK wire format so a future caller\n * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)\n * does not have to re-discover the codes.\n */\nexport const HL_ABSTRACTION_WIRE = {\n disabled: 'i',\n unifiedAccount: 'u',\n portfolioMargin: 'p',\n} as const;\n\n/**\n * Long-form abstraction-mode value targeted by the migration. Used as the\n * `abstraction` parameter for `userSetAbstraction` and as the success / target\n * value reported by Account Setup analytics.\n */\nexport const HL_UNIFIED_ACCOUNT_MODE = 'unifiedAccount' as const;\n\n/**\n * True when the given HL abstraction mode treats spot balances as perps\n * collateral. Fail-CLOSED on missing mode: until userAbstraction has been\n * resolved we do not fold spot, because over-reporting withdrawable funds\n * for Standard / dexAbstraction users (which `withdraw3` cannot actually\n * draw) is worse than briefly under-reporting for Unified users during the\n * initial subscription window or a transient REST outage.\n *\n * @param mode - Abstraction mode returned by HyperLiquid.\n * @returns Whether spot balances should fold into perps collateral.\n */\nexport function hyperLiquidModeFoldsSpot(\n mode?: UserAbstractionResponse | null,\n): boolean {\n if (mode === null || mode === undefined) {\n return false;\n }\n\n return mode === 'unifiedAccount' || mode === 'portfolioMargin';\n}\n\n// Clearinghouse (Account) Types\nexport type AssetPosition =\n ClearinghouseStateResponse['assetPositions'][number];\nexport type SpotBalance = SpotClearinghouseStateResponse['balances'][number];\n\n// Market/Asset Types\nexport type PerpsUniverse = MetaResponse['universe'][number];\nexport type PerpsAssetCtx = MetaAndAssetCtxsResponse[1][number];\nexport type PredictedFunding = PredictedFundingsResponse[number];\n\n// Order Types\nexport type FrontendOrder = FrontendOpenOrdersResponse[number];\nexport type SDKOrderParams = OrderParameters['orders'][number];\nexport type OrderType = FrontendOrder['orderType'];\n\n// Re-export Response types for convenience\nexport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n AllMidsResponse,\n MetaAndAssetCtxsResponse,\n PredictedFundingsResponse,\n SpotMetaResponse,\n UserAbstractionResponse,\n};\n"]}
@@ -7,7 +7,39 @@
7
7
  * Pattern: Import Response types, extract nested types using TypeScript index access.
8
8
  * This is the SDK's intentional design - not bad practice!
9
9
  */
10
- import type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, MetaAndAssetCtxsResponse, AllMidsResponse, PredictedFundingsResponse, OrderParameters, SpotMetaResponse } from "@nktkas/hyperliquid";
10
+ import type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, MetaAndAssetCtxsResponse, AllMidsResponse, PredictedFundingsResponse, OrderParameters, SpotMetaResponse, UserAbstractionResponse } from "@nktkas/hyperliquid";
11
+ /**
12
+ * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK
13
+ * types these as a `"i" | "u" | "p"` literal union with no exported constant.
14
+ *
15
+ * Only `unifiedAccount` is referenced by the current migration flow; the
16
+ * other entries document the full SDK wire format so a future caller
17
+ * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)
18
+ * does not have to re-discover the codes.
19
+ */
20
+ export declare const HL_ABSTRACTION_WIRE: {
21
+ readonly disabled: "i";
22
+ readonly unifiedAccount: "u";
23
+ readonly portfolioMargin: "p";
24
+ };
25
+ /**
26
+ * Long-form abstraction-mode value targeted by the migration. Used as the
27
+ * `abstraction` parameter for `userSetAbstraction` and as the success / target
28
+ * value reported by Account Setup analytics.
29
+ */
30
+ export declare const HL_UNIFIED_ACCOUNT_MODE: "unifiedAccount";
31
+ /**
32
+ * True when the given HL abstraction mode treats spot balances as perps
33
+ * collateral. Fail-CLOSED on missing mode: until userAbstraction has been
34
+ * resolved we do not fold spot, because over-reporting withdrawable funds
35
+ * for Standard / dexAbstraction users (which `withdraw3` cannot actually
36
+ * draw) is worse than briefly under-reporting for Unified users during the
37
+ * initial subscription window or a transient REST outage.
38
+ *
39
+ * @param mode - Abstraction mode returned by HyperLiquid.
40
+ * @returns Whether spot balances should fold into perps collateral.
41
+ */
42
+ export declare function hyperLiquidModeFoldsSpot(mode?: UserAbstractionResponse | null): boolean;
11
43
  export type AssetPosition = ClearinghouseStateResponse['assetPositions'][number];
12
44
  export type SpotBalance = SpotClearinghouseStateResponse['balances'][number];
13
45
  export type PerpsUniverse = MetaResponse['universe'][number];
@@ -16,5 +48,5 @@ export type PredictedFunding = PredictedFundingsResponse[number];
16
48
  export type FrontendOrder = FrontendOpenOrdersResponse[number];
17
49
  export type SDKOrderParams = OrderParameters['orders'][number];
18
50
  export type OrderType = FrontendOrder['orderType'];
19
- export type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, AllMidsResponse, MetaAndAssetCtxsResponse, PredictedFundingsResponse, SpotMetaResponse, };
51
+ export type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, AllMidsResponse, MetaAndAssetCtxsResponse, PredictedFundingsResponse, SpotMetaResponse, UserAbstractionResponse, };
20
52
  //# sourceMappingURL=hyperliquid-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperliquid-types.d.cts","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EACjB,4BAA4B;AAG7B,MAAM,MAAM,aAAa,GACvB,0BAA0B,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,8BAA8B,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7E,MAAM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AAM,MAAM,aAAa,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAGjE,MAAM,MAAM,aAAa,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;AAGnD,YAAY,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,uBAAuB,GACxB,CAAC"}
@@ -7,7 +7,39 @@
7
7
  * Pattern: Import Response types, extract nested types using TypeScript index access.
8
8
  * This is the SDK's intentional design - not bad practice!
9
9
  */
10
- import type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, MetaAndAssetCtxsResponse, AllMidsResponse, PredictedFundingsResponse, OrderParameters, SpotMetaResponse } from "@nktkas/hyperliquid";
10
+ import type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, MetaAndAssetCtxsResponse, AllMidsResponse, PredictedFundingsResponse, OrderParameters, SpotMetaResponse, UserAbstractionResponse } from "@nktkas/hyperliquid";
11
+ /**
12
+ * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK
13
+ * types these as a `"i" | "u" | "p"` literal union with no exported constant.
14
+ *
15
+ * Only `unifiedAccount` is referenced by the current migration flow; the
16
+ * other entries document the full SDK wire format so a future caller
17
+ * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)
18
+ * does not have to re-discover the codes.
19
+ */
20
+ export declare const HL_ABSTRACTION_WIRE: {
21
+ readonly disabled: "i";
22
+ readonly unifiedAccount: "u";
23
+ readonly portfolioMargin: "p";
24
+ };
25
+ /**
26
+ * Long-form abstraction-mode value targeted by the migration. Used as the
27
+ * `abstraction` parameter for `userSetAbstraction` and as the success / target
28
+ * value reported by Account Setup analytics.
29
+ */
30
+ export declare const HL_UNIFIED_ACCOUNT_MODE: "unifiedAccount";
31
+ /**
32
+ * True when the given HL abstraction mode treats spot balances as perps
33
+ * collateral. Fail-CLOSED on missing mode: until userAbstraction has been
34
+ * resolved we do not fold spot, because over-reporting withdrawable funds
35
+ * for Standard / dexAbstraction users (which `withdraw3` cannot actually
36
+ * draw) is worse than briefly under-reporting for Unified users during the
37
+ * initial subscription window or a transient REST outage.
38
+ *
39
+ * @param mode - Abstraction mode returned by HyperLiquid.
40
+ * @returns Whether spot balances should fold into perps collateral.
41
+ */
42
+ export declare function hyperLiquidModeFoldsSpot(mode?: UserAbstractionResponse | null): boolean;
11
43
  export type AssetPosition = ClearinghouseStateResponse['assetPositions'][number];
12
44
  export type SpotBalance = SpotClearinghouseStateResponse['balances'][number];
13
45
  export type PerpsUniverse = MetaResponse['universe'][number];
@@ -16,5 +48,5 @@ export type PredictedFunding = PredictedFundingsResponse[number];
16
48
  export type FrontendOrder = FrontendOpenOrdersResponse[number];
17
49
  export type SDKOrderParams = OrderParameters['orders'][number];
18
50
  export type OrderType = FrontendOrder['orderType'];
19
- export type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, AllMidsResponse, MetaAndAssetCtxsResponse, PredictedFundingsResponse, SpotMetaResponse, };
51
+ export type { ClearinghouseStateResponse, SpotClearinghouseStateResponse, MetaResponse, FrontendOpenOrdersResponse, AllMidsResponse, MetaAndAssetCtxsResponse, PredictedFundingsResponse, SpotMetaResponse, UserAbstractionResponse, };
20
52
  //# sourceMappingURL=hyperliquid-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperliquid-types.d.mts","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EACjB,4BAA4B;AAG7B,MAAM,MAAM,aAAa,GACvB,0BAA0B,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,8BAA8B,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7E,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAGjE,MAAM,MAAM,aAAa,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;AAGnD,YAAY,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,GACjB,CAAC"}
1
+ {"version":3,"file":"hyperliquid-types.d.mts","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACxB,4BAA4B;AAE7B;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB;;;;CAItB,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,kBAA4B,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,CAAC,EAAE,uBAAuB,GAAG,IAAI,GACpC,OAAO,CAMT;AAGD,MAAM,MAAM,aAAa,GACvB,0BAA0B,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,8BAA8B,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7E,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAGjE,MAAM,MAAM,aAAa,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;AAGnD,YAAY,EACV,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,uBAAuB,GACxB,CAAC"}
@@ -1,2 +1,38 @@
1
- export {};
1
+ /**
2
+ * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK
3
+ * types these as a `"i" | "u" | "p"` literal union with no exported constant.
4
+ *
5
+ * Only `unifiedAccount` is referenced by the current migration flow; the
6
+ * other entries document the full SDK wire format so a future caller
7
+ * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)
8
+ * does not have to re-discover the codes.
9
+ */
10
+ export const HL_ABSTRACTION_WIRE = {
11
+ disabled: 'i',
12
+ unifiedAccount: 'u',
13
+ portfolioMargin: 'p',
14
+ };
15
+ /**
16
+ * Long-form abstraction-mode value targeted by the migration. Used as the
17
+ * `abstraction` parameter for `userSetAbstraction` and as the success / target
18
+ * value reported by Account Setup analytics.
19
+ */
20
+ export const HL_UNIFIED_ACCOUNT_MODE = 'unifiedAccount';
21
+ /**
22
+ * True when the given HL abstraction mode treats spot balances as perps
23
+ * collateral. Fail-CLOSED on missing mode: until userAbstraction has been
24
+ * resolved we do not fold spot, because over-reporting withdrawable funds
25
+ * for Standard / dexAbstraction users (which `withdraw3` cannot actually
26
+ * draw) is worse than briefly under-reporting for Unified users during the
27
+ * initial subscription window or a transient REST outage.
28
+ *
29
+ * @param mode - Abstraction mode returned by HyperLiquid.
30
+ * @returns Whether spot balances should fold into perps collateral.
31
+ */
32
+ export function hyperLiquidModeFoldsSpot(mode) {
33
+ if (mode === null || mode === undefined) {
34
+ return false;
35
+ }
36
+ return mode === 'unifiedAccount' || mode === 'portfolioMargin';
37
+ }
2
38
  //# sourceMappingURL=hyperliquid-types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hyperliquid-types.mjs","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * HyperLiquid SDK Type Aliases\n *\n * The @nktkas/hyperliquid SDK only exports Response types (e.g., ClearinghouseStateResponse).\n * We extract commonly-used nested types here to avoid repetitive type extraction syntax.\n *\n * Pattern: Import Response types, extract nested types using TypeScript index access.\n * This is the SDK's intentional design - not bad practice!\n */\nimport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n MetaAndAssetCtxsResponse,\n AllMidsResponse,\n PredictedFundingsResponse,\n OrderParameters,\n SpotMetaResponse,\n} from '@nktkas/hyperliquid';\n\n// Clearinghouse (Account) Types\nexport type AssetPosition =\n ClearinghouseStateResponse['assetPositions'][number];\nexport type SpotBalance = SpotClearinghouseStateResponse['balances'][number];\n\n// Market/Asset Types\nexport type PerpsUniverse = MetaResponse['universe'][number];\nexport type PerpsAssetCtx = MetaAndAssetCtxsResponse[1][number];\nexport type PredictedFunding = PredictedFundingsResponse[number];\n\n// Order Types\nexport type FrontendOrder = FrontendOpenOrdersResponse[number];\nexport type SDKOrderParams = OrderParameters['orders'][number];\nexport type OrderType = FrontendOrder['orderType'];\n\n// Re-export Response types for convenience\nexport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n AllMidsResponse,\n MetaAndAssetCtxsResponse,\n PredictedFundingsResponse,\n SpotMetaResponse,\n};\n"]}
1
+ {"version":3,"file":"hyperliquid-types.mjs","sourceRoot":"","sources":["../../src/types/hyperliquid-types.ts"],"names":[],"mappings":"AAsBA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,GAAG;IACb,cAAc,EAAE,GAAG;IACnB,eAAe,EAAE,GAAG;CACZ,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAyB,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAqC;IAErC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,iBAAiB,CAAC;AACjE,CAAC","sourcesContent":["/**\n * HyperLiquid SDK Type Aliases\n *\n * The @nktkas/hyperliquid SDK only exports Response types (e.g., ClearinghouseStateResponse).\n * We extract commonly-used nested types here to avoid repetitive type extraction syntax.\n *\n * Pattern: Import Response types, extract nested types using TypeScript index access.\n * This is the SDK's intentional design - not bad practice!\n */\nimport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n MetaAndAssetCtxsResponse,\n AllMidsResponse,\n PredictedFundingsResponse,\n OrderParameters,\n SpotMetaResponse,\n UserAbstractionResponse,\n} from '@nktkas/hyperliquid';\n\n/**\n * Wire codes accepted by `agentSetAbstraction({ abstraction })`. The SDK\n * types these as a `\"i\" | \"u\" | \"p\"` literal union with no exported constant.\n *\n * Only `unifiedAccount` is referenced by the current migration flow; the\n * other entries document the full SDK wire format so a future caller\n * (e.g. emergency rollback to `disabled`, or opting into `portfolioMargin`)\n * does not have to re-discover the codes.\n */\nexport const HL_ABSTRACTION_WIRE = {\n disabled: 'i',\n unifiedAccount: 'u',\n portfolioMargin: 'p',\n} as const;\n\n/**\n * Long-form abstraction-mode value targeted by the migration. Used as the\n * `abstraction` parameter for `userSetAbstraction` and as the success / target\n * value reported by Account Setup analytics.\n */\nexport const HL_UNIFIED_ACCOUNT_MODE = 'unifiedAccount' as const;\n\n/**\n * True when the given HL abstraction mode treats spot balances as perps\n * collateral. Fail-CLOSED on missing mode: until userAbstraction has been\n * resolved we do not fold spot, because over-reporting withdrawable funds\n * for Standard / dexAbstraction users (which `withdraw3` cannot actually\n * draw) is worse than briefly under-reporting for Unified users during the\n * initial subscription window or a transient REST outage.\n *\n * @param mode - Abstraction mode returned by HyperLiquid.\n * @returns Whether spot balances should fold into perps collateral.\n */\nexport function hyperLiquidModeFoldsSpot(\n mode?: UserAbstractionResponse | null,\n): boolean {\n if (mode === null || mode === undefined) {\n return false;\n }\n\n return mode === 'unifiedAccount' || mode === 'portfolioMargin';\n}\n\n// Clearinghouse (Account) Types\nexport type AssetPosition =\n ClearinghouseStateResponse['assetPositions'][number];\nexport type SpotBalance = SpotClearinghouseStateResponse['balances'][number];\n\n// Market/Asset Types\nexport type PerpsUniverse = MetaResponse['universe'][number];\nexport type PerpsAssetCtx = MetaAndAssetCtxsResponse[1][number];\nexport type PredictedFunding = PredictedFundingsResponse[number];\n\n// Order Types\nexport type FrontendOrder = FrontendOpenOrdersResponse[number];\nexport type SDKOrderParams = OrderParameters['orders'][number];\nexport type OrderType = FrontendOrder['orderType'];\n\n// Re-export Response types for convenience\nexport type {\n ClearinghouseStateResponse,\n SpotClearinghouseStateResponse,\n MetaResponse,\n FrontendOpenOrdersResponse,\n AllMidsResponse,\n MetaAndAssetCtxsResponse,\n PredictedFundingsResponse,\n SpotMetaResponse,\n UserAbstractionResponse,\n};\n"]}
@@ -45,6 +45,7 @@ var PerpsAnalyticsEvent;
45
45
  PerpsAnalyticsEvent["UiInteraction"] = "Perp UI Interaction";
46
46
  PerpsAnalyticsEvent["RiskManagement"] = "Perp Risk Management";
47
47
  PerpsAnalyticsEvent["PerpsError"] = "Perp Error";
48
+ PerpsAnalyticsEvent["AccountSetup"] = "Perp Account Setup";
48
49
  })(PerpsAnalyticsEvent || (exports.PerpsAnalyticsEvent = PerpsAnalyticsEvent = {}));
49
50
  /**
50
51
  * Perps trace name constants. Values match TraceName enum in mobile.