@huma-finance/shared 0.0.35 → 0.0.37
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/abis/BaseCreditPool.json +1179 -1179
- package/dist/abis/BaseFeeManager.json +480 -480
- package/dist/abis/BasePoolConfig.json +1364 -1364
- package/dist/abis/ERC20TransferableReceivable.json +648 -648
- package/dist/abis/HDT.json +512 -512
- package/dist/abis/IConstantFlowAgreementV1.json +890 -890
- package/dist/abis/ISuperfluid.json +1122 -1122
- package/dist/abis/InvoiceNFT.json +625 -625
- package/dist/abis/Multisend.json +26 -26
- package/dist/abis/RealWorldReceivable.json +823 -823
- package/dist/abis/ReceivableFactoringPool.json +1529 -1529
- package/dist/abis/StreamFactoringPool.json +1523 -1523
- package/dist/abis/StreamFeeManager.json +522 -522
- package/dist/abis/SuperfluidPoolProcessor.json +692 -692
- package/dist/abis/TestERC20.json +358 -358
- package/dist/abis/TradableStream.json +850 -850
- package/dist/abis/Transfer.json +24 -24
- package/dist/abis/TransferNFT.json +27 -27
- package/dist/abis/erc20.json +127 -117
- package/dist/abis/erc2612.json +132 -132
- package/dist/abis/erc721.json +673 -673
- package/dist/abis/index.js +3 -3
- package/dist/abis/types/BaseCreditPool.js +1 -1
- package/dist/abis/types/BaseFeeManager.js +1 -1
- package/dist/abis/types/BasePoolConfig.js +1 -1
- package/dist/abis/types/ERC20TransferableReceivable.js +1 -1
- package/dist/abis/types/Erc20.d.ts +184 -168
- package/dist/abis/types/Erc20.js +1 -1
- package/dist/abis/types/Erc2612.js +1 -1
- package/dist/abis/types/Erc721.js +1 -1
- package/dist/abis/types/HDT.js +1 -1
- package/dist/abis/types/IConstantFlowAgreementV1.js +1 -1
- package/dist/abis/types/ISuperfluid.js +1 -1
- package/dist/abis/types/InvoiceNFT.js +1 -1
- package/dist/abis/types/Multisend.js +1 -1
- package/dist/abis/types/RealWorldReceivable.js +1 -1
- package/dist/abis/types/ReceivableFactoringPool.js +1 -1
- package/dist/abis/types/StreamFactoringPool.js +1 -1
- package/dist/abis/types/StreamFeeManager.js +1 -1
- package/dist/abis/types/SuperfluidPoolProcessor.js +1 -1
- package/dist/abis/types/TestERC20.js +1 -1
- package/dist/abis/types/TradableStream.js +1 -1
- package/dist/abis/types/Transfer.js +1 -1
- package/dist/abis/types/TransferNFT.js +1 -1
- package/dist/abis/types/common.js +1 -1
- package/dist/abis/types/factories/BaseCreditPool__factory.js +1192 -1193
- package/dist/abis/types/factories/BaseCreditPool__factory.js.map +1 -1
- package/dist/abis/types/factories/BaseFeeManager__factory.js +493 -494
- package/dist/abis/types/factories/BaseFeeManager__factory.js.map +1 -1
- package/dist/abis/types/factories/BasePoolConfig__factory.js +1377 -1378
- package/dist/abis/types/factories/BasePoolConfig__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20TransferableReceivable__factory.js +661 -662
- package/dist/abis/types/factories/ERC20TransferableReceivable__factory.js.map +1 -1
- package/dist/abis/types/factories/Erc20__factory.d.ts +193 -175
- package/dist/abis/types/factories/Erc20__factory.js +259 -236
- package/dist/abis/types/factories/Erc20__factory.js.map +1 -1
- package/dist/abis/types/factories/Erc2612__factory.js +278 -279
- package/dist/abis/types/factories/Erc2612__factory.js.map +1 -1
- package/dist/abis/types/factories/Erc721__factory.js +686 -687
- package/dist/abis/types/factories/Erc721__factory.js.map +1 -1
- package/dist/abis/types/factories/HDT__factory.js +525 -526
- package/dist/abis/types/factories/HDT__factory.js.map +1 -1
- package/dist/abis/types/factories/IConstantFlowAgreementV1__factory.js +903 -904
- package/dist/abis/types/factories/IConstantFlowAgreementV1__factory.js.map +1 -1
- package/dist/abis/types/factories/ISuperfluid__factory.js +1135 -1136
- package/dist/abis/types/factories/ISuperfluid__factory.js.map +1 -1
- package/dist/abis/types/factories/InvoiceNFT__factory.js +638 -639
- package/dist/abis/types/factories/InvoiceNFT__factory.js.map +1 -1
- package/dist/abis/types/factories/Multisend__factory.js +39 -40
- package/dist/abis/types/factories/Multisend__factory.js.map +1 -1
- package/dist/abis/types/factories/RealWorldReceivable__factory.js +836 -837
- package/dist/abis/types/factories/RealWorldReceivable__factory.js.map +1 -1
- package/dist/abis/types/factories/ReceivableFactoringPool__factory.js +1542 -1543
- package/dist/abis/types/factories/ReceivableFactoringPool__factory.js.map +1 -1
- package/dist/abis/types/factories/StreamFactoringPool__factory.js +1536 -1537
- package/dist/abis/types/factories/StreamFactoringPool__factory.js.map +1 -1
- package/dist/abis/types/factories/StreamFeeManager__factory.js +535 -536
- package/dist/abis/types/factories/StreamFeeManager__factory.js.map +1 -1
- package/dist/abis/types/factories/SuperfluidPoolProcessor__factory.js +705 -706
- package/dist/abis/types/factories/SuperfluidPoolProcessor__factory.js.map +1 -1
- package/dist/abis/types/factories/TestERC20__factory.js +371 -372
- package/dist/abis/types/factories/TestERC20__factory.js.map +1 -1
- package/dist/abis/types/factories/TradableStream__factory.js +863 -864
- package/dist/abis/types/factories/TradableStream__factory.js.map +1 -1
- package/dist/abis/types/factories/TransferNFT__factory.js +40 -41
- package/dist/abis/types/factories/TransferNFT__factory.js.map +1 -1
- package/dist/abis/types/factories/Transfer__factory.js +37 -38
- package/dist/abis/types/factories/Transfer__factory.js.map +1 -1
- package/dist/abis/types/factories/index.js +24 -24
- package/dist/abis/types/index.js +22 -22
- package/dist/cjs/abis/erc20.json +10 -0
- package/dist/cjs/abis/types/Erc20.d.ts +17 -1
- package/dist/cjs/abis/types/factories/Erc20__factory.d.ts +18 -0
- package/dist/cjs/abis/types/factories/Erc20__factory.js +24 -0
- package/dist/cjs/abis/types/factories/Erc20__factory.js.map +1 -1
- package/dist/cjs/hooks/useCLPoolContract.d.ts +1 -0
- package/dist/cjs/hooks/usePoolContract.d.ts +1 -0
- package/dist/cjs/hooks/usePoolContract.js +3 -2
- package/dist/cjs/hooks/usePoolContract.js.map +1 -1
- package/dist/cjs/hooks/useRFPoolContract.d.ts +1 -0
- package/dist/cjs/hooks/web3/index.d.ts +1 -5
- package/dist/cjs/hooks/web3/index.js +61 -62
- package/dist/cjs/hooks/web3/index.js.map +1 -1
- package/dist/cjs/hooks/web3/useJsonRpcUrlsMap.js +2 -0
- package/dist/cjs/hooks/web3/useJsonRpcUrlsMap.js.map +1 -1
- package/dist/cjs/utils/chain.d.ts +4 -1
- package/dist/cjs/utils/chain.js +11 -1
- package/dist/cjs/utils/chain.js.map +1 -1
- package/dist/cjs/utils/credit.js +2 -0
- package/dist/cjs/utils/credit.js.map +1 -1
- package/dist/cjs/utils/jsonRpcEndpoints.js +5 -12
- package/dist/cjs/utils/jsonRpcEndpoints.js.map +1 -1
- package/dist/cjs/utils/notifi.d.ts +1 -0
- package/dist/cjs/utils/notifi.js +6 -3
- package/dist/cjs/utils/notifi.js.map +1 -1
- package/dist/cjs/utils/number.d.ts +1 -0
- package/dist/cjs/utils/number.js +16 -3
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/pool.d.ts +3 -2
- package/dist/cjs/utils/pool.js +33 -75
- package/dist/cjs/utils/pool.js.map +1 -1
- package/dist/cjs/utils/realWorldReceivable.d.ts +2 -2
- package/dist/hooks/index.js +18 -18
- package/dist/hooks/useActiveRoute.js +7 -7
- package/dist/hooks/useAsyncError.js +22 -22
- package/dist/hooks/useCLPoolContract.d.ts +28 -27
- package/dist/hooks/useContractFunction.js +54 -54
- package/dist/hooks/useERC2612Permit/ethPermit/index.js +139 -139
- package/dist/hooks/useERC2612Permit/ethPermit/lib.js +21 -21
- package/dist/hooks/useERC2612Permit/ethPermit/rpc.js +96 -96
- package/dist/hooks/useERC2612Permit/index.js +31 -31
- package/dist/hooks/useForceRefresh.js +8 -8
- package/dist/hooks/useGetSizes.js +19 -19
- package/dist/hooks/useMQ.js +14 -14
- package/dist/hooks/useMount.js +8 -8
- package/dist/hooks/useParamsSearch.js +6 -6
- package/dist/hooks/usePoolContract.d.ts +74 -73
- package/dist/hooks/usePoolContract.js +3 -2
- package/dist/hooks/usePoolContract.js.map +1 -1
- package/dist/hooks/useRFPoolContract.d.ts +23 -22
- package/dist/hooks/useRefresh.js +47 -47
- package/dist/hooks/web3/index.d.ts +11 -15
- package/dist/hooks/web3/index.js +60 -61
- package/dist/hooks/web3/index.js.map +1 -1
- package/dist/hooks/web3/useConnectors.js +24 -24
- package/dist/hooks/web3/useJsonRpcUrlsMap.js +2 -0
- package/dist/hooks/web3/useJsonRpcUrlsMap.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/JsonRpcConnector.js +38 -38
- package/dist/utils/WalletConnect.js +49 -50
- package/dist/utils/WalletConnect.js.map +1 -1
- package/dist/utils/chain.d.ts +4 -1
- package/dist/utils/chain.js +9 -0
- package/dist/utils/chain.js.map +1 -1
- package/dist/utils/common.js +10 -10
- package/dist/utils/const.js +2 -2
- package/dist/utils/contractError.json +73 -73
- package/dist/utils/credit.js +37 -35
- package/dist/utils/credit.js.map +1 -1
- package/dist/utils/errors.js +39 -39
- package/dist/utils/jsonRpcEndpoints.js +5 -12
- package/dist/utils/jsonRpcEndpoints.js.map +1 -1
- package/dist/utils/notifi.d.ts +1 -0
- package/dist/utils/notifi.js +4 -2
- package/dist/utils/notifi.js.map +1 -1
- package/dist/utils/number.d.ts +6 -5
- package/dist/utils/number.js +14 -2
- package/dist/utils/number.js.map +1 -1
- package/dist/utils/pool.d.ts +3 -2
- package/dist/utils/pool.js +33 -75
- package/dist/utils/pool.js.map +1 -1
- package/dist/utils/realWorldReceivable.d.ts +2 -2
- package/dist/utils/request.js +38 -38
- package/dist/utils/scientificToDecimal.js +57 -57
- package/dist/utils/string.js +1 -1
- package/dist/utils/style.js +12 -12
- package/dist/utils/time.js +50 -50
- package/dist/utils/transaction.js +87 -87
- package/dist/utils/web3.js +34 -34
- package/package.json +5 -4
package/dist/utils/time.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
import { isEmpty } from './common';
|
|
3
|
-
export const MILLISECONDS = 1000;
|
|
4
|
-
export const DAY_SECONDS = 24 * 60 * 60;
|
|
5
|
-
export const TIME_FORMAT_LL = 'll';
|
|
6
|
-
export const timestampToStr = (timestamp, format) => moment.unix(timestamp).format(format);
|
|
7
|
-
/**
|
|
8
|
-
* Convert timestamp to format ll: Nov 12, 2022
|
|
9
|
-
*
|
|
10
|
-
* @param timestamp
|
|
11
|
-
* @returns format ll: Nov 12, 2022
|
|
12
|
-
*/
|
|
13
|
-
export const timestampToLL = (timestamp) => {
|
|
14
|
-
if (!timestamp) {
|
|
15
|
-
return '';
|
|
16
|
-
}
|
|
17
|
-
return timestampToStr(timestamp, TIME_FORMAT_LL);
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* get unix time in seconds
|
|
21
|
-
*
|
|
22
|
-
* @returns timestamp
|
|
23
|
-
*/
|
|
24
|
-
export const getUnixTimestamp = (date) => {
|
|
25
|
-
if (date) {
|
|
26
|
-
return date.unix();
|
|
27
|
-
}
|
|
28
|
-
return Math.floor(Date.now() / MILLISECONDS);
|
|
29
|
-
};
|
|
30
|
-
export const secondsToDays = (seconds) => {
|
|
31
|
-
if (isEmpty(seconds)) {
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
return seconds / DAY_SECONDS;
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
// eslint-disable-next-line no-promise-executor-return
|
|
43
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
44
|
-
export const timeUtil = {
|
|
45
|
-
timestampToStr,
|
|
46
|
-
timestampToLL,
|
|
47
|
-
getUnixTimestamp,
|
|
48
|
-
secondsToDays,
|
|
49
|
-
sleep,
|
|
50
|
-
};
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { isEmpty } from './common';
|
|
3
|
+
export const MILLISECONDS = 1000;
|
|
4
|
+
export const DAY_SECONDS = 24 * 60 * 60;
|
|
5
|
+
export const TIME_FORMAT_LL = 'll';
|
|
6
|
+
export const timestampToStr = (timestamp, format) => moment.unix(timestamp).format(format);
|
|
7
|
+
/**
|
|
8
|
+
* Convert timestamp to format ll: Nov 12, 2022
|
|
9
|
+
*
|
|
10
|
+
* @param timestamp
|
|
11
|
+
* @returns format ll: Nov 12, 2022
|
|
12
|
+
*/
|
|
13
|
+
export const timestampToLL = (timestamp) => {
|
|
14
|
+
if (!timestamp) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
return timestampToStr(timestamp, TIME_FORMAT_LL);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* get unix time in seconds
|
|
21
|
+
*
|
|
22
|
+
* @returns timestamp
|
|
23
|
+
*/
|
|
24
|
+
export const getUnixTimestamp = (date) => {
|
|
25
|
+
if (date) {
|
|
26
|
+
return date.unix();
|
|
27
|
+
}
|
|
28
|
+
return Math.floor(Date.now() / MILLISECONDS);
|
|
29
|
+
};
|
|
30
|
+
export const secondsToDays = (seconds) => {
|
|
31
|
+
if (isEmpty(seconds)) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return seconds / DAY_SECONDS;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
43
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
44
|
+
export const timeUtil = {
|
|
45
|
+
timestampToStr,
|
|
46
|
+
timestampToLL,
|
|
47
|
+
getUnixTimestamp,
|
|
48
|
+
secondsToDays,
|
|
49
|
+
sleep,
|
|
50
|
+
};
|
|
51
51
|
//# sourceMappingURL=time.js.map
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import TxErrors from './contractError.json';
|
|
3
|
-
import { capitalizeFirstLetter } from './string';
|
|
4
|
-
export var TxStateType;
|
|
5
|
-
(function (TxStateType) {
|
|
6
|
-
TxStateType["Success"] = "Success";
|
|
7
|
-
TxStateType["Denied"] = "Denied";
|
|
8
|
-
TxStateType["Invalid"] = "Invalid";
|
|
9
|
-
TxStateType["Failed"] = "Failed";
|
|
10
|
-
TxStateType["New"] = "New";
|
|
11
|
-
TxStateType["GasEstimating"] = "GasEstimating";
|
|
12
|
-
TxStateType["Signing"] = "Signing";
|
|
13
|
-
TxStateType["Confirming"] = "Confirming";
|
|
14
|
-
})(TxStateType || (TxStateType = {}));
|
|
15
|
-
export const isTxFailed = (txState) => [TxStateType.Denied, TxStateType.Invalid, TxStateType.Failed].includes(txState);
|
|
16
|
-
export const increaseGasLimit = (estimatedGasLimit) => {
|
|
17
|
-
if (!estimatedGasLimit || Number.isNaN(estimatedGasLimit.toNumber())) {
|
|
18
|
-
console.log('estimatedGasLimit', estimatedGasLimit);
|
|
19
|
-
throw new Error('Estimated gas limited error.');
|
|
20
|
-
}
|
|
21
|
-
return estimatedGasLimit.mul(150).div(100);
|
|
22
|
-
};
|
|
23
|
-
const parseErrorMessageToUserFriendlyMessage = (message) => capitalizeFirstLetter(message
|
|
24
|
-
.replace('()', '')
|
|
25
|
-
.split(/(?=[A-Z])/)
|
|
26
|
-
.join(' ')
|
|
27
|
-
.toLowerCase());
|
|
28
|
-
const findContractErrorMessage = (code) => {
|
|
29
|
-
let reason = null;
|
|
30
|
-
Object.keys(TxErrors).forEach((key) => {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
if (code.toLowerCase() === TxErrors[key].toLowerCase()) {
|
|
33
|
-
reason = parseErrorMessageToUserFriendlyMessage(key);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return reason;
|
|
37
|
-
};
|
|
38
|
-
export const getTransactionErrorFromHash = async (provider, txHash) => {
|
|
39
|
-
const commonErrorMessage = 'Send transaction failed';
|
|
40
|
-
try {
|
|
41
|
-
const originTx = await provider.getTransaction(txHash);
|
|
42
|
-
const { from, to, data, gasLimit, blockNumber } = originTx;
|
|
43
|
-
// Only provide necessary params to get the tx return which can avoid unexpected error
|
|
44
|
-
const tx = { from, to, data, gasLimit };
|
|
45
|
-
const code = await provider.call(tx, blockNumber);
|
|
46
|
-
const reason = findContractErrorMessage(code);
|
|
47
|
-
return reason !== null && reason !== void 0 ? reason : commonErrorMessage;
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
if (!error.data) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
return commonErrorMessage;
|
|
54
|
-
}
|
|
55
|
-
const code = error.data.replace('Reverted ', '');
|
|
56
|
-
const reason = ethers.utils.toUtf8String(`0x${code.substr(138)}`);
|
|
57
|
-
return reason;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
export const getTransactionErrorFromError = (e) => {
|
|
62
|
-
var _a, _b, _c, _d, _e;
|
|
63
|
-
const errorCode = ((_c = (_b = (_a = e.error) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.originalError) === null || _c === void 0 ? void 0 : _c.data) || ((_e = (_d = e.error) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.data);
|
|
64
|
-
if (errorCode) {
|
|
65
|
-
const contractErrorMessage = findContractErrorMessage(errorCode);
|
|
66
|
-
if (contractErrorMessage) {
|
|
67
|
-
return contractErrorMessage;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
};
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
export const decodeLogs = (txlogs, abi) => {
|
|
74
|
-
const result = [];
|
|
75
|
-
const iface = new ethers.utils.Interface(abi);
|
|
76
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
77
|
-
for (const log of txlogs) {
|
|
78
|
-
try {
|
|
79
|
-
result.push(iface.parseLog(log));
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error(error);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import TxErrors from './contractError.json';
|
|
3
|
+
import { capitalizeFirstLetter } from './string';
|
|
4
|
+
export var TxStateType;
|
|
5
|
+
(function (TxStateType) {
|
|
6
|
+
TxStateType["Success"] = "Success";
|
|
7
|
+
TxStateType["Denied"] = "Denied";
|
|
8
|
+
TxStateType["Invalid"] = "Invalid";
|
|
9
|
+
TxStateType["Failed"] = "Failed";
|
|
10
|
+
TxStateType["New"] = "New";
|
|
11
|
+
TxStateType["GasEstimating"] = "GasEstimating";
|
|
12
|
+
TxStateType["Signing"] = "Signing";
|
|
13
|
+
TxStateType["Confirming"] = "Confirming";
|
|
14
|
+
})(TxStateType || (TxStateType = {}));
|
|
15
|
+
export const isTxFailed = (txState) => [TxStateType.Denied, TxStateType.Invalid, TxStateType.Failed].includes(txState);
|
|
16
|
+
export const increaseGasLimit = (estimatedGasLimit) => {
|
|
17
|
+
if (!estimatedGasLimit || Number.isNaN(estimatedGasLimit.toNumber())) {
|
|
18
|
+
console.log('estimatedGasLimit', estimatedGasLimit);
|
|
19
|
+
throw new Error('Estimated gas limited error.');
|
|
20
|
+
}
|
|
21
|
+
return estimatedGasLimit.mul(150).div(100);
|
|
22
|
+
};
|
|
23
|
+
const parseErrorMessageToUserFriendlyMessage = (message) => capitalizeFirstLetter(message
|
|
24
|
+
.replace('()', '')
|
|
25
|
+
.split(/(?=[A-Z])/)
|
|
26
|
+
.join(' ')
|
|
27
|
+
.toLowerCase());
|
|
28
|
+
const findContractErrorMessage = (code) => {
|
|
29
|
+
let reason = null;
|
|
30
|
+
Object.keys(TxErrors).forEach((key) => {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
if (code.toLowerCase() === TxErrors[key].toLowerCase()) {
|
|
33
|
+
reason = parseErrorMessageToUserFriendlyMessage(key);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return reason;
|
|
37
|
+
};
|
|
38
|
+
export const getTransactionErrorFromHash = async (provider, txHash) => {
|
|
39
|
+
const commonErrorMessage = 'Send transaction failed';
|
|
40
|
+
try {
|
|
41
|
+
const originTx = await provider.getTransaction(txHash);
|
|
42
|
+
const { from, to, data, gasLimit, blockNumber } = originTx;
|
|
43
|
+
// Only provide necessary params to get the tx return which can avoid unexpected error
|
|
44
|
+
const tx = { from, to, data, gasLimit };
|
|
45
|
+
const code = await provider.call(tx, blockNumber);
|
|
46
|
+
const reason = findContractErrorMessage(code);
|
|
47
|
+
return reason !== null && reason !== void 0 ? reason : commonErrorMessage;
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (!error.data) {
|
|
52
|
+
console.error(error);
|
|
53
|
+
return commonErrorMessage;
|
|
54
|
+
}
|
|
55
|
+
const code = error.data.replace('Reverted ', '');
|
|
56
|
+
const reason = ethers.utils.toUtf8String(`0x${code.substr(138)}`);
|
|
57
|
+
return reason;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
export const getTransactionErrorFromError = (e) => {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
const errorCode = ((_c = (_b = (_a = e.error) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.originalError) === null || _c === void 0 ? void 0 : _c.data) || ((_e = (_d = e.error) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.data);
|
|
64
|
+
if (errorCode) {
|
|
65
|
+
const contractErrorMessage = findContractErrorMessage(errorCode);
|
|
66
|
+
if (contractErrorMessage) {
|
|
67
|
+
return contractErrorMessage;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
export const decodeLogs = (txlogs, abi) => {
|
|
74
|
+
const result = [];
|
|
75
|
+
const iface = new ethers.utils.Interface(abi);
|
|
76
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
77
|
+
for (const log of txlogs) {
|
|
78
|
+
try {
|
|
79
|
+
result.push(iface.parseLog(log));
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
88
|
//# sourceMappingURL=transaction.js.map
|
package/dist/utils/web3.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Contract } from '@ethersproject/contracts';
|
|
2
|
-
import { AddressZero } from '@ethersproject/constants';
|
|
3
|
-
import { getAddress } from '@ethersproject/address';
|
|
4
|
-
// returns the checksummed address if the address is valid, otherwise returns false
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
export function isAddress(value) {
|
|
7
|
-
try {
|
|
8
|
-
// Alphabetical letters must be made lowercase for getAddress to work.
|
|
9
|
-
// See documentation here: https://docs.ethers.io/v5/api/utils/address/
|
|
10
|
-
return getAddress(value.toLowerCase());
|
|
11
|
-
}
|
|
12
|
-
catch (_a) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// account is not optional
|
|
17
|
-
function getSigner(provider, account) {
|
|
18
|
-
return provider.getSigner(account).connectUnchecked();
|
|
19
|
-
}
|
|
20
|
-
// account is optional
|
|
21
|
-
function getProviderOrSigner(provider, account) {
|
|
22
|
-
return account ? getSigner(provider, account) : provider;
|
|
23
|
-
}
|
|
24
|
-
// account is optional
|
|
25
|
-
export function getContract(address,
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
ABI, provider, account) {
|
|
28
|
-
if (!isAddress(address) || address === AddressZero) {
|
|
29
|
-
throw Error(`Invalid 'address' parameter '${address}'.`);
|
|
30
|
-
}
|
|
31
|
-
return new Contract(address, ABI,
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
getProviderOrSigner(provider, account));
|
|
34
|
-
}
|
|
1
|
+
import { Contract } from '@ethersproject/contracts';
|
|
2
|
+
import { AddressZero } from '@ethersproject/constants';
|
|
3
|
+
import { getAddress } from '@ethersproject/address';
|
|
4
|
+
// returns the checksummed address if the address is valid, otherwise returns false
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
export function isAddress(value) {
|
|
7
|
+
try {
|
|
8
|
+
// Alphabetical letters must be made lowercase for getAddress to work.
|
|
9
|
+
// See documentation here: https://docs.ethers.io/v5/api/utils/address/
|
|
10
|
+
return getAddress(value.toLowerCase());
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// account is not optional
|
|
17
|
+
function getSigner(provider, account) {
|
|
18
|
+
return provider.getSigner(account).connectUnchecked();
|
|
19
|
+
}
|
|
20
|
+
// account is optional
|
|
21
|
+
function getProviderOrSigner(provider, account) {
|
|
22
|
+
return account ? getSigner(provider, account) : provider;
|
|
23
|
+
}
|
|
24
|
+
// account is optional
|
|
25
|
+
export function getContract(address,
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
ABI, provider, account) {
|
|
28
|
+
if (!isAddress(address) || address === AddressZero) {
|
|
29
|
+
throw Error(`Invalid 'address' parameter '${address}'.`);
|
|
30
|
+
}
|
|
31
|
+
return new Contract(address, ABI,
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
getProviderOrSigner(provider, account));
|
|
34
|
+
}
|
|
35
35
|
//# sourceMappingURL=web3.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
"postbuild": "copyfiles -u 1 ./src/components/icons/*.svg dist",
|
|
13
13
|
"build": "tsc --project ./tsconfig.build.json && tsc --project ./tsconfig.cjs.json",
|
|
14
14
|
"contracts:compile:abi": "typechain --target ethers-v5 --out-dir src/abis/types \"./src/abis/**/*.json\"",
|
|
15
|
+
"lint": "eslint --max-warnings=0 \"src/**/*.{js,ts,tsx,graphql}\" \"tests/**/*.{js,ts,tsx,graphql}\"",
|
|
15
16
|
"lint-staged": "lint-staged",
|
|
16
|
-
"prettier": "prettier --write \"
|
|
17
|
+
"prettier": "prettier --write \"**/*.{js,ts,tsx,graphql}\"",
|
|
17
18
|
"test": "jest",
|
|
18
19
|
"test:coverage": "jest --verbose --coverage"
|
|
19
20
|
},
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
"lint-staged": {
|
|
87
|
-
"
|
|
88
|
+
"**/*.{js,ts,tsx,graphql}": [
|
|
88
89
|
"eslint --fix --max-warnings=0",
|
|
89
90
|
"prettier --write",
|
|
90
91
|
"git add .",
|
|
@@ -149,5 +150,5 @@
|
|
|
149
150
|
"optionalDependencies": {
|
|
150
151
|
"encoding": "^0.1.13"
|
|
151
152
|
},
|
|
152
|
-
"gitHead": "
|
|
153
|
+
"gitHead": "7ec34fafed3ca19acf9e1be6e3de27d6a03460a5"
|
|
153
154
|
}
|