@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.
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 +2 -0
  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 -30
  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 +2 -0
  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 -30
  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 +28 -27
  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,24 +1,22 @@
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 { 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
- signer: Signer;
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
- multisigConfig?: MultisigConfig;
36
+ multisig?: MultisigConfig;
39
37
  };
40
38
  export interface MultisigTxDetails {
41
39
  status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
42
- txHash?: string;
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: string;
47
+ value?: bigint;
50
48
  data: string;
51
49
  }
52
50
  export interface MultisigConfig {
53
- isMultisigSigner?: boolean;
54
- getMultisigTransactionDetails?: (txHash: string, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
55
- sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<MultisigTransactionResponse>;
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<Signer | undefined>;
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 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 {
@@ -9,25 +9,26 @@ var ErrorType;
9
9
  ErrorType["UnknownError"] = "UnknownError";
10
10
  ErrorType["SlippageError"] = "SlippageError";
11
11
  })(ErrorType || (ErrorType = {}));
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["TransactionRejected"] = 1012] = "TransactionRejected";
27
- LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
28
- LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
29
- LifiErrorCode[LifiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
30
- })(LifiErrorCode || (LifiErrorCode = {}));
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 LifiError extends Error {
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, LifiError.prototype);
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 LifiError {
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 LifiError {
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 LifiError {
101
+ export class ServerError extends LiFiError {
101
102
  constructor(message, htmlMessage, stack) {
102
- super(ErrorType.ServerError, LifiErrorCode.InternalError, message, htmlMessage, stack);
103
+ super(ErrorType.ServerError, LiFiErrorCode.InternalError, message, htmlMessage, stack);
103
104
  }
104
105
  }
105
- export class ValidationError extends LifiError {
106
+ export class ValidationError extends LiFiError {
106
107
  constructor(message, htmlMessage, stack) {
107
- super(ErrorType.ValidationError, LifiErrorCode.ValidationError, message, htmlMessage, stack);
108
+ super(ErrorType.ValidationError, LiFiErrorCode.ValidationError, message, htmlMessage, stack);
108
109
  }
109
110
  }
110
- export class TransactionError extends LifiError {
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 LifiError {
116
+ export class SlippageError extends LiFiError {
116
117
  constructor(message, htmlMessage, stack) {
117
- super(ErrorType.SlippageError, LifiErrorCode.SlippageError, message, htmlMessage, stack);
118
+ super(ErrorType.SlippageError, LiFiErrorCode.SlippageError, message, htmlMessage, stack);
118
119
  }
119
120
  }
120
- export class BalanceError extends LifiError {
121
+ export class BalanceError extends LiFiError {
121
122
  constructor(message, htmlMessage, stack) {
122
- super(ErrorType.ValidationError, LifiErrorCode.BalanceError, message, htmlMessage, stack);
123
+ super(ErrorType.ValidationError, LiFiErrorCode.BalanceError, message, htmlMessage, stack);
123
124
  }
124
125
  }
125
- export class NotFoundError extends LifiError {
126
+ export class NotFoundError extends LiFiError {
126
127
  constructor(message, htmlMessage, stack) {
127
- super(ErrorType.NotFoundError, LifiErrorCode.NotFound, message, htmlMessage, stack);
128
+ super(ErrorType.NotFoundError, LiFiErrorCode.NotFound, message, htmlMessage, stack);
128
129
  }
129
130
  }
130
- export class UnknownError extends LifiError {
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,2 @@
1
+ import type { PublicClient } from 'viem';
2
+ export declare const getMaxPriorityFeePerGas: (client: PublicClient) => Promise<bigint | undefined>;
@@ -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,5 @@
1
+ export * from './errors';
2
+ export * from './getMaxPriorityFeePerGas';
3
+ export * from './median';
4
+ export * from './parseError';
5
+ export * from './utils';
@@ -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 @@
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 { 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>;
@@ -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, LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
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 += ` (${formatTokenAmountOnly(step.action.fromToken, step.action.fromAmount)} ${step.action.fromToken.symbol} on ${chain.name})`;
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 LifiError) {
65
+ if (e instanceof LiFiError) {
66
66
  return e;
67
67
  }
68
- if (e.code) {
69
- // MetaMask errors have a numeric error code
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('Signer is not defined.');
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(LifiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
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(LifiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
86
+ return new ProviderError(LiFiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
109
87
  }
110
88
  case EthersErrorType.InsufficientFunds:
111
- return new TransactionError(LifiErrorCode.InsufficientFunds, e.message, await getTransactionNotSentMessage(step, process), e.stack);
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(LifiErrorCode.TransactionRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
115
- case LifiErrorCode.TransactionUnprepared:
116
- return new TransactionError(LifiErrorCode.TransactionUnprepared, e.message, await getTransactionNotSentMessage(step, process), e.stack);
117
- case LifiErrorCode.ValidationError:
118
- return new TransactionError(LifiErrorCode.ValidationError, e.message, e.htmlMessage);
119
- default:
120
- return new UnknownError(LifiErrorCode.InternalError, e.message || ErrorMessage.UnknownError, undefined, e.stack);
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) => {
@@ -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;
@@ -1,59 +1,9 @@
1
- import BigNumber from 'bignumber.js';
2
- import { constants } from 'ethers';
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, mills);
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 sleep(timeout);
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 === constants.AddressZero ||
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 === constants.AddressZero ||
93
- address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
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.2.2";
2
+ export declare const version = "3.0.0-alpha.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk';
2
- export const version = '2.2.2';
2
+ export const version = '3.0.0-alpha.1';