@lifi/sdk 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Lifi.js CHANGED
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,66 +7,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var allowance_1 = require("./allowance");
54
- var balances_1 = __importDefault(require("./balances"));
55
- var connectors_1 = require("./connectors");
56
- var StatusManager_1 = require("./execution/StatusManager");
57
- var StepExecutor_1 = require("./execution/StepExecutor");
58
- var ApiService_1 = __importDefault(require("./services/ApiService"));
59
- var ChainsService_1 = __importDefault(require("./services/ChainsService"));
60
- var ConfigService_1 = __importDefault(require("./services/ConfigService"));
61
- var typeguards_1 = require("./typeguards");
62
- var errors_1 = require("./utils/errors");
63
- var preRestart_1 = require("./utils/preRestart");
64
- var utils_1 = require("./utils/utils");
65
- var LIFI = /** @class */ (function () {
66
- function LIFI(configUpdate) {
67
- var _this = this;
10
+ import { approveToken, bulkGetTokenApproval, getTokenApproval, revokeTokenApproval, } from './allowance';
11
+ import balances from './balances';
12
+ import { getRpcProvider } from './connectors';
13
+ import { StatusManager } from './execution/StatusManager';
14
+ import { StepExecutor } from './execution/StepExecutor';
15
+ import ApiService from './services/ApiService';
16
+ import ChainsService from './services/ChainsService';
17
+ import ConfigService from './services/ConfigService';
18
+ import { isToken } from './typeguards';
19
+ import { ValidationError } from './utils/errors';
20
+ import { handlePreRestart } from './utils/preRestart';
21
+ import { deepClone } from './utils/utils';
22
+ export default class LIFI {
23
+ constructor(configUpdate) {
68
24
  this.activeRouteDictionary = {};
69
25
  /**
70
26
  * Get the current configuration of the SDK
71
27
  * @return {Config} - The config object
72
28
  */
73
- this.getConfig = function () {
74
- return _this.configService.getConfig();
29
+ this.getConfig = () => {
30
+ return this.configService.getConfig();
75
31
  };
76
32
  /**
77
33
  * Get the SDK configuration after all setup calls are finished
78
34
  * @return {Promise<Config>} - The config object
79
35
  */
80
- this.getConfigAsync = function () {
81
- return _this.configService.getConfigAsync();
36
+ this.getConfigAsync = () => {
37
+ return this.configService.getConfigAsync();
82
38
  };
83
39
  /**
84
40
  * Get an instance of a provider for a specific cahin
@@ -86,17 +42,16 @@ var LIFI = /** @class */ (function () {
86
42
  * @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
87
43
  * @return {FallbackProvider} The provider for the given chain
88
44
  */
89
- this.getRpcProvider = function (chainId, archive) {
90
- if (archive === void 0) { archive = false; }
91
- return (0, connectors_1.getRpcProvider)(chainId, archive);
45
+ this.getRpcProvider = (chainId, archive = false) => {
46
+ return getRpcProvider(chainId, archive);
92
47
  };
93
48
  /**
94
49
  * Set a new confuration for the SDK
95
50
  * @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
96
51
  * @return {Config} The renewed config object
97
52
  */
98
- this.setConfig = function (configUpdate) {
99
- return _this.configService.updateConfig(configUpdate);
53
+ this.setConfig = (configUpdate) => {
54
+ return this.configService.updateConfig(configUpdate);
100
55
  };
101
56
  /**
102
57
  * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
@@ -104,130 +59,108 @@ var LIFI = /** @class */ (function () {
104
59
  * @return {Promise<PossibilitiesResponse>} Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
105
60
  * @throws {LifiError} Throws a LifiError if request fails.
106
61
  */
107
- this.getPossibilities = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
108
- return __generator(this, function (_a) {
109
- return [2 /*return*/, ApiService_1.default.getPossibilities(request, options)];
110
- });
111
- }); };
62
+ this.getPossibilities = (request, options) => __awaiter(this, void 0, void 0, function* () {
63
+ return ApiService.getPossibilities(request, options);
64
+ });
112
65
  /**
113
66
  * Fetch information about a Token
114
67
  * @param {ChainKey | ChainId} chain - Id or key of the chain that contains the token
115
68
  * @param {string} token - Address or symbol of the token on the requested chain
116
69
  * @throws {LifiError} - Throws a LifiError if request fails
117
70
  */
118
- this.getToken = function (chain, token, options) { return __awaiter(_this, void 0, void 0, function () {
119
- return __generator(this, function (_a) {
120
- return [2 /*return*/, ApiService_1.default.getToken(chain, token, options)];
121
- });
122
- }); };
71
+ this.getToken = (chain, token, options) => __awaiter(this, void 0, void 0, function* () {
72
+ return ApiService.getToken(chain, token, options);
73
+ });
123
74
  /**
124
75
  * Get a quote for a token transfer
125
76
  * @param {QuoteRequest} request - The configuration of the requested quote
126
77
  * @throws {LifiError} - Throws a LifiError if request fails
127
78
  */
128
- this.getQuote = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
129
- return __generator(this, function (_a) {
130
- return [2 /*return*/, ApiService_1.default.getQuote(request, options)];
131
- });
132
- }); };
79
+ this.getQuote = (request, options) => __awaiter(this, void 0, void 0, function* () {
80
+ return ApiService.getQuote(request, options);
81
+ });
133
82
  /**
134
83
  * Get a quote for a destination contract call
135
84
  * @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
136
85
  * @throws {LifiError} - Throws a LifiError if request fails
137
86
  */
138
- this.getContractCallQuote = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
139
- return __generator(this, function (_a) {
140
- return [2 /*return*/, ApiService_1.default.getContractCallQuote(request, options)];
141
- });
142
- }); };
87
+ this.getContractCallQuote = (request, options) => __awaiter(this, void 0, void 0, function* () {
88
+ return ApiService.getContractCallQuote(request, options);
89
+ });
143
90
  /**
144
91
  * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
145
92
  * @param {GetStatusRequest} request - Configuration of the requested status
146
93
  * @throws {LifiError} - Throws a LifiError if request fails
147
94
  */
148
- this.getStatus = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
149
- return __generator(this, function (_a) {
150
- return [2 /*return*/, ApiService_1.default.getStatus(request, options)];
151
- });
152
- }); };
95
+ this.getStatus = (request, options) => __awaiter(this, void 0, void 0, function* () {
96
+ return ApiService.getStatus(request, options);
97
+ });
153
98
  /**
154
99
  * Get the available tools to bridge and swap tokens.
155
100
  * @param {ToolsRequest?} request - The configuration of the requested tools
156
101
  * @returns The tools that are available on the requested chains
157
102
  */
158
- this.getTools = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
159
- return __generator(this, function (_a) {
160
- return [2 /*return*/, ApiService_1.default.getTools(request || {}, options)];
161
- });
162
- }); };
103
+ this.getTools = (request, options) => __awaiter(this, void 0, void 0, function* () {
104
+ return ApiService.getTools(request || {}, options);
105
+ });
163
106
  /**
164
107
  * Get all known tokens.
165
108
  * @param {TokensRequest?} request - The configuration of the requested tokens
166
109
  * @returns The tokens that are available on the requested chains
167
110
  */
