@lifi/sdk 2.0.0-beta.13 → 2.0.0-beta.14

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 (164) hide show
  1. package/dist/cjs/{execution → src/execution}/RouteExecutionManager.js +1 -1
  2. package/dist/cjs/src/execution/RouteExecutionManager.unit.handlers.d.ts +1 -0
  3. package/dist/cjs/src/execution/RouteExecutionManager.unit.handlers.js +20 -0
  4. package/dist/cjs/src/execution/RouteExecutionManager.unit.mock.d.ts +80 -0
  5. package/dist/cjs/src/execution/RouteExecutionManager.unit.mock.js +76 -0
  6. package/dist/cjs/{execution → src/execution}/StepExecutionManager.js +6 -0
  7. package/dist/cjs/src/utils/preRestart.d.ts +3 -0
  8. package/dist/cjs/{utils → src/utils}/preRestart.js +14 -3
  9. package/dist/cjs/src/version.d.ts +2 -0
  10. package/dist/cjs/{version.js → src/version.js} +1 -1
  11. package/dist/cjs/test/fixtures.d.ts +7 -0
  12. package/dist/cjs/test/fixtures.js +157 -0
  13. package/dist/{execution → src/execution}/RouteExecutionManager.js +1 -1
  14. package/dist/src/execution/RouteExecutionManager.unit.handlers.d.ts +1 -0
  15. package/dist/src/execution/RouteExecutionManager.unit.handlers.js +14 -0
  16. package/dist/src/execution/RouteExecutionManager.unit.mock.d.ts +80 -0
  17. package/dist/src/execution/RouteExecutionManager.unit.mock.js +72 -0
  18. package/dist/{execution → src/execution}/StepExecutionManager.js +6 -0
  19. package/dist/src/utils/preRestart.d.ts +3 -0
  20. package/dist/{utils → src/utils}/preRestart.js +14 -3
  21. package/dist/src/version.d.ts +2 -0
  22. package/dist/src/version.js +2 -0
  23. package/dist/test/fixtures.d.ts +7 -0
  24. package/dist/test/fixtures.js +152 -0
  25. package/package.json +8 -8
  26. package/dist/cjs/utils/preRestart.d.ts +0 -2
  27. package/dist/cjs/version.d.ts +0 -2
  28. package/dist/utils/preRestart.d.ts +0 -2
  29. package/dist/version.d.ts +0 -2
  30. package/dist/version.js +0 -2
  31. /package/dist/{LiFi.d.ts → cjs/src/LiFi.d.ts} +0 -0
  32. /package/dist/cjs/{LiFi.js → src/LiFi.js} +0 -0
  33. /package/dist/{allowance → cjs/src/allowance}/checkAllowance.d.ts +0 -0
  34. /package/dist/cjs/{allowance → src/allowance}/checkAllowance.js +0 -0
  35. /package/dist/{allowance → cjs/src/allowance}/index.d.ts +0 -0
  36. /package/dist/cjs/{allowance → src/allowance}/index.js +0 -0
  37. /package/dist/{allowance → cjs/src/allowance}/tokenApproval.d.ts +0 -0
  38. /package/dist/cjs/{allowance → src/allowance}/tokenApproval.js +0 -0
  39. /package/dist/{allowance → cjs/src/allowance}/utils.d.ts +0 -0
  40. /package/dist/cjs/{allowance → src/allowance}/utils.js +0 -0
  41. /package/dist/{balance → cjs/src/balance}/checkBalance.d.ts +0 -0
  42. /package/dist/cjs/{balance → src/balance}/checkBalance.js +0 -0
  43. /package/dist/{balance → cjs/src/balance}/getTokenBalance.d.ts +0 -0
  44. /package/dist/cjs/{balance → src/balance}/getTokenBalance.js +0 -0
  45. /package/dist/{balance → cjs/src/balance}/index.d.ts +0 -0
  46. /package/dist/cjs/{balance → src/balance}/index.js +0 -0
  47. /package/dist/{balance → cjs/src/balance}/utils.d.ts +0 -0
  48. /package/dist/cjs/{balance → src/balance}/utils.js +0 -0
  49. /package/dist/cjs/{connectors.d.ts → src/connectors.d.ts} +0 -0
  50. /package/dist/cjs/{connectors.js → src/connectors.js} +0 -0
  51. /package/dist/cjs/{execution → src/execution}/RouteExecutionManager.d.ts +0 -0
  52. /package/dist/cjs/{execution → src/execution}/StatusManager.d.ts +0 -0
  53. /package/dist/cjs/{execution → src/execution}/StatusManager.js +0 -0
  54. /package/dist/cjs/{execution → src/execution}/StepExecutionManager.d.ts +0 -0
  55. /package/dist/cjs/{execution → src/execution}/StepExecutor.d.ts +0 -0
  56. /package/dist/cjs/{execution → src/execution}/StepExecutor.js +0 -0
  57. /package/dist/cjs/{execution → src/execution}/index.d.ts +0 -0
  58. /package/dist/cjs/{execution → src/execution}/index.js +0 -0
  59. /package/dist/cjs/{execution → src/execution}/stepComparison.d.ts +0 -0
  60. /package/dist/cjs/{execution → src/execution}/stepComparison.js +0 -0
  61. /package/dist/cjs/{execution → src/execution}/switchChain.d.ts +0 -0
  62. /package/dist/cjs/{execution → src/execution}/switchChain.js +0 -0
  63. /package/dist/cjs/{execution → src/execution}/utils.d.ts +0 -0
  64. /package/dist/cjs/{execution → src/execution}/utils.js +0 -0
  65. /package/dist/cjs/{helpers.d.ts → src/helpers.d.ts} +0 -0
  66. /package/dist/cjs/{helpers.js → src/helpers.js} +0 -0
  67. /package/dist/cjs/{index.d.ts → src/index.d.ts} +0 -0
  68. /package/dist/cjs/{index.js → src/index.js} +0 -0
  69. /package/dist/cjs/{request.d.ts → src/request.d.ts} +0 -0
  70. /package/dist/cjs/{request.js → src/request.js} +0 -0
  71. /package/dist/cjs/{services → src/services}/ApiService.d.ts +0 -0
  72. /package/dist/cjs/{services → src/services}/ApiService.js +0 -0
  73. /package/dist/cjs/{services → src/services}/ApiService.unit.handlers.d.ts +0 -0
  74. /package/dist/cjs/{services → src/services}/ApiService.unit.handlers.js +0 -0
  75. /package/dist/cjs/{services → src/services}/ChainsService.d.ts +0 -0
  76. /package/dist/cjs/{services → src/services}/ChainsService.js +0 -0
  77. /package/dist/cjs/{services → src/services}/ConfigService.d.ts +0 -0
  78. /package/dist/cjs/{services → src/services}/ConfigService.js +0 -0
  79. /package/dist/cjs/{typeguards.d.ts → src/typeguards.d.ts} +0 -0
  80. /package/dist/cjs/{typeguards.js → src/typeguards.js} +0 -0
  81. /package/dist/cjs/{types → src/types}/ERC20.d.ts +0 -0
  82. /package/dist/cjs/{types → src/types}/ERC20.js +0 -0
  83. /package/dist/cjs/{types → src/types}/index.d.ts +0 -0
  84. /package/dist/cjs/{types → src/types}/index.js +0 -0
  85. /package/dist/cjs/{types → src/types}/internal.types.d.ts +0 -0
  86. /package/dist/cjs/{types → src/types}/internal.types.js +0 -0
  87. /package/dist/cjs/{utils → src/utils}/errors.d.ts +0 -0
  88. /package/dist/cjs/{utils → src/utils}/errors.js +0 -0
  89. /package/dist/cjs/{utils → src/utils}/getProvider.d.ts +0 -0
  90. /package/dist/cjs/{utils → src/utils}/getProvider.js +0 -0
  91. /package/dist/cjs/{utils → src/utils}/multicall.d.ts +0 -0
  92. /package/dist/cjs/{utils → src/utils}/multicall.js +0 -0
  93. /package/dist/cjs/{utils → src/utils}/multicallAbi.json +0 -0
  94. /package/dist/cjs/{utils → src/utils}/parseError.d.ts +0 -0
  95. /package/dist/cjs/{utils → src/utils}/parseError.js +0 -0
  96. /package/dist/cjs/{utils → src/utils}/utils.d.ts +0 -0
  97. /package/dist/cjs/{utils → src/utils}/utils.js +0 -0
  98. /package/dist/{cjs → src}/LiFi.d.ts +0 -0
  99. /package/dist/{LiFi.js → src/LiFi.js} +0 -0
  100. /package/dist/{cjs → src}/allowance/checkAllowance.d.ts +0 -0
  101. /package/dist/{allowance → src/allowance}/checkAllowance.js +0 -0
  102. /package/dist/{cjs → src}/allowance/index.d.ts +0 -0
  103. /package/dist/{allowance → src/allowance}/index.js +0 -0
  104. /package/dist/{cjs → src}/allowance/tokenApproval.d.ts +0 -0
  105. /package/dist/{allowance → src/allowance}/tokenApproval.js +0 -0
  106. /package/dist/{cjs → src}/allowance/utils.d.ts +0 -0
  107. /package/dist/{allowance → src/allowance}/utils.js +0 -0
  108. /package/dist/{cjs → src}/balance/checkBalance.d.ts +0 -0
  109. /package/dist/{balance → src/balance}/checkBalance.js +0 -0
  110. /package/dist/{cjs → src}/balance/getTokenBalance.d.ts +0 -0
  111. /package/dist/{balance → src/balance}/getTokenBalance.js +0 -0
  112. /package/dist/{cjs → src}/balance/index.d.ts +0 -0
  113. /package/dist/{balance → src/balance}/index.js +0 -0
  114. /package/dist/{cjs → src}/balance/utils.d.ts +0 -0
  115. /package/dist/{balance → src/balance}/utils.js +0 -0
  116. /package/dist/{connectors.d.ts → src/connectors.d.ts} +0 -0
  117. /package/dist/{connectors.js → src/connectors.js} +0 -0
  118. /package/dist/{execution → src/execution}/RouteExecutionManager.d.ts +0 -0
  119. /package/dist/{execution → src/execution}/StatusManager.d.ts +0 -0
  120. /package/dist/{execution → src/execution}/StatusManager.js +0 -0
  121. /package/dist/{execution → src/execution}/StepExecutionManager.d.ts +0 -0
  122. /package/dist/{execution → src/execution}/StepExecutor.d.ts +0 -0
  123. /package/dist/{execution → src/execution}/StepExecutor.js +0 -0
  124. /package/dist/{execution → src/execution}/index.d.ts +0 -0
  125. /package/dist/{execution → src/execution}/index.js +0 -0
  126. /package/dist/{execution → src/execution}/stepComparison.d.ts +0 -0
  127. /package/dist/{execution → src/execution}/stepComparison.js +0 -0
  128. /package/dist/{execution → src/execution}/switchChain.d.ts +0 -0
  129. /package/dist/{execution → src/execution}/switchChain.js +0 -0
  130. /package/dist/{execution → src/execution}/utils.d.ts +0 -0
  131. /package/dist/{execution → src/execution}/utils.js +0 -0
  132. /package/dist/{helpers.d.ts → src/helpers.d.ts} +0 -0
  133. /package/dist/{helpers.js → src/helpers.js} +0 -0
  134. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  135. /package/dist/{index.js → src/index.js} +0 -0
  136. /package/dist/{request.d.ts → src/request.d.ts} +0 -0
  137. /package/dist/{request.js → src/request.js} +0 -0
  138. /package/dist/{services → src/services}/ApiService.d.ts +0 -0
  139. /package/dist/{services → src/services}/ApiService.js +0 -0
  140. /package/dist/{services → src/services}/ApiService.unit.handlers.d.ts +0 -0
  141. /package/dist/{services → src/services}/ApiService.unit.handlers.js +0 -0
  142. /package/dist/{services → src/services}/ChainsService.d.ts +0 -0
  143. /package/dist/{services → src/services}/ChainsService.js +0 -0
  144. /package/dist/{services → src/services}/ConfigService.d.ts +0 -0
  145. /package/dist/{services → src/services}/ConfigService.js +0 -0
  146. /package/dist/{typeguards.d.ts → src/typeguards.d.ts} +0 -0
  147. /package/dist/{typeguards.js → src/typeguards.js} +0 -0
  148. /package/dist/{types → src/types}/ERC20.d.ts +0 -0
  149. /package/dist/{types → src/types}/ERC20.js +0 -0
  150. /package/dist/{types → src/types}/index.d.ts +0 -0
  151. /package/dist/{types → src/types}/index.js +0 -0
  152. /package/dist/{types → src/types}/internal.types.d.ts +0 -0
  153. /package/dist/{types → src/types}/internal.types.js +0 -0
  154. /package/dist/{utils → src/utils}/errors.d.ts +0 -0
  155. /package/dist/{utils → src/utils}/errors.js +0 -0
  156. /package/dist/{utils → src/utils}/getProvider.d.ts +0 -0
  157. /package/dist/{utils → src/utils}/getProvider.js +0 -0
  158. /package/dist/{utils → src/utils}/multicall.d.ts +0 -0
  159. /package/dist/{utils → src/utils}/multicall.js +0 -0
  160. /package/dist/{utils → src/utils}/multicallAbi.json +0 -0
  161. /package/dist/{utils → src/utils}/parseError.d.ts +0 -0
  162. /package/dist/{utils → src/utils}/parseError.js +0 -0
  163. /package/dist/{utils → src/utils}/utils.d.ts +0 -0
  164. /package/dist/{utils → src/utils}/utils.js +0 -0
