@human-protocol/sdk 1.1.18 → 2.0.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/base.d.ts +4 -13
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +3 -18
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +18 -11
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +4 -2
- package/dist/encryption.d.ts +31 -0
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +37 -0
- package/dist/error.d.ts +0 -10
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -18
- package/dist/escrow.d.ts +39 -33
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +121 -137
- package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -0
- package/dist/graphql/queries/{staking.js → operator.js} +24 -1
- package/dist/graphql/types.d.ts +5 -6
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +28 -18
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +14 -14
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +30 -48
- package/dist/operator.d.ts +68 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +153 -0
- package/dist/staking.d.ts +35 -95
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +73 -201
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +7 -6
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -15
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -49
- package/package.json +4 -4
- package/src/base.ts +5 -30
- package/src/constants.ts +18 -10
- package/src/decorators.ts +3 -2
- package/src/encryption.ts +40 -0
- package/src/error.ts +0 -17
- package/src/escrow.ts +169 -178
- package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
- package/src/graphql/types.ts +5 -7
- package/src/index.ts +2 -0
- package/src/interfaces.ts +30 -18
- package/src/kvstore.ts +47 -59
- package/src/operator.ts +192 -0
- package/src/staking.ts +101 -213
- package/src/statistics.ts +8 -9
- package/src/types.ts +1 -3
- package/src/utils.ts +8 -58
- package/dist/graphql/queries/staking.d.ts.map +0 -1
package/src/utils.ts
CHANGED
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
import { BigNumber, Signer, ethers } from 'ethers';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
4
3
|
|
|
5
4
|
import {
|
|
6
5
|
ContractExecutionError,
|
|
7
|
-
ErrorMissingGasPrice,
|
|
8
6
|
EthereumError,
|
|
9
7
|
InvalidArgumentError,
|
|
10
8
|
NonceExpired,
|
|
11
9
|
NumericFault,
|
|
12
|
-
OutOfGasError,
|
|
13
10
|
ReplacementUnderpriced,
|
|
14
11
|
TransactionReplaced,
|
|
15
|
-
UnpredictableGasLimit,
|
|
16
12
|
} from './error';
|
|
17
13
|
|
|
18
|
-
/**
|
|
19
|
-
* **Get specific error text.*
|
|
20
|
-
*
|
|
21
|
-
* @param {any} error - An error message.
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
export const getRevertReason = (error: any): string => {
|
|
25
|
-
const prefix = "reverted with reason string '";
|
|
26
|
-
const suffix = "'";
|
|
27
|
-
const message = error.data.substring(
|
|
28
|
-
error.data.indexOf(prefix) + prefix.length
|
|
29
|
-
);
|
|
30
|
-
return message.substring(0, message.indexOf(suffix));
|
|
31
|
-
};
|
|
32
|
-
|
|
33
14
|
/**
|
|
34
15
|
* **Handle and throw the error.*
|
|
35
16
|
*
|
|
@@ -37,22 +18,17 @@ export const getRevertReason = (error: any): string => {
|
|
|
37
18
|
* @returns
|
|
38
19
|
*/
|
|
39
20
|
export const throwError = (e: any) => {
|
|
40
|
-
if (e
|
|
21
|
+
if (ethers.isError(e, 'INVALID_ARGUMENT')) {
|
|
41
22
|
throw new InvalidArgumentError(e.message);
|
|
42
|
-
} else if (e
|
|
43
|
-
throw new
|
|
44
|
-
} else if (e
|
|
45
|
-
const reason = getRevertReason(e.data);
|
|
46
|
-
throw new ContractExecutionError(reason);
|
|
47
|
-
} else if (e.code === ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
|
|
48
|
-
throw new UnpredictableGasLimit(e.message);
|
|
49
|
-
} else if (e.code === ethers.utils.Logger.errors.TRANSACTION_REPLACED) {
|
|
23
|
+
} else if (ethers.isError(e, 'CALL_EXCEPTION')) {
|
|
24
|
+
throw new ContractExecutionError(e.reason as string);
|
|
25
|
+
} else if (ethers.isError(e, 'TRANSACTION_REPLACED')) {
|
|
50
26
|
throw new TransactionReplaced(e.message);
|
|
51
|
-
} else if (e
|
|
27
|
+
} else if (ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {
|
|
52
28
|
throw new ReplacementUnderpriced(e.message);
|
|
53
|
-
} else if (e
|
|
29
|
+
} else if (ethers.isError(e, 'NUMERIC_FAULT')) {
|
|
54
30
|
throw new NumericFault(e.message);
|
|
55
|
-
} else if (e
|
|
31
|
+
} else if (ethers.isError(e, 'NONCE_EXPIRED')) {
|
|
56
32
|
throw new NonceExpired(e.message);
|
|
57
33
|
} else {
|
|
58
34
|
throw new EthereumError(e.message);
|
|
@@ -73,29 +49,3 @@ export const isValidUrl = (url: string) => {
|
|
|
73
49
|
return false;
|
|
74
50
|
}
|
|
75
51
|
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Increase/Decrease gas price
|
|
79
|
-
*
|
|
80
|
-
* @returns {Promise<BigNumber>} Returns the adjusted gas price
|
|
81
|
-
*/
|
|
82
|
-
export const gasPriceAdjusted = async (
|
|
83
|
-
signerOrProvider: Signer | Provider,
|
|
84
|
-
gasPriceMultiplier: number
|
|
85
|
-
): Promise<BigNumber> => {
|
|
86
|
-
let gasPrice;
|
|
87
|
-
|
|
88
|
-
if (Signer.isSigner(signerOrProvider)) {
|
|
89
|
-
gasPrice = (await signerOrProvider.provider?.getFeeData())?.gasPrice;
|
|
90
|
-
} else {
|
|
91
|
-
gasPrice = (await signerOrProvider.getFeeData()).gasPrice;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!gasPrice) {
|
|
95
|
-
throw ErrorMissingGasPrice;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return gasPrice
|
|
99
|
-
.mul(ethers.utils.parseEther(gasPriceMultiplier.toString()))
|
|
100
|
-
.div(ethers.utils.parseEther('1'));
|
|
101
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/staking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAuBhD,eAAO,MAAM,iBAAiB,WAAY,cAAc,mCAuBvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,gCAO5B,CAAC"}
|