@lifi/sdk 1.7.1 → 2.0.0-beta.0
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.js +97 -85
- package/dist/allowance/checkAllowance.js +12 -21
- package/dist/allowance/tokenApproval.js +20 -29
- package/dist/allowance/utils.js +12 -24
- package/dist/balance/checkBalance.js +5 -14
- package/dist/balance/getTokenBalance.js +12 -21
- package/dist/balance/index.d.ts +11 -0
- package/dist/balance/index.js +8 -0
- package/dist/balance/utils.d.ts +1 -0
- package/dist/balance/utils.js +36 -38
- package/dist/cjs/Lifi.js +97 -85
- package/dist/cjs/allowance/checkAllowance.js +12 -21
- package/dist/cjs/allowance/tokenApproval.js +20 -29
- package/dist/cjs/allowance/utils.js +12 -24
- package/dist/cjs/balance/checkBalance.js +5 -14
- package/dist/cjs/balance/getTokenBalance.js +12 -21
- package/dist/cjs/balance/index.d.ts +11 -0
- package/dist/cjs/balance/index.js +8 -0
- package/dist/cjs/balance/utils.d.ts +1 -0
- package/dist/cjs/balance/utils.js +39 -39
- package/dist/cjs/connectors.js +17 -25
- package/dist/cjs/execution/ExecutionManager.js +27 -33
- package/dist/cjs/execution/StatusManager.js +13 -13
- package/dist/cjs/execution/StepExecutor.js +8 -14
- package/dist/cjs/execution/stepComparison.js +4 -14
- package/dist/cjs/execution/switchChain.js +5 -14
- package/dist/cjs/execution/utils.js +43 -50
- package/dist/cjs/helpers.d.ts +12 -1
- package/dist/cjs/helpers.js +68 -19
- package/dist/cjs/services/ApiService.d.ts +10 -9
- package/dist/cjs/services/ApiService.js +190 -152
- package/dist/cjs/services/ApiService.unit.handlers.d.ts +1 -0
- package/dist/cjs/services/ApiService.unit.handlers.js +50 -0
- package/dist/cjs/services/ChainsService.js +16 -31
- package/dist/cjs/services/ConfigService.js +6 -16
- package/dist/cjs/typeguards.js +1 -1
- package/dist/cjs/types/internal.types.d.ts +4 -1
- package/dist/cjs/utils/errors.d.ts +5 -0
- package/dist/cjs/utils/errors.js +14 -1
- package/dist/cjs/utils/multicall.js +6 -15
- package/dist/cjs/utils/parseError.d.ts +2 -2
- package/dist/cjs/utils/parseError.js +36 -38
- package/dist/cjs/utils/preRestart.js +5 -7
- package/dist/cjs/utils/utils.d.ts +0 -1
- package/dist/cjs/utils/utils.js +21 -28
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.js +15 -23
- package/dist/execution/ExecutionManager.js +27 -33
- package/dist/execution/StatusManager.js +11 -11
- package/dist/execution/StepExecutor.js +8 -14
- package/dist/execution/stepComparison.js +4 -14
- package/dist/execution/switchChain.js +5 -14
- package/dist/execution/utils.js +43 -50
- package/dist/helpers.d.ts +12 -1
- package/dist/helpers.js +65 -18
- package/dist/services/ApiService.d.ts +10 -9
- package/dist/services/ApiService.js +190 -152
- package/dist/services/ApiService.unit.handlers.d.ts +1 -0
- package/dist/services/ApiService.unit.handlers.js +44 -0
- package/dist/services/ChainsService.js +16 -31
- package/dist/services/ConfigService.js +6 -16
- package/dist/typeguards.js +1 -1
- package/dist/types/internal.types.d.ts +4 -1
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +12 -0
- package/dist/utils/multicall.js +6 -15
- package/dist/utils/parseError.d.ts +2 -2
- package/dist/utils/parseError.js +36 -38
- package/dist/utils/preRestart.js +5 -7
- package/dist/utils/utils.d.ts +0 -1
- package/dist/utils/utils.js +20 -26
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +23 -25
- package/CHANGELOG.md +0 -490
package/dist/utils/errors.js
CHANGED
|
@@ -108,3 +108,15 @@ export class UnknownError extends LifiError {
|
|
|
108
108
|
super(ErrorType.UnknownError, code, message, htmlMessage, stack);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
export class HTTPError extends Error {
|
|
112
|
+
constructor(response) {
|
|
113
|
+
const code = response.status || response.status === 0 ? response.status : '';
|
|
114
|
+
const title = response.statusText || '';
|
|
115
|
+
const status = `${code} ${title}`.trim();
|
|
116
|
+
const reason = status ? `status code ${status}` : 'an unknown error';
|
|
117
|
+
super(`Request failed with ${reason}`);
|
|
118
|
+
this.name = 'HTTPError';
|
|
119
|
+
this.response = response;
|
|
120
|
+
this.status = response.status;
|
|
121
|
+
}
|
|
122
|
+
}
|
package/dist/utils/multicall.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Interface } from '@ethersproject/abi';
|
|
11
2
|
import { Contract } from '@ethersproject/contracts';
|
|
12
3
|
import { getRpcProvider } from '../connectors';
|
|
13
4
|
import { splitListIntoChunks } from './utils';
|
|
14
5
|
import MULTICALL_ABI from './multicallAbi.json';
|
|
15
6
|
const MAX_MULTICALL_SIZE = 100;
|
|
16
|
-
export const fetchDataUsingMulticall = (calls, abi, chainId, multicallAddress, requireSuccess = false) =>
|
|
7
|
+
export const fetchDataUsingMulticall = async (calls, abi, chainId, multicallAddress, requireSuccess = false) => {
|
|
17
8
|
// 1. create contract using multicall contract address and abi...
|
|
18
|
-
const provider =
|
|
9
|
+
const provider = await getRpcProvider(chainId);
|
|
19
10
|
const multicallContract = new Contract(multicallAddress, MULTICALL_ABI, provider);
|
|
20
11
|
const abiInterface = new Interface(abi);
|
|
21
12
|
// split up lists into chunks to stay below multicall limit
|
|
22
13
|
const chunkedList = splitListIntoChunks(calls, MAX_MULTICALL_SIZE);
|
|
23
|
-
const chunkedResults =
|
|
14
|
+
const chunkedResults = await Promise.all(chunkedList.map(async (chunkedCalls) => {
|
|
24
15
|
const callData = chunkedCalls.map((call) => [
|
|
25
16
|
call.address.toLowerCase(),
|
|
26
17
|
abiInterface.encodeFunctionData(call.name, call.params),
|
|
27
18
|
]);
|
|
28
19
|
try {
|
|
29
20
|
// 3. get bytes array from multicall contract by process aggregate method...
|
|
30
|
-
const { blockNumber, returnData } =
|
|
21
|
+
const { blockNumber, returnData } = await multicallContract.tryBlockAndAggregate(requireSuccess, callData);
|
|
31
22
|
// 4. decode bytes array to useful data array...
|
|
32
23
|
return returnData
|
|
33
24
|
.map(({ success, returnData }, i) => {
|
|
@@ -65,6 +56,6 @@ export const fetchDataUsingMulticall = (calls, abi, chainId, multicallAddress, r
|
|
|
65
56
|
console.error(`Multicall failed on chainId "${chainId}"`, chunkedList, e);
|
|
66
57
|
return [];
|
|
67
58
|
}
|
|
68
|
-
}))
|
|
59
|
+
}));
|
|
69
60
|
return chunkedResults.flat();
|
|
70
|
-
}
|
|
61
|
+
};
|
|
@@ -32,6 +32,6 @@ import { LifiError } from './errors';
|
|
|
32
32
|
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
33
33
|
*/
|
|
34
34
|
export declare const getTransactionNotSentMessage: (step?: Step, process?: Process) => Promise<string>;
|
|
35
|
-
export declare const getTransactionFailedMessage: (step: Step, txLink?: string) => string
|
|
35
|
+
export declare const getTransactionFailedMessage: (step: Step, txLink?: string) => Promise<string>;
|
|
36
36
|
export declare const parseError: (e: any, step?: Step, process?: Process) => Promise<LifiError>;
|
|
37
|
-
export declare const parseBackendError: (e: any) => LifiError
|
|
37
|
+
export declare const parseBackendError: (e: any) => Promise<LifiError>;
|
package/dist/utils/parseError.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getChainById } from '@lifi/types';
|
|
11
1
|
import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
|
|
12
2
|
import ChainsService from '../services/ChainsService';
|
|
13
3
|
import { LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
@@ -43,12 +33,12 @@ import { formatTokenAmountOnly } from './utils';
|
|
|
43
33
|
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
44
34
|
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
45
35
|
*/
|
|
46
|
-
export const getTransactionNotSentMessage = (step, process) =>
|
|
36
|
+
export const getTransactionNotSentMessage = async (step, process) => {
|
|
47
37
|
let transactionNotSend = 'Transaction was not sent, your funds are still in your wallet';
|
|
48
38
|
// add information about funds if available
|
|
49
39
|
if (step) {
|
|
50
40
|
const chainService = ChainsService.getInstance();
|
|
51
|
-
const chain =
|
|
41
|
+
const chain = await chainService.getChainById(step.action.fromChainId);
|
|
52
42
|
transactionNotSend += ` (${formatTokenAmountOnly(step.action.fromToken, step.action.fromAmount)} ${step.action.fromToken.symbol} on ${chain.name})`;
|
|
53
43
|
}
|
|
54
44
|
transactionNotSend +=
|
|
@@ -59,17 +49,18 @@ export const getTransactionNotSentMessage = (step, process) => __awaiter(void 0,
|
|
|
59
49
|
? `<br>You can check the failed transaction <a href="${process.txLink}" target="_blank" rel="nofollow noreferrer">here</a>.`
|
|
60
50
|
: '';
|
|
61
51
|
return transactionNotSend;
|
|
62
|
-
}
|
|
63
|
-
export const getTransactionFailedMessage = (step, txLink) => {
|
|
52
|
+
};
|
|
53
|
+
export const getTransactionFailedMessage = async (step, txLink) => {
|
|
54
|
+
const chainsService = ChainsService.getInstance();
|
|
55
|
+
const chain = await chainsService.getChainById(step.action.toChainId);
|
|
64
56
|
const baseString = `It appears that your transaction may not have been successful.
|
|
65
|
-
However, to confirm this, please check your ${
|
|
57
|
+
However, to confirm this, please check your ${chain.name} wallet for ${step.action.toToken.symbol}.`;
|
|
66
58
|
return txLink
|
|
67
59
|
? `${baseString}
|
|
68
60
|
You can also check the <a href="${txLink}" target="_blank" rel="nofollow noreferrer">block explorer</a> for more information.`
|
|
69
61
|
: baseString;
|
|
70
62
|
};
|
|
71
|
-
export const parseError = (e, step, process) =>
|
|
72
|
-
var _a, _b, _c;
|
|
63
|
+
export const parseError = async (e, step, process) => {
|
|
73
64
|
if (e instanceof LifiError) {
|
|
74
65
|
return e;
|
|
75
66
|
}
|
|
@@ -80,48 +71,55 @@ export const parseError = (e, step, process) => __awaiter(void 0, void 0, void 0
|
|
|
80
71
|
// rpc errors
|
|
81
72
|
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
82
73
|
if (e.code === MetaMaskErrorCodes.rpc.internal &&
|
|
83
|
-
(
|
|
84
|
-
|
|
74
|
+
(e.message?.includes('underpriced') ||
|
|
75
|
+
e.message?.includes('replacement fee too low'))) {
|
|
76
|
+
return new RPCError(LifiErrorCode.TransactionUnderpriced, 'Transaction is underpriced.', await getTransactionNotSentMessage(step, process), e.stack);
|
|
85
77
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
return new TransactionError(LifiErrorCode.GasLimitError, 'Gas limit is too low.',
|
|
78
|
+
if (e.message?.includes('intrinsic gas too low') ||
|
|
79
|
+
e.message?.includes('out of gas')) {
|
|
80
|
+
return new TransactionError(LifiErrorCode.GasLimitError, 'Gas limit is too low.', await getTransactionNotSentMessage(step, process), e.stack);
|
|
89
81
|
}
|
|
90
|
-
return new RPCError(e.code, getMessageFromCode(e.code),
|
|
82
|
+
return new RPCError(e.code, getMessageFromCode(e.code), await getTransactionNotSentMessage(step, process), e.stack);
|
|
91
83
|
}
|
|
92
84
|
// provider errors
|
|
93
85
|
if (Object.values(MetaMaskErrorCodes.provider).includes(e.code)) {
|
|
94
|
-
return new ProviderError(e.code, getMessageFromCode(e.code),
|
|
86
|
+
return new ProviderError(e.code, getMessageFromCode(e.code), await getTransactionNotSentMessage(step, process), e.stack);
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
switch (e.code) {
|
|
99
91
|
case 'CALL_EXCEPTION':
|
|
100
|
-
return new ProviderError(LifiErrorCode.TransactionFailed, e.reason,
|
|
92
|
+
return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, await getTransactionNotSentMessage(step, process), e.stack);
|
|
101
93
|
case 'ACTION_REJECTED':
|
|
102
94
|
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
103
|
-
return new TransactionError(LifiErrorCode.TransactionRejected, e.message,
|
|
95
|
+
return new TransactionError(LifiErrorCode.TransactionRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
104
96
|
case LifiErrorCode.TransactionUnprepared:
|
|
105
|
-
return new TransactionError(LifiErrorCode.TransactionUnprepared, e.message,
|
|
97
|
+
return new TransactionError(LifiErrorCode.TransactionUnprepared, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
106
98
|
case LifiErrorCode.ValidationError:
|
|
107
99
|
return new TransactionError(LifiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
108
100
|
default:
|
|
109
101
|
return new UnknownError(LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
|
|
110
102
|
}
|
|
111
|
-
}
|
|
112
|
-
export const parseBackendError = (e) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
};
|
|
104
|
+
export const parseBackendError = async (e) => {
|
|
105
|
+
let data;
|
|
106
|
+
try {
|
|
107
|
+
data = await e.response?.json();
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
if (e.response?.status === 400) {
|
|
113
|
+
return new ValidationError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
116
114
|
}
|
|
117
|
-
if (
|
|
118
|
-
return new NotFoundError(
|
|
115
|
+
if (e.response?.status === 404) {
|
|
116
|
+
return new NotFoundError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
119
117
|
}
|
|
120
|
-
if (
|
|
121
|
-
return new SlippageError(
|
|
118
|
+
if (e.response?.status === 409) {
|
|
119
|
+
return new SlippageError(data?.message || e.response?.statusText, 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.', e.stack);
|
|
122
120
|
}
|
|
123
|
-
if (
|
|
124
|
-
return new ServerError(
|
|
121
|
+
if (e.response?.status === 500) {
|
|
122
|
+
return new ServerError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
125
123
|
}
|
|
126
124
|
return new ServerError('Something went wrong.', undefined, e.stack);
|
|
127
125
|
};
|
package/dist/utils/preRestart.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { LifiErrorCode } from './errors';
|
|
2
2
|
export const handlePreRestart = (route) => {
|
|
3
|
-
var _a;
|
|
4
3
|
for (let index = 0; index < route.steps.length; index++) {
|
|
5
|
-
const stepHasFailed =
|
|
4
|
+
const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
|
|
6
5
|
if (stepHasFailed) {
|
|
7
6
|
handleErrorType(route, index);
|
|
8
7
|
deleteFailedProcesses(route, index);
|
|
@@ -11,14 +10,13 @@ export const handlePreRestart = (route) => {
|
|
|
11
10
|
}
|
|
12
11
|
};
|
|
13
12
|
const handleErrorType = (route, index) => {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const isGasPriceError = (_b = route.steps[index].execution) === null || _b === void 0 ? void 0 : _b.process.some((p) => { var _a; return ((_a = p.error) === null || _a === void 0 ? void 0 : _a.code) === LifiErrorCode.TransactionUnderpriced; });
|
|
13
|
+
const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.GasLimitError);
|
|
14
|
+
const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.TransactionUnderpriced);
|
|
17
15
|
if (isGasLimitError) {
|
|
18
|
-
|
|
16
|
+
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
|
|
19
17
|
}
|
|
20
18
|
if (isGasPriceError) {
|
|
21
|
-
|
|
19
|
+
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
const deleteFailedProcesses = (route, index) => {
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Token } from '@lifi/types';
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Signer } from 'ethers';
|
|
5
5
|
import { ChainId, Step } from '../types';
|
|
6
|
-
export declare const deepClone: <T>(src: T) => T;
|
|
7
6
|
export declare const sleep: (mills: number) => Promise<undefined>;
|
|
8
7
|
export declare const personalizeStep: (signer: Signer, step: Step) => Promise<Step>;
|
|
9
8
|
export declare const splitListIntoChunks: <T>(list: T[], chunkSize: number) => T[][];
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import BigNumber from 'bignumber.js';
|
|
11
2
|
import { constants } from 'ethers';
|
|
12
3
|
import { getRpcProvider } from '../connectors';
|
|
13
|
-
export const deepClone = (src) => {
|
|
14
|
-
return JSON.parse(JSON.stringify(src));
|
|
15
|
-
};
|
|
16
4
|
export const sleep = (mills) => {
|
|
17
5
|
return new Promise((resolve) => {
|
|
18
6
|
setTimeout(resolve, mills);
|
|
19
7
|
});
|
|
20
8
|
};
|
|
21
|
-
export const personalizeStep = (signer, step) =>
|
|
9
|
+
export const personalizeStep = async (signer, step) => {
|
|
22
10
|
if (step.action.toAddress && step.action.fromAddress) {
|
|
23
11
|
return step;
|
|
24
12
|
}
|
|
25
|
-
const address =
|
|
13
|
+
const address = await signer.getAddress();
|
|
26
14
|
const fromAddress = step.action.fromAddress || address;
|
|
27
15
|
const toAddress = step.action.toAddress || address;
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
return {
|
|
17
|
+
...step,
|
|
18
|
+
action: {
|
|
19
|
+
...step.action,
|
|
20
|
+
fromAddress,
|
|
21
|
+
toAddress,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
31
25
|
export const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
|
|
32
26
|
const chunkIndex = Math.floor(index / chunkSize);
|
|
33
27
|
if (!resultList[chunkIndex]) {
|
|
@@ -55,7 +49,7 @@ export const formatTokenAmountOnly = (token, amount) => {
|
|
|
55
49
|
}
|
|
56
50
|
// show at least 4 decimal places and at least two non-zero digests
|
|
57
51
|
let decimalPlaces = 3;
|
|
58
|
-
while (floated.lt(1 /
|
|
52
|
+
while (floated.lt(1 / 10 ** decimalPlaces)) {
|
|
59
53
|
decimalPlaces++;
|
|
60
54
|
}
|
|
61
55
|
return floated.toFixed(decimalPlaces + 1, 1);
|
|
@@ -66,27 +60,27 @@ export const formatTokenAmountOnly = (token, amount) => {
|
|
|
66
60
|
* @param timeout The timeout in milliseconds between retries, defaults to 5000
|
|
67
61
|
* @returns The result of the toRepeat function
|
|
68
62
|
*/
|
|
69
|
-
export const repeatUntilDone = (toRepeat, timeout = 5000) =>
|
|
63
|
+
export const repeatUntilDone = async (toRepeat, timeout = 5000) => {
|
|
70
64
|
let result;
|
|
71
65
|
while (!result) {
|
|
72
|
-
result =
|
|
66
|
+
result = await toRepeat();
|
|
73
67
|
if (!result) {
|
|
74
|
-
|
|
68
|
+
await sleep(timeout);
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
71
|
return result;
|
|
78
|
-
}
|
|
72
|
+
};
|
|
79
73
|
/**
|
|
80
74
|
* Loads a transaction receipt using the rpc for the given chain id
|
|
81
75
|
* @param chainId The chain id where the transaction should be loaded from
|
|
82
76
|
* @param txHash The hash of the transaction
|
|
83
77
|
* @returns TransactionReceipt
|
|
84
78
|
*/
|
|
85
|
-
export const loadTransactionReceipt = (chainId, txHash) =>
|
|
86
|
-
const rpc =
|
|
87
|
-
const tx =
|
|
79
|
+
export const loadTransactionReceipt = async (chainId, txHash) => {
|
|
80
|
+
const rpc = await getRpcProvider(chainId);
|
|
81
|
+
const tx = await rpc.getTransaction(txHash);
|
|
88
82
|
return tx.wait();
|
|
89
|
-
}
|
|
83
|
+
};
|
|
90
84
|
export const isZeroAddress = (address) => {
|
|
91
85
|
if (address === constants.AddressZero ||
|
|
92
86
|
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "
|
|
2
|
+
export declare const version = "2.0.0-beta.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '2.0.0-beta.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
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",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"build": "yarn clean && tsc --project ./tsconfig.json && tsc --project ./tsconfig.cjs.json",
|
|
11
11
|
"clean": "node tools/cleanup",
|
|
12
12
|
"package": "npm run build && npm pack",
|
|
13
|
-
"test": "
|
|
13
|
+
"test": "vitest --run --dangerouslyIgnoreUnhandledErrors",
|
|
14
14
|
"test:unit": "yarn test .unit.spec.ts",
|
|
15
|
-
"test:cov": "
|
|
16
|
-
"test:e2e": "
|
|
15
|
+
"test:cov": "yarn test --coverage",
|
|
16
|
+
"test:e2e": "yarn test -c vitest.e2e.config.ts",
|
|
17
17
|
"addscope": "node tools/packagejson name @lifi/sdk",
|
|
18
18
|
"pre-commit": "lint-staged",
|
|
19
19
|
"pre-push": "yarn types:check && yarn build && yarn test:unit",
|
|
@@ -76,36 +76,34 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@ethersproject/abi": "^5.7.0",
|
|
78
78
|
"@ethersproject/contracts": "^5.7.0",
|
|
79
|
-
"@lifi/types": "^
|
|
80
|
-
"
|
|
81
|
-
"bignumber.js": "^9.1.0",
|
|
79
|
+
"@lifi/types": "^2.3.0",
|
|
80
|
+
"bignumber.js": "^9.1.1",
|
|
82
81
|
"eth-rpc-errors": "^4.0.3",
|
|
83
82
|
"ethers": "^5.7.2"
|
|
84
83
|
},
|
|
85
84
|
"devDependencies": {
|
|
86
|
-
"@commitlint/cli": "^17.
|
|
87
|
-
"@commitlint/config-conventional": "^17.
|
|
88
|
-
"@
|
|
89
|
-
"@
|
|
90
|
-
"@
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"eslint": "^8.28.0",
|
|
95
|
-
"eslint-config-prettier": "^8.3.0",
|
|
85
|
+
"@commitlint/cli": "^17.4.4",
|
|
86
|
+
"@commitlint/config-conventional": "^17.4.4",
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
88
|
+
"@typescript-eslint/parser": "^5.54.1",
|
|
89
|
+
"@vitest/coverage-c8": "^0.29.2",
|
|
90
|
+
"cross-fetch": "^3.1.5",
|
|
91
|
+
"eslint": "^8.35.0",
|
|
92
|
+
"eslint-config-prettier": "^8.7.0",
|
|
96
93
|
"eslint-plugin-prettier": "^4.2.1",
|
|
97
|
-
"husky": "^8.0.
|
|
98
|
-
"
|
|
99
|
-
"
|
|
94
|
+
"husky": "^8.0.3",
|
|
95
|
+
"lint-staged": "^13.1.4",
|
|
96
|
+
"msw": "1.0.1",
|
|
100
97
|
"npm-run-all": "^4.1.5",
|
|
101
98
|
"pinst": "^3.0.0",
|
|
102
|
-
"prettier": "^2.8.
|
|
99
|
+
"prettier": "^2.8.4",
|
|
103
100
|
"standard-version": "^9.5.0",
|
|
104
|
-
"ts-
|
|
105
|
-
"
|
|
106
|
-
"
|
|
101
|
+
"ts-loader": "^9.4.2",
|
|
102
|
+
"typescript": "^4.9.5",
|
|
103
|
+
"vitest": "^0.29.2"
|
|
107
104
|
},
|
|
108
105
|
"directories": {
|
|
109
106
|
"test": "test"
|
|
110
|
-
}
|
|
107
|
+
},
|
|
108
|
+
"packageManager": "yarn@3.4.1"
|
|
111
109
|
}
|