168
- this.getTokens = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
169
- return __generator(this, function (_a) {
170
- return [2 /*return*/, ApiService_1.default.getTokens(request || {}, options)];
171
- });
172
- }); };
111
+ this.getTokens = (request, options) => __awaiter(this, void 0, void 0, function* () {
112
+ return ApiService.getTokens(request || {}, options);
113
+ });
173
114
  /**
174
115
  * Get all available chains
175
116
  * @return {Promise<Chain[]>} A list of all available chains
176
117
  * @throws {LifiError} Throws a LifiError if request fails.
177
118
  */
178
- this.getChains = function () { return __awaiter(_this, void 0, void 0, function () {
179
- return __generator(this, function (_a) {
180
- return [2 /*return*/, this.chainsService.getChains()];
181
- });
182
- }); };
119
+ this.getChains = () => __awaiter(this, void 0, void 0, function* () {
120
+ return this.chainsService.getChains();
121
+ });
183
122
  /**
184
123
  * Get a set of routes for a request that describes a transfer of tokens.
185
124
  * @param {RoutesRequest} routesRequest - A description of the transfer.
186
125
  * @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
187
126
  * @throws {LifiError} Throws a LifiError if request fails.
188
127
  */
189
- this.getRoutes = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
190
- return __generator(this, function (_a) {
191
- return [2 /*return*/, ApiService_1.default.getRoutes(request, options)];
192
- });
193
- }); };
128
+ this.getRoutes = (request, options) => __awaiter(this, void 0, void 0, function* () {
129
+ return ApiService.getRoutes(request, options);
130
+ });
194
131
  /**
195
132
  * Get the transaction data for a single step of a route
196
133
  * @param {Step} step - The step object.
197
134
  * @return {Promise<Step>} The step populated with the transaction data.
198
135
  * @throws {LifiError} Throws a LifiError if request fails.
199
136
  */
