@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,313 +0,0 @@
1
- [
2
- {
3
- "inputs": [
4
- {
5
- "components": [
6
- {
7
- "internalType": "address",
8
- "name": "target",
9
- "type": "address"
10
- },
11
- {
12
- "internalType": "bytes",
13
- "name": "callData",
14
- "type": "bytes"
15
- }
16
- ],
17
- "internalType": "struct Multicall2.Call[]",
18
- "name": "calls",
19
- "type": "tuple[]"
20
- }
21
- ],
22
- "name": "aggregate",
23
- "outputs": [
24
- {
25
- "internalType": "uint256",
26
- "name": "blockNumber",
27
- "type": "uint256"
28
- },
29
- {
30
- "internalType": "bytes[]",
31
- "name": "returnData",
32
- "type": "bytes[]"
33
- }
34
- ],
35
- "stateMutability": "view",
36
- "type": "function"
37
- },
38
- {
39
- "inputs": [
40
- {
41
- "components": [
42
- {
43
- "internalType": "address",
44
- "name": "target",
45
- "type": "address"
46
- },
47
- {
48
- "internalType": "bytes",
49
- "name": "callData",
50
- "type": "bytes"
51
- }
52
- ],
53
- "internalType": "struct Multicall2.Call[]",
54
- "name": "calls",
55
- "type": "tuple[]"
56
- }
57
- ],
58
- "name": "blockAndAggregate",
59
- "outputs": [
60
- {
61
- "internalType": "uint256",
62
- "name": "blockNumber",
63
- "type": "uint256"
64
- },
65
- {
66
- "internalType": "bytes32",
67
- "name": "blockHash",
68
- "type": "bytes32"
69
- },
70
- {
71
- "components": [
72
- {
73
- "internalType": "bool",
74
- "name": "success",
75
- "type": "bool"
76
- },
77
- {
78
- "internalType": "bytes",
79
- "name": "returnData",
80
- "type": "bytes"
81
- }
82
- ],
83
- "internalType": "struct Multicall2.Result[]",
84
- "name": "returnData",
85
- "type": "tuple[]"
86
- }
87
- ],
88
- "stateMutability": "nonpayable",
89
- "type": "function"
90
- },
91
- {
92
- "inputs": [
93
- {
94
- "internalType": "uint256",
95
- "name": "blockNumber",
96
- "type": "uint256"
97
- }
98
- ],
99
- "name": "getBlockHash",
100
- "outputs": [
101
- {
102
- "internalType": "bytes32",
103
- "name": "blockHash",
104
- "type": "bytes32"
105
- }
106
- ],
107
- "stateMutability": "view",
108
- "type": "function"
109
- },
110
- {
111
- "inputs": [],
112
- "name": "getBlockNumber",
113
- "outputs": [
114
- {
115
- "internalType": "uint256",
116
- "name": "blockNumber",
117
- "type": "uint256"
118
- }
119
- ],
120
- "stateMutability": "view",
121
- "type": "function"
122
- },
123
- {
124
- "inputs": [],
125
- "name": "getCurrentBlockCoinbase",
126
- "outputs": [
127
- {
128
- "internalType": "address",
129
- "name": "coinbase",
130
- "type": "address"
131
- }
132
- ],
133
- "stateMutability": "view",
134
- "type": "function"
135
- },
136
- {
137
- "inputs": [],
138
- "name": "getCurrentBlockDifficulty",
139
- "outputs": [
140
- {
141
- "internalType": "uint256",
142
- "name": "difficulty",
143
- "type": "uint256"
144
- }
145
- ],
146
- "stateMutability": "view",
147
- "type": "function"
148
- },
149
- {
150
- "inputs": [],
151
- "name": "getCurrentBlockGasLimit",
152
- "outputs": [
153
- {
154
- "internalType": "uint256",
155
- "name": "gaslimit",
156
- "type": "uint256"
157
- }
158
- ],
159
- "stateMutability": "view",
160
- "type": "function"
161
- },
162
- {
163
- "inputs": [],
164
- "name": "getCurrentBlockTimestamp",
165
- "outputs": [
166
- {
167
- "internalType": "uint256",
168
- "name": "timestamp",
169
- "type": "uint256"
170
- }
171
- ],
172
- "stateMutability": "view",
173
- "type": "function"
174
- },
175
- {
176
- "inputs": [
177
- {
178
- "internalType": "address",
179
- "name": "addr",
180
- "type": "address"
181
- }
182
- ],
183
- "name": "getEthBalance",
184
- "outputs": [
185
- {
186
- "internalType": "uint256",
187
- "name": "balance",
188
- "type": "uint256"
189
- }
190
- ],
191
- "stateMutability": "view",
192
- "type": "function"
193
- },
194
- {
195
- "inputs": [],
196
- "name": "getLastBlockHash",
197
- "outputs": [
198
- {
199
- "internalType": "bytes32",
200
- "name": "blockHash",
201
- "type": "bytes32"
202
- }
203
- ],
204
- "stateMutability": "view",
205
- "type": "function"
206
- },
207
- {
208
- "inputs": [
209
- {
210
- "internalType": "bool",
211
- "name": "requireSuccess",
212
- "type": "bool"
213
- },
214
- {
215
- "components": [
216
- {
217
- "internalType": "address",
218
- "name": "target",
219
- "type": "address"
220
- },
221
- {
222
- "internalType": "bytes",
223
- "name": "callData",
224
- "type": "bytes"
225
- }
226
- ],
227
- "internalType": "struct Multicall2.Call[]",
228
- "name": "calls",
229
- "type": "tuple[]"
230
- }
231
- ],
232
- "name": "tryAggregate",
233
- "outputs": [
234
- {
235
- "components": [
236
- {
237
- "internalType": "bool",
238
- "name": "success",
239
- "type": "bool"
240
- },
241
- {
242
- "internalType": "bytes",
243
- "name": "returnData",
244
- "type": "bytes"
245
- }
246
- ],
247
- "internalType": "struct Multicall2.Result[]",
248
- "name": "returnData",
249
- "type": "tuple[]"
250
- }
251
- ],
252
- "stateMutability": "view",
253
- "type": "function"
254
- },
255
- {
256
- "inputs": [
257
- {
258
- "internalType": "bool",
259
- "name": "requireSuccess",
260
- "type": "bool"
261
- },
262
- {
263
- "components": [
264
- {
265
- "internalType": "address",
266
- "name": "target",
267
- "type": "address"
268
- },
269
- {
270
- "internalType": "bytes",
271
- "name": "callData",
272
- "type": "bytes"
273
- }
274
- ],
275
- "internalType": "struct Multicall2.Call[]",
276
- "name": "calls",
277
- "type": "tuple[]"
278
- }
279
- ],
280
- "name": "tryBlockAndAggregate",
281
- "outputs": [
282
- {
283
- "internalType": "uint256",
284
- "name": "blockNumber",
285
- "type": "uint256"
286
- },
287
- {
288
- "internalType": "bytes32",
289
- "name": "blockHash",
290
- "type": "bytes32"
291
- },
292
- {
293
- "components": [
294
- {
295
- "internalType": "bool",
296
- "name": "success",
297
- "type": "bool"
298
- },
299
- {
300
- "internalType": "bytes",
301
- "name": "returnData",
302
- "type": "bytes"
303
- }
304
- ],
305
- "internalType": "struct Multicall2.Result[]",
306
- "name": "returnData",
307
- "type": "tuple[]"
308
- }
309
- ],
310
- "stateMutability": "view",
311
- "type": "function"
312
- }
313
- ]
@@ -1,3 +0,0 @@
1
- import { Signer } from 'ethers';
2
- import { Route } from '../types';
3
- export declare const handlePreRestart: (route: Route, signer: Signer) => Promise<void>;
@@ -1,52 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { BigNumber } from 'ethers';
3
- import { LifiErrorCode } from './errors';
4
- export const handlePreRestart = async (route, signer) => {
5
- for (let index = 0; index < route.steps.length; index++) {
6
- const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
7
- if (stepHasFailed) {
8
- await handleErrorType(route, index, signer);
9
- deleteFailedProcesses(route, index);
10
- deleteTransactionData(route, index);
11
- }
12
- }
13
- };
14
- const handleErrorType = async (route, index, signer) => {
15
- const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.GasLimitError);
16
- const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.TransactionUnderpriced);
17
- const { transactionRequest } = route.steps[index];
18
- if (isGasLimitError) {
19
- if (transactionRequest) {
20
- let gasLimit = transactionRequest.gasLimit;
21
- try {
22
- gasLimit = await signer.estimateGas(transactionRequest);
23
- }
24
- catch (error) { }
25
- if (gasLimit) {
26
- transactionRequest.gasLimit = BigNumber.from(`${(BigInt(gasLimit.toString()) * 125n) / 100n}`);
27
- }
28
- }
29
- route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
30
- }
31
- if (isGasPriceError) {
32
- if (transactionRequest) {
33
- let gasPrice = transactionRequest.gasPrice;
34
- try {
35
- gasPrice = await signer.getGasPrice();
36
- }
37
- catch (error) { }
38
- if (gasPrice) {
39
- transactionRequest.gasPrice = BigNumber.from(`${(BigInt(gasPrice.toString()) * 125n) / 100n}`);
40
- }
41
- }
42
- route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
43
- }
44
- };
45
- const deleteFailedProcesses = (route, index) => {
46
- if (route.steps[index].execution) {
47
- route.steps[index].execution.process = route.steps[index].execution.process.filter((process) => process.status === 'DONE');
48
- }
49
- };
50
- const deleteTransactionData = (route, index) => {
51
- route.steps[index].transactionRequest = undefined;
52
- };