@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.
Files changed (183) hide show
  1. package/dist/LiFi.d.ts +69 -62
  2. package/dist/LiFi.js +71 -60
  3. package/dist/allowance/getAllowance.d.ts +6 -0
  4. package/dist/allowance/getAllowance.js +78 -0
  5. package/dist/allowance/index.d.ts +3 -2
  6. package/dist/allowance/index.js +3 -2
  7. package/dist/allowance/setAllowance.d.ts +5 -0
  8. package/dist/allowance/setAllowance.js +50 -0
  9. package/dist/allowance/types.d.ts +27 -0
  10. package/dist/allowance/types.js +1 -0
  11. package/dist/balance/getBalance.d.ts +2 -0
  12. package/dist/balance/getBalance.js +93 -0
  13. package/dist/balance/getTokenBalance.d.ts +2 -2
  14. package/dist/balance/getTokenBalance.js +4 -4
  15. package/dist/balance/index.d.ts +1 -12
  16. package/dist/balance/index.js +1 -9
  17. package/dist/cjs/LiFi.d.ts +69 -62
  18. package/dist/cjs/LiFi.js +69 -58
  19. package/dist/cjs/allowance/getAllowance.d.ts +6 -0
  20. package/dist/cjs/allowance/getAllowance.js +85 -0
  21. package/dist/cjs/allowance/index.d.ts +3 -2
  22. package/dist/cjs/allowance/index.js +3 -2
  23. package/dist/cjs/allowance/setAllowance.d.ts +5 -0
  24. package/dist/cjs/allowance/setAllowance.js +56 -0
  25. package/dist/cjs/allowance/types.d.ts +27 -0
  26. package/dist/cjs/allowance/types.js +2 -0
  27. package/dist/cjs/balance/getBalance.d.ts +2 -0
  28. package/dist/cjs/balance/getBalance.js +97 -0
  29. package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
  30. package/dist/cjs/balance/getTokenBalance.js +6 -9
  31. package/dist/cjs/balance/index.d.ts +1 -12
  32. package/dist/cjs/balance/index.js +1 -9
  33. package/dist/cjs/connectors.d.ts +7 -5
  34. package/dist/cjs/connectors.js +45 -37
  35. package/dist/cjs/constants.d.ts +6 -0
  36. package/dist/cjs/constants.js +9 -0
  37. package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
  38. package/dist/cjs/execution/RouteExecutionManager.js +27 -45
  39. package/dist/cjs/execution/StatusManager.d.ts +22 -23
  40. package/dist/cjs/execution/StatusManager.js +21 -22
  41. package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
  42. package/dist/cjs/execution/StepExecutionManager.js +118 -125
  43. package/dist/cjs/execution/StepExecutor.d.ts +4 -4
  44. package/dist/cjs/execution/StepExecutor.js +6 -6
  45. package/dist/cjs/execution/checkAllowance.d.ts +4 -0
  46. package/dist/cjs/execution/checkAllowance.js +77 -0
  47. package/dist/cjs/execution/checkBalance.d.ts +2 -0
  48. package/dist/cjs/execution/checkBalance.js +42 -0
  49. package/dist/cjs/execution/multisig.d.ts +4 -3
  50. package/dist/cjs/execution/multisig.js +9 -11
  51. package/dist/cjs/execution/prepareRestart.d.ts +3 -0
  52. package/dist/cjs/execution/prepareRestart.js +65 -0
  53. package/dist/cjs/execution/stepComparison.d.ts +3 -3
  54. package/dist/cjs/execution/stepComparison.js +2 -2
  55. package/dist/cjs/execution/switchChain.d.ts +13 -8
  56. package/dist/cjs/execution/switchChain.js +16 -11
  57. package/dist/cjs/execution/utils.d.ts +9 -3
  58. package/dist/cjs/execution/utils.js +19 -66
  59. package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
  60. package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
  61. package/dist/cjs/helpers.d.ts +7 -17
  62. package/dist/cjs/helpers.js +6 -38
  63. package/dist/cjs/request.js +1 -1
  64. package/dist/cjs/services/ApiService.d.ts +2 -2
  65. package/dist/cjs/services/ApiService.js +4 -2
  66. package/dist/cjs/services/ChainsService.d.ts +1 -1
  67. package/dist/cjs/services/ConfigService.d.ts +1 -1
  68. package/dist/cjs/services/ConfigService.js +1 -2
  69. package/dist/cjs/typeguards.d.ts +1 -1
  70. package/dist/cjs/types/abi.d.ts +5 -0
  71. package/dist/cjs/types/abi.js +45 -0
  72. package/dist/cjs/types/index.d.ts +2 -2
  73. package/dist/cjs/types/index.js +3 -3
  74. package/dist/cjs/types/internal.types.d.ts +24 -31
  75. package/dist/cjs/utils/errors.d.ts +15 -14
  76. package/dist/cjs/utils/errors.js +38 -37
  77. package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  78. package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
  79. package/dist/cjs/utils/index.d.ts +5 -0
  80. package/dist/cjs/utils/index.js +21 -0
  81. package/dist/cjs/utils/median.d.ts +1 -0
  82. package/dist/cjs/utils/median.js +15 -0
  83. package/dist/cjs/utils/parseError.d.ts +4 -4
  84. package/dist/cjs/utils/parseError.js +41 -38
  85. package/dist/cjs/utils/utils.d.ts +1 -16
  86. package/dist/cjs/utils/utils.js +9 -78
  87. package/dist/cjs/version.d.ts +1 -1
  88. package/dist/cjs/version.js +1 -1
  89. package/dist/connectors.d.ts +7 -5
  90. package/dist/connectors.js +19 -35
  91. package/dist/constants.d.ts +6 -0
  92. package/dist/constants.js +6 -0
  93. package/dist/execution/RouteExecutionManager.d.ts +24 -30
  94. package/dist/execution/RouteExecutionManager.js +27 -45
  95. package/dist/execution/StatusManager.d.ts +22 -23
  96. package/dist/execution/StatusManager.js +22 -23
  97. package/dist/execution/StepExecutionManager.d.ts +3 -3
  98. package/dist/execution/StepExecutionManager.js +116 -123
  99. package/dist/execution/StepExecutor.d.ts +4 -4
  100. package/dist/execution/StepExecutor.js +6 -6
  101. package/dist/execution/checkAllowance.d.ts +4 -0
  102. package/dist/execution/checkAllowance.js +73 -0
  103. package/dist/execution/checkBalance.d.ts +2 -0
  104. package/dist/execution/checkBalance.js +38 -0
  105. package/dist/execution/multisig.d.ts +4 -3
  106. package/dist/execution/multisig.js +10 -12
  107. package/dist/execution/prepareRestart.d.ts +3 -0
  108. package/dist/execution/prepareRestart.js +61 -0
  109. package/dist/execution/stepComparison.d.ts +3 -3
  110. package/dist/execution/stepComparison.js +3 -3
  111. package/dist/execution/switchChain.d.ts +13 -8
  112. package/dist/execution/switchChain.js +17 -12
  113. package/dist/execution/utils.d.ts +9 -3
  114. package/dist/execution/utils.js +18 -61
  115. package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
  116. package/dist/execution/waitForReceivingTransaction.js +51 -0
  117. package/dist/helpers.d.ts +7 -17
  118. package/dist/helpers.js +5 -34
  119. package/dist/request.js +2 -2
  120. package/dist/services/ApiService.d.ts +2 -2
  121. package/dist/services/ApiService.js +4 -2
  122. package/dist/services/ChainsService.d.ts +1 -1
  123. package/dist/services/ConfigService.d.ts +1 -1
  124. package/dist/services/ConfigService.js +2 -3
  125. package/dist/typeguards.d.ts +1 -1
  126. package/dist/types/abi.d.ts +5 -0
  127. package/dist/types/abi.js +42 -0
  128. package/dist/types/index.d.ts +2 -2
  129. package/dist/types/index.js +2 -2
  130. package/dist/types/internal.types.d.ts +24 -31
  131. package/dist/utils/errors.d.ts +15 -14
  132. package/dist/utils/errors.js +36 -35
  133. package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  134. package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
  135. package/dist/utils/index.d.ts +5 -0
  136. package/dist/utils/index.js +5 -0
  137. package/dist/utils/median.d.ts +1 -0
  138. package/dist/utils/median.js +11 -0
  139. package/dist/utils/parseError.d.ts +4 -4
  140. package/dist/utils/parseError.js +42 -39
  141. package/dist/utils/utils.d.ts +1 -16
  142. package/dist/utils/utils.js +7 -69
  143. package/dist/version.d.ts +1 -1
  144. package/dist/version.js +1 -1
  145. package/package.json +43 -40
  146. package/dist/allowance/checkAllowance.d.ts +0 -4
  147. package/dist/allowance/checkAllowance.js +0 -96
  148. package/dist/allowance/tokenApproval.d.ts +0 -22
  149. package/dist/allowance/tokenApproval.js +0 -59
  150. package/dist/allowance/utils.d.ts +0 -15
  151. package/dist/allowance/utils.js +0 -77
  152. package/dist/balance/checkBalance.d.ts +0 -3
  153. package/dist/balance/checkBalance.js +0 -38
  154. package/dist/balance/utils.d.ts +0 -6
  155. package/dist/balance/utils.js +0 -143
  156. package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
  157. package/dist/cjs/allowance/checkAllowance.js +0 -103
  158. package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
  159. package/dist/cjs/allowance/tokenApproval.js +0 -69
  160. package/dist/cjs/allowance/utils.d.ts +0 -15
  161. package/dist/cjs/allowance/utils.js +0 -87
  162. package/dist/cjs/balance/checkBalance.d.ts +0 -3
  163. package/dist/cjs/balance/checkBalance.js +0 -45
  164. package/dist/cjs/balance/utils.d.ts +0 -6
  165. package/dist/cjs/balance/utils.js +0 -150
  166. package/dist/cjs/types/ERC20.d.ts +0 -22
  167. package/dist/cjs/types/ERC20.js +0 -53
  168. package/dist/cjs/utils/getProvider.d.ts +0 -3
  169. package/dist/cjs/utils/getProvider.js +0 -11
  170. package/dist/cjs/utils/multicall.d.ts +0 -10
  171. package/dist/cjs/utils/multicall.js +0 -68
  172. package/dist/cjs/utils/multicallAbi.json +0 -313
  173. package/dist/cjs/utils/preRestart.d.ts +0 -3
  174. package/dist/cjs/utils/preRestart.js +0 -56
  175. package/dist/types/ERC20.d.ts +0 -22
  176. package/dist/types/ERC20.js +0 -50
  177. package/dist/utils/getProvider.d.ts +0 -3
  178. package/dist/utils/getProvider.js +0 -7
  179. package/dist/utils/multicall.d.ts +0 -10
  180. package/dist/utils/multicall.js +0 -61
  181. package/dist/utils/multicallAbi.json +0 -313
  182. package/dist/utils/preRestart.d.ts +0 -3
  183. package/dist/utils/preRestart.js +0 -52
