@lifi/sdk 1.7.2 → 2.0.0-beta.0

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 (76) hide show
  1. package/dist/Lifi.js +97 -85
  2. package/dist/allowance/checkAllowance.js +12 -21
  3. package/dist/allowance/tokenApproval.js +20 -29
  4. package/dist/allowance/utils.js +12 -24
  5. package/dist/balance/checkBalance.js +5 -14
  6. package/dist/balance/getTokenBalance.js +12 -21
  7. package/dist/balance/index.d.ts +11 -0
  8. package/dist/balance/index.js +8 -0
  9. package/dist/balance/utils.d.ts +1 -0
  10. package/dist/balance/utils.js +36 -38
  11. package/dist/cjs/Lifi.js +97 -85
  12. package/dist/cjs/allowance/checkAllowance.js +12 -21
  13. package/dist/cjs/allowance/tokenApproval.js +20 -29
  14. package/dist/cjs/allowance/utils.js +12 -24
  15. package/dist/cjs/balance/checkBalance.js +5 -14
  16. package/dist/cjs/balance/getTokenBalance.js +12 -21
  17. package/dist/cjs/balance/index.d.ts +11 -0
  18. package/dist/cjs/balance/index.js +8 -0
  19. package/dist/cjs/balance/utils.d.ts +1 -0
  20. package/dist/cjs/balance/utils.js +39 -39
  21. package/dist/cjs/connectors.js +17 -25
  22. package/dist/cjs/execution/ExecutionManager.js +27 -33
  23. package/dist/cjs/execution/StatusManager.js +13 -13
  24. package/dist/cjs/execution/StepExecutor.js +8 -14
  25. package/dist/cjs/execution/stepComparison.js +4 -14
  26. package/dist/cjs/execution/switchChain.js +5 -14
  27. package/dist/cjs/execution/utils.js +43 -50
  28. package/dist/cjs/helpers.d.ts +12 -1
  29. package/dist/cjs/helpers.js +68 -19
  30. package/dist/cjs/services/ApiService.d.ts +10 -9
  31. package/dist/cjs/services/ApiService.js +190 -152
  32. package/dist/cjs/services/ApiService.unit.handlers.d.ts +1 -0
  33. package/dist/cjs/services/ApiService.unit.handlers.js +50 -0
  34. package/dist/cjs/services/ChainsService.js +16 -31
  35. package/dist/cjs/services/ConfigService.js +6 -16
  36. package/dist/cjs/typeguards.js +1 -1
  37. package/dist/cjs/types/internal.types.d.ts +4 -1
  38. package/dist/cjs/utils/errors.d.ts +5 -0
  39. package/dist/cjs/utils/errors.js +14 -1
  40. package/dist/cjs/utils/multicall.js +6 -15
  41. package/dist/cjs/utils/parseError.d.ts +2 -2
  42. package/dist/cjs/utils/parseError.js +36 -38
  43. package/dist/cjs/utils/preRestart.js +5 -7
  44. package/dist/cjs/utils/utils.d.ts +0 -1
  45. package/dist/cjs/utils/utils.js +21 -28
  46. package/dist/cjs/version.d.ts +1 -1
  47. package/dist/cjs/version.js +1 -1
  48. package/dist/connectors.js +15 -23
  49. package/dist/execution/ExecutionManager.js +27 -33
  50. package/dist/execution/StatusManager.js +11 -11
  51. package/dist/execution/StepExecutor.js +8 -14
  52. package/dist/execution/stepComparison.js +4 -14
  53. package/dist/execution/switchChain.js +5 -14
  54. package/dist/execution/utils.js +43 -50
  55. package/dist/helpers.d.ts +12 -1
  56. package/dist/helpers.js +65 -18
  57. package/dist/services/ApiService.d.ts +10 -9
  58. package/dist/services/ApiService.js +190 -152
  59. package/dist/services/ApiService.unit.handlers.d.ts +1 -0
  60. package/dist/services/ApiService.unit.handlers.js +44 -0
  61. package/dist/services/ChainsService.js +16 -31
  62. package/dist/services/ConfigService.js +6 -16
  63. package/dist/typeguards.js +1 -1
  64. package/dist/types/internal.types.d.ts +4 -1
  65. package/dist/utils/errors.d.ts +5 -0
  66. package/dist/utils/errors.js +12 -0
  67. package/dist/utils/multicall.js +6 -15
  68. package/dist/utils/parseError.d.ts +2 -2
  69. package/dist/utils/parseError.js +36 -38
  70. package/dist/utils/preRestart.js +5 -7
  71. package/dist/utils/utils.d.ts +0 -1
  72. package/dist/utils/utils.js +20 -26
  73. package/dist/version.d.ts +1 -1
  74. package/dist/version.js +1 -1
  75. package/package.json +22 -24
  76. package/CHANGELOG.md +0 -492