200
- this.getStepTransaction = function (step, options) { return __awaiter(_this, void 0, void 0, function () {
201
- return __generator(this, function (_a) {
202
- return [2 /*return*/, ApiService_1.default.getStepTransaction(step, options)];
203
- });
204
- }); };
137
+ this.getStepTransaction = (step, options) => __awaiter(this, void 0, void 0, function* () {
138
+ return ApiService.getStepTransaction(step, options);
139
+ });
205
140
  /**
206
141
  * Stops the execution of an active route.
207
142
  * @param {Route} route - A route that is currently in execution.
208
143
  * @return {Route} The stopped route.
209
144
  */
210
- this.stopExecution = function (route) {
211
- if (!_this.activeRouteDictionary[route.id]) {
145
+ this.stopExecution = (route) => {
146
+ if (!this.activeRouteDictionary[route.id]) {
212
147
  return route;
213
148
  }
214
- for (var _i = 0, _a = _this.activeRouteDictionary[route.id].executors; _i < _a.length; _i++) {
215
- var executor = _a[_i];
149
+ for (const executor of this.activeRouteDictionary[route.id].executors) {
216
150
  executor.stopStepExecution({ allowUpdates: false });
217
151
  }
218
- delete _this.activeRouteDictionary[route.id];
152
+ delete this.activeRouteDictionary[route.id];
219
153
  return route;
220
154
  };
221
155
  /**
222
156
  * Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
223
157
  * @param {Route} route - A route that is currently in execution.
224
158
  */
225
- this.moveExecutionToBackground = function (route) {
226
- if (!_this.activeRouteDictionary[route.id]) {
159
+ this.moveExecutionToBackground = (route) => {
160
+ if (!this.activeRouteDictionary[route.id]) {
227
161
  return;
228
162
  }
229
- for (var _i = 0, _a = _this.activeRouteDictionary[route.id].executors; _i < _a.length; _i++) {
230
- var executor = _a[_i];
163
+ for (const executor of this.activeRouteDictionary[route.id].executors) {
231
164
  executor.stopStepExecution({ allowUpdates: true });
232
165
  }
233
166
  };
@@ -239,19 +172,15 @@ var LIFI = /** @class */ (function () {
239
172
  * @return {Promise<Route>} The executed route.
240
173
  * @throws {LifiError} Throws a LifiError if the execution fails.
241
174
  */
242
- this.executeRoute = function (signer, route, settings) { return __awaiter(_this, void 0, void 0, function () {
243
- var clonedRoute;
244
- return __generator(this, function (_a) {
245
- clonedRoute = (0, utils_1.deepClone)(route) // deep clone to prevent side effects
246
- ;
247
- // check if route is already running
248
- if (this.activeRouteDictionary[clonedRoute.id]) {
249
- // TODO: maybe inform user why nothing happens?
250
- return [2 /*return*/, clonedRoute];
251
- }
252
- return [2 /*return*/, this.executeSteps(signer, clonedRoute, settings)];
253
- });
254
- }); };
175
+ this.executeRoute = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
176
+ const clonedRoute = deepClone(route); // deep clone to prevent side effects
177
+ // check if route is already running
178
+ if (this.activeRouteDictionary[clonedRoute.id]) {
179
+ // TODO: maybe inform user why nothing happens?
180
+ return clonedRoute;
181
+ }
182
+ return this.executeSteps(signer, clonedRoute, settings);
183
+ });
255
184
  /**
256
185
  * Resume the execution of a route that has been stopped or had an error while executing.
257
186
  * @param {Signer} signer - The signer required to send the transactions.
@@ -260,113 +189,92 @@ var LIFI = /** @class */ (function () {
260
189
  * @return {Promise<Route>} The executed route.
261
190
  * @throws {LifiError} Throws a LifiError if the execution fails.
262
191
  */
263
- this.resumeRoute = function (signer, route, settings) { return __awaiter(_this, void 0, void 0, function () {
264
- var clonedRoute, activeRoute, executionHalted;
265
- return __generator(this, function (_a) {
266
- clonedRoute = (0, utils_1.deepClone)(route) // deep clone to prevent side effects
267
- ;
268
- activeRoute = this.activeRouteDictionary[clonedRoute.id];
269
- if (activeRoute) {
270
- executionHalted = activeRoute.executors.some(function (executor) { return executor.executionStopped; });
271
- if (!executionHalted) {
272
- return [2 /*return*/, clonedRoute];
273
- }
192
+ this.resumeRoute = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
193
+ const clonedRoute = deepClone(route); // deep clone to prevent side effects
194
+ const activeRoute = this.activeRouteDictionary[clonedRoute.id];
195
+ if (activeRoute) {
196
+ const executionHalted = activeRoute.executors.some((executor) => executor.executionStopped);
197
+ if (!executionHalted) {
198
+ return clonedRoute;
199
+ }
200
+ }
201
+ handlePreRestart(clonedRoute);
202
+ return this.executeSteps(signer, clonedRoute, settings);
203
+ });
204
+ this.executeSteps = (signer, route, settings) => __awaiter(this, void 0, void 0, function* () {
205
+ const config = this.configService.getConfig();
206
+ const execData = {
207
+ route,
208
+ executors: [],
209
+ settings: Object.assign(Object.assign({}, config.defaultExecutionSettings), settings),
210
+ };
211
+ this.activeRouteDictionary[route.id] = execData;
212
+ const statusManager = new StatusManager(route, this.activeRouteDictionary[route.id].settings, (route) => (this.activeRouteDictionary[route.id].route = route));
213
+ // loop over steps and execute them
214
+ for (let index = 0; index < route.steps.length; index++) {
215
+ //check if execution has stopped in meantime
216
+ if (!this.activeRouteDictionary[route.id]) {
217
+ break;
218
+ }
219
+ const step = route.steps[index];
220
+ const previousStep = index !== 0 ? route.steps[index - 1] : undefined;
221
+ // check if step already done
222
+ if (step.execution && step.execution.status === 'DONE') {
223
+ continue;
274
224
  }
275
- (0, preRestart_1.handlePreRestart)(clonedRoute);
276
- return [2 /*return*/, this.executeSteps(signer, clonedRoute, settings)];
277
- });
278
- }); };
279
- this.executeSteps = function (signer, route, settings) { return __awaiter(_this, void 0, void 0, function () {
280
- var config, execData, statusManager, index, step, previousStep, stepExecutor, e_1;
281
- var _this = this;
282
- return __generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- config = this.configService.getConfig();
286
- execData = {
287
- route: route,
288
- executors: [],
289
- settings: __assign(__assign({}, config.defaultExecutionSettings), settings),
290
- };
291
- this.activeRouteDictionary[route.id] = execData;
292
- statusManager = new StatusManager_1.StatusManager(route, this.activeRouteDictionary[route.id].settings, function (route) { return (_this.activeRouteDictionary[route.id].route = route); });
293
- index = 0;
294
- _a.label = 1;
295
- case 1:
296
- if (!(index < route.steps.length)) return [3 /*break*/, 7];
297
- //check if execution has stopped in meantime
298
- if (!this.activeRouteDictionary[route.id]) {
299
- return [3 /*break*/, 7];
300
- }
301
- step = route.steps[index];
302
- previousStep = index !== 0 ? route.steps[index - 1] : undefined;
303
- // check if step already done
304
- if (step.execution && step.execution.status === 'DONE') {
305
- return [3 /*break*/, 6];
306
- }
307
- // update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
308
- if (previousStep &&
309
- previousStep.execution &&
310
- previousStep.execution.toAmount) {
311
- step.action.fromAmount = previousStep.execution.toAmount;
312
- }
313
- stepExecutor = void 0;
314
- _a.label = 2;
315
- case 2:
316
- _a.trys.push([2, 4, , 5]);
317
- stepExecutor = new StepExecutor_1.StepExecutor(statusManager, this.activeRouteDictionary[route.id].settings);
318
- this.activeRouteDictionary[route.id].executors.push(stepExecutor);
319
- return [4 /*yield*/, stepExecutor.executeStep(signer, step)];
320
- case 3:
321
- _a.sent();
322
- return [3 /*break*/, 5];
323
- case 4:
324
- e_1 = _a.sent();
325
- this.stopExecution(route);
326
- throw e_1;
327
- case 5:
328
- // execution stopped during the current step, we don't want to continue to the next step so we return already
329
- if (stepExecutor.executionStopped) {
330
- return [2 /*return*/, route];
331
- }
332
- _a.label = 6;
333
- case 6:
334
- index++;
335
- return [3 /*break*/, 1];
336
- case 7:
337
- //clean up after execution
338
- delete this.activeRouteDictionary[route.id];
339
- return [2 /*return*/, route];
225
+ // update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
226
+ if (previousStep &&
227
+ previousStep.execution &&
228
+ previousStep.execution.toAmount) {
229
+ step.action.fromAmount = previousStep.execution.toAmount;
340
230
  }
341
- });
342
- }); };
231
+ let stepExecutor;
232
+ try {
233
+ stepExecutor = new StepExecutor(statusManager, this.activeRouteDictionary[route.id].settings);
234
+ this.activeRouteDictionary[route.id].executors.push(stepExecutor);
235
+ yield stepExecutor.executeStep(signer, step);
236
+ }
237
+ catch (e) {
238
+ this.stopExecution(route);
239
+ throw e;
240
+ }
241
+ // execution stopped during the current step, we don't want to continue to the next step so we return already
242
+ if (stepExecutor.executionStopped) {
243
+ return route;
244
+ }
245
+ }
246
+ //clean up after execution
247
+ delete this.activeRouteDictionary[route.id];
248
+ return route;
249
+ });
343
250
  /**
344
251
  * Update the ExecutionSettings for an active route.
345
252
  * @param {ExecutionSettings} settings - An object with execution settings.
346
253
  * @param {Route} route - The active route that gets the new execution settings.
347
254
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
348
255
  */
349
- this.updateExecutionSettings = function (settings, route) {
350
- if (!_this.activeRouteDictionary[route.id]) {
351
- throw new errors_1.ValidationError("Can't set ExecutionSettings for the inactive route.");
256
+ this.updateExecutionSettings = (settings, route) => {
257
+ if (!this.activeRouteDictionary[route.id]) {
258
+ throw new ValidationError("Can't set ExecutionSettings for the inactive route.");
352
259
  }
353
- var config = _this.configService.getConfig();
354
- _this.activeRouteDictionary[route.id].settings = __assign(__assign({}, config.defaultExecutionSettings), settings);
260
+ const config = this.configService.getConfig();
261
+ this.activeRouteDictionary[route.id].settings = Object.assign(Object.assign({}, config.defaultExecutionSettings), settings);
355
262
  };
356
263
  /**
357
264
  * Get the list of active routes.
358
265
  * @return {Route[]} A list of routes.
359
266
  */
360
- this.getActiveRoutes = function () {
361
- return Object.values(_this.activeRouteDictionary).map(function (dict) { return dict.route; });
267
+ this.getActiveRoutes = () => {
268
+ return Object.values(this.activeRouteDictionary).map((dict) => dict.route);
362
269
  };
363
270
  /**
364
271
  * Return the current route information for given route. The route has to be active.
365
272
  * @param {Route} route - A route object.
366
273
  * @return {Route} The updated route.
367
274
  */
368
- this.getActiveRoute = function (route) {
369
- return _this.activeRouteDictionary[route.id].route;
275
+ this.getActiveRoute = (route) => {
276
+ var _a;
277
+ return (_a = this.activeRouteDictionary[route.id]) === null || _a === void 0 ? void 0 : _a.route;
370
278
  };
371
279
  /**
372
280
  * Returns the balances of a specific token a wallet holds across all aggregated chains.
@@ -375,17 +283,15 @@ var LIFI = /** @class */ (function () {
375
283
  * @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
376
284
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
377
285
  */
378
- this.getTokenBalance = function (walletAddress, token) { return __awaiter(_this, void 0, void 0, function () {
379
- return __generator(this, function (_a) {
380
- if (!walletAddress) {
381
- throw new errors_1.ValidationError('Missing walletAddress.');
382
- }
383
- if (!(0, typeguards_1.isToken)(token)) {
384
- throw new errors_1.ValidationError("Invalid token passed: address \"".concat(token.address, "\" on chainId \"").concat(token.chainId, "\""));
385
- }
386
- return [2 /*return*/, balances_1.default.getTokenBalance(walletAddress, token)];
387
- });
388
- }); };
286
+ this.getTokenBalance = (walletAddress, token) => __awaiter(this, void 0, void 0, function* () {
287
+ if (!walletAddress) {
288
+ throw new ValidationError('Missing walletAddress.');
289
+ }
290
+ if (!isToken(token)) {
291
+ throw new ValidationError(`Invalid token passed: address "${token.address}" on chainId "${token.chainId}"`);
292
+ }
293
+ return balances.getTokenBalance(walletAddress, token);
294
+ });
389
295
  /**
390
296
  * Returns the balances for a list tokens a wallet holds across all aggregated chains.
391
297
  * @param {string} walletAddress - A wallet address.
@@ -393,19 +299,16 @@ var LIFI = /** @class */ (function () {
393
299
  * @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
394
300
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
395
301
  */
396
- this.getTokenBalances = function (walletAddress, tokens) { return __awaiter(_this, void 0, void 0, function () {
397
- var invalidTokens;
398
- return __generator(this, function (_a) {
399
- if (!walletAddress) {
400
- throw new errors_1.ValidationError('Missing walletAddress.');
401
- }
402
- invalidTokens = tokens.filter(function (token) { return !(0, typeguards_1.isToken)(token); });
403
- if (invalidTokens.length) {
404
- throw new errors_1.ValidationError("Invalid token passed: address \"".concat(invalidTokens[0].address, "\" on chainId \"").concat(invalidTokens[0].chainId, "\""));
405
- }
406
- return [2 /*return*/, balances_1.default.getTokenBalances(walletAddress, tokens)];
407
- });
408
- }); };
302
+ this.getTokenBalances = (walletAddress, tokens) => __awaiter(this, void 0, void 0, function* () {
303
+ if (!walletAddress) {
304
+ throw new ValidationError('Missing walletAddress.');
305
+ }
306
+ const invalidTokens = tokens.filter((token) => !isToken(token));
307
+ if (invalidTokens.length) {
308
+ throw new ValidationError(`Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`);
309
+ }
310
+ return balances.getTokenBalances(walletAddress, tokens);
311
+ });
409
312
  /**
410
313
  * This method queries the balances of tokens for a specific list of chains for a given wallet.
411
314
  * @param {string} walletAddress - A walletaddress.
@@ -413,64 +316,55 @@ var LIFI = /** @class */ (function () {
413
316
  * @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
414
317
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
415
318
  */
416
- this.getTokenBalancesForChains = function (walletAddress, tokensByChain) { return __awaiter(_this, void 0, void 0, function () {
417
- var tokenList, invalidTokens;
418
- return __generator(this, function (_a) {
419
- if (!walletAddress) {
420
- throw new errors_1.ValidationError('Missing walletAddress.');
421
- }
422
- tokenList = Object.values(tokensByChain).flat();
423
- invalidTokens = tokenList.filter(function (token) { return !(0, typeguards_1.isToken)(token); });
424
- if (invalidTokens.length) {
425
- throw new errors_1.ValidationError("Invalid token passed: address \"".concat(invalidTokens[0].address, "\" on chainId \"").concat(invalidTokens[0].chainId, "\""));
426
- }
427
- return [2 /*return*/, balances_1.default.getTokenBalancesForChains(walletAddress, tokensByChain)];
428
- });
429
- }); };
319
+ this.getTokenBalancesForChains = (walletAddress, tokensByChain) => __awaiter(this, void 0, void 0, function* () {
320
+ if (!walletAddress) {
321
+ throw new ValidationError('Missing walletAddress.');
322
+ }
323
+ const tokenList = Object.values(tokensByChain).flat();
324
+ const invalidTokens = tokenList.filter((token) => !isToken(token));
325
+ if (invalidTokens.length) {
326
+ throw new ValidationError(`Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`);
327
+ }
328
+ return balances.getTokenBalancesForChains(walletAddress, tokensByChain);
329
+ });
430
330
  /**
431
331
  * Get the current approval for a certain token.
432
332
  * @param signer - The signer owning the token
433
333
  * @param token - The token that should be checked
434
334
  * @param approvalAddress - The address that has be approved
435
335
  */
436
- this.getTokenApproval = function (signer, token, approvalAddress) { return __awaiter(_this, void 0, void 0, function () {
437
- return __generator(this, function (_a) {
438
- return [2 /*return*/, (0, allowance_1.getTokenApproval)(signer, token, approvalAddress)];
439
- });
440
- }); };
336
+ this.getTokenApproval = (signer, token, approvalAddress) => __awaiter(this, void 0, void 0, function* () {
337
+ return getTokenApproval(signer, token, approvalAddress);
338
+ });
441
339
  /**
442
340
  * Get the current approval for a list of token / approval address pairs.
443
341
  * @param signer - The signer owning the tokens
444
342
  * @param tokenData - A list of token and approval address pairs
445
343
  */
446
- this.bulkGetTokenApproval = function (signer, tokenData) { return __awaiter(_this, void 0, void 0, function () {
447
- return __generator(this, function (_a) {
448
- return [2 /*return*/, (0, allowance_1.bulkGetTokenApproval)(signer, tokenData)];
449
- });
450
- }); };
344
+ this.bulkGetTokenApproval = (signer, tokenData) => __awaiter(this, void 0, void 0, function* () {
345
+ return bulkGetTokenApproval(signer, tokenData);
346
+ });
451
347
  /**
452
348
  * Set approval for a certain token and amount.
453
349
  * @param { ApproveTokenRequest } request - The approval request
454
350
  */
455
- this.approveToken = function (request) {
456
- return (0, allowance_1.approveToken)(request);
351
+ this.approveToken = (request) => {
352
+ return approveToken(request);
457
353
  };
458
354
  /**
459
355
  * Revoke approval for a certain token.
460
356
  * @param { RevokeApprovalRequest } request - The revoke request
461
357
  */
462
- this.revokeTokenApproval = function (request) {
463
- return (0, allowance_1.revokeTokenApproval)(request);
358
+ this.revokeTokenApproval = (request) => {
359
+ return revokeTokenApproval(request);
464
360
  };
465
- this.configService = ConfigService_1.default.getInstance();
361
+ this.configService = ConfigService.getInstance();
466
362
  if (configUpdate) {
467
363
  this.configService.updateConfig(configUpdate); // update API urls before we request chains
468
364
  }
469
- this.chainsService = ChainsService_1.default.getInstance();
470
- this.chainsService.getChains().then(function (chains) {
471
- _this.configService.updateChains(chains);
365
+ this.chainsService = ChainsService.getInstance();
366
+ this.chainsService.getChains().then((chains) => {
367
+ this.configService.updateChains(chains);
472
368
  });
473
369
  }
474
- return LIFI;
475
- }());
476
- exports.default = LIFI;
370
+ }