@lifi/sdk 2.2.3 → 3.0.0-alpha.2
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 +4 -2
- 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 -31
- 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 +4 -2
- 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 -31
- 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 +43 -40
- 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,30 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
gasPrice: string;
|
|
17
|
-
gasFee: string;
|
|
18
|
-
toTokenAddress?: string;
|
|
1
|
+
import type { ChainId, LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
|
+
import type { Hash, Hex, WalletClient } from 'viem';
|
|
3
|
+
import type { StatusManager } from '../execution/StatusManager';
|
|
4
|
+
import type { StepExecutor } from '../execution/StepExecutor';
|
|
5
|
+
export type TransactionParameters = {
|
|
6
|
+
chainId?: number;
|
|
7
|
+
to?: string;
|
|
8
|
+
from?: string;
|
|
9
|
+
nonce?: number;
|
|
10
|
+
data?: Hex;
|
|
11
|
+
value?: bigint;
|
|
12
|
+
gas?: bigint;
|
|
13
|
+
gasPrice?: bigint;
|
|
14
|
+
maxFeePerGas?: bigint;
|
|
15
|
+
maxPriorityFeePerGas?: bigint;
|
|
19
16
|
};
|
|
20
17
|
export interface ExecutionParams {
|
|
21
|
-
|
|
18
|
+
walletClient: WalletClient;
|
|
22
19
|
step: LifiStep;
|
|
23
20
|
statusManager: StatusManager;
|
|
24
21
|
settings: InternalExecutionSettings;
|
|
25
22
|
}
|
|
26
23
|
export type UpdateRouteHook = (updatedRoute: Route) => void;
|
|
27
|
-
export type TransactionRequestUpdateHook = (updatedTxRequest:
|
|
24
|
+
export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionParameters) => Promise<TransactionParameters>;
|
|
28
25
|
export type Config = {
|
|
29
26
|
apiUrl: string;
|
|
30
27
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -35,24 +32,24 @@ export type Config = {
|
|
|
35
32
|
userId?: string;
|
|
36
33
|
integrator: string;
|
|
37
34
|
widgetVersion?: string;
|
|
38
|
-
|
|
35
|
+
multisig?: MultisigConfig;
|
|
39
36
|
};
|
|
40
37
|
export interface MultisigTxDetails {
|
|
41
38
|
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
42
|
-
txHash?:
|
|
39
|
+
txHash?: Hash;
|
|
43
40
|
}
|
|
44
41
|
export interface MultisigTransactionResponse {
|
|
45
42
|
hash: string;
|
|
46
43
|
}
|
|
47
44
|
export interface BaseTransaction {
|
|
48
45
|
to: string;
|
|
49
|
-
value
|
|
46
|
+
value?: bigint;
|
|
50
47
|
data: string;
|
|
51
48
|
}
|
|
52
49
|
export interface MultisigConfig {
|
|
53
|
-
|
|
54
|
-
getMultisigTransactionDetails
|
|
55
|
-
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<
|
|
50
|
+
isMultisigWalletClient: boolean;
|
|
51
|
+
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
52
|
+
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
56
53
|
shouldBatchTransactions?: boolean;
|
|
57
54
|
}
|
|
58
55
|
export type ConfigUpdate = {
|
|
@@ -67,7 +64,7 @@ export type ConfigUpdate = {
|
|
|
67
64
|
widgetVersion?: string;
|
|
68
65
|
multisigConfig?: MultisigConfig;
|
|
69
66
|
};
|
|
70
|
-
export type SwitchChainHook = (requiredChainId: number) => Promise<
|
|
67
|
+
export type SwitchChainHook = (requiredChainId: number) => Promise<WalletClient | undefined>;
|
|
71
68
|
export interface AcceptSlippageUpdateHookParams {
|
|
72
69
|
toToken: Token;
|
|
73
70
|
oldToAmount: string;
|
|
@@ -98,10 +95,6 @@ export interface InternalExecutionSettings {
|
|
|
98
95
|
}
|
|
99
96
|
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
100
97
|
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
101
|
-
export type RevokeTokenData = {
|
|
102
|
-
token: Token;
|
|
103
|
-
approvalAddress: string;
|
|
104
|
-
};
|
|
105
98
|
export interface InteractionSettings {
|
|
106
99
|
allowInteraction?: boolean;
|
|
107
100
|
allowUpdates?: boolean;
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -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/utils/errors.js
CHANGED
|
@@ -9,25 +9,26 @@ var ErrorType;
|
|
|
9
9
|
ErrorType["UnknownError"] = "UnknownError";
|
|
10
10
|
ErrorType["SlippageError"] = "SlippageError";
|
|
11
11
|
})(ErrorType || (ErrorType = {}));
|
|
12
|
-
export var
|
|
13
|
-
(function (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
export var LiFiErrorCode;
|
|
13
|
+
(function (LiFiErrorCode) {
|
|
14
|
+
LiFiErrorCode[LiFiErrorCode["InternalError"] = 1000] = "InternalError";
|
|
15
|
+
LiFiErrorCode[LiFiErrorCode["ValidationError"] = 1001] = "ValidationError";
|
|
16
|
+
LiFiErrorCode[LiFiErrorCode["TransactionUnderpriced"] = 1002] = "TransactionUnderpriced";
|
|
17
|
+
LiFiErrorCode[LiFiErrorCode["TransactionFailed"] = 1003] = "TransactionFailed";
|
|
18
|
+
LiFiErrorCode[LiFiErrorCode["Timeout"] = 1004] = "Timeout";
|
|
19
|
+
LiFiErrorCode[LiFiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
|
|
20
|
+
LiFiErrorCode[LiFiErrorCode["NotFound"] = 1006] = "NotFound";
|
|
21
|
+
LiFiErrorCode[LiFiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
|
|
22
|
+
LiFiErrorCode[LiFiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
|
|
23
|
+
LiFiErrorCode[LiFiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
|
|
24
|
+
LiFiErrorCode[LiFiErrorCode["TransactionCanceled"] = 1010] = "TransactionCanceled";
|
|
25
|
+
LiFiErrorCode[LiFiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
26
|
+
LiFiErrorCode[LiFiErrorCode["SignatureRejected"] = 1012] = "SignatureRejected";
|
|
27
|
+
LiFiErrorCode[LiFiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
28
|
+
LiFiErrorCode[LiFiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
29
|
+
LiFiErrorCode[LiFiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
|
|
30
|
+
LiFiErrorCode[LiFiErrorCode["ExchangeRateUpdateCanceled"] = 1016] = "ExchangeRateUpdateCanceled";
|
|
31
|
+
})(LiFiErrorCode || (LiFiErrorCode = {}));
|
|
31
32
|
export var EthersErrorType;
|
|
32
33
|
(function (EthersErrorType) {
|
|
33
34
|
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
@@ -72,11 +73,11 @@ export var MetaMaskProviderErrorCode;
|
|
|
72
73
|
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["disconnected"] = 4900] = "disconnected";
|
|
73
74
|
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["chainDisconnected"] = 4901] = "chainDisconnected";
|
|
74
75
|
})(MetaMaskProviderErrorCode || (MetaMaskProviderErrorCode = {}));
|
|
75
|
-
export class
|
|
76
|
+
export class LiFiError extends Error {
|
|
76
77
|
constructor(type, code, message, htmlMessage, stack) {
|
|
77
78
|
super(message);
|
|
78
79
|
// Set the prototype explicitly: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
79
|
-
Object.setPrototypeOf(this,
|
|
80
|
+
Object.setPrototypeOf(this, LiFiError.prototype);
|
|
80
81
|
this.code = code;
|
|
81
82
|
// 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
|
|
82
83
|
this.name = type.toString();
|
|
@@ -87,47 +88,47 @@ export class LifiError extends Error {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
export class RPCError extends
|
|
91
|
+
export class RPCError extends LiFiError {
|
|
91
92
|
constructor(code, message, htmlMessage, stack) {
|
|
92
93
|
super(ErrorType.RPCError, code, message, htmlMessage, stack);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
export class ProviderError extends
|
|
96
|
+
export class ProviderError extends LiFiError {
|
|
96
97
|
constructor(code, message, htmlMessage, stack) {
|
|
97
98
|
super(ErrorType.ProviderError, code, message, htmlMessage, stack);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
export class ServerError extends
|
|
101
|
+
export class ServerError extends LiFiError {
|
|
101
102
|
constructor(message, htmlMessage, stack) {
|
|
102
|
-
super(ErrorType.ServerError,
|
|
103
|
+
super(ErrorType.ServerError, LiFiErrorCode.InternalError, message, htmlMessage, stack);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
export class ValidationError extends
|
|
106
|
+
export class ValidationError extends LiFiError {
|
|
106
107
|
constructor(message, htmlMessage, stack) {
|
|
107
|
-
super(ErrorType.ValidationError,
|
|
108
|
+
super(ErrorType.ValidationError, LiFiErrorCode.ValidationError, message, htmlMessage, stack);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
export class TransactionError extends
|
|
111
|
+
export class TransactionError extends LiFiError {
|
|
111
112
|
constructor(code, message, htmlMessage, stack) {
|
|
112
113
|
super(ErrorType.TransactionError, code, message, htmlMessage, stack);
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
|
-
export class SlippageError extends
|
|
116
|
+
export class SlippageError extends LiFiError {
|
|
116
117
|
constructor(message, htmlMessage, stack) {
|
|
117
|
-
super(ErrorType.SlippageError,
|
|
118
|
+
super(ErrorType.SlippageError, LiFiErrorCode.SlippageError, message, htmlMessage, stack);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
|
-
export class BalanceError extends
|
|
121
|
+
export class BalanceError extends LiFiError {
|
|
121
122
|
constructor(message, htmlMessage, stack) {
|
|
122
|
-
super(ErrorType.ValidationError,
|
|
123
|
+
super(ErrorType.ValidationError, LiFiErrorCode.BalanceError, message, htmlMessage, stack);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
export class NotFoundError extends
|
|
126
|
+
export class NotFoundError extends LiFiError {
|
|
126
127
|
constructor(message, htmlMessage, stack) {
|
|
127
|
-
super(ErrorType.NotFoundError,
|
|
128
|
+
super(ErrorType.NotFoundError, LiFiErrorCode.NotFound, message, htmlMessage, stack);
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
export class UnknownError extends
|
|
131
|
+
export class UnknownError extends LiFiError {
|
|
131
132
|
constructor(code, message, htmlMessage, stack) {
|
|
132
133
|
super(ErrorType.UnknownError, code, message, htmlMessage, stack);
|
|
133
134
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { median } from './median';
|
|
2
|
+
export const getMaxPriorityFeePerGas = async (client) => {
|
|
3
|
+
const block = await client.getBlock({
|
|
4
|
+
includeTransactions: true,
|
|
5
|
+
});
|
|
6
|
+
const maxPriorityFeePerGasList = block.transactions
|
|
7
|
+
.filter((tx) => tx.maxPriorityFeePerGas)
|
|
8
|
+
.map((tx) => tx.maxPriorityFeePerGas);
|
|
9
|
+
if (!maxPriorityFeePerGasList.length) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const maxPriorityFeePerGasSum = maxPriorityFeePerGasList.reduce((acc, value) => (acc += value), 0n);
|
|
13
|
+
const maxPriorityFeePerGasMedian = median(maxPriorityFeePerGasList) ?? 0n;
|
|
14
|
+
const maxPriorityFeePerGasAvg = maxPriorityFeePerGasSum / BigInt(maxPriorityFeePerGasList.length);
|
|
15
|
+
return maxPriorityFeePerGasMedian > maxPriorityFeePerGasAvg
|
|
16
|
+
? maxPriorityFeePerGasAvg
|
|
17
|
+
: maxPriorityFeePerGasMedian;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const median: (arr: bigint[]) => bigint | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const median = (arr) => {
|
|
2
|
+
if (!arr.length) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const s = [...arr].sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
|
|
6
|
+
const mid = Math.floor(s.length / 2);
|
|
7
|
+
if (s.length % 2 === 0) {
|
|
8
|
+
return (s[mid - 1] + s[mid]) / 2n;
|
|
9
|
+
}
|
|
10
|
+
return s[mid];
|
|
11
|
+
};
|
|
@@ -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>;
|
package/dist/utils/parseError.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
|
|
2
|
+
import { formatUnits } from 'viem';
|
|
2
3
|
import { fetchTxErrorDetails } from '../helpers';
|
|
3
4
|
import ChainsService from '../services/ChainsService';
|
|
4
|
-
import { ErrorMessage, EthersErrorMessage, EthersErrorType,
|
|
5
|
-
import { formatTokenAmountOnly } from './utils';
|
|
5
|
+
import { ErrorMessage, EthersErrorMessage, EthersErrorType, LiFiError, LiFiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
6
6
|
/**
|
|
7
7
|
* Available MetaMask error codes:
|
|
8
8
|
*
|
|
@@ -40,7 +40,7 @@ export const getTransactionNotSentMessage = async (step, process) => {
|
|
|
40
40
|
if (step) {
|
|
41
41
|
const chainService = ChainsService.getInstance();
|
|
42
42
|
const chain = await chainService.getChainById(step.action.fromChainId);
|
|
43
|
-
transactionNotSend += ` (${
|
|
43
|
+
transactionNotSend += ` (${formatUnits(BigInt(step.action.fromAmount), step.action.fromToken.decimals)} ${step.action.fromToken.symbol} on ${chain.name})`;
|
|
44
44
|
}
|
|
45
45
|
transactionNotSend +=
|
|
46
46
|
", please retry.<br/>If it still doesn't work, it is safe to delete this transfer and start a new one.";
|
|
@@ -62,62 +62,65 @@ export const getTransactionFailedMessage = async (step, txLink) => {
|
|
|
62
62
|
: baseString;
|
|
63
63
|
};
|
|
64
64
|
export const parseError = async (e, step, process) => {
|
|
65
|
-
if (e instanceof
|
|
65
|
+
if (e instanceof LiFiError) {
|
|
66
66
|
return e;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (typeof e.code === 'number') {
|
|
71
|
-
if (Object.values(MetaMaskErrorCodes.rpc).includes(e.code)) {
|
|
72
|
-
// rpc errors
|
|
73
|
-
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
74
|
-
if (e.code === MetaMaskErrorCodes.rpc.internal &&
|
|
75
|
-
(e.message?.includes(EthersErrorMessage.Underpriced) ||
|
|
76
|
-
e.message?.includes(EthersErrorMessage.LowReplacementFee))) {
|
|
77
|
-
return new RPCError(LifiErrorCode.TransactionUnderpriced, ErrorMessage.TransactionUnderpriced, await getTransactionNotSentMessage(step, process), e.stack);
|
|
78
|
-
}
|
|
79
|
-
if (e.message?.includes(EthersErrorMessage.LowGas) ||
|
|
80
|
-
e.message?.includes(EthersErrorMessage.OutOfGas)) {
|
|
81
|
-
return new TransactionError(LifiErrorCode.GasLimitError, ErrorMessage.GasLimitLow, await getTransactionNotSentMessage(step, process), e.stack);
|
|
82
|
-
}
|
|
83
|
-
return new RPCError(e.code, getMessageFromCode(e.code), await getTransactionNotSentMessage(step, process), e.stack);
|
|
84
|
-
}
|
|
85
|
-
// provider errors
|
|
86
|
-
if (Object.values(MetaMaskErrorCodes.provider).includes(e.code)) {
|
|
87
|
-
return new ProviderError(e.code, getMessageFromCode(e.code), await getTransactionNotSentMessage(step, process), e.stack);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
switch (e.code) {
|
|
68
|
+
const errorCode = e.code || e.cause?.code;
|
|
69
|
+
switch (errorCode) {
|
|
92
70
|
case EthersErrorType.CallExecption:
|
|
93
71
|
const defaultErrorMessage = await getTransactionNotSentMessage(step, process);
|
|
94
72
|
try {
|
|
95
73
|
if (!step?.action.fromChainId) {
|
|
96
|
-
throw new Error('
|
|
74
|
+
throw new Error('fromChainId is not defined.');
|
|
97
75
|
}
|
|
98
76
|
const response = await fetchTxErrorDetails(e.transactionHash, step?.action.fromChainId);
|
|
99
77
|
const errorMessage = response?.error_message ?? e.reason;
|
|
100
78
|
const isAllowanceError = response?.error_message?.includes(EthersErrorMessage.ERC20Allowance) || e.reason?.includes(EthersErrorMessage.ERC20Allowance);
|
|
101
79
|
if (isAllowanceError) {
|
|
102
|
-
return new TransactionError(
|
|
80
|
+
return new TransactionError(LiFiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
|
|
103
81
|
}
|
|
104
82
|
// Error messages other than allowance error will be handled in catch block
|
|
105
83
|
throw new Error(e);
|
|
106
84
|
}
|
|
107
85
|
catch (error) {
|
|
108
|
-
return new ProviderError(
|
|
86
|
+
return new ProviderError(LiFiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
|
|
109
87
|
}
|
|
110
88
|
case EthersErrorType.InsufficientFunds:
|
|
111
|
-
return new TransactionError(
|
|
89
|
+
return new TransactionError(LiFiErrorCode.InsufficientFunds, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
112
90
|
case EthersErrorType.ActionRejected:
|
|
113
91
|
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
114
|
-
return new TransactionError(
|
|
115
|
-
case
|
|
116
|
-
return new TransactionError(
|
|
117
|
-
case
|
|
118
|
-
return new TransactionError(
|
|
119
|
-
|
|
120
|
-
return new
|
|
92
|
+
return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
93
|
+
case LiFiErrorCode.TransactionUnprepared:
|
|
94
|
+
return new TransactionError(LiFiErrorCode.TransactionUnprepared, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
95
|
+
case LiFiErrorCode.ValidationError:
|
|
96
|
+
return new TransactionError(LiFiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
97
|
+
case LiFiErrorCode.TransactionCanceled:
|
|
98
|
+
return new TransactionError(LiFiErrorCode.TransactionCanceled, e.message, e.htmlMessage);
|
|
99
|
+
case LiFiErrorCode.ExchangeRateUpdateCanceled:
|
|
100
|
+
return new TransactionError(LiFiErrorCode.ExchangeRateUpdateCanceled, e.message, e.htmlMessage);
|
|
101
|
+
default: {
|
|
102
|
+
if (errorCode && typeof errorCode === 'number') {
|
|
103
|
+
if (Object.values(MetaMaskErrorCodes.rpc).includes(errorCode)) {
|
|
104
|
+
// rpc errors
|
|
105
|
+
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
106
|
+
if (errorCode === MetaMaskErrorCodes.rpc.internal &&
|
|
107
|
+
(e.message?.includes(EthersErrorMessage.Underpriced) ||
|
|
108
|
+
e.message?.includes(EthersErrorMessage.LowReplacementFee))) {
|
|
109
|
+
return new RPCError(LiFiErrorCode.TransactionUnderpriced, ErrorMessage.TransactionUnderpriced, await getTransactionNotSentMessage(step, process), e.stack);
|
|
110
|
+
}
|
|
111
|
+
if (e.message?.includes(EthersErrorMessage.LowGas) ||
|
|
112
|
+
e.message?.includes(EthersErrorMessage.OutOfGas)) {
|
|
113
|
+
return new TransactionError(LiFiErrorCode.GasLimitError, ErrorMessage.GasLimitLow, await getTransactionNotSentMessage(step, process), e.stack);
|
|
114
|
+
}
|
|
115
|
+
return new RPCError(errorCode, getMessageFromCode(errorCode), await getTransactionNotSentMessage(step, process), e.stack);
|
|
116
|
+
}
|
|
117
|
+
// provider errors
|
|
118
|
+
if (Object.values(MetaMaskErrorCodes.provider).includes(errorCode)) {
|
|
119
|
+
return new ProviderError(errorCode, getMessageFromCode(errorCode), await getTransactionNotSentMessage(step, process), e.stack);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return new UnknownError(LiFiErrorCode.InternalError, e.message || ErrorMessage.UnknownError, undefined, e.stack);
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
125
|
};
|
|
123
126
|
export const parseBackendError = async (e) => {
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,59 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { getRpcProvider } from '../connectors';
|
|
4
|
-
export const sleep = (mills) => {
|
|
1
|
+
import { AddressZero, AlternativeAddressZero } from '../constants';
|
|
2
|
+
export const wait = (ms) => {
|
|
5
3
|
return new Promise((resolve) => {
|
|
6
|
-
setTimeout(resolve,
|
|
4
|
+
setTimeout(resolve, ms);
|
|
7
5
|
});
|
|
8
6
|
};
|
|
9
|
-
export const personalizeStep = async (signer, step) => {
|
|
10
|
-
if (step.action.toAddress && step.action.fromAddress) {
|
|
11
|
-
return step;
|
|
12
|
-
}
|
|
13
|
-
const address = await signer.getAddress();
|
|
14
|
-
const fromAddress = step.action.fromAddress || address;
|
|
15
|
-
const toAddress = step.action.toAddress || address;
|
|
16
|
-
return {
|
|
17
|
-
...step,
|
|
18
|
-
action: {
|
|
19
|
-
...step.action,
|
|
20
|
-
fromAddress,
|
|
21
|
-
toAddress,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
|
|
26
|
-
const chunkIndex = Math.floor(index / chunkSize);
|
|
27
|
-
if (!resultList[chunkIndex]) {
|
|
28
|
-
resultList[chunkIndex] = []; // start a new chunk
|
|
29
|
-
}
|
|
30
|
-
resultList[chunkIndex].push(item);
|
|
31
|
-
return resultList;
|
|
32
|
-
}, []);
|
|
33
|
-
export const formatTokenAmountOnly = (token, amount) => {
|
|
34
|
-
if (!amount) {
|
|
35
|
-
return '0.0';
|
|
36
|
-
}
|
|
37
|
-
let floated;
|
|
38
|
-
if (typeof amount === 'string') {
|
|
39
|
-
if (amount === '0') {
|
|
40
|
-
return '0.0';
|
|
41
|
-
}
|
|
42
|
-
floated = new BigNumber(amount).shiftedBy(-token.decimals);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
floated = amount;
|
|
46
|
-
if (floated.isZero()) {
|
|
47
|
-
return '0.0';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// show at least 4 decimal places and at least two non-zero digests
|
|
51
|
-
let decimalPlaces = 3;
|
|
52
|
-
while (floated.lt(1 / 10 ** decimalPlaces)) {
|
|
53
|
-
decimalPlaces++;
|
|
54
|
-
}
|
|
55
|
-
return floated.toFixed(decimalPlaces + 1, 1);
|
|
56
|
-
};
|
|
57
7
|
/**
|
|
58
8
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
59
9
|
* @param toRepeat The function that should be repeated
|
|
@@ -65,32 +15,20 @@ export const repeatUntilDone = async (toRepeat, timeout = 5000) => {
|
|
|
65
15
|
while (!result) {
|
|
66
16
|
result = await toRepeat();
|
|
67
17
|
if (!result) {
|
|
68
|
-
await
|
|
18
|
+
await wait(timeout);
|
|
69
19
|
}
|
|
70
20
|
}
|
|
71
21
|
return result;
|
|
72
22
|
};
|
|
73
|
-
/**
|
|
74
|
-
* Loads a transaction receipt using the rpc for the given chain id
|
|
75
|
-
* @param chainId The chain id where the transaction should be loaded from
|
|
76
|
-
* @param txHash The hash of the transaction
|
|
77
|
-
* @returns TransactionReceipt
|
|
78
|
-
*/
|
|
79
|
-
export const loadTransactionReceipt = async (chainId, txHash) => {
|
|
80
|
-
const rpc = await getRpcProvider(chainId);
|
|
81
|
-
const tx = await rpc.getTransaction(txHash);
|
|
82
|
-
return tx.wait();
|
|
83
|
-
};
|
|
84
23
|
export const isZeroAddress = (address) => {
|
|
85
|
-
if (address ===
|
|
86
|
-
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
24
|
+
if (address === AddressZero || address === AlternativeAddressZero) {
|
|
87
25
|
return true;
|
|
88
26
|
}
|
|
89
27
|
return false;
|
|
90
28
|
};
|
|
91
29
|
export const isNativeTokenAddress = (address) => {
|
|
92
|
-
if (address ===
|
|
93
|
-
address ===
|
|
30
|
+
if (address === AddressZero ||
|
|
31
|
+
address === AlternativeAddressZero ||
|
|
94
32
|
// CELO native token
|
|
95
33
|
address === '0x471ece3750da237f93b8e339c536989b8978a438') {
|
|
96
34
|
return true;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "
|
|
2
|
+
export declare const version = "3.0.0-alpha.2";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '3.0.0-alpha.2';
|