@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 +1 -1
- package/dist/LiFi.js +1 -1
- package/dist/allowance/utils.js +12 -3
- package/dist/cjs/LiFi.d.ts +1 -1
- package/dist/cjs/LiFi.js +1 -1
- package/dist/cjs/allowance/utils.js +11 -2
- package/dist/cjs/execution/StepExecutionManager.js +8 -6
- package/dist/cjs/execution/utils.js +1 -3
- package/dist/cjs/utils/preRestart.js +4 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/execution/StepExecutionManager.js +8 -6
- package/dist/execution/utils.js +1 -3
- package/dist/utils/preRestart.js +4 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +12 -12
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<
|
|
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<
|
|
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) => {
|
package/dist/allowance/utils.js
CHANGED
|
@@ -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
|
-
|
|
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();
|
package/dist/cjs/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<
|
|
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<
|
|
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
|
-
|
|
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:
|
|
165
|
+
txHash: statusReceiving?.txHash,
|
|
164
166
|
txLink: toChain.metamask.blockExplorerUrls[0] +
|
|
165
167
|
'tx/' +
|
|
166
|
-
|
|
168
|
+
statusReceiving?.txHash,
|
|
167
169
|
});
|
|
168
170
|
statusManager.updateExecution(step, 'DONE', {
|
|
169
171
|
fromAmount: statusResponse.sending.amount,
|
|
170
|
-
toAmount:
|
|
171
|
-
toToken:
|
|
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
|
-
|
|
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)}`));
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.
|
|
2
|
+
export declare const version = "2.1.1";
|
package/dist/cjs/version.js
CHANGED
|
@@ -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:
|
|
159
|
+
txHash: statusReceiving?.txHash,
|
|
158
160
|
txLink: toChain.metamask.blockExplorerUrls[0] +
|
|
159
161
|
'tx/' +
|
|
160
|
-
|
|
162
|
+
statusReceiving?.txHash,
|
|
161
163
|
});
|
|
162
164
|
statusManager.updateExecution(step, 'DONE', {
|
|
163
165
|
fromAmount: statusResponse.sending.amount,
|
|
164
|
-
toAmount:
|
|
165
|
-
toToken:
|
|
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,
|
package/dist/execution/utils.js
CHANGED
|
@@ -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
|
-
|
|
30
|
-
txLink: statusResponse.bridgeExplorerLink,
|
|
31
|
-
}),
|
|
29
|
+
txLink: statusResponse.bridgeExplorerLink,
|
|
32
30
|
});
|
|
33
31
|
return resolve(undefined);
|
|
34
32
|
case 'NOT_FOUND':
|
package/dist/utils/preRestart.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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": "^
|
|
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.
|
|
86
|
-
"@commitlint/config-conventional": "^17.6.
|
|
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.
|
|
89
|
-
"@typescript-eslint/parser": "^5.
|
|
90
|
-
"@vitest/coverage-c8": "^0.32.
|
|
91
|
-
"cross-fetch": "^3.1.
|
|
92
|
-
"eslint": "^8.
|
|
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.
|
|
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.
|
|
103
|
-
"vitest": "^0.32.
|
|
102
|
+
"typescript": "^5.1.6",
|
|
103
|
+
"vitest": "^0.32.3"
|
|
104
104
|
},
|
|
105
105
|
"directories": {
|
|
106
106
|
"test": "test"
|