@lifi/sdk 2.2.3 → 3.0.0-alpha.2

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 +4 -2
  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 -31
  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 +4 -2
  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 -31
  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 +43 -40
  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
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareRestart = void 0;
4
+ const viem_1 = require("viem");
5
+ const errors_1 = require("../utils/errors");
6
+ const prepareRestart = async (route, walletClient) => {
7
+ for (let index = 0; index < route.steps.length; index++) {
8
+ const step = route.steps[index];
9
+ const stepHasFailed = step.execution?.status === 'FAILED';
10
+ if (stepHasFailed) {
11
+ await handleErrorType(walletClient, step);
12
+ deleteFailedProcesses(step);
13
+ deleteTransactionData(step);
14
+ }
15
+ }
16
+ };
17
+ exports.prepareRestart = prepareRestart;
18
+ const handleErrorType = async (walletClient, step) => {
19
+ const client = walletClient.extend(viem_1.publicActions);
20
+ const isGasLimitError = step.execution?.process.some((p) => p.error?.code === errors_1.LiFiErrorCode.GasLimitError);
21
+ const isGasPriceError = step.execution?.process.some((p) => p.error?.code === errors_1.LiFiErrorCode.TransactionUnderpriced);
22
+ const { transactionRequest } = step;
23
+ // if (isGasLimitError) {
24
+ // if (transactionRequest) {
25
+ // let gasLimit = transactionRequest.gasLimit
26
+ // try {
27
+ // gasLimit = await client.estimateGas(transactionRequest)
28
+ // } catch (error) {}
29
+ // if (gasLimit) {
30
+ // transactionRequest.gasLimit = BigNumber.from(
31
+ // `${(BigInt(gasLimit.toString()) * 125n) / 100n}`
32
+ // )
33
+ // }
34
+ // }
35
+ // step.estimate.gasCosts?.forEach(
36
+ // (gasCost) =>
37
+ // (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`)
38
+ // )
39
+ // }
40
+ // if (isGasPriceError) {
41
+ // if (transactionRequest) {
42
+ // let gasPrice = transactionRequest.gasPrice
43
+ // try {
44
+ // gasPrice = await client.getGasPrice()
45
+ // } catch (error) {}
46
+ // if (gasPrice) {
47
+ // transactionRequest.gasPrice = BigNumber.from(
48
+ // `${(BigInt(gasPrice.toString()) * 125n) / 100n}`
49
+ // )
50
+ // }
51
+ // }
52
+ // step.estimate.gasCosts?.forEach(
53
+ // (gasCost) =>
54
+ // (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`)
55
+ // )
56
+ // }
57
+ };
58
+ const deleteFailedProcesses = (step) => {
59
+ if (step.execution) {
60
+ step.execution.process = step.execution.process.filter((process) => process.status === 'DONE');
61
+ }
62
+ };
63
+ const deleteTransactionData = (step) => {
64
+ step.transactionRequest = undefined;
65
+ };
@@ -1,14 +1,14 @@
1
- import { StatusManager } from '.';
2
- import { InternalExecutionSettings, LifiStep } from '../types';
1
+ import type { InternalExecutionSettings, LifiStep } from '../types';
2
+ import type { StatusManager } from './StatusManager';
3
3
  /**
4
4
  * This method checks whether the new and updated Step meets the required exchange rate conditions.
5
5
  * If yes it returns the updated Step.
6
6
  * If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
7
- *
8
7
  * @param statusManager
9
8
  * @param oldStep
10
9
  * @param newStep
11
10
  * @param settings
12
11
  * @param allowUserInteraction
12
+ * @returns Return LifiStep
13
13
  */
