@lifi/sdk 1.0.1 → 1.1.1
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 +26 -0
- package/dist/Lifi.d.ts +15 -1
- package/dist/Lifi.js +25 -10
- package/dist/execution/StatusManager.d.ts +3 -1
- package/dist/execution/StatusManager.js +16 -1
- package/dist/execution/allowance.execute.js +9 -9
- package/dist/execution/bridges/bridge.execute.js +70 -52
- package/dist/execution/exchanges/swap.execute.js +75 -57
- package/dist/execution/stepComparison.d.ts +14 -0
- package/dist/execution/stepComparison.js +81 -0
- package/dist/execution/switchChain.js +2 -2
- package/dist/execution/utils.d.ts +1 -0
- package/dist/execution/utils.js +12 -1
- package/dist/services/ApiService.d.ts +3 -2
- package/dist/services/ApiService.js +126 -72
- package/dist/services/ConfigService.js +1 -0
- package/dist/types/internal.types.d.ts +13 -3
- package/dist/utils/errors.d.ts +3 -1
- package/dist/utils/errors.js +2 -0
- package/dist/utils/parseError.d.ts +1 -0
- package/dist/utils/parseError.js +40 -26
- package/dist/utils/preRestart.d.ts +2 -0
- package/dist/utils/preRestart.js +34 -0
- package/package.json +2 -2
|
@@ -117,73 +117,126 @@ var getToken = function (chain, token, options) { return __awaiter(void 0, void
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
}); };
|
|
120
|
-
var getQuote = function (
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!toChain) {
|
|
140
|
-
throw new errors_1.ValidationError('Required parameter "toChain" is missing.');
|
|
120
|
+
var getQuote = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
+
var configService, config, requiredParameters, result, e_3;
|
|
122
|
+
var _a, _b, _c, _d, _e, _f;
|
|
123
|
+
return __generator(this, function (_g) {
|
|
124
|
+
switch (_g.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
configService = ConfigService_1.default.getInstance();
|
|
127
|
+
config = configService.getConfig();
|
|
128
|
+
requiredParameters = [
|
|
129
|
+
'fromChain',
|
|
130
|
+
'fromToken',
|
|
131
|
+
'fromAddress',
|
|
132
|
+
'fromAmount',
|
|
133
|
+
'toChain',
|
|
134
|
+
'toToken',
|
|
135
|
+
];
|
|
136
|
+
requiredParameters.forEach(function (requiredParameter) {
|
|
137
|
+
if (!request[requiredParameter]) {
|
|
138
|
+
throw new errors_1.ValidationError("Required parameter \"".concat(requiredParameter, "\" is missing."));
|
|
141
139
|
}
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
});
|
|
141
|
+
// apply defaults
|
|
142
|
+
request.order = request.order || config.defaultRouteOptions.order;
|
|
143
|
+
request.slippage = request.slippage || config.defaultRouteOptions.slippage;
|
|
144
|
+
request.integrator =
|
|
145
|
+
request.integrator || config.defaultRouteOptions.integrator;
|
|
146
|
+
request.referrer = request.referrer || config.defaultRouteOptions.referrer;
|
|
147
|
+
request.fee = request.fee || config.defaultRouteOptions.fee;
|
|
148
|
+
request.allowBridges =
|
|
149
|
+
request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
|
|
150
|
+
request.denyBridges =
|
|
151
|
+
request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
|
|
152
|
+
request.preferBridges =
|
|
153
|
+
request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
|
|
154
|
+
request.allowExchanges =
|
|
155
|
+
request.allowExchanges || ((_d = config.defaultRouteOptions.bridges) === null || _d === void 0 ? void 0 : _d.allow);
|
|
156
|
+
request.denyExchanges =
|
|
157
|
+
request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
|
|
158
|
+
request.preferExchanges =
|
|
159
|
+
request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
|
|
160
|
+
_g.label = 1;
|
|
161
|
+
case 1:
|
|
162
|
+
_g.trys.push([1, 3, , 4]);
|
|
163
|
+
return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'quote', {
|
|
164
|
+
params: request,
|
|
165
|
+
signal: options === null || options === void 0 ? void 0 : options.signal,
|
|
166
|
+
})];
|
|
167
|
+
case 2:
|
|
168
|
+
result = _g.sent();
|
|
169
|
+
return [2 /*return*/, result.data];
|
|
170
|
+
case 3:
|
|
171
|
+
e_3 = _g.sent();
|
|
172
|
+
throw (0, parseError_1.parseBackendError)(e_3);
|
|
173
|
+
case 4: return [2 /*return*/];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}); };
|
|
177
|
+
var getContractCallQuote = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
178
|
+
var configService, config, requiredParameters, result, e_4;
|
|
179
|
+
var _a, _b, _c, _d, _e, _f;
|
|
180
|
+
return __generator(this, function (_g) {
|
|
181
|
+
switch (_g.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
configService = ConfigService_1.default.getInstance();
|
|
184
|
+
config = configService.getConfig();
|
|
185
|
+
requiredParameters = [
|
|
186
|
+
'fromChain',
|
|
187
|
+
'fromToken',
|
|
188
|
+
'fromAddress',
|
|
189
|
+
'toChain',
|
|
190
|
+
'toToken',
|
|
191
|
+
'toAmount',
|
|
192
|
+
'toContractAddress',
|
|
193
|
+
'toContractCallData',
|
|
194
|
+
'toContractGasLimit',
|
|
195
|
+
];
|
|
196
|
+
requiredParameters.forEach(function (requiredParameter) {
|
|
197
|
+
if (!request[requiredParameter]) {
|
|
198
|
+
throw new errors_1.ValidationError("Required parameter \"".concat(requiredParameter, "\" is missing."));
|
|
144
199
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
});
|
|
200
|
+
});
|
|
201
|
+
// apply defaults
|
|
202
|
+
// option.order is not used in this endpoint
|
|
203
|
+
request.slippage = request.slippage || config.defaultRouteOptions.slippage;
|
|
204
|
+
request.integrator =
|
|
205
|
+
request.integrator || config.defaultRouteOptions.integrator;
|
|
206
|
+
request.referrer = request.referrer || config.defaultRouteOptions.referrer;
|
|
207
|
+
request.fee = request.fee || config.defaultRouteOptions.fee;
|
|
208
|
+
request.allowBridges =
|
|
209
|
+
request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
|
|
210
|
+
request.denyBridges =
|
|
211
|
+
request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
|
|
212
|
+
request.preferBridges =
|
|
213
|
+
request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
|
|
214
|
+
request.allowExchanges =
|
|
215
|
+
request.allowExchanges || ((_d = config.defaultRouteOptions.bridges) === null || _d === void 0 ? void 0 : _d.allow);
|
|
216
|
+
request.denyExchanges =
|
|
217
|
+
request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
|
|
218
|
+
request.preferExchanges =
|
|
219
|
+
request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
|
|
220
|
+
_g.label = 1;
|
|
221
|
+
case 1:
|
|
222
|
+
_g.trys.push([1, 3, , 4]);
|
|
223
|
+
return [4 /*yield*/, axios_1.default.post(config.apiUrl + 'quoteContractCall', request, {
|
|
224
|
+
signal: options === null || options === void 0 ? void 0 : options.signal,
|
|
225
|
+
})];
|
|
226
|
+
case 2:
|
|
227
|
+
result = _g.sent();
|
|
228
|
+
return [2 /*return*/, result.data];
|
|
229
|
+
case 3:
|
|
230
|
+
e_4 = _g.sent();
|
|
231
|
+
throw (0, parseError_1.parseBackendError)(e_4);
|
|
232
|
+
case 4: return [2 /*return*/];
|
|
233
|
+
}
|
|
181
234
|
});
|
|
182
|
-
};
|
|
235
|
+
}); };
|
|
183
236
|
var getStatus = function (_a, options) {
|
|
184
237
|
var bridge = _a.bridge, fromChain = _a.fromChain, toChain = _a.toChain, txHash = _a.txHash;
|
|
185
238
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
186
|
-
var configService, config, result,
|
|
239
|
+
var configService, config, result, e_5;
|
|
187
240
|
return __generator(this, function (_b) {
|
|
188
241
|
switch (_b.label) {
|
|
189
242
|
case 0:
|
|
@@ -217,15 +270,15 @@ var getStatus = function (_a, options) {
|
|
|
217
270
|
result = _b.sent();
|
|
218
271
|
return [2 /*return*/, result.data];
|
|
219
272
|
case 3:
|
|
220
|
-
|
|
221
|
-
throw (0, parseError_1.parseBackendError)(
|
|
273
|
+
e_5 = _b.sent();
|
|
274
|
+
throw (0, parseError_1.parseBackendError)(e_5);
|
|
222
275
|
case 4: return [2 /*return*/];
|
|
223
276
|
}
|
|
224
277
|
});
|
|
225
278
|
});
|
|
226
279
|
};
|
|
227
280
|
var getChains = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
228
|
-
var configService, config, result,
|
|
281
|
+
var configService, config, result, e_6;
|
|
229
282
|
return __generator(this, function (_a) {
|
|
230
283
|
switch (_a.label) {
|
|
231
284
|
case 0:
|
|
@@ -241,14 +294,14 @@ var getChains = function (options) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
241
294
|
result = _a.sent();
|
|
242
295
|
return [2 /*return*/, result.data.chains];
|
|
243
296
|
case 3:
|
|
244
|
-
|
|
245
|
-
throw (0, parseError_1.parseBackendError)(
|
|
297
|
+
e_6 = _a.sent();
|
|
298
|
+
throw (0, parseError_1.parseBackendError)(e_6);
|
|
246
299
|
case 4: return [2 /*return*/];
|
|
247
300
|
}
|
|
248
301
|
});
|
|
249
302
|
}); };
|
|
250
303
|
var getRoutes = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
251
|
-
var configService, config, result,
|
|
304
|
+
var configService, config, result, e_7;
|
|
252
305
|
return __generator(this, function (_a) {
|
|
253
306
|
switch (_a.label) {
|
|
254
307
|
case 0:
|
|
@@ -269,14 +322,14 @@ var getRoutes = function (request, options) { return __awaiter(void 0, void 0, v
|
|
|
269
322
|
result = _a.sent();
|
|
270
323
|
return [2 /*return*/, result.data];
|
|
271
324
|
case 3:
|
|
272
|
-
|
|
273
|
-
throw (0, parseError_1.parseBackendError)(
|
|
325
|
+
e_7 = _a.sent();
|
|
326
|
+
throw (0, parseError_1.parseBackendError)(e_7);
|
|
274
327
|
case 4: return [2 /*return*/];
|
|
275
328
|
}
|
|
276
329
|
});
|
|
277
330
|
}); };
|
|
278
331
|
var getStepTransaction = function (step, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
279
|
-
var configService, config, result,
|
|
332
|
+
var configService, config, result, e_8;
|
|
280
333
|
return __generator(this, function (_a) {
|
|
281
334
|
switch (_a.label) {
|
|
282
335
|
case 0:
|
|
@@ -297,8 +350,8 @@ var getStepTransaction = function (step, options) { return __awaiter(void 0, voi
|
|
|
297
350
|
result = _a.sent();
|
|
298
351
|
return [2 /*return*/, result.data];
|
|
299
352
|
case 3:
|
|
300
|
-
|
|
301
|
-
throw (0, parseError_1.parseBackendError)(
|
|
353
|
+
e_8 = _a.sent();
|
|
354
|
+
throw (0, parseError_1.parseBackendError)(e_8);
|
|
302
355
|
case 4: return [2 /*return*/];
|
|
303
356
|
}
|
|
304
357
|
});
|
|
@@ -341,6 +394,7 @@ exports.default = {
|
|
|
341
394
|
getPossibilities: getPossibilities,
|
|
342
395
|
getToken: getToken,
|
|
343
396
|
getQuote: getQuote,
|
|
397
|
+
getContractCallQuote: getContractCallQuote,
|
|
344
398
|
getStatus: getStatus,
|
|
345
399
|
getChains: getChains,
|
|
346
400
|
getRoutes: getRoutes,
|
|
@@ -41,6 +41,7 @@ var DefaultExecutionSettings = {
|
|
|
41
41
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
42
42
|
updateCallback: function () { },
|
|
43
43
|
switchChainHook: function () { return Promise.resolve(undefined); },
|
|
44
|
+
acceptSlippageUpdateHook: function () { return Promise.resolve(undefined); },
|
|
44
45
|
infiniteApproval: false,
|
|
45
46
|
};
|
|
46
47
|
var ConfigService = /** @class */ (function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Route, RouteOptions, Step, Token } from '@lifi/types';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ChainId } from '.';
|
|
@@ -23,10 +23,10 @@ interface ExecutionParams {
|
|
|
23
23
|
settings: InternalExecutionSettings;
|
|
24
24
|
}
|
|
25
25
|
export interface ExecuteSwapParams extends ExecutionParams {
|
|
26
|
-
step:
|
|
26
|
+
step: Step;
|
|
27
27
|
}
|
|
28
28
|
export interface ExecuteCrossParams extends ExecutionParams {
|
|
29
|
-
step:
|
|
29
|
+
step: Step;
|
|
30
30
|
}
|
|
31
31
|
export declare type CallbackFunction = (updatedRoute: Route) => void;
|
|
32
32
|
export declare type Config = {
|
|
@@ -44,6 +44,14 @@ export declare type ConfigUpdate = {
|
|
|
44
44
|
defaultRouteOptions?: RouteOptions;
|
|
45
45
|
};
|
|
46
46
|
export declare type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
47
|
+
export interface AcceptSlippageUpdateHookParams {
|
|
48
|
+
toToken: Token;
|
|
49
|
+
oldToAmount: string;
|
|
50
|
+
newToAmount: string;
|
|
51
|
+
oldSlippage: number;
|
|
52
|
+
newSlippage: number;
|
|
53
|
+
}
|
|
54
|
+
export declare type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>;
|
|
47
55
|
export interface ExecutionData {
|
|
48
56
|
route: Route;
|
|
49
57
|
executors: StepExecutor[];
|
|
@@ -52,11 +60,13 @@ export interface ExecutionData {
|
|
|
52
60
|
export interface ExecutionSettings {
|
|
53
61
|
updateCallback?: CallbackFunction;
|
|
54
62
|
switchChainHook?: SwitchChainHook;
|
|
63
|
+
acceptSlippageUpdateHook?: AcceptSlippageUpdateHook;
|
|
55
64
|
infiniteApproval?: boolean;
|
|
56
65
|
}
|
|
57
66
|
export interface InternalExecutionSettings extends ExecutionSettings {
|
|
58
67
|
updateCallback: CallbackFunction;
|
|
59
68
|
switchChainHook: SwitchChainHook;
|
|
69
|
+
acceptSlippageUpdateHook: AcceptSlippageUpdateHook;
|
|
60
70
|
infiniteApproval: boolean;
|
|
61
71
|
}
|
|
62
72
|
export declare type EnforcedObjectProperties<T> = T & {
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export declare enum LifiErrorCode {
|
|
|
18
18
|
ProviderUnavailable = 1005,
|
|
19
19
|
NotFound = 1006,
|
|
20
20
|
ChainSwitchError = 1007,
|
|
21
|
-
|
|
21
|
+
SlippageNotMet = 1008,
|
|
22
|
+
SlippageError = 1008,
|
|
23
|
+
GasLimitError = 1009
|
|
22
24
|
}
|
|
23
25
|
export declare enum MetaMaskRPCErrorCode {
|
|
24
26
|
invalidInput = -32000,
|
package/dist/utils/errors.js
CHANGED
|
@@ -38,7 +38,9 @@ var LifiErrorCode;
|
|
|
38
38
|
LifiErrorCode[LifiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
|
|
39
39
|
LifiErrorCode[LifiErrorCode["NotFound"] = 1006] = "NotFound";
|
|
40
40
|
LifiErrorCode[LifiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
|
|
41
|
+
LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1008] = "SlippageNotMet";
|
|
41
42
|
LifiErrorCode[LifiErrorCode["SlippageError"] = 1008] = "SlippageError";
|
|
43
|
+
LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
|
|
42
44
|
})(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
|
|
43
45
|
var MetaMaskRPCErrorCode;
|
|
44
46
|
(function (MetaMaskRPCErrorCode) {
|
|
@@ -35,3 +35,4 @@ export declare const getTransactionNotSentMessage: (step?: Step, process?: Proce
|
|
|
35
35
|
export declare const getTransactionFailedMessage: (step: Step, txLink?: string) => string;
|
|
36
36
|
export declare const parseError: (e: any, step?: Step, process?: Process) => Promise<LifiError>;
|
|
37
37
|
export declare const parseBackendError: (e: any) => LifiError;
|
|
38
|
+
export declare const getSlippageNotMetMessage: (step: Step) => string;
|
package/dist/utils/parseError.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0;
|
|
42
|
+
exports.getSlippageNotMetMessage = exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0;
|
|
43
43
|
var types_1 = require("@lifi/types");
|
|
44
44
|
var eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
45
45
|
var ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
@@ -110,16 +110,17 @@ var getTransactionFailedMessage = function (step, txLink) {
|
|
|
110
110
|
};
|
|
111
111
|
exports.getTransactionFailedMessage = getTransactionFailedMessage;
|
|
112
112
|
var parseError = function (e, step, process) { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
114
|
+
var _o, _p;
|
|
115
|
+
return __generator(this, function (_q) {
|
|
116
|
+
switch (_q.label) {
|
|
116
117
|
case 0:
|
|
117
118
|
if (e instanceof errors_1.LifiError) {
|
|
118
119
|
return [2 /*return*/, e];
|
|
119
120
|
}
|
|
120
|
-
if (!e.code) return [3 /*break*/,
|
|
121
|
-
if (!(typeof e.code === 'number')) return [3 /*break*/,
|
|
122
|
-
if (!Object.values(eth_rpc_errors_1.errorCodes.rpc).includes(e.code)) return [3 /*break*/,
|
|
121
|
+
if (!e.code) return [3 /*break*/, 13];
|
|
122
|
+
if (!(typeof e.code === 'number')) return [3 /*break*/, 8];
|
|
123
|
+
if (!Object.values(eth_rpc_errors_1.errorCodes.rpc).includes(e.code)) return [3 /*break*/, 6];
|
|
123
124
|
if (!(e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
124
125
|
e.message &&
|
|
125
126
|
e.message.includes('underpriced'))) return [3 /*break*/, 2];
|
|
@@ -127,40 +128,48 @@ var parseError = function (e, step, process) { return __awaiter(void 0, void 0,
|
|
|
127
128
|
_b = [void 0, errors_1.LifiErrorCode.TransactionUnderpriced,
|
|
128
129
|
'Transaction is underpriced.'];
|
|
129
130
|
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
130
|
-
case 1: return [2 /*return*/, new (_a.apply(errors_1.RPCError, _b.concat([
|
|
131
|
+
case 1: return [2 /*return*/, new (_a.apply(errors_1.RPCError, _b.concat([_q.sent(), e.stack])))()];
|
|
131
132
|
case 2:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
if (!(((_o = e.message) === null || _o === void 0 ? void 0 : _o.includes('intrinsic gas too low')) ||
|
|
134
|
+
((_p = e.message) === null || _p === void 0 ? void 0 : _p.includes('out of gas')))) return [3 /*break*/, 4];
|
|
135
|
+
_c = errors_1.TransactionError.bind;
|
|
136
|
+
_d = [void 0, errors_1.LifiErrorCode.GasLimitError,
|
|
137
|
+
'Gas limit is too low.'];
|
|
135
138
|
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
136
|
-
case 3: return [2 /*return*/, new (_c.apply(errors_1.
|
|
139
|
+
case 3: return [2 /*return*/, new (_c.apply(errors_1.TransactionError, _d.concat([_q.sent(), e.stack])))()];
|
|
137
140
|
case 4:
|
|
138
|
-
|
|
139
|
-
_e = errors_1.ProviderError.bind;
|
|
141
|
+
_e = errors_1.RPCError.bind;
|
|
140
142
|
_f = [void 0, e.code,
|
|
141
143
|
(0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
|
|
142
144
|
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
143
|
-
case 5: return [2 /*return*/, new (_e.apply(errors_1.
|
|
145
|
+
case 5: return [2 /*return*/, new (_e.apply(errors_1.RPCError, _f.concat([_q.sent(), e.stack])))()];
|
|
144
146
|
case 6:
|
|
145
|
-
if (!(e.code
|
|
147
|
+
if (!Object.values(eth_rpc_errors_1.errorCodes.provider).includes(e.code)) return [3 /*break*/, 8];
|
|
146
148
|
_g = errors_1.ProviderError.bind;
|
|
147
|
-
_h = [void 0,
|
|
148
|
-
e.
|
|
149
|
+
_h = [void 0, e.code,
|
|
150
|
+
(0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
|
|
149
151
|
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
150
|
-
case 7: return [2 /*return*/, new (_g.apply(errors_1.ProviderError, _h.concat([
|
|
152
|
+
case 7: return [2 /*return*/, new (_g.apply(errors_1.ProviderError, _h.concat([_q.sent(), e.stack])))()];
|
|
151
153
|
case 8:
|
|
152
|
-
if (!(e.code ===
|
|
153
|
-
_j = errors_1.
|
|
154
|
-
_k = [void 0, errors_1.LifiErrorCode.
|
|
155
|
-
e.
|
|
154
|
+
if (!(e.code === 'CALL_EXCEPTION')) return [3 /*break*/, 10];
|
|
155
|
+
_j = errors_1.ProviderError.bind;
|
|
156
|
+
_k = [void 0, errors_1.LifiErrorCode.TransactionFailed,
|
|
157
|
+
e.reason];
|
|
156
158
|
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
157
|
-
case 9: return [2 /*return*/, new (_j.apply(errors_1.
|
|
159
|
+
case 9: return [2 /*return*/, new (_j.apply(errors_1.ProviderError, _k.concat([_q.sent(), e.stack])))()];
|
|
158
160
|
case 10:
|
|
161
|
+
if (!(e.code === errors_1.LifiErrorCode.TransactionUnprepared)) return [3 /*break*/, 12];
|
|
162
|
+
_l = errors_1.TransactionError.bind;
|
|
163
|
+
_m = [void 0, errors_1.LifiErrorCode.TransactionUnprepared,
|
|
164
|
+
e.message];
|
|
165
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
166
|
+
case 11: return [2 /*return*/, new (_l.apply(errors_1.TransactionError, _m.concat([_q.sent(), e.stack])))()];
|
|
167
|
+
case 12:
|
|
159
168
|
if (e.code === errors_1.LifiErrorCode.ValidationError) {
|
|
160
169
|
return [2 /*return*/, new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage)];
|
|
161
170
|
}
|
|
162
|
-
|
|
163
|
-
case
|
|
171
|
+
_q.label = 13;
|
|
172
|
+
case 13: return [2 /*return*/, new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack)];
|
|
164
173
|
}
|
|
165
174
|
});
|
|
166
175
|
}); };
|
|
@@ -182,3 +191,8 @@ var parseBackendError = function (e) {
|
|
|
182
191
|
return new errors_1.ServerError('Something went wrong.', undefined, e.stack);
|
|
183
192
|
};
|
|
184
193
|
exports.parseBackendError = parseBackendError;
|
|
194
|
+
var getSlippageNotMetMessage = function (step) {
|
|
195
|
+
var slippage = step.action.slippage;
|
|
196
|
+
return "Transaction was not sent, your funds are still in your wallet.\n The updated quote for the current transaction does not meet your set slippage of ".concat(slippage * 100, "%.");
|
|
197
|
+
};
|
|
198
|
+
exports.getSlippageNotMetMessage = getSlippageNotMetMessage;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handlePreRestart = void 0;
|
|
4
|
+
var errors_1 = require("./errors");
|
|
5
|
+
var handlePreRestart = function (route) {
|
|
6
|
+
var _a;
|
|
7
|
+
for (var index = 0; index < route.steps.length; index++) {
|
|
8
|
+
var stepHasFailed = ((_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
|
|
9
|
+
if (stepHasFailed) {
|
|
10
|
+
handleErrorType(route, index);
|
|
11
|
+
popLastProcess(route, index);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.handlePreRestart = handlePreRestart;
|
|
16
|
+
var handleErrorType = function (route, index) {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
var isGasLimitError = (_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.process.some(function (p) { var _a; return ((_a = p.error) === null || _a === void 0 ? void 0 : _a.code) === errors_1.LifiErrorCode.GasLimitError; });
|
|
19
|
+
var isGasPriceError = (_b = route.steps[index].execution) === null || _b === void 0 ? void 0 : _b.process.some(function (p) { var _a; return ((_a = p.error) === null || _a === void 0 ? void 0 : _a.code) === errors_1.LifiErrorCode.TransactionUnderpriced; });
|
|
20
|
+
if (isGasLimitError) {
|
|
21
|
+
(_c = route.steps[index].estimate.gasCosts) === null || _c === void 0 ? void 0 : _c.forEach(function (gasCost) {
|
|
22
|
+
return (gasCost.limit = "".concat(Math.round(Number(gasCost.limit) * 1.25)));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (isGasPriceError) {
|
|
26
|
+
(_d = route.steps[index].estimate.gasCosts) === null || _d === void 0 ? void 0 : _d.forEach(function (gasCost) {
|
|
27
|
+
return (gasCost.price = "".concat(Math.round(Number(gasCost.price) * 1.25)));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var popLastProcess = function (route, index) {
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.process.pop();
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@ethersproject/abi": "^5.6.4",
|
|
54
54
|
"@ethersproject/contracts": "^5.6.2",
|
|
55
|
-
"@lifi/types": "^1.
|
|
55
|
+
"@lifi/types": "^1.3.0",
|
|
56
56
|
"axios": "^0.27.2",
|
|
57
57
|
"bignumber.js": "^9.0.1",
|
|
58
58
|
"eth-rpc-errors": "^4.0.3",
|