@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
|
@@ -1,21 +1,20 @@
|
|
|
1
|
+
import { EVMProvider } from '../providers/EVMProvider';
|
|
1
2
|
import ConfigService from '../services/ConfigService';
|
|
2
3
|
import { ValidationError } from '../utils/errors';
|
|
3
4
|
import { StatusManager } from './StatusManager';
|
|
4
|
-
import { StepExecutor } from './StepExecutor';
|
|
5
5
|
import { prepareRestart } from './prepareRestart';
|
|
6
6
|
export class RouteExecutionManager {
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(options) {
|
|
8
8
|
this.executionDictionary = {};
|
|
9
9
|
this.executionPromiseDictionary = {};
|
|
10
10
|
/**
|
|
11
11
|
* Execute a route.
|
|
12
|
-
* @param walletClient - The walletClient required to send the transactions.
|
|
13
12
|
* @param route - The route that should be executed. Cannot be an active route.
|
|
14
13
|
* @param settings - An object containing settings and callbacks.
|
|
15
14
|
* @returns The executed route.
|
|
16
15
|
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
17
16
|
*/
|
|
18
|
-
this.executeRoute = async (
|
|
17
|
+
this.executeRoute = async (route, settings) => {
|
|
19
18
|
// Deep clone to prevent side effects
|
|
20
19
|
const clonedRoute = structuredClone(route);
|
|
21
20
|
let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
|
|
@@ -23,24 +22,23 @@ export class RouteExecutionManager {
|
|
|
23
22
|
if (executionPromise) {
|
|
24
23
|
return executionPromise;
|
|
25
24
|
}
|
|
26
|
-
executionPromise = this.executeSteps(
|
|
25
|
+
executionPromise = this.executeSteps(clonedRoute, settings);
|
|
27
26
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
28
27
|
return executionPromise;
|
|
29
28
|
};
|
|
30
29
|
/**
|
|
31
30
|
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
32
|
-
* @param walletClient - The walletClient required to send the transactions.
|
|
33
31
|
* @param route - The route that is to be executed. Cannot be an active route.
|
|
34
32
|
* @param settings - An object containing settings and callbacks.
|
|
35
33
|
* @returns The executed route.
|
|
36
34
|
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
37
35
|
*/
|
|
38
|
-
this.resumeRoute = async (
|
|
36
|
+
this.resumeRoute = async (route, settings) => {
|
|
39
37
|
// Deep clone to prevent side effects
|
|
40
38
|
const clonedRoute = structuredClone(route);
|
|
41
39
|
const execution = this.executionDictionary[clonedRoute.id];
|
|
42
40
|
if (execution) {
|
|
43
|
-
const executionHalted = execution.executors.some((executor) => executor.
|
|
41
|
+
const executionHalted = execution.executors.some((executor) => !executor.allowExecution);
|
|
44
42
|
if (!executionHalted) {
|
|
45
43
|
// Check if we want to resume route execution in the background
|
|
46
44
|
this.updateRouteExecution(route, {
|
|
@@ -50,12 +48,12 @@ export class RouteExecutionManager {
|
|
|
50
48
|
return executionPromise ?? clonedRoute;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
await prepareRestart(clonedRoute
|
|
54
|
-
const executionPromise = this.executeSteps(
|
|
51
|
+
await prepareRestart(clonedRoute);
|
|
52
|
+
const executionPromise = this.executeSteps(clonedRoute, settings);
|
|
55
53
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
56
54
|
return executionPromise;
|
|
57
55
|
};
|
|
58
|
-
this.executeSteps = async (
|
|
56
|
+
this.executeSteps = async (route, settings) => {
|
|
59
57
|
const config = this.configService.getConfig();
|
|
60
58
|
const execution = {
|
|
61
59
|
route,
|
|
@@ -87,17 +85,21 @@ export class RouteExecutionManager {
|
|
|
87
85
|
step.action.fromAmount = previousStep.execution.toAmount;
|
|
88
86
|
}
|
|
89
87
|
try {
|
|
90
|
-
const
|
|
88
|
+
const provider = this.providers.find((provider) => provider.isProviderStep(step));
|
|
89
|
+
const stepExecutor = await provider.getStepExecutor({
|
|
90
|
+
statusManager,
|
|
91
|
+
settings: execution.settings,
|
|
92
|
+
});
|
|
91
93
|
execution.executors.push(stepExecutor);
|
|
92
94
|
// Check if we want to execute this step in the background
|
|
93
95
|
this.updateRouteExecution(route, execution.settings);
|
|
94
|
-
const executedStep = await stepExecutor.executeStep(
|
|
96
|
+
const executedStep = await stepExecutor.executeStep(step);
|
|
95
97
|
// We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
|
|
96
98
|
if (executedStep.execution?.status !== 'DONE') {
|
|
97
99
|
this.stopExecution(route);
|
|
98
100
|
}
|
|
99
101
|
// Execution stopped during the current step, we don't want to continue to the next step so we return already
|
|
100
|
-
if (stepExecutor.
|
|
102
|
+
if (stepExecutor.allowExecution) {
|
|
101
103
|
return route;
|
|
102
104
|
}
|
|
103
105
|
}
|
|
@@ -163,7 +165,7 @@ export class RouteExecutionManager {
|
|
|
163
165
|
executor.setInteraction({
|
|
164
166
|
allowInteraction: false,
|
|
165
167
|
allowUpdates: false,
|
|
166
|
-
|
|
168
|
+
allowExecution: false,
|
|
167
169
|
});
|
|
168
170
|
}
|
|
169
171
|
delete this.executionDictionary[route.id];
|
|
@@ -187,9 +189,7 @@ export class RouteExecutionManager {
|
|
|
187
189
|
return this.executionDictionary[route.id]?.route;
|
|
188
190
|
};
|
|
189
191
|
this.configService = ConfigService.getInstance();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.configService.updateConfig(configUpdate);
|
|
193
|
-
}
|
|
192
|
+
this.configService.updateConfig(options);
|
|
193
|
+
this.providers = options.providers ?? [new EVMProvider()];
|
|
194
194
|
}
|
|
195
195
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Execution,
|
|
1
|
+
import type { Execution, LiFiStep, Process, ProcessType, Route, Status, Token } from '@lifi/types';
|
|
2
|
+
import type { InternalExecutionSettings } from './types';
|
|
2
3
|
interface Receipt {
|
|
3
4
|
fromAmount?: string;
|
|
4
5
|
toAmount?: string;
|
|
@@ -29,7 +30,7 @@ export declare class StatusManager {
|
|
|
29
30
|
* @param step The current step in execution
|
|
30
31
|
* @returns The initialized execution object for this step and a function to update this step
|
|
31
32
|
*/
|
|
32
|
-
initExecutionObject: (step:
|
|
33
|
+
initExecutionObject: (step: LiFiStep) => Execution;
|
|
33
34
|
/**
|
|
34
35
|
* Updates the execution object of a Step.
|
|
35
36
|
* @param step The current step in execution
|
|
@@ -37,7 +38,7 @@ export declare class StatusManager {
|
|
|
37
38
|
* @param receipt Optional. Information about received tokens
|
|
38
39
|
* @returns The step with the updated execution object
|
|
39
40
|
*/
|
|
40
|
-
updateExecution(step:
|
|
41
|
+
updateExecution(step: LiFiStep, status: Status, receipt?: Receipt): LiFiStep;
|
|
41
42
|
/**
|
|
42
43
|
* Create and push a new process into the execution.
|
|
43
44
|
* @param step The step that should contain the new process.
|
|
@@ -45,7 +46,7 @@ export declare class StatusManager {
|
|
|
45
46
|
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
46
47
|
* @returns Returns process.
|
|
47
48
|
*/
|
|
48
|
-
findOrCreateProcess: (step:
|
|
49
|
+
findOrCreateProcess: (step: LiFiStep, type: ProcessType, status?: Status) => Process;
|
|
49
50
|
/**
|
|
50
51
|
* Update a process object.
|
|
51
52
|
* @param step The step where the process should be updated
|
|
@@ -54,14 +55,14 @@ export declare class StatusManager {
|
|
|
54
55
|
* @param [params] Additional parameters to append to the process.
|
|
55
56
|
* @returns The update process
|
|
56
57
|
*/
|
|
57
|
-
updateProcess: (step:
|
|
58
|
+
updateProcess: (step: LiFiStep, type: ProcessType, status: Status, params?: OptionalParameters) => Process;
|
|
58
59
|
/**
|
|
59
60
|
* Remove a process from the execution
|
|
60
61
|
* @param step The step where the process should be removed from
|
|
61
62
|
* @param type The process type to remove
|
|
62
63
|
*/
|
|
63
|
-
removeProcess: (step:
|
|
64
|
-
updateStepInRoute: (step:
|
|
64
|
+
removeProcess: (step: LiFiStep, type: ProcessType) => void;
|
|
65
|
+
updateStepInRoute: (step: LiFiStep) => LiFiStep;
|
|
65
66
|
allowUpdates(value: boolean): void;
|
|
66
67
|
}
|
|
67
68
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExecutionParams } from '
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
import type { ExecutionParams } from './types';
|
|
3
3
|
export declare class StepExecutionManager {
|
|
4
4
|
allowUserInteraction: boolean;
|
|
5
5
|
allowInteraction: (value: boolean) => void;
|
|
6
|
-
execute: ({ walletClient, step, statusManager, settings, }: ExecutionParams) => Promise<
|
|
6
|
+
execute: ({ walletClient, step, statusManager, settings, }: ExecutionParams) => Promise<LiFiStep>;
|
|
7
7
|
}
|
|
@@ -67,7 +67,7 @@ export class StepExecutionManager {
|
|
|
67
67
|
const updatedWalletClient = await switchChain(walletClient, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
68
68
|
if (!updatedWalletClient) {
|
|
69
69
|
// Chain switch was not successful, stop execution here
|
|
70
|
-
return step
|
|
70
|
+
return step;
|
|
71
71
|
}
|
|
72
72
|
walletClient = updatedWalletClient;
|
|
73
73
|
// Load exiting transaction
|
|
@@ -86,30 +86,7 @@ export class StepExecutionManager {
|
|
|
86
86
|
execution: step.execution,
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
to: step.transactionRequest?.to,
|
|
91
|
-
from: step.transactionRequest?.from,
|
|
92
|
-
data: step.transactionRequest?.data,
|
|
93
|
-
value: step.transactionRequest?.value
|
|
94
|
-
? BigInt(step.transactionRequest.value)
|
|
95
|
-
: undefined,
|
|
96
|
-
maxPriorityFeePerGas: walletClient.account?.type === 'local'
|
|
97
|
-
? await getMaxPriorityFeePerGas(client)
|
|
98
|
-
: undefined,
|
|
99
|
-
// gas: step.transactionRequest?.gasLimit
|
|
100
|
-
// ? BigInt(step.transactionRequest.gasLimit as string)
|
|
101
|
-
// : undefined,
|
|
102
|
-
// gasPrice: step.transactionRequest?.gasPrice
|
|
103
|
-
// ? BigInt(step.transactionRequest.gasPrice as string)
|
|
104
|
-
// : undefined,
|
|
105
|
-
// maxFeePerGas: step.transactionRequest?.maxFeePerGas
|
|
106
|
-
// ? BigInt(step.transactionRequest.maxFeePerGas as string)
|
|
107
|
-
// : undefined,
|
|
108
|
-
// maxPriorityFeePerGas: step.transactionRequest?.maxPriorityFeePerGas
|
|
109
|
-
// ? BigInt(step.transactionRequest.maxPriorityFeePerGas as string)
|
|
110
|
-
// : undefined,
|
|
111
|
-
};
|
|
112
|
-
if (!transactionRequest) {
|
|
89
|
+
if (!step.transactionRequest) {
|
|
113
90
|
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
114
91
|
}
|
|
115
92
|
// STEP 3: Send the transaction
|
|
@@ -117,15 +94,40 @@ export class StepExecutionManager {
|
|
|
117
94
|
const updatedWalletClient = await switchChain(walletClient, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
118
95
|
if (!updatedWalletClient) {
|
|
119
96
|
// Chain switch was not successful, stop execution here
|
|
120
|
-
return step
|
|
97
|
+
return step;
|
|
121
98
|
}
|
|
122
99
|
walletClient = updatedWalletClient;
|
|
123
100
|
process = statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
|
|
124
101
|
if (!this.allowUserInteraction) {
|
|
125
|
-
return step
|
|
102
|
+
return step;
|
|
126
103
|
}
|
|
104
|
+
let transactionRequest = {
|
|
105
|
+
to: step.transactionRequest.to,
|
|
106
|
+
from: step.transactionRequest.from,
|
|
107
|
+
data: step.transactionRequest.data,
|
|
108
|
+
value: step.transactionRequest.value
|
|
109
|
+
? BigInt(step.transactionRequest.value)
|
|
110
|
+
: undefined,
|
|
111
|
+
gas: step.transactionRequest.gasLimit
|
|
112
|
+
? BigInt(step.transactionRequest.gasLimit)
|
|
113
|
+
: undefined,
|
|
114
|
+
// gasPrice: step.transactionRequest.gasPrice
|
|
115
|
+
// ? BigInt(step.transactionRequest.gasPrice as string)
|
|
116
|
+
// : undefined,
|
|
117
|
+
// maxFeePerGas: step.transactionRequest.maxFeePerGas
|
|
118
|
+
// ? BigInt(step.transactionRequest.maxFeePerGas as string)
|
|
119
|
+
// : undefined,
|
|
120
|
+
maxPriorityFeePerGas: walletClient.account?.type === 'local'
|
|
121
|
+
? await getMaxPriorityFeePerGas(client)
|
|
122
|
+
: step.transactionRequest.maxPriorityFeePerGas
|
|
123
|
+
? BigInt(step.transactionRequest.maxPriorityFeePerGas)
|
|
124
|
+
: undefined,
|
|
125
|
+
};
|
|
127
126
|
if (settings.updateTransactionRequestHook) {
|
|
128
|
-
const customizedTransactionRequest = await settings.updateTransactionRequestHook(
|
|
127
|
+
const customizedTransactionRequest = await settings.updateTransactionRequestHook({
|
|
128
|
+
requestType: 'transaction',
|
|
129
|
+
...transactionRequest,
|
|
130
|
+
});
|
|
129
131
|
transactionRequest = {
|
|
130
132
|
...transactionRequest,
|
|
131
133
|
...customizedTransactionRequest,
|
|
@@ -151,6 +153,9 @@ export class StepExecutionManager {
|
|
|
151
153
|
to: transactionRequest.to,
|
|
152
154
|
account: walletClient.account,
|
|
153
155
|
data: transactionRequest.data,
|
|
156
|
+
gas: transactionRequest.gas,
|
|
157
|
+
gasPrice: transactionRequest.gasPrice,
|
|
158
|
+
maxFeePerGas: transactionRequest.maxFeePerGas,
|
|
154
159
|
maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
|
|
155
160
|
chain: null,
|
|
156
161
|
});
|
|
@@ -254,7 +259,7 @@ export class StepExecutionManager {
|
|
|
254
259
|
throw e;
|
|
255
260
|
}
|
|
256
261
|
// DONE
|
|
257
|
-
return step
|
|
262
|
+
return step;
|
|
258
263
|
};
|
|
259
264
|
}
|
|
260
265
|
}
|
|
@@ -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>;
|
|
@@ -21,7 +21,7 @@ export const checkAllowance = async (walletClient, step, statusManager, settings
|
|
|
21
21
|
? maxUint256
|
|
22
22
|
: fromAmount;
|
|
23
23
|
if (shouldBatchTransactions) {
|
|
24
|
-
const approveTxHash = await setAllowance(walletClient, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount, true);
|
|
24
|
+
const approveTxHash = await setAllowance(walletClient, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount, settings, true);
|
|
25
25
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
26
26
|
return approveTxHash;
|
|
27
27
|
}
|
|
@@ -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>;
|
package/dist/execution/index.js
CHANGED
|
@@ -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>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { publicActions } from 'viem';
|
|
2
2
|
import { LiFiErrorCode } from '../utils/errors';
|
|
3
|
-
export const prepareRestart = async (route
|
|
3
|
+
export const prepareRestart = async (route) => {
|
|
4
4
|
for (let index = 0; index < route.steps.length; index++) {
|
|
5
5
|
const step = route.steps[index];
|
|
6
6
|
const stepHasFailed = step.execution?.status === 'FAILED';
|
|
7
7
|
if (stepHasFailed) {
|
|
8
|
-
await handleErrorType(walletClient, step)
|
|
8
|
+
// await handleErrorType(walletClient, step)
|
|
9
9
|
deleteFailedProcesses(step);
|
|
10
10
|
deleteTransactionData(step);
|
|
11
11
|
}
|
|
@@ -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>;
|
|
@@ -9,7 +9,7 @@ import { checkStepSlippageThreshold } from './utils';
|
|
|
9
9
|
* @param newStep
|
|
10
10
|
* @param settings
|
|
11
11
|
* @param allowUserInteraction
|
|
12
|
-
* @returns Return
|
|
12
|
+
* @returns Return LiFiStep
|
|
13
13
|
*/
|
|
14
14
|
export const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
|
|
15
15
|
// 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>;
|
|
@@ -14,6 +14,7 @@ import { LiFiErrorCode, ProviderError } from '../utils/errors';
|
|
|
14
14
|
* @param step
|
|
15
15
|
* @param switchChainHook
|
|
16
16
|
* @param allowUserInteraction
|
|
17
|
+
* @returns New WalletClient
|
|
17
18
|
*/
|
|
18
19
|
export const switchChain = async (walletClient, statusManager, step, switchChainHook, allowUserInteraction) => {
|
|
19
20
|
// 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/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/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/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// expose types and helpers
|
|
2
|
+
export * from '@lifi/types';
|
|
3
|
+
export { LiFi } from './LiFi';
|
|
2
4
|
export * from './execution';
|
|
3
5
|
export * from './helpers';
|
|
4
|
-
export { LiFi } from './LiFi';
|
|
5
6
|
export * from './types';
|
|
6
7
|
export * from './utils/errors';
|
|
8
|
+
export { LiFiError } from './utils/errors';
|
|
@@ -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
|
+
}
|