@@ -56,7 +56,7 @@ class RouteExecutionManager {
56
56
  return executionPromise ?? clonedRoute;
57
57
  }
58
58
  }
59
- (0, preRestart_1.handlePreRestart)(clonedRoute);
59
+ await (0, preRestart_1.handlePreRestart)(clonedRoute, signer);
60
60
  const executionPromise = this.executeSteps(signer, clonedRoute, settings);
61
61
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
62
62
  return executionPromise;
@@ -0,0 +1 @@
1
+ export declare const lifiHandlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
@@ -0,0 +1,20 @@
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.lifiHandlers = void 0;
7
+ const msw_1 = require("msw");
8
+ const RouteExecutionManager_unit_mock_1 = require("./RouteExecutionManager.unit.mock");
9
+ const ConfigService_1 = __importDefault(require("../services/ConfigService"));
10
+ const fixtures_1 = require("../../test/fixtures");
11
+ const config = ConfigService_1.default.getInstance().getConfig();
12
+ exports.lifiHandlers = [
13
+ msw_1.rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (_, response, context) => response(context.status(200), context.json((0, RouteExecutionManager_unit_mock_1.mockStepTransactionWithTxRequest)((0, fixtures_1.buildStepObject)({
14
+ includingExecution: true,
15
+ }))))),
16
+ msw_1.rest.get(`${config.apiUrl}/chains`, async (_, response, context) => response(context.status(200), context.json({
17
+ chains: RouteExecutionManager_unit_mock_1.mockChainsResponse,
18
+ }))),
19
+ msw_1.rest.get(`${config.apiUrl}/status`, async (_, response, context) => response(context.status(200), context.json(RouteExecutionManager_unit_mock_1.mockStatus))),
20
+ ];
@@ -0,0 +1,80 @@
1
+ import { LifiStep } from '@lifi/types';
2
+ export declare const mockChainsResponse: {
3
+ key: string;
4
+ chainType: string;
5
+ name: string;
6
+ coin: string;
7
+ id: number;
8
+ mainnet: boolean;
9
+ logoURI: string;
10
+ tokenlistUrl: string;
11
+ faucetUrls: string[];
12
+ multicallAddress: string;
13
+ metamask: {
14
+ chainId: string;
15
+ blockExplorerUrls: string[];
16
+ chainName: string;
17
+ nativeCurrency: {
18
+ name: string;
19
+ symbol: string;
20
+ decimals: number;
21
+ };
22
+ rpcUrls: string[];
23
+ };
24
+ nativeToken: {
25
+ address: string;
26
+ chainId: number;
27
+ symbol: string;
28
+ decimals: number;
29
+ name: string;
30
+ priceUSD: string;
31
+ logoURI: string;
32
+ coinKey: string;
33
+ };
34
+ }[];
35
+ export declare const mockTransactionRequest: {
36
+ transactionRequest: {
37
+ data: string;
38
+ to: string;
39
+ value: string;
40
+ from: string;
41
+ chainId: number;
42
+ gasPrice: string;
43
+ gasLimit: string;
44
+ };
45
+ };
46
+ export declare const mockStatus: {
47
+ status: string;
48
+ receiving: boolean;
49
+ sending: {
50
+ amount: string;
51
+ gasAmount: string;
52
+ gasAmountUSD: string;
53
+ gasPrice: string;
54
+ gasToken: string;
55
+ gasUsed: string;
56
+ };
57
+ };
58
+ export declare const mockStepTransactionWithTxRequest: (step?: LifiStep) => {
59
+ transactionRequest: {
60
+ transactionRequest: {
61
+ data: string;
62
+ to: string;
63
+ value: string;
64
+ from: string;
65
+ chainId: number;
66
+ gasPrice: string;
67
+ gasLimit: string;
68
+ };
69
+ };
70
+ type: "lifi";
71
+ includedSteps: import("@lifi/types").Step[];
72
+ id: string;
73
+ referrer?: string | undefined;
74
+ action: import("@lifi/types").Action | import("@lifi/types").CallAction;
75
+ estimate: import("@lifi/types").Estimate;
76
+ tool: string;
77
+ toolDetails: Pick<import("@lifi/types").Bridge | import("@lifi/types").ExchangeAggregator | import("@lifi/types").Exchange, "key" | "name" | "logoURI">;
78
+ integrator?: string | undefined;
79
+ execution?: import("@lifi/types").Execution | undefined;
80
+ };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockStepTransactionWithTxRequest = exports.mockStatus = exports.mockTransactionRequest = exports.mockChainsResponse = void 0;
4
+ const fixtures_1 = require("../../test/fixtures");
5
+ exports.mockChainsResponse = [
6
+ {
7
+ key: 'pol',
8
+ chainType: 'EVM',
9
+ name: 'Polygon',
10
+ coin: 'MATIC',
11
+ id: 137,
12
+ mainnet: true,
13
+ logoURI: 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/polygon.svg',
14
+ tokenlistUrl: 'https://unpkg.com/quickswap-default-token-list@1.0.71/build/quickswap-default.tokenlist.json',
15
+ faucetUrls: ['https://stakely.io/faucet/polygon-matic'],
16
+ multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
17
+ metamask: {
18
+ chainId: '0x89',
19
+ blockExplorerUrls: [
20
+ 'https://polygonscan.com/',
21
+ 'https://explorer-mainnet.maticvigil.com/',
22
+ ],
23
+ chainName: 'Matic(Polygon) Mainnet',
24
+ nativeCurrency: {
25
+ name: 'MATIC',
26
+ symbol: 'MATIC',
27
+ decimals: 18,
28
+ },
29
+ rpcUrls: [
30
+ 'https://polygon-rpc.com/',
31
+ 'https://rpc-mainnet.maticvigil.com/',
32
+ ],
33
+ },
34
+ nativeToken: {
35
+ address: '0x0000000000000000000000000000000000000000',
36
+ chainId: 137,
37
+ symbol: 'MATIC',
38
+ decimals: 18,
39
+ name: 'MATIC',
40
+ priceUSD: '0.899628',
41
+ logoURI: 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
42
+ coinKey: 'MATIC',
43
+ },
44
+ },
45
+ ];
46
+ exports.mockTransactionRequest = {
47
+ transactionRequest: {
48
+ // eslint-disable-next-line max-len
49
+ data: '0xdata',
50
+ to: '0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE',
51
+ value: '0x0600830dbc7f5bf7',
52
+ from: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
53
+ chainId: 137,
54
+ gasPrice: '0x27c01c1727',
55
+ gasLimit: '682701',
56
+ },
57
+ };
58
+ exports.mockStatus = {
59
+ status: 'DONE',
60
+ receiving: true,
61
+ sending: {
62
+ amount: '123',
63
+ gasAmount: '123',
64
+ gasAmountUSD: '123',
65
+ gasPrice: '123',
66
+ gasToken: '123',
67
+ gasUsed: '123',
68
+ },
69
+ };
70
+ const mockStepTransactionWithTxRequest = (step = (0, fixtures_1.buildStepObject)({
71
+ includingExecution: false,
72
+ })) => ({
73
+ ...step,
74
+ transactionRequest: exports.mockTransactionRequest,
75
+ });
76
+ exports.mockStepTransactionWithTxRequest = mockStepTransactionWithTxRequest;
@@ -89,6 +89,12 @@ class StepExecutionManager {
89
89
  customConfig.maxPriorityFeePerGas;
90
90
  transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
91
91
  }
