@lifi/sdk 2.0.0-beta.3 → 2.0.0-beta.4

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 (33) hide show
  1. package/dist/{Lifi.d.ts → LiFi.d.ts} +4 -60
  2. package/dist/{Lifi.js → LiFi.js} +3 -213
  3. package/dist/cjs/{Lifi.d.ts → LiFi.d.ts} +4 -60
  4. package/dist/cjs/{Lifi.js → LiFi.js} +5 -214
  5. package/dist/cjs/execution/RouteExecutionManager.d.ts +65 -0
  6. package/dist/cjs/execution/RouteExecutionManager.js +220 -0
  7. package/dist/cjs/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
  8. package/dist/cjs/execution/{ExecutionManager.js → StepExecutionManager.js} +3 -3
  9. package/dist/cjs/execution/StepExecutor.d.ts +2 -2
  10. package/dist/cjs/execution/StepExecutor.js +4 -4
  11. package/dist/cjs/helpers.d.ts +1 -1
  12. package/dist/cjs/index.d.ts +1 -2
  13. package/dist/cjs/index.js +3 -6
  14. package/dist/cjs/services/ApiService.d.ts +1 -1
  15. package/dist/cjs/services/ApiService.js +10 -8
  16. package/dist/cjs/types/internal.types.d.ts +3 -7
  17. package/dist/cjs/version.d.ts +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/execution/RouteExecutionManager.d.ts +65 -0
  20. package/dist/execution/RouteExecutionManager.js +213 -0
  21. package/dist/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
  22. package/dist/execution/{ExecutionManager.js → StepExecutionManager.js} +1 -1
  23. package/dist/execution/StepExecutor.d.ts +2 -2
  24. package/dist/execution/StepExecutor.js +4 -4
  25. package/dist/helpers.d.ts +1 -1
  26. package/dist/index.d.ts +1 -2
  27. package/dist/index.js +1 -3
  28. package/dist/services/ApiService.d.ts +1 -1
  29. package/dist/services/ApiService.js +10 -8
  30. package/dist/types/internal.types.d.ts +3 -7
  31. package/dist/version.d.ts +1 -1
  32. package/dist/version.js +1 -1
  33. package/package.json +4 -4
