@lifi/sdk 2.0.0-beta.1 → 2.0.0-beta.11
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.d.ts → LiFi.d.ts} +19 -63
- package/dist/{Lifi.js → LiFi.js} +19 -212
- package/dist/allowance/checkAllowance.d.ts +2 -2
- package/dist/allowance/checkAllowance.js +16 -2
- package/dist/allowance/utils.d.ts +2 -1
- package/dist/allowance/utils.js +7 -2
- package/dist/balance/checkBalance.d.ts +2 -2
- package/dist/balance/index.d.ts +1 -1
- package/dist/cjs/{Lifi.d.ts → LiFi.d.ts} +19 -63
- package/dist/cjs/{Lifi.js → LiFi.js} +22 -213
- package/dist/cjs/allowance/checkAllowance.d.ts +2 -2
- package/dist/cjs/allowance/checkAllowance.js +16 -2
- package/dist/cjs/allowance/utils.d.ts +2 -1
- package/dist/cjs/allowance/utils.js +7 -2
- package/dist/cjs/balance/checkBalance.d.ts +2 -2
- package/dist/cjs/balance/index.d.ts +1 -1
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/connectors.js +7 -9
- package/dist/cjs/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/cjs/execution/RouteExecutionManager.js +220 -0
- package/dist/cjs/execution/StatusManager.d.ts +12 -12
- package/dist/cjs/execution/StatusManager.js +5 -5
- package/dist/cjs/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/cjs/execution/{ExecutionManager.js → StepExecutionManager.js} +11 -3
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +17 -9
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -5
- package/dist/cjs/execution/switchChain.d.ts +2 -2
- package/dist/cjs/execution/utils.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +5 -7
- package/dist/cjs/helpers.js +10 -30
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/request.d.ts +9 -0
- package/dist/cjs/request.js +60 -0
- package/dist/cjs/services/ApiService.d.ts +8 -7
- package/dist/cjs/services/ApiService.js +52 -31
- package/dist/cjs/services/ConfigService.js +6 -2
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/internal.types.d.ts +54 -10
- package/dist/cjs/utils/errors.d.ts +20 -1
- package/dist/cjs/utils/errors.js +23 -1
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +29 -12
- package/dist/cjs/utils/utils.d.ts +3 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +1 -1
- package/dist/connectors.js +7 -9
- package/dist/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/execution/RouteExecutionManager.js +213 -0
- package/dist/execution/StatusManager.d.ts +12 -12
- package/dist/execution/StatusManager.js +5 -5
- package/dist/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/execution/{ExecutionManager.js → StepExecutionManager.js} +9 -1
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +17 -9
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +2 -5
- package/dist/execution/switchChain.d.ts +2 -2
- package/dist/execution/utils.d.ts +3 -3
- package/dist/helpers.d.ts +5 -7
- package/dist/helpers.js +9 -29
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/dist/request.d.ts +9 -0
- package/dist/request.js +53 -0
- package/dist/services/ApiService.d.ts +8 -7
- package/dist/services/ApiService.js +43 -22
- package/dist/services/ConfigService.js +7 -2
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/internal.types.d.ts +54 -10
- package/dist/utils/errors.d.ts +20 -1
- package/dist/utils/errors.js +22 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +30 -13
- package/dist/utils/utils.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -15
|
@@ -26,22 +26,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getConnections = exports.LiFi = void 0;
|
|
29
30
|
const allowance_1 = require("./allowance");
|
|
30
31
|
const balance = __importStar(require("./balance"));
|
|
31
32
|
const connectors_1 = require("./connectors");
|
|
32
|
-
const
|
|
33
|
-
const StepExecutor_1 = require("./execution/StepExecutor");
|
|
33
|
+
const RouteExecutionManager_1 = require("./execution/RouteExecutionManager");
|
|
34
34
|
const helpers_1 = require("./helpers");
|
|
35
35
|
const ApiService_1 = __importDefault(require("./services/ApiService"));
|
|
36
36
|
const ChainsService_1 = __importDefault(require("./services/ChainsService"));
|
|
37
|
-
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
38
37
|
const typeguards_1 = require("./typeguards");
|
|
39
38
|
const errors_1 = require("./utils/errors");
|
|
40
|
-
const preRestart_1 = require("./utils/preRestart");
|
|
41
39
|
const version_1 = require("./version");
|
|
42
|
-
class
|
|
40
|
+
class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
|
|
43
41
|
constructor(configUpdate) {
|
|
44
|
-
|
|
42
|
+
super(configUpdate);
|
|
45
43
|
/**
|
|
46
44
|
* Get the current configuration of the SDK
|
|
47
45
|
* @return {Config} - The config object
|
|
@@ -141,7 +139,7 @@ class LIFI {
|
|
|
141
139
|
};
|
|
142
140
|
/**
|
|
143
141
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
144
|
-
* @param {RoutesRequest}
|
|
142
|
+
* @param {RoutesRequest} request - A description of the transfer.
|
|
145
143
|
* @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
|
|
146
144
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
147
145
|
*/
|
|
@@ -150,7 +148,7 @@ class LIFI {
|
|
|
150
148
|
};
|
|
151
149
|
/**
|
|
152
150
|
* Get the transaction data for a single step of a route
|
|
153
|
-
* @param {
|
|
151
|
+
* @param {LifiStep} step - The step object.
|
|
154
152
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
155
153
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
156
154
|
*/
|
|
@@ -158,206 +156,12 @@ class LIFI {
|
|
|
158
156
|
return ApiService_1.default.getStepTransaction(step, options);
|
|
159
157
|
};
|
|
160
158
|
/**
|
|
161
|
-
*
|
|
162
|
-
* @param {
|
|
163
|
-
* @
|
|
164
|
-
*/
|
|
165
|
-
this.stopExecution = (route) => {
|
|
166
|
-
if (!this.activeRouteDictionary[route.id]) {
|
|
167
|
-
return route;
|
|
168
|
-
}
|
|
169
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
170
|
-
for (const executor of executionData.executors) {
|
|
171
|
-
executor.setInteraction({
|
|
172
|
-
allowInteraction: false,
|
|
173
|
-
allowUpdates: false,
|
|
174
|
-
stopExecution: true,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
delete this.activeRouteDictionary[route.id];
|
|
178
|
-
return route;
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
182
|
-
* @param {Route} route - A route that is currently in execution.
|
|
183
|
-
* @deprecated use updateRouteExecution instead.
|
|
184
|
-
*/
|
|
185
|
-
this.moveExecutionToBackground = (route) => {
|
|
186
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
187
|
-
if (!executionData) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
for (const executor of executionData.executors) {
|
|
191
|
-
executor.setInteraction({ allowInteraction: false, allowUpdates: true });
|
|
192
|
-
}
|
|
193
|
-
executionData.settings = {
|
|
194
|
-
...executionData.settings,
|
|
195
|
-
executeInBackground: true,
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Updates route execution to background or foreground state.
|
|
200
|
-
* @param {Route} route - A route that is currently in execution.
|
|
201
|
-
* @param {boolean} settings - An object with execution settings.
|
|
202
|
-
*/
|
|
203
|
-
this.updateRouteExecution = (route, settings) => {
|
|
204
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
205
|
-
if (!executionData) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
for (const executor of executionData.executors) {
|
|
209
|
-
executor.setInteraction({
|
|
210
|
-
allowInteraction: !settings.executeInBackground,
|
|
211
|
-
allowUpdates: true,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
// Update active route settings so we know what the current state of execution is
|
|
215
|
-
executionData.settings = {
|
|
216
|
-
...executionData.settings,
|
|
217
|
-
...settings,
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* Execute a route.
|
|
222
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
223
|
-
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
224
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
225
|
-
* @return {Promise<Route>} The executed route.
|
|
226
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
227
|
-
*/
|
|
228
|
-
this.executeRoute = async (signer, route, settings) => {
|
|
229
|
-
// Deep clone to prevent side effects
|
|
230
|
-
const clonedRoute = structuredClone(route);
|
|
231
|
-
// Check if route is already running
|
|
232
|
-
if (this.activeRouteDictionary[clonedRoute.id]) {
|
|
233
|
-
// TODO: maybe inform user why nothing happens?
|
|
234
|
-
return this.activeRouteDictionary[clonedRoute.id].executionPromise;
|
|
235
|
-
}
|
|
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
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
245
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
246
|
-
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
247
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
248
|
-
* @return {Promise<Route>} The executed route.
|
|
249
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
250
|
-
*/
|
|
251
|
-
this.resumeRoute = async (signer, route, settings) => {
|
|
252
|
-
// Deep clone to prevent side effects
|
|
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);
|
|
257
|
-
if (!executionHalted) {
|
|
258
|
-
// Check if we want to resume route execution in the background
|
|
259
|
-
this.updateRouteExecution(route, {
|
|
260
|
-
executeInBackground: settings?.executeInBackground,
|
|
261
|
-
});
|
|
262
|
-
return executionPromise;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
(0, preRestart_1.handlePreRestart)(clonedRoute);
|
|
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) => {
|
|
274
|
-
const config = this.configService.getConfig();
|
|
275
|
-
const updatedExecutionData = {
|
|
276
|
-
route,
|
|
277
|
-
executors: [],
|
|
278
|
-
settings: { ...config.defaultExecutionSettings, ...settings },
|
|
279
|
-
};
|
|
280
|
-
this.activeRouteDictionary[route.id].executionData = {
|
|
281
|
-
...updatedExecutionData,
|
|
282
|
-
};
|
|
283
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
284
|
-
const statusManager = new StatusManager_1.StatusManager(route, executionData.settings, (route) => {
|
|
285
|
-
if (this.activeRouteDictionary[route.id]) {
|
|
286
|
-
executionData.route = route;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
// Loop over steps and execute them
|
|
290
|
-
for (let index = 0; index < route.steps.length; index++) {
|
|
291
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
292
|
-
// Check if execution has stopped in the meantime
|
|
293
|
-
if (!executionData) {
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
const step = route.steps[index];
|
|
297
|
-
const previousStep = route.steps[index - 1];
|
|
298
|
-
// Check if the step is already done
|
|
299
|
-
//
|
|
300
|
-
if (step.execution?.status === 'DONE') {
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
// Update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
|
|
304
|
-
if (previousStep?.execution?.toAmount) {
|
|
305
|
-
step.action.fromAmount = previousStep.execution.toAmount;
|
|
306
|
-
}
|
|
307
|
-
try {
|
|
308
|
-
const stepExecutor = new StepExecutor_1.StepExecutor(statusManager, executionData.settings);
|
|
309
|
-
executionData.executors.push(stepExecutor);
|
|
310
|
-
// Check if we want to execute this step in the background
|
|
311
|
-
this.updateRouteExecution(route, executionData.settings);
|
|
312
|
-
const executedStep = await stepExecutor.executeStep(signer, step);
|
|
313
|
-
// We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
|
|
314
|
-
if (executedStep.execution?.status !== 'DONE') {
|
|
315
|
-
this.stopExecution(route);
|
|
316
|
-
}
|
|
317
|
-
// Execution stopped during the current step, we don't want to continue to the next step so we return already
|
|
318
|
-
if (stepExecutor.executionStopped) {
|
|
319
|
-
return route;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
catch (e) {
|
|
323
|
-
this.stopExecution(route);
|
|
324
|
-
throw e;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
// Clean up after the execution
|
|
328
|
-
delete this.activeRouteDictionary[route.id];
|
|
329
|
-
return route;
|
|
330
|
-
};
|
|
331
|
-
/**
|
|
332
|
-
* Update the ExecutionSettings for an active route.
|
|
333
|
-
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
334
|
-
* @param {Route} route - The active route that gets the new execution settings.
|
|
335
|
-
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
336
|
-
*/
|
|
337
|
-
this.updateExecutionSettings = (settings, route) => {
|
|
338
|
-
if (!this.activeRouteDictionary[route.id]) {
|
|
339
|
-
throw new errors_1.ValidationError("Can't set ExecutionSettings for the inactive route.");
|
|
340
|
-
}
|
|
341
|
-
const config = this.configService.getConfig();
|
|
342
|
-
this.activeRouteDictionary[route.id].executionData.settings = {
|
|
343
|
-
...config.defaultExecutionSettings,
|
|
344
|
-
...settings,
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
|
-
/**
|
|
348
|
-
* Get the list of active routes.
|
|
349
|
-
* @return {Route[]} A list of routes.
|
|
350
|
-
*/
|
|
351
|
-
this.getActiveRoutes = () => {
|
|
352
|
-
return Object.values(this.activeRouteDictionary).map((dict) => dict.executionData.route);
|
|
353
|
-
};
|
|
354
|
-
/**
|
|
355
|
-
* Return the current route information for given route. The route has to be active.
|
|
356
|
-
* @param {Route} route - A route object.
|
|
357
|
-
* @return {Route} The updated route.
|
|
159
|
+
* Get gas recommendation for a certain chain
|
|
160
|
+
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
161
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
358
162
|
*/
|
|
359
|
-
this.
|
|
360
|
-
return
|
|
163
|
+
this.getGasRecommendation = async (request, options) => {
|
|
164
|
+
return ApiService_1.default.getGasRecommendation(request, options);
|
|
361
165
|
};
|
|
362
166
|
/**
|
|
363
167
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
@@ -441,11 +245,6 @@ class LIFI {
|
|
|
441
245
|
this.revokeTokenApproval = (request) => {
|
|
442
246
|
return (0, allowance_1.revokeTokenApproval)(request);
|
|
443
247
|
};
|
|
444
|
-
this.configService = ConfigService_1.default.getInstance();
|
|
445
|
-
if (configUpdate) {
|
|
446
|
-
// Update API urls before we request chains
|
|
447
|
-
this.configService.updateConfig(configUpdate);
|
|
448
|
-
}
|
|
449
248
|
this.chainsService = ChainsService_1.default.getInstance();
|
|
450
249
|
this.chainsService.getChains().then((chains) => {
|
|
451
250
|
this.configService.updateChains(chains);
|
|
@@ -453,4 +252,14 @@ class LIFI {
|
|
|
453
252
|
(0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate?.disableVersionCheck);
|
|
454
253
|
}
|
|
455
254
|
}
|
|
456
|
-
exports.
|
|
255
|
+
exports.LiFi = LiFi;
|
|
256
|
+
/**
|
|
257
|
+
* Get all the available connections for swap/bridging tokens
|
|
258
|
+
* @param connectionRequest ConnectionsRequest
|
|
259
|
+
* @returns ConnectionsResponse
|
|
260
|
+
*/
|
|
261
|
+
const getConnections = async (connectionRequest) => {
|
|
262
|
+
const connections = await ApiService_1.default.getAvailableConnections(connectionRequest);
|
|
263
|
+
return connections;
|
|
264
|
+
};
|
|
265
|
+
exports.getConnections = getConnections;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
2
|
import { StatusManager } from '../execution/StatusManager';
|
|
3
|
-
import { Chain, InternalExecutionSettings,
|
|
4
|
-
export declare const checkAllowance: (signer: Signer, step:
|
|
3
|
+
import { Chain, InternalExecutionSettings, LifiStep } from '../types';
|
|
4
|
+
export declare const checkAllowance: (signer: Signer, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean) => Promise<void>;
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkAllowance = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
8
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
8
|
const ethers_1 = require("ethers");
|
|
10
9
|
const utils_1 = require("../allowance/utils");
|
|
@@ -23,7 +22,22 @@ const checkAllowance = async (signer, step, statusManager, settings, chain, allo
|
|
|
23
22
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
|
-
const
|
|
25
|
+
const approvalRequest = {
|
|
26
|
+
from: step.action.fromToken.address,
|
|
27
|
+
to: step.estimate.approvalAddress,
|
|
28
|
+
};
|
|
29
|
+
if (settings.updateTransactionRequest) {
|
|
30
|
+
const config = await settings.updateTransactionRequest(approvalRequest);
|
|
31
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
32
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
33
|
+
}
|
|
34
|
+
if (!approvalRequest.from) {
|
|
35
|
+
throw new Error('Missing Signer address');
|
|
36
|
+
}
|
|
37
|
+
if (!approvalRequest.to) {
|
|
38
|
+
throw new Error('Missing ERC20 contract address');
|
|
39
|
+
}
|
|
40
|
+
const approved = await (0, utils_1.getApproved)(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
27
41
|
if (new bignumber_js_1.default(step.action.fromAmount).gt(approved)) {
|
|
28
42
|
if (!allowUserInteraction) {
|
|
29
43
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
|
@@ -10,11 +10,16 @@ const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
|
10
10
|
const types_1 = require("../types");
|
|
11
11
|
const errors_1 = require("../utils/errors");
|
|
12
12
|
const multicall_1 = require("../utils/multicall");
|
|
13
|
-
const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
13
|
+
const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
14
14
|
const signerAddress = await signer.getAddress();
|
|
15
15
|
const erc20 = new ethers_1.Contract(tokenAddress, types_1.ERC20_ABI, signer);
|
|
16
16
|
try {
|
|
17
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
17
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
18
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
19
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
20
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
21
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
22
|
+
});
|
|
18
23
|
return new bignumber_js_1.default(approved.toString());
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export declare const checkBalance: (signer: ethers.Signer, step:
|
|
2
|
+
import { LifiStep } from '..';
|
|
3
|
+
export declare const checkBalance: (signer: ethers.Signer, step: LifiStep, depth?: number) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './checkBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").
|
|
4
|
+
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
|
|
5
5
|
getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
|
|
6
6
|
getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
|
|
7
7
|
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
package/dist/cjs/connectors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChainId } from './types';
|
|
2
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
+
import { ChainId } from './types';
|
|
3
3
|
export declare const getRpcUrl: (chainId: ChainId, archive?: boolean) => Promise<string>;
|
|
4
4
|
export declare const getRpcUrls: (chainId: ChainId, archive?: boolean) => Promise<string[]>;
|
|
5
5
|
export declare const getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
|
package/dist/cjs/connectors.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getMulticallAddress = exports.getRpcProvider = exports.getRpcUrls = exports.getRpcUrl = void 0;
|
|
7
|
-
const
|
|
8
|
-
const types_1 = require("./types");
|
|
9
|
-
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
7
|
+
const providers_1 = require("@ethersproject/providers");
|
|
10
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
10
|
+
const types_1 = require("./types");
|
|
11
11
|
const errors_1 = require("./utils/errors");
|
|
12
12
|
// cached providers
|
|
13
13
|
const chainProviders = {};
|
|
@@ -41,17 +41,15 @@ const getRandomProvider = (providerList) => {
|
|
|
41
41
|
const getRpcProvider = async (chainId, archive = false) => {
|
|
42
42
|
if (archive && archiveRpcs[chainId]) {
|
|
43
43
|
// return archive PRC, but don't cache it
|
|
44
|
-
return new
|
|
45
|
-
new
|
|
44
|
+
return new providers_1.FallbackProvider([
|
|
45
|
+
new providers_1.StaticJsonRpcProvider(await (0, exports.getRpcUrl)(chainId, archive), chainId),
|
|
46
46
|
]);
|
|
47
47
|
}
|
|
48
|
-
if (!chainProviders[chainId]) {
|
|
48
|
+
if (!chainProviders[chainId]?.length) {
|
|
49
49
|
chainProviders[chainId] = [];
|
|
50
50
|
const urls = await (0, exports.getRpcUrls)(chainId, archive);
|
|
51
51
|
urls.forEach((url) => {
|
|
52
|
-
chainProviders[chainId].push(new
|
|
53
|
-
new ethers_1.providers.StaticJsonRpcProvider(url, chainId),
|
|
54
|
-
]));
|
|
52
|
+
chainProviders[chainId].push(new providers_1.FallbackProvider([new providers_1.StaticJsonRpcProvider(url, chainId)]));
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
if (!chainProviders[chainId].length) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Route } from '@lifi/types';
|
|
2
|
+
import { Signer } from 'ethers';
|
|
3
|
+
import ConfigService from '../services/ConfigService';
|
|
4
|
+
import { ConfigUpdate, ExecutionSettings } from '../types';
|
|
5
|
+
export declare class RouteExecutionManager {
|
|
6
|
+
private executionDictionary;
|
|
7
|
+
private executionPromiseDictionary;
|
|
8
|
+
protected configService: ConfigService;
|
|
9
|
+
constructor(configUpdate?: ConfigUpdate);
|
|
10
|
+
/**
|
|
11
|
+
* Execute a route.
|
|
12
|
+
* @param {Signer} signer - The signer required to send the transactions.
|
|
13
|
+
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
14
|
+
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
15
|
+
* @return {Promise<Route>} The executed route.
|
|
16
|
+
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
17
|
+
*/
|
|
18
|
+
executeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
19
|
+
/**
|
|
20
|
+
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
21
|
+
* @param {Signer} signer - The signer required to send the transactions.
|
|
22
|
+
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
23
|
+
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
24
|
+
* @return {Promise<Route>} The executed route.
|
|
25
|
+
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
26
|
+
*/
|
|
27
|
+
resumeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
28
|
+
private executeSteps;
|
|
29
|
+
/**
|
|
30
|
+
* Updates route execution to background or foreground state.
|
|
31
|
+
* @param {Route} route - A route that is currently in execution.
|
|
32
|
+
* @param {boolean} settings - An object with execution settings.
|
|
33
|
+
*/
|
|
34
|
+
updateRouteExecution: (route: Route, settings: Pick<ExecutionSettings, 'executeInBackground'>) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Update the ExecutionSettings for an active route.
|
|
37
|
+
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
38
|
+
* @param {Route} route - The active route that gets the new execution settings.
|
|
39
|
+
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
40
|
+
*/
|
|
41
|
+
updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
44
|
+
* @param {Route} route - A route that is currently in execution.
|
|
45
|
+
* @deprecated use updateRouteExecution instead.
|
|
46
|
+
*/
|
|
47
|
+
moveExecutionToBackground: (route: Route) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Stops the execution of an active route.
|
|
50
|
+
* @param {Route} route - A route that is currently in execution.
|
|
51
|
+
* @return {Route} The stopped route.
|
|
52
|
+
*/
|
|
53
|
+
stopExecution: (route: Route) => Route;
|
|
54
|
+
/**
|
|
55
|
+
* Get the list of active routes.
|
|
56
|
+
* @return {Route[]} A list of routes.
|
|
57
|
+
*/
|
|
58
|
+
getActiveRoutes: () => Route[];
|
|
59
|
+
/**
|
|
60
|
+
* Return the current route information for given route. The route has to be active.
|
|
61
|
+
* @param {Route} route - A route object.
|
|
62
|
+
* @return {Route} The updated route.
|
|
63
|
+
*/
|
|
64
|
+
getActiveRoute: (route: Route) => Route | undefined;
|
|
65
|
+
}
|