package/dist/cjs/Lifi.js CHANGED
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -47,7 +38,6 @@ const ConfigService_1 = __importDefault(require("./services/ConfigService"));
47
38
  const typeguards_1 = require("./typeguards");
48
39
  const errors_1 = require("./utils/errors");
49
40
  const preRestart_1 = require("./utils/preRestart");
50
- const utils_1 = require("./utils/utils");
51
41
  const version_1 = require("./version");
52
42
  class LIFI {
53
43
  constructor(configUpdate) {
@@ -89,84 +79,84 @@ class LIFI {
89
79
  * @return {Promise<PossibilitiesResponse>} Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
90
80
  * @throws {LifiError} Throws a LifiError if request fails.
91
81
  */
92
- this.getPossibilities = (request, options) => __awaiter(this, void 0, void 0, function* () {
82
+ this.getPossibilities = async (request, options) => {
93
83
  return ApiService_1.default.getPossibilities(request, options);
94
- });
84
+ };
95
85
  /**
96
86
  * Fetch information about a Token
97
87
  * @param {ChainKey | ChainId} chain - Id or key of the chain that contains the token
98
88
  * @param {string} token - Address or symbol of the token on the requested chain
99
89
  * @throws {LifiError} - Throws a LifiError if request fails
100
90
  */
101
- this.getToken = (chain, token, options) => __awaiter(this, void 0, void 0, function* () {
91
+ this.getToken = async (chain, token, options) => {
102
92
  return ApiService_1.default.getToken(chain, token, options);
103
- });
93
+ };
104
94
  /**
105
95
  * Get a quote for a token transfer
106
96
  * @param {QuoteRequest} request - The configuration of the requested quote
107
97
  * @throws {LifiError} - Throws a LifiError if request fails
108
98
  */
109
- this.getQuote = (request, options) => __awaiter(this, void 0, void 0, function* () {
99
+ this.getQuote = async (request, options) => {
110
100
  return ApiService_1.default.getQuote(request, options);
111
- });
101
+ };
112
102
  /**
113
103
  * Get a quote for a destination contract call
114
104
  * @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
115
105
  * @throws {LifiError} - Throws a LifiError if request fails
116
106
  */
117
- this.getContractCallQuote = (request, options) => __awaiter(this, void 0, void 0, function* () {
107
+ this.getContractCallQuote = async (request, options) => {
118
108
  return ApiService_1.default.getContractCallQuote(request, options);
119
- });
109
+ };
120
110
  /**
121
111
  * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
122
112
  * @param {GetStatusRequest} request - Configuration of the requested status
123
113
  * @throws {LifiError} - Throws a LifiError if request fails
124
114
  */
125
- this.getStatus = (request, options) => __awaiter(this, void 0, void 0, function* () {
115
+ this.getStatus = async (request, options) => {
126
116
  return ApiService_1.default.getStatus(request, options);
127
- });
117
+ };
128
118
  /**
129
119
  * Get the available tools to bridge and swap tokens.
130
120
  * @param {ToolsRequest?} request - The configuration of the requested tools
131
121
  * @returns The tools that are available on the requested chains
132
122
  */
133
- this.getTools = (request, options) => __awaiter(this, void 0, void 0, function* () {
123
+ this.getTools = async (request, options) => {
134
124
  return ApiService_1.default.getTools(request || {}, options);
135
- });
125
+ };
136
126
  /**
137
127
  * Get all known tokens.
138
128
  * @param {TokensRequest?} request - The configuration of the requested tokens
139
129
  * @returns The tokens that are available on the requested chains
140
130
  */
141
- this.getTokens = (request, options) => __awaiter(this, void 0, void 0, function* () {
131
+ this.getTokens = async (request, options) => {
142
132
  return ApiService_1.default.getTokens(request || {}, options);
143
- });
133
+ };
144
134
  /**
145
135
  * Get all available chains
146
136
  * @return {Promise<Chain[]>} A list of all available chains
147
137
  * @throws {LifiError} Throws a LifiError if request fails.
148
138
  */
149
- this.getChains = () => __awaiter(this, void 0, void 0, function* () {
139
+ this.getChains = async () => {
150
140
  return this.chainsService.getChains();
151
- });
141
+ };
152
142
  /**
153
143
  * Get a set of routes for a request that describes a transfer of tokens.
154
144
  * @param {RoutesRequest} routesRequest - A description of the transfer.
155
145
  * @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
156
146
  * @throws {LifiError} Throws a LifiError if request fails.
157
147
  */
158
- this.getRoutes = (request, options) => __awaiter(this, void 0, void 0, function* () {
148
+ this.getRoutes = async (request, options) => {
159
149
  return ApiService_1.default.getRoutes(request, options);
160
- });
150
+ };
161
151
  /**
162
152
  * Get the transaction data for a single step of a route
163
153
  * @param {Step} step - The step object.
164
154
  * @return {Promise<Step>} The step populated with the transaction data.
165
155
  * @throws {LifiError} Throws a LifiError if request fails.
166
156
  */
167
- this.getStepTransaction = (step, options) => __awaiter(this, void 0, void 0, function* () {
157
+ this.getStepTransaction = async (step, options) => {
168
158
  return ApiService_1.default.getStepTransaction(step, options);
169
- });
159
+ };
170
160
  /**
171
161
  * Stops the execution of an active route.
172
162
  * @param {Route} route - A route that is currently in execution.
@@ -176,7 +166,8 @@ class LIFI {
176
166
  if (!this.activeRouteDictionary[route.id]) {
177
167
  return route;
178
168
  }
179
- for (const executor of this.activeRouteDictionary[route.id].executors) {
169
+ const { executionData } = this.activeRouteDictionary[route.id];
170
+ for (const executor of executionData.executors) {
180
171
  executor.setInteraction({
181
172
  allowInteraction: false,
182
173
  allowUpdates: false,
@@ -192,14 +183,17 @@ class LIFI {
192
183
  * @deprecated use updateRouteExecution instead.
193
184
  */
194
185
  this.moveExecutionToBackground = (route) => {
195
- const activeRoute = this.activeRouteDictionary[route.id];
196
- if (!activeRoute) {
186
+ const { executionData } = this.activeRouteDictionary[route.id];
187
+ if (!executionData) {
197
188
  return;
198
189
  }
199
- for (const executor of activeRoute.executors) {
190
+ for (const executor of executionData.executors) {
200
191
  executor.setInteraction({ allowInteraction: false, allowUpdates: true });
201
192
  }
202
- activeRoute.settings = Object.assign(Object.assign({}, activeRoute.settings), { executeInBackground: true });
193
+ executionData.settings = {
194
+ ...executionData.settings,
195
+ executeInBackground: true,
196
+ };
203
197
  };
204
198
  /**
205
199
  * Updates route execution to background or foreground state.
@@ -207,18 +201,21 @@ class LIFI {
207
201
  * @param {boolean} settings - An object with execution settings.
208
202
  */
209
203
  this.updateRouteExecution = (route, settings) => {
210
- const activeRoute = this.activeRouteDictionary[route.id];
211
- if (!activeRoute) {
204
+ const { executionData } = this.activeRouteDictionary[route.id];
205
+ if (!executionData) {
212
206
  return;
213
207
  }
214
- for (const executor of activeRoute.executors) {
208
+ for (const executor of executionData.executors) {
215
209
  executor.setInteraction({
216
210
  allowInteraction: !settings.executeInBackground,
217
211
  allowUpdates: true,
218
212
  });
219
213
  }
220
214
  // Update active route settings so we know what the current state of execution is
221
- activeRoute.settings = Object.assign(Object.assign({}, activeRoute.settings), settings);
215
+ executionData.settings = {
216
+ ...executionData.settings,
217
+ ...settings,
218
+ };
222
219
  };
223
220
  /**
224
221
  * Execute a route.
@@ -228,16 +225,21 @@ class LIFI {
228
225
  * @return {Promise<Route>} The executed route.
229
226
  * @throws {LifiError} Throws a LifiError if the execution fails.
230
227
  */
231
- this.executeRoute = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
228
+ this.executeRoute = async (signer, route, settings) => {
232
229
  // Deep clone to prevent side effects
233
- const clonedRoute = (0, utils_1.deepClone)(route);
230
+ const clonedRoute = structuredClone(route);
234
231
  // Check if route is already running
235
232
  if (this.activeRouteDictionary[clonedRoute.id]) {
236
233
  // TODO: maybe inform user why nothing happens?
237
- return clonedRoute;
234
+ return this.activeRouteDictionary[clonedRoute.id].executionPromise;
238
235
  }
239
- return this.executeSteps(signer, clonedRoute, settings);
240
- });
236
+ const executionPromise = this.executeSteps(signer, clonedRoute, settings);
237
+ this.activeRouteDictionary[clonedRoute.id] = {
238
+ ...this.activeRouteDictionary[clonedRoute.id],
239
+ executionPromise,
240
+ };
241
+ return executionPromise;
242
+ };
241
243
  /**
242
244
  * Resume the execution of a route that has been stopped or had an error while executing.
243
245
  * @param {Signer} signer - The signer required to send the transactions.
@@ -246,62 +248,70 @@ class LIFI {
246
248
  * @return {Promise<Route>} The executed route.
247
249
  * @throws {LifiError} Throws a LifiError if the execution fails.
248
250
  */
249
- this.resumeRoute = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
251
+ this.resumeRoute = async (signer, route, settings) => {
250
252
  // Deep clone to prevent side effects
251
- const clonedRoute = (0, utils_1.deepClone)(route);
252
- const activeRoute = this.activeRouteDictionary[clonedRoute.id];
253
- if (activeRoute) {
254
- const executionHalted = activeRoute.executors.some((executor) => executor.executionStopped);
253
+ const clonedRoute = structuredClone(route);
254
+ const { executionData, executionPromise } = this.activeRouteDictionary[clonedRoute.id];
255
+ if (executionData) {
256
+ const executionHalted = executionData.executors.some((executor) => executor.executionStopped);
255
257
  if (!executionHalted) {
256
258
  // Check if we want to resume route execution in the background
257
259
  this.updateRouteExecution(route, {
258
- executeInBackground: settings === null || settings === void 0 ? void 0 : settings.executeInBackground,
260
+ executeInBackground: settings?.executeInBackground,
259
261
  });
260
- return clonedRoute;
262
+ return executionPromise;
261
263
  }
262
264
  }
263
265
  (0, preRestart_1.handlePreRestart)(clonedRoute);
264
- return this.executeSteps(signer, clonedRoute, settings);
265
- });
266
- this.executeSteps = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
267
- var _a, _b, _c;
266
+ const newExecutionPromise = this.executeSteps(signer, clonedRoute, settings);
267
+ this.activeRouteDictionary[clonedRoute.id] = {
268
+ ...this.activeRouteDictionary[clonedRoute.id],
269
+ executionPromise: newExecutionPromise,
270
+ };
271
+ return newExecutionPromise;
272
+ };
273
+ this.executeSteps = async (signer, route, settings) => {
268
274
  const config = this.configService.getConfig();
269
- const executionData = {
275
+ const updatedExecutionData = {
270
276
  route,
271
277
  executors: [],
272
- settings: Object.assign(Object.assign({}, config.defaultExecutionSettings), settings),
278
+ settings: { ...config.defaultExecutionSettings, ...settings },
279
+ };
280
+ this.activeRouteDictionary[route.id].executionData = {
281
+ ...updatedExecutionData,
273
282
  };
274
- this.activeRouteDictionary[route.id] = executionData;
275
- const statusManager = new StatusManager_1.StatusManager(route, this.activeRouteDictionary[route.id].settings, (route) => {
283
+ const { executionData } = this.activeRouteDictionary[route.id];
284
+ const statusManager = new StatusManager_1.StatusManager(route, executionData.settings, (route) => {
276
285
  if (this.activeRouteDictionary[route.id]) {
277
- this.activeRouteDictionary[route.id].route = route;
286
+ executionData.route = route;
278
287
  }
279
288
  });
280
289
  // Loop over steps and execute them
281
290
  for (let index = 0; index < route.steps.length; index++) {
282
- const activeRoute = this.activeRouteDictionary[route.id];
291
+ const { executionData } = this.activeRouteDictionary[route.id];
283
292
  // Check if execution has stopped in the meantime
284
- if (!activeRoute) {
293
+ if (!executionData) {
285
294
  break;
286
295
  }
287
296
  const step = route.steps[index];
288
297
  const previousStep = route.steps[index - 1];
289
298
  // Check if the step is already done
290
- if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE') {
299
+ //
300
+ if (step.execution?.status === 'DONE') {
291
301
  continue;
292
302
  }
293
303
  // Update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
294
- if ((_b = previousStep === null || previousStep === void 0 ? void 0 : previousStep.execution) === null || _b === void 0 ? void 0 : _b.toAmount) {
304
+ if (previousStep?.execution?.toAmount) {
295
305
  step.action.fromAmount = previousStep.execution.toAmount;
296
306
  }
297
307
  try {
298
- const stepExecutor = new StepExecutor_1.StepExecutor(statusManager, activeRoute.settings);
299
- activeRoute.executors.push(stepExecutor);
308
+ const stepExecutor = new StepExecutor_1.StepExecutor(statusManager, executionData.settings);
309
+ executionData.executors.push(stepExecutor);
300
310
  // Check if we want to execute this step in the background
301
- this.updateRouteExecution(route, activeRoute.settings);
302
- const executedStep = yield stepExecutor.executeStep(signer, step);
311
+ this.updateRouteExecution(route, executionData.settings);
312
+ const executedStep = await stepExecutor.executeStep(signer, step);
303
313
  // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
304
- if (((_c = executedStep.execution) === null || _c === void 0 ? void 0 : _c.status) !== 'DONE') {
314
+ if (executedStep.execution?.status !== 'DONE') {
305
315
  this.stopExecution(route);
306
316
  }
307
317
  // Execution stopped during the current step, we don't want to continue to the next step so we return already
@@ -317,7 +327,7 @@ class LIFI {
317
327
  // Clean up after the execution
318
328
  delete this.activeRouteDictionary[route.id];
319
329
  return route;
320
- });
330
+ };
321
331
  /**
322
332
  * Update the ExecutionSettings for an active route.
323
333
  * @param {ExecutionSettings} settings - An object with execution settings.
@@ -329,14 +339,17 @@ class LIFI {
329
339
  throw new errors_1.ValidationError("Can't set ExecutionSettings for the inactive route.");
330
340
  }
331
341
  const config = this.configService.getConfig();
332
- this.activeRouteDictionary[route.id].settings = Object.assign(Object.assign({}, config.defaultExecutionSettings), settings);
342
+ this.activeRouteDictionary[route.id].executionData.settings = {
343
+ ...config.defaultExecutionSettings,
344
+ ...settings,
345
+ };
333
346
  };
334
347
  /**
335
348
  * Get the list of active routes.
336
349
  * @return {Route[]} A list of routes.
337
350
  */
338
351
  this.getActiveRoutes = () => {
339
- return Object.values(this.activeRouteDictionary).map((dict) => dict.route);
352
+ return Object.values(this.activeRouteDictionary).map((dict) => dict.executionData.route);
340
353
  };
341
354
  /**
342
355
  * Return the current route information for given route. The route has to be active.
@@ -344,8 +357,7 @@ class LIFI {
344
357
  * @return {Route} The updated route.
345
358
  */
346
359
  this.getActiveRoute = (route) => {
347
- var _a;
348
- return (_a = this.activeRouteDictionary[route.id]) === null || _a === void 0 ? void 0 : _a.route;
360
+ return this.activeRouteDictionary[route.id]?.executionData.route;
349
361
  };
350
362
  /**
351
363
  * Returns the balances of a specific token a wallet holds across all aggregated chains.
@@ -354,7 +366,7 @@ class LIFI {
354
366
  * @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
355
367
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
356
368
  */
357
- this.getTokenBalance = (walletAddress, token) => __awaiter(this, void 0, void 0, function* () {
369
+ this.getTokenBalance = async (walletAddress, token) => {
358
370
  if (!walletAddress) {
359
371
  throw new errors_1.ValidationError('Missing walletAddress.');
360
372
  }
@@ -362,7 +374,7 @@ class LIFI {
362
374
  throw new errors_1.ValidationError(`Invalid token passed: address "${token.address}" on chainId "${token.chainId}"`);
363
375
  }
364
376
  return balance.getTokenBalance(walletAddress, token);
365
- });
377
+ };
366
378
  /**
367
379
  * Returns the balances for a list tokens a wallet holds across all aggregated chains.
368
380
  * @param {string} walletAddress - A wallet address.
@@ -370,7 +382,7 @@ class LIFI {
370
382
  * @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
371
383
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
372
384
  */
373
- this.getTokenBalances = (walletAddress, tokens) => __awaiter(this, void 0, void 0, function* () {
385
+ this.getTokenBalances = async (walletAddress, tokens) => {
374
386
  if (!walletAddress) {
375
387
  throw new errors_1.ValidationError('Missing walletAddress.');
376
388
  }
@@ -379,7 +391,7 @@ class LIFI {
379
391
  throw new errors_1.ValidationError(`Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`);
380
392
  }
381
393
  return balance.getTokenBalances(walletAddress, tokens);
382
- });
394
+ };
383
395
  /**
384
396
  * This method queries the balances of tokens for a specific list of chains for a given wallet.
385
397
  * @param {string} walletAddress - A walletaddress.
@@ -387,7 +399,7 @@ class LIFI {
387
399
  * @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
388
400
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
389
401
  */
390
- this.getTokenBalancesForChains = (walletAddress, tokensByChain) => __awaiter(this, void 0, void 0, function* () {
402
+ this.getTokenBalancesForChains = async (walletAddress, tokensByChain) => {
391
403
  if (!walletAddress) {
392
404
  throw new errors_1.ValidationError('Missing walletAddress.');
393
405
  }
@@ -397,24 +409,24 @@ class LIFI {
397
409
  throw new errors_1.ValidationError(`Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`);
398
410
  }
399
411
  return balance.getTokenBalancesForChains(walletAddress, tokensByChain);
400
- });
412
+ };
401
413
  /**
402
414
  * Get the current approval for a certain token.
403
415
  * @param signer - The signer owning the token
404
416
  * @param token - The token that should be checked
405
417
  * @param approvalAddress - The address that has be approved
406
418
  */
407
- this.getTokenApproval = (signer, token, approvalAddress) => __awaiter(this, void 0, void 0, function* () {
419
+ this.getTokenApproval = async (signer, token, approvalAddress) => {
408
420
  return (0, allowance_1.getTokenApproval)(signer, token, approvalAddress);
409
- });
421
+ };
410
422
  /**
411
423
  * Get the current approval for a list of token / approval address pairs.
412
424
  * @param signer - The signer owning the tokens
413
425
  * @param tokenData - A list of token and approval address pairs
414
426
  */
415
- this.bulkGetTokenApproval = (signer, tokenData) => __awaiter(this, void 0, void 0, function* () {
427
+ this.bulkGetTokenApproval = async (signer, tokenData) => {
416
428
  return (0, allowance_1.bulkGetTokenApproval)(signer, tokenData);
417
- });
429
+ };
418
430
  /**
419
431
  * Set approval for a certain token and amount.
420
432
  * @param { ApproveTokenRequest } request - The approval request
@@ -438,7 +450,7 @@ class LIFI {
438
450
  this.chainsService.getChains().then((chains) => {
439
451
  this.configService.updateChains(chains);
440
452
  });
441
- (0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate === null || configUpdate === void 0 ? void 0 : configUpdate.disableVersionCheck);
453
+ (0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate?.disableVersionCheck);
442
454
  }
443
455
  }
444
456
  exports.default = LIFI;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,7 +10,7 @@ const ethers_1 = require("ethers");
19
10
  const utils_1 = require("../allowance/utils");
20
11
  const getProvider_1 = require("../utils/getProvider");
21
12
  const parseError_1 = require("../utils/parseError");
22
- const checkAllowance = (signer, step, statusManager, settings, chain, allowUserInteraction = false) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const checkAllowance = async (signer, step, statusManager, settings, chain, allowUserInteraction = false) => {
23
14
  // Ask the user to set an allowance
24
15
  let allowanceProcess = statusManager.findOrCreateProcess(step, 'TOKEN_ALLOWANCE');
25
16
  // Check allowance
@@ -28,11 +19,11 @@ const checkAllowance = (signer, step, statusManager, settings, chain, allowUserI
28
19
  if (allowanceProcess.status !== 'PENDING') {
29
20
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING');
30
21
  }
31
- yield (0, getProvider_1.getProvider)(signer).waitForTransaction(allowanceProcess.txHash);
22
+ await (0, getProvider_1.getProvider)(signer).waitForTransaction(allowanceProcess.txHash);
32
23
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
33
24
  }
34
25
  else {
35
- const approved = yield (0, utils_1.getApproved)(signer, step.action.fromToken.address, step.estimate.approvalAddress);
26
+ const approved = await (0, utils_1.getApproved)(signer, step.action.fromToken.address, step.estimate.approvalAddress);
36
27
  if (new bignumber_js_1.default(step.action.fromAmount).gt(approved)) {
37
28
  if (!allowUserInteraction) {
38
29
  return;
@@ -40,13 +31,13 @@ const checkAllowance = (signer, step, statusManager, settings, chain, allowUserI
40
31
  const approvalAmount = settings.infiniteApproval
41
32
  ? ethers_1.constants.MaxUint256.toString()
42
33
  : step.action.fromAmount;
43
- const approveTx = yield (0, utils_1.setApproval)(signer, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount);
34
+ const approveTx = await (0, utils_1.setApproval)(signer, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount);
44
35
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
45
36
  txHash: approveTx.hash,
46
37
  txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + approveTx.hash,
47
38
  });
48
39
  // Wait for the transcation
49
- yield approveTx.wait();
40
+ await approveTx.wait();
50
41
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
51
42
  }
52
43
  else {
@@ -56,10 +47,10 @@ const checkAllowance = (signer, step, statusManager, settings, chain, allowUserI
56
47
  }
57
48
  catch (e) {
58
49
  if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
59
- yield transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
50
+ await transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
60
51
  }
61
52
  else {
62
- const error = yield (0, parseError_1.parseError)(e, step, allowanceProcess);
53
+ const error = await (0, parseError_1.parseError)(e, step, allowanceProcess);
63
54
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
64
55
  error: {
65
56
  message: error.message,
@@ -71,21 +62,21 @@ const checkAllowance = (signer, step, statusManager, settings, chain, allowUserI
71
62
  throw error;
72
63
  }
73
64
  }
74
- });
65
+ };
75
66
  exports.checkAllowance = checkAllowance;
76
- const transactionReplaced = (replacementTx, allowanceProcess, step, chain, statusManager) => __awaiter(void 0, void 0, void 0, function* () {
67
+ const transactionReplaced = async (replacementTx, allowanceProcess, step, chain, statusManager) => {
77
68
  try {
78
69
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
79
70
  txHash: replacementTx.hash,
80
71
  txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + replacementTx.hash,
81
72
  });
82
- yield replacementTx.wait();
73
+ await replacementTx.wait();
83
74
  allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
84
75
  }
85
76
  catch (e) {
86
77
  if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
87
- yield transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
78
+ await transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
88
79
  }
89
80
  throw e;
90
81
  }
91
- });
82
+ };
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -18,26 +9,26 @@ const ethers_1 = require("ethers");
18
9
  const helpers_1 = require("../helpers");
19
10
  const utils_1 = require("../utils/utils");
20
11
  const utils_2 = require("./utils");
21
- const getTokenApproval = (signer, token, approvalAddress) => __awaiter(void 0, void 0, void 0, function* () {
12
+ const getTokenApproval = async (signer, token, approvalAddress) => {
22
13
  // native token don't need approval
23
14
  if ((0, utils_1.isNativeTokenAddress)(token.address)) {
24
15
  return;
25
16
  }
26
- const approved = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress);
27
- return approved.toString();
28
- });
17
+ const approved = await (0, utils_2.getApproved)(signer, token.address, approvalAddress);
18
+ return approved.toFixed(0);
19
+ };
29
20
  exports.getTokenApproval = getTokenApproval;
30
- const bulkGetTokenApproval = (signer, tokenData) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const bulkGetTokenApproval = async (signer, tokenData) => {
31
22
  // filter out native tokens
32
23
  const filteredTokenData = tokenData.filter(({ token }) => !(0, utils_1.isNativeTokenAddress)(token.address));
33
24
  // group by chain
34
25
  const tokenDataByChain = (0, utils_2.groupByChain)(filteredTokenData);
35
- const approvalPromises = Object.keys(tokenDataByChain).map((chainId) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const approvalPromises = Object.keys(tokenDataByChain).map(async (chainId) => {
36
27
  const parsedChainId = Number.parseInt(chainId);
37
28
  // get allowances for current chain and token list
38
29
  return (0, utils_2.getAllowanceViaMulticall)(signer, parsedChainId, tokenDataByChain[parsedChainId]);
39
- }));
40
- const approvalsByChain = yield Promise.all(approvalPromises);
30
+ });
31
+ const approvalsByChain = await Promise.all(approvalPromises);
41
32
  const approvals = approvalsByChain.flat();
42
33
  return tokenData.map(({ token }) => {
43
34
  // native token don't need approval
@@ -45,34 +36,34 @@ const bulkGetTokenApproval = (signer, tokenData) => __awaiter(void 0, void 0, vo
45
36
  return { token, approval: undefined };
46
37
  }
47
38
  const approved = approvals.find((approval) => (0, helpers_1.isSameToken)(approval.token, token));
48
- return { token, approval: approved === null || approved === void 0 ? void 0 : approved.approvedAmount.toString() };
39
+ return { token, approval: approved?.approvedAmount.toString() };
49
40
  });
50
- });
41
+ };
51
42
  exports.bulkGetTokenApproval = bulkGetTokenApproval;
52
- const approveToken = ({ signer, token, approvalAddress, amount, infiniteApproval = false, }) => __awaiter(void 0, void 0, void 0, function* () {
43
+ const approveToken = async ({ signer, token, approvalAddress, amount, infiniteApproval = false, }) => {
53
44
  // native token don't need approval
54
45
  if ((0, utils_1.isNativeTokenAddress)(token.address)) {
55
46
  return;
56
47
  }
57
- const approvedAmount = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress);
48
+ const approvedAmount = await (0, utils_2.getApproved)(signer, token.address, approvalAddress);
58
49
  if (new bignumber_js_1.default(amount).gt(approvedAmount)) {
59
50
  const approvalAmount = infiniteApproval
60
51
  ? ethers_1.constants.MaxUint256.toString()
61
52
  : amount;
62
- const approveTx = yield (0, utils_2.setApproval)(signer, token.address, approvalAddress, approvalAmount);
63
- yield approveTx.wait();
53
+ const approveTx = await (0, utils_2.setApproval)(signer, token.address, approvalAddress, approvalAmount);
54
+ await approveTx.wait();
64
55
  }
65
- });
56
+ };
66
57
  exports.approveToken = approveToken;
67
- const revokeTokenApproval = ({ signer, token, approvalAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const revokeTokenApproval = async ({ signer, token, approvalAddress, }) => {
68
59
  // native token don't need approval
69
60
  if ((0, utils_1.isNativeTokenAddress)(token.address)) {
70
61
  return;
71
62
  }
72
- const approvedAmount = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress);
63
+ const approvedAmount = await (0, utils_2.getApproved)(signer, token.address, approvalAddress);
73
64
  if (!approvedAmount.isZero()) {
74
- const approveTx = yield (0, utils_2.setApproval)(signer, token.address, approvalAddress, '0');
75
- yield approveTx.wait();
65
+ const approveTx = await (0, utils_2.setApproval)(signer, token.address, approvalAddress, '0');
66
+ await approveTx.wait();
76
67
  }
77
- });
68
+ };
78
69
  exports.revokeTokenApproval = revokeTokenApproval;