14
14
  export declare const stepComparison: (statusManager: StatusManager, oldStep: LifiStep, newStep: LifiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LifiStep>;
@@ -7,12 +7,12 @@ const utils_1 = require("./utils");
7
7
  * This method checks whether the new and updated Step meets the required exchange rate conditions.
8
8
  * If yes it returns the updated Step.
9
9
  * If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
10
- *
11
10
  * @param statusManager
12
11
  * @param oldStep
13
12
  * @param newStep
14
13
  * @param settings
15
14
  * @param allowUserInteraction
15
+ * @returns Return LifiStep
16
16
  */
17
17
  const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
18
18
  // Check if changed exchange rate is in the range of slippage threshold
@@ -29,7 +29,7 @@ const stepComparison = async (statusManager, oldStep, newStep, settings, allowUs
29
29
  }
30
30
  if (!allowStepUpdate) {
31
31
  // The user declined the new exchange rate, so we are not going to proceed
32
- throw new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionCanceled, 'Exchange rate has changed!', `Transaction was not sent, your funds are still in your wallet.
32
+ throw new errors_1.TransactionError(errors_1.LiFiErrorCode.ExchangeRateUpdateCanceled, 'Exchange rate has changed!', `Transaction was not sent, your funds are still in your wallet.
33
33
  The exchange rate has changed and the previous estimation can not be fulfilled due to value loss.`);
34
34
  }
35
35
  return statusManager.updateStepInRoute(newStep);
@@ -1,16 +1,21 @@
1
- import { LifiStep } from '@lifi/types';
2
- import { Signer } from 'ethers';
3
- import { SwitchChainHook } from '../types';
4
- import { StatusManager } from './StatusManager';
1
+ import type { LifiStep } from '@lifi/types';
2
+ import type { WalletClient } from 'viem';
3
+ import type { SwitchChainHook } from '../types';
4
+ import type { StatusManager } from './StatusManager';
5
5
  /**
6
- * This method checks whether the signer is configured for the correct chain.
7
- * If yes it returns the signer.
6
+ * This method checks whether the wallet client is configured for the correct chain.
7
+ * If yes it returns the wallet clien.
8
8
  * If no and if user interaction is allowed it triggers the switchChainHook. If no user interaction is allowed it aborts.
9
9
  *
10
- * @param signer
10
+ * Account Type: local -
11
+ * We need to create and return a new WalletClient from the switchChainHook in order to continue execution on a new chain.
12
+ *
13
+ * Account Type: json-rpc -
14
+ * We can switch chain and return existing WalletClient from the switchChainHook in order to continue execution on a new chain.
15
+ * @param walletClient
11
16
  * @param statusManager
12
17
  * @param step
13
18
  * @param switchChainHook
14
19
  * @param allowUserInteraction
15
20
  */
16
- export declare const switchChain: (signer: Signer, statusManager: StatusManager, step: LifiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<Signer | undefined>;
21
+ export declare const switchChain: (walletClient: WalletClient, statusManager: StatusManager, step: LifiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<WalletClient | undefined>;
@@ -3,20 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.switchChain = void 0;
4
4
  const errors_1 = require("../utils/errors");
5
5
  /**
6
- * This method checks whether the signer is configured for the correct chain.
7
- * If yes it returns the signer.
6
+ * This method checks whether the wallet client is configured for the correct chain.
7
+ * If yes it returns the wallet clien.
8
8
  * If no and if user interaction is allowed it triggers the switchChainHook. If no user interaction is allowed it aborts.
9
9
  *
10
- * @param signer
10
+ * Account Type: local -
11
+ * We need to create and return a new WalletClient from the switchChainHook in order to continue execution on a new chain.
12
+ *
13
+ * Account Type: json-rpc -
14
+ * We can switch chain and return existing WalletClient from the switchChainHook in order to continue execution on a new chain.
15
+ * @param walletClient
11
16
  * @param statusManager
12
17
  * @param step
13
18
  * @param switchChainHook
14
19
  * @param allowUserInteraction
15
20
  */
16
- const switchChain = async (signer, statusManager, step, switchChainHook, allowUserInteraction) => {
21
+ const switchChain = async (walletClient, statusManager, step, switchChainHook, allowUserInteraction) => {
17
22
  // if we are already on the correct chain we can proceed directly
18
- if ((await signer.getChainId()) === step.action.fromChainId) {
19
- return signer;
23
+ if ((await walletClient.getChainId()) === step.action.fromChainId) {
24
+ return walletClient;
20
25
  }
21
26
  // -> set status message
22
27
  step.execution = statusManager.initExecutionObject(step);
@@ -26,20 +31,20 @@ const switchChain = async (signer, statusManager, step, switchChainHook, allowUs
26
31
  return;
27
32
  }
28
33
  try {
29
- const updatedSigner = await switchChainHook(step.action.fromChainId);
30
- const updatedChainId = await updatedSigner?.getChainId();
34
+ const updatedWalletClient = await switchChainHook(step.action.fromChainId);
35
+ const updatedChainId = await updatedWalletClient?.getChainId();
31
36
  if (updatedChainId !== step.action.fromChainId) {
32
- throw new errors_1.ProviderError(errors_1.LifiErrorCode.ChainSwitchError, 'Chain switch required.');
37
+ throw new errors_1.ProviderError(errors_1.LiFiErrorCode.ChainSwitchError, 'Chain switch required.');
33
38
  }
34
39
  switchProcess = statusManager.updateProcess(step, switchProcess.type, 'DONE');
35
40
  statusManager.updateExecution(step, 'PENDING');
36
- return updatedSigner;
41
+ return updatedWalletClient;
37
42
  }
38
43
  catch (error) {
39
44
  statusManager.updateProcess(step, switchProcess.type, 'FAILED', {
40
45
  error: {
41
46
  message: error.message,
42
- code: errors_1.LifiErrorCode.ChainSwitchError,
47
+ code: errors_1.LiFiErrorCode.ChainSwitchError,
43
48
  },
44
49
  });
45
50
  statusManager.updateExecution(step, 'FAILED');
@@ -1,6 +1,12 @@
1
- import { LifiStep, ProcessType, Status, StatusMessage, StatusResponse, Substatus } from '@lifi/types';
2
- import { StatusManager } from '..';
3
- export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LifiStep): Promise<StatusResponse>;
1
+ import type { LifiStep, ProcessType, Status, StatusMessage, Substatus } from '@lifi/types';
4
2
  export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
5
3
  export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
4
+ /**
5
+ * Used to check if changed exchange rate is in the range of slippage threshold.
6
+ * We use a slippage value as a threshold to trigger the rate change hook.
7
+ * This can result in almost doubled slippage for the user and need to be revisited.
8
+ * @param oldStep
9
+ * @param newStep
10
+ * @returns Boolean
11
+ */
6
12
  export declare function checkStepSlippageThreshold(oldStep: LifiStep, newStep: LifiStep): boolean;
@@ -1,61 +1,6 @@
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.checkStepSlippageThreshold = exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
- const ApiService_1 = __importDefault(require("../services/ApiService"));
9
- const errors_1 = require("../utils/errors");
10
- const utils_1 = require("../utils/utils");
11
- const TRANSACTION_HASH_OBSERVERS = {};
12
- async function waitForReceivingTransaction(txHash, statusManager, processType, step) {
13
- const getStatus = () => new Promise(async (resolve, reject) => {
14
- let statusResponse;
15
- try {
16
- statusResponse = await ApiService_1.default.getStatus({
17
- bridge: step.tool,
18
- fromChain: step.action.fromChainId,
19
- toChain: step.action.toChainId,
20
- txHash,
21
- });
22
- }
23
- catch (e) {
24
- console.debug('Fetching status from backend failed.', e);
25
- return resolve(undefined);
26
- }
27
- switch (statusResponse.status) {
28
- case 'DONE':
29
- return resolve(statusResponse);
30
- case 'PENDING':
31
- statusManager?.updateProcess(step, processType, 'PENDING', {
32
- substatus: statusResponse.substatus,
33
- substatusMessage: statusResponse.substatusMessage ||
34
- getSubstatusMessage(statusResponse.status, statusResponse.substatus),
35
- txLink: statusResponse.bridgeExplorerLink,
36
- });
37
- return resolve(undefined);
38
- case 'NOT_FOUND':
39
- return resolve(undefined);
40
- case 'FAILED':
41
- default:
42
- return reject();
43
- }
44
- });
45
- let status;
46
- if (txHash in TRANSACTION_HASH_OBSERVERS) {
47
- status = await TRANSACTION_HASH_OBSERVERS[txHash];
48
- }
49
- else {
50
- TRANSACTION_HASH_OBSERVERS[txHash] = (0, utils_1.repeatUntilDone)(getStatus, 5000);
51
- status = await TRANSACTION_HASH_OBSERVERS[txHash];
52
- }
53
- if (!status.receiving) {
54
- throw new errors_1.ServerError("Status doesn't contain receiving information.");
55
- }
56
- return status;
57
- }
58
- exports.waitForReceivingTransaction = waitForReceivingTransaction;
3
+ exports.checkStepSlippageThreshold = exports.getSubstatusMessage = exports.getProcessMessage = void 0;
59
4
  const processMessages = {
60
5
  TOKEN_ALLOWANCE: {
61
6
  STARTED: 'Setting token allowance.',
@@ -115,18 +60,26 @@ function getSubstatusMessage(status, substatus) {
115
60
  return message;
116
61
  }
117
62
  exports.getSubstatusMessage = getSubstatusMessage;
118
- // Used to check if changed exchange rate is in the range of slippage threshold
63
+ /**
64
+ * Used to check if changed exchange rate is in the range of slippage threshold.
65
+ * We use a slippage value as a threshold to trigger the rate change hook.
66
+ * This can result in almost doubled slippage for the user and need to be revisited.
67
+ * @param oldStep
68
+ * @param newStep
69
+ * @returns Boolean
70
+ */
119
71
  function checkStepSlippageThreshold(oldStep, newStep) {
120
- const setSlippage = new bignumber_js_1.default(oldStep.action.slippage);
121
- const oldEstimatedToAmount = new bignumber_js_1.default(oldStep.estimate.toAmountMin);
122
- const newEstimatedToAmount = new bignumber_js_1.default(newStep.estimate.toAmountMin);
123
- const amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
72
+ const setSlippage = oldStep.action.slippage;
73
+ const oldEstimatedToAmount = BigInt(oldStep.estimate.toAmountMin);
74
+ const newEstimatedToAmount = BigInt(newStep.estimate.toAmountMin);
75
+ const amountDifference = oldEstimatedToAmount - newEstimatedToAmount;
124
76
  // oldEstimatedToAmount can be 0 when we use conract calls
125
- let actualSlippage = new bignumber_js_1.default(0);
126
- if (oldEstimatedToAmount.gt(0)) {
127
- actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
77
+ let actualSlippage = 0;
78
+ if (oldEstimatedToAmount > 0) {
79
+ actualSlippage =
80
+ Number((amountDifference * 1000000000n) / oldEstimatedToAmount) /
81
+ 1000000000;
128
82
  }
129
- return (newEstimatedToAmount.gte(oldEstimatedToAmount) &&
130
- actualSlippage.lte(setSlippage));
83
+ return actualSlippage <= setSlippage;
131
84
  }
132
85
  exports.checkStepSlippageThreshold = checkStepSlippageThreshold;
@@ -0,0 +1,3 @@
1
+ import type { LifiStep, ProcessType, StatusResponse } from '@lifi/types';
2
+ import type { StatusManager } from '..';
3
+ export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LifiStep): Promise<StatusResponse>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.waitForReceivingTransaction = void 0;
7
+ const ApiService_1 = __importDefault(require("../services/ApiService"));
8
+ const errors_1 = require("../utils/errors");
9
+ const utils_1 = require("../utils/utils");
10
+ const utils_2 = require("./utils");
11
+ const TRANSACTION_HASH_OBSERVERS = {};
12
+ async function waitForReceivingTransaction(txHash, statusManager, processType, step) {
13
+ const getStatus = () => new Promise(async (resolve, reject) => {
14
+ let statusResponse;
15
+ try {
16
+ statusResponse = await ApiService_1.default.getStatus({
17
+ bridge: step.tool,
18
+ fromChain: step.action.fromChainId,
19
+ toChain: step.action.toChainId,
20
+ txHash,
21
+ });
22
+ }
23
+ catch (e) {
24
+ console.debug('Fetching status from backend failed.', e);
25
+ return resolve(undefined);
26
+ }
27
+ switch (statusResponse.status) {
28
+ case 'DONE':
29
+ return resolve(statusResponse);
30
+ case 'PENDING':
31
+ statusManager?.updateProcess(step, processType, 'PENDING', {
32
+ substatus: statusResponse.substatus,
33
+ substatusMessage: statusResponse.substatusMessage ||
34
+ (0, utils_2.getSubstatusMessage)(statusResponse.status, statusResponse.substatus),
35
+ txLink: statusResponse.bridgeExplorerLink,
36
+ });
37
+ return resolve(undefined);
38
+ case 'NOT_FOUND':
39
+ return resolve(undefined);
40
+ case 'FAILED':
41
+ default:
42
+ return reject();
43
+ }
44
+ });
45
+ let status;
46
+ if (txHash in TRANSACTION_HASH_OBSERVERS) {
47
+ status = await TRANSACTION_HASH_OBSERVERS[txHash];
48
+ }
49
+ else {
50
+ TRANSACTION_HASH_OBSERVERS[txHash] = (0, utils_1.repeatUntilDone)(getStatus, 5000);
51
+ status = await TRANSACTION_HASH_OBSERVERS[txHash];
52
+ }
53
+ if (!status.receiving) {
54
+ throw new errors_1.ServerError("Status doesn't contain receiving information.");
55
+ }
56
+ return status;
57
+ }
58
+ exports.waitForReceivingTransaction = waitForReceivingTransaction;
@@ -1,27 +1,17 @@
1
- import { LifiStep, Route, Token } from '@lifi/types';
2
- import { TenderlyResponse } from './types';
3
- /**
4
- * Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
5
- * @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
6
- * @return {(encryptedData: string) => Promise<any>} A function that decrypts data using EIP-1193 compliant wallet functions.
7
- */
8
- export declare const getEthereumDecryptionHook: (walletAddress: string) => (encryptedData: string) => Promise<string>;
9
- /**
10
- * Predefined hook that get the public encryption key of a user using EIP-1193 compliant wallet functions.
11
- * @param {string} walletAddress - The wallet address of the user.
12
- * @return {(walletAddress: string) => () => Promise<any>} A function that return the public encryption key using EIP-1193 compliant wallet functions.
13
- */
14
- export declare const getEthereumPublicKeyHook: (walletAddress: string) => () => Promise<string>;
1
+ import type { LifiStep, Route } from '@lifi/types';
2
+ import type { TenderlyResponse } from './types';
15
3
  /**
16
4
  * Returns a random number between min (inclusive) and max (inclusive)
5
+ * @param min - minimum number.
6
+ * @param max - maximum number.
7
+ * @returns - random number.
17
8
  */
18
9
  export declare const getRandomNumber: (min: number, max: number) => number;
19
- export declare const isSameToken: (tokenA: Token, tokenB: Token) => boolean;
20
10
  export declare const checkPackageUpdates: (packageName?: string, packageVersion?: string, disableCheck?: boolean) => Promise<void>;
21
11
  /**
22
12
  * Converts a quote to Route
23
- * @param {LifiStep} step - Step returned from the quote endpoint.
24
- * @return {Route} - The route to be executed.
13
+ * @param step - Step returned from the quote endpoint.
14
+ * @returns - The route to be executed.
25
15
  * @throws {ValidationError} Throws a ValidationError if the step has missing values.
26
16
  */
27
17
  export declare const convertQuoteToRoute: (step: LifiStep) => Route;
@@ -1,51 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchTxErrorDetails = exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
3
+ exports.fetchTxErrorDetails = exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.getRandomNumber = void 0;
4
4
  const request_1 = require("./request");
5
5
  const errors_1 = require("./utils/errors");
6
6
  const version_1 = require("./version");
7
- const ethereumRequest = async (method, params) => {
8
- // If ethereum.request() exists, the provider is probably EIP-1193 compliant.
9
- if (!ethereum?.request) {
10
- throw new Error('Provider not available.');
11
- }
12
- return ethereum.request({
13
- method,
14
- params,
15
- });
16
- };
17
- /**
18
- * Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
19
- * @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
20
- * @return {(encryptedData: string) => Promise<any>} A function that decrypts data using EIP-1193 compliant wallet functions.
21
- */
22
- const getEthereumDecryptionHook = (walletAddress) => {
23
- return (encryptedData) => {
24
- return ethereumRequest('eth_decrypt', [encryptedData, walletAddress]);
25
- };
26
- };
27
- exports.getEthereumDecryptionHook = getEthereumDecryptionHook;
28
- /**
29
- * Predefined hook that get the public encryption key of a user using EIP-1193 compliant wallet functions.
30
- * @param {string} walletAddress - The wallet address of the user.
31
- * @return {(walletAddress: string) => () => Promise<any>} A function that return the public encryption key using EIP-1193 compliant wallet functions.
32
- */
33
- const getEthereumPublicKeyHook = (walletAddress) => {
34
- return () => {
35
- return ethereumRequest('eth_getEncryptionPublicKey', [walletAddress]);
36
- };
37
- };
38
- exports.getEthereumPublicKeyHook = getEthereumPublicKeyHook;
39
7
  /**
40
8
  * Returns a random number between min (inclusive) and max (inclusive)
9
+ * @param min - minimum number.
10
+ * @param max - maximum number.
11
+ * @returns - random number.
41
12
  */
42
13
  const getRandomNumber = (min, max) => {
43
14
  return Math.floor(Math.random() * (max - min + 1) + min);
44
15
  };
45
16
  exports.getRandomNumber = getRandomNumber;
46
- const isSameToken = (tokenA, tokenB) => tokenA.chainId === tokenB.chainId &&
47
- tokenA.address.toLowerCase() === tokenB.address.toLowerCase();
48
- exports.isSameToken = isSameToken;
49
17
  function semverCompare(a, b) {
50
18
  if (a.startsWith(b + '-')) {
51
19
  return -1;
@@ -81,8 +49,8 @@ const checkPackageUpdates = async (packageName, packageVersion, disableCheck) =>
81
49
  exports.checkPackageUpdates = checkPackageUpdates;
82
50
  /**
83
51
  * Converts a quote to Route
84
- * @param {LifiStep} step - Step returned from the quote endpoint.
85
- * @return {Route} - The route to be executed.
52
+ * @param step - Step returned from the quote endpoint.
53
+ * @returns - The route to be executed.
86
54
  * @throws {ValidationError} Throws a ValidationError if the step has missing values.
87
55
  */
88
56
  const convertQuoteToRoute = (step) => {
@@ -51,7 +51,7 @@ const request = async (url, options = {
51
51
  }
52
52
  catch (error) {
53
53
  if (options.retries > 0 && error?.status === 500) {
54
- await (0, utils_1.sleep)(500);
54
+ await (0, utils_1.wait)(500);
55
55
  return (0, exports.request)(url, { ...options, retries: options.retries - 1 });
56
56
  }
57
57
  throw error;
@@ -1,5 +1,5 @@
1
- import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
2
- import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
1
+ import type { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
2
+ import type { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
3
3
  declare const _default: {
4
4
  getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
5
5
  getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
@@ -9,6 +9,8 @@ const errors_1 = require("../utils/errors");
9
9
  const parseError_1 = require("../utils/parseError");
10
10
  const ConfigService_1 = __importDefault(require("./ConfigService"));
11
11
  /**
12
+ * @param requestConfig
13
+ * @param options
12
14
  * @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
13
15
  */
14
16
  const getPossibilities = async (requestConfig, options) => {
@@ -279,10 +281,10 @@ const getAvailableConnections = async (connectionRequest) => {
279
281
  url.searchParams.append('fromToken', fromToken);
280
282
  }
281
283
  if (toChain) {
282
- url.searchParams.append('toChain', toChain);
284
+ url.searchParams.append('fromToken', toChain);
283
285
  }
284
286
  if (toToken) {
285
- url.searchParams.append('toToken', toToken);
287
+ url.searchParams.append('fromToken', toToken);
286
288
  }
287
289
  const connectionRequestArrayParams = [
288
290
  'allowBridges',
@@ -1,4 +1,4 @@
1
- import { ChainId, ExtendedChain } from '@lifi/types';
1
+ import type { ChainId, ExtendedChain } from '@lifi/types';
2
2
  export default class ChainsService {
3
3
  private static instance;
4
4
  private readonly loadingPromise;
@@ -1,4 +1,4 @@
1
- import { Chain, Config, ConfigUpdate } from '../types';
1
+ import type { Chain, Config, ConfigUpdate } from '../types';
2
2
  export default class ConfigService {
3
3
  private static instance;
4
4
  private readonly config;
@@ -46,8 +46,7 @@ class ConfigService {
46
46
  this.config.integrator;
47
47
  this.config.widgetVersion =
48
48
  configUpdate.widgetVersion || this.config.widgetVersion;
49
- this.config.multisigConfig =
50
- configUpdate.multisigConfig || this.config.multisigConfig;
49
+ this.config.multisig = configUpdate.multisigConfig || this.config.multisig;
51
50
  return this.config;
52
51
  };
53
52
  this.updateChains = (chains) => {
@@ -1,4 +1,4 @@
1
- import { LifiStep, RoutesRequest, StaticToken } from './types';
1
+ import type { LifiStep, RoutesRequest, StaticToken } from './types';
2
2
  export declare const isRoutesRequest: (routesRequest: RoutesRequest) => routesRequest is RoutesRequest;
3
3
  export declare const isStep: (step: LifiStep) => step is LifiStep;
4
4
  export declare const isToken: (token: StaticToken) => token is StaticToken;
@@ -0,0 +1,5 @@
1
+ import type { Abi } from 'viem';
2
+ export declare const approveAbi: Abi;
3
+ export declare const allowanceAbi: Abi;
4
+ export declare const getEthBalanceAbi: Abi;
5
+ export declare const balanceOfAbi: Abi;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.balanceOfAbi = exports.getEthBalanceAbi = exports.allowanceAbi = exports.approveAbi = void 0;
4
+ exports.approveAbi = [
5
+ {
6
+ name: 'approve',
7
+ inputs: [
8
+ { internalType: 'address', name: 'spender', type: 'address' },
9
+ { internalType: 'uint256', name: 'amount', type: 'uint256' },
10
+ ],
11
+ outputs: [{ internalType: 'bool', name: 'approved', type: 'bool' }],
12
+ stateMutability: 'nonpayable',
13
+ type: 'function',
14
+ },
15
+ ];
16
+ exports.allowanceAbi = [
17
+ {
18
+ name: 'allowance',
19
+ inputs: [
20
+ { internalType: 'address', name: 'owner', type: 'address' },
21
+ { internalType: 'address', name: 'spender', type: 'address' },
22
+ ],
23
+ outputs: [{ internalType: 'uint256', name: 'allowance', type: 'uint256' }],
24
+ stateMutability: 'view',
25
+ type: 'function',
26
+ },
27
+ ];
28
+ exports.getEthBalanceAbi = [
29
+ {
30
+ inputs: [{ name: '_owner', type: 'address' }],
31
+ name: 'getEthBalance',
32
+ outputs: [{ name: 'balance', type: 'uint256' }],
33
+ type: 'function',
34
+ stateMutability: 'view',
35
+ },
36
+ ];
37
+ exports.balanceOfAbi = [
38
+ {
39
+ inputs: [{ name: '_owner', type: 'address' }],
40
+ name: 'balanceOf',
41
+ outputs: [{ name: 'balance', type: 'uint256' }],
42
+ type: 'function',
43
+ stateMutability: 'view',
44
+ },
45
+ ];
@@ -1,4 +1,4 @@
1
1
  export * from '@lifi/types';
2
- export { ErrorCode, LifiError } from '../utils/errors';
3
- export * from './ERC20';
2
+ export { ErrorCode, LiFiError } from '../utils/errors';
3
+ export * from './abi';
4
4
  export * from './internal.types';
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.LifiError = void 0;
17
+ exports.LiFiError = void 0;
18
18
  __exportStar(require("@lifi/types"), exports);
19
19
  var errors_1 = require("../utils/errors");
20
- Object.defineProperty(exports, "LifiError", { enumerable: true, get: function () { return errors_1.LifiError; } });
21
- __exportStar(require("./ERC20"), exports);
20
+ Object.defineProperty(exports, "LiFiError", { enumerable: true, get: function () { return errors_1.LiFiError; } });
21
+ __exportStar(require("./abi"), exports);
22
22
  __exportStar(require("./internal.types"), exports);