@lifi/sdk 4.0.0-alpha.16 → 4.0.0-alpha.18
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/cjs/core/BaseStepExecutor.d.ts +4 -1
- package/dist/cjs/core/BaseStepExecutor.js +35 -6
- package/dist/cjs/core/BaseStepExecutor.js.map +1 -1
- package/dist/cjs/core/StatusManager.d.ts +7 -8
- package/dist/cjs/core/StatusManager.js +14 -19
- package/dist/cjs/core/StatusManager.js.map +1 -1
- package/dist/cjs/core/TaskPipeline.js +9 -28
- package/dist/cjs/core/TaskPipeline.js.map +1 -1
- package/dist/cjs/core/tasks/CheckBalanceTask.js +2 -1
- package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +1 -1
- package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
- package/dist/cjs/types/core.d.ts +10 -5
- package/dist/cjs/types/execution.d.ts +1 -4
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/core/BaseStepExecutor.d.ts +4 -1
- package/dist/esm/core/BaseStepExecutor.js +35 -6
- package/dist/esm/core/BaseStepExecutor.js.map +1 -1
- package/dist/esm/core/StatusManager.d.ts +17 -26
- package/dist/esm/core/StatusManager.js +24 -37
- package/dist/esm/core/StatusManager.js.map +1 -1
- package/dist/esm/core/TaskPipeline.js +9 -28
- package/dist/esm/core/TaskPipeline.js.map +1 -1
- package/dist/esm/core/tasks/CheckBalanceTask.js +2 -1
- package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +1 -1
- package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -1
- package/dist/esm/types/core.d.ts +10 -5
- package/dist/esm/types/execution.d.ts +1 -4
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/core/BaseStepExecutor.d.ts +4 -1
- package/dist/types/core/BaseStepExecutor.d.ts.map +1 -1
- package/dist/types/core/StatusManager.d.ts +17 -26
- package/dist/types/core/StatusManager.d.ts.map +1 -1
- package/dist/types/core/TaskPipeline.d.ts.map +1 -1
- package/dist/types/core/tasks/CheckBalanceTask.d.ts.map +1 -1
- package/dist/types/types/core.d.ts +10 -5
- package/dist/types/types/core.d.ts.map +1 -1
- package/dist/types/types/execution.d.ts +1 -4
- package/dist/types/types/execution.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/core/BaseStepExecutor.ts +46 -7
- package/src/core/StatusManager.ts +31 -45
- package/src/core/TaskPipeline.ts +10 -29
- package/src/core/tasks/CheckBalanceTask.ts +2 -1
- package/src/core/tasks/WaitForTransactionStatusTask.ts +1 -1
- package/src/types/core.ts +4 -1
- package/src/types/execution.ts +0 -8
- package/src/version.ts +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExecuteStepRetryError } from '../errors/errors.js';
|
|
2
|
+
import type { SDKError } from '../errors/SDKError.js';
|
|
3
|
+
import type { ExecuteStepRetryParams, ExecutionAction, ExecutionOptions, InteractionSettings, LiFiStepExtended, SDKClient, StepExecutor, StepExecutorOptions } from '../types/core.js';
|
|
2
4
|
import type { StepExecutorBaseContext, StepExecutorContext } from '../types/execution.js';
|
|
3
5
|
import { StatusManager } from './StatusManager.js';
|
|
4
6
|
import type { TaskPipeline } from './TaskPipeline.js';
|
|
@@ -12,5 +14,6 @@ export declare abstract class BaseStepExecutor implements StepExecutor {
|
|
|
12
14
|
private createBaseContext;
|
|
13
15
|
abstract createContext(baseContext: StepExecutorBaseContext): Promise<StepExecutorContext>;
|
|
14
16
|
abstract createPipeline(context: StepExecutorContext): TaskPipeline;
|
|
17
|
+
abstract parseErrors(error: Error, step?: LiFiStepExtended, action?: ExecutionAction, retryParams?: ExecuteStepRetryParams): Promise<SDKError | ExecuteStepRetryError>;
|
|
15
18
|
executeStep: (client: SDKClient, step: LiFiStepExtended, retryParams?: ExecuteStepRetryParams) => Promise<LiFiStepExtended>;
|
|
16
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseStepExecutor = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors/errors.js");
|
|
4
5
|
const StatusManager_js_1 = require("./StatusManager.js");
|
|
5
6
|
const defaultInteractionSettings = {
|
|
6
7
|
allowInteraction: true,
|
|
@@ -42,12 +43,40 @@ class BaseStepExecutor {
|
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
45
|
executeStep = async (client, step, retryParams) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
try {
|
|
47
|
+
step.execution = this.statusManager.initializeExecution(step);
|
|
48
|
+
const baseContext = await this.createBaseContext(client, step, retryParams);
|
|
49
|
+
const context = await this.createContext(baseContext);
|
|
50
|
+
const pipeline = this.createPipeline(context);
|
|
51
|
+
await pipeline.run(context);
|
|
52
|
+
return step;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const action = step.execution?.lastActionType
|
|
56
|
+
? this.statusManager.findAction(step, step.execution.lastActionType)
|
|
57
|
+
: undefined;
|
|
58
|
+
const parsed = await this.parseErrors(error, step, action, retryParams);
|
|
59
|
+
if (!(parsed instanceof errors_js_1.ExecuteStepRetryError)) {
|
|
60
|
+
if (action) {
|
|
61
|
+
this.statusManager.updateAction(step, action.type, 'FAILED', {
|
|
62
|
+
error: {
|
|
63
|
+
message: parsed.cause?.message,
|
|
64
|
+
code: parsed.code,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.statusManager.updateExecution(step, {
|
|
70
|
+
status: 'FAILED',
|
|
71
|
+
error: {
|
|
72
|
+
message: parsed.cause?.message,
|
|
73
|
+
code: parsed.code,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw parsed;
|
|
79
|
+
}
|
|
51
80
|
};
|
|
52
81
|
}
|
|
53
82
|
exports.BaseStepExecutor = BaseStepExecutor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseStepExecutor.js","sourceRoot":"","sources":["../../../src/core/BaseStepExecutor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"BaseStepExecutor.js","sourceRoot":"","sources":["../../../src/core/BaseStepExecutor.ts"],"names":[],"mappings":";;;AAAA,mDAA2D;AAgB3D,yDAAkD;AAIlD,MAAM,0BAA0B,GAAG;IACjC,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;CACrB,CAAA;AAED,MAAsB,gBAAgB;IAC1B,gBAAgB,CAAmB;IACnC,aAAa,CAAe;IAE/B,oBAAoB,GAAG,IAAI,CAAA;IAC3B,cAAc,GAAG,IAAI,CAAA;IAE5B,YAAY,OAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,IAAI,gCAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACvD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;IAClD,CAAC;IAED,cAAc,GAAG,CAAC,QAA8B,EAAQ,EAAE;QACxD,MAAM,mBAAmB,GAAG;YAC1B,GAAG,0BAA0B;YAC7B,GAAG,QAAQ;SACZ,CAAA;QACD,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,gBAAgB,CAAA;QAChE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAA;QACjE,IAAI,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,CAAA;IAC1D,CAAC,CAAA;IAEO,iBAAiB,GAAG,KAAK,EAC/B,MAAiB,E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BACpE,CAAC,CAAC,SAAS,CAAA;YACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;YACvE,IAAI,CAAC,CAAC,MAAM,YAAY,iCAAqB,CAAC,EAAE,CAAC;gBAC/C,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE;wBAC3D,KAAK,EAAE;4BACL,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO;4BAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;yBAClB;qBACF,CAAC,CAAA;gBACJ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE;wBACvC,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE;4BACL,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO;4BAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;yBAClB;qBACF,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YACD,MAAM,MAAM,CAAA;QACd,CAAC;IACH,CAAC,CAAA;CACF;AAvGD,4CAuGC"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import type { ChainId, LiFiStep } from '@lifi/types';
|
|
2
2
|
import type { Execution, ExecutionAction, ExecutionActionStatus, ExecutionActionType, LiFiStepExtended } from '../types/core.js';
|
|
3
|
-
type
|
|
3
|
+
type ActionProps = {
|
|
4
4
|
step: LiFiStepExtended;
|
|
5
5
|
type: ExecutionActionType;
|
|
6
|
-
chainId
|
|
7
|
-
status
|
|
6
|
+
chainId: ChainId;
|
|
7
|
+
status: ExecutionActionStatus;
|
|
8
8
|
};
|
|
9
9
|
export declare class StatusManager {
|
|
10
10
|
private readonly routeId;
|
|
11
11
|
private shouldUpdate;
|
|
12
12
|
constructor(routeId: string);
|
|
13
|
-
|
|
13
|
+
initializeExecution: (step: LiFiStepExtended) => Execution;
|
|
14
14
|
updateExecution(step: LiFiStepExtended, execution: Partial<Execution>): LiFiStep;
|
|
15
|
-
findAction(step: LiFiStepExtended, type: ExecutionActionType
|
|
16
|
-
createAction: ({ step, type, chainId, status, }:
|
|
17
|
-
|
|
15
|
+
findAction(step: LiFiStepExtended, type: ExecutionActionType): ExecutionAction | undefined;
|
|
16
|
+
createAction: ({ step, type, chainId, status, }: ActionProps) => ExecutionAction;
|
|
17
|
+
initializeAction: ({ step, type, chainId, status, }: ActionProps) => ExecutionAction;
|
|
18
18
|
updateAction: (step: LiFiStepExtended, type: ExecutionActionType, status: ExecutionActionStatus, params?: Partial<ExecutionAction & {
|
|
19
19
|
signedAt?: number;
|
|
20
20
|
}>) => ExecutionAction;
|
|
21
|
-
removeAction: (step: LiFiStepExtended, type: ExecutionActionType) => void;
|
|
22
21
|
updateStepInRoute: (step: LiFiStep) => LiFiStep;
|
|
23
22
|
allowUpdates(value: boolean): void;
|
|
24
23
|
}
|
|
@@ -9,7 +9,7 @@ class StatusManager {
|
|
|
9
9
|
constructor(routeId) {
|
|
10
10
|
this.routeId = routeId;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
initializeExecution = (step) => {
|
|
13
13
|
if (!step.execution) {
|
|
14
14
|
step.execution = {
|
|
15
15
|
startedAt: Date.now(),
|
|
@@ -22,6 +22,8 @@ class StatusManager {
|
|
|
22
22
|
step.execution.startedAt = Date.now();
|
|
23
23
|
step.execution.status = 'PENDING';
|
|
24
24
|
step.execution.signedAt = undefined;
|
|
25
|
+
step.execution.lastActionType = undefined;
|
|
26
|
+
step.execution.error = undefined;
|
|
25
27
|
this.updateStepInRoute(step);
|
|
26
28
|
}
|
|
27
29
|
return step.execution;
|
|
@@ -37,15 +39,11 @@ class StatusManager {
|
|
|
37
39
|
this.updateStepInRoute(step);
|
|
38
40
|
return step;
|
|
39
41
|
}
|
|
40
|
-
findAction(step, type
|
|
42
|
+
findAction(step, type) {
|
|
41
43
|
if (!step.execution?.actions) {
|
|
42
44
|
throw new Error("Execution hasn't been initialized.");
|
|
43
45
|
}
|
|
44
46
|
const action = step.execution.actions.find((p) => p.type === type);
|
|
45
|
-
if (action && status && action.status !== status) {
|
|
46
|
-
action.status = status;
|
|
47
|
-
this.updateStepInRoute(step);
|
|
48
|
-
}
|
|
49
47
|
return action;
|
|
50
48
|
}
|
|
51
49
|
createAction = ({ step, type, chainId, status, }) => {
|
|
@@ -54,8 +52,8 @@ class StatusManager {
|
|
|
54
52
|
}
|
|
55
53
|
const newAction = {
|
|
56
54
|
type,
|
|
57
|
-
message: (0, actionMessages_js_1.getActionMessage)(type, status
|
|
58
|
-
status
|
|
55
|
+
message: (0, actionMessages_js_1.getActionMessage)(type, status),
|
|
56
|
+
status,
|
|
59
57
|
chainId,
|
|
60
58
|
};
|
|
61
59
|
step.execution.actions.push(newAction);
|
|
@@ -63,10 +61,12 @@ class StatusManager {
|
|
|
63
61
|
this.updateStepInRoute(step);
|
|
64
62
|
return newAction;
|
|
65
63
|
};
|
|
66
|
-
|
|
67
|
-
const action = this.findAction(step, type
|
|
64
|
+
initializeAction = ({ step, type, chainId, status, }) => {
|
|
65
|
+
const action = this.findAction(step, type);
|
|
68
66
|
if (action) {
|
|
69
|
-
return
|
|
67
|
+
return this.updateAction(step, type, status, {
|
|
68
|
+
error: undefined,
|
|
69
|
+
});
|
|
70
70
|
}
|
|
71
71
|
return this.createAction({ step, type, chainId, status });
|
|
72
72
|
};
|
|
@@ -83,6 +83,9 @@ class StatusManager {
|
|
|
83
83
|
break;
|
|
84
84
|
case 'FAILED':
|
|
85
85
|
step.execution.status = 'FAILED';
|
|
86
|
+
if (params?.error) {
|
|
87
|
+
step.execution.error = params.error;
|
|
88
|
+
}
|
|
86
89
|
break;
|
|
87
90
|
case 'DONE':
|
|
88
91
|
break;
|
|
@@ -114,14 +117,6 @@ class StatusManager {
|
|
|
114
117
|
this.updateStepInRoute(step);
|
|
115
118
|
return currentAction;
|
|
116
119
|
};
|
|
117
|
-
removeAction = (step, type) => {
|
|
118
|
-
if (!step.execution) {
|
|
119
|
-
throw new Error("Execution hasn't been initialized.");
|
|
120
|
-
}
|
|
121
|
-
const index = step.execution.actions.findIndex((p) => p.type === type);
|
|
122
|
-
step.execution.actions.splice(index, 1);
|
|
123
|
-
this.updateStepInRoute(step);
|
|
124
|
-
};
|
|
125
120
|
updateStepInRoute = (step) => {
|
|
126
121
|
if (!this.shouldUpdate) {
|
|
127
122
|
return step;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusManager.js","sourceRoot":"","sources":["../../../src/core/StatusManager.ts"],"names":[],"mappings":";;;AAQA,2DAAsD;AACtD,2DAAoD;
|
|
1
|
+
{"version":3,"file":"StatusManager.js","sourceRoot":"","sources":["../../../src/core/StatusManager.ts"],"names":[],"mappings":";;;AAQA,2DAAsD;AACtD,2DAAoD;AAYpD,MAAa,aAAa;IACP,OAAO,CAAQ;IACxB,YAAY,GAAG,IAAI,CAAA;IAE3B,YAAY,OAAe;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAOD,mBAAmB,GAAG,CAAC,IAAsB,EAAa,EAAE;QAC1D,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG;gBACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,EAAE;aACZ,CAAA;YACD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;QAGD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACrC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,SAAS,CAAA;YACjC,IAAI,CAAC,SAAS,C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Aa,CAAA;IACtB,CAAC,CAAA;IAED,iBAAiB,GAAG,CAAC,IAAc,EAAY,EAAE;QAC/C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAAM,IAAI,GAAG,kCAAc,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAE7C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAC1C,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CACxC,CAAA;QAED,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;QAEzE,IAAI,CAAC,gBAAgB,EAAE,eAAe,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACpC,CAAC,CAAA;IAED,YAAY,CAAC,KAAc;QACzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;IAC3B,CAAC;CACF;AAnOD,sCAmOC"}
|
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TaskPipeline = void 0;
|
|
4
|
-
const errors_js_1 = require("../errors/errors.js");
|
|
5
4
|
class TaskPipeline {
|
|
6
5
|
tasks;
|
|
7
6
|
constructor(tasks) {
|
|
8
7
|
this.tasks = tasks;
|
|
9
8
|
}
|
|
10
9
|
async run(context) {
|
|
11
|
-
const { statusManager, step, parseErrors } = context;
|
|
12
10
|
for (const task of this.tasks) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
const result = await task.run(context);
|
|
19
|
-
if (result.status === 'PAUSED') {
|
|
20
|
-
return { status: 'PAUSED' };
|
|
21
|
-
}
|
|
22
|
-
if (result.context && typeof result.context === 'object') {
|
|
23
|
-
Object.assign(context, result.context);
|
|
24
|
-
}
|
|
11
|
+
const shouldRun = await task.shouldRun(context);
|
|
12
|
+
if (!shouldRun) {
|
|
13
|
+
continue;
|
|
25
14
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
statusManager.updateAction(step, action.type, 'FAILED', {
|
|
33
|
-
error: {
|
|
34
|
-
message: parsed.cause?.message,
|
|
35
|
-
code: parsed.code,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
throw parsed;
|
|
15
|
+
const result = await task.run(context);
|
|
16
|
+
if (result.status === 'PAUSED') {
|
|
17
|
+
return { status: 'PAUSED' };
|
|
18
|
+
}
|
|
19
|
+
if (result.context && typeof result.context === 'object') {
|
|
20
|
+
Object.assign(context, result.context);
|
|
40
21
|
}
|
|
41
22
|
}
|
|
42
23
|
return { status: 'COMPLETED' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskPipeline.js","sourceRoot":"","sources":["../../../src/core/TaskPipeline.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TaskPipeline.js","sourceRoot":"","sources":["../../../src/core/TaskPipeline.ts"],"names":[],"mappings":";;;AAGA,MAAa,YAAY;IACN,KAAK,CAAyB;IAE/C,YAAY,KAA8B;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAA4B;QACpC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,SAAQ;YACV,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACtC,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;YAC7B,CAAC;YACD,IAAI,MAAM,CAAC,OAAO,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACzD,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;IAChC,CAAC;CACF;AAxBD,oCAwBC"}
|
|
@@ -8,10 +8,11 @@ const checkBalance_js_1 = require("./helpers/checkBalance.js");
|
|
|
8
8
|
class CheckBalanceTask extends BaseStepExecutionTask_js_1.BaseStepExecutionTask {
|
|
9
9
|
async run(context) {
|
|
10
10
|
const { client, step, statusManager, isBridgeExecution } = context;
|
|
11
|
-
statusManager.
|
|
11
|
+
statusManager.initializeAction({
|
|
12
12
|
step,
|
|
13
13
|
type: isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP',
|
|
14
14
|
chainId: step.action.fromChainId,
|
|
15
|
+
status: 'STARTED',
|
|
15
16
|
});
|
|
16
17
|
const walletAddress = step.action.fromAddress;
|
|
17
18
|
if (!walletAddress) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckBalanceTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/CheckBalanceTask.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AACzD,sDAAyD;AAEzD,0EAAmE;AACnE,+DAAwD;AAExD,MAAa,gBAAiB,SAAQ,gDAAqB;IACzD,KAAK,CAAC,GAAG,CAAC,OAA4B;QACpC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAA;QAElE,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"CheckBalanceTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/CheckBalanceTask.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AACzD,sDAAyD;AAEzD,0EAAmE;AACnE,+DAAwD;AAExD,MAAa,gBAAiB,SAAQ,gDAAqB;IACzD,KAAK,CAAC,GAAG,CAAC,OAA4B;QACpC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAA;QAElE,aAAa,CAAC,gBAAgB,CAAC;YAC7B,IAAI;YACJ,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM;YAChD,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YAChC,MAAM,EAAE,SAAS;SAClB,CAAC,CAAA;QAEF,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAA;QAC7C,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,4BAAgB,CACxB,4BAAa,CAAC,aAAa,EAC3B,kCAAkC,CACnC,CAAA;QACH,CAAC;QAED,MAAM,IAAA,8BAAY,EAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;QAC/C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;IAChC,CAAC;CACF;AAtBD,4CAsBC"}
|
|
@@ -21,7 +21,7 @@ class WaitForTransactionStatusTask extends BaseStepExecutionTask_js_1.BaseStepEx
|
|
|
21
21
|
if (!transactionHash) {
|
|
22
22
|
throw new Error('Transaction hash is undefined.');
|
|
23
23
|
}
|
|
24
|
-
const action = statusManager.
|
|
24
|
+
const action = statusManager.initializeAction({
|
|
25
25
|
step,
|
|
26
26
|
type: this.actionType,
|
|
27
27
|
chainId: this.actionType === 'RECEIVING_CHAIN'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WaitForTransactionStatusTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/WaitForTransactionStatusTask.ts"],"names":[],"mappings":";;;AACA,4DAAyD;AACzD,sDAAyD;AAGzD,mFAAkF;AAClF,0EAAmE;AACnE,uFAAgF;AAEhF,MAAa,4BAA6B,SAAQ,gDAAqB;IAC5D,UAAU,CAAqB;IAExC,YAAY,UAA+B;QACzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAA4B;QACpC,MAAM,EACJ,MAAM,EACN,IAAI,EACJ,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,iBAAiB,GAClB,GAAG,OAAO,CAAA;QAIX,IAAI,eAAmC,CAAA;QACvC,IAAI,CAAC;YACH,MAAM,kBAAkB,GAAG,aAAa,CAAC,UAAU,CACjD,IAAI,EACJ,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAC3C,CAAA;YACD,eAAe,GAAG,kBAAkB,EAAE,MAAM,IAAI,kBAAkB,EAAE,MAAM,CAAA;YAG1E,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;YACnD,CAAC;YAED,MAAM,MAAM,GAAG,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"WaitForTransactionStatusTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/WaitForTransactionStatusTask.ts"],"names":[],"mappings":";;;AACA,4DAAyD;AACzD,sDAAyD;AAGzD,mFAAkF;AAClF,0EAAmE;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AAO,CAAM,EAAE,CAAC;YAChB,MAAM,WAAW,GAAG,MAAM,IAAA,sDAA2B,EACnD,MAAM,EACN,IAAI,EACJ,GAAG,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,eAAe,EAAE,CAChE,CAAA;YACD,MAAM,IAAI,4BAAgB,CACxB,4BAAa,CAAC,iBAAiB,EAC/B,WAAW;gBACT,mEAAmE,EACrE,CAAC,CACF,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAxGD,oEAwGC"}
|
package/dist/cjs/types/core.d.ts
CHANGED
|
@@ -142,16 +142,16 @@ export type ExecutionAction = {
|
|
|
142
142
|
substatus?: Substatus;
|
|
143
143
|
substatusMessage?: string;
|
|
144
144
|
chainId?: number;
|
|
145
|
-
error?: {
|
|
146
|
-
code: string | number;
|
|
147
|
-
message: string;
|
|
148
|
-
htmlMessage?: string;
|
|
149
|
-
};
|
|
150
145
|
txHash?: string;
|
|
151
146
|
txLink?: string;
|
|
152
147
|
taskId?: string;
|
|
153
148
|
txType?: TransactionMethodType;
|
|
154
149
|
txHex?: string;
|
|
150
|
+
error?: {
|
|
151
|
+
code: string | number;
|
|
152
|
+
message: string;
|
|
153
|
+
htmlMessage?: string;
|
|
154
|
+
};
|
|
155
155
|
};
|
|
156
156
|
export interface Execution {
|
|
157
157
|
startedAt: number;
|
|
@@ -166,5 +166,10 @@ export interface Execution {
|
|
|
166
166
|
gasCosts?: GasCost[];
|
|
167
167
|
internalTxLink?: string;
|
|
168
168
|
externalTxLink?: string;
|
|
169
|
+
error?: {
|
|
170
|
+
code: string | number;
|
|
171
|
+
message: string;
|
|
172
|
+
htmlMessage?: string;
|
|
173
|
+
};
|
|
169
174
|
}
|
|
170
175
|
export type TransactionMethodType = 'standard' | 'relayed' | 'batched';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ExtendedChain } from '@lifi/types';
|
|
2
2
|
import type { StatusManager } from '../core/StatusManager.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type { SDKError } from '../errors/SDKError.js';
|
|
5
|
-
import type { ExecuteStepRetryParams, ExecutionAction, ExecutionOptions, LiFiStepExtended, SDKClient } from './core.js';
|
|
3
|
+
import type { ExecuteStepRetryParams, ExecutionOptions, LiFiStepExtended, SDKClient } from './core.js';
|
|
6
4
|
export interface StepExecutorBaseContext {
|
|
7
5
|
statusManager: StatusManager;
|
|
8
6
|
executionOptions?: ExecutionOptions;
|
|
@@ -16,7 +14,6 @@ export interface StepExecutorBaseContext {
|
|
|
16
14
|
}
|
|
17
15
|
export interface StepExecutorContext extends StepExecutorBaseContext {
|
|
18
16
|
pollingIntervalMs?: number;
|
|
19
|
-
parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError | ExecuteStepRetryError>;
|
|
20
17
|
}
|
|
21
18
|
export interface TaskResult<TContext = Record<string, unknown>> {
|
|
22
19
|
status: TaskStatus;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "4.0.0-alpha.
|
|
2
|
+
export declare const version = "4.0.0-alpha.18";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExecuteStepRetryError } from '../errors/errors.js';
|
|
2
|
+
import type { SDKError } from '../errors/SDKError.js';
|
|
3
|
+
import type { ExecuteStepRetryParams, ExecutionAction, ExecutionOptions, InteractionSettings, LiFiStepExtended, SDKClient, StepExecutor, StepExecutorOptions } from '../types/core.js';
|
|
2
4
|
import type { StepExecutorBaseContext, StepExecutorContext } from '../types/execution.js';
|
|
3
5
|
import { StatusManager } from './StatusManager.js';
|
|
4
6
|
import type { TaskPipeline } from './TaskPipeline.js';
|
|
@@ -12,5 +14,6 @@ export declare abstract class BaseStepExecutor implements StepExecutor {
|
|
|
12
14
|
private createBaseContext;
|
|
13
15
|
abstract createContext(baseContext: StepExecutorBaseContext): Promise<StepExecutorContext>;
|
|
14
16
|
abstract createPipeline(context: StepExecutorContext): TaskPipeline;
|
|
17
|
+
abstract parseErrors(error: Error, step?: LiFiStepExtended, action?: ExecutionAction, retryParams?: ExecuteStepRetryParams): Promise<SDKError | ExecuteStepRetryError>;
|
|
15
18
|
executeStep: (client: SDKClient, step: LiFiStepExtended, retryParams?: ExecuteStepRetryParams) => Promise<LiFiStepExtended>;
|
|
16
19
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExecuteStepRetryError } from '../errors/errors.js';
|
|
1
2
|
import { StatusManager } from './StatusManager.js';
|
|
2
3
|
// Please be careful when changing the defaults as it may break the behavior (e.g., background execution)
|
|
3
4
|
const defaultInteractionSettings = {
|
|
@@ -40,12 +41,40 @@ export class BaseStepExecutor {
|
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
43
|
executeStep = async (client, step, retryParams) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
try {
|
|
45
|
+
step.execution = this.statusManager.initializeExecution(step);
|
|
46
|
+
const baseContext = await this.createBaseContext(client, step, retryParams);
|
|
47
|
+
const context = await this.createContext(baseContext);
|
|
48
|
+
const pipeline = this.createPipeline(context);
|
|
49
|
+
await pipeline.run(context);
|
|
50
|
+
return step;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const action = step.execution?.lastActionType
|
|
54
|
+
? this.statusManager.findAction(step, step.execution.lastActionType)
|
|
55
|
+
: undefined;
|
|
56
|
+
const parsed = await this.parseErrors(error, step, action, retryParams);
|
|
57
|
+
if (!(parsed instanceof ExecuteStepRetryError)) {
|
|
58
|
+
if (action) {
|
|
59
|
+
this.statusManager.updateAction(step, action.type, 'FAILED', {
|
|
60
|
+
error: {
|
|
61
|
+
message: parsed.cause?.message,
|
|
62
|
+
code: parsed.code,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.statusManager.updateExecution(step, {
|
|
68
|
+
status: 'FAILED',
|
|
69
|
+
error: {
|
|
70
|
+
message: parsed.cause?.message,
|
|
71
|
+
code: parsed.code,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw parsed;
|
|
77
|
+
}
|
|
49
78
|
};
|
|
50
79
|
}
|
|
51
80
|
//# sourceMappingURL=BaseStepExecutor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseStepExecutor.js","sourceRoot":"","sources":["../../../src/core/BaseStepExecutor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseStepExecutor.js","sourceRoot":"","sources":["../../../src/core/BaseStepExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAgB3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,yGAAyG;AACzG,MAAM,0BAA0B,GAAG;IACjC,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;CACrB,CAAA;AAED,MAAM,OAAgB,gBAAgB;IAC1B,gBAAgB,CAAmB;IACnC,aAAa,CAAe;IAE/B,oBAAoB,GAAG,IAAI,CAAA;IAC3B,cAAc,GAAG,IAAI,CAAA;IAE5B,YAAY,OAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACvD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;IAClD,CAAC;IAED,cAAc,GAAG,CAAC,QAA8B,EAAQ,EAAE;QACxD,MAAM,mBAAmB,GAAG;YAC1B,GAAG,0BAA0B;YAC7B,GAAG,QAAQ;SACZ,CAAA;QACD,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,gBAAgB,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b,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,cAAc;gBAC3C,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;gBACpE,CAAC,CAAC,SAAS,CAAA;YACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;YACvE,IAAI,CAAC,CAAC,MAAM,YAAY,qBAAqB,CAAC,EAAE,CAAC;gBAC/C,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE;wBAC3D,KAAK,EAAE;4BACL,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO;4BAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;yBAClB;qBACF,CAAC,CAAA;gBACJ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE;wBACvC,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE;4BACL,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO;4BAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;yBAClB;qBACF,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YACD,MAAM,MAAM,CAAA;QACd,CAAC;IACH,CAAC,CAAA;CACF"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { ChainId, LiFiStep } from '@lifi/types';
|
|
2
2
|
import type { Execution, ExecutionAction, ExecutionActionStatus, ExecutionActionType, LiFiStepExtended } from '../types/core.js';
|
|
3
|
-
type
|
|
3
|
+
type ActionProps = {
|
|
4
4
|
step: LiFiStepExtended;
|
|
5
5
|
type: ExecutionActionType;
|
|
6
|
-
chainId
|
|
7
|
-
status
|
|
6
|
+
chainId: ChainId;
|
|
7
|
+
status: ExecutionActionStatus;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
* Manages status updates of a route and provides various functions for tracking actions
|
|
11
|
-
* @param {string} routeId The route dd this StatusManger belongs to.
|
|
12
|
-
* @returns {StatusManager} An instance of StatusManager.
|
|
10
|
+
* Manages status updates of a route and provides various functions for tracking actions.
|
|
13
11
|
*/
|
|
14
12
|
export declare class StatusManager {
|
|
15
13
|
private readonly routeId;
|
|
@@ -17,14 +15,14 @@ export declare class StatusManager {
|
|
|
17
15
|
constructor(routeId: string);
|
|
18
16
|
/**
|
|
19
17
|
* Initializes the execution object of a Step.
|
|
20
|
-
* @param step
|
|
21
|
-
* @returns The initialized execution object for this step
|
|
18
|
+
* @param step The current step in execution
|
|
19
|
+
* @returns The initialized execution object for this step
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
initializeExecution: (step: LiFiStepExtended) => Execution;
|
|
24
22
|
/**
|
|
25
23
|
* Updates the execution object of a Step.
|
|
26
|
-
* @param step
|
|
27
|
-
* @param execution
|
|
24
|
+
* @param step The current step in execution
|
|
25
|
+
* @param execution Partial execution data to merge
|
|
28
26
|
* @returns The step with the updated execution object
|
|
29
27
|
*/
|
|
30
28
|
updateExecution(step: LiFiStepExtended, execution: Partial<Execution>): LiFiStep;
|
|
@@ -32,29 +30,28 @@ export declare class StatusManager {
|
|
|
32
30
|
* Finds an action of the specified type in the step's execution
|
|
33
31
|
* @param step The step to search in
|
|
34
32
|
* @param type The action type to find
|
|
35
|
-
* @param status Optional status to update the action with if found
|
|
36
33
|
* @returns The found action or undefined if not found
|
|
37
34
|
*/
|
|
38
|
-
findAction(step: LiFiStepExtended, type: ExecutionActionType
|
|
35
|
+
findAction(step: LiFiStepExtended, type: ExecutionActionType): ExecutionAction | undefined;
|
|
39
36
|
/**
|
|
40
37
|
* Create and push a new action into the execution.
|
|
41
|
-
* Caller is responsible for ensuring an action of this type does not already exist
|
|
38
|
+
* Caller is responsible for ensuring an action of this type does not already exist.
|
|
42
39
|
* @param step The step that should contain the new action.
|
|
43
40
|
* @param type Type of the action.
|
|
44
41
|
* @param chainId Chain Id of the action.
|
|
45
|
-
* @param status
|
|
42
|
+
* @param status The initial status for the new action.
|
|
46
43
|
* @returns The created action.
|
|
47
44
|
*/
|
|
48
|
-
createAction: ({ step, type, chainId, status, }:
|
|
45
|
+
createAction: ({ step, type, chainId, status, }: ActionProps) => ExecutionAction;
|
|
49
46
|
/**
|
|
50
|
-
* Find an existing action by type, or create
|
|
47
|
+
* Find an existing action by type and update it, or create a new one if none exists.
|
|
51
48
|
* @param step The step that should contain the action.
|
|
52
49
|
* @param type Type of the action. Used to identify already existing actions.
|
|
53
50
|
* @param chainId Chain Id of the action (used when creating).
|
|
54
|
-
* @param status
|
|
55
|
-
* @returns The
|
|
51
|
+
* @param status The status to set on the found or newly created action.
|
|
52
|
+
* @returns The updated or newly created action.
|
|
56
53
|
*/
|
|
57
|
-
|
|
54
|
+
initializeAction: ({ step, type, chainId, status, }: ActionProps) => ExecutionAction;
|
|
58
55
|
/**
|
|
59
56
|
* Update an action object.
|
|
60
57
|
* @param step The step where the action should be updated
|
|
@@ -66,12 +63,6 @@ export declare class StatusManager {
|
|
|
66
63
|
updateAction: (step: LiFiStepExtended, type: ExecutionActionType, status: ExecutionActionStatus, params?: Partial<ExecutionAction & {
|
|
67
64
|
signedAt?: number;
|
|
68
65
|
}>) => ExecutionAction;
|
|
69
|
-
/**
|
|
70
|
-
* Remove an action from the execution
|
|
71
|
-
* @param step The step where the action should be removed from
|
|
72
|
-
* @param type The action type to remove
|
|
73
|
-
*/
|
|
74
|
-
removeAction: (step: LiFiStepExtended, type: ExecutionActionType) => void;
|
|
75
66
|
updateStepInRoute: (step: LiFiStep) => LiFiStep;
|
|
76
67
|
allowUpdates(value: boolean): void;
|
|
77
68
|
}
|