@metamask-previews/perps-controller 22.1.2-preview-2c49dc768 → 22.1.2-preview-4a5ac306d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -11
- package/dist/PerpsController-method-action-types.d.ts +5 -7
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +5 -7
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +5 -7
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/perpsConfig.d.ts +22 -0
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +18 -0
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/errors.d.ts +2 -13
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/perpsErrorCodes.d.ts +0 -2
- package/dist/perpsErrorCodes.d.ts.map +1 -1
- package/dist/perpsErrorCodes.js +0 -3
- package/dist/perpsErrorCodes.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +5 -6
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +133 -107
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/services/TradingService.d.ts.map +1 -1
- package/dist/services/TradingService.js +4 -7
- package/dist/services/TradingService.js.map +1 -1
- package/dist/types/index.d.ts +1 -36
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/accountUtils.d.ts +61 -0
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +50 -0
- package/dist/utils/accountUtils.js.map +1 -1
- package/dist/utils/errorContext.d.ts +0 -33
- package/dist/utils/errorContext.d.ts.map +1 -1
- package/dist/utils/errorContext.js +0 -41
- package/dist/utils/errorContext.js.map +1 -1
- package/dist/utils/errorUtils.d.ts +0 -18
- package/dist/utils/errorUtils.d.ts.map +1 -1
- package/dist/utils/errorUtils.js +1 -127
- package/dist/utils/errorUtils.js.map +1 -1
- package/dist/utils/hyperLiquidValidation.d.ts +2 -9
- package/dist/utils/hyperLiquidValidation.d.ts.map +1 -1
- package/dist/utils/hyperLiquidValidation.js +17 -18
- package/dist/utils/hyperLiquidValidation.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/significantFigures.d.ts.map +1 -1
- package/dist/utils/significantFigures.js +4 -6
- package/dist/utils/significantFigures.js.map +1 -1
- package/dist/utils/stringParseUtils.d.ts +8 -0
- package/dist/utils/stringParseUtils.d.ts.map +1 -1
- package/dist/utils/stringParseUtils.js +10 -0
- package/dist/utils/stringParseUtils.js.map +1 -1
- package/dist/utils/tpslCalculations.d.ts +187 -0
- package/dist/utils/tpslCalculations.d.ts.map +1 -0
- package/dist/utils/tpslCalculations.js +405 -0
- package/dist/utils/tpslCalculations.js.map +1 -0
- package/package.json +2 -2
|
@@ -21,7 +21,7 @@ import { PerpsAnalyticsEvent } from '../types/index.js';
|
|
|
21
21
|
import { addSpotBalanceToAccountState, aggregateAccountStates, } from '../utils/accountUtils.js';
|
|
22
22
|
import { isValidCapabilitySymbol } from '../utils/capabilitySymbols.js';
|
|
23
23
|
import { PERPS_ERROR_ACTION, PERPS_ERROR_COMPONENT, PERPS_ERROR_OPERATION, createPerpsErrorContext, } from '../utils/errorContext.js';
|
|
24
|
-
import { ensureError, isHyperLiquidMultiSigRequiredError, isHyperLiquidUserNotFoundError, isKeyringLockedError,
|
|
24
|
+
import { ensureError, isHyperLiquidMultiSigRequiredError, isHyperLiquidUserNotFoundError, isKeyringLockedError, } from '../utils/errorUtils.js';
|
|
25
25
|
import { shouldDeferUnifiedAccountSetup } from '../utils/hyperLiquidAbstraction.js';
|
|
26
26
|
import { adaptAccountStateFromSDK, adaptHyperLiquidLedgerUpdateToUserHistoryItem, adaptMarketFromSDK, adaptOrderFromSDK, adaptPositionFromSDK, adaptPositionTriggerOrderFromSDK, adaptTpslLinkageToGrouping, buildAssetMapping, buildHyperLiquidFillId, formatHyperLiquidPrice, formatHyperLiquidSize, HYPERLIQUID_SCALE_CLOID_MARKER, parseAssetName, readScaleGroupId, } from '../utils/hyperLiquidAdapter.js';
|
|
27
27
|
import { previewHyperLiquidIsolatedPositionModify, resolveHyperLiquidMarginTiers, } from '../utils/hyperLiquidPositionPreview.js';
|
|
@@ -835,6 +835,13 @@ export class HyperLiquidProvider {
|
|
|
835
835
|
#pendingValidatedDexsPromise = null;
|
|
836
836
|
// Cache for USDC token ID from spot metadata
|
|
837
837
|
#cachedUsdcTokenId;
|
|
838
|
+
// Error mappings from HyperLiquid API errors to standardized PERPS_ERROR_CODES
|
|
839
|
+
#errorMappings = {
|
|
840
|
+
'isolated position does not have sufficient margin available to decrease leverage': PERPS_ERROR_CODES.ORDER_LEVERAGE_REDUCTION_FAILED,
|
|
841
|
+
'could not immediately match': PERPS_ERROR_CODES.IOC_CANCEL,
|
|
842
|
+
'multi-sig required': PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED,
|
|
843
|
+
'invalid nonce': PERPS_ERROR_CODES.EXCHANGE_INVALID_NONCE,
|
|
844
|
+
};
|
|
838
845
|
// Scale ladders placed by this provider instance, keyed by group handle, so
|
|
839
846
|
// one cancel can reach every rung. Cleared on disconnect; the rung IDs are
|
|
840
847
|
// also returned to the caller as `OrderResult.childOrderIds`.
|
|
@@ -3432,7 +3439,22 @@ export class HyperLiquidProvider {
|
|
|
3432
3439
|
* @returns The result of the operation.
|
|
3433
3440
|
*/
|
|
3434
3441
|
#mapError(error) {
|
|
3435
|
-
|
|
3442
|
+
const { message } = ensureError(error, 'HyperLiquidProvider.mapError');
|
|
3443
|
+
// "User or API Wallet 0x... does not exist." carries the user's address, so
|
|
3444
|
+
// it cannot be matched by the static substring table below. It means the
|
|
3445
|
+
// wallet has no Hyperliquid account yet — surface an actionable code the
|
|
3446
|
+
// client can translate ("fund your account") instead of leaking the raw
|
|
3447
|
+
// exchange string to the UI and to failed-trade analytics.
|
|
3448
|
+
if (isHyperLiquidUserNotFoundError(error)) {
|
|
3449
|
+
return new PerpsControllerError(PERPS_ERROR_CODES.EXCHANGE_ACCOUNT_NOT_FOUND, PERPS_ERROR_CODES.EXCHANGE_ACCOUNT_NOT_FOUND);
|
|
3450
|
+
}
|
|
3451
|
+
for (const [pattern, code] of Object.entries(this.#errorMappings)) {
|
|
3452
|
+
if (message.toLowerCase().includes(pattern.toLowerCase())) {
|
|
3453
|
+
return new PerpsControllerError(code, code);
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
// Return original error to preserve stack trace for unmapped errors
|
|
3457
|
+
return ensureError(error, 'HyperLiquidProvider.mapError');
|
|
3436
3458
|
}
|
|
3437
3459
|
/**
|
|
3438
3460
|
* Map a rejection the venue reported in a status entry rather than threw,
|
|
@@ -4884,7 +4906,7 @@ export class HyperLiquidProvider {
|
|
|
4884
4906
|
error: isMinimumOrderError &&
|
|
4885
4907
|
!params.reduceOnly &&
|
|
4886
4908
|
!isStrategyOrderType(params.orderType)
|
|
4887
|
-
? new PerpsControllerError(PERPS_ERROR_CODES.ORDER_SIZE_MIN, PERPS_ERROR_CODES.ORDER_SIZE_MIN
|
|
4909
|
+
? new PerpsControllerError(PERPS_ERROR_CODES.ORDER_SIZE_MIN, PERPS_ERROR_CODES.ORDER_SIZE_MIN)
|
|
4888
4910
|
: error,
|
|
4889
4911
|
symbol: params.symbol,
|
|
4890
4912
|
orderType: params.orderType,
|
|
@@ -7848,15 +7870,21 @@ export class HyperLiquidProvider {
|
|
|
7848
7870
|
};
|
|
7849
7871
|
}
|
|
7850
7872
|
catch (error) {
|
|
7851
|
-
const
|
|
7873
|
+
const signerFailure = await this.#handleSignerFailure(error, 'editOrder', {
|
|
7874
|
+
orderId: params.orderId,
|
|
7875
|
+
});
|
|
7876
|
+
if (signerFailure) {
|
|
7877
|
+
return createErrorResult(signerFailure, { success: false });
|
|
7878
|
+
}
|
|
7879
|
+
this.#deps.logger.error(ensureError(error, 'HyperLiquidProvider.editOrder'), this.#getErrorContext('editOrder', {
|
|
7852
7880
|
orderId: params.orderId,
|
|
7853
7881
|
coin: params.newOrder.symbol,
|
|
7854
7882
|
orderType: params.newOrder.orderType,
|
|
7855
7883
|
}, {
|
|
7856
7884
|
operation: PERPS_ERROR_OPERATION.OrderManagement,
|
|
7857
7885
|
action: PERPS_ERROR_ACTION.EditOrder,
|
|
7858
|
-
});
|
|
7859
|
-
return createErrorResult(
|
|
7886
|
+
}));
|
|
7887
|
+
return createErrorResult(error, { success: false });
|
|
7860
7888
|
}
|
|
7861
7889
|
}
|
|
7862
7890
|
/**
|
|
@@ -8347,36 +8375,17 @@ export class HyperLiquidProvider {
|
|
|
8347
8375
|
}
|
|
8348
8376
|
// Index submitted and skipped outcomes by symbol so `results` can keep the
|
|
8349
8377
|
// order of the requested positions: consumers may correlate them by index.
|
|
8350
|
-
const submittedResults = new Map(statuses.map((status, index) =>
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
return [
|
|
8362
|
-
orderedPositions[index].symbol,
|
|
8363
|
-
{
|
|
8364
|
-
symbol: orderedPositions[index].symbol,
|
|
8365
|
-
success,
|
|
8366
|
-
error: success || normalizedStatusError === undefined
|
|
8367
|
-
? undefined
|
|
8368
|
-
: normalizedStatusError.message,
|
|
8369
|
-
...(success || normalizedStatusError === undefined
|
|
8370
|
-
? {}
|
|
8371
|
-
: {
|
|
8372
|
-
errorCode: normalizedStatusError.errorCode,
|
|
8373
|
-
...(normalizedStatusError.errorDetails === undefined
|
|
8374
|
-
? {}
|
|
8375
|
-
: { errorDetails: normalizedStatusError.errorDetails }),
|
|
8376
|
-
}),
|
|
8377
|
-
},
|
|
8378
|
-
];
|
|
8379
|
-
}));
|
|
8378
|
+
const submittedResults = new Map(statuses.map((status, index) => [
|
|
8379
|
+
orderedPositions[index].symbol,
|
|
8380
|
+
{
|
|
8381
|
+
symbol: orderedPositions[index].symbol,
|
|
8382
|
+
success: isStatusObject(status) &&
|
|
8383
|
+
(hasProperty(status, 'filled') || hasProperty(status, 'resting')),
|
|
8384
|
+
error: isStatusObject(status) && hasProperty(status, 'error')
|
|
8385
|
+
? String(status.error)
|
|
8386
|
+
: undefined,
|
|
8387
|
+
},
|
|
8388
|
+
]));
|
|
8380
8389
|
const skippedBySymbol = new Map(skippedResults.map((skipped) => [skipped.symbol, skipped]));
|
|
8381
8390
|
return {
|
|
8382
8391
|
success: successCount > 0,
|
|
@@ -8396,31 +8405,34 @@ export class HyperLiquidProvider {
|
|
|
8396
8405
|
if (accountContext) {
|
|
8397
8406
|
this.#recordUnsupportedAccountFromError(error, accountContext);
|
|
8398
8407
|
}
|
|
8399
|
-
const
|
|
8400
|
-
? error
|
|
8401
|
-
: new Error(PERPS_ERROR_CODES.BATCH_CLOSE_FAILED), 'closePositions', {
|
|
8408
|
+
const signerFailure = await this.#handleSignerFailure(error, 'closePositions', {
|
|
8402
8409
|
positionCount: positionsToClose.length,
|
|
8403
|
-
}, {
|
|
8404
|
-
operation: PERPS_ERROR_OPERATION.PositionManagement,
|
|
8405
|
-
action: PERPS_ERROR_ACTION.ClosePosition,
|
|
8406
8410
|
});
|
|
8407
|
-
const
|
|
8408
|
-
|
|
8411
|
+
const safeError = signerFailure ??
|
|
8412
|
+
ensureError(error, 'HyperLiquidProvider.closePositions');
|
|
8413
|
+
if (!signerFailure) {
|
|
8414
|
+
this.#deps.logger.error(safeError, this.#getErrorContext('closePositions', {
|
|
8415
|
+
positionCount: positionsToClose.length,
|
|
8416
|
+
}, {
|
|
8417
|
+
operation: PERPS_ERROR_OPERATION.PositionManagement,
|
|
8418
|
+
action: PERPS_ERROR_ACTION.ClosePosition,
|
|
8419
|
+
}));
|
|
8420
|
+
}
|
|
8409
8421
|
// Return all selected positions as failed, including unavailable DEXes.
|
|
8410
8422
|
return {
|
|
8411
8423
|
success: false,
|
|
8412
8424
|
successCount: 0,
|
|
8413
8425
|
failureCount: positionsToClose.length + unavailableResults.length,
|
|
8414
|
-
error:
|
|
8415
|
-
|
|
8416
|
-
|
|
8426
|
+
error: error instanceof Error
|
|
8427
|
+
? safeError.message
|
|
8428
|
+
: PERPS_ERROR_CODES.BATCH_CLOSE_FAILED,
|
|
8417
8429
|
results: [
|
|
8418
8430
|
...positionsToClose.map((position) => ({
|
|
8419
8431
|
symbol: position.symbol,
|
|
8420
8432
|
success: false,
|
|
8421
|
-
error:
|
|
8422
|
-
|
|
8423
|
-
|
|
8433
|
+
error: error instanceof Error
|
|
8434
|
+
? safeError.message
|
|
8435
|
+
: PERPS_ERROR_CODES.BATCH_CLOSE_FAILED,
|
|
8424
8436
|
})),
|
|
8425
8437
|
...unavailableResults,
|
|
8426
8438
|
],
|
|
@@ -9260,15 +9272,19 @@ export class HyperLiquidProvider {
|
|
|
9260
9272
|
});
|
|
9261
9273
|
}
|
|
9262
9274
|
catch (error) {
|
|
9263
|
-
const
|
|
9275
|
+
const signerFailure = await this.#handleSignerFailure(error, 'updatePositionTPSL', { symbol: params.symbol });
|
|
9276
|
+
if (signerFailure) {
|
|
9277
|
+
return createErrorResult(signerFailure, { success: false });
|
|
9278
|
+
}
|
|
9279
|
+
this.#deps.logger.error(ensureError(error, 'HyperLiquidProvider.updatePositionTPSL'), this.#getErrorContext('updatePositionTPSL', {
|
|
9264
9280
|
symbol: params.symbol,
|
|
9265
9281
|
hasTakeProfit: params.takeProfitPrice !== undefined,
|
|
9266
9282
|
hasStopLoss: params.stopLossPrice !== undefined,
|
|
9267
9283
|
}, {
|
|
9268
9284
|
operation: PERPS_ERROR_OPERATION.PositionManagement,
|
|
9269
9285
|
action: PERPS_ERROR_ACTION.PositionTpslUpdate,
|
|
9270
|
-
});
|
|
9271
|
-
return createErrorResult(
|
|
9286
|
+
}));
|
|
9287
|
+
return createErrorResult(error, { success: false });
|
|
9272
9288
|
}
|
|
9273
9289
|
}
|
|
9274
9290
|
/**
|
|
@@ -9414,8 +9430,6 @@ export class HyperLiquidProvider {
|
|
|
9414
9430
|
return result;
|
|
9415
9431
|
}
|
|
9416
9432
|
catch (error) {
|
|
9417
|
-
// Setup failures are returned for the service boundary to report. The
|
|
9418
|
-
// result is still normalized so the raw message never crosses it.
|
|
9419
9433
|
const safeError = ensureError(error, 'HyperLiquidProvider.closePosition');
|
|
9420
9434
|
this.#deps.debugLogger.log('[closePosition] Close failed', {
|
|
9421
9435
|
error: safeError.message,
|
|
@@ -9499,17 +9513,29 @@ export class HyperLiquidProvider {
|
|
|
9499
9513
|
};
|
|
9500
9514
|
}
|
|
9501
9515
|
catch (error) {
|
|
9502
|
-
|
|
9503
|
-
this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
9516
|
+
const isMultiSigRequired = accountContext
|
|
9517
|
+
? this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
9518
|
+
: false;
|
|
9519
|
+
const signerFailure = await this.#handleSignerFailure(error, 'updateMargin', {
|
|
9520
|
+
symbol: params.symbol,
|
|
9521
|
+
});
|
|
9522
|
+
if (signerFailure) {
|
|
9523
|
+
return { success: false, error: signerFailure.message };
|
|
9504
9524
|
}
|
|
9505
|
-
const
|
|
9525
|
+
const safeError = isMultiSigRequired
|
|
9526
|
+
? new Error(PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED)
|
|
9527
|
+
: ensureError(error, 'HyperLiquidProvider.updateMargin');
|
|
9528
|
+
this.#deps.logger.error(safeError, this.#getErrorContext('updateMargin', {
|
|
9506
9529
|
symbol: params.symbol,
|
|
9507
9530
|
amount: params.amount,
|
|
9508
9531
|
}, {
|
|
9509
9532
|
operation: PERPS_ERROR_OPERATION.PositionManagement,
|
|
9510
9533
|
action: PERPS_ERROR_ACTION.UpdateMargin,
|
|
9511
|
-
});
|
|
9512
|
-
return
|
|
9534
|
+
}));
|
|
9535
|
+
return {
|
|
9536
|
+
success: false,
|
|
9537
|
+
error: safeError.message,
|
|
9538
|
+
};
|
|
9513
9539
|
}
|
|
9514
9540
|
}
|
|
9515
9541
|
/**
|
|
@@ -11606,42 +11632,50 @@ export class HyperLiquidProvider {
|
|
|
11606
11632
|
};
|
|
11607
11633
|
}
|
|
11608
11634
|
const rejection = new Error(`Withdrawal failed: ${JSON.stringify(result)}`);
|
|
11609
|
-
this.#recordUnsupportedAccountFromError(rejection, accountContext);
|
|
11635
|
+
const isMultiSigRequired = this.#recordUnsupportedAccountFromError(rejection, accountContext);
|
|
11636
|
+
const errorMessage = isMultiSigRequired
|
|
11637
|
+
? PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED
|
|
11638
|
+
: `Withdrawal failed: ${String(result.status)}`;
|
|
11610
11639
|
this.#deps.debugLogger.log('HyperLiquidProvider: WITHDRAWAL FAILED', {
|
|
11611
|
-
error:
|
|
11640
|
+
error: errorMessage,
|
|
11612
11641
|
status: result.status,
|
|
11613
11642
|
response: result,
|
|
11614
11643
|
params,
|
|
11615
11644
|
});
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
}, {
|
|
11621
|
-
operation: PERPS_ERROR_OPERATION.FinancialOperations,
|
|
11622
|
-
action: PERPS_ERROR_ACTION.FinancialWithdrawal,
|
|
11623
|
-
});
|
|
11624
|
-
return createErrorResult(mappedError, { success: false });
|
|
11645
|
+
return {
|
|
11646
|
+
success: false,
|
|
11647
|
+
error: errorMessage,
|
|
11648
|
+
};
|
|
11625
11649
|
}
|
|
11626
11650
|
catch (error) {
|
|
11627
|
-
|
|
11628
|
-
this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
11651
|
+
const isMultiSigRequired = accountContext
|
|
11652
|
+
? this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
11653
|
+
: false;
|
|
11654
|
+
const signerFailure = await this.#handleSignerFailure(error, 'withdraw', {
|
|
11655
|
+
assetId: params.assetId,
|
|
11656
|
+
});
|
|
11657
|
+
if (signerFailure) {
|
|
11658
|
+
return createErrorResult(signerFailure, { success: false });
|
|
11629
11659
|
}
|
|
11660
|
+
const safeError = isMultiSigRequired
|
|
11661
|
+
? new Error(PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED)
|
|
11662
|
+
: ensureError(error, 'HyperLiquidProvider.initiateWithdrawal');
|
|
11630
11663
|
this.#deps.debugLogger.log('HyperLiquidProvider: WITHDRAWAL EXCEPTION', {
|
|
11631
|
-
error:
|
|
11632
|
-
|
|
11664
|
+
error: safeError.message,
|
|
11665
|
+
errorType: safeError.name,
|
|
11666
|
+
stack: safeError.stack,
|
|
11633
11667
|
params,
|
|
11634
11668
|
timestamp: new Date().toISOString(),
|
|
11635
11669
|
});
|
|
11636
|
-
|
|
11670
|
+
this.#deps.logger.error(safeError, this.#getErrorContext('withdraw', {
|
|
11637
11671
|
assetId: params.assetId,
|
|
11638
11672
|
amount: params.amount,
|
|
11639
11673
|
destination: params.destination,
|
|
11640
11674
|
}, {
|
|
11641
11675
|
operation: PERPS_ERROR_OPERATION.FinancialOperations,
|
|
11642
11676
|
action: PERPS_ERROR_ACTION.FinancialWithdrawal,
|
|
11643
|
-
});
|
|
11644
|
-
return createErrorResult(
|
|
11677
|
+
}));
|
|
11678
|
+
return createErrorResult(safeError, { success: false });
|
|
11645
11679
|
}
|
|
11646
11680
|
}
|
|
11647
11681
|
/**
|
|
@@ -11745,25 +11779,28 @@ export class HyperLiquidProvider {
|
|
|
11745
11779
|
if (this.#recordUnsupportedAccountFromError(new Error(`DEX transfer failed: ${JSON.stringify(result)}`), accountContext)) {
|
|
11746
11780
|
throw new Error(PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED);
|
|
11747
11781
|
}
|
|
11748
|
-
throw new Error(PERPS_ERROR_CODES.TRANSFER_FAILED
|
|
11749
|
-
cause: new Error(`DEX transfer failed: ${JSON.stringify(result)}`),
|
|
11750
|
-
});
|
|
11782
|
+
throw new Error(PERPS_ERROR_CODES.TRANSFER_FAILED);
|
|
11751
11783
|
}
|
|
11752
11784
|
catch (error) {
|
|
11753
|
-
|
|
11754
|
-
this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
11785
|
+
const isMultiSigRequired = accountContext
|
|
11786
|
+
? this.#recordUnsupportedAccountFromError(error, accountContext)
|
|
11787
|
+
: false;
|
|
11788
|
+
const signerFailure = await this.#handleSignerFailure(error, 'transferBetweenDexs', { sourceDex: params.sourceDex, destinationDex: params.destinationDex });
|
|
11789
|
+
if (signerFailure) {
|
|
11790
|
+
return { success: false, error: signerFailure.message };
|
|
11755
11791
|
}
|
|
11756
|
-
const
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
}, {
|
|
11760
|
-
operation: PERPS_ERROR_OPERATION.FinancialOperations,
|
|
11761
|
-
});
|
|
11792
|
+
const safeError = isMultiSigRequired
|
|
11793
|
+
? new Error(PERPS_ERROR_CODES.EXCHANGE_MULTI_SIG_REQUIRED)
|
|
11794
|
+
: ensureError(error, 'HyperLiquidProvider.transferToSpot');
|
|
11762
11795
|
this.#deps.debugLogger.log('❌ HyperLiquidProvider: TRANSFER FAILED', {
|
|
11763
|
-
error:
|
|
11796
|
+
error: safeError.message,
|
|
11764
11797
|
params,
|
|
11765
11798
|
});
|
|
11766
|
-
|
|
11799
|
+
this.#deps.logger.error(safeError, this.#getErrorContext('transferBetweenDexs', { ...params }));
|
|
11800
|
+
return {
|
|
11801
|
+
success: false,
|
|
11802
|
+
error: safeError.message,
|
|
11803
|
+
};
|
|
11767
11804
|
}
|
|
11768
11805
|
}
|
|
11769
11806
|
/**
|
|
@@ -12126,7 +12163,6 @@ export class HyperLiquidProvider {
|
|
|
12126
12163
|
return { ready: false, error: PERPS_ERROR_CODES.KEYRING_LOCKED };
|
|
12127
12164
|
}
|
|
12128
12165
|
const caughtError = ensureError(error, 'HyperLiquidProvider.prepareTradingWallet');
|
|
12129
|
-
const normalizedError = normalizeHyperLiquidError(caughtError);
|
|
12130
12166
|
if (caughtError.message === PERPS_ERROR_CODES.PROVIDER_LIFECYCLE_STALE) {
|
|
12131
12167
|
this.#deps.debugLogger.log('[prepareTradingWallet] Provider replaced during preparation');
|
|
12132
12168
|
}
|
|
@@ -12138,16 +12174,9 @@ export class HyperLiquidProvider {
|
|
|
12138
12174
|
this.#deps.debugLogger.log('[prepareTradingWallet] Builder fee approval refused', { error: caughtError.message });
|
|
12139
12175
|
}
|
|
12140
12176
|
else {
|
|
12141
|
-
this.#deps.logger.error(
|
|
12177
|
+
this.#deps.logger.error(caughtError, this.#getErrorContext('prepareTradingWallet'));
|
|
12142
12178
|
}
|
|
12143
|
-
return {
|
|
12144
|
-
ready: false,
|
|
12145
|
-
error: normalizedError.message,
|
|
12146
|
-
errorCode: normalizedError.errorCode,
|
|
12147
|
-
...(normalizedError.errorDetails === undefined
|
|
12148
|
-
? {}
|
|
12149
|
-
: { errorDetails: normalizedError.errorDetails }),
|
|
12150
|
-
};
|
|
12179
|
+
return { ready: false, error: caughtError.message };
|
|
12151
12180
|
}
|
|
12152
12181
|
}
|
|
12153
12182
|
/**
|
|
@@ -12177,16 +12206,13 @@ export class HyperLiquidProvider {
|
|
|
12177
12206
|
};
|
|
12178
12207
|
}
|
|
12179
12208
|
catch (error) {
|
|
12180
|
-
const normalizedError = normalizeHyperLiquidError(error);
|
|
12181
12209
|
return {
|
|
12182
12210
|
ready: false,
|
|
12183
12211
|
walletConnected: false,
|
|
12184
12212
|
networkSupported: false,
|
|
12185
|
-
error:
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
? {}
|
|
12189
|
-
: { errorDetails: normalizedError.errorDetails }),
|
|
12213
|
+
error: error instanceof Error
|
|
12214
|
+
? error.message
|
|
12215
|
+
: PERPS_ERROR_CODES.UNKNOWN_ERROR,
|
|
12190
12216
|
};
|
|
12191
12217
|
}
|
|
12192
12218
|
}
|