@metamask-previews/perps-controller 2.0.0-preview-27fa5d81d → 2.0.0-preview-086e47368
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/PerpsController.cjs +87 -10
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +25 -2
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +25 -2
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +87 -10
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/hyperLiquidConfig.cjs +2 -2
- package/dist/constants/hyperLiquidConfig.cjs.map +1 -1
- package/dist/constants/hyperLiquidConfig.mjs +2 -2
- package/dist/constants/hyperLiquidConfig.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +8 -1
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +7 -0
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +7 -0
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +7 -0
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +31 -0
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +31 -0
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/AccountService.cjs +35 -35
- package/dist/services/AccountService.cjs.map +1 -1
- package/dist/services/AccountService.d.cts.map +1 -1
- package/dist/services/AccountService.d.mts.map +1 -1
- package/dist/services/AccountService.mjs +35 -35
- package/dist/services/AccountService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +32 -19
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +32 -19
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/TradingService.cjs +4 -3
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +4 -3
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/utils/orderCalculations.cjs +4 -1
- package/dist/utils/orderCalculations.cjs.map +1 -1
- package/dist/utils/orderCalculations.d.cts.map +1 -1
- package/dist/utils/orderCalculations.d.mts.map +1 -1
- package/dist/utils/orderCalculations.mjs +5 -2
- package/dist/utils/orderCalculations.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,29 @@ 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
|
+
|
|
10
16
|
### Changed
|
|
11
17
|
|
|
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))
|
|
12
21
|
- Bump `@metamask/account-tree-controller` from `^6.0.0` to `^7.0.0` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
13
22
|
- Bump `@metamask/profile-sync-controller` from `^28.0.1` to `^28.0.2` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
14
23
|
|
|
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
|
+
|
|
15
33
|
## [2.0.0]
|
|
16
34
|
|
|
17
35
|
### Changed
|
package/dist/PerpsController.cjs
CHANGED
|
@@ -106,6 +106,8 @@ const getDefaultPerpsControllerState = () => ({
|
|
|
106
106
|
withdrawInProgress: false,
|
|
107
107
|
lastDepositTransactionId: null,
|
|
108
108
|
lastWithdrawResult: null,
|
|
109
|
+
lastCompletedWithdrawalTimestamp: null,
|
|
110
|
+
lastCompletedWithdrawalTxHashes: [],
|
|
109
111
|
withdrawalRequests: [],
|
|
110
112
|
withdrawalProgress: {
|
|
111
113
|
progress: 0,
|
|
@@ -218,6 +220,18 @@ const metadata = {
|
|
|
218
220
|
includeInDebugSnapshot: false,
|
|
219
221
|
usedInUi: true,
|
|
220
222
|
},
|
|
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
|
+
},
|
|
221
235
|
withdrawalRequests: {
|
|
222
236
|
includeInStateLogs: true,
|
|
223
237
|
persist: true,
|
|
@@ -1186,8 +1200,9 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1186
1200
|
});
|
|
1187
1201
|
}
|
|
1188
1202
|
/**
|
|
1189
|
-
* Update withdrawal request status when it completes
|
|
1190
|
-
* This is called when a withdrawal is matched with a completed withdrawal from the API
|
|
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).
|
|
1191
1206
|
*
|
|
1192
1207
|
* @param withdrawalId - The withdrawal transaction ID.
|
|
1193
1208
|
* @param status - The current status.
|
|
@@ -1205,13 +1220,22 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1205
1220
|
withdrawalAmount = request.amount;
|
|
1206
1221
|
shouldTrack =
|
|
1207
1222
|
withdrawalAmount !== undefined && request.status !== status;
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
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
|
+
};
|
|
1212
1231
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
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
|
|
1215
1239
|
state.withdrawalProgress = {
|
|
1216
1240
|
progress: 0,
|
|
1217
1241
|
lastUpdated: Date.now(),
|
|
@@ -1236,6 +1260,59 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1236
1260
|
});
|
|
1237
1261
|
}
|
|
1238
1262
|
}
|
|
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
|
+
}
|
|
1239
1316
|
/**
|
|
1240
1317
|
* Update withdrawal progress (persistent across navigation)
|
|
1241
1318
|
*
|
|
@@ -2408,7 +2485,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
2408
2485
|
timestamp: new Date().toISOString(),
|
|
2409
2486
|
});
|
|
2410
2487
|
this.update((state) => {
|
|
2411
|
-
// Filter out pending/bridging withdrawals, keep completed
|
|
2488
|
+
// Filter out pending/bridging withdrawals, keep completed for history
|
|
2412
2489
|
state.withdrawalRequests = state.withdrawalRequests.filter((req) => req.status !== 'pending' && req.status !== 'bridging');
|
|
2413
2490
|
// Filter out pending deposits, keep completed/failed for history
|
|
2414
2491
|
state.depositRequests = state.depositRequests.filter((req) => req.status !== 'pending' && req.status !== 'bridging');
|
|
@@ -2911,7 +2988,7 @@ async function _PerpsController_submitTransaction(txParams, options) {
|
|
|
2911
2988
|
}, _PerpsController_migrateRequestsIfNeeded = function _PerpsController_migrateRequestsIfNeeded() {
|
|
2912
2989
|
this.update((state) => {
|
|
2913
2990
|
// Remove withdrawal requests without accountAddress - they can't be attributed to any account
|
|
2914
|
-
state.withdrawalRequests = state.withdrawalRequests.filter((req) => Boolean(req.accountAddress));
|
|
2991
|
+
state.withdrawalRequests = state.withdrawalRequests.filter((req) => Boolean(req.accountAddress) && req.status !== 'failed');
|
|
2915
2992
|
// Remove deposit requests without accountAddress - they can't be attributed to any account
|
|
2916
2993
|
state.depositRequests = state.depositRequests.filter((req) => Boolean(req.accountAddress));
|
|
2917
2994
|
});
|