@@ -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
+ }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RouteExecutionManager = void 0;
7
+ const ConfigService_1 = __importDefault(require("../services/ConfigService"));
8
+ const errors_1 = require("../utils/errors");
9
+ const preRestart_1 = require("../utils/preRestart");
10
+ const StatusManager_1 = require("./StatusManager");
11
+ const StepExecutor_1 = require("./StepExecutor");
12
+ class RouteExecutionManager {
13
+ constructor(configUpdate) {
14
+ this.executionDictionary = {};
15
+ this.executionPromiseDictionary = {};
16
+ /**
17
+ * Execute a route.
18
+ * @param {Signer} signer - The signer required to send the transactions.
19
+ * @param {Route} route - The route that should be executed. Cannot be an active route.
20
+ * @param {ExecutionSettings} settings - An object containing settings and callbacks.
21
+ * @return {Promise<Route>} The executed route.
22
+ * @throws {LifiError} Throws a LifiError if the execution fails.
23
+ */
24
+ this.executeRoute = async (signer, route, settings) => {
25
+ // Deep clone to prevent side effects
26
+ const clonedRoute = structuredClone(route);
27
+ let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
28
+ // Check if route is already running
29
+ if (executionPromise) {
30
+ return executionPromise;
31
+ }
32
+ executionPromise = this.executeSteps(signer, clonedRoute, settings);
33
+ this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
34
+ return executionPromise;
35
+ };
36
+ /**
37
+ * Resume the execution of a route that has been stopped or had an error while executing.
38
+ * @param {Signer} signer - The signer required to send the transactions.
39
+ * @param {Route} route - The route that is to be executed. Cannot be an active route.
40
+ * @param {ExecutionSettings} settings - An object containing settings and callbacks.
41
+ * @return {Promise<Route>} The executed route.
42
+ * @throws {LifiError} Throws a LifiError if the execution fails.
43
+ */
44
+ this.resumeRoute = async (signer, route, settings) => {
45
+ // Deep clone to prevent side effects
46
+ const clonedRoute = structuredClone(route);
47
+ const execution = this.executionDictionary[clonedRoute.id];
48
+ if (execution) {
49
+ const executionHalted = execution.executors.some((executor) => executor.executionStopped);
50
+ if (!executionHalted) {
51
+ // Check if we want to resume route execution in the background
52
+ this.updateRouteExecution(route, {
53
+ executeInBackground: settings?.executeInBackground,
54
+ });
55
+ const executionPromise = this.executionPromiseDictionary[clonedRoute.id];
56
+ return executionPromise ?? clonedRoute;
57
+ }
58
+ }
59
+ (0, preRestart_1.handlePreRestart)(clonedRoute);
60
+ const executionPromise = this.executeSteps(signer, clonedRoute, settings);
61
+ this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
62
+ return executionPromise;
63
+ };
64
+ this.executeSteps = async (signer, route, settings) => {
65
+ const config = this.configService.getConfig();
66
+ const execution = {
67
+ route,
68
+ executors: [],
69
+ settings: { ...config.defaultExecutionSettings, ...settings },
70
+ };
71
+ this.executionDictionary[route.id] = execution;
72
+ const statusManager = new StatusManager_1.StatusManager(route, execution.settings, (route) => {
73
+ if (this.executionDictionary[route.id]) {
74
+ execution.route = route;
75
+ }
76
+ });
77
+ // Loop over steps and execute them
78
+ for (let index = 0; index < route.steps.length; index++) {
79
+ const execution = this.executionDictionary[route.id];
80
+ // Check if execution has stopped in the meantime
81
+ if (!execution) {
82
+ break;
83
+ }
84
+ const step = route.steps[index];
85
+ const previousStep = route.steps[index - 1];
86
+ // Check if the step is already done
87
+ //
88
+ if (step.execution?.status === 'DONE') {
89
+ continue;
90
+ }
91
+ // Update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
92
+ if (previousStep?.execution?.toAmount) {
93
+ step.action.fromAmount = previousStep.execution.toAmount;
94
+ }
95
+ try {
96
+ const stepExecutor = new StepExecutor_1.StepExecutor(statusManager, execution.settings);
97
+ execution.executors.push(stepExecutor);
98
+ // Check if we want to execute this step in the background
99
+ this.updateRouteExecution(route, execution.settings);
100
+ const executedStep = await stepExecutor.executeStep(signer, step);
101
+ // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
102
+ if (executedStep.execution?.status !== 'DONE') {
103
+ this.stopExecution(route);
104
+ }
105
+ // Execution stopped during the current step, we don't want to continue to the next step so we return already
106
+ if (stepExecutor.executionStopped) {
107
+ return route;
108
+ }
109
+ }
110
+ catch (e) {
111
+ this.stopExecution(route);
112
+ throw e;
113
+ }
114
+ }
115
+ // Clean up after the execution
116
+ delete this.executionDictionary[route.id];
117
+ return route;
118
+ };
119
+ /**
120
+ * Updates route execution to background or foreground state.
121
+ * @param {Route} route - A route that is currently in execution.
122
+ * @param {boolean} settings - An object with execution settings.
123
+ */
124
+ this.updateRouteExecution = (route, settings) => {
125
+ const execution = this.executionDictionary[route.id];
126
+ if (!execution) {
127
+ return;
128
+ }
129
+ for (const executor of execution.executors) {
130
+ executor.setInteraction({
131
+ allowInteraction: !settings.executeInBackground,
132
+ allowUpdates: true,
133
+ });
134
+ }
135
+ // Update active route settings so we know what the current state of execution is
136
+ execution.settings = {
137
+ ...execution.settings,
138
+ ...settings,
139
+ };
140
+ };
141
+ /**
142
+ * Update the ExecutionSettings for an active route.
143
+ * @param {ExecutionSettings} settings - An object with execution settings.
144
+ * @param {Route} route - The active route that gets the new execution settings.
145
+ * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
146
+ */
147
+ this.updateExecutionSettings = (settings, route) => {
148
+ const execution = this.executionDictionary[route.id];
149
+ if (!execution) {
150
+ throw new errors_1.ValidationError("Can't set ExecutionSettings for the inactive route.");
151
+ }
152
+ const config = this.configService.getConfig();
153
+ execution.settings = {
154
+ ...config.defaultExecutionSettings,
155
+ ...settings,
156
+ };
157
+ };
158
+ /**
159
+ * Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
160
+ * @param {Route} route - A route that is currently in execution.
161
+ * @deprecated use updateRouteExecution instead.
162
+ */
163
+ this.moveExecutionToBackground = (route) => {
164
+ const execution = this.executionDictionary[route.id];
165
+ if (!execution) {
166
+ return;
167
+ }
168
+ for (const executor of execution.executors) {
169
+ executor.setInteraction({ allowInteraction: false, allowUpdates: true });
170
+ }
171
+ execution.settings = {
172
+ ...execution.settings,
173
+ executeInBackground: true,
174
+ };
175
+ };
176
+ /**
177
+ * Stops the execution of an active route.
178
+ * @param {Route} route - A route that is currently in execution.
179
+ * @return {Route} The stopped route.
180
+ */
181
+ this.stopExecution = (route) => {
182
+ const execution = this.executionDictionary[route.id];
183
+ if (!execution) {
184
+ return route;
185
+ }
186
+ for (const executor of execution.executors) {
187
+ executor.setInteraction({
188
+ allowInteraction: false,
189
+ allowUpdates: false,
190
+ stopExecution: true,
191
+ });
192
+ }
193
+ delete this.executionDictionary[route.id];
194
+ return route;
195
+ };
196
+ /**
197
+ * Get the list of active routes.
198
+ * @return {Route[]} A list of routes.
199
+ */
200
+ this.getActiveRoutes = () => {
201
+ return Object.values(this.executionDictionary)
202
+ .map((dict) => dict?.route)
203
+ .filter(Boolean);
204
+ };
205
+ /**
206
+ * Return the current route information for given route. The route has to be active.
207
+ * @param {Route} route - A route object.
208
+ * @return {Route} The updated route.
209
+ */
210
+ this.getActiveRoute = (route) => {
211
+ return this.executionDictionary[route.id]?.route;
212
+ };
213
+ this.configService = ConfigService_1.default.getInstance();
214
+ if (configUpdate) {
215
+ // Update API urls before we request chains
216
+ this.configService.updateConfig(configUpdate);
217
+ }
218
+ }
219
+ }
220
+ exports.RouteExecutionManager = RouteExecutionManager;
@@ -1,6 +1,6 @@
1
1
  import { Execution } from '@lifi/types';
