@getclave/lifi-sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
72 lines (71 loc) • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAtomicReadyWalletRejectedUpgradeError = exports.parseEVMErrors = void 0;
const viem_1 = require("viem");
const SDKError_1 = require("../../errors/SDKError");
const baseError_1 = require("../../errors/baseError");
const constants_1 = require("../../errors/constants");
const errors_1 = require("../../errors/errors");
const fetchTxErrorDetails_1 = require("../../utils/fetchTxErrorDetails");
const parseEVMErrors = async (e, step, process) => {
if (e instanceof SDKError_1.SDKError) {
e.step = e.step ?? step;
e.process = e.process ?? process;
return e;
}
const baseError = await handleSpecificErrors(e, step, process);
return new SDKError_1.SDKError(baseError, step, process);
};
exports.parseEVMErrors = parseEVMErrors;
const handleSpecificErrors = async (e, step, process) => {
if (e.name === 'UserRejectedRequestError' ||
e.cause?.name === 'UserRejectedRequestError') {
return new errors_1.TransactionError(constants_1.LiFiErrorCode.SignatureRejected, e.message, e);
}
// Safe Wallet via WalletConnect returns -32000 code when user rejects the signature
// {
// code: -32000,
// message: 'User rejected transaction',
// }
if (e.cause?.code === -32000 ||
// Safe doesn't return proper code, but the error details includes 'rejected'
(e.name === 'TransactionExecutionError' &&
e.cause?.details?.includes('rejected'))) {
return new errors_1.TransactionError(constants_1.LiFiErrorCode.SignatureRejected, e.message, e);
}
// Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:
// {
// "code": -32603,
// "message": "Pop up window failed to open",
// "docUrl": "https://docs.cloud.coinbase.com/wallet-sdk/docs/errors"
// }
if (e.cause?.code === -32603) {
return new errors_1.TransactionError(constants_1.LiFiErrorCode.TransactionRejected, e.message, e);
}
if (step &&
process?.txHash &&
e.code === constants_1.LiFiErrorCode.TransactionFailed &&
e.message === constants_1.ErrorMessage.TransactionReverted) {
const response = await (0, fetchTxErrorDetails_1.fetchTxErrorDetails)(process.txHash, step.action.fromChainId);
const errorMessage = response?.error_message;
if (errorMessage?.toLowerCase().includes('out of gas')) {
return new errors_1.TransactionError(constants_1.LiFiErrorCode.GasLimitError, constants_1.ErrorMessage.GasLimitLow, e);
}
}
if (e instanceof baseError_1.BaseError) {
return e;
}
return new errors_1.UnknownError(e.message || constants_1.ErrorMessage.UnknownError, e);
};
const isAtomicReadyWalletRejectedUpgradeError = (e) => {
if (e.cause?.code === viem_1.AtomicReadyWalletRejectedUpgradeError.code) {
return true;
}
const details = e.cause?.details?.toLowerCase();
const isTransactionError = e.name === 'TransactionExecutionError' ||
e.cause?.name === 'TransactionExecutionError';
const hasRejectedUpgrade = details?.includes('rejected') && details?.includes('upgrade');
const has7702ErrorCode = details?.includes('7702');
return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode);
};
exports.isAtomicReadyWalletRejectedUpgradeError = isAtomicReadyWalletRejectedUpgradeError;