@lifi/sdk 1.1.2 → 1.1.5
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/CHANGELOG.md +11 -0
- package/dist/Lifi.js +179 -285
- package/dist/allowance/index.js +56 -148
- package/dist/allowance/utils.js +51 -116
- package/dist/balances/index.js +29 -92
- package/dist/balances/utils.js +108 -218
- package/dist/cjs/Lifi.d.ts +200 -0
- package/dist/cjs/Lifi.js +376 -0
- package/dist/cjs/allowance/index.d.ts +22 -0
- package/dist/cjs/allowance/index.js +78 -0
- package/dist/cjs/allowance/utils.d.ts +14 -0
- package/dist/cjs/allowance/utils.js +82 -0
- package/dist/cjs/balances/index.d.ts +11 -0
- package/dist/cjs/balances/index.js +46 -0
- package/dist/cjs/balances/utils.d.ts +5 -0
- package/dist/cjs/balances/utils.js +150 -0
- package/dist/cjs/connectors.d.ts +6 -0
- package/dist/cjs/connectors.js +77 -0
- package/dist/cjs/execution/StatusManager.d.ts +65 -0
- package/dist/cjs/execution/StatusManager.js +167 -0
- package/dist/cjs/execution/StepExecutor.d.ts +15 -0
- package/dist/cjs/execution/StepExecutor.js +74 -0
- package/dist/cjs/execution/allowance.execute.d.ts +4 -0
- package/dist/cjs/execution/allowance.execute.js +97 -0
- package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/cjs/execution/balanceCheck.execute.js +48 -0
- package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
- package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +17 -0
- package/dist/cjs/execution/stepComparison.d.ts +14 -0
- package/dist/cjs/execution/stepComparison.js +46 -0
- package/dist/cjs/execution/switchChain.d.ts +16 -0
- package/dist/cjs/execution/switchChain.js +58 -0
- package/dist/cjs/execution/utils.d.ts +6 -0
- package/dist/cjs/execution/utils.js +137 -0
- package/dist/cjs/helpers.d.ts +18 -0
- package/dist/cjs/helpers.js +54 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/services/ApiService.d.ts +15 -0
- package/dist/cjs/services/ApiService.js +272 -0
- package/dist/cjs/services/ChainsService.d.ts +11 -0
- package/dist/cjs/services/ChainsService.js +54 -0
- package/dist/cjs/services/ConfigService.d.ts +23 -0
- package/dist/cjs/services/ConfigService.js +98 -0
- package/dist/cjs/typeguards.d.ts +4 -0
- package/dist/cjs/typeguards.js +53 -0
- package/dist/cjs/types/ERC20.d.ts +22 -0
- package/dist/cjs/types/ERC20.js +53 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/internal.types.d.ts +85 -0
- package/dist/cjs/types/internal.types.js +2 -0
- package/dist/cjs/utils/errors.d.ts +75 -0
- package/dist/cjs/utils/errors.js +115 -0
- package/dist/cjs/utils/getProvider.d.ts +3 -0
- package/dist/cjs/utils/getProvider.js +11 -0
- package/dist/cjs/utils/multicall.d.ts +10 -0
- package/dist/cjs/utils/multicall.js +77 -0
- package/dist/cjs/utils/multicallAbi.json +313 -0
- package/dist/cjs/utils/parseError.d.ts +38 -0
- package/dist/cjs/utils/parseError.js +141 -0
- package/dist/cjs/utils/preRestart.d.ts +2 -0
- package/dist/cjs/utils/preRestart.js +31 -0
- package/dist/cjs/utils/utils.d.ts +26 -0
- package/dist/cjs/utils/utils.js +120 -0
- package/dist/connectors.js +50 -133
- package/dist/execution/StatusManager.js +34 -41
- package/dist/execution/StepExecutor.js +54 -123
- package/dist/execution/allowance.execute.js +76 -142
- package/dist/execution/balanceCheck.execute.js +29 -74
- package/dist/execution/bridges/bridge.execute.js +132 -221
- package/dist/execution/exchanges/swap.execute.js +142 -225
- package/dist/execution/index.js +1 -17
- package/dist/execution/stepComparison.js +22 -61
- package/dist/execution/switchChain.js +33 -81
- package/dist/execution/utils.js +60 -119
- package/dist/helpers.js +15 -53
- package/dist/index.js +6 -25
- package/dist/services/ApiService.js +248 -385
- package/dist/services/ChainsService.js +29 -89
- package/dist/services/ConfigService.js +47 -86
- package/dist/typeguards.js +13 -21
- package/dist/types/ERC20.js +1 -4
- package/dist/types/index.js +4 -22
- package/dist/types/internal.types.js +1 -2
- package/dist/utils/errors.js +47 -93
- package/dist/utils/getProvider.js +3 -7
- package/dist/utils/multicall.js +61 -117
- package/dist/utils/parseError.js +73 -141
- package/dist/utils/preRestart.js +14 -21
- package/dist/utils/utils.js +47 -130
- package/package.json +34 -11
package/dist/connectors.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,143 +7,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
var _a;
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.getMulticallAddress = exports.getRpcProvider = exports.getRpcUrls = exports.getRpcUrl = void 0;
|
|
44
|
-
var ethers_1 = require("ethers");
|
|
45
|
-
var _1 = require(".");
|
|
46
|
-
var types_1 = require("./types");
|
|
47
|
-
var ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
10
|
+
import { providers } from 'ethers';
|
|
11
|
+
import { getRandomNumber, ServerError } from '.';
|
|
12
|
+
import { ChainId } from './types';
|
|
13
|
+
import ConfigService from './services/ConfigService';
|
|
48
14
|
// cached providers
|
|
49
|
-
|
|
15
|
+
const chainProviders = {};
|
|
50
16
|
// Archive RPC Provider
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_a);
|
|
57
|
-
// RPC Urls
|
|
58
|
-
var getRpcUrl = function (chainId, archive) {
|
|
59
|
-
if (archive === void 0) { archive = false; }
|
|
60
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
-
var rpcUrls;
|
|
62
|
-
return __generator(this, function (_a) {
|
|
63
|
-
switch (_a.label) {
|
|
64
|
-
case 0: return [4 /*yield*/, (0, exports.getRpcUrls)(chainId, archive)];
|
|
65
|
-
case 1:
|
|
66
|
-
rpcUrls = _a.sent();
|
|
67
|
-
return [2 /*return*/, rpcUrls[0]];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
exports.getRpcUrl = getRpcUrl;
|
|
73
|
-
var getRpcUrls = function (chainId, archive) {
|
|
74
|
-
if (archive === void 0) { archive = false; }
|
|
75
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
-
var configService, config;
|
|
77
|
-
return __generator(this, function (_a) {
|
|
78
|
-
switch (_a.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
if (archive && archiveRpcs[chainId]) {
|
|
81
|
-
return [2 /*return*/, [archiveRpcs[chainId]]];
|
|
82
|
-
}
|
|
83
|
-
configService = ConfigService_1.default.getInstance();
|
|
84
|
-
return [4 /*yield*/, configService.getConfigAsync()];
|
|
85
|
-
case 1:
|
|
86
|
-
config = _a.sent();
|
|
87
|
-
return [2 /*return*/, config.rpcs[chainId]];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
17
|
+
const archiveRpcs = {
|
|
18
|
+
[ChainId.ETH]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/eth/mainnet/archive',
|
|
19
|
+
[ChainId.BSC]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/bsc/mainnet/archive',
|
|
20
|
+
[ChainId.POL]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/polygon/mainnet/archive',
|
|
21
|
+
[ChainId.FTM]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/fantom/mainnet',
|
|
91
22
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
23
|
+
// RPC Urls
|
|
24
|
+
export const getRpcUrl = (chainId, archive = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const rpcUrls = yield getRpcUrls(chainId, archive);
|
|
26
|
+
return rpcUrls[0];
|
|
27
|
+
});
|
|
28
|
+
export const getRpcUrls = (chainId, archive = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
if (archive && archiveRpcs[chainId]) {
|
|
30
|
+
return [archiveRpcs[chainId]];
|
|
31
|
+
}
|
|
32
|
+
const configService = ConfigService.getInstance();
|
|
33
|
+
const config = yield configService.getConfigAsync();
|
|
34
|
+
return config.rpcs[chainId];
|
|
35
|
+
});
|
|
36
|
+
const getRandomProvider = (providerList) => {
|
|
37
|
+
const index = getRandomNumber(0, providerList.length - 1);
|
|
95
38
|
return providerList[index];
|
|
96
39
|
};
|
|
97
40
|
// Provider
|
|
98
|
-
|
|
99
|
-
if (archive
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
new (_d.apply(_c, [void 0, _e.sent(), chainId]))()
|
|
113
|
-
]]))()];
|
|
114
|
-
case 2:
|
|
115
|
-
if (!!chainProviders[chainId]) return [3 /*break*/, 4];
|
|
116
|
-
chainProviders[chainId] = [];
|
|
117
|
-
return [4 /*yield*/, (0, exports.getRpcUrls)(chainId, archive)];
|
|
118
|
-
case 3:
|
|
119
|
-
urls = _e.sent();
|
|
120
|
-
urls.forEach(function (url) {
|
|
121
|
-
chainProviders[chainId].push(new ethers_1.providers.FallbackProvider([
|
|
122
|
-
new ethers_1.providers.StaticJsonRpcProvider(url, chainId),
|
|
123
|
-
]));
|
|
124
|
-
});
|
|
125
|
-
_e.label = 4;
|
|
126
|
-
case 4:
|
|
127
|
-
if (!chainProviders[chainId].length) {
|
|
128
|
-
throw new _1.ServerError("Unable to configure provider for chain ".concat(chainId));
|
|
129
|
-
}
|
|
130
|
-
return [2 /*return*/, getRandomProvider(chainProviders[chainId])];
|
|
131
|
-
}
|
|
41
|
+
export const getRpcProvider = (chainId, archive = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
if (archive && archiveRpcs[chainId]) {
|
|
43
|
+
// return archive PRC, but don't cache it
|
|
44
|
+
return new providers.FallbackProvider([
|
|
45
|
+
new providers.StaticJsonRpcProvider(yield getRpcUrl(chainId, archive), chainId),
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
if (!chainProviders[chainId]) {
|
|
49
|
+
chainProviders[chainId] = [];
|
|
50
|
+
const urls = yield getRpcUrls(chainId, archive);
|
|
51
|
+
urls.forEach((url) => {
|
|
52
|
+
chainProviders[chainId].push(new providers.FallbackProvider([
|
|
53
|
+
new providers.StaticJsonRpcProvider(url, chainId),
|
|
54
|
+
]));
|
|
132
55
|
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
56
|
+
}
|
|
57
|
+
if (!chainProviders[chainId].length) {
|
|
58
|
+
throw new ServerError(`Unable to configure provider for chain ${chainId}`);
|
|
59
|
+
}
|
|
60
|
+
return getRandomProvider(chainProviders[chainId]);
|
|
61
|
+
});
|
|
136
62
|
// Multicall
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
configService = ConfigService_1.default.getInstance();
|
|
143
|
-
return [4 /*yield*/, configService.getConfigAsync()];
|
|
144
|
-
case 1:
|
|
145
|
-
config = _a.sent();
|
|
146
|
-
return [2 /*return*/, config.multicallAddresses[chainId]];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}); };
|
|
150
|
-
exports.getMulticallAddress = getMulticallAddress;
|
|
63
|
+
export const getMulticallAddress = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const configService = ConfigService.getInstance();
|
|
65
|
+
const config = yield configService.getConfigAsync();
|
|
66
|
+
return config.multicallAddresses[chainId];
|
|
67
|
+
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var types_1 = require("../types");
|
|
5
|
-
var utils_1 = require("../utils/utils");
|
|
6
|
-
var utils_2 = require("./utils");
|
|
1
|
+
import { emptyExecution, } from '../types';
|
|
2
|
+
import { deepClone } from '../utils/utils';
|
|
3
|
+
import { getProcessMessage } from './utils';
|
|
7
4
|
/**
|
|
8
5
|
* Manages status updates of a route and provides various functions for tracking processes
|
|
9
6
|
* @param {Route} route The route this StatusManger belongs to.
|
|
@@ -11,26 +8,25 @@ var utils_2 = require("./utils");
|
|
|
11
8
|
* @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
|
|
12
9
|
* @return {StatusManager} An instance of StatusManager.
|
|
13
10
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _this = this;
|
|
11
|
+
export class StatusManager {
|
|
12
|
+
constructor(route, settings, internalUpdateRouteCallback) {
|
|
17
13
|
this.shouldUpdate = true;
|
|
18
14
|
/**
|
|
19
15
|
* Initializes the execution object of a Step.
|
|
20
16
|
* @param {Step} step The current step in execution
|
|
21
17
|
* @return {Execution} The initialized execution object for this step and a function to update this step
|
|
22
18
|
*/
|
|
23
|
-
this.initExecutionObject =
|
|
24
|
-
|
|
19
|
+
this.initExecutionObject = (step) => {
|
|
20
|
+
const currentExecution = step.execution || deepClone(emptyExecution);
|
|
25
21
|
if (!step.execution) {
|
|
26
22
|
step.execution = currentExecution;
|
|
27
23
|
step.execution.status = 'PENDING';
|
|
28
|
-
|
|
24
|
+
this.updateStepInRoute(step);
|
|
29
25
|
}
|
|
30
26
|
// Change status to PENDING after resuming from FAILED
|
|
31
27
|
if (currentExecution.status === 'FAILED') {
|
|
32
28
|
currentExecution.status = 'PENDING';
|
|
33
|
-
|
|
29
|
+
this.updateStepInRoute(step);
|
|
34
30
|
}
|
|
35
31
|
return currentExecution;
|
|
36
32
|
};
|
|
@@ -41,22 +37,22 @@ var StatusManager = /** @class */ (function () {
|
|
|
41
37
|
* @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
42
38
|
* @return {Process}
|
|
43
39
|
*/
|
|
44
|
-
this.findOrCreateProcess =
|
|
40
|
+
this.findOrCreateProcess = (type, step, status) => {
|
|
45
41
|
if (!step.execution || !step.execution.process) {
|
|
46
42
|
throw new Error("Execution hasn't been initialized.");
|
|
47
43
|
}
|
|
48
|
-
|
|
44
|
+
const process = step.execution.process.find((p) => p.type === type);
|
|
49
45
|
if (process) {
|
|
50
46
|
return process;
|
|
51
47
|
}
|
|
52
|
-
|
|
48
|
+
const newProcess = {
|
|
53
49
|
type: type,
|
|
54
50
|
startedAt: Date.now(),
|
|
55
|
-
message:
|
|
51
|
+
message: getProcessMessage(type, status !== null && status !== void 0 ? status : 'STARTED'),
|
|
56
52
|
status: status !== null && status !== void 0 ? status : 'STARTED',
|
|
57
53
|
};
|
|
58
54
|
step.execution.process.push(newProcess);
|
|
59
|
-
|
|
55
|
+
this.updateStepInRoute(step);
|
|
60
56
|
return newProcess;
|
|
61
57
|
};
|
|
62
58
|
/**
|
|
@@ -67,12 +63,12 @@ var StatusManager = /** @class */ (function () {
|
|
|
67
63
|
* @param {object} [params] Additional parameters to append to the process.
|
|
68
64
|
* @return {Process} The update process
|
|
69
65
|
*/
|
|
70
|
-
this.updateProcess =
|
|
66
|
+
this.updateProcess = (step, type, status, params) => {
|
|
71
67
|
var _a;
|
|
72
68
|
if (!step.execution) {
|
|
73
69
|
throw new Error("Can't update an empty step execution.");
|
|
74
70
|
}
|
|
75
|
-
|
|
71
|
+
const currentProcess = (_a = step === null || step === void 0 ? void 0 : step.execution) === null || _a === void 0 ? void 0 : _a.process.find((p) => p.type === type);
|
|
76
72
|
if (!currentProcess) {
|
|
77
73
|
throw new Error("Can't find a process for the given type.");
|
|
78
74
|
}
|
|
@@ -100,15 +96,14 @@ var StatusManager = /** @class */ (function () {
|
|
|
100
96
|
break;
|
|
101
97
|
}
|
|
102
98
|
currentProcess.status = status;
|
|
103
|
-
currentProcess.message =
|
|
99
|
+
currentProcess.message = getProcessMessage(type, status);
|
|
104
100
|
// set extra parameters or overwritte the standard params set in the switch statement
|
|
105
101
|
if (params) {
|
|
106
|
-
for (
|
|
107
|
-
var _c = _b[_i], key = _c[0], value = _c[1];
|
|
102
|
+
for (const [key, value] of Object.entries(params)) {
|
|
108
103
|
currentProcess[key] = value;
|
|
109
104
|
}
|
|
110
105
|
}
|
|
111
|
-
|
|
106
|
+
this.updateStepInRoute(step); // updates the step in the route
|
|
112
107
|
return currentProcess;
|
|
113
108
|
};
|
|
114
109
|
/**
|
|
@@ -117,26 +112,26 @@ var StatusManager = /** @class */ (function () {
|
|
|
117
112
|
* @param {ProcessType} type The process type to remove
|
|
118
113
|
* @return {void}
|
|
119
114
|
*/
|
|
120
|
-
this.removeProcess =
|
|
115
|
+
this.removeProcess = (step, type) => {
|
|
121
116
|
if (!step.execution) {
|
|
122
117
|
throw new Error("Execution hasn't been initialized.");
|
|
123
118
|
}
|
|
124
|
-
|
|
119
|
+
const index = step.execution.process.findIndex((p) => p.type === type);
|
|
125
120
|
step.execution.process.splice(index, 1);
|
|
126
|
-
|
|
121
|
+
this.updateStepInRoute(step);
|
|
127
122
|
};
|
|
128
|
-
this.updateStepInRoute =
|
|
129
|
-
if (!
|
|
123
|
+
this.updateStepInRoute = (step) => {
|
|
124
|
+
if (!this.shouldUpdate) {
|
|
130
125
|
return step;
|
|
131
126
|
}
|
|
132
|
-
|
|
127
|
+
const stepIndex = this.route.steps.findIndex((routeStep) => routeStep.id === step.id);
|
|
133
128
|
if (stepIndex === -1) {
|
|
134
129
|
throw new Error("Couldn't find a step to update.");
|
|
135
130
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return
|
|
131
|
+
this.route.steps[stepIndex] = Object.assign(this.route.steps[stepIndex], step);
|
|
132
|
+
this.settings.updateCallback(this.route);
|
|
133
|
+
this.internalUpdateRouteCallback(this.route);
|
|
134
|
+
return this.route.steps[stepIndex];
|
|
140
135
|
};
|
|
141
136
|
this.route = route;
|
|
142
137
|
this.settings = settings;
|
|
@@ -149,7 +144,7 @@ var StatusManager = /** @class */ (function () {
|
|
|
149
144
|
* @param {Receipt} receipt Optional. Information about received tokens
|
|
150
145
|
* @return {Step} The step with the updated execution object
|
|
151
146
|
*/
|
|
152
|
-
|
|
147
|
+
updateExecution(step, status, receipt) {
|
|
153
148
|
if (!step.execution) {
|
|
154
149
|
throw Error("Can't update empty execution.");
|
|
155
150
|
}
|
|
@@ -161,10 +156,8 @@ var StatusManager = /** @class */ (function () {
|
|
|
161
156
|
}
|
|
162
157
|
this.updateStepInRoute(step);
|
|
163
158
|
return step;
|
|
164
|
-
}
|
|
165
|
-
|
|
159
|
+
}
|
|
160
|
+
setShouldUpdate(value) {
|
|
166
161
|
this.shouldUpdate = value;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}());
|
|
170
|
-
exports.StatusManager = StatusManager;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -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,121 +7,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
8
|
});
|
|
21
9
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.StepExecutor = void 0;
|
|
51
|
-
var bridge_execute_1 = require("./bridges/bridge.execute");
|
|
52
|
-
var swap_execute_1 = require("./exchanges/swap.execute");
|
|
53
|
-
var switchChain_1 = require("./switchChain");
|
|
54
|
-
var defaultExecutionHaltSettings = {
|
|
10
|
+
import { BridgeExecutionManager } from './bridges/bridge.execute';
|
|
11
|
+
import { SwapExecutionManager } from './exchanges/swap.execute';
|
|
12
|
+
import { switchChain } from './switchChain';
|
|
13
|
+
const defaultExecutionHaltSettings = {
|
|
55
14
|
allowUpdates: true,
|
|
56
15
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
this.bridgeExecutionManager = new bridge_execute_1.BridgeExecutionManager();
|
|
16
|
+
export class StepExecutor {
|
|
17
|
+
constructor(statusManager, settings) {
|
|
18
|
+
this.swapExecutionManager = new SwapExecutionManager();
|
|
19
|
+
this.bridgeExecutionManager = new BridgeExecutionManager();
|
|
62
20
|
this.executionStopped = false;
|
|
63
|
-
this.stopStepExecution =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
21
|
+
this.stopStepExecution = (settings) => {
|
|
22
|
+
const haltingSettings = Object.assign(Object.assign({}, defaultExecutionHaltSettings), settings);
|
|
23
|
+
this.swapExecutionManager.setShouldContinue(false);
|
|
24
|
+
this.bridgeExecutionManager.setShouldContinue(false);
|
|
25
|
+
this.statusManager.setShouldUpdate(haltingSettings.allowUpdates);
|
|
26
|
+
this.executionStopped = true;
|
|
69
27
|
};
|
|
70
|
-
this.executeStep =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
step: step,
|
|
110
|
-
settings: this.settings,
|
|
111
|
-
statusManager: this.statusManager,
|
|
112
|
-
};
|
|
113
|
-
return [4 /*yield*/, this.swapExecutionManager.execute(swapParams)];
|
|
114
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); };
|
|
118
|
-
this.executeCross = function (signer, step) { return __awaiter(_this, void 0, void 0, function () {
|
|
119
|
-
var crossParams;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
crossParams = {
|
|
124
|
-
signer: signer,
|
|
125
|
-
step: step,
|
|
126
|
-
settings: this.settings,
|
|
127
|
-
statusManager: this.statusManager,
|
|
128
|
-
};
|
|
129
|
-
return [4 /*yield*/, this.bridgeExecutionManager.execute(crossParams)];
|
|
130
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}); };
|
|
28
|
+
this.executeStep = (signer, step) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// check if signer is for correct chain
|
|
30
|
+
const updatedSigner = yield switchChain(signer, this.statusManager, step, this.settings.switchChainHook, !this.executionStopped);
|
|
31
|
+
if (!updatedSigner) {
|
|
32
|
+
// chain switch was not successful, stop execution here
|
|
33
|
+
return step;
|
|
34
|
+
}
|
|
35
|
+
signer = updatedSigner;
|
|
36
|
+
switch (step.type) {
|
|
37
|
+
case 'lifi':
|
|
38
|
+
case 'cross':
|
|
39
|
+
yield this.executeCross(signer, step);
|
|
40
|
+
break;
|
|
41
|
+
case 'swap':
|
|
42
|
+
yield this.executeSwap(signer, step);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
throw new Error('Unsupported step type.');
|
|
46
|
+
}
|
|
47
|
+
return step;
|
|
48
|
+
});
|
|
49
|
+
this.executeSwap = (signer, step) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const swapParams = {
|
|
51
|
+
signer,
|
|
52
|
+
step,
|
|
53
|
+
settings: this.settings,
|
|
54
|
+
statusManager: this.statusManager,
|
|
55
|
+
};
|
|
56
|
+
return yield this.swapExecutionManager.execute(swapParams);
|
|
57
|
+
});
|
|
58
|
+
this.executeCross = (signer, step) => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const crossParams = {
|
|
60
|
+
signer,
|
|
61
|
+
step,
|
|
62
|
+
settings: this.settings,
|
|
63
|
+
statusManager: this.statusManager,
|
|
64
|
+
};
|
|
65
|
+
return yield this.bridgeExecutionManager.execute(crossParams);
|
|
66
|
+
});
|
|
134
67
|
this.statusManager = statusManager;
|
|
135
68
|
this.settings = settings;
|
|
136
69
|
}
|
|
137
|
-
|
|
138
|
-
}());
|
|
139
|
-
exports.StepExecutor = StepExecutor;
|
|
70
|
+
}
|