@lifi/sdk 2.2.2 → 3.0.0-alpha.1

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 (183) hide show
  1. package/dist/LiFi.d.ts +69 -62
  2. package/dist/LiFi.js +71 -60
  3. package/dist/allowance/getAllowance.d.ts +6 -0
  4. package/dist/allowance/getAllowance.js +78 -0
  5. package/dist/allowance/index.d.ts +3 -2
  6. package/dist/allowance/index.js +3 -2
  7. package/dist/allowance/setAllowance.d.ts +5 -0
  8. package/dist/allowance/setAllowance.js +50 -0
  9. package/dist/allowance/types.d.ts +27 -0
  10. package/dist/allowance/types.js +1 -0
  11. package/dist/balance/getBalance.d.ts +2 -0
  12. package/dist/balance/getBalance.js +93 -0
  13. package/dist/balance/getTokenBalance.d.ts +2 -2
  14. package/dist/balance/getTokenBalance.js +4 -4
  15. package/dist/balance/index.d.ts +1 -12
  16. package/dist/balance/index.js +1 -9
  17. package/dist/cjs/LiFi.d.ts +69 -62
  18. package/dist/cjs/LiFi.js +69 -58
  19. package/dist/cjs/allowance/getAllowance.d.ts +6 -0
  20. package/dist/cjs/allowance/getAllowance.js +85 -0
  21. package/dist/cjs/allowance/index.d.ts +3 -2
  22. package/dist/cjs/allowance/index.js +3 -2
  23. package/dist/cjs/allowance/setAllowance.d.ts +5 -0
  24. package/dist/cjs/allowance/setAllowance.js +56 -0
  25. package/dist/cjs/allowance/types.d.ts +27 -0
  26. package/dist/cjs/allowance/types.js +2 -0
  27. package/dist/cjs/balance/getBalance.d.ts +2 -0
  28. package/dist/cjs/balance/getBalance.js +97 -0
  29. package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
  30. package/dist/cjs/balance/getTokenBalance.js +6 -9
  31. package/dist/cjs/balance/index.d.ts +1 -12
  32. package/dist/cjs/balance/index.js +1 -9
  33. package/dist/cjs/connectors.d.ts +7 -5
  34. package/dist/cjs/connectors.js +45 -37
  35. package/dist/cjs/constants.d.ts +6 -0
  36. package/dist/cjs/constants.js +9 -0
  37. package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
  38. package/dist/cjs/execution/RouteExecutionManager.js +27 -45
  39. package/dist/cjs/execution/StatusManager.d.ts +22 -23
  40. package/dist/cjs/execution/StatusManager.js +21 -22
  41. package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
  42. package/dist/cjs/execution/StepExecutionManager.js +118 -125
  43. package/dist/cjs/execution/StepExecutor.d.ts +4 -4
  44. package/dist/cjs/execution/StepExecutor.js +6 -6
  45. package/dist/cjs/execution/checkAllowance.d.ts +4 -0
  46. package/dist/cjs/execution/checkAllowance.js +77 -0
  47. package/dist/cjs/execution/checkBalance.d.ts +2 -0
  48. package/dist/cjs/execution/checkBalance.js +42 -0
  49. package/dist/cjs/execution/multisig.d.ts +4 -3
  50. package/dist/cjs/execution/multisig.js +9 -11
  51. package/dist/cjs/execution/prepareRestart.d.ts +3 -0
  52. package/dist/cjs/execution/prepareRestart.js +65 -0
  53. package/dist/cjs/execution/stepComparison.d.ts +3 -3
  54. package/dist/cjs/execution/stepComparison.js +2 -2
  55. package/dist/cjs/execution/switchChain.d.ts +13 -8
  56. package/dist/cjs/execution/switchChain.js +16 -11
  57. package/dist/cjs/execution/utils.d.ts +9 -3
  58. package/dist/cjs/execution/utils.js +19 -66
  59. package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
  60. package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
  61. package/dist/cjs/helpers.d.ts +7 -17
  62. package/dist/cjs/helpers.js +6 -38
  63. package/dist/cjs/request.js +1 -1
  64. package/dist/cjs/services/ApiService.d.ts +2 -2
  65. package/dist/cjs/services/ApiService.js +2 -0
  66. package/dist/cjs/services/ChainsService.d.ts +1 -1
  67. package/dist/cjs/services/ConfigService.d.ts +1 -1
  68. package/dist/cjs/services/ConfigService.js +1 -2
  69. package/dist/cjs/typeguards.d.ts +1 -1
  70. package/dist/cjs/types/abi.d.ts +5 -0
  71. package/dist/cjs/types/abi.js +45 -0
  72. package/dist/cjs/types/index.d.ts +2 -2
  73. package/dist/cjs/types/index.js +3 -3
  74. package/dist/cjs/types/internal.types.d.ts +24 -30
  75. package/dist/cjs/utils/errors.d.ts +15 -14
  76. package/dist/cjs/utils/errors.js +38 -37
  77. package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  78. package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
  79. package/dist/cjs/utils/index.d.ts +5 -0
  80. package/dist/cjs/utils/index.js +21 -0
  81. package/dist/cjs/utils/median.d.ts +1 -0
  82. package/dist/cjs/utils/median.js +15 -0
  83. package/dist/cjs/utils/parseError.d.ts +4 -4
  84. package/dist/cjs/utils/parseError.js +41 -38
  85. package/dist/cjs/utils/utils.d.ts +1 -16
  86. package/dist/cjs/utils/utils.js +9 -78
  87. package/dist/cjs/version.d.ts +1 -1
  88. package/dist/cjs/version.js +1 -1
  89. package/dist/connectors.d.ts +7 -5
  90. package/dist/connectors.js +19 -35
  91. package/dist/constants.d.ts +6 -0
  92. package/dist/constants.js +6 -0
  93. package/dist/execution/RouteExecutionManager.d.ts +24 -30
  94. package/dist/execution/RouteExecutionManager.js +27 -45
  95. package/dist/execution/StatusManager.d.ts +22 -23
  96. package/dist/execution/StatusManager.js +22 -23
  97. package/dist/execution/StepExecutionManager.d.ts +3 -3
  98. package/dist/execution/StepExecutionManager.js +116 -123
  99. package/dist/execution/StepExecutor.d.ts +4 -4
  100. package/dist/execution/StepExecutor.js +6 -6
  101. package/dist/execution/checkAllowance.d.ts +4 -0
  102. package/dist/execution/checkAllowance.js +73 -0
  103. package/dist/execution/checkBalance.d.ts +2 -0
  104. package/dist/execution/checkBalance.js +38 -0
  105. package/dist/execution/multisig.d.ts +4 -3
  106. package/dist/execution/multisig.js +10 -12
  107. package/dist/execution/prepareRestart.d.ts +3 -0
  108. package/dist/execution/prepareRestart.js +61 -0
  109. package/dist/execution/stepComparison.d.ts +3 -3
  110. package/dist/execution/stepComparison.js +3 -3
  111. package/dist/execution/switchChain.d.ts +13 -8
  112. package/dist/execution/switchChain.js +17 -12
  113. package/dist/execution/utils.d.ts +9 -3
  114. package/dist/execution/utils.js +18 -61
  115. package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
  116. package/dist/execution/waitForReceivingTransaction.js +51 -0
  117. package/dist/helpers.d.ts +7 -17
  118. package/dist/helpers.js +5 -34
  119. package/dist/request.js +2 -2
  120. package/dist/services/ApiService.d.ts +2 -2
  121. package/dist/services/ApiService.js +2 -0
  122. package/dist/services/ChainsService.d.ts +1 -1
  123. package/dist/services/ConfigService.d.ts +1 -1
  124. package/dist/services/ConfigService.js +2 -3
  125. package/dist/typeguards.d.ts +1 -1
  126. package/dist/types/abi.d.ts +5 -0
  127. package/dist/types/abi.js +42 -0
  128. package/dist/types/index.d.ts +2 -2
  129. package/dist/types/index.js +2 -2
  130. package/dist/types/internal.types.d.ts +24 -30
  131. package/dist/utils/errors.d.ts +15 -14
  132. package/dist/utils/errors.js +36 -35
  133. package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  134. package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
  135. package/dist/utils/index.d.ts +5 -0
  136. package/dist/utils/index.js +5 -0
  137. package/dist/utils/median.d.ts +1 -0
  138. package/dist/utils/median.js +11 -0
  139. package/dist/utils/parseError.d.ts +4 -4
  140. package/dist/utils/parseError.js +42 -39
  141. package/dist/utils/utils.d.ts +1 -16
  142. package/dist/utils/utils.js +7 -69
  143. package/dist/version.d.ts +1 -1
  144. package/dist/version.js +1 -1
  145. package/package.json +28 -27
  146. package/dist/allowance/checkAllowance.d.ts +0 -4
  147. package/dist/allowance/checkAllowance.js +0 -96
  148. package/dist/allowance/tokenApproval.d.ts +0 -22
  149. package/dist/allowance/tokenApproval.js +0 -59
  150. package/dist/allowance/utils.d.ts +0 -15
  151. package/dist/allowance/utils.js +0 -77
  152. package/dist/balance/checkBalance.d.ts +0 -3
  153. package/dist/balance/checkBalance.js +0 -38
  154. package/dist/balance/utils.d.ts +0 -6
  155. package/dist/balance/utils.js +0 -143
  156. package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
  157. package/dist/cjs/allowance/checkAllowance.js +0 -103
  158. package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
  159. package/dist/cjs/allowance/tokenApproval.js +0 -69
  160. package/dist/cjs/allowance/utils.d.ts +0 -15
  161. package/dist/cjs/allowance/utils.js +0 -87
  162. package/dist/cjs/balance/checkBalance.d.ts +0 -3
  163. package/dist/cjs/balance/checkBalance.js +0 -45
  164. package/dist/cjs/balance/utils.d.ts +0 -6
  165. package/dist/cjs/balance/utils.js +0 -150
  166. package/dist/cjs/types/ERC20.d.ts +0 -22
  167. package/dist/cjs/types/ERC20.js +0 -53
  168. package/dist/cjs/utils/getProvider.d.ts +0 -3
  169. package/dist/cjs/utils/getProvider.js +0 -11
  170. package/dist/cjs/utils/multicall.d.ts +0 -10
  171. package/dist/cjs/utils/multicall.js +0 -68
  172. package/dist/cjs/utils/multicallAbi.json +0 -313
  173. package/dist/cjs/utils/preRestart.d.ts +0 -3
  174. package/dist/cjs/utils/preRestart.js +0 -56
  175. package/dist/types/ERC20.d.ts +0 -22
  176. package/dist/types/ERC20.js +0 -50
  177. package/dist/utils/getProvider.d.ts +0 -3
  178. package/dist/utils/getProvider.js +0 -7
  179. package/dist/utils/multicall.d.ts +0 -10
  180. package/dist/utils/multicall.js +0 -61
  181. package/dist/utils/multicallAbi.json +0 -313
  182. package/dist/utils/preRestart.d.ts +0 -3
  183. package/dist/utils/preRestart.js +0 -52