92
+ else {
93
+ const estimatedGasLimit = await signer.estimateGas(transactionRequest);
94
+ if (estimatedGasLimit) {
95
+ transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
96
+ }
97
+ }
92
98
  // Submit the transaction
93
99
  transaction = await signer.sendTransaction(transactionRequest);
94
100
  // STEP 4: Wait for the transaction
@@ -0,0 +1,3 @@
1
+ import { Signer } from 'ethers';
2
+ import { Route } from '../types';
3
+ export declare const handlePreRestart: (route: Route, signer: Signer) => Promise<void>;
@@ -2,21 +2,32 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePreRestart = void 0;
4
4
  const errors_1 = require("./errors");
5
- const handlePreRestart = (route) => {
5
+ const handlePreRestart = async (route, signer) => {
6
6
  for (let index = 0; index < route.steps.length; index++) {
7
7
  const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
8
8
  if (stepHasFailed) {
9
- handleErrorType(route, index);
9
+ await handleErrorType(route, index, signer);
10
10
  deleteFailedProcesses(route, index);
11
11
  deleteTransactionData(route, index);
12
12
  }
13
13
  }
14
14
  };
15
15
  exports.handlePreRestart = handlePreRestart;
16
- const handleErrorType = (route, index) => {
16
+ const handleErrorType = async (route, index, signer) => {
17
17
  const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.GasLimitError);
18
18
  const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.TransactionUnderpriced);
19
+ const { transactionRequest } = route.steps[index];
19
20
  if (isGasLimitError) {
21
+ if (transactionRequest) {
22
+ let gasLimit = transactionRequest.gasLimit;
23
+ try {
24
+ gasLimit = await signer.estimateGas(transactionRequest);
25
+ }
26
+ catch (error) { }
27
+ if (gasLimit) {
28
+ transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
29
+ }
30
+ }
20
31
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
21
32
  }
22
33
  if (isGasPriceError) {
@@ -0,0 +1,2 @@
1
+ export declare const name = "@lifi/sdk";
2
+ export declare const version = "2.0.0-beta.14";
@@ -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.0.0-beta.13';
5
+ exports.version = '2.0.0-beta.14';
@@ -0,0 +1,7 @@
1
+ import { LifiStep, Route } from '@lifi/types';
2
+ export declare const buildStepObject: ({ includingExecution, }: {
3
+ includingExecution?: boolean | undefined;
4
+ }) => LifiStep;
5
+ export declare const buildRouteObject: ({ step, }: {
6
+ step?: LifiStep | undefined;
7
+ }) => Route;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ // This file holds generator functions to create objects for testing purposes
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.buildRouteObject = exports.buildStepObject = void 0;
5
+ const types_1 = require("@lifi/types");
6
+ const SOME_TOKEN = {
7
+ ...(0, types_1.findDefaultToken)(types_1.CoinKey.USDC, types_1.ChainId.DAI),
8
+ priceUSD: '',
9
+ };
10
+ const SOME_OTHER_TOKEN = {
11
+ ...(0, types_1.findDefaultToken)(types_1.CoinKey.USDT, types_1.ChainId.DAI),
12
+ priceUSD: '',
13
+ };
14
+ const SOME_DATE = new Date('2021-04-10').getTime();
15
+ const buildStepObject = ({ includingExecution = true, }) => ({
16
+ id: '8d3a0474-4ee3-4a7a-90c7-2a2264b7f3a9',
17
+ type: 'lifi',
18
+ tool: '1inch',
19
+ toolDetails: {
20
+ key: '1inch',
21
+ name: '1inch',
22
+ logoURI: 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/oneinch.png',
23
+ },
24
+ action: {
25
+ fromChainId: 137,
26
+ toChainId: 137,
27
+ fromToken: SOME_TOKEN,
28
+ toToken: SOME_OTHER_TOKEN,
29
+ fromAmount: '1000000',
30
+ slippage: 0.03,
31
+ fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
32
+ toAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
33
+ },
34
+ estimate: {
35
+ fromAmount: '1000000',
36
+ fromAmountUSD: '100',
37
+ toAmount: '260982615655554',
38
+ toAmountUSD: '26098',
39
+ toAmountMin: '253153137185887',
40
+ approvalAddress: '0x11111112542d85b3ef69ae05771c2dccff4faa26',
41
+ executionDuration: 300,
42
+ tool: '1inch',
43
+ },
44
+ includedSteps: [
45
+ {
46
+ id: 'f8474598-a553-4643-bbd1-bf8c77e679b3',
47
+ type: 'swap',
48
+ action: {
49
+ fromChainId: 137,
50
+ fromAmount: '5000000000000000000',
51
+ fromToken: {
52
+ address: '0x0000000000000000000000000000000000000000',
53
+ chainId: 137,
54
+ symbol: 'MATIC',
55
+ decimals: 18,
56
+ name: 'MATIC',
57
+ priceUSD: '1.124763',
58
+ logoURI: 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
59
+ coinKey: types_1.CoinKey.MATIC,
60
+ },
61
+ toChainId: 137,
62
+ toToken: {
63
+ address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
64
+ chainId: 137,
65
+ symbol: 'USDT',
66
+ decimals: 6,
67
+ name: '(PoS) Tether USD',
68
+ priceUSD: '1.00081',
69
+ logoURI: 'https://static.debank.com/image/coin/logo_url/usdt/23af7472292cb41dc39b3f1146ead0fe.png',
70
+ coinKey: types_1.CoinKey.USDT,
71
+ },
72
+ slippage: 0.005,
73
+ },
74
+ estimate: {
75
+ tool: '1inch',
76
+ fromAmount: '5000000000000000000',
77
+ toAmount: '5617317',
78
+ toAmountMin: '5589230',
79
+ approvalAddress: '0x1111111254eeb25477b68fb85ed929f73a960582',
80
+ executionDuration: 30,
81
+ feeCosts: [],
82
+ gasCosts: [
83
+ {
84
+ type: 'SEND',
85
+ price: '149725515512',
86
+ estimate: '258059',
87
+ limit: '344079',
88
+ amount: '51517405651853448',
89
+ amountUSD: '0.06',
90
+ token: {
91
+ address: '0x0000000000000000000000000000000000000000',
92
+ chainId: 137,
93
+ symbol: 'MATIC',
94
+ decimals: 18,
95
+ name: 'MATIC',
96
+ priceUSD: '1.124763',
97
+ logoURI: 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
98
+ coinKey: types_1.CoinKey.MATIC,
99
+ },
100
+ },
101
+ ],
102
+ },
103
+ tool: '1inch',
104
+ toolDetails: {
105
+ key: '1inch',
106
+ name: '1inch',
107
+ logoURI: 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/oneinch.png',
108
+ },
109
+ },
110
+ ],
111
+ execution: includingExecution
112
+ ? {
113
+ status: 'PENDING',
114
+ process: [
115
+ {
116
+ type: 'TOKEN_ALLOWANCE',
117
+ startedAt: SOME_DATE,
118
+ message: 'Somethings done',
119
+ status: 'DONE',
120
+ doneAt: SOME_DATE + 10,
121
+ txHash: '0x11111112542d85b3ef69ae05771c2dccff4faa26',
122
+ txLink: 'https://example.com',
123
+ },
124
+ {
125
+ type: 'SWAP',
126
+ startedAt: SOME_DATE + 20,
127
+ message: 'Somethings pending',
128
+ status: 'PENDING',
129
+ },
130
+ ],
131
+ fromAmount: '1000000',
132
+ toAmount: '261490494702370',
133
+ }
134
+ : undefined,
135
+ });
136
+ exports.buildStepObject = buildStepObject;
137
+ const buildRouteObject = ({ step = (0, exports.buildStepObject)({}), }) => ({
138
+ id: '0x433df53dbf6dbd7b946fc4f3b501c3ff32957d77d96c9d5ba1805b01eb6461cc',
139
+ fromChainId: 137,
140
+ fromAmountUSD: '1.00',
141
+ fromAmount: '1000000',
142
+ fromToken: SOME_TOKEN,
143
+ fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
144
+ toChainId: 137,
145
+ toAmountUSD: '1.00',
146
+ toAmount: '260982615655554',
147
+ toAmountMin: '253153137185887',
148
+ toToken: SOME_OTHER_TOKEN,
149
+ toAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
150
+ gasCostUSD: '0.01',
151
+ steps: [step],
152
+ insurance: {
153
+ feeAmountUsd: '0',
154
+ state: 'NOT_INSURABLE',
155
+ },
156
+ });
157
+ exports.buildRouteObject = buildRouteObject;
@@ -50,7 +50,7 @@ export class RouteExecutionManager {
50
50
  return executionPromise ?? clonedRoute;
51
51
  }
52
52
  }
53
- handlePreRestart(clonedRoute);
53
+ await handlePreRestart(clonedRoute, signer);
54
54
  const executionPromise = this.executeSteps(signer, clonedRoute, settings);
55
55
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
56
56
  return executionPromise;
@@ -0,0 +1 @@
1
+ export declare const lifiHandlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
@@ -0,0 +1,14 @@
1
+ import { rest } from 'msw';
2
+ import { mockStepTransactionWithTxRequest, mockChainsResponse, mockStatus, } from './RouteExecutionManager.unit.mock';
3
+ import ConfigService from '../services/ConfigService';
4
+ import { buildStepObject } from '../../test/fixtures';
5
+ const config = ConfigService.getInstance().getConfig();
6
+ export const lifiHandlers = [
7
+ rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (_, response, context) => response(context.status(200), context.json(mockStepTransactionWithTxRequest(buildStepObject({
8
+ includingExecution: true,
9
+ }))))),
10
+ rest.get(`${config.apiUrl}/chains`, async (_, response, context) => response(context.status(200), context.json({
11
+ chains: mockChainsResponse,
12
+ }))),
13
+ rest.get(`${config.apiUrl}/status`, async (_, response, context) => response(context.status(200), context.json(mockStatus))),
14
+ ];
@@ -0,0 +1,80 @@
1
+ import { LifiStep } from '@lifi/types';
2
+ export declare const mockChainsResponse: {
3
+ key: string;
4
+ chainType: string;
5
+ name: string;
6
+ coin: string;
7
+ id: number;
8
+ mainnet: boolean;
9
+ logoURI: string;
10
+ tokenlistUrl: string;
11
+ faucetUrls: string[];
12
+ multicallAddress: string;
13
+ metamask: {
14
+ chainId: string;
15
+ blockExplorerUrls: string[];
16
+ chainName: string;
17
+ nativeCurrency: {
18
+ name: string;
19
+ symbol: string;
20
+ decimals: number;
21
+ };
22
+ rpcUrls: string[];
23
+ };
24
+ nativeToken: {
25
+ address: string;
26
+ chainId: number;
27
+ symbol: string;
28
+ decimals: number;
29
+ name: string;
30
+ priceUSD: string;
31
+ logoURI: string;
32
+ coinKey: string;
33
+ };
34
+ }[];
35
+ export declare const mockTransactionRequest: {
36
+ transactionRequest: {
37
+ data: string;
38
+ to: string;
39
+ value: string;
40
+ from: string;
41
+ chainId: number;
42
+ gasPrice: string;
43
+ gasLimit: string;
44
+ };
45
+ };
46
+ export declare const mockStatus: {
47
+ status: string;
48
+ receiving: boolean;
49
+ sending: {
50
+ amount: string;
51
+ gasAmount: string;
52
+ gasAmountUSD: string;
53
+ gasPrice: string;
54
+ gasToken: string;
55
+ gasUsed: string;
56
+ };
57
+ };
58
+ export declare const mockStepTransactionWithTxRequest: (step?: LifiStep) => {
59
+ transactionRequest: {
60
+ transactionRequest: {
61
+ data: string;
62
+ to: string;
63
+ value: string;
64
+ from: string;
65
+ chainId: number;
66
+ gasPrice: string;
67
+ gasLimit: string;
68
+ };
69
+ };
70
+ type: "lifi";
71
+ includedSteps: import("@lifi/types").Step[];
72
+ id: string;
73
+ referrer?: string | undefined;
74
+ action: import("@lifi/types").Action | import("@lifi/types").CallAction;
75
+ estimate: import("@lifi/types").Estimate;
76
+ tool: string;
77
+ toolDetails: Pick<import("@lifi/types").Bridge | import("@lifi/types").ExchangeAggregator | import("@lifi/types").Exchange, "key" | "name" | "logoURI">;
78
+ integrator?: string | undefined;
79
+ execution?: import("@lifi/types").Execution | undefined;
80
+ };
@@ -0,0 +1,72 @@
1
+ import { buildStepObject } from '../../test/fixtures';
2
+ export const mockChainsResponse = [
3
+ {
4
+ key: 'pol',
5
+ chainType: 'EVM',
6
+ name: 'Polygon',
7
+ coin: 'MATIC',
8
+ id: 137,
9
+ mainnet: true,
10
+ logoURI: 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/polygon.svg',
11
+ tokenlistUrl: 'https://unpkg.com/quickswap-default-token-list@1.0.71/build/quickswap-default.tokenlist.json',
12
+ faucetUrls: ['https://stakely.io/faucet/polygon-matic'],
13
+ multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
14
+ metamask: {
15
+ chainId: '0x89',
16
+ blockExplorerUrls: [
17
+ 'https://polygonscan.com/',
18
+ 'https://explorer-mainnet.maticvigil.com/',
19
+ ],
20
+ chainName: 'Matic(Polygon) Mainnet',
21
+ nativeCurrency: {
22
+ name: 'MATIC',
23
+ symbol: 'MATIC',
24
+ decimals: 18,
25
+ },
26
+ rpcUrls: [
27
+ 'https://polygon-rpc.com/',
28
+ 'https://rpc-mainnet.maticvigil.com/',
29
+ ],
30
+ },
31
+ nativeToken: {
32
+ address: '0x0000000000000000000000000000000000000000',
33
+ chainId: 137,
34
+ symbol: 'MATIC',
35
+ decimals: 18,
36
+ name: 'MATIC',
37
+ priceUSD: '0.899628',
38
+ logoURI: 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
39
+ coinKey: 'MATIC',
40
+ },
41
+ },
42
+ ];
43
+ export const mockTransactionRequest = {
44
+ transactionRequest: {
45
+ // eslint-disable-next-line max-len
46
+ data: '0xdata',
47
+ to: '0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE',
48
+ value: '0x0600830dbc7f5bf7',
49
+ from: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
50
+ chainId: 137,
51
+ gasPrice: '0x27c01c1727',
52
+ gasLimit: '682701',
53
+ },
54
+ };
55
+ export const mockStatus = {
56
+ status: 'DONE',
57
+ receiving: true,
58
+ sending: {
59
+ amount: '123',
60
+ gasAmount: '123',
61
+ gasAmountUSD: '123',
62
+ gasPrice: '123',
63
+ gasToken: '123',
64
+ gasUsed: '123',
65
+ },
66
+ };
67
+ export const mockStepTransactionWithTxRequest = (step = buildStepObject({
68
+ includingExecution: false,
69
+ })) => ({
70
+ ...step,
71
+ transactionRequest: mockTransactionRequest,
72
+ });
@@ -83,6 +83,12 @@ export class StepExecutionManager {
83
83
  customConfig.maxPriorityFeePerGas;
84
84
  transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
85
85
  }
