@lifi/sdk 3.0.0-alpha.4 → 3.0.0-alpha.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 +28 -21
- package/dist/LiFi.js +20 -13
- package/dist/allowance/setAllowance.d.ts +2 -1
- package/dist/allowance/setAllowance.js +23 -7
- package/dist/cjs/LiFi.d.ts +28 -21
- package/dist/cjs/LiFi.js +20 -13
- package/dist/cjs/allowance/setAllowance.d.ts +2 -1
- package/dist/cjs/allowance/setAllowance.js +23 -7
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/execution/BaseStepExecutor.d.ts +12 -0
- package/dist/cjs/execution/BaseStepExecutor.js +27 -0
- package/dist/cjs/execution/EVMStepExecutor.d.ts +13 -0
- package/dist/cjs/execution/EVMStepExecutor.js +292 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +6 -7
- package/dist/cjs/execution/RouteExecutionManager.js +19 -19
- package/dist/cjs/execution/StatusManager.d.ts +8 -7
- package/dist/cjs/execution/StatusManager.js +1 -1
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +34 -29
- package/dist/cjs/execution/checkAllowance.d.ts +3 -2
- package/dist/cjs/execution/checkAllowance.js +1 -1
- package/dist/cjs/execution/checkBalance.d.ts +2 -2
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +1 -0
- package/dist/cjs/execution/multisig.d.ts +2 -2
- package/dist/cjs/execution/prepareRestart.d.ts +2 -3
- package/dist/cjs/execution/prepareRestart.js +2 -2
- package/dist/cjs/execution/stepComparison.d.ts +4 -3
- package/dist/cjs/execution/stepComparison.js +1 -1
- package/dist/cjs/execution/switchChain.d.ts +4 -3
- package/dist/cjs/execution/switchChain.js +1 -0
- package/dist/cjs/{types/internal.types.d.ts → execution/types.d.ts} +36 -96
- package/dist/cjs/execution/utils.d.ts +2 -2
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +2 -2
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/providers/BaseProvider.d.ts +7 -0
- package/dist/cjs/providers/BaseProvider.js +6 -0
- package/dist/cjs/providers/EVMProvider.d.ts +16 -0
- package/dist/cjs/providers/EVMProvider.js +28 -0
- package/dist/cjs/providers/SolanaProvider.d.ts +15 -0
- package/dist/cjs/providers/SolanaProvider.js +32 -0
- package/dist/cjs/providers/types.d.ts +0 -0
- package/dist/cjs/providers/types.js +1 -0
- package/dist/cjs/request.js +11 -5
- package/dist/cjs/services/ApiService.d.ts +4 -5
- package/dist/cjs/services/ApiService.js +2 -2
- package/dist/cjs/services/ConfigService.d.ts +6 -5
- package/dist/cjs/services/ConfigService.js +3 -3
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/index.d.ts +1 -3
- package/dist/cjs/types/index.js +1 -5
- package/dist/cjs/types/internal.d.ts +60 -0
- package/dist/cjs/types/internal.js +2 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +1 -1
- package/dist/execution/BaseStepExecutor.d.ts +12 -0
- package/dist/execution/BaseStepExecutor.js +23 -0
- package/dist/execution/EVMStepExecutor.d.ts +13 -0
- package/dist/execution/EVMStepExecutor.js +285 -0
- package/dist/execution/RouteExecutionManager.d.ts +6 -7
- package/dist/execution/RouteExecutionManager.js +19 -19
- package/dist/execution/StatusManager.d.ts +8 -7
- package/dist/execution/StatusManager.js +1 -1
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +34 -29
- package/dist/execution/checkAllowance.d.ts +3 -2
- package/dist/execution/checkAllowance.js +1 -1
- package/dist/execution/checkBalance.d.ts +2 -2
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.js +1 -0
- package/dist/execution/multisig.d.ts +2 -2
- package/dist/execution/prepareRestart.d.ts +2 -3
- package/dist/execution/prepareRestart.js +2 -2
- package/dist/execution/stepComparison.d.ts +4 -3
- package/dist/execution/stepComparison.js +1 -1
- package/dist/execution/switchChain.d.ts +4 -3
- package/dist/execution/switchChain.js +1 -0
- package/dist/{types/internal.types.d.ts → execution/types.d.ts} +36 -96
- package/dist/execution/utils.d.ts +2 -2
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -3
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/providers/BaseProvider.d.ts +7 -0
- package/dist/providers/BaseProvider.js +2 -0
- package/dist/providers/EVMProvider.d.ts +16 -0
- package/dist/providers/EVMProvider.js +24 -0
- package/dist/providers/SolanaProvider.d.ts +15 -0
- package/dist/providers/SolanaProvider.js +28 -0
- package/dist/providers/types.d.ts +0 -0
- package/dist/providers/types.js +1 -0
- package/dist/request.js +11 -5
- package/dist/services/ApiService.d.ts +4 -5
- package/dist/services/ApiService.js +2 -2
- package/dist/services/ConfigService.d.ts +6 -5
- package/dist/services/ConfigService.js +3 -3
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/index.js +1 -3
- package/dist/types/internal.d.ts +60 -0
- package/dist/types/internal.js +1 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +61 -62
- package/dist/cjs/execution/StepExecutor.d.ts +0 -15
- package/dist/cjs/execution/StepExecutor.js +0 -62
- package/dist/execution/StepExecutor.d.ts +0 -15
- package/dist/execution/StepExecutor.js +0 -58
- /package/dist/cjs/{types/internal.types.js → execution/types.js} +0 -0
- /package/dist/{types/internal.types.js → execution/types.js} +0 -0
|
@@ -73,7 +73,7 @@ class StepExecutionManager {
|
|
|
73
73
|
const updatedWalletClient = await (0, switchChain_1.switchChain)(walletClient, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
74
74
|
if (!updatedWalletClient) {
|
|
75
75
|
// Chain switch was not successful, stop execution here
|
|
76
|
-
return step
|
|
76
|
+
return step;
|
|
77
77
|
}
|
|
78
78
|
walletClient = updatedWalletClient;
|
|
79
79
|
// Load exiting transaction
|
|
@@ -92,30 +92,7 @@ class StepExecutionManager {
|
|
|
92
92
|
execution: step.execution,
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
to: step.transactionRequest?.to,
|
|
97
|
-
from: step.transactionRequest?.from,
|
|
98
|
-
data: step.transactionRequest?.data,
|
|
99
|
-
value: step.transactionRequest?.value
|
|
100
|
-
? BigInt(step.transactionRequest.value)
|
|
101
|
-
: undefined,
|
|
102
|
-
maxPriorityFeePerGas: walletClient.account?.type === 'local'
|
|
103
|
-
? await (0, utils_1.getMaxPriorityFeePerGas)(client)
|
|
104
|
-
: undefined,
|
|
105
|
-
// gas: step.transactionRequest?.gasLimit
|
|
106
|
-
// ? BigInt(step.transactionRequest.gasLimit as string)
|
|
107
|
-
// : undefined,
|
|
108
|
-
// gasPrice: step.transactionRequest?.gasPrice
|
|
109
|
-
// ? BigInt(step.transactionRequest.gasPrice as string)
|
|
110
|
-
// : undefined,
|
|
111
|
-
// maxFeePerGas: step.transactionRequest?.maxFeePerGas
|
|
112
|
-
// ? BigInt(step.transactionRequest.maxFeePerGas as string)
|
|
113
|
-
// : undefined,
|
|
114
|
-
// maxPriorityFeePerGas: step.transactionRequest?.maxPriorityFeePerGas
|
|
115
|
-
// ? BigInt(step.transactionRequest.maxPriorityFeePerGas as string)
|
|
116
|
-
// : undefined,
|
|
117
|
-
};
|
|
118
|
-
if (!transactionRequest) {
|
|
95
|
+
if (!step.transactionRequest) {
|
|
119
96
|
throw new errors_1.TransactionError(errors_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
120
97
|
}
|
|
121
98
|
// STEP 3: Send the transaction
|
|
@@ -123,15 +100,40 @@ class StepExecutionManager {
|
|
|
123
100
|
const updatedWalletClient = await (0, switchChain_1.switchChain)(walletClient, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
124
101
|
if (!updatedWalletClient) {
|
|
125
102
|
// Chain switch was not successful, stop execution here
|
|
126
|
-
return step
|
|
103
|
+
return step;
|
|
127
104
|
}
|
|
128
105
|
walletClient = updatedWalletClient;
|
|
129
106
|
process = statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
|
|
130
107
|
if (!this.allowUserInteraction) {
|
|
131
|
-
return step
|
|
108
|
+
return step;
|
|
132
109
|
}
|
|
110
|
+
let transactionRequest = {
|
|
111
|
+
to: step.transactionRequest.to,
|
|
112
|
+
from: step.transactionRequest.from,
|
|
113
|
+
data: step.transactionRequest.data,
|
|
114
|
+
value: step.transactionRequest.value
|
|
115
|
+
? BigInt(step.transactionRequest.value)
|
|
116
|
+
: undefined,
|
|
117
|
+
gas: step.transactionRequest.gasLimit
|
|
118
|
+
? BigInt(step.transactionRequest.gasLimit)
|
|
119
|
+
: undefined,
|
|
120
|
+
// gasPrice: step.transactionRequest.gasPrice
|
|
121
|
+
// ? BigInt(step.transactionRequest.gasPrice as string)
|
|
122
|
+
// : undefined,
|
|
123
|
+
// maxFeePerGas: step.transactionRequest.maxFeePerGas
|
|
124
|
+
// ? BigInt(step.transactionRequest.maxFeePerGas as string)
|
|
125
|
+
// : undefined,
|
|
126
|
+
maxPriorityFeePerGas: walletClient.account?.type === 'local'
|
|
127
|
+
? await (0, utils_1.getMaxPriorityFeePerGas)(client)
|
|
128
|
+
: step.transactionRequest.maxPriorityFeePerGas
|
|
129
|
+
? BigInt(step.transactionRequest.maxPriorityFeePerGas)
|
|
130
|
+
: undefined,
|
|
131
|
+
};
|
|
133
132
|
if (settings.updateTransactionRequestHook) {
|
|
134
|
-
const customizedTransactionRequest = await settings.updateTransactionRequestHook(
|
|
133
|
+
const customizedTransactionRequest = await settings.updateTransactionRequestHook({
|
|
134
|
+
requestType: 'transaction',
|
|
135
|
+
...transactionRequest,
|
|
136
|
+
});
|
|
135
137
|
transactionRequest = {
|
|
136
138
|
...transactionRequest,
|
|
137
139
|
...customizedTransactionRequest,
|
|
@@ -157,6 +159,9 @@ class StepExecutionManager {
|
|
|
157
159
|
to: transactionRequest.to,
|
|
158
160
|
account: walletClient.account,
|
|
159
161
|
data: transactionRequest.data,
|
|
162
|
+
gas: transactionRequest.gas,
|
|
163
|
+
gasPrice: transactionRequest.gasPrice,
|
|
164
|
+
maxFeePerGas: transactionRequest.maxFeePerGas,
|
|
160
165
|
maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
|
|
161
166
|
chain: null,
|
|
162
167
|
});
|
|
@@ -260,7 +265,7 @@ class StepExecutionManager {
|
|
|
260
265
|
throw e;
|
|
261
266
|
}
|
|
262
267
|
// DONE
|
|
263
|
-
return step
|
|
268
|
+
return step;
|
|
264
269
|
};
|
|
265
270
|
}
|
|
266
271
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { Chain, LiFiStep } from '@lifi/types';
|
|
1
2
|
import type { Hash, WalletClient } from 'viem';
|
|
2
3
|
import type { StatusManager } from '../execution/StatusManager';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const checkAllowance: (walletClient: WalletClient, step:
|
|
4
|
+
import type { InternalExecutionSettings } from './types';
|
|
5
|
+
export declare const checkAllowance: (walletClient: WalletClient, step: LiFiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean, shouldBatchTransactions?: boolean) => Promise<Hash | void>;
|
|
@@ -24,7 +24,7 @@ const checkAllowance = async (walletClient, step, statusManager, settings, chain
|
|
|
24
24
|
? viem_1.maxUint256
|
|
25
25
|
: fromAmount;
|
|
26
26
|
if (shouldBatchTransactions) {
|
|
27
|
-
const approveTxHash = await (0, allowance_1.setAllowance)(walletClient, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount, true);
|
|
27
|
+
const approveTxHash = await (0, allowance_1.setAllowance)(walletClient, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount, settings, true);
|
|
28
28
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
29
29
|
return approveTxHash;
|
|
30
30
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const checkBalance: (walletAddress: string, step:
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
export declare const checkBalance: (walletAddress: string, step: LiFiStep, depth?: number) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtendedChain,
|
|
1
|
+
import type { ExtendedChain, LiFiStep, ProcessType } from '@lifi/types';
|
|
2
2
|
import type { Hash } from 'viem';
|
|
3
3
|
import type { StatusManager } from './StatusManager';
|
|
4
|
-
export declare const updateMultisigRouteProcess: (internalTxHash: Hash, step:
|
|
4
|
+
export declare const updateMultisigRouteProcess: (internalTxHash: Hash, step: LiFiStep, statusManager: StatusManager, processType: ProcessType, fromChain: ExtendedChain) => Promise<void>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const prepareRestart: (route: Route, walletClient: WalletClient) => Promise<void>;
|
|
1
|
+
import type { Route } from '@lifi/types';
|
|
2
|
+
export declare const prepareRestart: (route: Route) => Promise<void>;
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prepareRestart = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const errors_1 = require("../utils/errors");
|
|
6
|
-
const prepareRestart = async (route
|
|
6
|
+
const prepareRestart = async (route) => {
|
|
7
7
|
for (let index = 0; index < route.steps.length; index++) {
|
|
8
8
|
const step = route.steps[index];
|
|
9
9
|
const stepHasFailed = step.execution?.status === 'FAILED';
|
|
10
10
|
if (stepHasFailed) {
|
|
11
|
-
await handleErrorType(walletClient, step)
|
|
11
|
+
// await handleErrorType(walletClient, step)
|
|
12
12
|
deleteFailedProcesses(step);
|
|
13
13
|
deleteTransactionData(step);
|
|
14
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
2
|
import type { StatusManager } from './StatusManager';
|
|
3
|
+
import type { InternalExecutionSettings } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
5
6
|
* If yes it returns the updated Step.
|
|
@@ -9,6 +10,6 @@ import type { StatusManager } from './StatusManager';
|
|
|
9
10
|
* @param newStep
|
|
10
11
|
* @param settings
|
|
11
12
|
* @param allowUserInteraction
|
|
12
|
-
* @returns Return
|
|
13
|
+
* @returns Return LiFiStep
|
|
13
14
|
*/
|
|
14
|
-
export declare const stepComparison: (statusManager: StatusManager, oldStep:
|
|
15
|
+
export declare const stepComparison: (statusManager: StatusManager, oldStep: LiFiStep, newStep: LiFiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LiFiStep>;
|
|
@@ -12,7 +12,7 @@ const utils_1 = require("./utils");
|
|
|
12
12
|
* @param newStep
|
|
13
13
|
* @param settings
|
|
14
14
|
* @param allowUserInteraction
|
|
15
|
-
* @returns Return
|
|
15
|
+
* @returns Return LiFiStep
|
|
16
16
|
*/
|
|
17
17
|
const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
|
|
18
18
|
// Check if changed exchange rate is in the range of slippage threshold
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
2
|
import type { WalletClient } from 'viem';
|
|
3
|
-
import type { SwitchChainHook } from '../types';
|
|
4
3
|
import type { StatusManager } from './StatusManager';
|
|
4
|
+
import type { SwitchChainHook } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* This method checks whether the wallet client is configured for the correct chain.
|
|
7
7
|
* If yes it returns the wallet clien.
|
|
@@ -17,5 +17,6 @@ import type { StatusManager } from './StatusManager';
|
|
|
17
17
|
* @param step
|
|
18
18
|
* @param switchChainHook
|
|
19
19
|
* @param allowUserInteraction
|
|
20
|
+
* @returns New WalletClient
|
|
20
21
|
*/
|
|
21
|
-
export declare const switchChain: (walletClient: WalletClient, statusManager: StatusManager, step:
|
|
22
|
+
export declare const switchChain: (walletClient: WalletClient, statusManager: StatusManager, step: LiFiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<WalletClient | undefined>;
|
|
@@ -17,6 +17,7 @@ const errors_1 = require("../utils/errors");
|
|
|
17
17
|
* @param step
|
|
18
18
|
* @param switchChainHook
|
|
19
19
|
* @param allowUserInteraction
|
|
20
|
+
* @returns New WalletClient
|
|
20
21
|
*/
|
|
21
22
|
const switchChain = async (walletClient, statusManager, step, switchChainHook, allowUserInteraction) => {
|
|
22
23
|
// if we are already on the correct chain we can proceed directly
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, Route, Token } from '@lifi/types';
|
|
2
2
|
import type { Hash, Hex, WalletClient } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { BaseStepExecutor } from './BaseStepExecutor';
|
|
4
|
+
import type { StatusManager } from './StatusManager';
|
|
5
|
+
export interface StepExecutorOptions {
|
|
6
|
+
statusManager: StatusManager;
|
|
7
|
+
settings: InternalExecutionSettings;
|
|
8
|
+
}
|
|
9
|
+
export interface RouteExecutionData {
|
|
10
|
+
route: Route;
|
|
11
|
+
executors: BaseStepExecutor[];
|
|
12
|
+
settings: InternalExecutionSettings;
|
|
13
|
+
}
|
|
14
|
+
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
15
|
+
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
5
16
|
export type TransactionParameters = {
|
|
6
17
|
chainId?: number;
|
|
7
18
|
to?: string;
|
|
@@ -14,56 +25,11 @@ export type TransactionParameters = {
|
|
|
14
25
|
maxFeePerGas?: bigint;
|
|
15
26
|
maxPriorityFeePerGas?: bigint;
|
|
16
27
|
};
|
|
17
|
-
export interface ExecutionParams {
|
|
18
|
-
walletClient: WalletClient;
|
|
19
|
-
step: LifiStep;
|
|
20
|
-
statusManager: StatusManager;
|
|
21
|
-
settings: InternalExecutionSettings;
|
|
22
|
-
}
|
|
23
28
|
export type UpdateRouteHook = (updatedRoute: Route) => void;
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
apiUrl: string;
|
|
27
|
-
rpcs: Record<ChainId, string[]>;
|
|
28
|
-
multicallAddresses: Record<ChainId, string | undefined>;
|
|
29
|
-
defaultExecutionSettings: InternalExecutionSettings;
|
|
30
|
-
defaultRouteOptions: RouteOptions;
|
|
31
|
-
disableVersionCheck?: boolean;
|
|
32
|
-
userId?: string;
|
|
33
|
-
integrator: string;
|
|
34
|
-
widgetVersion?: string;
|
|
35
|
-
multisig?: MultisigConfig;
|
|
36
|
-
};
|
|
37
|
-
export interface MultisigTxDetails {
|
|
38
|
-
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
39
|
-
txHash?: Hash;
|
|
40
|
-
}
|
|
41
|
-
export interface MultisigTransactionResponse {
|
|
42
|
-
hash: string;
|
|
43
|
-
}
|
|
44
|
-
export interface BaseTransaction {
|
|
45
|
-
to: string;
|
|
46
|
-
value?: bigint;
|
|
47
|
-
data: string;
|
|
48
|
-
}
|
|
49
|
-
export interface MultisigConfig {
|
|
50
|
-
isMultisigWalletClient: boolean;
|
|
51
|
-
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
52
|
-
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
53
|
-
shouldBatchTransactions?: boolean;
|
|
29
|
+
export interface TransactionRequestParameters extends TransactionParameters {
|
|
30
|
+
requestType: 'approve' | 'transaction';
|
|
54
31
|
}
|
|
55
|
-
export type
|
|
56
|
-
apiUrl?: string;
|
|
57
|
-
rpcs?: Record<number, string[]>;
|
|
58
|
-
multicallAddresses?: Record<number, string | undefined>;
|
|
59
|
-
defaultExecutionSettings?: ExecutionSettings;
|
|
60
|
-
defaultRouteOptions?: RouteOptions;
|
|
61
|
-
disableVersionCheck?: boolean;
|
|
62
|
-
userId?: string;
|
|
63
|
-
integrator: string;
|
|
64
|
-
widgetVersion?: string;
|
|
65
|
-
multisigConfig?: MultisigConfig;
|
|
66
|
-
};
|
|
32
|
+
export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequestParameters) => Promise<TransactionParameters>;
|
|
67
33
|
export type SwitchChainHook = (requiredChainId: number) => Promise<WalletClient | undefined>;
|
|
68
34
|
export interface AcceptSlippageUpdateHookParams {
|
|
69
35
|
toToken: Token;
|
|
@@ -79,11 +45,6 @@ export interface ExchangeRateUpdateParams {
|
|
|
79
45
|
newToAmount: string;
|
|
80
46
|
}
|
|
81
47
|
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>;
|
|
82
|
-
export interface RouteExecutionData {
|
|
83
|
-
route: Route;
|
|
84
|
-
executors: StepExecutor[];
|
|
85
|
-
settings: InternalExecutionSettings;
|
|
86
|
-
}
|
|
87
48
|
export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
88
49
|
export interface InternalExecutionSettings {
|
|
89
50
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
@@ -93,50 +54,29 @@ export interface InternalExecutionSettings {
|
|
|
93
54
|
executeInBackground: boolean;
|
|
94
55
|
infiniteApproval: boolean;
|
|
95
56
|
}
|
|
96
|
-
export
|
|
97
|
-
|
|
57
|
+
export interface ExecutionParams {
|
|
58
|
+
walletClient: WalletClient;
|
|
59
|
+
step: LiFiStep;
|
|
60
|
+
statusManager: StatusManager;
|
|
61
|
+
settings: InternalExecutionSettings;
|
|
62
|
+
}
|
|
98
63
|
export interface InteractionSettings {
|
|
99
64
|
allowInteraction?: boolean;
|
|
100
65
|
allowUpdates?: boolean;
|
|
101
|
-
|
|
66
|
+
allowExecution?: boolean;
|
|
102
67
|
}
|
|
103
|
-
export interface
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
gas: number;
|
|
109
|
-
gas_price: number;
|
|
110
|
-
gas_fee_cap: number;
|
|
111
|
-
gas_tip_cap: number;
|
|
112
|
-
cumulative_gas_used: number;
|
|
113
|
-
gas_used: number;
|
|
114
|
-
effective_gas_price: number;
|
|
115
|
-
input: string;
|
|
116
|
-
nonce: number;
|
|
68
|
+
export interface MultisigTxDetails {
|
|
69
|
+
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
70
|
+
txHash?: Hash;
|
|
71
|
+
}
|
|
72
|
+
export interface BaseTransaction {
|
|
117
73
|
to: string;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
access_list: any;
|
|
121
|
-
status: boolean;
|
|
122
|
-
addresses: string[];
|
|
123
|
-
contract_ids: string[];
|
|
124
|
-
network_id: string;
|
|
125
|
-
timestamp: string;
|
|
126
|
-
function_selector: string;
|
|
127
|
-
l1_block_number: number;
|
|
128
|
-
l1_timestamp: number;
|
|
129
|
-
deposit_tx: boolean;
|
|
130
|
-
system_tx: boolean;
|
|
131
|
-
mint: number;
|
|
132
|
-
sig: Signature;
|
|
133
|
-
error_message: string;
|
|
134
|
-
method: string;
|
|
135
|
-
decoded_input: any;
|
|
136
|
-
call_trace: any;
|
|
74
|
+
value?: bigint;
|
|
75
|
+
data: string;
|
|
137
76
|
}
|
|
138
|
-
export interface
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
77
|
+
export interface MultisigConfig {
|
|
78
|
+
isMultisigWalletClient: boolean;
|
|
79
|
+
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
80
|
+
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
81
|
+
shouldBatchTransactions?: boolean;
|
|
142
82
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, ProcessType, Status, StatusMessage, Substatus } from '@lifi/types';
|
|
2
2
|
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
3
3
|
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
4
4
|
/**
|
|
@@ -9,4 +9,4 @@ export declare function getSubstatusMessage(status: StatusMessage, substatus?: S
|
|
|
9
9
|
* @param newStep
|
|
10
10
|
* @returns Boolean
|
|
11
11
|
*/
|
|
12
|
-
export declare function checkStepSlippageThreshold(oldStep:
|
|
12
|
+
export declare function checkStepSlippageThreshold(oldStep: LiFiStep, newStep: LiFiStep): boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { StatusManager } from '
|
|
3
|
-
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step:
|
|
1
|
+
import type { LiFiStep, ProcessType, StatusResponse } from '@lifi/types';
|
|
2
|
+
import type { StatusManager } from './StatusManager';
|
|
3
|
+
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LiFiStep): Promise<StatusResponse>;
|
package/dist/cjs/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, Route } from '@lifi/types';
|
|
2
2
|
import type { TenderlyResponse } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Returns a random number between min (inclusive) and max (inclusive)
|
|
@@ -14,5 +14,5 @@ export declare const checkPackageUpdates: (packageName?: string, packageVersion?
|
|
|
14
14
|
* @returns - The route to be executed.
|
|
15
15
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
16
16
|
*/
|
|
17
|
-
export declare const convertQuoteToRoute: (step:
|
|
17
|
+
export declare const convertQuoteToRoute: (step: LiFiStep) => Route;
|
|
18
18
|
export declare const fetchTxErrorDetails: (txHash: string, chainId: number) => Promise<TenderlyResponse>;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export * from '@lifi/types';
|
|
2
|
+
export { LiFi } from './LiFi';
|
|
1
3
|
export * from './execution';
|
|
2
4
|
export * from './helpers';
|
|
3
|
-
export { LiFi } from './LiFi';
|
|
4
5
|
export * from './types';
|
|
5
6
|
export * from './utils/errors';
|
|
7
|
+
export { ErrorCode, LiFiError } from './utils/errors';
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,11 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.LiFi = void 0;
|
|
17
|
+
exports.LiFiError = exports.LiFi = void 0;
|
|
18
18
|
// expose types and helpers
|
|
19
|
-
__exportStar(require("
|
|
20
|
-
__exportStar(require("./helpers"), exports);
|
|
19
|
+
__exportStar(require("@lifi/types"), exports);
|
|
21
20
|
var LiFi_1 = require("./LiFi");
|
|
22
21
|
Object.defineProperty(exports, "LiFi", { enumerable: true, get: function () { return LiFi_1.LiFi; } });
|
|
22
|
+
__exportStar(require("./execution"), exports);
|
|
23
|
+
__exportStar(require("./helpers"), exports);
|
|
23
24
|
__exportStar(require("./types"), exports);
|
|
24
25
|
__exportStar(require("./utils/errors"), exports);
|
|
26
|
+
var errors_1 = require("./utils/errors");
|
|
27
|
+
Object.defineProperty(exports, "LiFiError", { enumerable: true, get: function () { return errors_1.LiFiError; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
import type { BaseStepExecutor } from '../execution/BaseStepExecutor';
|
|
3
|
+
import type { StepExecutorOptions } from '../execution/types';
|
|
4
|
+
export declare abstract class BaseProvider {
|
|
5
|
+
abstract isProviderStep(step: LiFiStep): boolean;
|
|
6
|
+
abstract getStepExecutor(options: StepExecutorOptions): Promise<BaseStepExecutor>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
import { type WalletClient } from 'viem';
|
|
3
|
+
import type { BaseStepExecutor } from '../execution/BaseStepExecutor';
|
|
4
|
+
import type { StepExecutorOptions } from '../execution/types';
|
|
5
|
+
import { BaseProvider } from './BaseProvider';
|
|
6
|
+
export type GetEVMWalletClient = () => Promise<WalletClient>;
|
|
7
|
+
export interface EVMProviderOptions {
|
|
8
|
+
getWalletClient: GetEVMWalletClient;
|
|
9
|
+
}
|
|
10
|
+
export declare class EVMProvider extends BaseProvider {
|
|
11
|
+
getWalletClient?: GetEVMWalletClient;
|
|
12
|
+
constructor(options?: EVMProviderOptions);
|
|
13
|
+
isProviderStep(step: LiFiStep): boolean;
|
|
14
|
+
getStepExecutor(options: StepExecutorOptions): Promise<BaseStepExecutor>;
|
|
15
|
+
setOptions(options: EVMProviderOptions): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVMProvider = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const EVMStepExecutor_1 = require("../execution/EVMStepExecutor");
|
|
6
|
+
const BaseProvider_1 = require("./BaseProvider");
|
|
7
|
+
class EVMProvider extends BaseProvider_1.BaseProvider {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
10
|
+
this.getWalletClient = options?.getWalletClient;
|
|
11
|
+
}
|
|
12
|
+
isProviderStep(step) {
|
|
13
|
+
const isProviderStep = (0, viem_1.isAddress)(step.action.fromAddress);
|
|
14
|
+
return isProviderStep;
|
|
15
|
+
}
|
|
16
|
+
async getStepExecutor(options) {
|
|
17
|
+
if (!this.getWalletClient) {
|
|
18
|
+
throw new Error(`getWalletClient is not provided.`);
|
|
19
|
+
}
|
|
20
|
+
const walletClient = await this.getWalletClient();
|
|
21
|
+
const executor = new EVMStepExecutor_1.EVMStepExecutor({ walletClient, ...options });
|
|
22
|
+
return executor;
|
|
23
|
+
}
|
|
24
|
+
setOptions(options) {
|
|
25
|
+
this.getWalletClient = options.getWalletClient;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.EVMProvider = EVMProvider;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
import type { BaseStepExecutor } from '../execution/BaseStepExecutor';
|
|
3
|
+
import type { StepExecutorOptions } from '../execution/types';
|
|
4
|
+
import { BaseProvider } from './BaseProvider';
|
|
5
|
+
export type GetSolanaWalletClient = () => Promise<unknown>;
|
|
6
|
+
export interface SolanaProviderOptions {
|
|
7
|
+
getWalletClient: GetSolanaWalletClient;
|
|
8
|
+
}
|
|
9
|
+
export declare class SolanaProvider extends BaseProvider {
|
|
10
|
+
getWalletClient?: GetSolanaWalletClient;
|
|
11
|
+
constructor(options?: SolanaProviderOptions);
|
|
12
|
+
isProviderStep(step: LiFiStep): boolean;
|
|
13
|
+
getStepExecutor(options: StepExecutorOptions): Promise<BaseStepExecutor>;
|
|
14
|
+
setOptions(options: SolanaProviderOptions): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaProvider = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const BaseProvider_1 = require("./BaseProvider");
|
|
6
|
+
class SolanaProvider extends BaseProvider_1.BaseProvider {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super();
|
|
9
|
+
this.getWalletClient = options?.getWalletClient;
|
|
10
|
+
}
|
|
11
|
+
isProviderStep(step) {
|
|
12
|
+
try {
|
|
13
|
+
const publickKey = new web3_js_1.PublicKey(step.action.fromAddress);
|
|
14
|
+
const isProviderStep = web3_js_1.PublicKey.isOnCurve(publickKey);
|
|
15
|
+
return isProviderStep;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async getStepExecutor(options) {
|
|
22
|
+
if (!this.getWalletClient) {
|
|
23
|
+
throw new Error(`getWalletClient is not provided.`);
|
|
24
|
+
}
|
|
25
|
+
const walletClient = await this.getWalletClient();
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
setOptions(options) {
|
|
29
|
+
this.getWalletClient = options.getWalletClient;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.SolanaProvider = SolanaProvider;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/cjs/request.js
CHANGED
|
@@ -14,32 +14,38 @@ exports.requestSettings = {
|
|
|
14
14
|
const request = async (url, options = {
|
|
15
15
|
retries: exports.requestSettings.retries,
|
|
16
16
|
}) => {
|
|
17
|
-
const { userId, integrator, widgetVersion } = ConfigService_1.default.getInstance().getConfig();
|
|
17
|
+
const { userId, integrator, widgetVersion, apiKey } = ConfigService_1.default.getInstance().getConfig();
|
|
18
18
|
options.retries = options.retries ?? exports.requestSettings.retries;
|
|
19
19
|
try {
|
|
20
20
|
if (!options.skipTrackingHeaders) {
|
|
21
|
+
if (apiKey) {
|
|
22
|
+
options.headers = {
|
|
23
|
+
...options?.headers,
|
|
24
|
+
'x-lifi-api-key': apiKey,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
21
27
|
if (userId) {
|
|
22
28
|
options.headers = {
|
|
23
29
|
...options?.headers,
|
|
24
|
-
'
|
|
30
|
+
'x-lifi-userid': userId,
|
|
25
31
|
};
|
|
26
32
|
}
|
|
27
33
|
if (widgetVersion) {
|
|
28
34
|
options.headers = {
|
|
29
35
|
...options?.headers,
|
|
30
|
-
'
|
|
36
|
+
'x-lifi-widget': widgetVersion,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
if (version_1.version) {
|
|
34
40
|
options.headers = {
|
|
35
41
|
...options?.headers,
|
|
36
|
-
'
|
|
42
|
+
'x-lifi-sdk': version_1.version,
|
|
37
43
|
};
|
|
38
44
|
}
|
|
39
45
|
// integrator is mandatory during SDK initialization
|
|
40
46
|
options.headers = {
|
|
41
47
|
...options?.headers,
|
|
42
|
-
'
|
|
48
|
+
'x-lifi-integrator': integrator,
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
const response = await fetch(url, options);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest,
|
|
2
|
-
import type { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
1
|
+
import type { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LiFiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
2
|
declare const _default: {
|
|
4
3
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
4
|
+
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
6
5
|
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
6
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
7
|
+
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
9
8
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
9
|
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
|
-
getStepTransaction: (step:
|
|
10
|
+
getStepTransaction: (step: LiFiStep, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
12
11
|
getToken: (chain: ChainId | ChainKey, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
13
12
|
getTokens: (requestConfig?: TokensRequest | undefined, options?: RequestOptions | undefined) => Promise<TokensResponse>;
|
|
14
13
|
getTools: (requestConfig?: ToolsRequest | undefined, options?: RequestOptions | undefined) => Promise<ToolsResponse>;
|