@lifi/sdk 2.0.0-beta.5 → 2.0.0-beta.7
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 +8 -2
- package/dist/LiFi.js +9 -0
- package/dist/allowance/checkAllowance.d.ts +2 -2
- package/dist/balance/checkBalance.d.ts +2 -2
- package/dist/balance/index.d.ts +1 -1
- package/dist/cjs/LiFi.d.ts +8 -2
- package/dist/cjs/LiFi.js +11 -1
- package/dist/cjs/allowance/checkAllowance.d.ts +2 -2
- package/dist/cjs/balance/checkBalance.d.ts +2 -2
- package/dist/cjs/balance/index.d.ts +1 -1
- package/dist/cjs/execution/StatusManager.d.ts +12 -12
- package/dist/cjs/execution/StatusManager.js +5 -5
- package/dist/cjs/execution/StepExecutor.d.ts +2 -2
- package/dist/cjs/execution/stepComparison.d.ts +2 -2
- package/dist/cjs/execution/switchChain.d.ts +2 -2
- package/dist/cjs/execution/utils.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +0 -4
- package/dist/cjs/helpers.js +3 -55
- package/dist/cjs/request.d.ts +9 -0
- package/dist/cjs/request.js +60 -0
- package/dist/cjs/services/ApiService.d.ts +4 -3
- package/dist/cjs/services/ApiService.js +45 -28
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/internal.types.d.ts +2 -2
- package/dist/cjs/utils/parseError.d.ts +4 -4
- 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/execution/StatusManager.d.ts +12 -12
- package/dist/execution/StatusManager.js +5 -5
- package/dist/execution/StepExecutor.d.ts +2 -2
- package/dist/execution/stepComparison.d.ts +2 -2
- package/dist/execution/switchChain.d.ts +2 -2
- package/dist/execution/utils.d.ts +3 -3
- package/dist/helpers.d.ts +0 -4
- package/dist/helpers.js +3 -51
- package/dist/request.d.ts +9 -0
- package/dist/request.js +53 -0
- package/dist/services/ApiService.d.ts +4 -3
- package/dist/services/ApiService.js +35 -18
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/internal.types.d.ts +2 -2
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/utils.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -13
|
@@ -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;
|
|
@@ -290,7 +277,7 @@ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options)
|
|
|
290
277
|
url.searchParams.append('fromToken', fromToken);
|
|
291
278
|
}
|
|
292
279
|
try {
|
|
293
|
-
const response = await (0,
|
|
280
|
+
const response = await (0, request_1.request)(url, {
|
|
294
281
|
signal: options?.signal,
|
|
295
282
|
});
|
|
296
283
|
return response;
|
|
@@ -299,6 +286,35 @@ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options)
|
|
|
299
286
|
throw await (0, parseError_1.parseBackendError)(e);
|
|
300
287
|
}
|
|
301
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
|
+
};
|
|
302
318
|
exports.default = {
|
|
303
319
|
getChains,
|
|
304
320
|
getContractCallQuote,
|
|
@@ -311,4 +327,5 @@ exports.default = {
|
|
|
311
327
|
getToken,
|
|
312
328
|
getTokens,
|
|
313
329
|
getTools,
|
|
330
|
+
getAvailableConnections,
|
|
314
331
|
};
|
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,4 @@
|
|
|
1
|
-
import { Route, RouteOptions,
|
|
1
|
+
import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ChainId } from '.';
|
|
@@ -18,7 +18,7 @@ export type ParsedReceipt = {
|
|
|
18
18
|
};
|
|
19
19
|
export interface ExecutionParams {
|
|
20
20
|
signer: Signer;
|
|
21
|
-
step:
|
|
21
|
+
step: LifiStep;
|
|
22
22
|
statusManager: StatusManager;
|
|
23
23
|
settings: InternalExecutionSettings;
|
|
24
24
|
}
|
|
@@ -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>;
|
|
@@ -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.7";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Execution, InternalExecutionSettings, Process, ProcessType, Route, Status,
|
|
1
|
+
import { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
|
|
2
2
|
interface Receipt {
|
|
3
3
|
fromAmount?: string;
|
|
4
4
|
toAmount?: string;
|
|
@@ -26,43 +26,43 @@ export declare class StatusManager {
|
|
|
26
26
|
constructor(route: Route, settings: InternalExecutionSettings, internalUpdateRouteCallback: InternalUpdateRouteCallback);
|
|
27
27
|
/**
|
|
28
28
|
* Initializes the execution object of a Step.
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {LifiStep} step The current step in execution
|
|
30
30
|
* @return {Execution} The initialized execution object for this step and a function to update this step
|
|
31
31
|
*/
|
|
32
|
-
initExecutionObject: (step:
|
|
32
|
+
initExecutionObject: (step: LifiStep) => Execution;
|
|
33
33
|
/**
|
|
34
34
|
* Updates the execution object of a Step.
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {LifiStep} step The current step in execution
|
|
36
36
|
* @param {Status} status The status for the execution
|
|
37
37
|
* @param {Receipt} receipt Optional. Information about received tokens
|
|
38
38
|
* @return {Step} The step with the updated execution object
|
|
39
39
|
*/
|
|
40
|
-
updateExecution(step:
|
|
40
|
+
updateExecution(step: LifiStep, status: Status, receipt?: Receipt): LifiStep;
|
|
41
41
|
/**
|
|
42
42
|
* Create and push a new process into the execution.
|
|
43
43
|
* @param {ProcessType} type Type of the process. Used to identify already existing processes.
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {LifiStep} step The step that should contain the new process.
|
|
45
45
|
* @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
46
46
|
* @return {Process}
|
|
47
47
|
*/
|
|
48
|
-
findOrCreateProcess: (step:
|
|
48
|
+
findOrCreateProcess: (step: LifiStep, type: ProcessType, status?: Status) => Process;
|
|
49
49
|
/**
|
|
50
50
|
* Update a process object.
|
|
51
|
-
* @param {
|
|
51
|
+
* @param {LifiStep} step The step where the process should be updated
|
|
52
52
|
* @param {ProcessType} type The process type to update
|
|
53
53
|
* @param {Status} status The status the process gets.
|
|
54
54
|
* @param {object} [params] Additional parameters to append to the process.
|
|
55
55
|
* @return {Process} The update process
|
|
56
56
|
*/
|
|
57
|
-
updateProcess: (step:
|
|
57
|
+
updateProcess: (step: LifiStep, type: ProcessType, status: Status, params?: OptionalParameters) => Process;
|
|
58
58
|
/**
|
|
59
59
|
* Remove a process from the execution
|
|
60
|
-
* @param {
|
|
60
|
+
* @param {LifiStep} step The step where the process should be removed from
|
|
61
61
|
* @param {ProcessType} type The process type to remove
|
|
62
62
|
* @return {void}
|
|
63
63
|
*/
|
|
64
|
-
removeProcess: (step:
|
|
65
|
-
updateStepInRoute: (step:
|
|
64
|
+
removeProcess: (step: LifiStep, type: ProcessType) => void;
|
|
65
|
+
updateStepInRoute: (step: LifiStep) => LifiStep;
|
|
66
66
|
allowUpdates(value: boolean): void;
|
|
67
67
|
}
|
|
68
68
|
export {};
|
|
@@ -12,7 +12,7 @@ export class StatusManager {
|
|
|
12
12
|
this.shouldUpdate = true;
|
|
13
13
|
/**
|
|
14
14
|
* Initializes the execution object of a Step.
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {LifiStep} step The current step in execution
|
|
16
16
|
* @return {Execution} The initialized execution object for this step and a function to update this step
|
|
17
17
|
*/
|
|
18
18
|
this.initExecutionObject = (step) => {
|
|
@@ -32,7 +32,7 @@ export class StatusManager {
|
|
|
32
32
|
/**
|
|
33
33
|
* Create and push a new process into the execution.
|
|
34
34
|
* @param {ProcessType} type Type of the process. Used to identify already existing processes.
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {LifiStep} step The step that should contain the new process.
|
|
36
36
|
* @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
37
37
|
* @return {Process}
|
|
38
38
|
*/
|
|
@@ -60,7 +60,7 @@ export class StatusManager {
|
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
62
|
* Update a process object.
|
|
63
|
-
* @param {
|
|
63
|
+
* @param {LifiStep} step The step where the process should be updated
|
|
64
64
|
* @param {ProcessType} type The process type to update
|
|
65
65
|
* @param {Status} status The status the process gets.
|
|
66
66
|
* @param {object} [params] Additional parameters to append to the process.
|
|
@@ -112,7 +112,7 @@ export class StatusManager {
|
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
114
|
* Remove a process from the execution
|
|
115
|
-
* @param {
|
|
115
|
+
* @param {LifiStep} step The step where the process should be removed from
|
|
116
116
|
* @param {ProcessType} type The process type to remove
|
|
117
117
|
* @return {void}
|
|
118
118
|
*/
|
|
@@ -143,7 +143,7 @@ export class StatusManager {
|
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Updates the execution object of a Step.
|
|
146
|
-
* @param {
|
|
146
|
+
* @param {LifiStep} step The current step in execution
|
|
147
147
|
* @param {Status} status The status for the execution
|
|
148
148
|
* @param {Receipt} receipt Optional. Information about received tokens
|
|
149
149
|
* @return {Step} The step with the updated execution object
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { InteractionSettings, InternalExecutionSettings,
|
|
2
|
+
import { InteractionSettings, InternalExecutionSettings, LifiStep } from '../types';
|
|
3
3
|
import { StatusManager } from './StatusManager';
|
|
4
4
|
import { StepExecutionManager } from './StepExecutionManager';
|
|
5
5
|
export declare class StepExecutor {
|
|
@@ -11,5 +11,5 @@ export declare class StepExecutor {
|
|
|
11
11
|
constructor(statusManager: StatusManager, settings: InternalExecutionSettings);
|
|
12
12
|
setInteraction: (settings?: InteractionSettings) => void;
|
|
13
13
|
checkChain: () => never;
|
|
14
|
-
executeStep: (signer: Signer, step:
|
|
14
|
+
executeStep: (signer: Signer, step: LifiStep) => Promise<LifiStep>;
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StatusManager } from '.';
|
|
2
|
-
import { InternalExecutionSettings,
|
|
2
|
+
import { InternalExecutionSettings, LifiStep } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
5
5
|
* If yes it returns the updated Step.
|
|
@@ -11,4 +11,4 @@ import { InternalExecutionSettings, Step } from '../types';
|
|
|
11
11
|
* @param acceptSlippageUpdateHook
|
|
12
12
|
* @param allowUserInteraction
|
|
13
13
|
*/
|
|
14
|
-
export declare const stepComparison: (statusManager: StatusManager, oldStep:
|
|
14
|
+
export declare const stepComparison: (statusManager: StatusManager, oldStep: LifiStep, newStep: LifiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LifiStep>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifiStep } from '@lifi/types';
|
|
2
2
|
import { Signer } from 'ethers';
|
|
3
3
|
import { SwitchChainHook } from '../types';
|
|
4
4
|
import { StatusManager } from './StatusManager';
|
|
@@ -13,4 +13,4 @@ import { StatusManager } from './StatusManager';
|
|
|
13
13
|
* @param switchChainHook
|
|
14
14
|
* @param allowUserInteraction
|
|
15
15
|
*/
|
|
16
|
-
export declare const switchChain: (signer: Signer, statusManager: StatusManager, step:
|
|
16
|
+
export declare const switchChain: (signer: Signer, statusManager: StatusManager, step: LifiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<Signer | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ProcessType, Status, StatusMessage, StatusResponse,
|
|
1
|
+
import { LifiStep, ProcessType, Status, StatusMessage, StatusResponse, Substatus } from '@lifi/types';
|
|
2
2
|
import { StatusManager } from '..';
|
|
3
|
-
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step:
|
|
3
|
+
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LifiStep): Promise<StatusResponse>;
|
|
4
4
|
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
5
5
|
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
6
|
-
export declare function checkStepSlippageThreshold(oldStep:
|
|
6
|
+
export declare function checkStepSlippageThreshold(oldStep: LifiStep, newStep: LifiStep): boolean;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -24,7 +24,3 @@ export declare const checkPackageUpdates: (packageName?: string, packageVersion?
|
|
|
24
24
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
25
25
|
*/
|
|
26
26
|
export declare const convertQuoteToRoute: (step: Step) => Route;
|
|
27
|
-
export declare const requestSettings: {
|
|
28
|
-
retries: number;
|
|
29
|
-
};
|
|
30
|
-
export declare const request: <T = Response>(url: RequestInfo | URL, options?: RequestInit, retries?: number) => Promise<T>;
|
package/dist/helpers.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { sleep } from './utils/utils';
|
|
1
|
+
import { request } from './request';
|
|
2
|
+
import { ValidationError } from './utils/errors';
|
|
4
3
|
import { name, version } from './version';
|
|
5
4
|
const ethereumRequest = async (method, params) => {
|
|
6
5
|
// If ethereum.request() exists, the provider is probably EIP-1193 compliant.
|
|
@@ -59,7 +58,7 @@ export const checkPackageUpdates = async (packageName, packageVersion, disableCh
|
|
|
59
58
|
}
|
|
60
59
|
try {
|
|
61
60
|
const pkgName = packageName ?? name;
|
|
62
|
-
const response = await request(`https://registry.npmjs.org/${pkgName}/latest
|
|
61
|
+
const response = await request(`https://registry.npmjs.org/${pkgName}/latest`, { skipTrackingHeaders: true });
|
|
63
62
|
const latestVersion = response.version;
|
|
64
63
|
const currentVersion = packageVersion ?? version;
|
|
65
64
|
if (semverCompare(latestVersion, currentVersion)) {
|
|
@@ -106,50 +105,3 @@ export const convertQuoteToRoute = (step) => {
|
|
|
106
105
|
};
|
|
107
106
|
return route;
|
|
108
107
|
};
|
|
109
|
-
export const requestSettings = {
|
|
110
|
-
retries: 1,
|
|
111
|
-
};
|
|
112
|
-
export const request = async (url, options, retries = requestSettings.retries) => {
|
|
113
|
-
const { userId, integrator, widgetVersion } = ConfigService.getInstance().getConfig();
|
|
114
|
-
try {
|
|
115
|
-
const updatedOptions = {
|
|
116
|
-
...(options ?? {}),
|
|
117
|
-
};
|
|
118
|
-
if (userId) {
|
|
119
|
-
updatedOptions.headers = {
|
|
120
|
-
...options?.headers,
|
|
121
|
-
'X-LIFI-UserId': userId,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
if (widgetVersion) {
|
|
125
|
-
updatedOptions.headers = {
|
|
126
|
-
...options?.headers,
|
|
127
|
-
'X-LIFI-Widget': widgetVersion,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
if (version) {
|
|
131
|
-
updatedOptions.headers = {
|
|
132
|
-
...options?.headers,
|
|
133
|
-
'X-LIFI-SDK': version,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
// integrator is mandatory during SDK initialization
|
|
137
|
-
updatedOptions.headers = {
|
|
138
|
-
...options?.headers,
|
|
139
|
-
'X-LIFI-Integrator': integrator,
|
|
140
|
-
};
|
|
141
|
-
const response = await fetch(url, updatedOptions);
|
|
142
|
-
if (!response.ok) {
|
|
143
|
-
throw new HTTPError(response);
|
|
144
|
-
}
|
|
145
|
-
const data = await response.json();
|
|
146
|
-
return data;
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
if (retries > 0 && error?.status === 500) {
|
|
150
|
-
await sleep(500);
|
|
151
|
-
return request(url, options, retries - 1);
|
|
152
|
-
}
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
@@ -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 {};
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import ConfigService from './services/ConfigService';
|
|
2
|
+
import { HTTPError } from './utils/errors';
|
|
3
|
+
import { sleep } from './utils/utils';
|
|
4
|
+
import { version } from './version';
|
|
5
|
+
export const requestSettings = {
|
|
6
|
+
retries: 1,
|
|
7
|
+
};
|
|
8
|
+
export const request = async (url, options = {
|
|
9
|
+
retries: requestSettings.retries,
|
|
10
|
+
}) => {
|
|
11
|
+
const { userId, integrator, widgetVersion } = ConfigService.getInstance().getConfig();
|
|
12
|
+
options.retries = options.retries ?? requestSettings.retries;
|
|
13
|
+
try {
|
|
14
|
+
if (!options.skipTrackingHeaders) {
|
|
15
|
+
if (userId) {
|
|
16
|
+
options.headers = {
|
|
17
|
+
...options?.headers,
|
|
18
|
+
'X-LIFI-UserId': userId,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (widgetVersion) {
|
|
22
|
+
options.headers = {
|
|
23
|
+
...options?.headers,
|
|
24
|
+
'X-LIFI-Widget': widgetVersion,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (version) {
|
|
28
|
+
options.headers = {
|
|
29
|
+
...options?.headers,
|
|
30
|
+
'X-LIFI-SDK': version,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// integrator is mandatory during SDK initialization
|
|
34
|
+
options.headers = {
|
|
35
|
+
...options?.headers,
|
|
36
|
+
'X-LIFI-Integrator': integrator,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const response = await fetch(url, options);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new HTTPError(response);
|
|
42
|
+
}
|
|
43
|
+
const data = await response.json();
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (options.retries > 0 && error?.status === 500) {
|
|
48
|
+
await sleep(500);
|
|
49
|
+
return request(url, { ...options, retries: options.retries - 1 });
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
1
|
+
import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
2
|
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
@@ -7,10 +7,11 @@ declare const _default: {
|
|
|
7
7
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
8
|
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<Step>;
|
|
9
9
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
|
-
getStatus: (
|
|
11
|
-
getStepTransaction: (step:
|
|
10
|
+
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
12
12
|
getToken: (chain: ChainKey | ChainId, 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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { request } from '../
|
|
1
|
+
import { request } from '../request';
|
|
2
2
|
import { isRoutesRequest, isStep } from '../typeguards';
|
|
3
3
|
import { ValidationError } from '../utils/errors';
|
|
4
4
|
import { parseBackendError } from '../utils/parseError';
|
|
@@ -161,27 +161,14 @@ const getContractCallQuote = async (requestConfig, options) => {
|
|
|
161
161
|
throw await parseBackendError(e);
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
const getStatus = async (
|
|
165
|
-
if (
|
|
166
|
-
throw new ValidationError('Parameter "bridge" is required for cross chain transfers.');
|
|
167
|
-
}
|
|
168
|
-
if (!fromChain) {
|
|
169
|
-
throw new ValidationError('Required parameter "fromChain" is missing.');
|
|
170
|
-
}
|
|
171
|
-
if (!toChain) {
|
|
172
|
-
throw new ValidationError('Required parameter "toChain" is missing.');
|
|
173
|
-
}
|
|
174
|
-
if (!txHash) {
|
|
164
|
+
const getStatus = async (requestConfig, options) => {
|
|
165
|
+
if (!requestConfig.txHash) {
|
|
175
166
|
throw new ValidationError('Required parameter "txHash" is missing.');
|
|
176
167
|
}
|
|
177
168
|
const config = ConfigService.getInstance().getConfig();
|
|
169
|
+
const queryParams = new URLSearchParams(requestConfig);
|
|
178
170
|
try {
|
|
179
|
-
const response = await request(`${config.apiUrl}/status?${
|
|
180
|
-
bridge,
|
|
181
|
-
fromChain,
|
|
182
|
-
toChain,
|
|
183
|
-
txHash,
|
|
184
|
-
})}`, {
|
|
171
|
+
const response = await request(`${config.apiUrl}/status?${queryParams}`, {
|
|
185
172
|
signal: options?.signal,
|
|
186
173
|
});
|
|
187
174
|
return response;
|
|
@@ -294,6 +281,35 @@ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options)
|
|
|
294
281
|
throw await parseBackendError(e);
|
|
295
282
|
}
|
|
296
283
|
};
|
|
284
|
+
const getAvailableConnections = async (connectionRequest) => {
|
|
285
|
+
const config = ConfigService.getInstance().getConfig();
|
|
286
|
+
const url = new URL(`${config.apiUrl}/connections`);
|
|
287
|
+
const { fromChain, fromToken, toChain, toToken, allowBridges } = connectionRequest;
|
|
288
|
+
if (fromChain) {
|
|
289
|
+
url.searchParams.append('fromChain', fromChain);
|
|
290
|
+
}
|
|
291
|
+
if (fromToken) {
|
|
292
|
+
url.searchParams.append('fromToken', fromToken);
|
|
293
|
+
}
|
|
294
|
+
if (toChain) {
|
|
295
|
+
url.searchParams.append('fromToken', toChain);
|
|
296
|
+
}
|
|
297
|
+
if (toToken) {
|
|
298
|
+
url.searchParams.append('fromToken', toToken);
|
|
299
|
+
}
|
|
300
|
+
if (allowBridges?.length) {
|
|
301
|
+
allowBridges.forEach((bridge) => {
|
|
302
|
+
url.searchParams.append('allowBridges', bridge);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const response = await request(url);
|
|
307
|
+
return response;
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
throw await parseBackendError(e);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
297
313
|
export default {
|
|
298
314
|
getChains,
|
|
299
315
|
getContractCallQuote,
|
|
@@ -306,4 +322,5 @@ export default {
|
|
|
306
322
|
getToken,
|
|
307
323
|
getTokens,
|
|
308
324
|
getTools,
|
|
325
|
+
getAvailableConnections,
|
|
309
326
|
};
|
package/dist/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;
|