@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
package/dist/LiFi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
5
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
@@ -93,7 +93,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
93
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
94
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
95
95
|
*/
|
|
96
|
-
getStepTransaction: (step:
|
|
96
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
|
|
97
97
|
/**
|
|
98
98
|
* Get gas recommendation for a certain chain
|
|
99
99
|
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
@@ -155,3 +155,9 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
155
155
|
*/
|
|
156
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get all the available connections for swap/bridging tokens
|
|
160
|
+
* @param connectionRequest ConnectionsRequest
|
|
161
|
+
* @returns ConnectionsResponse
|
|
162
|
+
*/
|
|
163
|
+
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
package/dist/LiFi.js
CHANGED
|
@@ -223,3 +223,12 @@ export class LiFi extends RouteExecutionManager {
|
|
|
223
223
|
checkPackageUpdates(name, version, configUpdate?.disableVersionCheck);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Get all the available connections for swap/bridging tokens
|
|
228
|
+
* @param connectionRequest ConnectionsRequest
|
|
229
|
+
* @returns ConnectionsResponse
|
|
230
|
+
*/
|
|
231
|
+
export const getConnections = async (connectionRequest) => {
|
|
232
|
+
const connections = await ApiService.getAvailableConnections(connectionRequest);
|
|
233
|
+
return connections;
|
|
234
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
2
|
import { StatusManager } from '../execution/StatusManager';
|
|
3
|
-
import { Chain, InternalExecutionSettings,
|
|
4
|
-
export declare const checkAllowance: (signer: Signer, step:
|
|
3
|
+
import { Chain, InternalExecutionSettings, LifiStep } from '../types';
|
|
4
|
+
export declare const checkAllowance: (signer: Signer, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean) => Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export declare const checkBalance: (signer: ethers.Signer, step:
|
|
2
|
+
import { LifiStep } from '..';
|
|
3
|
+
export declare const checkBalance: (signer: ethers.Signer, step: LifiStep, depth?: number) => Promise<void>;
|
package/dist/balance/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './checkBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").
|
|
4
|
+
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
|
|
5
5
|
getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
|
|
6
6
|
getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
|
|
7
7
|
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
package/dist/cjs/LiFi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
5
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
@@ -93,7 +93,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
93
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
94
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
95
95
|
*/
|
|
96
|
-
getStepTransaction: (step:
|
|
96
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
|
|
97
97
|
/**
|
|
98
98
|
* Get gas recommendation for a certain chain
|
|
99
99
|
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
@@ -155,3 +155,9 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
155
155
|
*/
|
|
156
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get all the available connections for swap/bridging tokens
|
|
160
|
+
* @param connectionRequest ConnectionsRequest
|
|
161
|
+
* @returns ConnectionsResponse
|
|
162
|
+
*/
|
|
163
|
+
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
package/dist/cjs/LiFi.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.LiFi = void 0;
|
|
29
|
+
exports.getConnections = exports.LiFi = void 0;
|
|
30
30
|
const allowance_1 = require("./allowance");
|
|
31
31
|
const balance = __importStar(require("./balance"));
|
|
32
32
|
const connectors_1 = require("./connectors");
|
|
@@ -253,3 +253,13 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
exports.LiFi = LiFi;
|
|
256
|
+
/**
|
|
257
|
+
* Get all the available connections for swap/bridging tokens
|
|
258
|
+
* @param connectionRequest ConnectionsRequest
|
|
259
|
+
* @returns ConnectionsResponse
|
|
260
|
+
*/
|
|
261
|
+
const getConnections = async (connectionRequest) => {
|
|
262
|
+
const connections = await ApiService_1.default.getAvailableConnections(connectionRequest);
|
|
263
|
+
return connections;
|
|
264
|
+
};
|
|
265
|
+
exports.getConnections = getConnections;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
2
|
import { StatusManager } from '../execution/StatusManager';
|
|
3
|
-
import { Chain, InternalExecutionSettings,
|
|
4
|
-
export declare const checkAllowance: (signer: Signer, step:
|
|
3
|
+
import { Chain, InternalExecutionSettings, LifiStep } from '../types';
|
|
4
|
+
export declare const checkAllowance: (signer: Signer, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean) => Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export declare const checkBalance: (signer: ethers.Signer, step:
|
|
2
|
+
import { LifiStep } from '..';
|
|
3
|
+
export declare const checkBalance: (signer: ethers.Signer, step: LifiStep, depth?: number) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './checkBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").
|
|
4
|
+
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
|
|
5
5
|
getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
|
|
6
6
|
getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
|
|
7
7
|
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
@@ -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 {};
|
|
@@ -15,7 +15,7 @@ class StatusManager {
|
|
|
15
15
|
this.shouldUpdate = true;
|
|
16
16
|
/**
|
|
17
17
|
* Initializes the execution object of a Step.
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {LifiStep} step The current step in execution
|
|
19
19
|
* @return {Execution} The initialized execution object for this step and a function to update this step
|
|
20
20
|
*/
|
|
21
21
|
this.initExecutionObject = (step) => {
|
|
@@ -35,7 +35,7 @@ class StatusManager {
|
|
|
35
35
|
/**
|
|
36
36
|
* Create and push a new process into the execution.
|
|
37
37
|
* @param {ProcessType} type Type of the process. Used to identify already existing processes.
|
|
38
|
-
* @param {
|
|
38
|
+
* @param {LifiStep} step The step that should contain the new process.
|
|
39
39
|
* @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
40
40
|
* @return {Process}
|
|
41
41
|
*/
|
|
@@ -63,7 +63,7 @@ class StatusManager {
|
|
|
63
63
|
};
|
|
64
64
|
/**
|
|
65
65
|
* Update a process object.
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {LifiStep} step The step where the process should be updated
|
|
67
67
|
* @param {ProcessType} type The process type to update
|
|
68
68
|
* @param {Status} status The status the process gets.
|
|
69
69
|
* @param {object} [params] Additional parameters to append to the process.
|
|
@@ -115,7 +115,7 @@ class StatusManager {
|
|
|
115
115
|
};
|
|
116
116
|
/**
|
|
117
117
|
* Remove a process from the execution
|
|
118
|
-
* @param {
|
|
118
|
+
* @param {LifiStep} step The step where the process should be removed from
|
|
119
119
|
* @param {ProcessType} type The process type to remove
|
|
120
120
|
* @return {void}
|
|
121
121
|
*/
|
|
@@ -146,7 +146,7 @@ class StatusManager {
|
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Updates the execution object of a Step.
|
|
149
|
-
* @param {
|
|
149
|
+
* @param {LifiStep} step The current step in execution
|
|
150
150
|
* @param {Status} status The status for the execution
|
|
151
151
|
* @param {Receipt} receipt Optional. Information about received tokens
|
|
152
152
|
* @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/cjs/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/cjs/helpers.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
3
|
+
exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
|
|
4
|
+
const request_1 = require("./request");
|
|
8
5
|
const errors_1 = require("./utils/errors");
|
|
9
|
-
const utils_1 = require("./utils/utils");
|
|
10
6
|
const version_1 = require("./version");
|
|
11
7
|
const ethereumRequest = async (method, params) => {
|
|
12
8
|
// If ethereum.request() exists, the provider is probably EIP-1193 compliant.
|
|
@@ -69,7 +65,7 @@ const checkPackageUpdates = async (packageName, packageVersion, disableCheck) =>
|
|
|
69
65
|
}
|
|
70
66
|
try {
|
|
71
67
|
const pkgName = packageName ?? version_1.name;
|
|
72
|
-
const response = await (0,
|
|
68
|
+
const response = await (0, request_1.request)(`https://registry.npmjs.org/${pkgName}/latest`, { skipTrackingHeaders: true });
|
|
73
69
|
const latestVersion = response.version;
|
|
74
70
|
const currentVersion = packageVersion ?? version_1.version;
|
|
75
71
|
if (semverCompare(latestVersion, currentVersion)) {
|
|
@@ -118,51 +114,3 @@ const convertQuoteToRoute = (step) => {
|
|
|
118
114
|
return route;
|
|
119
115
|
};
|
|
120
116
|
exports.convertQuoteToRoute = convertQuoteToRoute;
|
|
121
|
-
exports.requestSettings = {
|
|
122
|
-
retries: 1,
|
|
123
|
-
};
|
|
124
|
-
const request = async (url, options, retries = exports.requestSettings.retries) => {
|
|
125
|
-
const { userId, integrator, widgetVersion } = ConfigService_1.default.getInstance().getConfig();
|
|
126
|
-
try {
|
|
127
|
-
const updatedOptions = {
|
|
128
|
-
...(options ?? {}),
|
|
129
|
-
};
|
|
130
|
-
if (userId) {
|
|
131
|
-
updatedOptions.headers = {
|
|
132
|
-
...options?.headers,
|
|
133
|
-
'X-LIFI-UserId': userId,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
if (widgetVersion) {
|
|
137
|
-
updatedOptions.headers = {
|
|
138
|
-
...options?.headers,
|
|
139
|
-
'X-LIFI-Widget': widgetVersion,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
if (version_1.version) {
|
|
143
|
-
updatedOptions.headers = {
|
|
144
|
-
...options?.headers,
|
|
145
|
-
'X-LIFI-SDK': version_1.version,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
// integrator is mandatory during SDK initialization
|
|
149
|
-
updatedOptions.headers = {
|
|
150
|
-
...options?.headers,
|
|
151
|
-
'X-LIFI-Integrator': integrator,
|
|
152
|
-
};
|
|
153
|
-
const response = await fetch(url, updatedOptions);
|
|
154
|
-
if (!response.ok) {
|
|
155
|
-
throw new errors_1.HTTPError(response);
|
|
156
|
-
}
|
|
157
|
-
const data = await response.json();
|
|
158
|
-
return data;
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
if (retries > 0 && error?.status === 500) {
|
|
162
|
-
await (0, utils_1.sleep)(500);
|
|
163
|
-
return (0, exports.request)(url, options, retries - 1);
|
|
164
|
-
}
|
|
165
|
-
throw error;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
exports.request = request;
|
|
@@ -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,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;
|