2
2
  import { ExecutionParams } from '../types';
3
- export declare class ExecutionManager {
3
+ export declare class StepExecutionManager {
4
4
  allowUserInteraction: boolean;
5
5
  allowInteraction: (value: boolean) => void;
6
6
  execute: ({ signer, step, statusManager, settings, }: ExecutionParams) => Promise<Execution>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ExecutionManager = void 0;
6
+ exports.StepExecutionManager = void 0;
7
7
  const allowance_1 = require("../allowance");
8
8
  const balance_1 = require("../balance");
9
9
  const ApiService_1 = __importDefault(require("../services/ApiService"));
@@ -15,7 +15,7 @@ const utils_1 = require("../utils/utils");
15
15
  const stepComparison_1 = require("./stepComparison");
16
16
  const switchChain_1 = require("./switchChain");
17
17
  const utils_2 = require("./utils");
18
- class ExecutionManager {
18
+ class StepExecutionManager {
19
19
  constructor() {
20
20
  this.allowUserInteraction = true;
21
21
  this.allowInteraction = (value) => {
@@ -172,4 +172,4 @@ class ExecutionManager {
172
172
  };
173
173
  }
174
174
  }
175
- exports.ExecutionManager = ExecutionManager;
175
+ exports.StepExecutionManager = StepExecutionManager;
@@ -1,9 +1,9 @@
1
1
  import { Signer } from 'ethers';
2
2
  import { InteractionSettings, InternalExecutionSettings, Step } from '../types';
3
- import { ExecutionManager } from './ExecutionManager';
4
3
  import { StatusManager } from './StatusManager';
4
+ import { StepExecutionManager } from './StepExecutionManager';
5
5
  export declare class StepExecutor {
6
- executionManager: ExecutionManager;
6
+ stepExecutionManager: StepExecutionManager;
7
7
  statusManager: StatusManager;
8
8
  settings: InternalExecutionSettings;
9
9
  allowUserInteraction: boolean;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StepExecutor = void 0;
4
- const ExecutionManager_1 = require("./ExecutionManager");
4
+ const StepExecutionManager_1 = require("./StepExecutionManager");
5
5
  const switchChain_1 = require("./switchChain");
6
6
  // Please be careful when changing the defaults as it may break the behavior (e.g., background execution)
7
7
  const defaultInteractionSettings = {
@@ -19,7 +19,7 @@ class StepExecutor {
19
19
  ...settings,
20
20
  };
21
21
  this.allowUserInteraction = interactionSettings.allowInteraction;
22
- this.executionManager.allowInteraction(interactionSettings.allowInteraction);
22
+ this.stepExecutionManager.allowInteraction(interactionSettings.allowInteraction);
23
23
  this.statusManager.allowUpdates(interactionSettings.allowUpdates);
24
24
  this.executionStopped = interactionSettings.stopExecution;
25
25
  };
@@ -43,10 +43,10 @@ class StepExecutor {
43
43
  settings: this.settings,
44
44
  statusManager: this.statusManager,
45
45
  };
46
- await this.executionManager.execute(parameters);
46
+ await this.stepExecutionManager.execute(parameters);
47
47
  return step;
48
48
  };
49
- this.executionManager = new ExecutionManager_1.ExecutionManager();
49
+ this.stepExecutionManager = new StepExecutionManager_1.StepExecutionManager();
50
50
  this.statusManager = statusManager;
51
51
  this.settings = settings;
52
52
  }
@@ -27,4 +27,4 @@ export declare const convertQuoteToRoute: (step: Step) => Route;
27
27
  export declare const requestSettings: {
28
28
  retries: number;
29
29
  };
30
- export declare const request: <T = Response>(url: string, options?: RequestInit, retries?: number) => Promise<T>;
30
+ export declare const request: <T = Response>(url: RequestInfo | URL, options?: RequestInit, retries?: number) => Promise<T>;
@@ -1,6 +1,5 @@
1
- import LIFI from './Lifi';
2
1
  export * from './execution';
3
2
  export * from './helpers';
3
+ export { LiFi } from './LiFi';
4
4
  export * from './types';
5
5
  export * from './utils/errors';
6
- export default LIFI;
package/dist/cjs/index.js CHANGED
@@ -13,15 +13,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.LiFi = void 0;
20
18
  // expose types and helpers
21
- const Lifi_1 = __importDefault(require("./Lifi"));
22
19
  __exportStar(require("./execution"), exports);
23
20
  __exportStar(require("./helpers"), exports);
21
+ var LiFi_1 = require("./LiFi");
22
+ Object.defineProperty(exports, "LiFi", { enumerable: true, get: function () { return LiFi_1.LiFi; } });
24
23
  __exportStar(require("./types"), exports);
25
24
  __exportStar(require("./utils/errors"), exports);
26
- // expose sdk
27
- exports.default = Lifi_1.default;
@@ -3,7 +3,7 @@ import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesRe
3
3
  declare const _default: {
4
4
  getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
5
5
  getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<Step>;
6
- getGasRecommendation: (requestConfig: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
6
+ getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
7
7
  getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
8
8
  getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<Step>;
9
9
  getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
@@ -277,18 +277,20 @@ const getTokens = async (requestConfig, options) => {
277
277
  });
278
278
  return response;
279
279
  };
280
- const getGasRecommendation = async (requestConfig, options) => {
280
+ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options) => {
281
281
  const config = ConfigService_1.default.getInstance().getConfig();
282
- Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
283
- delete requestConfig[key]);
284
- if (!requestConfig.chainId) {
282
+ if (!chainId) {
285
283
  throw new errors_1.ValidationError('Required parameter "chainId" is missing.');
286
284
  }
285
+ const url = new URL(`${config.apiUrl}/gas/suggestion/${chainId}`);
286
+ if (fromChain) {
287
+ url.searchParams.append('fromChain', fromChain);
288
+ }
289
+ if (fromToken) {
290
+ url.searchParams.append('fromToken', fromToken);
291
+ }
287
292
  try {
288
- const response = await (0, helpers_1.request)(`${config.apiUrl}/gas/suggestion/${requestConfig.chainId}?${new URLSearchParams({
289
- fromChain: requestConfig.fromChain,
290
- fromToken: requestConfig.fromToken,
291
- })}`, {
293
+ const response = await (0, helpers_1.request)(url, {
292
294
  signal: options?.signal,
293
295
  });
294
296
  return response;
@@ -54,7 +54,7 @@ export interface ExchangeRateUpdateParams {
54
54
  newToAmount: string;
55
55
  }
56
56
  export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>;
57
- export interface ExecutionData {
57
+ export interface RouteExecutionData {
58
58
  route: Route;
59
59
  executors: StepExecutor[];
60
60
  settings: InternalExecutionSettings;
@@ -71,12 +71,8 @@ export interface InternalExecutionSettings {
71
71
  export type EnforcedObjectProperties<T> = T & {
72
72
  [P in keyof T]-?: T[P];
73
73
  };
74
- export interface ActiveRouteDictionary {
75
- [k: string]: {
76
- executionData: ExecutionData;
77
- executionPromise: Promise<Route>;
78
- };
79
- }
74
+ export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
75
+ export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
80
76
  export type RevokeTokenData = {
81
77
  token: Token;
82
78
  approvalAddress: string;
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.0.0-beta.3";
2
+ export declare const version = "2.0.0-beta.4";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/sdk';
5
- exports.version = '2.0.0-beta.3';
5
+ exports.version = '2.0.0-beta.4';
@@ -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
+ }