@lifi/sdk 2.2.2 → 3.0.0-alpha.1
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/dist/LiFi.d.ts +69 -62
- package/dist/LiFi.js +71 -60
- package/dist/allowance/getAllowance.d.ts +6 -0
- package/dist/allowance/getAllowance.js +78 -0
- package/dist/allowance/index.d.ts +3 -2
- package/dist/allowance/index.js +3 -2
- package/dist/allowance/setAllowance.d.ts +5 -0
- package/dist/allowance/setAllowance.js +50 -0
- package/dist/allowance/types.d.ts +27 -0
- package/dist/allowance/types.js +1 -0
- package/dist/balance/getBalance.d.ts +2 -0
- package/dist/balance/getBalance.js +93 -0
- package/dist/balance/getTokenBalance.d.ts +2 -2
- package/dist/balance/getTokenBalance.js +4 -4
- package/dist/balance/index.d.ts +1 -12
- package/dist/balance/index.js +1 -9
- package/dist/cjs/LiFi.d.ts +69 -62
- package/dist/cjs/LiFi.js +69 -58
- package/dist/cjs/allowance/getAllowance.d.ts +6 -0
- package/dist/cjs/allowance/getAllowance.js +85 -0
- package/dist/cjs/allowance/index.d.ts +3 -2
- package/dist/cjs/allowance/index.js +3 -2
- package/dist/cjs/allowance/setAllowance.d.ts +5 -0
- package/dist/cjs/allowance/setAllowance.js +56 -0
- package/dist/cjs/allowance/types.d.ts +27 -0
- package/dist/cjs/allowance/types.js +2 -0
- package/dist/cjs/balance/getBalance.d.ts +2 -0
- package/dist/cjs/balance/getBalance.js +97 -0
- package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
- package/dist/cjs/balance/getTokenBalance.js +6 -9
- package/dist/cjs/balance/index.d.ts +1 -12
- package/dist/cjs/balance/index.js +1 -9
- package/dist/cjs/connectors.d.ts +7 -5
- package/dist/cjs/connectors.js +45 -37
- package/dist/cjs/constants.d.ts +6 -0
- package/dist/cjs/constants.js +9 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/cjs/execution/RouteExecutionManager.js +27 -45
- package/dist/cjs/execution/StatusManager.d.ts +22 -23
- package/dist/cjs/execution/StatusManager.js +21 -22
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +118 -125
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +6 -6
- package/dist/cjs/execution/checkAllowance.d.ts +4 -0
- package/dist/cjs/execution/checkAllowance.js +77 -0
- package/dist/cjs/execution/checkBalance.d.ts +2 -0
- package/dist/cjs/execution/checkBalance.js +42 -0
- package/dist/cjs/execution/multisig.d.ts +4 -3
- package/dist/cjs/execution/multisig.js +9 -11
- package/dist/cjs/execution/prepareRestart.d.ts +3 -0
- package/dist/cjs/execution/prepareRestart.js +65 -0
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -2
- package/dist/cjs/execution/switchChain.d.ts +13 -8
- package/dist/cjs/execution/switchChain.js +16 -11
- package/dist/cjs/execution/utils.d.ts +9 -3
- package/dist/cjs/execution/utils.js +19 -66
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
- package/dist/cjs/helpers.d.ts +7 -17
- package/dist/cjs/helpers.js +6 -38
- package/dist/cjs/request.js +1 -1
- package/dist/cjs/services/ApiService.d.ts +2 -2
- package/dist/cjs/services/ApiService.js +2 -0
- package/dist/cjs/services/ChainsService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.js +1 -2
- package/dist/cjs/typeguards.d.ts +1 -1
- package/dist/cjs/types/abi.d.ts +5 -0
- package/dist/cjs/types/abi.js +45 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.js +3 -3
- package/dist/cjs/types/internal.types.d.ts +24 -30
- package/dist/cjs/utils/errors.d.ts +15 -14
- package/dist/cjs/utils/errors.js +38 -37
- package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
- package/dist/cjs/utils/index.d.ts +5 -0
- package/dist/cjs/utils/index.js +21 -0
- package/dist/cjs/utils/median.d.ts +1 -0
- package/dist/cjs/utils/median.js +15 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +41 -38
- package/dist/cjs/utils/utils.d.ts +1 -16
- package/dist/cjs/utils/utils.js +9 -78
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +7 -5
- package/dist/connectors.js +19 -35
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +6 -0
- package/dist/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/execution/RouteExecutionManager.js +27 -45
- package/dist/execution/StatusManager.d.ts +22 -23
- package/dist/execution/StatusManager.js +22 -23
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +116 -123
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +6 -6
- package/dist/execution/checkAllowance.d.ts +4 -0
- package/dist/execution/checkAllowance.js +73 -0
- package/dist/execution/checkBalance.d.ts +2 -0
- package/dist/execution/checkBalance.js +38 -0
- package/dist/execution/multisig.d.ts +4 -3
- package/dist/execution/multisig.js +10 -12
- package/dist/execution/prepareRestart.d.ts +3 -0
- package/dist/execution/prepareRestart.js +61 -0
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +3 -3
- package/dist/execution/switchChain.d.ts +13 -8
- package/dist/execution/switchChain.js +17 -12
- package/dist/execution/utils.d.ts +9 -3
- package/dist/execution/utils.js +18 -61
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/execution/waitForReceivingTransaction.js +51 -0
- package/dist/helpers.d.ts +7 -17
- package/dist/helpers.js +5 -34
- package/dist/request.js +2 -2
- package/dist/services/ApiService.d.ts +2 -2
- package/dist/services/ApiService.js +2 -0
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +2 -3
- package/dist/typeguards.d.ts +1 -1
- package/dist/types/abi.d.ts +5 -0
- package/dist/types/abi.js +42 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types/internal.types.d.ts +24 -30
- package/dist/utils/errors.d.ts +15 -14
- package/dist/utils/errors.js +36 -35
- package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/median.d.ts +1 -0
- package/dist/utils/median.js +11 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +42 -39
- package/dist/utils/utils.d.ts +1 -16
- package/dist/utils/utils.js +7 -69
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +28 -27
- package/dist/allowance/checkAllowance.d.ts +0 -4
- package/dist/allowance/checkAllowance.js +0 -96
- package/dist/allowance/tokenApproval.d.ts +0 -22
- package/dist/allowance/tokenApproval.js +0 -59
- package/dist/allowance/utils.d.ts +0 -15
- package/dist/allowance/utils.js +0 -77
- package/dist/balance/checkBalance.d.ts +0 -3
- package/dist/balance/checkBalance.js +0 -38
- package/dist/balance/utils.d.ts +0 -6
- package/dist/balance/utils.js +0 -143
- package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
- package/dist/cjs/allowance/checkAllowance.js +0 -103
- package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
- package/dist/cjs/allowance/tokenApproval.js +0 -69
- package/dist/cjs/allowance/utils.d.ts +0 -15
- package/dist/cjs/allowance/utils.js +0 -87
- package/dist/cjs/balance/checkBalance.d.ts +0 -3
- package/dist/cjs/balance/checkBalance.js +0 -45
- package/dist/cjs/balance/utils.d.ts +0 -6
- package/dist/cjs/balance/utils.js +0 -150
- package/dist/cjs/types/ERC20.d.ts +0 -22
- package/dist/cjs/types/ERC20.js +0 -53
- package/dist/cjs/utils/getProvider.d.ts +0 -3
- package/dist/cjs/utils/getProvider.js +0 -11
- package/dist/cjs/utils/multicall.d.ts +0 -10
- package/dist/cjs/utils/multicall.js +0 -68
- package/dist/cjs/utils/multicallAbi.json +0 -313
- package/dist/cjs/utils/preRestart.d.ts +0 -3
- package/dist/cjs/utils/preRestart.js +0 -56
- package/dist/types/ERC20.d.ts +0 -22
- package/dist/types/ERC20.js +0 -50
- package/dist/utils/getProvider.d.ts +0 -3
- package/dist/utils/getProvider.js +0 -7
- package/dist/utils/multicall.d.ts +0 -10
- package/dist/utils/multicall.js +0 -61
- package/dist/utils/multicallAbi.json +0 -313
- package/dist/utils/preRestart.d.ts +0 -3
- package/dist/utils/preRestart.js +0 -52
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
gasFee: string;
|
|
18
|
-
toTokenAddress?: string;
|
|
1
|
+
import type { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
|
+
import type { Hash, Hex, WalletClient } from 'viem';
|
|
3
|
+
import type { ChainId } from '.';
|
|
4
|
+
import type { StatusManager } from '../execution/StatusManager';
|
|
5
|
+
import type { StepExecutor } from '../execution/StepExecutor';
|
|
6
|
+
export type TransactionRequest = {
|
|
7
|
+
chainId?: number;
|
|
8
|
+
to?: string;
|
|
9
|
+
from?: string;
|
|
10
|
+
nonce?: number;
|
|
11
|
+
data?: Hex;
|
|
12
|
+
value?: bigint;
|
|
13
|
+
gas?: bigint;
|
|
14
|
+
gasPrice?: bigint;
|
|
15
|
+
maxFeePerGas?: bigint;
|
|
16
|
+
maxPriorityFeePerGas?: bigint;
|
|
19
17
|
};
|
|
20
18
|
export interface ExecutionParams {
|
|
21
|
-
|
|
19
|
+
walletClient: WalletClient;
|
|
22
20
|
step: LifiStep;
|
|
23
21
|
statusManager: StatusManager;
|
|
24
22
|
settings: InternalExecutionSettings;
|
|
@@ -35,24 +33,24 @@ export type Config = {
|
|
|
35
33
|
userId?: string;
|
|
36
34
|
integrator: string;
|
|
37
35
|
widgetVersion?: string;
|
|
38
|
-
|
|
36
|
+
multisig?: MultisigConfig;
|
|
39
37
|
};
|
|
40
38
|
export interface MultisigTxDetails {
|
|
41
39
|
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
42
|
-
txHash?:
|
|
40
|
+
txHash?: Hash;
|
|
43
41
|
}
|
|
44
42
|
export interface MultisigTransactionResponse {
|
|
45
43
|
hash: string;
|
|
46
44
|
}
|
|
47
45
|
export interface BaseTransaction {
|
|
48
46
|
to: string;
|
|
49
|
-
value
|
|
47
|
+
value?: bigint;
|
|
50
48
|
data: string;
|
|
51
49
|
}
|
|
52
50
|
export interface MultisigConfig {
|
|
53
|
-
|
|
54
|
-
getMultisigTransactionDetails
|
|
55
|
-
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<
|
|
51
|
+
isMultisigWalletClient: boolean;
|
|
52
|
+
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
53
|
+
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
56
54
|
shouldBatchTransactions?: boolean;
|
|
57
55
|
}
|
|
58
56
|
export type ConfigUpdate = {
|
|
@@ -67,7 +65,7 @@ export type ConfigUpdate = {
|
|
|
67
65
|
widgetVersion?: string;
|
|
68
66
|
multisigConfig?: MultisigConfig;
|
|
69
67
|
};
|
|
70
|
-
export type SwitchChainHook = (requiredChainId: number) => Promise<
|
|
68
|
+
export type SwitchChainHook = (requiredChainId: number) => Promise<WalletClient | undefined>;
|
|
71
69
|
export interface AcceptSlippageUpdateHookParams {
|
|
72
70
|
toToken: Token;
|
|
73
71
|
oldToAmount: string;
|
|
@@ -98,10 +96,6 @@ export interface InternalExecutionSettings {
|
|
|
98
96
|
}
|
|
99
97
|
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
100
98
|
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
101
|
-
export type RevokeTokenData = {
|
|
102
|
-
token: Token;
|
|
103
|
-
approvalAddress: string;
|
|
104
|
-
};
|
|
105
99
|
export interface InteractionSettings {
|
|
106
100
|
allowInteraction?: boolean;
|
|
107
101
|
allowUpdates?: boolean;
|
|
@@ -8,7 +8,7 @@ declare enum ErrorType {
|
|
|
8
8
|
UnknownError = "UnknownError",
|
|
9
9
|
SlippageError = "SlippageError"
|
|
10
10
|
}
|
|
11
|
-
export declare enum
|
|
11
|
+
export declare enum LiFiErrorCode {
|
|
12
12
|
InternalError = 1000,
|
|
13
13
|
ValidationError = 1001,
|
|
14
14
|
TransactionUnderpriced = 1002,
|
|
@@ -21,10 +21,11 @@ export declare enum LifiErrorCode {
|
|
|
21
21
|
GasLimitError = 1009,
|
|
22
22
|
TransactionCanceled = 1010,
|
|
23
23
|
SlippageError = 1011,
|
|
24
|
-
|
|
24
|
+
SignatureRejected = 1012,
|
|
25
25
|
BalanceError = 1013,
|
|
26
26
|
AllowanceRequired = 1014,
|
|
27
|
-
InsufficientFunds = 1015
|
|
27
|
+
InsufficientFunds = 1015,
|
|
28
|
+
ExchangeRateUpdateCanceled = 1016
|
|
28
29
|
}
|
|
29
30
|
export declare enum EthersErrorType {
|
|
30
31
|
ActionRejected = "ACTION_REJECTED",
|
|
@@ -65,37 +66,37 @@ export declare enum MetaMaskProviderErrorCode {
|
|
|
65
66
|
disconnected = 4900,
|
|
66
67
|
chainDisconnected = 4901
|
|
67
68
|
}
|
|
68
|
-
export type ErrorCode =
|
|
69
|
-
export declare class
|
|
69
|
+
export type ErrorCode = LiFiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode;
|
|
70
|
+
export declare class LiFiError extends Error {
|
|
70
71
|
code: ErrorCode;
|
|
71
72
|
htmlMessage?: string;
|
|
72
73
|
constructor(type: ErrorType, code: number, message: string, htmlMessage?: string, stack?: string);
|
|
73
74
|
}
|
|
74
|
-
export declare class RPCError extends
|
|
75
|
+
export declare class RPCError extends LiFiError {
|
|
75
76
|
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
76
77
|
}
|
|
77
|
-
export declare class ProviderError extends
|
|
78
|
+
export declare class ProviderError extends LiFiError {
|
|
78
79
|
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
79
80
|
}
|
|
80
|
-
export declare class ServerError extends
|
|
81
|
+
export declare class ServerError extends LiFiError {
|
|
81
82
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
82
83
|
}
|
|
83
|
-
export declare class ValidationError extends
|
|
84
|
+
export declare class ValidationError extends LiFiError {
|
|
84
85
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
85
86
|
}
|
|
86
|
-
export declare class TransactionError extends
|
|
87
|
+
export declare class TransactionError extends LiFiError {
|
|
87
88
|
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
88
89
|
}
|
|
89
|
-
export declare class SlippageError extends
|
|
90
|
+
export declare class SlippageError extends LiFiError {
|
|
90
91
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
91
92
|
}
|
|
92
|
-
export declare class BalanceError extends
|
|
93
|
+
export declare class BalanceError extends LiFiError {
|
|
93
94
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
94
95
|
}
|
|
95
|
-
export declare class NotFoundError extends
|
|
96
|
+
export declare class NotFoundError extends LiFiError {
|
|
96
97
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
97
98
|
}
|
|
98
|
-
export declare class UnknownError extends
|
|
99
|
+
export declare class UnknownError extends LiFiError {
|
|
99
100
|
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
100
101
|
}
|
|
101
102
|
export declare class HTTPError extends Error {
|
package/dist/cjs/utils/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.
|
|
3
|
+
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LiFiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.ErrorMessage = exports.EthersErrorMessage = exports.EthersErrorType = exports.LiFiErrorCode = void 0;
|
|
4
4
|
var ErrorType;
|
|
5
5
|
(function (ErrorType) {
|
|
6
6
|
ErrorType["RPCError"] = "RPCError";
|
|
@@ -12,25 +12,26 @@ var ErrorType;
|
|
|
12
12
|
ErrorType["UnknownError"] = "UnknownError";
|
|
13
13
|
ErrorType["SlippageError"] = "SlippageError";
|
|
14
14
|
})(ErrorType || (ErrorType = {}));
|
|
15
|
-
var
|
|
16
|
-
(function (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
var LiFiErrorCode;
|
|
16
|
+
(function (LiFiErrorCode) {
|
|
17
|
+
LiFiErrorCode[LiFiErrorCode["InternalError"] = 1000] = "InternalError";
|
|
18
|
+
LiFiErrorCode[LiFiErrorCode["ValidationError"] = 1001] = "ValidationError";
|
|
19
|
+
LiFiErrorCode[LiFiErrorCode["TransactionUnderpriced"] = 1002] = "TransactionUnderpriced";
|
|
20
|
+
LiFiErrorCode[LiFiErrorCode["TransactionFailed"] = 1003] = "TransactionFailed";
|
|
21
|
+
LiFiErrorCode[LiFiErrorCode["Timeout"] = 1004] = "Timeout";
|
|
22
|
+
LiFiErrorCode[LiFiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
|
|
23
|
+
LiFiErrorCode[LiFiErrorCode["NotFound"] = 1006] = "NotFound";
|
|
24
|
+
LiFiErrorCode[LiFiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
|
|
25
|
+
LiFiErrorCode[LiFiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
|
|
26
|
+
LiFiErrorCode[LiFiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
|
|
27
|
+
LiFiErrorCode[LiFiErrorCode["TransactionCanceled"] = 1010] = "TransactionCanceled";
|
|
28
|
+
LiFiErrorCode[LiFiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
29
|
+
LiFiErrorCode[LiFiErrorCode["SignatureRejected"] = 1012] = "SignatureRejected";
|
|
30
|
+
LiFiErrorCode[LiFiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
31
|
+
LiFiErrorCode[LiFiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
32
|
+
LiFiErrorCode[LiFiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
|
|
33
|
+
LiFiErrorCode[LiFiErrorCode["ExchangeRateUpdateCanceled"] = 1016] = "ExchangeRateUpdateCanceled";
|
|
34
|
+
})(LiFiErrorCode || (exports.LiFiErrorCode = LiFiErrorCode = {}));
|
|
34
35
|
var EthersErrorType;
|
|
35
36
|
(function (EthersErrorType) {
|
|
36
37
|
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
@@ -75,11 +76,11 @@ var MetaMaskProviderErrorCode;
|
|
|
75
76
|
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["disconnected"] = 4900] = "disconnected";
|
|
76
77
|
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["chainDisconnected"] = 4901] = "chainDisconnected";
|
|
77
78
|
})(MetaMaskProviderErrorCode || (exports.MetaMaskProviderErrorCode = MetaMaskProviderErrorCode = {}));
|
|
78
|
-
class
|
|
79
|
+
class LiFiError extends Error {
|
|
79
80
|
constructor(type, code, message, htmlMessage, stack) {
|
|
80
81
|
super(message);
|
|
81
82
|
// Set the prototype explicitly: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
82
|
-
Object.setPrototypeOf(this,
|
|
83
|
+
Object.setPrototypeOf(this, LiFiError.prototype);
|
|
83
84
|
this.code = code;
|
|
84
85
|
// the name property is used by toString(). It is a string and we can't use our custom ErrorTypes, that's why we have to cast
|
|
85
86
|
this.name = type.toString();
|
|
@@ -90,56 +91,56 @@ class LifiError extends Error {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
|
-
exports.
|
|
94
|
-
class RPCError extends
|
|
94
|
+
exports.LiFiError = LiFiError;
|
|
95
|
+
class RPCError extends LiFiError {
|
|
95
96
|
constructor(code, message, htmlMessage, stack) {
|
|
96
97
|
super(ErrorType.RPCError, code, message, htmlMessage, stack);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
exports.RPCError = RPCError;
|
|
100
|
-
class ProviderError extends
|
|
101
|
+
class ProviderError extends LiFiError {
|
|
101
102
|
constructor(code, message, htmlMessage, stack) {
|
|
102
103
|
super(ErrorType.ProviderError, code, message, htmlMessage, stack);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
exports.ProviderError = ProviderError;
|
|
106
|
-
class ServerError extends
|
|
107
|
+
class ServerError extends LiFiError {
|
|
107
108
|
constructor(message, htmlMessage, stack) {
|
|
108
|
-
super(ErrorType.ServerError,
|
|
109
|
+
super(ErrorType.ServerError, LiFiErrorCode.InternalError, message, htmlMessage, stack);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
exports.ServerError = ServerError;
|
|
112
|
-
class ValidationError extends
|
|
113
|
+
class ValidationError extends LiFiError {
|
|
113
114
|
constructor(message, htmlMessage, stack) {
|
|
114
|
-
super(ErrorType.ValidationError,
|
|
115
|
+
super(ErrorType.ValidationError, LiFiErrorCode.ValidationError, message, htmlMessage, stack);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
exports.ValidationError = ValidationError;
|
|
118
|
-
class TransactionError extends
|
|
119
|
+
class TransactionError extends LiFiError {
|
|
119
120
|
constructor(code, message, htmlMessage, stack) {
|
|
120
121
|
super(ErrorType.TransactionError, code, message, htmlMessage, stack);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
exports.TransactionError = TransactionError;
|
|
124
|
-
class SlippageError extends
|
|
125
|
+
class SlippageError extends LiFiError {
|
|
125
126
|
constructor(message, htmlMessage, stack) {
|
|
126
|
-
super(ErrorType.SlippageError,
|
|
127
|
+
super(ErrorType.SlippageError, LiFiErrorCode.SlippageError, message, htmlMessage, stack);
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
exports.SlippageError = SlippageError;
|
|
130
|
-
class BalanceError extends
|
|
131
|
+
class BalanceError extends LiFiError {
|
|
131
132
|
constructor(message, htmlMessage, stack) {
|
|
132
|
-
super(ErrorType.ValidationError,
|
|
133
|
+
super(ErrorType.ValidationError, LiFiErrorCode.BalanceError, message, htmlMessage, stack);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
exports.BalanceError = BalanceError;
|
|
136
|
-
class NotFoundError extends
|
|
137
|
+
class NotFoundError extends LiFiError {
|
|
137
138
|
constructor(message, htmlMessage, stack) {
|
|
138
|
-
super(ErrorType.NotFoundError,
|
|
139
|
+
super(ErrorType.NotFoundError, LiFiErrorCode.NotFound, message, htmlMessage, stack);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
exports.NotFoundError = NotFoundError;
|
|
142
|
-
class UnknownError extends
|
|
143
|
+
class UnknownError extends LiFiError {
|
|
143
144
|
constructor(code, message, htmlMessage, stack) {
|
|
144
145
|
super(ErrorType.UnknownError, code, message, htmlMessage, stack);
|
|
145
146
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxPriorityFeePerGas = void 0;
|
|
4
|
+
const median_1 = require("./median");
|
|
5
|
+
const getMaxPriorityFeePerGas = async (client) => {
|
|
6
|
+
const block = await client.getBlock({
|
|
7
|
+
includeTransactions: true,
|
|
8
|
+
});
|
|
9
|
+
const maxPriorityFeePerGasList = block.transactions
|
|
10
|
+
.filter((tx) => tx.maxPriorityFeePerGas)
|
|
11
|
+
.map((tx) => tx.maxPriorityFeePerGas);
|
|
12
|
+
if (!maxPriorityFeePerGasList.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const maxPriorityFeePerGasSum = maxPriorityFeePerGasList.reduce((acc, value) => (acc += value), 0n);
|
|
16
|
+
const maxPriorityFeePerGasMedian = (0, median_1.median)(maxPriorityFeePerGasList) ?? 0n;
|
|
17
|
+
const maxPriorityFeePerGasAvg = maxPriorityFeePerGasSum / BigInt(maxPriorityFeePerGasList.length);
|
|
18
|
+
return maxPriorityFeePerGasMedian > maxPriorityFeePerGasAvg
|
|
19
|
+
? maxPriorityFeePerGasAvg
|
|
20
|
+
: maxPriorityFeePerGasMedian;
|
|
21
|
+
};
|
|
22
|
+
exports.getMaxPriorityFeePerGas = getMaxPriorityFeePerGas;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors"), exports);
|
|
18
|
+
__exportStar(require("./getMaxPriorityFeePerGas"), exports);
|
|
19
|
+
__exportStar(require("./median"), exports);
|
|
20
|
+
__exportStar(require("./parseError"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const median: (arr: bigint[]) => bigint | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.median = void 0;
|
|
4
|
+
const median = (arr) => {
|
|
5
|
+
if (!arr.length) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const s = [...arr].sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
|
|
9
|
+
const mid = Math.floor(s.length / 2);
|
|
10
|
+
if (s.length % 2 === 0) {
|
|
11
|
+
return (s[mid - 1] + s[mid]) / 2n;
|
|
12
|
+
}
|
|
13
|
+
return s[mid];
|
|
14
|
+
};
|
|
15
|
+
exports.median = median;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LifiStep, Process } from '@lifi/types';
|
|
2
|
-
import {
|
|
1
|
+
import type { LifiStep, Process } from '@lifi/types';
|
|
2
|
+
import { LiFiError } from './errors';
|
|
3
3
|
/**
|
|
4
4
|
* Available MetaMask error codes:
|
|
5
5
|
*
|
|
@@ -33,5 +33,5 @@ import { LifiError } from './errors';
|
|
|
33
33
|
*/
|
|
34
34
|
export declare const getTransactionNotSentMessage: (step?: LifiStep, process?: Process) => Promise<string>;
|
|
35
35
|
export declare const getTransactionFailedMessage: (step: LifiStep, txLink?: string) => Promise<string>;
|
|
36
|
-
export declare const parseError: (e: any, step?: LifiStep, process?: Process) => Promise<
|
|
37
|
-
export declare const parseBackendError: (e: any) => Promise<
|
|
36
|
+
export declare const parseError: (e: any, step?: LifiStep, process?: Process) => Promise<LiFiError>;
|
|
37
|
+
export declare const parseBackendError: (e: any) => Promise<LiFiError>;
|
|
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0;
|
|
7
7
|
const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
8
|
+
const viem_1 = require("viem");
|
|
8
9
|
const helpers_1 = require("../helpers");
|
|
9
10
|
const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
10
11
|
const errors_1 = require("./errors");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
12
|
/**
|
|
13
13
|
* Available MetaMask error codes:
|
|
14
14
|
*
|
|
@@ -46,7 +46,7 @@ const getTransactionNotSentMessage = async (step, process) => {
|
|
|
46
46
|
if (step) {
|
|
47
47
|
const chainService = ChainsService_1.default.getInstance();
|
|
48
48
|
const chain = await chainService.getChainById(step.action.fromChainId);
|
|
49
|
-
transactionNotSend += ` (${(0,
|
|
49
|
+
transactionNotSend += ` (${(0, viem_1.formatUnits)(BigInt(step.action.fromAmount), step.action.fromToken.decimals)} ${step.action.fromToken.symbol} on ${chain.name})`;
|
|
50
50
|
}
|
|
51
51
|
transactionNotSend +=
|
|
52
52
|
", please retry.<br/>If it still doesn't work, it is safe to delete this transfer and start a new one.";
|
|
@@ -70,62 +70,65 @@ const getTransactionFailedMessage = async (step, txLink) => {
|
|
|
70
70
|
};
|
|
71
71
|
exports.getTransactionFailedMessage = getTransactionFailedMessage;
|
|
72
72
|
const parseError = async (e, step, process) => {
|
|
73
|
-
if (e instanceof errors_1.
|
|
73
|
+
if (e instanceof errors_1.LiFiError) {
|
|
74
74
|
return e;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (typeof e.code === 'number') {
|
|
79
|
-
if (Object.values(eth_rpc_errors_1.errorCodes.rpc).includes(e.code)) {
|
|
80
|
-
// rpc errors
|
|
81
|
-
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
82
|
-
if (e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
83
|
-
(e.message?.includes(errors_1.EthersErrorMessage.Underpriced) ||
|
|
84
|
-
e.message?.includes(errors_1.EthersErrorMessage.LowReplacementFee))) {
|
|
85
|
-
return new errors_1.RPCError(errors_1.LifiErrorCode.TransactionUnderpriced, errors_1.ErrorMessage.TransactionUnderpriced, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
86
|
-
}
|
|
87
|
-
if (e.message?.includes(errors_1.EthersErrorMessage.LowGas) ||
|
|
88
|
-
e.message?.includes(errors_1.EthersErrorMessage.OutOfGas)) {
|
|
89
|
-
return new errors_1.TransactionError(errors_1.LifiErrorCode.GasLimitError, errors_1.ErrorMessage.GasLimitLow, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
90
|
-
}
|
|
91
|
-
return new errors_1.RPCError(e.code, (0, eth_rpc_errors_1.getMessageFromCode)(e.code), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
92
|
-
}
|
|
93
|
-
// provider errors
|
|
94
|
-
if (Object.values(eth_rpc_errors_1.errorCodes.provider).includes(e.code)) {
|
|
95
|
-
return new errors_1.ProviderError(e.code, (0, eth_rpc_errors_1.getMessageFromCode)(e.code), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
switch (e.code) {
|
|
76
|
+
const errorCode = e.code || e.cause?.code;
|
|
77
|
+
switch (errorCode) {
|
|
100
78
|
case errors_1.EthersErrorType.CallExecption:
|
|
101
79
|
const defaultErrorMessage = await (0, exports.getTransactionNotSentMessage)(step, process);
|
|
102
80
|
try {
|
|
103
81
|
if (!step?.action.fromChainId) {
|
|
104
|
-
throw new Error('
|
|
82
|
+
throw new Error('fromChainId is not defined.');
|
|
105
83
|
}
|
|
106
84
|
const response = await (0, helpers_1.fetchTxErrorDetails)(e.transactionHash, step?.action.fromChainId);
|
|
107
85
|
const errorMessage = response?.error_message ?? e.reason;
|
|
108
86
|
const isAllowanceError = response?.error_message?.includes(errors_1.EthersErrorMessage.ERC20Allowance) || e.reason?.includes(errors_1.EthersErrorMessage.ERC20Allowance);
|
|
109
87
|
if (isAllowanceError) {
|
|
110
|
-
return new errors_1.TransactionError(errors_1.
|
|
88
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
|
|
111
89
|
}
|
|
112
90
|
// Error messages other than allowance error will be handled in catch block
|
|
113
91
|
throw new Error(e);
|
|
114
92
|
}
|
|
115
93
|
catch (error) {
|
|
116
|
-
return new errors_1.ProviderError(errors_1.
|
|
94
|
+
return new errors_1.ProviderError(errors_1.LiFiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
|
|
117
95
|
}
|
|
118
96
|
case errors_1.EthersErrorType.InsufficientFunds:
|
|
119
|
-
return new errors_1.TransactionError(errors_1.
|
|
97
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.InsufficientFunds, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
120
98
|
case errors_1.EthersErrorType.ActionRejected:
|
|
121
99
|
case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
|
|
122
|
-
return new errors_1.TransactionError(errors_1.
|
|
123
|
-
case errors_1.
|
|
124
|
-
return new errors_1.TransactionError(errors_1.
|
|
125
|
-
case errors_1.
|
|
126
|
-
return new errors_1.TransactionError(errors_1.
|
|
127
|
-
|
|
128
|
-
return new errors_1.
|
|
100
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.SignatureRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
101
|
+
case errors_1.LiFiErrorCode.TransactionUnprepared:
|
|
102
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.TransactionUnprepared, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
103
|
+
case errors_1.LiFiErrorCode.ValidationError:
|
|
104
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
105
|
+
case errors_1.LiFiErrorCode.TransactionCanceled:
|
|
106
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.TransactionCanceled, e.message, e.htmlMessage);
|
|
107
|
+
case errors_1.LiFiErrorCode.ExchangeRateUpdateCanceled:
|
|
108
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.ExchangeRateUpdateCanceled, e.message, e.htmlMessage);
|
|
109
|
+
default: {
|
|
110
|
+
if (errorCode && typeof errorCode === 'number') {
|
|
111
|
+
if (Object.values(eth_rpc_errors_1.errorCodes.rpc).includes(errorCode)) {
|
|
112
|
+
// rpc errors
|
|
113
|
+
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
114
|
+
if (errorCode === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
115
|
+
(e.message?.includes(errors_1.EthersErrorMessage.Underpriced) ||
|
|
116
|
+
e.message?.includes(errors_1.EthersErrorMessage.LowReplacementFee))) {
|
|
117
|
+
return new errors_1.RPCError(errors_1.LiFiErrorCode.TransactionUnderpriced, errors_1.ErrorMessage.TransactionUnderpriced, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
118
|
+
}
|
|
119
|
+
if (e.message?.includes(errors_1.EthersErrorMessage.LowGas) ||
|
|
120
|
+
e.message?.includes(errors_1.EthersErrorMessage.OutOfGas)) {
|
|
121
|
+
return new errors_1.TransactionError(errors_1.LiFiErrorCode.GasLimitError, errors_1.ErrorMessage.GasLimitLow, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
122
|
+
}
|
|
123
|
+
return new errors_1.RPCError(errorCode, (0, eth_rpc_errors_1.getMessageFromCode)(errorCode), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
124
|
+
}
|
|
125
|
+
// provider errors
|
|
126
|
+
if (Object.values(eth_rpc_errors_1.errorCodes.provider).includes(errorCode)) {
|
|
127
|
+
return new errors_1.ProviderError(errorCode, (0, eth_rpc_errors_1.getMessageFromCode)(errorCode), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return new errors_1.UnknownError(errors_1.LiFiErrorCode.InternalError, e.message || errors_1.ErrorMessage.UnknownError, undefined, e.stack);
|
|
131
|
+
}
|
|
129
132
|
}
|
|
130
133
|
};
|
|
131
134
|
exports.parseError = parseError;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { LifiStep, Token } from '@lifi/types';
|
|
3
|
-
import BigNumber from 'bignumber.js';
|
|
4
|
-
import { Signer } from 'ethers';
|
|
5
|
-
import { ChainId } from '../types';
|
|
6
|
-
export declare const sleep: (mills: number) => Promise<undefined>;
|
|
7
|
-
export declare const personalizeStep: (signer: Signer, step: LifiStep) => Promise<LifiStep>;
|
|
8
|
-
export declare const splitListIntoChunks: <T>(list: T[], chunkSize: number) => T[][];
|
|
9
|
-
export declare const formatTokenAmountOnly: (token: Token, amount: string | BigNumber | undefined) => string;
|
|
1
|
+
export declare const wait: (ms: number) => Promise<undefined>;
|
|
10
2
|
/**
|
|
11
3
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
12
4
|
* @param toRepeat The function that should be repeated
|
|
@@ -14,12 +6,5 @@ export declare const formatTokenAmountOnly: (token: Token, amount: string | BigN
|
|
|
14
6
|
* @returns The result of the toRepeat function
|
|
15
7
|
*/
|
|
16
8
|
export declare const repeatUntilDone: <T>(toRepeat: () => Promise<T | undefined>, timeout?: number) => Promise<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Loads a transaction receipt using the rpc for the given chain id
|
|
19
|
-
* @param chainId The chain id where the transaction should be loaded from
|
|
20
|
-
* @param txHash The hash of the transaction
|
|
21
|
-
* @returns TransactionReceipt
|
|
22
|
-
*/
|
|
23
|
-
export declare const loadTransactionReceipt: (chainId: ChainId, txHash: string) => Promise<TransactionReceipt>;
|
|
24
9
|
export declare const isZeroAddress: (address: string) => boolean;
|
|
25
10
|
export declare const isNativeTokenAddress: (address: string) => boolean;
|