@lifi/sdk 1.0.0
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 +354 -0
- package/LICENSE +1 -0
- package/README.md +16 -0
- package/dist/Lifi.d.ts +186 -0
- package/dist/Lifi.js +461 -0
- package/dist/allowance/index.d.ts +22 -0
- package/dist/allowance/index.js +160 -0
- package/dist/allowance/utils.d.ts +14 -0
- package/dist/allowance/utils.js +137 -0
- package/dist/balances/index.d.ts +11 -0
- package/dist/balances/index.js +104 -0
- package/dist/balances/utils.d.ts +5 -0
- package/dist/balances/utils.js +255 -0
- package/dist/connectors.d.ts +6 -0
- package/dist/connectors.js +150 -0
- package/dist/execution/StatusManager.d.ts +63 -0
- package/dist/execution/StatusManager.js +150 -0
- package/dist/execution/StepExecutor.d.ts +15 -0
- package/dist/execution/StepExecutor.js +139 -0
- package/dist/execution/allowance.execute.d.ts +4 -0
- package/dist/execution/allowance.execute.js +156 -0
- package/dist/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/execution/balanceCheck.execute.js +86 -0
- package/dist/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/execution/bridges/bridge.execute.js +218 -0
- package/dist/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/execution/exchanges/swap.execute.js +222 -0
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.js +17 -0
- package/dist/execution/switchChain.d.ts +16 -0
- package/dist/execution/switchChain.js +102 -0
- package/dist/execution/utils.d.ts +5 -0
- package/dist/execution/utils.js +175 -0
- package/dist/helpers.d.ts +18 -0
- package/dist/helpers.js +85 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +27 -0
- package/dist/services/ApiService.d.ts +14 -0
- package/dist/services/ApiService.js +350 -0
- package/dist/services/ChainsService.d.ts +11 -0
- package/dist/services/ChainsService.js +108 -0
- package/dist/services/ConfigService.d.ts +23 -0
- package/dist/services/ConfigService.js +133 -0
- package/dist/typeguards.d.ts +4 -0
- package/dist/typeguards.js +55 -0
- package/dist/types/ERC20.d.ts +22 -0
- package/dist/types/ERC20.js +53 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +22 -0
- package/dist/types/internal.types.d.ts +75 -0
- package/dist/types/internal.types.js +2 -0
- package/dist/utils/errors.d.ts +73 -0
- package/dist/utils/errors.js +147 -0
- package/dist/utils/getProvider.d.ts +3 -0
- package/dist/utils/getProvider.js +11 -0
- package/dist/utils/multicall.d.ts +10 -0
- package/dist/utils/multicall.js +111 -0
- package/dist/utils/multicallAbi.json +313 -0
- package/dist/utils/parseError.d.ts +37 -0
- package/dist/utils/parseError.js +184 -0
- package/dist/utils/utils.d.ts +26 -0
- package/dist/utils/utils.js +188 -0
- package/package.json +90 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"components": [
|
|
6
|
+
{
|
|
7
|
+
"internalType": "address",
|
|
8
|
+
"name": "target",
|
|
9
|
+
"type": "address"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"internalType": "bytes",
|
|
13
|
+
"name": "callData",
|
|
14
|
+
"type": "bytes"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"internalType": "struct Multicall2.Call[]",
|
|
18
|
+
"name": "calls",
|
|
19
|
+
"type": "tuple[]"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"name": "aggregate",
|
|
23
|
+
"outputs": [
|
|
24
|
+
{
|
|
25
|
+
"internalType": "uint256",
|
|
26
|
+
"name": "blockNumber",
|
|
27
|
+
"type": "uint256"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"internalType": "bytes[]",
|
|
31
|
+
"name": "returnData",
|
|
32
|
+
"type": "bytes[]"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"stateMutability": "view",
|
|
36
|
+
"type": "function"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"inputs": [
|
|
40
|
+
{
|
|
41
|
+
"components": [
|
|
42
|
+
{
|
|
43
|
+
"internalType": "address",
|
|
44
|
+
"name": "target",
|
|
45
|
+
"type": "address"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"internalType": "bytes",
|
|
49
|
+
"name": "callData",
|
|
50
|
+
"type": "bytes"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"internalType": "struct Multicall2.Call[]",
|
|
54
|
+
"name": "calls",
|
|
55
|
+
"type": "tuple[]"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"name": "blockAndAggregate",
|
|
59
|
+
"outputs": [
|
|
60
|
+
{
|
|
61
|
+
"internalType": "uint256",
|
|
62
|
+
"name": "blockNumber",
|
|
63
|
+
"type": "uint256"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"internalType": "bytes32",
|
|
67
|
+
"name": "blockHash",
|
|
68
|
+
"type": "bytes32"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"components": [
|
|
72
|
+
{
|
|
73
|
+
"internalType": "bool",
|
|
74
|
+
"name": "success",
|
|
75
|
+
"type": "bool"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"internalType": "bytes",
|
|
79
|
+
"name": "returnData",
|
|
80
|
+
"type": "bytes"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"internalType": "struct Multicall2.Result[]",
|
|
84
|
+
"name": "returnData",
|
|
85
|
+
"type": "tuple[]"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"stateMutability": "nonpayable",
|
|
89
|
+
"type": "function"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"inputs": [
|
|
93
|
+
{
|
|
94
|
+
"internalType": "uint256",
|
|
95
|
+
"name": "blockNumber",
|
|
96
|
+
"type": "uint256"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"name": "getBlockHash",
|
|
100
|
+
"outputs": [
|
|
101
|
+
{
|
|
102
|
+
"internalType": "bytes32",
|
|
103
|
+
"name": "blockHash",
|
|
104
|
+
"type": "bytes32"
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"stateMutability": "view",
|
|
108
|
+
"type": "function"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"inputs": [],
|
|
112
|
+
"name": "getBlockNumber",
|
|
113
|
+
"outputs": [
|
|
114
|
+
{
|
|
115
|
+
"internalType": "uint256",
|
|
116
|
+
"name": "blockNumber",
|
|
117
|
+
"type": "uint256"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"stateMutability": "view",
|
|
121
|
+
"type": "function"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"inputs": [],
|
|
125
|
+
"name": "getCurrentBlockCoinbase",
|
|
126
|
+
"outputs": [
|
|
127
|
+
{
|
|
128
|
+
"internalType": "address",
|
|
129
|
+
"name": "coinbase",
|
|
130
|
+
"type": "address"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"stateMutability": "view",
|
|
134
|
+
"type": "function"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"inputs": [],
|
|
138
|
+
"name": "getCurrentBlockDifficulty",
|
|
139
|
+
"outputs": [
|
|
140
|
+
{
|
|
141
|
+
"internalType": "uint256",
|
|
142
|
+
"name": "difficulty",
|
|
143
|
+
"type": "uint256"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"stateMutability": "view",
|
|
147
|
+
"type": "function"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"inputs": [],
|
|
151
|
+
"name": "getCurrentBlockGasLimit",
|
|
152
|
+
"outputs": [
|
|
153
|
+
{
|
|
154
|
+
"internalType": "uint256",
|
|
155
|
+
"name": "gaslimit",
|
|
156
|
+
"type": "uint256"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"stateMutability": "view",
|
|
160
|
+
"type": "function"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"inputs": [],
|
|
164
|
+
"name": "getCurrentBlockTimestamp",
|
|
165
|
+
"outputs": [
|
|
166
|
+
{
|
|
167
|
+
"internalType": "uint256",
|
|
168
|
+
"name": "timestamp",
|
|
169
|
+
"type": "uint256"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"stateMutability": "view",
|
|
173
|
+
"type": "function"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"inputs": [
|
|
177
|
+
{
|
|
178
|
+
"internalType": "address",
|
|
179
|
+
"name": "addr",
|
|
180
|
+
"type": "address"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
"name": "getEthBalance",
|
|
184
|
+
"outputs": [
|
|
185
|
+
{
|
|
186
|
+
"internalType": "uint256",
|
|
187
|
+
"name": "balance",
|
|
188
|
+
"type": "uint256"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"stateMutability": "view",
|
|
192
|
+
"type": "function"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"inputs": [],
|
|
196
|
+
"name": "getLastBlockHash",
|
|
197
|
+
"outputs": [
|
|
198
|
+
{
|
|
199
|
+
"internalType": "bytes32",
|
|
200
|
+
"name": "blockHash",
|
|
201
|
+
"type": "bytes32"
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
"stateMutability": "view",
|
|
205
|
+
"type": "function"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"inputs": [
|
|
209
|
+
{
|
|
210
|
+
"internalType": "bool",
|
|
211
|
+
"name": "requireSuccess",
|
|
212
|
+
"type": "bool"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"components": [
|
|
216
|
+
{
|
|
217
|
+
"internalType": "address",
|
|
218
|
+
"name": "target",
|
|
219
|
+
"type": "address"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"internalType": "bytes",
|
|
223
|
+
"name": "callData",
|
|
224
|
+
"type": "bytes"
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
"internalType": "struct Multicall2.Call[]",
|
|
228
|
+
"name": "calls",
|
|
229
|
+
"type": "tuple[]"
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
"name": "tryAggregate",
|
|
233
|
+
"outputs": [
|
|
234
|
+
{
|
|
235
|
+
"components": [
|
|
236
|
+
{
|
|
237
|
+
"internalType": "bool",
|
|
238
|
+
"name": "success",
|
|
239
|
+
"type": "bool"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"internalType": "bytes",
|
|
243
|
+
"name": "returnData",
|
|
244
|
+
"type": "bytes"
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
"internalType": "struct Multicall2.Result[]",
|
|
248
|
+
"name": "returnData",
|
|
249
|
+
"type": "tuple[]"
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
"stateMutability": "view",
|
|
253
|
+
"type": "function"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"inputs": [
|
|
257
|
+
{
|
|
258
|
+
"internalType": "bool",
|
|
259
|
+
"name": "requireSuccess",
|
|
260
|
+
"type": "bool"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"components": [
|
|
264
|
+
{
|
|
265
|
+
"internalType": "address",
|
|
266
|
+
"name": "target",
|
|
267
|
+
"type": "address"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"internalType": "bytes",
|
|
271
|
+
"name": "callData",
|
|
272
|
+
"type": "bytes"
|
|
273
|
+
}
|
|
274
|
+
],
|
|
275
|
+
"internalType": "struct Multicall2.Call[]",
|
|
276
|
+
"name": "calls",
|
|
277
|
+
"type": "tuple[]"
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
"name": "tryBlockAndAggregate",
|
|
281
|
+
"outputs": [
|
|
282
|
+
{
|
|
283
|
+
"internalType": "uint256",
|
|
284
|
+
"name": "blockNumber",
|
|
285
|
+
"type": "uint256"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"internalType": "bytes32",
|
|
289
|
+
"name": "blockHash",
|
|
290
|
+
"type": "bytes32"
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
"components": [
|
|
294
|
+
{
|
|
295
|
+
"internalType": "bool",
|
|
296
|
+
"name": "success",
|
|
297
|
+
"type": "bool"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"internalType": "bytes",
|
|
301
|
+
"name": "returnData",
|
|
302
|
+
"type": "bytes"
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"internalType": "struct Multicall2.Result[]",
|
|
306
|
+
"name": "returnData",
|
|
307
|
+
"type": "tuple[]"
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
"stateMutability": "view",
|
|
311
|
+
"type": "function"
|
|
312
|
+
}
|
|
313
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Process, Step } from '@lifi/types';
|
|
2
|
+
import { LifiError } from './errors';
|
|
3
|
+
/**
|
|
4
|
+
* Available MetaMask error codes:
|
|
5
|
+
*
|
|
6
|
+
* export const errorCodes: ErrorCodes = {
|
|
7
|
+
rpc: {
|
|
8
|
+
invalidInput: -32000,
|
|
9
|
+
resourceNotFound: -32001,
|
|
10
|
+
resourceUnavailable: -32002,
|
|
11
|
+
transactionRejected: -32003,
|
|
12
|
+
methodNotSupported: -32004,
|
|
13
|
+
limitExceeded: -32005,
|
|
14
|
+
parse: -32700,
|
|
15
|
+
invalidRequest: -32600,
|
|
16
|
+
methodNotFound: -32601,
|
|
17
|
+
invalidParams: -32602,
|
|
18
|
+
internal: -32603,
|
|
19
|
+
},
|
|
20
|
+
provider: {
|
|
21
|
+
userRejectedRequest: 4001,
|
|
22
|
+
unauthorized: 4100,
|
|
23
|
+
unsupportedMethod: 4200,
|
|
24
|
+
disconnected: 4900,
|
|
25
|
+
chainDisconnected: 4901,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
*
|
|
29
|
+
* For more information about error codes supported by metamask check
|
|
30
|
+
* https://github.com/MetaMask/eth-rpc-errors
|
|
31
|
+
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
32
|
+
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
33
|
+
*/
|
|
34
|
+
export declare const getTransactionNotSentMessage: (step?: Step, process?: Process) => Promise<string>;
|
|
35
|
+
export declare const getTransactionFailedMessage: (step: Step, txLink?: string) => string;
|
|
36
|
+
export declare const parseError: (e: any, step?: Step, process?: Process) => Promise<LifiError>;
|
|
37
|
+
export declare const parseBackendError: (e: any) => LifiError;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
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.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");
|
|
48
|
+
/**
|
|
49
|
+
* Available MetaMask error codes:
|
|
50
|
+
*
|
|
51
|
+
* export const errorCodes: ErrorCodes = {
|
|
52
|
+
rpc: {
|
|
53
|
+
invalidInput: -32000,
|
|
54
|
+
resourceNotFound: -32001,
|
|
55
|
+
resourceUnavailable: -32002,
|
|
56
|
+
transactionRejected: -32003,
|
|
57
|
+
methodNotSupported: -32004,
|
|
58
|
+
limitExceeded: -32005,
|
|
59
|
+
parse: -32700,
|
|
60
|
+
invalidRequest: -32600,
|
|
61
|
+
methodNotFound: -32601,
|
|
62
|
+
invalidParams: -32602,
|
|
63
|
+
internal: -32603,
|
|
64
|
+
},
|
|
65
|
+
provider: {
|
|
66
|
+
userRejectedRequest: 4001,
|
|
67
|
+
unauthorized: 4100,
|
|
68
|
+
unsupportedMethod: 4200,
|
|
69
|
+
disconnected: 4900,
|
|
70
|
+
chainDisconnected: 4901,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
*
|
|
74
|
+
* For more information about error codes supported by metamask check
|
|
75
|
+
* https://github.com/MetaMask/eth-rpc-errors
|
|
76
|
+
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
77
|
+
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
78
|
+
*/
|
|
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 <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, ".");
|
|
107
|
+
return txLink
|
|
108
|
+
? "".concat(baseString, "\n You can also check the <a href=\"").concat(txLink, "\" target=\"_blank\" rel=\"nofollow noreferrer\">block explorer</a> for more information.")
|
|
109
|
+
: baseString;
|
|
110
|
+
};
|
|
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;
|
|
114
|
+
return __generator(this, function (_l) {
|
|
115
|
+
switch (_l.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
if (e instanceof errors_1.LifiError) {
|
|
118
|
+
return [2 /*return*/, e];
|
|
119
|
+
}
|
|
120
|
+
if (!e.code) return [3 /*break*/, 11];
|
|
121
|
+
if (!(typeof e.code === 'number')) return [3 /*break*/, 6];
|
|
122
|
+
if (!Object.values(eth_rpc_errors_1.errorCodes.rpc).includes(e.code)) return [3 /*break*/, 4];
|
|
123
|
+
if (!(e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
124
|
+
e.message &&
|
|
125
|
+
e.message.includes('underpriced'))) return [3 /*break*/, 2];
|
|
126
|
+
_a = errors_1.RPCError.bind;
|
|
127
|
+
_b = [void 0, errors_1.LifiErrorCode.TransactionUnderpriced,
|
|
128
|
+
'Transaction is underpriced.'];
|
|
129
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
130
|
+
case 1: return [2 /*return*/, new (_a.apply(errors_1.RPCError, _b.concat([_l.sent(), e.stack])))()];
|
|
131
|
+
case 2:
|
|
132
|
+
_c = errors_1.RPCError.bind;
|
|
133
|
+
_d = [void 0, e.code,
|
|
134
|
+
(0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
|
|
135
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
136
|
+
case 3: return [2 /*return*/, new (_c.apply(errors_1.RPCError, _d.concat([_l.sent(), e.stack])))()];
|
|
137
|
+
case 4:
|
|
138
|
+
if (!Object.values(eth_rpc_errors_1.errorCodes.provider).includes(e.code)) return [3 /*break*/, 6];
|
|
139
|
+
_e = errors_1.ProviderError.bind;
|
|
140
|
+
_f = [void 0, e.code,
|
|
141
|
+
(0, eth_rpc_errors_1.getMessageFromCode)(e.code)];
|
|
142
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
143
|
+
case 5: return [2 /*return*/, new (_e.apply(errors_1.ProviderError, _f.concat([_l.sent(), e.stack])))()];
|
|
144
|
+
case 6:
|
|
145
|
+
if (!(e.code === 'CALL_EXCEPTION')) return [3 /*break*/, 8];
|
|
146
|
+
_g = errors_1.ProviderError.bind;
|
|
147
|
+
_h = [void 0, errors_1.LifiErrorCode.TransactionFailed,
|
|
148
|
+
e.reason];
|
|
149
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
150
|
+
case 7: return [2 /*return*/, new (_g.apply(errors_1.ProviderError, _h.concat([_l.sent(), e.stack])))()];
|
|
151
|
+
case 8:
|
|
152
|
+
if (!(e.code === errors_1.LifiErrorCode.TransactionUnprepared)) return [3 /*break*/, 10];
|
|
153
|
+
_j = errors_1.TransactionError.bind;
|
|
154
|
+
_k = [void 0, errors_1.LifiErrorCode.TransactionUnprepared,
|
|
155
|
+
e.message];
|
|
156
|
+
return [4 /*yield*/, (0, exports.getTransactionNotSentMessage)(step, process)];
|
|
157
|
+
case 9: return [2 /*return*/, new (_j.apply(errors_1.TransactionError, _k.concat([_l.sent(), e.stack])))()];
|
|
158
|
+
case 10:
|
|
159
|
+
if (e.code === errors_1.LifiErrorCode.ValidationError) {
|
|
160
|
+
return [2 /*return*/, new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage)];
|
|
161
|
+
}
|
|
162
|
+
_l.label = 11;
|
|
163
|
+
case 11: return [2 /*return*/, new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack)];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); };
|
|
167
|
+
exports.parseError = parseError;
|
|
168
|
+
var parseBackendError = function (e) {
|
|
169
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
170
|
+
if (((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 400) {
|
|
171
|
+
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);
|
|
172
|
+
}
|
|
173
|
+
if (((_e = e.response) === null || _e === void 0 ? void 0 : _e.status) === 404) {
|
|
174
|
+
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);
|
|
175
|
+
}
|
|
176
|
+
if (((_j = e.response) === null || _j === void 0 ? void 0 : _j.status) === 409) {
|
|
177
|
+
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);
|
|
178
|
+
}
|
|
179
|
+
if (((_o = e.response) === null || _o === void 0 ? void 0 : _o.status) === 500) {
|
|
180
|
+
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);
|
|
181
|
+
}
|
|
182
|
+
return new errors_1.ServerError('Something went wrong.', undefined, e.stack);
|
|
183
|
+
};
|
|
184
|
+
exports.parseBackendError = parseBackendError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TransactionReceipt } from '@ethersproject/providers';
|
|
2
|
+
import { Token } from '@lifi/types';
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
4
|
+
import { Signer } from 'ethers';
|
|
5
|
+
import { ChainId, Step } from '../types';
|
|
6
|
+
export declare const deepClone: <T>(src: T) => T;
|
|
7
|
+
export declare const sleep: (mills: number) => Promise<undefined>;
|
|
8
|
+
export declare const personalizeStep: (signer: Signer, step: Step) => Promise<Step>;
|
|
9
|
+
export declare const splitListIntoChunks: <T>(list: T[], chunkSize: number) => T[][];
|
|
10
|
+
export declare const formatTokenAmountOnly: (token: Token, amount: string | BigNumber | undefined) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
13
|
+
* @param toRepeat The function that should be repeated
|
|
14
|
+
* @param timeout The timeout in milliseconds between retries, defaults to 5000
|
|
15
|
+
* @returns The result of the toRepeat function
|
|
16
|
+
*/
|
|
17
|
+
export declare const repeatUntilDone: <T>(toRepeat: () => Promise<T | undefined>, timeout?: number) => Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Loads a transaction receipt using the rpc for the given chain id
|
|
20
|
+
* @param chainId The chain id where the transaction should be loaded from
|
|
21
|
+
* @param txHash The hash of the transaction
|
|
22
|
+
* @returns TransactionReceipt
|
|
23
|
+
*/
|
|
24
|
+
export declare const loadTransactionReceipt: (chainId: ChainId, txHash: string) => Promise<TransactionReceipt>;
|
|
25
|
+
export declare const isZeroAddress: (address: string) => boolean;
|
|
26
|
+
export declare const isNativeTokenAddress: (address: string) => boolean;
|