@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/utils/multicall.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,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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
});
|
package/dist/utils/parseError.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,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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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 <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
|
-
?
|
|
67
|
+
? `${baseString}
|
|
68
|
+
You can also check the <a href="${txLink}" target="_blank" rel="nofollow noreferrer">block explorer</a> for more information.`
|
|
109
69
|
: baseString;
|
|
110
70
|
};
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
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'))
|
|
127
|
-
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
124
|
+
return new ServerError('Something went wrong.', undefined, e.stack);
|
|
192
125
|
};
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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;
|
package/dist/utils/preRestart.js
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 (
|
|
8
|
-
|
|
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
|
-
|
|
8
|
+
deleteFailedProcesses(route, index);
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
var handleErrorType = function (route, index) {
|
|
12
|
+
const handleErrorType = (route, index) => {
|
|
17
13
|
var _a, _b, _c, _d;
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
};
|