@lifi/sdk 2.0.1 → 2.1.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.
package/dist/LiFi.d.ts CHANGED
@@ -90,7 +90,7 @@ export declare class LiFi extends RouteExecutionManager {
90
90
  /**
91
91
  * Get the transaction data for a single step of a route
92
92
  * @param {LifiStep} step - The step object.
93
- * @return {Promise<Step>} The step populated with the transaction data.
93
+ * @return {Promise<LifiStep>} The step populated with the transaction data.
94
94
  * @throws {LifiError} Throws a LifiError if request fails.
95
95
  */
96
96
  getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
package/dist/LiFi.js CHANGED
@@ -120,7 +120,7 @@ export class LiFi extends RouteExecutionManager {
120
120
  /**
121
121
  * Get the transaction data for a single step of a route
122
122
  * @param {LifiStep} step - The step object.
123
- * @return {Promise<Step>} The step populated with the transaction data.
123
+ * @return {Promise<LifiStep>} The step populated with the transaction data.
124
124
  * @throws {LifiError} Throws a LifiError if request fails.
125
125
  */
126
126
  this.getStepTransaction = async (step, options) => {
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { Contract } from 'ethers';
2
+ import { Contract, ethers } from 'ethers';
3
3
  import ChainsService from '../services/ChainsService';
4
4
  import { ERC20_ABI } from '../types';
5
5
  import { ServerError } from '../utils/errors';
@@ -20,9 +20,18 @@ export const getApproved = async (signer, tokenAddress, contractAddress, transac
20
20
  return new BigNumber(0);
21
21
  }
22
22
  };
23
- export const setApproval = (signer, tokenAddress, contractAddress, amount) => {
23
+ export const setApproval = async (signer, tokenAddress, contractAddress, amount) => {
24
24
  const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
25
- return erc20.approve(contractAddress, amount);
25
+ const transactionRequest = await erc20.populateTransaction.approve(contractAddress, amount);
26
+ try {
27
+ const estimatedGasLimit = await signer.estimateGas(transactionRequest);
28
+ if (estimatedGasLimit) {
29
+ const formattedGasLimit = ethers.BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
30
+ transactionRequest.gasLimit = formattedGasLimit;
31
+ }
32
+ }
33
+ catch (error) { }
34
+ return signer.sendTransaction(transactionRequest);
26
35
  };
27
36
  export const getAllowanceViaMulticall = async (signer, chainId, tokenData) => {
28
37
  const chainsService = ChainsService.getInstance();
@@ -90,7 +90,7 @@ export declare class LiFi extends RouteExecutionManager {
90
90
  /**
91
91
  * Get the transaction data for a single step of a route
92
92
  * @param {LifiStep} step - The step object.
93
- * @return {Promise<Step>} The step populated with the transaction data.
93
+ * @return {Promise<LifiStep>} The step populated with the transaction data.
94
94
  * @throws {LifiError} Throws a LifiError if request fails.
95
95
  */
96
96
  getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
package/dist/cjs/LiFi.js CHANGED
@@ -149,7 +149,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
149
149
  /**
150
150
  * Get the transaction data for a single step of a route
151
151
  * @param {LifiStep} step - The step object.
152
- * @return {Promise<Step>} The step populated with the transaction data.
152
+ * @return {Promise<LifiStep>} The step populated with the transaction data.
153
153
  * @throws {LifiError} Throws a LifiError if request fails.
154
154
  */
155
155
  this.getStepTransaction = async (step, options) => {
@@ -27,9 +27,18 @@ const getApproved = async (signer, tokenAddress, contractAddress, transactionReq
27
27
  }
28
28
  };
29
29
  exports.getApproved = getApproved;
30
- const setApproval = (signer, tokenAddress, contractAddress, amount) => {
30
+ const setApproval = async (signer, tokenAddress, contractAddress, amount) => {
31
31
  const erc20 = new ethers_1.Contract(tokenAddress, types_1.ERC20_ABI, signer);
32
- return erc20.approve(contractAddress, amount);
32
+ const transactionRequest = await erc20.populateTransaction.approve(contractAddress, amount);
33
+ try {
34
+ const estimatedGasLimit = await signer.estimateGas(transactionRequest);
35
+ if (estimatedGasLimit) {
36
+ const formattedGasLimit = ethers_1.ethers.BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
37
+ transactionRequest.gasLimit = formattedGasLimit;
38
+ }
39
+ }
40
+ catch (error) { }
41
+ return signer.sendTransaction(transactionRequest);
33
42
  };
34
43
  exports.setApproval = setApproval;
35
44
  const getAllowanceViaMulticall = async (signer, chainId, tokenData) => {
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.StepExecutionManager = void 0;
7
+ const ethers_1 = require("ethers");
7
8
  const allowance_1 = require("../allowance");
8
9
  const balance_1 = require("../balance");
9
10
  const ApiService_1 = __importDefault(require("../services/ApiService"));
@@ -93,7 +94,7 @@ class StepExecutionManager {
93
94
  try {
94
95
  const estimatedGasLimit = await signer.estimateGas(transactionRequest);
95
96
  if (estimatedGasLimit) {
96
- transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
97
+ transactionRequest.gasLimit = ethers_1.BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
97
98
  }
98
99
  // Fetch latest gasPrice from provider and use it
99
100
  const gasPrice = await signer.getGasPrice();
@@ -155,20 +156,21 @@ class StepExecutionManager {
155
156
  if (!processTxHash) {
156
157
  throw new Error('Transaction hash is undefined.');
157
158
  }
158
- statusResponse = await (0, utils_2.waitForReceivingTransaction)(processTxHash, statusManager, process.type, step);
159
+ statusResponse = (await (0, utils_2.waitForReceivingTransaction)(processTxHash, statusManager, process.type, step));
160
+ const statusReceiving = statusResponse.receiving;
159
161
  process = statusManager.updateProcess(step, process.type, 'DONE', {
160
162
  substatus: statusResponse.substatus,
161
163
  substatusMessage: statusResponse.substatusMessage ||
162
164
  (0, utils_2.getSubstatusMessage)(statusResponse.status, statusResponse.substatus),
163
- txHash: statusResponse.receiving?.txHash,
165
+ txHash: statusReceiving?.txHash,
164
166
  txLink: toChain.metamask.blockExplorerUrls[0] +
165
167
  'tx/' +
166
- statusResponse.receiving?.txHash,
168
+ statusReceiving?.txHash,
167
169
  });
168
170
  statusManager.updateExecution(step, 'DONE', {
169
171
  fromAmount: statusResponse.sending.amount,
170
- toAmount: statusResponse.receiving?.amount,
171
- toToken: statusResponse.receiving?.token,
172
+ toAmount: statusReceiving?.amount,
173
+ toToken: statusReceiving?.token,
172
174
  gasAmount: statusResponse.sending.gasAmount,
173
175
  gasAmountUSD: statusResponse.sending.gasAmountUSD,
174
176
  gasPrice: statusResponse.sending.gasPrice,
@@ -32,9 +32,7 @@ async function waitForReceivingTransaction(txHash, statusManager, processType, s
32
32
  substatus: statusResponse.substatus,
33
33
  substatusMessage: statusResponse.substatusMessage ||
34
34
  getSubstatusMessage(statusResponse.status, statusResponse.substatus),
35
- ...(statusResponse.bridgeExplorerLink && {
36
- txLink: statusResponse.bridgeExplorerLink,
37
- }),
35
+ txLink: statusResponse.bridgeExplorerLink,
38
36
  });
39
37
  return resolve(undefined);
40
38
  case 'NOT_FOUND':
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePreRestart = void 0;
4
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
5
+ const ethers_1 = require("ethers");
4
6
  const errors_1 = require("./errors");
5
7
  const handlePreRestart = async (route, signer) => {
6
8
  for (let index = 0; index < route.steps.length; index++) {
@@ -25,7 +27,7 @@ const handleErrorType = async (route, index, signer) => {
25
27
  }
26
28
  catch (error) { }
27
29
  if (gasLimit) {
28
- transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
30
+ transactionRequest.gasLimit = ethers_1.BigNumber.from(`${(BigInt(gasLimit.toString()) * 125n) / 100n}`);
29
31
  }
30
32
  }
31
33
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
@@ -38,7 +40,7 @@ const handleErrorType = async (route, index, signer) => {
38
40
  }
39
41
  catch (error) { }
40
42
  if (gasPrice) {
41
- transactionRequest.gasPrice = `${(BigInt(gasPrice.toString()) * 125n) / 100n}`;
43
+ transactionRequest.gasPrice = ethers_1.BigNumber.from(`${(BigInt(gasPrice.toString()) * 125n) / 100n}`);
42
44
  }
43
45
  }
44
46
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.0.1";
2
+ export declare const version = "2.1.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.0.1';
5
+ exports.version = '2.1.1';
@@ -1,3 +1,4 @@
1
+ import { BigNumber } from 'ethers';
1
2
  import { checkAllowance } from '../allowance';
2
3
  import { checkBalance } from '../balance';
3
4
  import ApiService from '../services/ApiService';
@@ -87,7 +88,7 @@ export class StepExecutionManager {
87
88
  try {
88
89
  const estimatedGasLimit = await signer.estimateGas(transactionRequest);
89
90
  if (estimatedGasLimit) {
90
- transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
91
+ transactionRequest.gasLimit = BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
91
92
  }
92
93
  // Fetch latest gasPrice from provider and use it
93
94
  const gasPrice = await signer.getGasPrice();
@@ -149,20 +150,21 @@ export class StepExecutionManager {
149
150
  if (!processTxHash) {
150
151
  throw new Error('Transaction hash is undefined.');
151
152
  }
152
- statusResponse = await waitForReceivingTransaction(processTxHash, statusManager, process.type, step);
153
+ statusResponse = (await waitForReceivingTransaction(processTxHash, statusManager, process.type, step));
154
+ const statusReceiving = statusResponse.receiving;
153
155
  process = statusManager.updateProcess(step, process.type, 'DONE', {
154
156
  substatus: statusResponse.substatus,
155
157
  substatusMessage: statusResponse.substatusMessage ||
156
158
  getSubstatusMessage(statusResponse.status, statusResponse.substatus),
157
- txHash: statusResponse.receiving?.txHash,
159
+ txHash: statusReceiving?.txHash,
158
160
  txLink: toChain.metamask.blockExplorerUrls[0] +
159
161
  'tx/' +
160
- statusResponse.receiving?.txHash,
162
+ statusReceiving?.txHash,
161
163
  });
162
164
  statusManager.updateExecution(step, 'DONE', {
163
165
  fromAmount: statusResponse.sending.amount,
164
- toAmount: statusResponse.receiving?.amount,
165
- toToken: statusResponse.receiving?.token,
166
+ toAmount: statusReceiving?.amount,
167
+ toToken: statusReceiving?.token,
166
168
  gasAmount: statusResponse.sending.gasAmount,
167
169
  gasAmountUSD: statusResponse.sending.gasAmountUSD,
168
170
  gasPrice: statusResponse.sending.gasPrice,
@@ -26,9 +26,7 @@ export async function waitForReceivingTransaction(txHash, statusManager, process
26
26
  substatus: statusResponse.substatus,
27
27
  substatusMessage: statusResponse.substatusMessage ||
28
28
  getSubstatusMessage(statusResponse.status, statusResponse.substatus),
29
- ...(statusResponse.bridgeExplorerLink && {
30
- txLink: statusResponse.bridgeExplorerLink,
31
- }),
29
+ txLink: statusResponse.bridgeExplorerLink,
32
30
  });
33
31
  return resolve(undefined);
34
32
  case 'NOT_FOUND':
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { BigNumber } from 'ethers';
1
3
  import { LifiErrorCode } from './errors';
2
4
  export const handlePreRestart = async (route, signer) => {
3
5
  for (let index = 0; index < route.steps.length; index++) {
@@ -21,7 +23,7 @@ const handleErrorType = async (route, index, signer) => {
21
23
  }
22
24
  catch (error) { }
23
25
  if (gasLimit) {
24
- transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
26
+ transactionRequest.gasLimit = BigNumber.from(`${(BigInt(gasLimit.toString()) * 125n) / 100n}`);
25
27
  }
26
28
  }
27
29
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
@@ -34,7 +36,7 @@ const handleErrorType = async (route, index, signer) => {
34
36
  }
35
37
  catch (error) { }
36
38
  if (gasPrice) {
37
- transactionRequest.gasPrice = `${(BigInt(gasPrice.toString()) * 125n) / 100n}`;
39
+ transactionRequest.gasPrice = BigNumber.from(`${(BigInt(gasPrice.toString()) * 125n) / 100n}`);
38
40
  }
39
41
  }
40
42
  route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
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.1";
2
+ export declare const version = "2.1.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk';
2
- export const version = '2.0.1';
2
+ export const version = '2.1.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
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",
@@ -76,31 +76,31 @@
76
76
  "dependencies": {
77
77
  "@ethersproject/abi": "^5.7.0",
78
78
  "@ethersproject/contracts": "^5.7.0",
79
- "@lifi/types": "^6.0.0",
79
+ "@lifi/types": "^8.0.2",
80
80
  "bignumber.js": "^9.1.1",
81
81
  "eth-rpc-errors": "^4.0.3",
82
82
  "ethers": "^5.7.2"
83
83
  },
84
84
  "devDependencies": {
85
- "@commitlint/cli": "^17.6.5",
86
- "@commitlint/config-conventional": "^17.6.5",
85
+ "@commitlint/cli": "^17.6.6",
86
+ "@commitlint/config-conventional": "^17.6.6",
87
87
  "@mswjs/interceptors": "^0.22.15",
88
- "@typescript-eslint/eslint-plugin": "^5.59.9",
89
- "@typescript-eslint/parser": "^5.59.9",
90
- "@vitest/coverage-c8": "^0.32.0",
91
- "cross-fetch": "^3.1.6",
92
- "eslint": "^8.42.0",
88
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
89
+ "@typescript-eslint/parser": "^5.60.1",
90
+ "@vitest/coverage-c8": "^0.32.3",
91
+ "cross-fetch": "^3.1.8",
92
+ "eslint": "^8.44.0",
93
93
  "eslint-config-prettier": "^8.8.0",
94
94
  "eslint-plugin-prettier": "^4.2.1",
95
95
  "husky": "^8.0.3",
96
- "lint-staged": "^13.2.2",
96
+ "lint-staged": "^13.2.3",
97
97
  "msw": "1.0.1",
98
98
  "npm-run-all": "^4.1.5",
99
99
  "pinst": "^3.0.0",
100
100
  "prettier": "^2.8.8",
101
101
  "standard-version": "^9.5.0",
102
- "typescript": "^5.1.3",
103
- "vitest": "^0.32.0"
102
+ "typescript": "^5.1.6",
103
+ "vitest": "^0.32.3"
104
104
  },
105
105
  "directories": {
106
106
  "test": "test"