@lifi/sdk 2.0.0-beta.1 → 2.0.0-beta.11
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/dist/{Lifi.d.ts → LiFi.d.ts} +19 -63
- package/dist/{Lifi.js → LiFi.js} +19 -212
- package/dist/allowance/checkAllowance.d.ts +2 -2
- package/dist/allowance/checkAllowance.js +16 -2
- package/dist/allowance/utils.d.ts +2 -1
- package/dist/allowance/utils.js +7 -2
- package/dist/balance/checkBalance.d.ts +2 -2
- package/dist/balance/index.d.ts +1 -1
- package/dist/cjs/{Lifi.d.ts → LiFi.d.ts} +19 -63
- package/dist/cjs/{Lifi.js → LiFi.js} +22 -213
- package/dist/cjs/allowance/checkAllowance.d.ts +2 -2
- package/dist/cjs/allowance/checkAllowance.js +16 -2
- package/dist/cjs/allowance/utils.d.ts +2 -1
- package/dist/cjs/allowance/utils.js +7 -2
- package/dist/cjs/balance/checkBalance.d.ts +2 -2
- package/dist/cjs/balance/index.d.ts +1 -1
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/connectors.js +7 -9
- package/dist/cjs/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/cjs/execution/RouteExecutionManager.js +220 -0
- package/dist/cjs/execution/StatusManager.d.ts +12 -12
- package/dist/cjs/execution/StatusManager.js +5 -5
- package/dist/cjs/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/cjs/execution/{ExecutionManager.js → StepExecutionManager.js} +11 -3
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +17 -9
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -5
- package/dist/cjs/execution/switchChain.d.ts +2 -2
- package/dist/cjs/execution/utils.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +5 -7
- package/dist/cjs/helpers.js +10 -30
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/request.d.ts +9 -0
- package/dist/cjs/request.js +60 -0
- package/dist/cjs/services/ApiService.d.ts +8 -7
- package/dist/cjs/services/ApiService.js +52 -31
- package/dist/cjs/services/ConfigService.js +6 -2
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/internal.types.d.ts +54 -10
- package/dist/cjs/utils/errors.d.ts +20 -1
- package/dist/cjs/utils/errors.js +23 -1
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +29 -12
- package/dist/cjs/utils/utils.d.ts +3 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +1 -1
- package/dist/connectors.js +7 -9
- package/dist/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/execution/RouteExecutionManager.js +213 -0
- package/dist/execution/StatusManager.d.ts +12 -12
- package/dist/execution/StatusManager.js +5 -5
- package/dist/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/execution/{ExecutionManager.js → StepExecutionManager.js} +9 -1
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +17 -9
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +2 -5
- package/dist/execution/switchChain.d.ts +2 -2
- package/dist/execution/utils.d.ts +3 -3
- package/dist/helpers.d.ts +5 -7
- package/dist/helpers.js +9 -29
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/dist/request.d.ts +9 -0
- package/dist/request.js +53 -0
- package/dist/services/ApiService.d.ts +8 -7
- package/dist/services/ApiService.js +43 -22
- package/dist/services/ConfigService.js +7 -2
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/internal.types.d.ts +54 -10
- package/dist/utils/errors.d.ts +20 -1
- package/dist/utils/errors.js +22 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +30 -13
- package/dist/utils/utils.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const requestSettings: {
|
|
2
|
+
retries: number;
|
|
3
|
+
};
|
|
4
|
+
interface ExtendedRequestInit extends RequestInit {
|
|
5
|
+
retries?: number;
|
|
6
|
+
skipTrackingHeaders?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const request: <T = Response>(url: RequestInfo | URL, options?: ExtendedRequestInit) => Promise<T>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.request = exports.requestSettings = void 0;
|
|
7
|
+
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
8
|
+
const errors_1 = require("./utils/errors");
|
|
9
|
+
const utils_1 = require("./utils/utils");
|
|
10
|
+
const version_1 = require("./version");
|
|
11
|
+
exports.requestSettings = {
|
|
12
|
+
retries: 1,
|
|
13
|
+
};
|
|
14
|
+
const request = async (url, options = {
|
|
15
|
+
retries: exports.requestSettings.retries,
|
|
16
|
+
}) => {
|
|
17
|
+
const { userId, integrator, widgetVersion } = ConfigService_1.default.getInstance().getConfig();
|
|
18
|
+
options.retries = options.retries ?? exports.requestSettings.retries;
|
|
19
|
+
try {
|
|
20
|
+
if (!options.skipTrackingHeaders) {
|
|
21
|
+
if (userId) {
|
|
22
|
+
options.headers = {
|
|
23
|
+
...options?.headers,
|
|
24
|
+
'X-LIFI-UserId': userId,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (widgetVersion) {
|
|
28
|
+
options.headers = {
|
|
29
|
+
...options?.headers,
|
|
30
|
+
'X-LIFI-Widget': widgetVersion,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (version_1.version) {
|
|
34
|
+
options.headers = {
|
|
35
|
+
...options?.headers,
|
|
36
|
+
'X-LIFI-SDK': version_1.version,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// integrator is mandatory during SDK initialization
|
|
40
|
+
options.headers = {
|
|
41
|
+
...options?.headers,
|
|
42
|
+
'X-LIFI-Integrator': integrator,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const response = await fetch(url, options);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new errors_1.HTTPError(response);
|
|
48
|
+
}
|
|
49
|
+
const data = await response.json();
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (options.retries > 0 && error?.status === 500) {
|
|
54
|
+
await (0, utils_1.sleep)(500);
|
|
55
|
+
return (0, exports.request)(url, { ...options, retries: options.retries - 1 });
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.request = request;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
|
-
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse,
|
|
1
|
+
import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
|
+
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
5
|
+
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
6
6
|
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
7
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
8
|
+
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
9
9
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
|
-
getStatus: (
|
|
11
|
-
getStepTransaction: (step:
|
|
12
|
-
getToken: (chain:
|
|
10
|
+
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
12
|
+
getToken: (chain: ChainId | ChainKey, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
13
13
|
getTokens: (requestConfig?: TokensRequest | undefined, options?: RequestOptions | undefined) => Promise<TokensResponse>;
|
|
14
14
|
getTools: (requestConfig?: ToolsRequest | undefined, options?: RequestOptions | undefined) => Promise<ToolsResponse>;
|
|
15
|
+
getAvailableConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
|
15
16
|
};
|
|
16
17
|
export default _default;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const request_1 = require("../request");
|
|
7
7
|
const typeguards_1 = require("../typeguards");
|
|
8
8
|
const errors_1 = require("../utils/errors");
|
|
9
9
|
const parseError_1 = require("../utils/parseError");
|
|
@@ -24,7 +24,7 @@ const getPossibilities = async (requestConfig, options) => {
|
|
|
24
24
|
}
|
|
25
25
|
// send request
|
|
26
26
|
try {
|
|
27
|
-
const response = await (0,
|
|
27
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/advanced/possibilities`, {
|
|
28
28
|
method: 'POST',
|
|
29
29
|
headers: {
|
|
30
30
|
'Content-Type': 'application/json',
|
|
@@ -47,7 +47,7 @@ const getToken = async (chain, token, options) => {
|
|
|
47
47
|
}
|
|
48
48
|
const config = ConfigService_1.default.getInstance().getConfig();
|
|
49
49
|
try {
|
|
50
|
-
const response = await (0,
|
|
50
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/token?${new URLSearchParams({
|
|
51
51
|
chain,
|
|
52
52
|
token,
|
|
53
53
|
})}`, {
|
|
@@ -100,7 +100,7 @@ const getQuote = async (requestConfig, options) => {
|
|
|
100
100
|
Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
|
|
101
101
|
delete requestConfig[key]);
|
|
102
102
|
try {
|
|
103
|
-
const response = await (0,
|
|
103
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/quote?${new URLSearchParams(requestConfig)}`, {
|
|
104
104
|
signal: options?.signal,
|
|
105
105
|
});
|
|
106
106
|
return response;
|
|
@@ -152,7 +152,7 @@ const getContractCallQuote = async (requestConfig, options) => {
|
|
|
152
152
|
config.defaultRouteOptions.exchanges?.prefer;
|
|
153
153
|
// send request
|
|
154
154
|
try {
|
|
155
|
-
const response = await (0,
|
|
155
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/quote/contractCall`, {
|
|
156
156
|
method: 'POST',
|
|
157
157
|
headers: {
|
|
158
158
|
'Content-Type': 'application/json',
|
|
@@ -166,27 +166,14 @@ const getContractCallQuote = async (requestConfig, options) => {
|
|
|
166
166
|
throw await (0, parseError_1.parseBackendError)(e);
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
const getStatus = async (
|
|
170
|
-
if (
|
|
171
|
-
throw new errors_1.ValidationError('Parameter "bridge" is required for cross chain transfers.');
|
|
172
|
-
}
|
|
173
|
-
if (!fromChain) {
|
|
174
|
-
throw new errors_1.ValidationError('Required parameter "fromChain" is missing.');
|
|
175
|
-
}
|
|
176
|
-
if (!toChain) {
|
|
177
|
-
throw new errors_1.ValidationError('Required parameter "toChain" is missing.');
|
|
178
|
-
}
|
|
179
|
-
if (!txHash) {
|
|
169
|
+
const getStatus = async (requestConfig, options) => {
|
|
170
|
+
if (!requestConfig.txHash) {
|
|
180
171
|
throw new errors_1.ValidationError('Required parameter "txHash" is missing.');
|
|
181
172
|
}
|
|
182
173
|
const config = ConfigService_1.default.getInstance().getConfig();
|
|
174
|
+
const queryParams = new URLSearchParams(requestConfig);
|
|
183
175
|
try {
|
|
184
|
-
const response = await (0,
|
|
185
|
-
bridge,
|
|
186
|
-
fromChain,
|
|
187
|
-
toChain,
|
|
188
|
-
txHash,
|
|
189
|
-
})}`, {
|
|
176
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/status?${queryParams}`, {
|
|
190
177
|
signal: options?.signal,
|
|
191
178
|
});
|
|
192
179
|
return response;
|
|
@@ -198,7 +185,7 @@ const getStatus = async ({ bridge, fromChain, toChain, txHash }, options) => {
|
|
|
198
185
|
const getChains = async (options) => {
|
|
199
186
|
const config = ConfigService_1.default.getInstance().getConfig();
|
|
200
187
|
try {
|
|
201
|
-
const response = await (0,
|
|
188
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/chains`, {
|
|
202
189
|
signal: options?.signal,
|
|
203
190
|
});
|
|
204
191
|
return response.chains;
|
|
@@ -219,7 +206,7 @@ const getRoutes = async (requestConfig, options) => {
|
|
|
219
206
|
};
|
|
220
207
|
// send request
|
|
221
208
|
try {
|
|
222
|
-
const response = await (0,
|
|
209
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/advanced/routes`, {
|
|
223
210
|
method: 'POST',
|
|
224
211
|
headers: {
|
|
225
212
|
'Content-Type': 'application/json',
|
|
@@ -241,7 +228,7 @@ const getStepTransaction = async (step, options) => {
|
|
|
241
228
|
}
|
|
242
229
|
const config = ConfigService_1.default.getInstance().getConfig();
|
|
243
230
|
try {
|
|
244
|
-
const response = await (0,
|
|
231
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/advanced/stepTransaction`, {
|
|
245
232
|
method: 'POST',
|
|
246
233
|
headers: {
|
|
247
234
|
'Content-Type': 'application/json',
|
|
@@ -261,7 +248,7 @@ const getTools = async (requestConfig, options) => {
|
|
|
261
248
|
Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
|
|
262
249
|
delete requestConfig[key]);
|
|
263
250
|
}
|
|
264
|
-
const response = await (0,
|
|
251
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/tools?${new URLSearchParams(requestConfig)}`, {
|
|
265
252
|
signal: options?.signal,
|
|
266
253
|
});
|
|
267
254
|
return response;
|
|
@@ -272,7 +259,7 @@ const getTokens = async (requestConfig, options) => {
|
|
|
272
259
|
Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
|
|
273
260
|
delete requestConfig[key]);
|
|
274
261
|
}
|
|
275
|
-
const response = await (0,
|
|
262
|
+
const response = await (0, request_1.request)(`${config.apiUrl}/tokens?${new URLSearchParams(requestConfig)}`, {
|
|
276
263
|
signal: options?.signal,
|
|
277
264
|
});
|
|
278
265
|
return response;
|
|
@@ -282,11 +269,15 @@ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options)
|
|
|
282
269
|
if (!chainId) {
|
|
283
270
|
throw new errors_1.ValidationError('Required parameter "chainId" is missing.');
|
|
284
271
|
}
|
|
272
|
+
const url = new URL(`${config.apiUrl}/gas/suggestion/${chainId}`);
|
|
273
|
+
if (fromChain) {
|
|
274
|
+
url.searchParams.append('fromChain', fromChain);
|
|
275
|
+
}
|
|
276
|
+
if (fromToken) {
|
|
277
|
+
url.searchParams.append('fromToken', fromToken);
|
|
278
|
+
}
|
|
285
279
|
try {
|
|
286
|
-
const response = await (0,
|
|
287
|
-
fromChain,
|
|
288
|
-
fromToken,
|
|
289
|
-
})}`, {
|
|
280
|
+
const response = await (0, request_1.request)(url, {
|
|
290
281
|
signal: options?.signal,
|
|
291
282
|
});
|
|
292
283
|
return response;
|
|
@@ -295,6 +286,35 @@ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options)
|
|
|
295
286
|
throw await (0, parseError_1.parseBackendError)(e);
|
|
296
287
|
}
|
|
297
288
|
};
|
|
289
|
+
const getAvailableConnections = async (connectionRequest) => {
|
|
290
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
291
|
+
const url = new URL(`${config.apiUrl}/connections`);
|
|
292
|
+
const { fromChain, fromToken, toChain, toToken, allowBridges } = connectionRequest;
|
|
293
|
+
if (fromChain) {
|
|
294
|
+
url.searchParams.append('fromChain', fromChain);
|
|
295
|
+
}
|
|
296
|
+
if (fromToken) {
|
|
297
|
+
url.searchParams.append('fromToken', fromToken);
|
|
298
|
+
}
|
|
299
|
+
if (toChain) {
|
|
300
|
+
url.searchParams.append('fromToken', toChain);
|
|
301
|
+
}
|
|
302
|
+
if (toToken) {
|
|
303
|
+
url.searchParams.append('fromToken', toToken);
|
|
304
|
+
}
|
|
305
|
+
if (allowBridges?.length) {
|
|
306
|
+
allowBridges.forEach((bridge) => {
|
|
307
|
+
url.searchParams.append('allowBridges', bridge);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const response = await (0, request_1.request)(url);
|
|
312
|
+
return response;
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
throw await (0, parseError_1.parseBackendError)(e);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
298
318
|
exports.default = {
|
|
299
319
|
getChains,
|
|
300
320
|
getContractCallQuote,
|
|
@@ -307,4 +327,5 @@ exports.default = {
|
|
|
307
327
|
getToken,
|
|
308
328
|
getTokens,
|
|
309
329
|
getTools,
|
|
330
|
+
getAvailableConnections,
|
|
310
331
|
};
|
|
@@ -5,7 +5,6 @@ const DefaultExecutionSettings = {
|
|
|
5
5
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
6
6
|
updateCallback: () => { },
|
|
7
7
|
switchChainHook: () => Promise.resolve(undefined),
|
|
8
|
-
acceptSlippageUpdateHook: () => Promise.resolve(undefined),
|
|
9
8
|
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined),
|
|
10
9
|
infiniteApproval: false,
|
|
11
10
|
executeInBackground: false,
|
|
@@ -39,6 +38,10 @@ class ConfigService {
|
|
|
39
38
|
this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
|
|
40
39
|
// OPTIONS
|
|
41
40
|
this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
|
|
41
|
+
this.config.userId = configUpdate.userId || this.config.userId;
|
|
42
|
+
this.config.integrator = configUpdate.integrator || this.config.integrator;
|
|
43
|
+
this.config.widgetVersion =
|
|
44
|
+
configUpdate.widgetVersion || this.config.widgetVersion;
|
|
42
45
|
return this.config;
|
|
43
46
|
};
|
|
44
47
|
this.updateChains = (chains) => {
|
|
@@ -78,7 +81,6 @@ class ConfigService {
|
|
|
78
81
|
return this.instance;
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
exports.default = ConfigService;
|
|
82
84
|
ConfigService.getDefaultConfig = () => {
|
|
83
85
|
return {
|
|
84
86
|
apiUrl: 'https://li.quest/v1',
|
|
@@ -88,5 +90,7 @@ ConfigService.getDefaultConfig = () => {
|
|
|
88
90
|
defaultRouteOptions: {
|
|
89
91
|
integrator: 'lifi-sdk',
|
|
90
92
|
},
|
|
93
|
+
integrator: 'lifi-sdk',
|
|
91
94
|
};
|
|
92
95
|
};
|
|
96
|
+
exports.default = ConfigService;
|
package/dist/cjs/typeguards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifiStep, RoutesRequest, Token } from './types';
|
|
2
2
|
export declare const isRoutesRequest: (routesRequest: RoutesRequest) => routesRequest is RoutesRequest;
|
|
3
|
-
export declare const isStep: (step:
|
|
3
|
+
export declare const isStep: (step: LifiStep) => step is LifiStep;
|
|
4
4
|
export declare const isToken: (token: Token) => token is Token;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
2
|
+
import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { Signer } from 'ethers';
|
|
4
5
|
import { ChainId } from '.';
|
|
@@ -18,11 +19,12 @@ export type ParsedReceipt = {
|
|
|
18
19
|
};
|
|
19
20
|
export interface ExecutionParams {
|
|
20
21
|
signer: Signer;
|
|
21
|
-
step:
|
|
22
|
+
step: LifiStep;
|
|
22
23
|
statusManager: StatusManager;
|
|
23
24
|
settings: InternalExecutionSettings;
|
|
24
25
|
}
|
|
25
26
|
export type CallbackFunction = (updatedRoute: Route) => void;
|
|
27
|
+
export type TxRequestCallbackFunction = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
|
|
26
28
|
export type Config = {
|
|
27
29
|
apiUrl: string;
|
|
28
30
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -30,6 +32,9 @@ export type Config = {
|
|
|
30
32
|
defaultExecutionSettings: InternalExecutionSettings;
|
|
31
33
|
defaultRouteOptions: RouteOptions;
|
|
32
34
|
disableVersionCheck?: boolean;
|
|
35
|
+
userId?: string;
|
|
36
|
+
integrator: string;
|
|
37
|
+
widgetVersion?: string;
|
|
33
38
|
};
|
|
34
39
|
export type ConfigUpdate = {
|
|
35
40
|
apiUrl?: string;
|
|
@@ -38,6 +43,9 @@ export type ConfigUpdate = {
|
|
|
38
43
|
defaultExecutionSettings?: ExecutionSettings;
|
|
39
44
|
defaultRouteOptions?: RouteOptions;
|
|
40
45
|
disableVersionCheck?: boolean;
|
|
46
|
+
userId?: string;
|
|
47
|
+
integrator: string;
|
|
48
|
+
widgetVersion?: string;
|
|
41
49
|
};
|
|
42
50
|
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
43
51
|
export interface AcceptSlippageUpdateHookParams {
|
|
@@ -54,7 +62,7 @@ export interface ExchangeRateUpdateParams {
|
|
|
54
62
|
newToAmount: string;
|
|
55
63
|
}
|
|
56
64
|
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>;
|
|
57
|
-
export interface
|
|
65
|
+
export interface RouteExecutionData {
|
|
58
66
|
route: Route;
|
|
59
67
|
executors: StepExecutor[];
|
|
60
68
|
settings: InternalExecutionSettings;
|
|
@@ -63,20 +71,16 @@ export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
|
63
71
|
export interface InternalExecutionSettings {
|
|
64
72
|
updateCallback: CallbackFunction;
|
|
65
73
|
switchChainHook: SwitchChainHook;
|
|
66
|
-
acceptSlippageUpdateHook: AcceptSlippageUpdateHook;
|
|
67
74
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
68
75
|
infiniteApproval: boolean;
|
|
69
76
|
executeInBackground: boolean;
|
|
77
|
+
updateTransactionRequest?: TxRequestCallbackFunction;
|
|
70
78
|
}
|
|
71
79
|
export type EnforcedObjectProperties<T> = T & {
|
|
72
80
|
[P in keyof T]-?: T[P];
|
|
73
81
|
};
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
executionData: ExecutionData;
|
|
77
|
-
executionPromise: Promise<Route>;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
82
|
+
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
83
|
+
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
80
84
|
export type RevokeTokenData = {
|
|
81
85
|
token: Token;
|
|
82
86
|
approvalAddress: string;
|
|
@@ -86,3 +90,43 @@ export interface InteractionSettings {
|
|
|
86
90
|
allowUpdates?: boolean;
|
|
87
91
|
stopExecution?: boolean;
|
|
88
92
|
}
|
|
93
|
+
export interface TenderlyResponse {
|
|
94
|
+
hash: string;
|
|
95
|
+
block_hash: string;
|
|
96
|
+
block_number: number;
|
|
97
|
+
from: string;
|
|
98
|
+
gas: number;
|
|
99
|
+
gas_price: number;
|
|
100
|
+
gas_fee_cap: number;
|
|
101
|
+
gas_tip_cap: number;
|
|
102
|
+
cumulative_gas_used: number;
|
|
103
|
+
gas_used: number;
|
|
104
|
+
effective_gas_price: number;
|
|
105
|
+
input: string;
|
|
106
|
+
nonce: number;
|
|
107
|
+
to: string;
|
|
108
|
+
index: number;
|
|
109
|
+
value: string;
|
|
110
|
+
access_list: any;
|
|
111
|
+
status: boolean;
|
|
112
|
+
addresses: string[];
|
|
113
|
+
contract_ids: string[];
|
|
114
|
+
network_id: string;
|
|
115
|
+
timestamp: string;
|
|
116
|
+
function_selector: string;
|
|
117
|
+
l1_block_number: number;
|
|
118
|
+
l1_timestamp: number;
|
|
119
|
+
deposit_tx: boolean;
|
|
120
|
+
system_tx: boolean;
|
|
121
|
+
mint: number;
|
|
122
|
+
sig: Signature;
|
|
123
|
+
error_message: string;
|
|
124
|
+
method: string;
|
|
125
|
+
decoded_input: any;
|
|
126
|
+
call_trace: any;
|
|
127
|
+
}
|
|
128
|
+
export interface Signature {
|
|
129
|
+
v: string;
|
|
130
|
+
r: string;
|
|
131
|
+
s: string;
|
|
132
|
+
}
|
|
@@ -22,7 +22,26 @@ export declare enum LifiErrorCode {
|
|
|
22
22
|
TransactionCanceled = 1010,
|
|
23
23
|
SlippageError = 1011,
|
|
24
24
|
TransactionRejected = 1012,
|
|
25
|
-
BalanceError = 1013
|
|
25
|
+
BalanceError = 1013,
|
|
26
|
+
AllowanceRequired = 1014
|
|
27
|
+
}
|
|
28
|
+
export declare enum EthersErrorType {
|
|
29
|
+
CallExecption = "CALL_EXCEPTION",
|
|
30
|
+
ActionRejected = "ACTION_REJECTED"
|
|
31
|
+
}
|
|
32
|
+
export declare enum EthersErrorMessage {
|
|
33
|
+
ERC20Allowance = "ERC20: transfer amount exceeds allowance",
|
|
34
|
+
LowGas = "intrinsic gas too low",
|
|
35
|
+
OutOfGas = "out of gas",
|
|
36
|
+
Underpriced = "underpriced",
|
|
37
|
+
LowReplacementFee = "replacement fee too low"
|
|
38
|
+
}
|
|
39
|
+
export declare enum ErrorMessage {
|
|
40
|
+
UnknownError = "Unknown error occurred.",
|
|
41
|
+
SlippageError = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.",
|
|
42
|
+
GasLimitLow = "Gas limit is too low.",
|
|
43
|
+
TransactionUnderpriced = "Transaction is underpriced.",
|
|
44
|
+
Default = "Something went wrong."
|
|
26
45
|
}
|
|
27
46
|
export declare enum MetaMaskRPCErrorCode {
|
|
28
47
|
invalidInput = -32000,
|
package/dist/cjs/utils/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.LifiErrorCode = void 0;
|
|
3
|
+
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.ErrorMessage = exports.EthersErrorMessage = exports.EthersErrorType = exports.LifiErrorCode = void 0;
|
|
4
4
|
var ErrorType;
|
|
5
5
|
(function (ErrorType) {
|
|
6
6
|
ErrorType["RPCError"] = "RPCError";
|
|
@@ -28,7 +28,29 @@ var LifiErrorCode;
|
|
|
28
28
|
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
29
29
|
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
|
|
30
30
|
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
31
|
+
LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
31
32
|
})(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
|
|
33
|
+
var EthersErrorType;
|
|
34
|
+
(function (EthersErrorType) {
|
|
35
|
+
EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
|
|
36
|
+
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
37
|
+
})(EthersErrorType = exports.EthersErrorType || (exports.EthersErrorType = {}));
|
|
38
|
+
var EthersErrorMessage;
|
|
39
|
+
(function (EthersErrorMessage) {
|
|
40
|
+
EthersErrorMessage["ERC20Allowance"] = "ERC20: transfer amount exceeds allowance";
|
|
41
|
+
EthersErrorMessage["LowGas"] = "intrinsic gas too low";
|
|
42
|
+
EthersErrorMessage["OutOfGas"] = "out of gas";
|
|
43
|
+
EthersErrorMessage["Underpriced"] = "underpriced";
|
|
44
|
+
EthersErrorMessage["LowReplacementFee"] = "replacement fee too low";
|
|
45
|
+
})(EthersErrorMessage = exports.EthersErrorMessage || (exports.EthersErrorMessage = {}));
|
|
46
|
+
var ErrorMessage;
|
|
47
|
+
(function (ErrorMessage) {
|
|
48
|
+
ErrorMessage["UnknownError"] = "Unknown error occurred.";
|
|
49
|
+
ErrorMessage["SlippageError"] = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.";
|
|
50
|
+
ErrorMessage["GasLimitLow"] = "Gas limit is too low.";
|
|
51
|
+
ErrorMessage["TransactionUnderpriced"] = "Transaction is underpriced.";
|
|
52
|
+
ErrorMessage["Default"] = "Something went wrong.";
|
|
53
|
+
})(ErrorMessage = exports.ErrorMessage || (exports.ErrorMessage = {}));
|
|
32
54
|
var MetaMaskRPCErrorCode;
|
|
33
55
|
(function (MetaMaskRPCErrorCode) {
|
|
34
56
|
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidInput"] = -32000] = "invalidInput";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifiStep, Process } from '@lifi/types';
|
|
2
2
|
import { LifiError } from './errors';
|
|
3
3
|
/**
|
|
4
4
|
* Available MetaMask error codes:
|
|
@@ -31,7 +31,7 @@ import { LifiError } from './errors';
|
|
|
31
31
|
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
32
32
|
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
33
33
|
*/
|
|
34
|
-
export declare const getTransactionNotSentMessage: (step?:
|
|
35
|
-
export declare const getTransactionFailedMessage: (step:
|
|
36
|
-
export declare const parseError: (e: any, step?:
|
|
34
|
+
export declare const getTransactionNotSentMessage: (step?: LifiStep, process?: Process) => Promise<string>;
|
|
35
|
+
export declare const getTransactionFailedMessage: (step: LifiStep, txLink?: string) => Promise<string>;
|
|
36
|
+
export declare const parseError: (e: any, step?: LifiStep, process?: Process) => Promise<LifiError>;
|
|
37
37
|
export declare const parseBackendError: (e: any) => Promise<LifiError>;
|
|
@@ -8,6 +8,7 @@ const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
|
8
8
|
const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
11
12
|
/**
|
|
12
13
|
* Available MetaMask error codes:
|
|
13
14
|
*
|
|
@@ -79,13 +80,13 @@ const parseError = async (e, step, process) => {
|
|
|
79
80
|
// rpc errors
|
|
80
81
|
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
81
82
|
if (e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
82
|
-
(e.message?.includes(
|
|
83
|
-
e.message?.includes(
|
|
84
|
-
return new errors_1.RPCError(errors_1.LifiErrorCode.TransactionUnderpriced,
|
|
83
|
+
(e.message?.includes(errors_1.EthersErrorMessage.Underpriced) ||
|
|
84
|
+
e.message?.includes(errors_1.EthersErrorMessage.LowReplacementFee))) {
|
|
85
|
+
return new errors_1.RPCError(errors_1.LifiErrorCode.TransactionUnderpriced, errors_1.ErrorMessage.TransactionUnderpriced, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
85
86
|
}
|
|
86
|
-
if (e.message?.includes(
|
|
87
|
-
e.message?.includes(
|
|
88
|
-
return new errors_1.TransactionError(errors_1.LifiErrorCode.GasLimitError,
|
|
87
|
+
if (e.message?.includes(errors_1.EthersErrorMessage.LowGas) ||
|
|
88
|
+
e.message?.includes(errors_1.EthersErrorMessage.OutOfGas)) {
|
|
89
|
+
return new errors_1.TransactionError(errors_1.LifiErrorCode.GasLimitError, errors_1.ErrorMessage.GasLimitLow, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
89
90
|
}
|
|
90
91
|
return new errors_1.RPCError(e.code, (0, eth_rpc_errors_1.getMessageFromCode)(e.code), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
91
92
|
}
|
|
@@ -96,9 +97,25 @@ const parseError = async (e, step, process) => {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
switch (e.code) {
|
|
99
|
-
case
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
case errors_1.EthersErrorType.CallExecption:
|
|
101
|
+
const defaultErrorMessage = await (0, exports.getTransactionNotSentMessage)(step, process);
|
|
102
|
+
try {
|
|
103
|
+
if (!step?.action.fromChainId) {
|
|
104
|
+
throw new Error('Signer is not defined.');
|
|
105
|
+
}
|
|
106
|
+
const response = await (0, helpers_1.fetchTxErrorDetails)(e.transactionHash, step?.action.fromChainId);
|
|
107
|
+
const errorMessage = response?.error_message ?? e.reason;
|
|
108
|
+
const isAllowanceError = response?.error_message?.includes(errors_1.EthersErrorMessage.ERC20Allowance) || e.reason?.includes(errors_1.EthersErrorMessage.ERC20Allowance);
|
|
109
|
+
if (isAllowanceError) {
|
|
110
|
+
return new errors_1.TransactionError(errors_1.LifiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
|
|
111
|
+
}
|
|
112
|
+
// Error messages other than allowance error will be handled in catch block
|
|
113
|
+
throw new Error(e);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return new errors_1.ProviderError(errors_1.LifiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
|
|
117
|
+
}
|
|
118
|
+
case errors_1.EthersErrorType.ActionRejected:
|
|
102
119
|
case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
|
|
103
120
|
return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
104
121
|
case errors_1.LifiErrorCode.TransactionUnprepared:
|
|
@@ -106,7 +123,7 @@ const parseError = async (e, step, process) => {
|
|
|
106
123
|
case errors_1.LifiErrorCode.ValidationError:
|
|
107
124
|
return new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
108
125
|
default:
|
|
109
|
-
return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message ||
|
|
126
|
+
return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || errors_1.ErrorMessage.UnknownError, undefined, e.stack);
|
|
110
127
|
}
|
|
111
128
|
};
|
|
112
129
|
exports.parseError = parseError;
|
|
@@ -125,11 +142,11 @@ const parseBackendError = async (e) => {
|
|
|
125
142
|
return new errors_1.NotFoundError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
126
143
|
}
|
|
127
144
|
if (e.response?.status === 409) {
|
|
128
|
-
return new errors_1.SlippageError(data?.message || e.response?.statusText,
|
|
145
|
+
return new errors_1.SlippageError(data?.message || e.response?.statusText, errors_1.ErrorMessage.SlippageError, e.stack);
|
|
129
146
|
}
|
|
130
147
|
if (e.response?.status === 500) {
|
|
131
148
|
return new errors_1.ServerError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
132
149
|
}
|
|
133
|
-
return new errors_1.ServerError(
|
|
150
|
+
return new errors_1.ServerError(errors_1.ErrorMessage.Default, undefined, e.stack);
|
|
134
151
|
};
|
|
135
152
|
exports.parseBackendError = parseBackendError;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TransactionReceipt } from '@ethersproject/providers';
|
|
2
|
-
import { Token } from '@lifi/types';
|
|
2
|
+
import { LifiStep, Token } from '@lifi/types';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Signer } from 'ethers';
|
|
5
|
-
import { ChainId
|
|
5
|
+
import { ChainId } from '../types';
|
|
6
6
|
export declare const sleep: (mills: number) => Promise<undefined>;
|
|
7
|
-
export declare const personalizeStep: (signer: Signer, step:
|
|
7
|
+
export declare const personalizeStep: (signer: Signer, step: LifiStep) => Promise<LifiStep>;
|
|
8
8
|
export declare const splitListIntoChunks: <T>(list: T[], chunkSize: number) => T[][];
|
|
9
9
|
export declare const formatTokenAmountOnly: (token: Token, amount: string | BigNumber | undefined) => string;
|
|
10
10
|
/**
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.11";
|
package/dist/cjs/version.js
CHANGED
package/dist/connectors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChainId } from './types';
|
|
2
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
+
import { ChainId } from './types';
|
|
3
3
|
export declare const getRpcUrl: (chainId: ChainId, archive?: boolean) => Promise<string>;
|
|
4
4
|
export declare const getRpcUrls: (chainId: ChainId, archive?: boolean) => Promise<string[]>;
|
|
5
5
|
export declare const getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
|