@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.
Files changed (61) hide show
  1. package/dist/base.d.ts +4 -13
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +3 -18
  4. package/dist/constants.d.ts +7 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +18 -11
  7. package/dist/decorators.d.ts.map +1 -1
  8. package/dist/decorators.js +4 -2
  9. package/dist/encryption.d.ts +31 -0
  10. package/dist/encryption.d.ts.map +1 -1
  11. package/dist/encryption.js +37 -0
  12. package/dist/error.d.ts +0 -10
  13. package/dist/error.d.ts.map +1 -1
  14. package/dist/error.js +2 -18
  15. package/dist/escrow.d.ts +39 -33
  16. package/dist/escrow.d.ts.map +1 -1
  17. package/dist/escrow.js +121 -137
  18. package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
  19. package/dist/graphql/queries/operator.d.ts.map +1 -0
  20. package/dist/graphql/queries/{staking.js → operator.js} +24 -1
  21. package/dist/graphql/types.d.ts +5 -6
  22. package/dist/graphql/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -1
  26. package/dist/interfaces.d.ts +28 -18
  27. package/dist/interfaces.d.ts.map +1 -1
  28. package/dist/kvstore.d.ts +14 -14
  29. package/dist/kvstore.d.ts.map +1 -1
  30. package/dist/kvstore.js +30 -48
  31. package/dist/operator.d.ts +68 -0
  32. package/dist/operator.d.ts.map +1 -0
  33. package/dist/operator.js +153 -0
  34. package/dist/staking.d.ts +35 -95
  35. package/dist/staking.d.ts.map +1 -1
  36. package/dist/staking.js +73 -201
  37. package/dist/statistics.d.ts.map +1 -1
  38. package/dist/statistics.js +7 -6
  39. package/dist/types.d.ts +1 -2
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -15
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +9 -49
  44. package/package.json +4 -4
  45. package/src/base.ts +5 -30
  46. package/src/constants.ts +18 -10
  47. package/src/decorators.ts +3 -2
  48. package/src/encryption.ts +40 -0
  49. package/src/error.ts +0 -17
  50. package/src/escrow.ts +169 -178
  51. package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
  52. package/src/graphql/types.ts +5 -7
  53. package/src/index.ts +2 -0
  54. package/src/interfaces.ts +30 -18
  55. package/src/kvstore.ts +47 -59
  56. package/src/operator.ts +192 -0
  57. package/src/staking.ts +101 -213
  58. package/src/statistics.ts +8 -9
  59. package/src/types.ts +1 -3
  60. package/src/utils.ts +8 -58
  61. 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 { Provider } from '@ethersproject/abstract-provider';
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.code === ethers.utils.Logger.errors.INVALID_ARGUMENT) {
21
+ if (ethers.isError(e, 'INVALID_ARGUMENT')) {
41
22
  throw new InvalidArgumentError(e.message);
42
- } else if (e.code === 'OUT_OF_GAS') {
43
- throw new OutOfGasError(e.message);
44
- } else if (e.code === ethers.utils.Logger.errors.CALL_EXCEPTION) {
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.code === ethers.utils.Logger.errors.REPLACEMENT_UNDERPRICED) {
27
+ } else if (ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {
52
28
  throw new ReplacementUnderpriced(e.message);
53
- } else if (e.code === ethers.utils.Logger.errors.NUMERIC_FAULT) {
29
+ } else if (ethers.isError(e, 'NUMERIC_FAULT')) {
54
30
  throw new NumericFault(e.message);
55
- } else if (e.code === ethers.utils.Logger.errors.NONCE_EXPIRED) {
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"}