@metamask-previews/perps-controller 2.0.0-preview-51571fe → 2.0.0-preview-27fa5d81d

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 (52) hide show
  1. package/CHANGELOG.md +0 -18
  2. package/dist/PerpsController.cjs +10 -87
  3. package/dist/PerpsController.cjs.map +1 -1
  4. package/dist/PerpsController.d.cts +2 -25
  5. package/dist/PerpsController.d.cts.map +1 -1
  6. package/dist/PerpsController.d.mts +2 -25
  7. package/dist/PerpsController.d.mts.map +1 -1
  8. package/dist/PerpsController.mjs +10 -87
  9. package/dist/PerpsController.mjs.map +1 -1
  10. package/dist/constants/hyperLiquidConfig.cjs +2 -2
  11. package/dist/constants/hyperLiquidConfig.cjs.map +1 -1
  12. package/dist/constants/hyperLiquidConfig.mjs +2 -2
  13. package/dist/constants/hyperLiquidConfig.mjs.map +1 -1
  14. package/dist/constants/perpsConfig.cjs +1 -8
  15. package/dist/constants/perpsConfig.cjs.map +1 -1
  16. package/dist/constants/perpsConfig.d.cts +0 -7
  17. package/dist/constants/perpsConfig.d.cts.map +1 -1
  18. package/dist/constants/perpsConfig.d.mts +0 -7
  19. package/dist/constants/perpsConfig.d.mts.map +1 -1
  20. package/dist/constants/perpsConfig.mjs +0 -7
  21. package/dist/constants/perpsConfig.mjs.map +1 -1
  22. package/dist/providers/HyperLiquidProvider.cjs +0 -31
  23. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  24. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  25. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  26. package/dist/providers/HyperLiquidProvider.mjs +0 -31
  27. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  28. package/dist/services/AccountService.cjs +35 -35
  29. package/dist/services/AccountService.cjs.map +1 -1
  30. package/dist/services/AccountService.d.cts.map +1 -1
  31. package/dist/services/AccountService.d.mts.map +1 -1
  32. package/dist/services/AccountService.mjs +35 -35
  33. package/dist/services/AccountService.mjs.map +1 -1
  34. package/dist/services/HyperLiquidSubscriptionService.cjs +19 -32
  35. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  36. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  37. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  38. package/dist/services/HyperLiquidSubscriptionService.mjs +19 -32
  39. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  40. package/dist/services/TradingService.cjs +3 -4
  41. package/dist/services/TradingService.cjs.map +1 -1
  42. package/dist/services/TradingService.d.cts.map +1 -1
  43. package/dist/services/TradingService.d.mts.map +1 -1
  44. package/dist/services/TradingService.mjs +3 -4
  45. package/dist/services/TradingService.mjs.map +1 -1
  46. package/dist/utils/orderCalculations.cjs +1 -4
  47. package/dist/utils/orderCalculations.cjs.map +1 -1
  48. package/dist/utils/orderCalculations.d.cts.map +1 -1
  49. package/dist/utils/orderCalculations.d.mts.map +1 -1
  50. package/dist/utils/orderCalculations.mjs +2 -5
  51. package/dist/utils/orderCalculations.mjs.map +1 -1
  52. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,29 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Refactor pending withdraw/deposit tracking to FIFO queue design ([#8333](https://github.com/MetaMask/core/pull/8333))
13
- - Add `completeWithdrawalFromHistory` method for FIFO-based withdrawal completion matching ([#8333](https://github.com/MetaMask/core/pull/8333))
14
- - Add `lastCompletedWithdrawalTimestamp` and `lastCompletedWithdrawalTxHashes` state fields ([#8333](https://github.com/MetaMask/core/pull/8333))
15
-
16
10
  ### Changed
17
11
 
18
- - Centralize Arbitrum network check in deposit hooks to prevent missing network errors ([#8333](https://github.com/MetaMask/core/pull/8333))
19
- - Provider credentials, builder fee injection, and env var centralization ([#8333](https://github.com/MetaMask/core/pull/8333))
20
- - Reduce max order amount by 0.5% buffer to avoid insufficient margin rejections ([#8333](https://github.com/MetaMask/core/pull/8333))
21
12
  - Bump `@metamask/account-tree-controller` from `^6.0.0` to `^7.0.0` ([#8325](https://github.com/MetaMask/core/pull/8325))
22
13
  - Bump `@metamask/profile-sync-controller` from `^28.0.1` to `^28.0.2` ([#8325](https://github.com/MetaMask/core/pull/8325))
23
14
 
24
- ### Fixed
25
-
26
- - Fix incorrect fee estimate when flipping a position ([#8333](https://github.com/MetaMask/core/pull/8333))
27
- - Fix incorrect PnL and order size displayed after SL execution ([#8333](https://github.com/MetaMask/core/pull/8333))
28
- - Fix stop loss not showing up in recent activity ([#8333](https://github.com/MetaMask/core/pull/8333))
29
- - Fix incorrect market categories ([#8333](https://github.com/MetaMask/core/pull/8333))
30
- - Fix TP/SL decimal precision for PUMP ([#8333](https://github.com/MetaMask/core/pull/8333))
31
- - Fix missing decimal on price input when using preset on limit price ([#8333](https://github.com/MetaMask/core/pull/8333))
32
-
33
15
  ## [2.0.0]
34
16
 
35
17
  ### Changed
@@ -106,8 +106,6 @@ const getDefaultPerpsControllerState = () => ({
106
106
  withdrawInProgress: false,
107
107
  lastDepositTransactionId: null,
108
108
  lastWithdrawResult: null,
109
- lastCompletedWithdrawalTimestamp: null,
110
- lastCompletedWithdrawalTxHashes: [],
111
109
  withdrawalRequests: [],
112
110
  withdrawalProgress: {
113
111
  progress: 0,
@@ -220,18 +218,6 @@ const metadata = {
220
218
  includeInDebugSnapshot: false,
221
219
  usedInUi: true,
222
220
  },
223
- lastCompletedWithdrawalTimestamp: {
224
- includeInStateLogs: true,
225
- persist: true,
226
- includeInDebugSnapshot: false,
227
- usedInUi: true,
228
- },
229
- lastCompletedWithdrawalTxHashes: {
230
- includeInStateLogs: false,
231
- persist: false,
232
- includeInDebugSnapshot: false,
233
- usedInUi: true,
234
- },
235
221
  withdrawalRequests: {
236
222
  includeInStateLogs: true,
237
223
  persist: true,
@@ -1200,9 +1186,8 @@ class PerpsController extends base_controller_1.BaseController {
1200
1186
  });
1201
1187
  }
1202
1188
  /**
1203
- * Update withdrawal request status when it completes, or remove it on failure.
1204
- * This is called when a withdrawal is matched with a completed withdrawal from the API.
1205
- * When status is `failed`, the request is removed from the queue (not retained).
1189
+ * Update withdrawal request status when it completes
1190
+ * This is called when a withdrawal is matched with a completed withdrawal from the API
1206
1191
  *
1207
1192
  * @param withdrawalId - The withdrawal transaction ID.
1208
1193
  * @param status - The current status.
@@ -1220,22 +1205,13 @@ class PerpsController extends base_controller_1.BaseController {
1220
1205
  withdrawalAmount = request.amount;
1221
1206
  shouldTrack =
1222
1207
  withdrawalAmount !== undefined && request.status !== status;
1223
- if (status === 'failed') {
1224
- state.withdrawalRequests.splice(withdrawalIndex, 1);
1225
- state.withdrawInProgress = state.withdrawalRequests.some((req) => req.status === 'pending' || req.status === 'bridging');
1226
- state.withdrawalProgress = {
1227
- progress: 0,
1228
- lastUpdated: Date.now(),
1229
- activeWithdrawalId: null,
1230
- };
1208
+ request.status = status;
1209
+ request.success = status === 'completed';
1210
+ if (txHash) {
1211
+ request.txHash = txHash;
1231
1212
  }
1232
- else {
1233
- request.status = status;
1234
- request.success = status === 'completed';
1235
- if (txHash) {
1236
- request.txHash = txHash;
1237
- }
1238
- // Clear withdrawal progress when withdrawal completes
1213
+ // Clear withdrawal progress when withdrawal completes
1214
+ if (status === 'completed' || status === 'failed') {
1239
1215
  state.withdrawalProgress = {
1240
1216
  progress: 0,
1241
1217
  lastUpdated: Date.now(),
@@ -1260,59 +1236,6 @@ class PerpsController extends base_controller_1.BaseController {
1260
1236
  });
1261
1237
  }
1262
1238
  }
1263
- /**
1264
- * Complete a specific withdrawal detected via transaction history polling (FIFO queue).
1265
- * Called when a completed withdrawal appears in the transaction history matching a pending request.
1266
- *
1267
- * Uses FIFO matching: oldest pending withdrawal is matched with first completed withdrawal
1268
- * in history that happened after its submission time.
1269
- *
1270
- * @param withdrawalRequestId - The ID of the pending withdrawal request to mark as complete.
1271
- * @param completedWithdrawal - The completed withdrawal data from the history API.
1272
- * @param completedWithdrawal.txHash - The on-chain transaction hash.
1273
- * @param completedWithdrawal.amount - The withdrawal amount.
1274
- * @param completedWithdrawal.timestamp - The completion timestamp from the history API.
1275
- * @param completedWithdrawal.asset - The asset symbol (e.g. USDC).
1276
- */
1277
- completeWithdrawalFromHistory(withdrawalRequestId, completedWithdrawal) {
1278
- let didRemove = false;
1279
- this.update((state) => {
1280
- const requestIndex = state.withdrawalRequests.findIndex((req) => req.id === withdrawalRequestId);
1281
- if (requestIndex === -1) {
1282
- return;
1283
- }
1284
- didRemove = true;
1285
- state.withdrawalRequests.splice(requestIndex, 1);
1286
- // Update the FIFO guard. The timestamp is persisted for cross-restart
1287
- // protection. The txHashes array (not persisted) accumulates within a
1288
- // session to prevent re-matching direct completions and same-millisecond
1289
- // API completions. It resets naturally on app restart.
1290
- state.lastCompletedWithdrawalTimestamp = completedWithdrawal.timestamp;
1291
- state.lastCompletedWithdrawalTxHashes.push(completedWithdrawal.txHash);
1292
- const hasPendingWithdrawals = state.withdrawalRequests.some((req) => req.status === 'pending' || req.status === 'bridging');
1293
- state.withdrawInProgress = hasPendingWithdrawals;
1294
- if (!hasPendingWithdrawals) {
1295
- state.withdrawalProgress = {
1296
- progress: 0,
1297
- lastUpdated: Date.now(),
1298
- activeWithdrawalId: null,
1299
- };
1300
- }
1301
- state.lastUpdateTimestamp = Date.now();
1302
- });
1303
- if (!didRemove) {
1304
- return;
1305
- }
1306
- __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, 'PerpsController: Completed withdrawal from transaction history (FIFO)', {
1307
- withdrawalRequestId,
1308
- txHash: completedWithdrawal.txHash,
1309
- amount: completedWithdrawal.amount,
1310
- });
1311
- __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getMetrics).call(this).trackPerpsEvent(types_1.PerpsAnalyticsEvent.WithdrawalTransaction, {
1312
- [eventNames_1.PERPS_EVENT_PROPERTY.STATUS]: eventNames_1.PERPS_EVENT_VALUE.STATUS.COMPLETED,
1313
- [eventNames_1.PERPS_EVENT_PROPERTY.WITHDRAWAL_AMOUNT]: Number.parseFloat(completedWithdrawal.amount),
1314
- });
1315
- }
1316
1239
  /**
1317
1240
  * Update withdrawal progress (persistent across navigation)
1318
1241
  *
@@ -2485,7 +2408,7 @@ class PerpsController extends base_controller_1.BaseController {
2485
2408
  timestamp: new Date().toISOString(),
2486
2409
  });
2487
2410
  this.update((state) => {
2488
- // Filter out pending/bridging withdrawals, keep completed for history
2411
+ // Filter out pending/bridging withdrawals, keep completed/failed for history
2489
2412
  state.withdrawalRequests = state.withdrawalRequests.filter((req) => req.status !== 'pending' && req.status !== 'bridging');
2490
2413
  // Filter out pending deposits, keep completed/failed for history
2491
2414
  state.depositRequests = state.depositRequests.filter((req) => req.status !== 'pending' && req.status !== 'bridging');
@@ -2988,7 +2911,7 @@ async function _PerpsController_submitTransaction(txParams, options) {
2988
2911
  }, _PerpsController_migrateRequestsIfNeeded = function _PerpsController_migrateRequestsIfNeeded() {
2989
2912
  this.update((state) => {
2990
2913
  // Remove withdrawal requests without accountAddress - they can't be attributed to any account
2991
- state.withdrawalRequests = state.withdrawalRequests.filter((req) => Boolean(req.accountAddress) && req.status !== 'failed');
2914
+ state.withdrawalRequests = state.withdrawalRequests.filter((req) => Boolean(req.accountAddress));
2992
2915
  // Remove deposit requests without accountAddress - they can't be attributed to any account
2993
2916
  state.depositRequests = state.depositRequests.filter((req) => Boolean(req.accountAddress));
2994
2917
  });