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

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.
@@ -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;
@@ -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
@@ -1,2 +1,3 @@
1
+ import { Signer } from 'ethers';
1
2
  import { Route } from '../types';
2
- export declare const handlePreRestart: (route: Route) => void;
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) {
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.0.0-beta.13";
2
+ export declare const version = "2.0.0-beta.15";
@@ -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.15';
@@ -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;
@@ -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
@@ -1,2 +1,3 @@
1
+ import { Signer } from 'ethers';
1
2
  import { Route } from '../types';
2
- export declare const handlePreRestart: (route: Route) => void;
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) {
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.0.0-beta.13";
2
+ export declare const version = "2.0.0-beta.15";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk';
2
- export const version = '2.0.0-beta.13';
2
+ export const version = '2.0.0-beta.15';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/index.js",
@@ -84,12 +84,12 @@
84
84
  "devDependencies": {
85
85
  "@commitlint/cli": "^17.6.3",
86
86
  "@commitlint/config-conventional": "^17.6.3",
87
- "@mswjs/interceptors": "^0.22.14",
88
- "@typescript-eslint/eslint-plugin": "^5.59.5",
89
- "@typescript-eslint/parser": "^5.59.5",
90
- "@vitest/coverage-c8": "^0.31.0",
91
- "cross-fetch": "^3.1.5",
92
- "eslint": "^8.40.0",
87
+ "@mswjs/interceptors": "^0.22.15",
88
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
89
+ "@typescript-eslint/parser": "^5.59.7",
90
+ "@vitest/coverage-c8": "^0.31.1",
91
+ "cross-fetch": "^3.1.6",
92
+ "eslint": "^8.41.0",
93
93
  "eslint-config-prettier": "^8.8.0",
94
94
  "eslint-plugin-prettier": "^4.2.1",
95
95
  "husky": "^8.0.3",
@@ -100,7 +100,7 @@
100
100
  "prettier": "^2.8.8",
101
101
  "standard-version": "^9.5.0",
102
102
  "typescript": "^5.0.4",
103
- "vitest": "^0.31.0"
103
+ "vitest": "^0.31.1"
104
104
  },
105
105
  "directories": {
106
106
  "test": "test"
@@ -1 +0,0 @@
1
- export declare const handlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
@@ -1,50 +0,0 @@
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.handlers = void 0;
7
- const types_1 = require("@lifi/types");
8
- const msw_1 = require("msw");
9
- const ConfigService_1 = __importDefault(require("./ConfigService"));
10
- const config = ConfigService_1.default.getInstance().getConfig();
11
- exports.handlers = [
12
- msw_1.rest.post(`${config.apiUrl}/advanced/routes`, async (request, response, context) => {
13
- const data = await request.json();
14
- if (isNaN(parseFloat(data.fromAmount))) {
15
- return response(context.status(500), context.json({ message: `Oops` }));
16
- }
17
- return response(context.json({}));
18
- }),
19
- msw_1.rest.post(`${config.apiUrl}/advanced/possibilities`, async (request, response, context) => {
20
- return response(context.json({}));
21
- }),
22
- msw_1.rest.get(`${config.apiUrl}/token`, async (request, response, context) => {
23
- return response(context.json({}));
24
- }),
25
- msw_1.rest.get(`${config.apiUrl}/quote`, async (request, response, context) => {
26
- return response(context.json({}));
27
- }),
28
- msw_1.rest.get(`${config.apiUrl}/status`, async (request, response, context) => {
29
- return response(context.json({}));
30
- }),
31
- msw_1.rest.get(`${config.apiUrl}/chains`, async (request, response, context) => {
32
- return response(context.json({ chains: [{ id: 1 }] }));
33
- }),
34
- msw_1.rest.get(`${config.apiUrl}/tools`, async (request, response, context) => {
35
- return response(context.json({ bridges: [], exchanges: [] }));
36
- }),
37
- msw_1.rest.get(`${config.apiUrl}/tokens`, async (request, response, context) => {
38
- return response(context.json({
39
- tokens: {
40
- [types_1.ChainId.ETH]: [(0, types_1.findDefaultToken)(types_1.CoinKey.ETH, types_1.ChainId.ETH)],
41
- },
42
- }));
43
- }),
44
- msw_1.rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (request, response, context) => {
45
- return response(context.json({}));
46
- }),
47
- msw_1.rest.get(`${config.apiUrl}/gas/suggestion/${types_1.ChainId.OPT}`, async (request, response, context) => {
48
- return response(context.json({}));
49
- }),
50
- ];
@@ -1 +0,0 @@
1
- export declare const handlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
@@ -1,44 +0,0 @@
1
- import { ChainId, CoinKey, findDefaultToken } from '@lifi/types';
2
- import { rest } from 'msw';
3
- import ConfigService from './ConfigService';
4
- const config = ConfigService.getInstance().getConfig();
5
- export const handlers = [
6
- rest.post(`${config.apiUrl}/advanced/routes`, async (request, response, context) => {
7
- const data = await request.json();
8
- if (isNaN(parseFloat(data.fromAmount))) {
9
- return response(context.status(500), context.json({ message: `Oops` }));
10
- }
11
- return response(context.json({}));
12
- }),
13
- rest.post(`${config.apiUrl}/advanced/possibilities`, async (request, response, context) => {
14
- return response(context.json({}));
15
- }),
16
- rest.get(`${config.apiUrl}/token`, async (request, response, context) => {
17
- return response(context.json({}));
18
- }),
19
- rest.get(`${config.apiUrl}/quote`, async (request, response, context) => {
20
- return response(context.json({}));
21
- }),
22
- rest.get(`${config.apiUrl}/status`, async (request, response, context) => {
23
- return response(context.json({}));
24
- }),
25
- rest.get(`${config.apiUrl}/chains`, async (request, response, context) => {
26
- return response(context.json({ chains: [{ id: 1 }] }));
27
- }),
28
- rest.get(`${config.apiUrl}/tools`, async (request, response, context) => {
29
- return response(context.json({ bridges: [], exchanges: [] }));
30
- }),
31
- rest.get(`${config.apiUrl}/tokens`, async (request, response, context) => {
32
- return response(context.json({
33
- tokens: {
34
- [ChainId.ETH]: [findDefaultToken(CoinKey.ETH, ChainId.ETH)],
35
- },
36
- }));
37
- }),
38
- rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (request, response, context) => {
39
- return response(context.json({}));
40
- }),
41
- rest.get(`${config.apiUrl}/gas/suggestion/${ChainId.OPT}`, async (request, response, context) => {
42
- return response(context.json({}));
43
- }),
44
- ];