@@ -1,30 +1,27 @@
1
- import { TransactionRequest } from '@ethersproject/abstract-provider';
2
- import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
3
- import BigNumber from 'bignumber.js';
4
- import { Signer } from 'ethers';
5
- import { ChainId } from '.';
6
- import { StatusManager } from '../execution/StatusManager';
7
- import { StepExecutor } from '../execution/StepExecutor';
8
- export interface TokenWithAmounts extends Token {
9
- amount?: BigNumber;
10
- amountRendered?: string;
11
- }
12
- export type ParsedReceipt = {
13
- fromAmount?: string;
14
- toAmount: string;
15
- gasUsed: string;
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
- signer: Signer;
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: TransactionRequest) => Promise<TransactionRequest>;
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
- multisigConfig?: MultisigConfig;
35
+ multisig?: MultisigConfig;
39
36
  };
40
37
  export interface MultisigTxDetails {
41
38
  status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
42
- txHash?: string;
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: string;
46
+ value?: bigint;
50
47
  data: string;
51
48
  }
52
49
  export interface MultisigConfig {
53
- isMultisigSigner?: boolean;
54
- getMultisigTransactionDetails?: (txHash: string, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
55
- sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<MultisigTransactionResponse>;
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<Signer | undefined>;
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;
@@ -8,7 +8,7 @@ declare enum ErrorType {
8
8
  UnknownError = "UnknownError",
9
9
  SlippageError = "SlippageError"
10
10
  }
11
- export declare enum LifiErrorCode {
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
- TransactionRejected = 1012,
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 = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode;
69
- export declare class LifiError extends Error {
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 LifiError {
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 LifiError {
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 LifiError {
81
+ export declare class ServerError extends LiFiError {
81
82
  constructor(message: string, htmlMessage?: string, stack?: string);
82
83
  }
83
- export declare class ValidationError extends LifiError {
84
+ export declare class ValidationError extends LiFiError {
84
85
  constructor(message: string, htmlMessage?: string, stack?: string);
85
86
  }
86
- export declare class TransactionError extends LifiError {
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 LifiError {
90
+ export declare class SlippageError extends LiFiError {
90
91
  constructor(message: string, htmlMessage?: string, stack?: string);
91
92
  }
92
- export declare class BalanceError extends LifiError {
93
+ export declare class BalanceError extends LiFiError {
93
94
  constructor(message: string, htmlMessage?: string, stack?: string);
94
95
  }
95
- export declare class NotFoundError extends LifiError {
96
+ export declare class NotFoundError extends LiFiError {
96
97
  constructor(message: string, htmlMessage?: string, stack?: string);
97
98
  }
98
- export declare class UnknownError extends LifiError {
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 {
@@ -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.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.ErrorMessage = exports.EthersErrorMessage = exports.EthersErrorType = exports.LifiErrorCode = void 0;
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 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["TransactionRejected"] = 1012] = "TransactionRejected";
30
- LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
31
- LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
32
- LifiErrorCode[LifiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
33
- })(LifiErrorCode || (exports.LifiErrorCode = LifiErrorCode = {}));
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 LifiError extends Error {
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, LifiError.prototype);
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.LifiError = LifiError;
94
- class RPCError extends LifiError {
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 LifiError {
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 LifiError {
107
+ class ServerError extends LiFiError {
107
108
  constructor(message, htmlMessage, stack) {
108
- super(ErrorType.ServerError, LifiErrorCode.InternalError, message, htmlMessage, stack);
109
+ super(ErrorType.ServerError, LiFiErrorCode.InternalError, message, htmlMessage, stack);
109
110
  }
110
111
  }
111
112
  exports.ServerError = ServerError;
112
- class ValidationError extends LifiError {
113
+ class ValidationError extends LiFiError {
113
114
  constructor(message, htmlMessage, stack) {
114
- super(ErrorType.ValidationError, LifiErrorCode.ValidationError, message, htmlMessage, stack);
115
+ super(ErrorType.ValidationError, LiFiErrorCode.ValidationError, message, htmlMessage, stack);
115
116
  }
116
117
  }
117
118
  exports.ValidationError = ValidationError;
118
- class TransactionError extends LifiError {
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 LifiError {
125
+ class SlippageError extends LiFiError {
125
126
  constructor(message, htmlMessage, stack) {
126
- super(ErrorType.SlippageError, LifiErrorCode.SlippageError, message, htmlMessage, stack);
127
+ super(ErrorType.SlippageError, LiFiErrorCode.SlippageError, message, htmlMessage, stack);
127
128
  }
128
129
  }
129
130
  exports.SlippageError = SlippageError;
130
- class BalanceError extends LifiError {
131
+ class BalanceError extends LiFiError {
131
132
  constructor(message, htmlMessage, stack) {
132
- super(ErrorType.ValidationError, LifiErrorCode.BalanceError, message, htmlMessage, stack);
133
+ super(ErrorType.ValidationError, LiFiErrorCode.BalanceError, message, htmlMessage, stack);
133
134
  }
134
135
  }
135
136
  exports.BalanceError = BalanceError;
136
- class NotFoundError extends LifiError {
137
+ class NotFoundError extends LiFiError {
137
138
  constructor(message, htmlMessage, stack) {
138
- super(ErrorType.NotFoundError, LifiErrorCode.NotFound, message, htmlMessage, stack);
139
+ super(ErrorType.NotFoundError, LiFiErrorCode.NotFound, message, htmlMessage, stack);
139
140
  }
140
141
  }
141
142
  exports.NotFoundError = NotFoundError;
142
- class UnknownError extends LifiError {
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,2 @@
1
+ import type { PublicClient } from 'viem';
2
+ export declare const getMaxPriorityFeePerGas: (client: PublicClient) => Promise<bigint | undefined>;
@@ -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,5 @@
1
+ export * from './errors';
2
+ export * from './getMaxPriorityFeePerGas';
3
+ export * from './median';
4
+ export * from './parseError';
5
+ export * from './utils';
@@ -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 { LifiError } from './errors';
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<LifiError>;
37
- export declare const parseBackendError: (e: any) => Promise<LifiError>;
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, utils_1.formatTokenAmountOnly)(step.action.fromToken, step.action.fromAmount)} ${step.action.fromToken.symbol} on ${chain.name})`;
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.LifiError) {
73
+ if (e instanceof errors_1.LiFiError) {
74
74
  return e;
75
75
  }
76
- if (e.code) {
77
- // MetaMask errors have a numeric error code
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('Signer is not defined.');
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.LifiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
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.LifiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
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.LifiErrorCode.InsufficientFunds, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
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.LifiErrorCode.TransactionRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
123
- case errors_1.LifiErrorCode.TransactionUnprepared:
124
- return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionUnprepared, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
125
- case errors_1.LifiErrorCode.ValidationError:
126
- return new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage);
127
- default:
128
- return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || errors_1.ErrorMessage.UnknownError, undefined, e.stack);
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
- import { TransactionReceipt } from '@ethersproject/providers';
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;