@@ -1,69 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isNativeTokenAddress = exports.isZeroAddress = exports.loadTransactionReceipt = exports.repeatUntilDone = exports.formatTokenAmountOnly = exports.splitListIntoChunks = exports.personalizeStep = exports.sleep = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
- const ethers_1 = require("ethers");
9
- const connectors_1 = require("../connectors");
10
- const sleep = (mills) => {
3
+ exports.isNativeTokenAddress = exports.isZeroAddress = exports.repeatUntilDone = exports.wait = void 0;
4
+ const constants_1 = require("../constants");
5
+ const wait = (ms) => {
11
6
  return new Promise((resolve) => {
12
- setTimeout(resolve, mills);
7
+ setTimeout(resolve, ms);
13
8
  });
14
9
  };
15
- exports.sleep = sleep;
16
- const personalizeStep = async (signer, step) => {
17
- if (step.action.toAddress && step.action.fromAddress) {
18
- return step;
19
- }
20
- const address = await signer.getAddress();
21
- const fromAddress = step.action.fromAddress || address;
22
- const toAddress = step.action.toAddress || address;
23
- return {
24
- ...step,
25
- action: {
26
- ...step.action,
27
- fromAddress,
28
- toAddress,
29
- },
30
- };
31
- };
32
- exports.personalizeStep = personalizeStep;
33
- const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
34
- const chunkIndex = Math.floor(index / chunkSize);
35
- if (!resultList[chunkIndex]) {
36
- resultList[chunkIndex] = []; // start a new chunk
37
- }
38
- resultList[chunkIndex].push(item);
39
- return resultList;
40
- }, []);
41
- exports.splitListIntoChunks = splitListIntoChunks;
42
- const formatTokenAmountOnly = (token, amount) => {
43
- if (!amount) {
44
- return '0.0';
45
- }
46
- let floated;
47
- if (typeof amount === 'string') {
48
- if (amount === '0') {
49
- return '0.0';
50
- }
51
- floated = new bignumber_js_1.default(amount).shiftedBy(-token.decimals);
52
- }
53
- else {
54
- floated = amount;
55
- if (floated.isZero()) {
56
- return '0.0';
57
- }
58
- }
59
- // show at least 4 decimal places and at least two non-zero digests
60
- let decimalPlaces = 3;
61
- while (floated.lt(1 / 10 ** decimalPlaces)) {
62
- decimalPlaces++;
63
- }
64
- return floated.toFixed(decimalPlaces + 1, 1);
65
- };
66
- exports.formatTokenAmountOnly = formatTokenAmountOnly;
10
+ exports.wait = wait;
67
11
  /**
68
12
  * Repeatedly calls a given asynchronous function until it resolves with a value
69
13
  * @param toRepeat The function that should be repeated
@@ -75,35 +19,22 @@ const repeatUntilDone = async (toRepeat, timeout = 5000) => {
75
19
  while (!result) {
76
20
  result = await toRepeat();
77
21
  if (!result) {
78
- await (0, exports.sleep)(timeout);
22
+ await (0, exports.wait)(timeout);
79
23
  }
80
24
  }
81
25
  return result;
82
26
  };
83
27
  exports.repeatUntilDone = repeatUntilDone;
84
- /**
85
- * Loads a transaction receipt using the rpc for the given chain id
86
- * @param chainId The chain id where the transaction should be loaded from
87
- * @param txHash The hash of the transaction
88
- * @returns TransactionReceipt
89
- */
90
- const loadTransactionReceipt = async (chainId, txHash) => {
91
- const rpc = await (0, connectors_1.getRpcProvider)(chainId);
92
- const tx = await rpc.getTransaction(txHash);
93
- return tx.wait();
94
- };
95
- exports.loadTransactionReceipt = loadTransactionReceipt;
96
28
  const isZeroAddress = (address) => {
97
- if (address === ethers_1.constants.AddressZero ||
98
- address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
29
+ if (address === constants_1.AddressZero || address === constants_1.AlternativeAddressZero) {
99
30
  return true;
100
31
  }
101
32
  return false;
102
33
  };
103
34
  exports.isZeroAddress = isZeroAddress;
104
35
  const isNativeTokenAddress = (address) => {
105
- if (address === ethers_1.constants.AddressZero ||
106
- address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
36
+ if (address === constants_1.AddressZero ||
37
+ address === constants_1.AlternativeAddressZero ||
107
38
  // CELO native token
108
39
  address === '0x471ece3750da237f93b8e339c536989b8978a438') {
109
40
  return true;
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.2.2";
2
+ export declare const version = "3.0.0-alpha.1";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/sdk';
5
- exports.version = '2.2.2';
5
+ exports.version = '3.0.0-alpha.1';
@@ -1,6 +1,8 @@
1
- import { FallbackProvider } from '@ethersproject/providers';
2
- import { ChainId } from './types';
3
- export declare const getRpcUrl: (chainId: ChainId, archive?: boolean) => Promise<string>;
4
- export declare const getRpcUrls: (chainId: ChainId, archive?: boolean) => Promise<string[]>;
5
- export declare const getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
1
+ import type { PublicClient } from 'viem';
2
+ import type { Chain } from 'viem/chains';
3
+ import type { ChainId } from './types';
4
+ export declare const getChainById: (chainId: ChainId) => Chain | undefined;
5
+ export declare const getRpcUrl: (chainId: ChainId) => Promise<string>;
6
+ export declare const getRpcUrls: (chainId: ChainId) => Promise<string[]>;
7
+ export declare const getPublicClient: (chainId: number) => Promise<PublicClient>;
6
8
  export declare const getMulticallAddress: (chainId: ChainId) => Promise<string | undefined>;
@@ -1,53 +1,37 @@
1
- import { FallbackProvider, StaticJsonRpcProvider, } from '@ethersproject/providers';
2
- import { getRandomNumber } from './helpers';
1
+ import { createPublicClient, fallback, http } from 'viem';
2
+ import * as chains from 'viem/chains'; // TODO: optimize using BE chains
3
3
  import ConfigService from './services/ConfigService';
4
- import { ChainId } from './types';
5
4
  import { ServerError } from './utils/errors';
6
5
  // cached providers
7
- const chainProviders = {};
8
- // Archive RPC Provider
9
- const archiveRpcs = {
10
- [ChainId.ETH]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/eth/mainnet/archive',
11
- [ChainId.BSC]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/bsc/mainnet/archive',
12
- [ChainId.POL]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/polygon/mainnet/archive',
13
- [ChainId.FTM]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/fantom/mainnet',
6
+ const publicClients = {};
7
+ export const getChainById = (chainId) => {
8
+ return Object.values(chains).find((chain) => chain.id === chainId);
14
9
  };
15
10
  // RPC Urls
16
- export const getRpcUrl = async (chainId, archive = false) => {
17
- const rpcUrls = await getRpcUrls(chainId, archive);
11
+ export const getRpcUrl = async (chainId) => {
12
+ const rpcUrls = await getRpcUrls(chainId);
18
13
  return rpcUrls[0];
19
14
  };
20
- export const getRpcUrls = async (chainId, archive = false) => {
21
- if (archive && archiveRpcs[chainId]) {
22
- return [archiveRpcs[chainId]];
23
- }
15
+ export const getRpcUrls = async (chainId) => {
24
16
  const configService = ConfigService.getInstance();
25
17
  const config = await configService.getConfigAsync();
26
18
  return config.rpcs[chainId];
27
19
  };
28
- const getRandomProvider = (providerList) => {
29
- const index = getRandomNumber(0, providerList.length - 1);
30
- return providerList[index];
31
- };
32
- // Provider
33
- export const getRpcProvider = async (chainId, archive = false) => {
34
- if (archive && archiveRpcs[chainId]) {
35
- // return archive PRC, but don't cache it
36
- return new FallbackProvider([
37
- new StaticJsonRpcProvider(await getRpcUrl(chainId, archive), chainId),
38
- ]);
39
- }
40
- if (!chainProviders[chainId]?.length) {
41
- chainProviders[chainId] = [];
42
- const urls = await getRpcUrls(chainId, archive);
43
- urls.forEach((url) => {
44
- chainProviders[chainId].push(new FallbackProvider([new StaticJsonRpcProvider(url, chainId)]));
20
+ export const getPublicClient = async (chainId) => {
21
+ if (!publicClients[chainId]) {
22
+ const urls = await getRpcUrls(chainId);
23
+ const fallbackTransports = urls.map((url) => http(url, {
24
+ batch: true,
25
+ }));
26
+ publicClients[chainId] = createPublicClient({
27
+ chain: getChainById(chainId),
28
+ transport: fallback(fallbackTransports),
45
29
  });
46
30
  }
47
- if (!chainProviders[chainId].length) {
31
+ if (!publicClients[chainId]) {
48
32
  throw new ServerError(`Unable to configure provider for chain ${chainId}`);
49
33
  }
50
- return getRandomProvider(chainProviders[chainId]);
34
+ return publicClients[chainId];
51
35
  };
52
36
  // Multicall
53
37
  export const getMulticallAddress = async (chainId) => {
@@ -0,0 +1,6 @@
1
+ export declare const AddressZero = "0x0000000000000000000000000000000000000000";
2
+ export declare const AlternativeAddressZero = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
3
+ /**
4
+ * Cronos require bigger multicall chunks than default 1024 (1 KB)
5
+ */
6
+ export declare const MulticallBatchSize = 16384;
@@ -0,0 +1,6 @@
1
+ export const AddressZero = '0x0000000000000000000000000000000000000000';
2
+ export const AlternativeAddressZero = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
3
+ /**
4
+ * Cronos require bigger multicall chunks than default 1024 (1 KB)
5
+ */
6
+ export const MulticallBatchSize = 16384; // 16 Kilobytes (KB)
@@ -1,7 +1,7 @@
1
- import { Route } from '@lifi/types';
2
- import { Signer } from 'ethers';
1
+ import type { Route } from '@lifi/types';
2
+ import type { WalletClient } from 'viem';
3
3
  import ConfigService from '../services/ConfigService';
4
- import { ConfigUpdate, ExecutionSettings } from '../types';
4
+ import type { ConfigUpdate, ExecutionSettings } from '../types';
5
5
  export declare class RouteExecutionManager {
6
6
  private executionDictionary;
7
7
  private executionPromiseDictionary;
@@ -9,57 +9,51 @@ export declare class RouteExecutionManager {
9
9
  constructor(configUpdate: ConfigUpdate);
10
10
  /**
11
11
  * Execute a route.
12
- * @param {Signer} signer - The signer required to send the transactions.
13
- * @param {Route} route - The route that should be executed. Cannot be an active route.
14
- * @param {ExecutionSettings} settings - An object containing settings and callbacks.
15
- * @return {Promise<Route>} The executed route.
16
- * @throws {LifiError} Throws a LifiError if the execution fails.
12
+ * @param walletClient - The walletClient required to send the transactions.
13
+ * @param route - The route that should be executed. Cannot be an active route.
14
+ * @param settings - An object containing settings and callbacks.
15
+ * @returns The executed route.
16
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
17
17
  */
18
- executeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
18
+ executeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
19
19
  /**
20
20
  * Resume the execution of a route that has been stopped or had an error while executing.
21
- * @param {Signer} signer - The signer required to send the transactions.
22
- * @param {Route} route - The route that is to be executed. Cannot be an active route.
23
- * @param {ExecutionSettings} settings - An object containing settings and callbacks.
24
- * @return {Promise<Route>} The executed route.
25
- * @throws {LifiError} Throws a LifiError if the execution fails.
21
+ * @param walletClient - The walletClient required to send the transactions.
22
+ * @param route - The route that is to be executed. Cannot be an active route.
23
+ * @param settings - An object containing settings and callbacks.
24
+ * @returns The executed route.
25
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
26
26
  */
27
- resumeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
27
+ resumeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
28
28
  private executeSteps;
29
29
  /**
30
30
  * Updates route execution to background or foreground state.
31
- * @param {Route} route - A route that is currently in execution.
32
- * @param {boolean} settings - An object with execution settings.
31
+ * @param route - A route that is currently in execution.
32
+ * @param settings - An object with execution settings.
33
33
  */
34
34
  updateRouteExecution: (route: Route, settings: Pick<ExecutionSettings, 'executeInBackground'>) => void;
35
35
  /**
36
36
  * Update the ExecutionSettings for an active route.
37
- * @param {ExecutionSettings} settings - An object with execution settings.
38
- * @param {Route} route - The active route that gets the new execution settings.
37
+ * @param settings - An object with execution settings.
38
+ * @param route - The active route that gets the new execution settings.
39
39
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
40
40
  */
41
41
  updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
42
- /**
43
- * Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
44
- * @param {Route} route - A route that is currently in execution.
45
- * @deprecated use updateRouteExecution instead.
46
- */
47
- moveExecutionToBackground: (route: Route) => void;
48
42
  /**
49
43
  * Stops the execution of an active route.
50
- * @param {Route} route - A route that is currently in execution.
51
- * @return {Route} The stopped route.
44
+ * @param route - A route that is currently in execution.
45
+ * @returns The stopped route.
52
46
  */
53
47
  stopExecution: (route: Route) => Route;
54
48
  /**
55
49
  * Get the list of active routes.
56
- * @return {Route[]} A list of routes.
50
+ * @returns A list of routes.
57
51
  */
58
52
  getActiveRoutes: () => Route[];
59
53
  /**
60
54
  * Return the current route information for given route. The route has to be active.
61
- * @param {Route} route - A route object.
62
- * @return {Route} The updated route.
55
+ * @param route - A route object.
56
+ * @returns The updated route.
63
57
  */
64
58
  getActiveRoute: (route: Route) => Route | undefined;
65
59
  }
@@ -1,21 +1,21 @@
1
1
  import ConfigService from '../services/ConfigService';
2
2
  import { ValidationError } from '../utils/errors';
3
- import { handlePreRestart } from '../utils/preRestart';
4
3
  import { StatusManager } from './StatusManager';
5
4
  import { StepExecutor } from './StepExecutor';
5
+ import { prepareRestart } from './prepareRestart';
6
6
  export class RouteExecutionManager {
7
7
  constructor(configUpdate) {
8
8
  this.executionDictionary = {};
9
9
  this.executionPromiseDictionary = {};
10
10
  /**
11
11
  * Execute a route.
12
- * @param {Signer} signer - The signer required to send the transactions.
13
- * @param {Route} route - The route that should be executed. Cannot be an active route.
14
- * @param {ExecutionSettings} settings - An object containing settings and callbacks.
15
- * @return {Promise<Route>} The executed route.
16
- * @throws {LifiError} Throws a LifiError if the execution fails.
12
+ * @param walletClient - The walletClient required to send the transactions.
13
+ * @param route - The route that should be executed. Cannot be an active route.
14
+ * @param settings - An object containing settings and callbacks.
15
+ * @returns The executed route.
16
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
17
17
  */
18
- this.executeRoute = async (signer, route, settings) => {
18
+ this.executeRoute = async (walletClient, route, settings) => {
19
19
  // Deep clone to prevent side effects
20
20
  const clonedRoute = structuredClone(route);
21
21
  let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
@@ -23,19 +23,19 @@ export class RouteExecutionManager {
23
23
  if (executionPromise) {
24
24
  return executionPromise;
25
25
  }
26
- executionPromise = this.executeSteps(signer, clonedRoute, settings);
26
+ executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
27
27
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
28
28
  return executionPromise;
29
29
  };
30
30
  /**
31
31
  * Resume the execution of a route that has been stopped or had an error while executing.
32
- * @param {Signer} signer - The signer required to send the transactions.
33
- * @param {Route} route - The route that is to be executed. Cannot be an active route.
34
- * @param {ExecutionSettings} settings - An object containing settings and callbacks.
35
- * @return {Promise<Route>} The executed route.
36
- * @throws {LifiError} Throws a LifiError if the execution fails.
32
+ * @param walletClient - The walletClient required to send the transactions.
33
+ * @param route - The route that is to be executed. Cannot be an active route.
34
+ * @param settings - An object containing settings and callbacks.
35
+ * @returns The executed route.
36
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
37
37
  */
38
- this.resumeRoute = async (signer, route, settings) => {
38
+ this.resumeRoute = async (walletClient, route, settings) => {
39
39
  // Deep clone to prevent side effects
40
40
  const clonedRoute = structuredClone(route);
41
41
  const execution = this.executionDictionary[clonedRoute.id];
@@ -50,12 +50,12 @@ export class RouteExecutionManager {
50
50
  return executionPromise ?? clonedRoute;
51
51
  }
52
52
  }
53
- await handlePreRestart(clonedRoute, signer);
54
- const executionPromise = this.executeSteps(signer, clonedRoute, settings);
53
+ await prepareRestart(clonedRoute, walletClient);
54
+ const executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
55
55
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
56
56
  return executionPromise;
57
57
  };
58
- this.executeSteps = async (signer, route, settings) => {
58
+ this.executeSteps = async (walletClient, route, settings) => {
59
59
  const config = this.configService.getConfig();
60
60
  const execution = {
61
61
  route,
@@ -91,7 +91,7 @@ export class RouteExecutionManager {
91
91
  execution.executors.push(stepExecutor);
92
92
  // Check if we want to execute this step in the background
93
93
  this.updateRouteExecution(route, execution.settings);
94
- const executedStep = await stepExecutor.executeStep(signer, step);
94
+ const executedStep = await stepExecutor.executeStep(walletClient, step);
95
95
  // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
96
96
  if (executedStep.execution?.status !== 'DONE') {
97
97
  this.stopExecution(route);
@@ -112,8 +112,8 @@ export class RouteExecutionManager {
112
112
  };
113
113
  /**
114
114
  * Updates route execution to background or foreground state.
115
- * @param {Route} route - A route that is currently in execution.
116
- * @param {boolean} settings - An object with execution settings.
115
+ * @param route - A route that is currently in execution.
116
+ * @param settings - An object with execution settings.
117
117
  */
118
118
  this.updateRouteExecution = (route, settings) => {
119
119
  const execution = this.executionDictionary[route.id];
@@ -134,8 +134,8 @@ export class RouteExecutionManager {
134
134
  };
135
135
  /**
136
136
  * Update the ExecutionSettings for an active route.
137
- * @param {ExecutionSettings} settings - An object with execution settings.
138
- * @param {Route} route - The active route that gets the new execution settings.
137
+ * @param settings - An object with execution settings.
138
+ * @param route - The active route that gets the new execution settings.
139
139
  * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
140
140
  */
141
141
  this.updateExecutionSettings = (settings, route) => {
@@ -149,28 +149,10 @@ export class RouteExecutionManager {
149
149
  ...settings,
150
150
  };
151
151
  };
152
- /**
153
- * Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
154
- * @param {Route} route - A route that is currently in execution.
155
- * @deprecated use updateRouteExecution instead.
156
- */
157
- this.moveExecutionToBackground = (route) => {
158
- const execution = this.executionDictionary[route.id];
159
- if (!execution) {
160
- return;
161
- }
162
- for (const executor of execution.executors) {
163
- executor.setInteraction({ allowInteraction: false, allowUpdates: true });
164
- }
165
- execution.settings = {
166
- ...execution.settings,
167
- executeInBackground: true,
168
- };
169
- };
170
152
  /**
171
153
  * Stops the execution of an active route.
172
- * @param {Route} route - A route that is currently in execution.
173
- * @return {Route} The stopped route.
154
+ * @param route - A route that is currently in execution.
155
+ * @returns The stopped route.
174
156
  */
175
157
  this.stopExecution = (route) => {
176
158
  const execution = this.executionDictionary[route.id];
@@ -189,7 +171,7 @@ export class RouteExecutionManager {
189
171
  };
190
172
  /**
191
173
  * Get the list of active routes.
192
- * @return {Route[]} A list of routes.
174
+ * @returns A list of routes.
193
175
  */
194
176
  this.getActiveRoutes = () => {
195
177
  return Object.values(this.executionDictionary)
@@ -198,8 +180,8 @@ export class RouteExecutionManager {
198
180
  };
199
181
  /**
200
182
  * Return the current route information for given route. The route has to be active.
201
- * @param {Route} route - A route object.
202
- * @return {Route} The updated route.
183
+ * @param route - A route object.
184
+ * @returns The updated route.
203
185
  */
204
186
  this.getActiveRoute = (route) => {
205
187
  return this.executionDictionary[route.id]?.route;
@@ -1,4 +1,4 @@
1
- import { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
1
+ import type { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
2
2
  interface Receipt {
3
3
  fromAmount?: string;
4
4
  toAmount?: string;
@@ -13,10 +13,10 @@ type InternalUpdateRouteCallback = (route: Route) => void;
13
13
  type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage' | 'multisigTxHash'>>;
14
14
  /**
15
15
  * Manages status updates of a route and provides various functions for tracking processes
16
- * @param {Route} route The route this StatusManger belongs to.
17
- * @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
18
- * @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
19
- * @return {StatusManager} An instance of StatusManager.
16
+ * @param {Route} route The route this StatusManger belongs to.
17
+ * @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
18
+ * @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
19
+ * @returns {StatusManager} An instance of StatusManager.
20
20
  */
21
21
  export declare class StatusManager {
22
22
  private readonly route;
@@ -26,40 +26,39 @@ export declare class StatusManager {
26
26
  constructor(route: Route, settings: InternalExecutionSettings, internalUpdateRouteCallback: InternalUpdateRouteCallback);
27
27
  /**
28
28
  * Initializes the execution object of a Step.
29
- * @param {LifiStep} step The current step in execution
30
- * @return {Execution} The initialized execution object for this step and a function to update this step
29
+ * @param step The current step in execution
30
+ * @returns The initialized execution object for this step and a function to update this step
31
31
  */
32
32
  initExecutionObject: (step: LifiStep) => Execution;
33
33
  /**
34
34
  * Updates the execution object of a Step.
35
- * @param {LifiStep} step The current step in execution
36
- * @param {Status} status The status for the execution
37
- * @param {Receipt} receipt Optional. Information about received tokens
38
- * @return {Step} The step with the updated execution object
35
+ * @param step The current step in execution
36
+ * @param status The status for the execution
37
+ * @param receipt Optional. Information about received tokens
38
+ * @returns The step with the updated execution object
39
39
  */
40
40
  updateExecution(step: LifiStep, status: Status, receipt?: Receipt): LifiStep;
41
41
  /**
42
42
  * Create and push a new process into the execution.
43
- * @param {ProcessType} type Type of the process. Used to identify already existing processes.
44
- * @param {LifiStep} step The step that should contain the new process.
45
- * @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
46
- * @return {Process}
43
+ * @param step The step that should contain the new process.
44
+ * @param type Type of the process. Used to identify already existing processes.
45
+ * @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
46
+ * @returns Returns process.
47
47
  */
48
48
  findOrCreateProcess: (step: LifiStep, type: ProcessType, status?: Status) => Process;
49
49
  /**
50
50
  * Update a process object.
51
- * @param {LifiStep} step The step where the process should be updated
52
- * @param {ProcessType} type The process type to update
53
- * @param {Status} status The status the process gets.
54
- * @param {object} [params] Additional parameters to append to the process.
55
- * @return {Process} The update process
51
+ * @param step The step where the process should be updated
52
+ * @param type The process type to update
53
+ * @param status The status the process gets.
54
+ * @param [params] Additional parameters to append to the process.
55
+ * @returns The update process
56
56
  */
57
57
  updateProcess: (step: LifiStep, type: ProcessType, status: Status, params?: OptionalParameters) => Process;
58
58
  /**
59
59
  * Remove a process from the execution
60
- * @param {LifiStep} step The step where the process should be removed from
61
- * @param {ProcessType} type The process type to remove
62
- * @return {void}
60
+ * @param step The step where the process should be removed from
61
+ * @param type The process type to remove
63
62
  */
64
63
  removeProcess: (step: LifiStep, type: ProcessType) => void;
65
64
  updateStepInRoute: (step: LifiStep) => LifiStep;
@@ -1,19 +1,19 @@
1
- import { emptyExecution, } from '../types';
1
+ import { emptyExecution } from '../types';
2
2
  import { getProcessMessage } from './utils';
3
3
  /**
4
4
  * Manages status updates of a route and provides various functions for tracking processes
5
- * @param {Route} route The route this StatusManger belongs to.
6
- * @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
7
- * @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
8
- * @return {StatusManager} An instance of StatusManager.
5
+ * @param {Route} route The route this StatusManger belongs to.
6
+ * @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
7
+ * @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
8
+ * @returns {StatusManager} An instance of StatusManager.
9
9
  */
10
10
  export class StatusManager {
11
11
  constructor(route, settings, internalUpdateRouteCallback) {
12
12
  this.shouldUpdate = true;
13
13
  /**
14
14
  * Initializes the execution object of a Step.
15
- * @param {LifiStep} step The current step in execution
16
- * @return {Execution} The initialized execution object for this step and a function to update this step
15
+ * @param step The current step in execution
16
+ * @returns The initialized execution object for this step and a function to update this step
17
17
  */
18
18
  this.initExecutionObject = (step) => {
19
19
  const currentExecution = step.execution || structuredClone(emptyExecution);
@@ -31,10 +31,10 @@ export class StatusManager {
31
31
  };
32
32
  /**
33
33
  * Create and push a new process into the execution.
34
- * @param {ProcessType} type Type of the process. Used to identify already existing processes.
35
- * @param {LifiStep} step The step that should contain the new process.
36
- * @param {Status} status By default created procces is set to the STARTED status. We can override new process with the needed status.
37
- * @return {Process}
34
+ * @param step The step that should contain the new process.
35
+ * @param type Type of the process. Used to identify already existing processes.
36
+ * @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
37
+ * @returns Returns process.
38
38
  */
39
39
  this.findOrCreateProcess = (step, type, status) => {
40
40
  if (!step.execution?.process) {
@@ -60,11 +60,11 @@ export class StatusManager {
60
60
  };
61
61
  /**
62
62
  * Update a process object.
63
- * @param {LifiStep} step The step where the process should be updated
64
- * @param {ProcessType} type The process type to update
65
- * @param {Status} status The status the process gets.
66
- * @param {object} [params] Additional parameters to append to the process.
67
- * @return {Process} The update process
63
+ * @param step The step where the process should be updated
64
+ * @param type The process type to update
65
+ * @param status The status the process gets.
66
+ * @param [params] Additional parameters to append to the process.
67
+ * @returns The update process
68
68
  */
69
69
  this.updateProcess = (step, type, status, params) => {
70
70
  if (!step.execution) {
@@ -112,9 +112,8 @@ export class StatusManager {
112
112
  };
113
113
  /**
114
114
  * Remove a process from the execution
115
- * @param {LifiStep} step The step where the process should be removed from
116
- * @param {ProcessType} type The process type to remove
117
- * @return {void}
115
+ * @param step The step where the process should be removed from
116
+ * @param type The process type to remove
118
117
  */
119
118
  this.removeProcess = (step, type) => {
120
119
  if (!step.execution) {
@@ -143,10 +142,10 @@ export class StatusManager {
143
142
  }
144
143
  /**
145
144
  * Updates the execution object of a Step.
146
- * @param {LifiStep} step The current step in execution
147
- * @param {Status} status The status for the execution
148
- * @param {Receipt} receipt Optional. Information about received tokens
149
- * @return {Step} The step with the updated execution object
145
+ * @param step The current step in execution
146
+ * @param status The status for the execution
147
+ * @param receipt Optional. Information about received tokens
148
+ * @returns The step with the updated execution object
150
149
  */
151
150
  updateExecution(step, status, receipt) {
152
151
  if (!step.execution) {