86
+ else {
87
+ const estimatedGasLimit = await signer.estimateGas(transactionRequest);
88
+ if (estimatedGasLimit) {
89
+ transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
90
+ }
91
+ }
86
92
  // Submit the transaction
87
93
  transaction = await signer.sendTransaction(transactionRequest);
88
94
  // STEP 4: Wait for the transaction
@@ -0,0 +1,3 @@
1
+ import { Signer } from 'ethers';
2
+ import { Route } from '../types';
3
+ export declare const handlePreRestart: (route: Route, signer: Signer) => Promise<void>;
@@ -1,18 +1,29 @@
1
1
  import { LifiErrorCode } from './errors';
2
- export const handlePreRestart = (route) => {
2
+ export const handlePreRestart = async (route, signer) => {
3
3
  for (let index = 0; index < route.steps.length; index++) {
4
4
  const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
5
5
  if (stepHasFailed) {
6
- handleErrorType(route, index);
6
+ await handleErrorType(route, index, signer);
7
7
  deleteFailedProcesses(route, index);
8
8
  deleteTransactionData(route, index);
9
9
  }
10
10
  }
11
11
  };
12
- const handleErrorType = (route, index) => {
12
+ const handleErrorType = async (route, index, signer) => {
13
13
  const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.GasLimitError);
14
14
  const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.TransactionUnderpriced);
15
+ const { transactionRequest } = route.steps[index];
15
16
  if (isGasLimitError) {
17
+ if (transactionRequest) {
18
+ let gasLimit = transactionRequest.gasLimit;
19
+ try {
20
+ gasLimit = await signer.estimateGas(transactionRequest);
21
+ }
22
+ catch (error) { }
23
+ if (gasLimit) {
24
+ transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
25
+ }
26
+ }
16
27
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
17
28
  }
18
29
  if (isGasPriceError) {
@@ -0,0 +1,2 @@
1
+ export declare const name = "@lifi/sdk";
2
+ export declare const version = "2.0.0-beta.14";
@@ -0,0 +1,2 @@
1
+ export const name = '@lifi/sdk';
2
+ export const version = '2.0.0-beta.14';