@lifi/sdk 1.1.2 → 1.1.3

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.
@@ -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,119 +7,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
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
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.fetchDataUsingMulticall = void 0;
43
- var abi_1 = require("@ethersproject/abi");
44
- var contracts_1 = require("@ethersproject/contracts");
45
- var connectors_1 = require("../connectors");
46
- var utils_1 = require("./utils");
47
- var multicallAbi_json_1 = __importDefault(require("./multicallAbi.json"));
48
- var MAX_MULTICALL_SIZE = 100;
49
- var fetchDataUsingMulticall = function (calls, abi, chainId, multicallAddress, requireSuccess) {
50
- if (requireSuccess === void 0) { requireSuccess = false; }
51
- return __awaiter(void 0, void 0, void 0, function () {
52
- var provider, multicallContract, abiInterface, chunkedList, chunkedResults;
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0: return [4 /*yield*/, (0, connectors_1.getRpcProvider)(chainId)];
56
- case 1:
57
- provider = _a.sent();
58
- multicallContract = new contracts_1.Contract(multicallAddress, multicallAbi_json_1.default, provider);
59
- abiInterface = new abi_1.Interface(abi);
60
- chunkedList = (0, utils_1.splitListIntoChunks)(calls, MAX_MULTICALL_SIZE);
61
- return [4 /*yield*/, Promise.all(chunkedList.map(function (chunkedCalls) { return __awaiter(void 0, void 0, void 0, function () {
62
- var callData, _a, blockNumber_1, returnData, e_1;
63
- return __generator(this, function (_b) {
64
- switch (_b.label) {
65
- case 0:
66
- callData = chunkedCalls.map(function (call) { return [
67
- call.address.toLowerCase(),
68
- abiInterface.encodeFunctionData(call.name, call.params),
69
- ]; });
70
- _b.label = 1;
71
- case 1:
72
- _b.trys.push([1, 3, , 4]);
73
- return [4 /*yield*/, multicallContract.tryBlockAndAggregate(requireSuccess, callData)
74
- // 4. decode bytes array to useful data array...
75
- ];
76
- case 2:
77
- _a = _b.sent(), blockNumber_1 = _a.blockNumber, returnData = _a.returnData;
78
- // 4. decode bytes array to useful data array...
79
- return [2 /*return*/, returnData
80
- .map(function (_a, i) {
81
- var success = _a.success, returnData = _a.returnData;
82
- if (!success) {
83
- // requested function failed
84
- console.error("Multicall unsuccessful for address \"".concat(chunkedCalls[i].address, "\", ") +
85
- "function \"".concat(chunkedCalls[i].name, "\", chainId \"").concat(chainId, "\""));
86
- return [];
87
- }
88
- if (returnData.toString() === '0x') {
89
- // requested function does probably not exist
90
- console.error("Multicall no response for address \"".concat(chunkedCalls[i].address, "\", ") +
91
- "function \"".concat(chunkedCalls[i].name, "\", chainId \"").concat(chainId, "\""));
92
- return [];
93
- }
94
- try {
95
- return abiInterface.decodeFunctionResult(chunkedCalls[i].name, returnData);
96
- }
97
- catch (e) {
98
- // requested function returns other data than expected
99
- console.error("Multicall parsing unsuccessful for address \"".concat(chunkedCalls[i].address, "\", ") +
100
- "function \"".concat(chunkedCalls[i].name, "\", chainId \"").concat(chainId, "\""));
101
- return [];
102
- }
103
- })
104
- .map(function (data) {
105
- return {
106
- data: data[0],
107
- blockNumber: blockNumber_1.toNumber(),
108
- };
109
- })];
110
- case 3:
111
- e_1 = _b.sent();
112
- // whole rpc call failed, probably an rpc issue
113
- console.error("Multicall failed on chainId \"".concat(chainId, "\""), chunkedList, e_1);
114
- return [2 /*return*/, []];
115
- case 4: return [2 /*return*/];
116
- }
117
- });
118
- }); }))];
119
- case 2:
120
- chunkedResults = _a.sent();
121
- return [2 /*return*/, chunkedResults.flat()];
122
- }
123
- });
124
- });
125
- };
126
- exports.fetchDataUsingMulticall = fetchDataUsingMulticall;
10
+ import { Interface } from '@ethersproject/abi';
11
+ import { Contract } from '@ethersproject/contracts';
12
+ import { getRpcProvider } from '../connectors';
13
+ import { splitListIntoChunks } from './utils';
14
+ import MULTICALL_ABI from './multicallAbi.json';
15
+ const MAX_MULTICALL_SIZE = 100;
16
+ export const fetchDataUsingMulticall = (calls, abi, chainId, multicallAddress, requireSuccess = false) => __awaiter(void 0, void 0, void 0, function* () {
17
+ // 1. create contract using multicall contract address and abi...
18
+ const provider = yield getRpcProvider(chainId);
19
+ const multicallContract = new Contract(multicallAddress, MULTICALL_ABI, provider);
20
+ const abiInterface = new Interface(abi);
21
+ // split up lists into chunks to stay below multicall limit
22
+ const chunkedList = splitListIntoChunks(calls, MAX_MULTICALL_SIZE);
23
+ const chunkedResults = yield Promise.all(chunkedList.map((chunkedCalls) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const callData = chunkedCalls.map((call) => [
25
+ call.address.toLowerCase(),
26
+ abiInterface.encodeFunctionData(call.name, call.params),
27
+ ]);
28
+ try {
29
+ // 3. get bytes array from multicall contract by process aggregate method...
30
+ const { blockNumber, returnData } = yield multicallContract.tryBlockAndAggregate(requireSuccess, callData);
31
+ // 4. decode bytes array to useful data array...
32
+ return returnData
33
+ .map(({ success, returnData }, i) => {
34
+ if (!success) {
35
+ // requested function failed
36
+ console.error(`Multicall unsuccessful for address "${chunkedCalls[i].address}", ` +
37
+ `function "${chunkedCalls[i].name}", chainId "${chainId}"`);
38
+ return [];
39
+ }
40
+ if (returnData.toString() === '0x') {
41
+ // requested function does probably not exist
42
+ console.error(`Multicall no response for address "${chunkedCalls[i].address}", ` +
43
+ `function "${chunkedCalls[i].name}", chainId "${chainId}"`);
44
+ return [];
45
+ }
46
+ try {
47
+ return abiInterface.decodeFunctionResult(chunkedCalls[i].name, returnData);
48
+ }
49
+ catch (e) {
50
+ // requested function returns other data than expected
51
+ console.error(`Multicall parsing unsuccessful for address "${chunkedCalls[i].address}", ` +
52
+ `function "${chunkedCalls[i].name}", chainId "${chainId}"`);
53
+ return [];
54
+ }
55
+ })
56
+ .map((data) => {
57
+ return {
58
+ data: data[0],
59
+ blockNumber: blockNumber.toNumber(),
60
+ };
61
+ });
62
+ }
63
+ catch (e) {
64
+ // whole rpc call failed, probably an rpc issue
65
+ console.error(`Multicall failed on chainId "${chainId}"`, chunkedList, e);
66
+ return [];
67
+ }
68
+ })));
69
+ return chunkedResults.flat();
70
+ });
@@ -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,43 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
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
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getSlippageNotMetMessage = exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0;
43
- var types_1 = require("@lifi/types");
44
- var eth_rpc_errors_1 = require("eth-rpc-errors");
45
- var ChainsService_1 = __importDefault(require("../services/ChainsService"));
46
- var errors_1 = require("./errors");
47
- var utils_1 = require("./utils");
10
+ import { getChainById } from '@lifi/types';
11
+ import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
12
+ import ChainsService from '../services/ChainsService';
13
+ import { LifiError, LifiErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
14
+ import { formatTokenAmountOnly } from './utils';
48
15
  /**
49
16
  * Available MetaMask error codes:
50
17
  *
@@ -76,123 +43,88 @@ var utils_1 = require("./utils");
76
43
  * https://eips.ethereum.org/EIPS/eip-1474#error-codes
77
44
  * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
78
45
  */
79
- var getTransactionNotSentMessage = function (step, process) { return __awaiter(void 0, void 0, void 0, function () {
80
- var transactionNotSend, chainService, chain;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- transactionNotSend = 'Transaction was not sent, your funds are still in your wallet';
85
- if (!step) return [3 /*break*/, 2];
86
- chainService = ChainsService_1.default.getInstance();
87
- return [4 /*yield*/, chainService.getChainById(step.action.fromChainId)];
88
- case 1:
89
- chain = _a.sent();
90
- transactionNotSend += " (".concat((0, utils_1.formatTokenAmountOnly)(step.action.fromToken, step.action.fromAmount), " ").concat(step.action.fromToken.symbol, " on ").concat(chain.name, ")");
91
- _a.label = 2;
92
- case 2:
93
- transactionNotSend +=
94
- ", please retry.<br/>If it still doesn't work, it is safe to delete this transfer and start a new one.";
95
- // add transaction explorer link if available
96
- transactionNotSend +=
97
- process && process.txLink
98
- ? "<br>You can check the failed transaction&nbsp;<a href=\"".concat(process.txLink, "\" target=\"_blank\" rel=\"nofollow noreferrer\">here</a>.")
99
- : '';
100
- return [2 /*return*/, transactionNotSend];
101
- }
102
- });
103
- }); };
104
- exports.getTransactionNotSentMessage = getTransactionNotSentMessage;
105
- var getTransactionFailedMessage = function (step, txLink) {
106
- var baseString = "It appears that your transaction may not have been successful.\n However, to confirm this, please check your ".concat((0, types_1.getChainById)(step.action.toChainId).name, " wallet for ").concat(step.action.toToken.symbol, ".");
46
+ export const getTransactionNotSentMessage = (step, process) => __awaiter(void 0, void 0, void 0, function* () {
47
+ let transactionNotSend = 'Transaction was not sent, your funds are still in your wallet';
48
+ // add information about funds if available
49
+ if (step) {
50
+ const chainService = ChainsService.getInstance();
51
+ const chain = yield chainService.getChainById(step.action.fromChainId);
52
+ transactionNotSend += ` (${formatTokenAmountOnly(step.action.fromToken, step.action.fromAmount)} ${step.action.fromToken.symbol} on ${chain.name})`;
53
+ }
54
+ transactionNotSend +=
55
+ ", please retry.<br/>If it still doesn't work, it is safe to delete this transfer and start a new one.";
56
+ // add transaction explorer link if available
57
+ transactionNotSend +=
58
+ process && process.txLink
59
+ ? `<br>You can check the failed transaction&nbsp;<a href="${process.txLink}" target="_blank" rel="nofollow noreferrer">here</a>.`
60
+ : '';
61
+ return transactionNotSend;
62
+ });
63
+ export const getTransactionFailedMessage = (step, txLink) => {
64
+ const baseString = `It appears that your transaction may not have been successful.
65
+ However, to confirm this, please check your ${getChainById(step.action.toChainId).name} wallet for ${step.action.toToken.symbol}.`;
107
66
  return txLink
108
- ? "".concat(baseString, "\n You can also check the&nbsp;<a href=\"").concat(txLink, "\" target=\"_blank\" rel=\"nofollow noreferrer\">block explorer</a> for more information.")
67
+ ? `${baseString}
68
+ You can also check the&nbsp;<a href="${txLink}" target="_blank" rel="nofollow noreferrer">block explorer</a> for more information.`
109
69
  : baseString;
110
70
  };
111
- exports.getTransactionFailedMessage = getTransactionFailedMessage;
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, _l, _m;
114
- var _o, _p;
115
- return __generator(this, function (_q) {
116
- switch (_q.label) {
117
- case 0:
118
- if (e instanceof errors_1.LifiError) {
119
- return [2 /*return*/, e];
120
- }
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];
124
- if (!(e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
71
+ export const parseError = (e, step, process) => __awaiter(void 0, void 0, void 0, function* () {
72
+ var _a, _b;
73
+ if (e instanceof LifiError) {
74
+ return e;
75
+ }
76
+ if (e.code) {
77
+ // MetaMask errors have a numeric error code
78
+ if (typeof e.code === 'number') {
79
+ if (Object.values(MetaMaskErrorCodes.rpc).includes(e.code)) {
80
+ // rpc errors
81
+ // underpriced errors are sent as internal errors, so we need to parse the message manually
82
+ if (e.code === MetaMaskErrorCodes.rpc.internal &&
125
83
  e.message &&
126
- e.message.includes('underpriced'))) return [3 /*break*/, 2];
127
- _a = errors_1.RPCError.bind;
128
- _b = [void 0, errors_1.LifiErrorCode.TransactionUnderpriced,
129
- 'Transaction is underpriced.'];
130
- return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
131
- case 1: return [2 /*return*/, new (_a.apply(errors_1.RPCError, _b.concat([_q.sent(), e.stack])))()];
132
- case 2:
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.'];
138
- return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
139
- case 3: return [2 /*return*/, new (_c.apply(errors_1.TransactionError, _d.concat([_q.sent(), e.stack])))()];
140
- case 4:
141
- _e = errors_1.RPCError.bind;
142
- _f = [void 0, e.code,
143
- (0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
144
- return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
145
- case 5: return [2 /*return*/, new (_e.apply(errors_1.RPCError, _f.concat([_q.sent(), e.stack])))()];
146
- case 6:
147
- if (!Object.values(eth_rpc_errors_1.errorCodes.provider).includes(e.code)) return [3 /*break*/, 8];
148
- _g = errors_1.ProviderError.bind;
149
- _h = [void 0, e.code,
150
- (0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
151
- return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
152
- case 7: return [2 /*return*/, new (_g.apply(errors_1.ProviderError, _h.concat([_q.sent(), e.stack])))()];
153
- case 8:
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];
158
- return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
159
- case 9: return [2 /*return*/, new (_j.apply(errors_1.ProviderError, _k.concat([_q.sent(), e.stack])))()];
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:
168
- if (e.code === errors_1.LifiErrorCode.ValidationError) {
169
- return [2 /*return*/, new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage)];
84
+ e.message.includes('underpriced')) {
85
+ return new RPCError(LifiErrorCode.TransactionUnderpriced, 'Transaction is underpriced.', yield getTransactionNotSentMessage(step, process), e.stack);
170
86
  }
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)];
87
+ if (((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes('intrinsic gas too low')) ||
88
+ ((_b = e.message) === null || _b === void 0 ? void 0 : _b.includes('out of gas'))) {
89
+ return new TransactionError(LifiErrorCode.GasLimitError, 'Gas limit is too low.', yield getTransactionNotSentMessage(step, process), e.stack);
90
+ }
91
+ return new RPCError(e.code, getMessageFromCode(e.code), yield getTransactionNotSentMessage(step, process), e.stack);
92
+ }
93
+ // provider errors
94
+ if (Object.values(MetaMaskErrorCodes.provider).includes(e.code)) {
95
+ return new ProviderError(e.code, getMessageFromCode(e.code), yield getTransactionNotSentMessage(step, process), e.stack);
96
+ }
173
97
  }
174
- });
175
- }); };
176
- exports.parseError = parseError;
177
- var parseBackendError = function (e) {
98
+ if (e.code === 'CALL_EXCEPTION') {
99
+ return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, yield getTransactionNotSentMessage(step, process), e.stack);
100
+ }
101
+ if (e.code === LifiErrorCode.TransactionUnprepared) {
102
+ return new TransactionError(LifiErrorCode.TransactionUnprepared, e.message, yield getTransactionNotSentMessage(step, process), e.stack);
103
+ }
104
+ if (e.code === LifiErrorCode.ValidationError) {
105
+ return new TransactionError(LifiErrorCode.ValidationError, e.message, e.htmlMessage);
106
+ }
107
+ }
108
+ return new UnknownError(LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
109
+ });
110
+ export const parseBackendError = (e) => {
178
111
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
179
112
  if (((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 400) {
180
- return new errors_1.ValidationError(((_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || ((_d = e.response) === null || _d === void 0 ? void 0 : _d.statusText), undefined, e.stack);
113
+ return new ValidationError(((_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || ((_d = e.response) === null || _d === void 0 ? void 0 : _d.statusText), undefined, e.stack);
181
114
  }
182
115
  if (((_e = e.response) === null || _e === void 0 ? void 0 : _e.status) === 404) {
183
- return new errors_1.NotFoundError(((_g = (_f = e.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message) || ((_h = e.response) === null || _h === void 0 ? void 0 : _h.statusText), undefined, e.stack);
116
+ return new NotFoundError(((_g = (_f = e.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message) || ((_h = e.response) === null || _h === void 0 ? void 0 : _h.statusText), undefined, e.stack);
184
117
  }
185
118
  if (((_j = e.response) === null || _j === void 0 ? void 0 : _j.status) === 409) {
186
- return new errors_1.SlippageError(((_l = (_k = e.response) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.message) || ((_m = e.response) === null || _m === void 0 ? void 0 : _m.statusText), 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.', e.stack);
119
+ return new SlippageError(((_l = (_k = e.response) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.message) || ((_m = e.response) === null || _m === void 0 ? void 0 : _m.statusText), 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.', e.stack);
187
120
  }
188
121
  if (((_o = e.response) === null || _o === void 0 ? void 0 : _o.status) === 500) {
189
- return new errors_1.ServerError(((_q = (_p = e.response) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.message) || ((_r = e.response) === null || _r === void 0 ? void 0 : _r.statusText), undefined, e.stack);
122
+ return new ServerError(((_q = (_p = e.response) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.message) || ((_r = e.response) === null || _r === void 0 ? void 0 : _r.statusText), undefined, e.stack);
190
123
  }
191
- return new errors_1.ServerError('Something went wrong.', undefined, e.stack);
124
+ return new ServerError('Something went wrong.', undefined, e.stack);
192
125
  };
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, "%.");
126
+ export const getSlippageNotMetMessage = (step) => {
127
+ const { slippage } = step.action;
128
+ return `Transaction was not sent, your funds are still in your wallet.
129
+ The updated quote for the current transaction does not meet your set slippage of ${slippage * 100}%.`;
197
130
  };
198
- exports.getSlippageNotMetMessage = getSlippageNotMetMessage;
@@ -1,34 +1,27 @@
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) {
1
+ import { LifiErrorCode } from './errors';
2
+ export const handlePreRestart = (route) => {
6
3
  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';
4
+ for (let index = 0; index < route.steps.length; index++) {
5
+ const stepHasFailed = ((_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
9
6
  if (stepHasFailed) {
10
7
  handleErrorType(route, index);
11
- popLastProcess(route, index);
8
+ deleteFailedProcesses(route, index);
12
9
  }
13
10
  }
14
11
  };
15
- exports.handlePreRestart = handlePreRestart;
16
- var handleErrorType = function (route, index) {
12
+ const handleErrorType = (route, index) => {
17
13
  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; });
14
+ const isGasLimitError = (_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.process.some((p) => { var _a; return ((_a = p.error) === null || _a === void 0 ? void 0 : _a.code) === LifiErrorCode.GasLimitError; });
15
+ const isGasPriceError = (_b = route.steps[index].execution) === null || _b === void 0 ? void 0 : _b.process.some((p) => { var _a; return ((_a = p.error) === null || _a === void 0 ? void 0 : _a.code) === LifiErrorCode.TransactionUnderpriced; });
20
16
  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
- });
17
+ (_c = route.steps[index].estimate.gasCosts) === null || _c === void 0 ? void 0 : _c.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
24
18
  }
25
19
  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
- });
20
+ (_d = route.steps[index].estimate.gasCosts) === null || _d === void 0 ? void 0 : _d.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
29
21
  }
30
22
  };
31
- var popLastProcess = function (route, index) {
32
- var _a;
33
- (_a = route.steps[index].execution) === null || _a === void 0 ? void 0 : _a.process.pop();
23
+ const deleteFailedProcesses = (route, index) => {
24
+ if (route.steps[index].execution) {
25
+ route.steps[index].execution.process = route.steps[index].execution.process.filter((process) => process.status !== 'FAILED');
26
+ }
34
27
  };