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