@lifi/sdk 3.0.0-alpha.6 → 3.0.0-alpha.8

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.
Files changed (121) hide show
  1. package/dist/LiFi.d.ts +21 -18
  2. package/dist/LiFi.js +16 -13
  3. package/dist/allowance/setAllowance.d.ts +1 -1
  4. package/dist/cjs/LiFi.d.ts +21 -18
  5. package/dist/cjs/LiFi.js +17 -14
  6. package/dist/cjs/allowance/setAllowance.d.ts +1 -1
  7. package/dist/cjs/connectors.d.ts +1 -1
  8. package/dist/cjs/connectors.js +3 -6
  9. package/dist/cjs/execution/BaseStepExecutor.d.ts +12 -0
  10. package/dist/cjs/execution/BaseStepExecutor.js +27 -0
  11. package/dist/cjs/execution/EVMStepExecutor.d.ts +13 -0
  12. package/dist/cjs/execution/EVMStepExecutor.js +292 -0
  13. package/dist/cjs/execution/RouteExecutionManager.d.ts +9 -8
  14. package/dist/cjs/execution/RouteExecutionManager.js +26 -24
  15. package/dist/cjs/execution/StatusManager.d.ts +8 -7
  16. package/dist/cjs/execution/StatusManager.js +1 -1
  17. package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
  18. package/dist/cjs/execution/StepExecutionManager.js +8 -8
  19. package/dist/cjs/execution/checkAllowance.d.ts +3 -2
  20. package/dist/cjs/execution/checkBalance.d.ts +2 -2
  21. package/dist/cjs/execution/index.d.ts +1 -0
  22. package/dist/cjs/execution/index.js +1 -0
  23. package/dist/cjs/execution/multisig.d.ts +2 -2
  24. package/dist/cjs/execution/multisig.js +2 -5
  25. package/dist/cjs/execution/prepareRestart.d.ts +2 -3
  26. package/dist/cjs/execution/prepareRestart.js +2 -2
  27. package/dist/cjs/execution/stepComparison.d.ts +4 -3
  28. package/dist/cjs/execution/stepComparison.js +1 -1
  29. package/dist/cjs/execution/switchChain.d.ts +4 -3
  30. package/dist/cjs/execution/switchChain.js +1 -0
  31. package/dist/cjs/{types/internal.types.d.ts → execution/types.d.ts} +33 -96
  32. package/dist/cjs/execution/utils.d.ts +2 -2
  33. package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -3
  34. package/dist/cjs/helpers.d.ts +2 -2
  35. package/dist/cjs/index.d.ts +5 -1
  36. package/dist/cjs/index.js +10 -4
  37. package/dist/cjs/providers/EVM.d.ts +10 -0
  38. package/dist/cjs/providers/EVM.js +34 -0
  39. package/dist/cjs/providers/Solana.d.ts +9 -0
  40. package/dist/cjs/providers/Solana.js +38 -0
  41. package/dist/cjs/providers/index.d.ts +1 -0
  42. package/dist/cjs/providers/index.js +17 -0
  43. package/dist/cjs/providers/types.d.ts +12 -0
  44. package/dist/cjs/providers/types.js +8 -0
  45. package/dist/cjs/request.js +12 -9
  46. package/dist/cjs/services/ApiService.d.ts +4 -5
  47. package/dist/cjs/services/ApiService.js +15 -18
  48. package/dist/cjs/services/ChainsService.d.ts +1 -1
  49. package/dist/cjs/services/ChainsService.js +2 -1
  50. package/dist/cjs/services/ConfigService.d.ts +9 -6
  51. package/dist/cjs/services/ConfigService.js +7 -4
  52. package/dist/cjs/typeguards.d.ts +2 -2
  53. package/dist/cjs/types/index.d.ts +1 -3
  54. package/dist/cjs/types/index.js +1 -5
  55. package/dist/cjs/types/internal.d.ts +60 -0
  56. package/dist/cjs/types/internal.js +2 -0
  57. package/dist/cjs/utils/parseError.d.ts +4 -4
  58. package/dist/cjs/utils/parseError.js +3 -6
  59. package/dist/cjs/version.d.ts +1 -1
  60. package/dist/cjs/version.js +1 -1
  61. package/dist/connectors.d.ts +1 -1
  62. package/dist/connectors.js +1 -1
  63. package/dist/execution/BaseStepExecutor.d.ts +12 -0
  64. package/dist/execution/BaseStepExecutor.js +23 -0
  65. package/dist/execution/EVMStepExecutor.d.ts +13 -0
  66. package/dist/execution/EVMStepExecutor.js +285 -0
  67. package/dist/execution/RouteExecutionManager.d.ts +9 -8
  68. package/dist/execution/RouteExecutionManager.js +25 -20
  69. package/dist/execution/StatusManager.d.ts +8 -7
  70. package/dist/execution/StatusManager.js +1 -1
  71. package/dist/execution/StepExecutionManager.d.ts +3 -3
  72. package/dist/execution/StepExecutionManager.js +6 -6
  73. package/dist/execution/checkAllowance.d.ts +3 -2
  74. package/dist/execution/checkBalance.d.ts +2 -2
  75. package/dist/execution/index.d.ts +1 -0
  76. package/dist/execution/index.js +1 -0
  77. package/dist/execution/multisig.d.ts +2 -2
  78. package/dist/execution/multisig.js +1 -1
  79. package/dist/execution/prepareRestart.d.ts +2 -3
  80. package/dist/execution/prepareRestart.js +2 -2
  81. package/dist/execution/stepComparison.d.ts +4 -3
  82. package/dist/execution/stepComparison.js +1 -1
  83. package/dist/execution/switchChain.d.ts +4 -3
  84. package/dist/execution/switchChain.js +1 -0
  85. package/dist/{types/internal.types.d.ts → execution/types.d.ts} +33 -96
  86. package/dist/execution/utils.d.ts +2 -2
  87. package/dist/execution/waitForReceivingTransaction.d.ts +3 -3
  88. package/dist/helpers.d.ts +2 -2
  89. package/dist/index.d.ts +5 -1
  90. package/dist/index.js +5 -2
  91. package/dist/providers/EVM.d.ts +10 -0
  92. package/dist/providers/EVM.js +29 -0
  93. package/dist/providers/Solana.d.ts +9 -0
  94. package/dist/providers/Solana.js +33 -0
  95. package/dist/providers/index.d.ts +1 -0
  96. package/dist/providers/index.js +1 -0
  97. package/dist/providers/types.d.ts +12 -0
  98. package/dist/providers/types.js +5 -0
  99. package/dist/request.js +12 -6
  100. package/dist/services/ApiService.d.ts +4 -5
  101. package/dist/services/ApiService.js +3 -3
  102. package/dist/services/ChainsService.d.ts +1 -1
  103. package/dist/services/ChainsService.js +1 -1
  104. package/dist/services/ConfigService.d.ts +9 -6
  105. package/dist/services/ConfigService.js +6 -5
  106. package/dist/typeguards.d.ts +2 -2
  107. package/dist/types/index.d.ts +1 -3
  108. package/dist/types/index.js +1 -3
  109. package/dist/types/internal.d.ts +60 -0
  110. package/dist/types/internal.js +1 -0
  111. package/dist/utils/parseError.d.ts +4 -4
  112. package/dist/utils/parseError.js +1 -1
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/package.json +6 -5
  116. package/dist/cjs/execution/StepExecutor.d.ts +0 -15
  117. package/dist/cjs/execution/StepExecutor.js +0 -62
  118. package/dist/execution/StepExecutor.d.ts +0 -15
  119. package/dist/execution/StepExecutor.js +0 -58
  120. /package/dist/cjs/{types/internal.types.js → execution/types.js} +0 -0
  121. /package/dist/{types/internal.types.js → execution/types.js} +0 -0
@@ -0,0 +1,285 @@
1
+ import { publicActions } from 'viem';
2
+ import ApiService from '../services/ApiService';
3
+ import { ChainsService } from '../services/ChainsService';
4
+ import { ConfigService } from '../services/ConfigService';
5
+ import { getMaxPriorityFeePerGas } from '../utils';
6
+ import { LiFiErrorCode, TransactionError, ValidationError, } from '../utils/errors';
7
+ import { getTransactionFailedMessage, parseError } from '../utils/parseError';
8
+ import { isZeroAddress } from '../utils/utils';
9
+ import { BaseStepExecutor } from './BaseStepExecutor';
10
+ import { checkAllowance } from './checkAllowance';
11
+ import { checkBalance } from './checkBalance';
12
+ import { updateMultisigRouteProcess } from './multisig';
13
+ import { stepComparison } from './stepComparison';
14
+ import { switchChain } from './switchChain';
15
+ import { getSubstatusMessage } from './utils';
16
+ import { waitForReceivingTransaction } from './waitForReceivingTransaction';
17
+ export class EVMStepExecutor extends BaseStepExecutor {
18
+ constructor(options) {
19
+ super(options);
20
+ // TODO: add checkChain method and update wallet client inside executors
21
+ // This can come in handy when we execute multiple routes simultaneously and
22
+ // should be sure that we are on the right chain when waiting for transactions.
23
+ this.checkChain = () => {
24
+ throw new Error('checkChain is not implemented.');
25
+ };
26
+ this.executeStep = async (step) => {
27
+ // Make sure that the chain is still correct
28
+ // Find if it's bridging and the step is waiting for a transaction on the receiving chain
29
+ const recievingChainProcess = step.execution?.process.find((process) => process.type === 'RECEIVING_CHAIN');
30
+ // If the step is waiting for a transaction on the receiving chain, we do not switch the chain
31
+ // All changes are already done from the source chain
32
+ // Return the step
33
+ if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION' ||
34
+ !recievingChainProcess) {
35
+ const updatedWalletClient = await switchChain(this.walletClient, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
36
+ if (!updatedWalletClient) {
37
+ // Chain switch was not successful, stop execution here
38
+ return step;
39
+ }
40
+ this.walletClient = updatedWalletClient;
41
+ }
42
+ const client = this.walletClient.extend(publicActions);
43
+ const config = ConfigService.getInstance().getConfig();
44
+ const isMultisigWalletClient = !!config.multisig?.isMultisigWalletClient;
45
+ const multisigBatchTransactions = [];
46
+ const shouldBatchTransactions = config.multisig?.shouldBatchTransactions &&
47
+ !!config.multisig.sendBatchTransaction;
48
+ step.execution = this.statusManager.initExecutionObject(step);
49
+ const chainsService = ChainsService.getInstance();
50
+ const fromChain = await chainsService.getChainById(step.action.fromChainId);
51
+ const toChain = await chainsService.getChainById(step.action.toChainId);
52
+ const isBridgeExecution = fromChain.id !== toChain.id;
53
+ const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP';
54
+ // STEP 1: Check allowance
55
+ const existingProcess = step.execution.process.find((p) => p.type === currentProcessType);
56
+ // Check token approval only if fromToken is not the native token => no approval needed in that case
57
+ const checkForAllowance = !existingProcess?.txHash &&
58
+ !isZeroAddress(step.action.fromToken.address) &&
59
+ (shouldBatchTransactions || !isMultisigWalletClient);
60
+ if (checkForAllowance) {
61
+ const data = await checkAllowance(client, step, this.statusManager, this.settings, fromChain, this.allowUserInteraction, shouldBatchTransactions);
62
+ if (data) {
63
+ // allowance doesn't need value
64
+ const baseTransaction = {
65
+ to: step.action.fromToken.address,
66
+ data,
67
+ };
68
+ multisigBatchTransactions.push(baseTransaction);
69
+ }
70
+ }
71
+ // STEP 2: Get transaction
72
+ let process = this.statusManager.findOrCreateProcess(step, currentProcessType);
73
+ if (process.status !== 'DONE') {
74
+ const multisigProcess = step.execution.process.find((p) => !!p.multisigTxHash);
75
+ try {
76
+ if (isMultisigWalletClient && multisigProcess) {
77
+ const multisigTxHash = multisigProcess.multisigTxHash;
78
+ if (!multisigTxHash) {
79
+ throw new ValidationError('Multisig internal transaction hash is undefined.');
80
+ }
81
+ await updateMultisigRouteProcess(multisigTxHash, step, this.statusManager, process.type, fromChain);
82
+ }
83
+ let txHash;
84
+ if (process.txHash) {
85
+ // Make sure that the chain is still correct
86
+ const updatedWalletClient = await switchChain(this.walletClient, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
87
+ if (!updatedWalletClient) {
88
+ // Chain switch was not successful, stop execution here
89
+ return step;
90
+ }
91
+ this.walletClient = updatedWalletClient;
92
+ // Load exiting transaction
93
+ txHash = process.txHash;
94
+ }
95
+ else {
96
+ process = this.statusManager.updateProcess(step, process.type, 'STARTED');
97
+ // Check balance
98
+ await checkBalance(client.account.address, step);
99
+ // Create new transaction
100
+ if (!step.transactionRequest) {
101
+ const updatedStep = await ApiService.getStepTransaction(step);
102
+ const comparedStep = await stepComparison(this.statusManager, step, updatedStep, this.settings, this.allowUserInteraction);
103
+ step = {
104
+ ...comparedStep,
105
+ execution: step.execution,
106
+ };
107
+ }
108
+ if (!step.transactionRequest) {
109
+ throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
110
+ }
111
+ // STEP 3: Send the transaction
112
+ // Make sure that the chain is still correct
113
+ const updatedWalletClient = await switchChain(this.walletClient, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
114
+ if (!updatedWalletClient) {
115
+ // Chain switch was not successful, stop execution here
116
+ return step;
117
+ }
118
+ this.walletClient = updatedWalletClient;
119
+ process = this.statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
120
+ if (!this.allowUserInteraction) {
121
+ return step;
122
+ }
123
+ let transactionRequest = {
124
+ to: step.transactionRequest.to,
125
+ from: step.transactionRequest.from,
126
+ data: step.transactionRequest.data,
127
+ value: step.transactionRequest.value
128
+ ? BigInt(step.transactionRequest.value)
129
+ : undefined,
130
+ gas: step.transactionRequest.gasLimit
131
+ ? BigInt(step.transactionRequest.gasLimit)
132
+ : undefined,
133
+ // gasPrice: step.transactionRequest.gasPrice
134
+ // ? BigInt(step.transactionRequest.gasPrice as string)
135
+ // : undefined,
136
+ // maxFeePerGas: step.transactionRequest.maxFeePerGas
137
+ // ? BigInt(step.transactionRequest.maxFeePerGas as string)
138
+ // : undefined,
139
+ maxPriorityFeePerGas: this.walletClient.account?.type === 'local'
140
+ ? await getMaxPriorityFeePerGas(client)
141
+ : step.transactionRequest.maxPriorityFeePerGas
142
+ ? BigInt(step.transactionRequest.maxPriorityFeePerGas)
143
+ : undefined,
144
+ };
145
+ if (this.settings.updateTransactionRequestHook) {
146
+ const customizedTransactionRequest = await this.settings.updateTransactionRequestHook({
147
+ requestType: 'transaction',
148
+ ...transactionRequest,
149
+ });
150
+ transactionRequest = {
151
+ ...transactionRequest,
152
+ ...customizedTransactionRequest,
153
+ };
154
+ }
155
+ if (shouldBatchTransactions &&
156
+ config.multisig?.sendBatchTransaction) {
157
+ if (transactionRequest.to && transactionRequest.data) {
158
+ const populatedTransaction = {
159
+ value: transactionRequest.value,
160
+ to: transactionRequest.to,
161
+ data: transactionRequest.data,
162
+ };
163
+ multisigBatchTransactions.push(populatedTransaction);
164
+ txHash = await config.multisig?.sendBatchTransaction(multisigBatchTransactions);
165
+ }
166
+ else {
167
+ throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
168
+ }
169
+ }
170
+ else {
171
+ txHash = await this.walletClient.sendTransaction({
172
+ to: transactionRequest.to,
173
+ account: this.walletClient.account,
174
+ data: transactionRequest.data,
175
+ gas: transactionRequest.gas,
176
+ gasPrice: transactionRequest.gasPrice,
177
+ maxFeePerGas: transactionRequest.maxFeePerGas,
178
+ maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
179
+ chain: null,
180
+ });
181
+ }
182
+ // STEP 4: Wait for the transaction
183
+ if (isMultisigWalletClient) {
184
+ process = this.statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED', {
185
+ multisigTxHash: txHash,
186
+ });
187
+ }
188
+ else {
189
+ process = this.statusManager.updateProcess(step, process.type, 'PENDING', {
190
+ txHash: txHash,
191
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
192
+ });
193
+ }
194
+ }
195
+ let replacementReason;
196
+ const transactionReceipt = await client.waitForTransactionReceipt({
197
+ hash: txHash,
198
+ onReplaced: (response) => {
199
+ replacementReason = response.reason;
200
+ this.statusManager.updateProcess(step, process.type, 'PENDING', {
201
+ txHash: response.transaction.hash,
202
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.hash}`,
203
+ });
204
+ },
205
+ });
206
+ if (replacementReason === 'cancelled') {
207
+ throw new TransactionError(LiFiErrorCode.TransactionCanceled, 'User canceled transaction.');
208
+ }
209
+ // if it's multisig wallet client and the process is in ACTION_REQUIRED
210
+ // then signatures are still needed
211
+ if (isMultisigWalletClient && process.status === 'ACTION_REQUIRED') {
212
+ await updateMultisigRouteProcess(transactionReceipt.transactionHash, step, this.statusManager, process.type, fromChain);
213
+ }
214
+ if (!isMultisigWalletClient) {
215
+ process = this.statusManager.updateProcess(step, process.type, 'PENDING', {
216
+ txHash: transactionReceipt.transactionHash,
217
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transactionReceipt.transactionHash}`,
218
+ });
219
+ }
220
+ if (isBridgeExecution) {
221
+ process = this.statusManager.updateProcess(step, process.type, 'DONE');
222
+ }
223
+ }
224
+ catch (e) {
225
+ const error = await parseError(e, step, process);
226
+ process = this.statusManager.updateProcess(step, process.type, 'FAILED', {
227
+ error: {
228
+ message: error.message,
229
+ htmlMessage: error.htmlMessage,
230
+ code: error.code,
231
+ },
232
+ });
233
+ this.statusManager.updateExecution(step, 'FAILED');
234
+ throw error;
235
+ }
236
+ }
237
+ // STEP 5: Wait for the receiving chain
238
+ const processTxHash = process.txHash;
239
+ if (isBridgeExecution) {
240
+ process = this.statusManager.findOrCreateProcess(step, 'RECEIVING_CHAIN', 'PENDING');
241
+ }
242
+ let statusResponse;
243
+ try {
244
+ if (!processTxHash) {
245
+ throw new Error('Transaction hash is undefined.');
246
+ }
247
+ statusResponse = (await waitForReceivingTransaction(processTxHash, this.statusManager, process.type, step));
248
+ const statusReceiving = statusResponse.receiving;
249
+ process = this.statusManager.updateProcess(step, process.type, 'DONE', {
250
+ substatus: statusResponse.substatus,
251
+ substatusMessage: statusResponse.substatusMessage ||
252
+ getSubstatusMessage(statusResponse.status, statusResponse.substatus),
253
+ txHash: statusReceiving?.txHash,
254
+ txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`,
255
+ });
256
+ this.statusManager.updateExecution(step, 'DONE', {
257
+ fromAmount: statusResponse.sending.amount,
258
+ toAmount: statusReceiving?.amount,
259
+ toToken: statusReceiving?.token,
260
+ gasAmount: statusResponse.sending.gasAmount,
261
+ gasAmountUSD: statusResponse.sending.gasAmountUSD,
262
+ gasPrice: statusResponse.sending.gasPrice,
263
+ gasToken: statusResponse.sending.gasToken,
264
+ gasUsed: statusResponse.sending.gasUsed,
265
+ });
266
+ }
267
+ catch (e) {
268
+ const htmlMessage = await getTransactionFailedMessage(step, process.txLink);
269
+ process = this.statusManager.updateProcess(step, process.type, 'FAILED', {
270
+ error: {
271
+ code: LiFiErrorCode.TransactionFailed,
272
+ message: 'Failed while waiting for receiving chain.',
273
+ htmlMessage,
274
+ },
275
+ });
276
+ this.statusManager.updateExecution(step, 'FAILED');
277
+ console.warn(e);
278
+ throw e;
279
+ }
280
+ // DONE
281
+ return step;
282
+ };
283
+ this.walletClient = options.walletClient;
284
+ }
285
+ }
@@ -1,30 +1,30 @@
1
1
  import type { Route } from '@lifi/types';
2
- import type { WalletClient } from 'viem';
3
- import ConfigService from '../services/ConfigService';
4
- import type { ConfigUpdate, ExecutionSettings } from '../types';
2
+ import type { ProviderType, SDKProvider } from '../providers';
3
+ import { ConfigService } from '../services/ConfigService';
4
+ import type { SDKOptions } from '../types';
5
+ import type { ExecutionSettings } from './types';
5
6
  export declare class RouteExecutionManager {
6
7
  private executionDictionary;
7
8
  private executionPromiseDictionary;
8
9
  protected configService: ConfigService;
9
- constructor(configUpdate: ConfigUpdate);
10
+ private providers?;
11
+ constructor(options: SDKOptions);
10
12
  /**
11
13
  * Execute a route.
12
- * @param walletClient - The walletClient required to send the transactions.
13
14
  * @param route - The route that should be executed. Cannot be an active route.
14
15
  * @param settings - An object containing settings and callbacks.
15
16
  * @returns The executed route.
16
17
  * @throws {LiFiError} Throws a LiFiError if the execution fails.
17
18
  */
18
- executeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
19
+ executeRoute: (route: Route, settings?: ExecutionSettings) => Promise<Route>;
19
20
  /**
20
21
  * Resume the execution of a route that has been stopped or had an error while executing.
21
- * @param walletClient - The walletClient required to send the transactions.
22
22
  * @param route - The route that is to be executed. Cannot be an active route.
23
23
  * @param settings - An object containing settings and callbacks.
24
24
  * @returns The executed route.
25
25
  * @throws {LiFiError} Throws a LiFiError if the execution fails.
26
26
  */
27
- resumeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
27
+ resumeRoute: (route: Route, settings?: ExecutionSettings) => Promise<Route>;
28
28
  private executeSteps;
29
29
  /**
30
30
  * Updates route execution to background or foreground state.
@@ -56,4 +56,5 @@ export declare class RouteExecutionManager {
56
56
  * @returns The updated route.
57
57
  */
58
58
  getActiveRoute: (route: Route) => Route | undefined;
59
+ getProvider: (type: ProviderType) => SDKProvider | undefined;
59
60
  }
@@ -1,21 +1,19 @@
1
- import ConfigService from '../services/ConfigService';
1
+ import { ConfigService } from '../services/ConfigService';
2
2
  import { ValidationError } from '../utils/errors';
3
3
  import { StatusManager } from './StatusManager';
4
- import { StepExecutor } from './StepExecutor';
5
4
  import { prepareRestart } from './prepareRestart';
6
5
  export class RouteExecutionManager {
7
- constructor(configUpdate) {
6
+ constructor(options) {
8
7
  this.executionDictionary = {};
9
8
  this.executionPromiseDictionary = {};
10
9
  /**
11
10
  * Execute a route.
12
- * @param walletClient - The walletClient required to send the transactions.
13
11
  * @param route - The route that should be executed. Cannot be an active route.
14
12
  * @param settings - An object containing settings and callbacks.
15
13
  * @returns The executed route.
16
14
  * @throws {LiFiError} Throws a LiFiError if the execution fails.
17
15
  */
18
- this.executeRoute = async (walletClient, route, settings) => {
16
+ this.executeRoute = async (route, settings) => {
19
17
  // Deep clone to prevent side effects
20
18
  const clonedRoute = structuredClone(route);
21
19
  let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
@@ -23,24 +21,23 @@ export class RouteExecutionManager {
23
21
  if (executionPromise) {
24
22
  return executionPromise;
25
23
  }
26
- executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
24
+ executionPromise = this.executeSteps(clonedRoute, settings);
27
25
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
28
26
  return executionPromise;
29
27
  };
30
28
  /**
31
29
  * 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
30
  * @param route - The route that is to be executed. Cannot be an active route.
34
31
  * @param settings - An object containing settings and callbacks.
35
32
  * @returns The executed route.
36
33
  * @throws {LiFiError} Throws a LiFiError if the execution fails.
37
34
  */
38
- this.resumeRoute = async (walletClient, route, settings) => {
35
+ this.resumeRoute = async (route, settings) => {
39
36
  // Deep clone to prevent side effects
40
37
  const clonedRoute = structuredClone(route);
41
38
  const execution = this.executionDictionary[clonedRoute.id];
42
39
  if (execution) {
43
- const executionHalted = execution.executors.some((executor) => executor.executionStopped);
40
+ const executionHalted = execution.executors.some((executor) => !executor.allowExecution);
44
41
  if (!executionHalted) {
45
42
  // Check if we want to resume route execution in the background
46
43
  this.updateRouteExecution(route, {
@@ -50,12 +47,12 @@ export class RouteExecutionManager {
50
47
  return executionPromise ?? clonedRoute;
51
48
  }
52
49
  }
53
- await prepareRestart(clonedRoute, walletClient);
54
- const executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
50
+ await prepareRestart(clonedRoute);
51
+ const executionPromise = this.executeSteps(clonedRoute, settings);
55
52
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
56
53
  return executionPromise;
57
54
  };
58
- this.executeSteps = async (walletClient, route, settings) => {
55
+ this.executeSteps = async (route, settings) => {
59
56
  const config = this.configService.getConfig();
60
57
  const execution = {
61
58
  route,
@@ -87,17 +84,24 @@ export class RouteExecutionManager {
87
84
  step.action.fromAmount = previousStep.execution.toAmount;
88
85
  }
89
86
  try {
90
- const stepExecutor = new StepExecutor(statusManager, execution.settings);
87
+ const provider = this.providers?.find((provider) => provider.isProviderStep(step));
88
+ if (!provider) {
89
+ throw new Error('SDK Execution Provider not found.');
90
+ }
91
+ const stepExecutor = await provider.getStepExecutor({
92
+ statusManager,
93
+ settings: execution.settings,
94
+ });
91
95
  execution.executors.push(stepExecutor);
92
96
  // Check if we want to execute this step in the background
93
97
  this.updateRouteExecution(route, execution.settings);
94
- const executedStep = await stepExecutor.executeStep(walletClient, step);
98
+ const executedStep = await stepExecutor.executeStep(step);
95
99
  // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
96
100
  if (executedStep.execution?.status !== 'DONE') {
97
101
  this.stopExecution(route);
98
102
  }
99
103
  // Execution stopped during the current step, we don't want to continue to the next step so we return already
100
- if (stepExecutor.executionStopped) {
104
+ if (stepExecutor.allowExecution) {
101
105
  return route;
102
106
  }
103
107
  }
@@ -163,7 +167,7 @@ export class RouteExecutionManager {
163
167
  executor.setInteraction({
164
168
  allowInteraction: false,
165
169
  allowUpdates: false,
166
- stopExecution: true,
170
+ allowExecution: false,
167
171
  });
168
172
  }
169
173
  delete this.executionDictionary[route.id];
@@ -186,10 +190,11 @@ export class RouteExecutionManager {
186
190
  this.getActiveRoute = (route) => {
187
191
  return this.executionDictionary[route.id]?.route;
188
192
  };
193
+ this.getProvider = (type) => {
194
+ return this.providers?.find((provider) => provider.type === type);
195
+ };
189
196
  this.configService = ConfigService.getInstance();
190
- if (configUpdate) {
191
- // Update API urls before we request chains
192
- this.configService.updateConfig(configUpdate);
193
- }
197
+ this.configService.updateConfig(options);
198
+ this.providers = options.providers;
194
199
  }
195
200
  }
@@ -1,4 +1,5 @@
1
- import type { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
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: LifiStep) => Execution;
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: LifiStep, status: Status, receipt?: Receipt): LifiStep;
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: LifiStep, type: ProcessType, status?: Status) => Process;
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: LifiStep, type: ProcessType, status: Status, params?: OptionalParameters) => Process;
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: LifiStep, type: ProcessType) => void;
64
- updateStepInRoute: (step: LifiStep) => LifiStep;
64
+ removeProcess: (step: LiFiStep, type: ProcessType) => void;
65
+ updateStepInRoute: (step: LiFiStep) => LiFiStep;
65
66
  allowUpdates(value: boolean): void;
66
67
  }
67
68
  export {};
@@ -1,4 +1,4 @@
1
- import { emptyExecution } from '../types';
1
+ import { emptyExecution } from '@lifi/types';
2
2
  import { getProcessMessage } from './utils';
3
3
  /**
4
4
  * Manages status updates of a route and provides various functions for tracking processes
@@ -1,7 +1,7 @@
1
- import type { Execution } from '@lifi/types';
2
- import type { ExecutionParams } from '../types';
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<Execution>;
6
+ execute: ({ walletClient, step, statusManager, settings, }: ExecutionParams) => Promise<LiFiStep>;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import { publicActions } from 'viem';
2
2
  import ApiService from '../services/ApiService';
3
- import ChainsService from '../services/ChainsService';
4
- import ConfigService from '../services/ConfigService';
3
+ import { ChainsService } from '../services/ChainsService';
4
+ import { ConfigService } from '../services/ConfigService';
5
5
  import { getMaxPriorityFeePerGas } from '../utils';
6
6
  import { LiFiErrorCode, TransactionError, ValidationError, } from '../utils/errors';
7
7
  import { getTransactionFailedMessage, parseError } from '../utils/parseError';
@@ -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.execution;
70
+ return step;
71
71
  }
72
72
  walletClient = updatedWalletClient;
73
73
  // Load exiting transaction
@@ -94,12 +94,12 @@ export class StepExecutionManager {
94
94
  const updatedWalletClient = await switchChain(walletClient, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
95
95
  if (!updatedWalletClient) {
96
96
  // Chain switch was not successful, stop execution here
97
- return step.execution;
97
+ return step;
98
98
  }
99
99
  walletClient = updatedWalletClient;
100
100
  process = statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
101
101
  if (!this.allowUserInteraction) {
102
- return step.execution;
102
+ return step;
103
103
  }
104
104
  let transactionRequest = {
105
105
  to: step.transactionRequest.to,
@@ -259,7 +259,7 @@ export class StepExecutionManager {
259
259
  throw e;
260
260
  }
261
261
  // DONE
262
- return step.execution;
262
+ return step;
263
263
  };
264
264
  }
265
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 { Chain, InternalExecutionSettings, LifiStep } from '../types';
4
- export declare const checkAllowance: (walletClient: WalletClient, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean, shouldBatchTransactions?: boolean) => Promise<Hash | void>;
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>;
@@ -1,2 +1,2 @@
1
- import type { LifiStep } from '..';
2
- export declare const checkBalance: (walletAddress: string, step: LifiStep, depth?: number) => Promise<void>;
1
+ import type { LiFiStep } from '@lifi/types';
2
+ export declare const checkBalance: (walletAddress: string, step: LiFiStep, depth?: number) => Promise<void>;
@@ -1 +1,2 @@
1
1
  export * from './StatusManager';
2
+ export * from './types';
@@ -1 +1,2 @@
1
1
  export * from './StatusManager';
2
+ export * from './types';
@@ -1,4 +1,4 @@
1
- import type { ExtendedChain, LifiStep, ProcessType } from '@lifi/types';
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: LifiStep, statusManager: StatusManager, processType: ProcessType, fromChain: ExtendedChain) => Promise<void>;
4
+ export declare const updateMultisigRouteProcess: (internalTxHash: Hash, step: LiFiStep, statusManager: StatusManager, processType: ProcessType, fromChain: ExtendedChain) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import ConfigService from '../services/ConfigService';
1
+ import { ConfigService } from '../services/ConfigService';
2
2
  import { LiFiErrorCode, TransactionError } from '../utils/errors';
3
3
  export const updateMultisigRouteProcess = async (internalTxHash, step, statusManager, processType, fromChain) => {
4
4
  const config = ConfigService.getInstance().getConfig();
@@ -1,3 +1,2 @@
1
- import { type WalletClient } from 'viem';
2
- import type { Route } from '../types';
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, walletClient) => {
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 { InternalExecutionSettings, LifiStep } from '../types';
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 LifiStep
13
+ * @returns Return LiFiStep
13
14
  */
14
- export declare const stepComparison: (statusManager: StatusManager, oldStep: LifiStep, newStep: LifiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LifiStep>;
15
+ export declare const stepComparison: (statusManager: StatusManager, oldStep: LiFiStep, newStep: LiFiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LiFiStep>;