@human-protocol/sdk 6.0.0 → 7.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 (129) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/base.d.ts +4 -2
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +14 -0
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +27 -16
  8. package/dist/encryption/encryption.d.ts +84 -0
  9. package/dist/encryption/encryption.d.ts.map +1 -0
  10. package/dist/{encryption.js → encryption/encryption.js} +3 -161
  11. package/dist/encryption/encryption_utils.d.ts +101 -0
  12. package/dist/encryption/encryption_utils.d.ts.map +1 -0
  13. package/dist/encryption/encryption_utils.js +191 -0
  14. package/dist/encryption/index.d.ts +4 -0
  15. package/dist/encryption/index.d.ts.map +1 -0
  16. package/dist/encryption/index.js +7 -0
  17. package/dist/encryption/types.d.ts +9 -0
  18. package/dist/encryption/types.d.ts.map +1 -0
  19. package/dist/encryption/types.js +9 -0
  20. package/dist/error.d.ts +6 -10
  21. package/dist/error.d.ts.map +1 -1
  22. package/dist/error.js +12 -14
  23. package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +16 -196
  24. package/dist/escrow/escrow_client.d.ts.map +1 -0
  25. package/dist/{escrow.js → escrow/escrow_client.js} +50 -430
  26. package/dist/escrow/escrow_utils.d.ts +172 -0
  27. package/dist/escrow/escrow_utils.d.ts.map +1 -0
  28. package/dist/escrow/escrow_utils.js +388 -0
  29. package/dist/escrow/index.d.ts +3 -0
  30. package/dist/escrow/index.d.ts.map +1 -0
  31. package/dist/escrow/index.js +7 -0
  32. package/dist/graphql/queries/statistics.d.ts +1 -0
  33. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  34. package/dist/graphql/queries/statistics.js +36 -2
  35. package/dist/graphql/types.d.ts +3 -1
  36. package/dist/graphql/types.d.ts.map +1 -1
  37. package/dist/index.d.ts +10 -10
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +23 -22
  40. package/dist/interfaces.d.ts +2 -7
  41. package/dist/interfaces.d.ts.map +1 -1
  42. package/dist/kvstore/index.d.ts +3 -0
  43. package/dist/kvstore/index.d.ts.map +1 -0
  44. package/dist/kvstore/index.js +7 -0
  45. package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +7 -112
  46. package/dist/kvstore/kvstore_client.d.ts.map +1 -0
  47. package/dist/{kvstore.js → kvstore/kvstore_client.js} +25 -187
  48. package/dist/kvstore/kvstore_utils.d.ts +105 -0
  49. package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
  50. package/dist/kvstore/kvstore_utils.js +184 -0
  51. package/dist/operator/index.d.ts +2 -0
  52. package/dist/operator/index.d.ts.map +1 -0
  53. package/dist/operator/index.js +5 -0
  54. package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
  55. package/dist/operator/operator_utils.d.ts.map +1 -0
  56. package/dist/{operator.js → operator/operator_utils.js} +6 -6
  57. package/dist/staking/index.d.ts +3 -0
  58. package/dist/staking/index.d.ts.map +1 -0
  59. package/dist/staking/index.js +7 -0
  60. package/dist/{staking.d.ts → staking/staking_client.d.ts} +10 -71
  61. package/dist/staking/staking_client.d.ts.map +1 -0
  62. package/dist/{staking.js → staking/staking_client.js} +11 -141
  63. package/dist/staking/staking_utils.d.ts +63 -0
  64. package/dist/staking/staking_utils.d.ts.map +1 -0
  65. package/dist/staking/staking_utils.js +137 -0
  66. package/dist/statistics/index.d.ts +2 -0
  67. package/dist/statistics/index.d.ts.map +1 -0
  68. package/dist/statistics/index.js +5 -0
  69. package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
  70. package/dist/statistics/statistics_utils.d.ts.map +1 -0
  71. package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
  72. package/dist/transaction/index.d.ts +2 -0
  73. package/dist/transaction/index.d.ts.map +1 -0
  74. package/dist/transaction/index.js +5 -0
  75. package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +5 -5
  76. package/dist/transaction/transaction_utils.d.ts.map +1 -0
  77. package/dist/{transaction.js → transaction/transaction_utils.js} +9 -9
  78. package/dist/types.d.ts +22 -1
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/utils.d.ts +16 -1
  81. package/dist/utils.d.ts.map +1 -1
  82. package/dist/utils.js +72 -6
  83. package/dist/worker/index.d.ts +2 -0
  84. package/dist/worker/index.d.ts.map +1 -0
  85. package/dist/worker/index.js +5 -0
  86. package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -3
  87. package/dist/worker/worker_utils.d.ts.map +1 -0
  88. package/dist/{worker.js → worker/worker_utils.js} +5 -5
  89. package/package.json +5 -5
  90. package/src/base.ts +38 -2
  91. package/src/constants.ts +38 -16
  92. package/src/{encryption.ts → encryption/encryption.ts} +1 -193
  93. package/src/encryption/encryption_utils.ts +179 -0
  94. package/src/encryption/index.ts +3 -0
  95. package/src/encryption/types.ts +15 -0
  96. package/src/error.ts +11 -17
  97. package/src/{escrow.ts → escrow/escrow_client.ts} +151 -659
  98. package/src/escrow/escrow_utils.ts +510 -0
  99. package/src/escrow/index.ts +2 -0
  100. package/src/graphql/queries/statistics.ts +37 -1
  101. package/src/graphql/types.ts +4 -1
  102. package/src/index.ts +11 -25
  103. package/src/interfaces.ts +2 -7
  104. package/src/kvstore/index.ts +2 -0
  105. package/src/kvstore/kvstore_client.ts +291 -0
  106. package/src/kvstore/kvstore_utils.ts +244 -0
  107. package/src/operator/index.ts +1 -0
  108. package/src/{operator.ts → operator/operator_utils.ts} +8 -8
  109. package/src/staking/index.ts +2 -0
  110. package/src/{staking.ts → staking/staking_client.ts} +49 -199
  111. package/src/staking/staking_utils.ts +170 -0
  112. package/src/statistics/index.ts +1 -0
  113. package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
  114. package/src/transaction/index.ts +1 -0
  115. package/src/{transaction.ts → transaction/transaction_utils.ts} +11 -11
  116. package/src/types.ts +24 -1
  117. package/src/utils.ts +82 -9
  118. package/src/worker/index.ts +1 -0
  119. package/src/{worker.ts → worker/worker_utils.ts} +7 -7
  120. package/dist/encryption.d.ts +0 -189
  121. package/dist/encryption.d.ts.map +0 -1
  122. package/dist/escrow.d.ts.map +0 -1
  123. package/dist/kvstore.d.ts.map +0 -1
  124. package/dist/operator.d.ts.map +0 -1
  125. package/dist/staking.d.ts.map +0 -1
  126. package/dist/statistics.d.ts.map +0 -1
  127. package/dist/transaction.d.ts.map +0 -1
  128. package/dist/worker.d.ts.map +0 -1
  129. package/src/kvstore.ts +0 -497
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TransactionLike } from 'ethers';
1
+ import { Overrides, TransactionLike } from 'ethers';
2
2
  /**
3
3
  * Enum for escrow statuses.
4
4
  * @readonly
@@ -74,6 +74,14 @@ export type NetworkData = {
74
74
  * Subgraph URL API key
75
75
  */
76
76
  subgraphUrlApiKey: string;
77
+ /**
78
+ * HMT statistics subgraph URL
79
+ */
80
+ hmtSubgraphUrl?: string;
81
+ /**
82
+ * HMT statistics subgraph URL API key
83
+ */
84
+ hmtSubgraphUrlApiKey?: string;
77
85
  /**
78
86
  * Old subgraph URL
79
87
  */
@@ -83,6 +91,19 @@ export type NetworkData = {
83
91
  */
84
92
  oldFactoryAddress: string;
85
93
  };
94
+ /**
95
+ * Options that configure how long to wait for transaction confirmations.
96
+ */
97
+ export type WaitOptions = {
98
+ /** Number of block confirmations to wait for. */
99
+ confirmations?: number;
100
+ /** Milliseconds to wait before aborting `tx.wait()`. */
101
+ timeoutMs?: number;
102
+ };
103
+ /**
104
+ * Extends ethers overrides with `wait()` options that control confirmation count and timeout.
105
+ */
106
+ export type TransactionOverrides = Overrides & WaitOptions;
86
107
  export type TransactionLikeWithNonce = TransactionLike & {
87
108
  nonce: number;
88
109
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEpD;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,CAAC;AAE3D,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { NetworkData } from './types';
2
1
  import { SubgraphOptions } from './interfaces';
2
+ import { NetworkData } from './types';
3
3
  /**
4
4
  * Handles and throws appropriate error types based on the Ethereum error.
5
5
  *
@@ -27,6 +27,13 @@ export declare const isValidUrl: (url: string) => boolean;
27
27
  * @returns True if the string is valid JSON, false otherwise
28
28
  */
29
29
  export declare const isValidJson: (input: string) => boolean;
30
+ /**
31
+ * Extracts a readable message from unknown error values.
32
+ *
33
+ * @param error - Unknown error value
34
+ * @returns Human-readable error message
35
+ */
36
+ export declare const getErrorMessage: (error: unknown) => string;
30
37
  /**
31
38
  * Gets the subgraph URL for the given network, using API key if available.
32
39
  *
@@ -34,6 +41,14 @@ export declare const isValidJson: (input: string) => boolean;
34
41
  * @returns The subgraph URL with API key if available
35
42
  */
36
43
  export declare const getSubgraphUrl: (networkData: NetworkData) => string;
44
+ /**
45
+ * Gets the HMT statistics subgraph URL for the given network.
46
+ * Falls back to the default subgraph URL when a dedicated HMT endpoint is not configured.
47
+ *
48
+ * @param networkData - The network data containing subgraph URLs
49
+ * @returns The HMT statistics subgraph URL with API key if available
50
+ */
51
+ export declare const getHMTSubgraphUrl: (networkData: NetworkData) => string;
37
52
  /**
38
53
  * Converts a Date object to Unix timestamp (seconds since epoch).
39
54
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAatD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CA4CX,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAUhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAUtD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAAa,WAAW,WAWzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AA6CF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CAiDX,CAAC"}
package/dist/utils.js CHANGED
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exports.getSubgraphUrl = exports.isValidJson = exports.isValidUrl = exports.throwError = void 0;
6
+ exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exports.getHMTSubgraphUrl = exports.getSubgraphUrl = exports.getErrorMessage = exports.isValidJson = exports.isValidUrl = exports.throwError = void 0;
7
7
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
8
  const ethers_1 = require("ethers");
9
9
  const graphql_request_1 = __importDefault(require("graphql-request"));
10
10
  const validator_1 = require("validator");
11
- const constants_1 = require("./constants");
12
11
  const enums_1 = require("./enums");
13
12
  const error_1 = require("./error");
14
13
  /**
@@ -77,6 +76,24 @@ const isValidJson = (input) => {
77
76
  }
78
77
  };
79
78
  exports.isValidJson = isValidJson;
79
+ /**
80
+ * Extracts a readable message from unknown error values.
81
+ *
82
+ * @param error - Unknown error value
83
+ * @returns Human-readable error message
84
+ */
85
+ const getErrorMessage = (error) => {
86
+ if (error instanceof Error) {
87
+ return error.message;
88
+ }
89
+ try {
90
+ return JSON.stringify(error);
91
+ }
92
+ catch {
93
+ return String(error);
94
+ }
95
+ };
96
+ exports.getErrorMessage = getErrorMessage;
80
97
  /**
81
98
  * Gets the subgraph URL for the given network, using API key if available.
82
99
  *
@@ -86,7 +103,7 @@ exports.isValidJson = isValidJson;
86
103
  const getSubgraphUrl = (networkData) => {
87
104
  let subgraphUrl = networkData.subgraphUrl;
88
105
  if (process.env.SUBGRAPH_API_KEY) {
89
- subgraphUrl = networkData.subgraphUrlApiKey.replace(constants_1.SUBGRAPH_API_KEY_PLACEHOLDER, process.env.SUBGRAPH_API_KEY);
106
+ subgraphUrl = networkData.subgraphUrlApiKey;
90
107
  }
91
108
  else if (networkData.chainId !== enums_1.ChainId.LOCALHOST) {
92
109
  // eslint-disable-next-line no-console
@@ -95,6 +112,26 @@ const getSubgraphUrl = (networkData) => {
95
112
  return subgraphUrl;
96
113
  };
97
114
  exports.getSubgraphUrl = getSubgraphUrl;
115
+ /**
116
+ * Gets the HMT statistics subgraph URL for the given network.
117
+ * Falls back to the default subgraph URL when a dedicated HMT endpoint is not configured.
118
+ *
119
+ * @param networkData - The network data containing subgraph URLs
120
+ * @returns The HMT statistics subgraph URL with API key if available
121
+ */
122
+ const getHMTSubgraphUrl = (networkData) => {
123
+ let subgraphUrl = networkData.hmtSubgraphUrl || networkData.subgraphUrl;
124
+ if (process.env.SUBGRAPH_API_KEY) {
125
+ subgraphUrl =
126
+ networkData.hmtSubgraphUrlApiKey || networkData.subgraphUrlApiKey;
127
+ }
128
+ else if (networkData.chainId !== enums_1.ChainId.LOCALHOST) {
129
+ // eslint-disable-next-line no-console
130
+ console.warn(error_1.WarnSubgraphApiKeyNotProvided);
131
+ }
132
+ return subgraphUrl;
133
+ };
134
+ exports.getHMTSubgraphUrl = getHMTSubgraphUrl;
98
135
  /**
99
136
  * Converts a Date object to Unix timestamp (seconds since epoch).
100
137
  *
@@ -115,6 +152,29 @@ const isIndexerError = (error) => {
115
152
  return errorMessage.toLowerCase().includes('bad indexers');
116
153
  };
117
154
  exports.isIndexerError = isIndexerError;
155
+ const getSubgraphErrorMessage = (error) => {
156
+ return (error?.response?.errors?.[0]?.message ||
157
+ error?.message ||
158
+ error?.toString?.() ||
159
+ 'Subgraph request failed');
160
+ };
161
+ const getSubgraphStatusCode = (error) => {
162
+ if (typeof error?.response?.status === 'number') {
163
+ return error.response.status;
164
+ }
165
+ if (typeof error?.status === 'number') {
166
+ return error.status;
167
+ }
168
+ return undefined;
169
+ };
170
+ const toSubgraphError = (error, url) => {
171
+ const message = getSubgraphErrorMessage(error);
172
+ const statusCode = getSubgraphStatusCode(error);
173
+ if ((0, exports.isIndexerError)(error)) {
174
+ return new error_1.SubgraphBadIndexerError(message, url, statusCode);
175
+ }
176
+ return new error_1.SubgraphRequestError(message, url, statusCode);
177
+ };
118
178
  const sleep = (ms) => {
119
179
  return new Promise((resolve) => setTimeout(resolve, ms));
120
180
  };
@@ -144,7 +204,12 @@ const customGqlFetch = async (url, query, variables, options) => {
144
204
  }
145
205
  : undefined;
146
206
  if (!options) {
147
- return await (0, graphql_request_1.default)(url, query, variables, headers);
207
+ try {
208
+ return await (0, graphql_request_1.default)(url, query, variables, headers);
209
+ }
210
+ catch (error) {
211
+ throw toSubgraphError(error, url);
212
+ }
148
213
  }
149
214
  const hasMaxRetries = options.maxRetries !== undefined;
150
215
  const hasBaseDelay = options.baseDelay !== undefined;
@@ -163,9 +228,10 @@ const customGqlFetch = async (url, query, variables, options) => {
163
228
  return await (0, graphql_request_1.default)(targetUrl, query, variables, headers);
164
229
  }
165
230
  catch (error) {
166
- lastError = error;
231
+ const wrappedError = toSubgraphError(error, targetUrl);
232
+ lastError = wrappedError;
167
233
  if (attempt === maxRetries || !(0, exports.isIndexerError)(error)) {
168
- throw error;
234
+ throw wrappedError;
169
235
  }
170
236
  const delay = baseDelay * attempt;
171
237
  await sleep(delay);
@@ -0,0 +1,2 @@
1
+ export { WorkerUtils } from './worker_utils';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerUtils = void 0;
4
+ var worker_utils_1 = require("./worker_utils");
5
+ Object.defineProperty(exports, "WorkerUtils", { enumerable: true, get: function () { return worker_utils_1.WorkerUtils; } });
@@ -1,5 +1,5 @@
1
- import { ChainId } from './enums';
2
- import { IWorker, IWorkersFilter, SubgraphOptions } from './interfaces';
1
+ import { ChainId } from '../enums';
2
+ import { IWorker, IWorkersFilter, SubgraphOptions } from '../interfaces';
3
3
  /**
4
4
  * Utility class for worker-related operations.
5
5
  *
@@ -83,4 +83,4 @@ export declare class WorkerUtils {
83
83
  */
84
84
  static getWorkers(filter: IWorkersFilter, options?: SubgraphOptions): Promise<IWorker[]>;
85
85
  }
86
- //# sourceMappingURL=worker.d.ts.map
86
+ //# sourceMappingURL=worker_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker_utils.d.ts","sourceRoot":"","sources":["../../src/worker/worker_utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,UAAU,CAAC;AAInD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGzE;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW;IACtB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IA0B1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACiB,UAAU,CAC5B,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CAoCtB"}
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkerUtils = void 0;
4
4
  const ethers_1 = require("ethers");
5
- const constants_1 = require("./constants");
6
- const enums_1 = require("./enums");
7
- const error_1 = require("./error");
8
- const worker_1 = require("./graphql/queries/worker");
9
- const utils_1 = require("./utils");
5
+ const constants_1 = require("../constants");
6
+ const enums_1 = require("../enums");
7
+ const error_1 = require("../error");
8
+ const worker_1 = require("../graphql/queries/worker");
9
+ const utils_1 = require("../utils");
10
10
  /**
11
11
  * Utility class for worker-related operations.
12
12
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "6.0.0",
4
+ "version": "7.0.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -38,7 +38,7 @@
38
38
  ]
39
39
  },
40
40
  "dependencies": {
41
- "@human-protocol/core": "5.0.1",
41
+ "@human-protocol/core": "6.0.0",
42
42
  "axios": "^1.4.0",
43
43
  "ethers": "~6.15.0",
44
44
  "graphql": "^16.8.1",
@@ -47,15 +47,15 @@
47
47
  "openpgp": "^6.2.2",
48
48
  "secp256k1": "^5.0.1",
49
49
  "validator": "^13.12.0",
50
- "vitest": "^3.0.9"
50
+ "vitest": "^4.0.18"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/validator": "^13.15.4",
54
54
  "eslint": "^9.39.1",
55
55
  "eslint-plugin-jest": "^28.9.0",
56
- "eslint-plugin-prettier": "^5.2.1",
56
+ "eslint-plugin-prettier": "^5.5.5",
57
57
  "glob": "^13.0.0",
58
- "prettier": "^3.7.4",
58
+ "prettier": "^3.8.1",
59
59
  "ts-node": "^10.9.2",
60
60
  "typedoc": "^0.28.15",
61
61
  "typedoc-plugin-markdown": "^4.9.0",
package/src/base.ts CHANGED
@@ -1,5 +1,10 @@
1
- import { ContractRunner } from 'ethers';
2
- import { NetworkData } from './types';
1
+ import {
2
+ ContractRunner,
3
+ ContractTransactionReceipt,
4
+ ContractTransactionResponse,
5
+ Overrides,
6
+ } from 'ethers';
7
+ import { NetworkData, TransactionOverrides, WaitOptions } from './types';
3
8
 
4
9
  /**
5
10
  * Base class for clients making on-chain calls.
@@ -20,4 +25,35 @@ export abstract class BaseEthersClient {
20
25
  this.networkData = networkData;
21
26
  this.runner = runner;
22
27
  }
28
+
29
+ protected normalizeTxOptions(
30
+ txOptions?: TransactionOverrides
31
+ ): [Overrides, WaitOptions] {
32
+ const options = txOptions ?? {};
33
+ const {
34
+ confirmations: waitConfirmations,
35
+ timeoutMs: waitTimeoutMs,
36
+ ...overrides
37
+ } = options;
38
+
39
+ const waitOptions: WaitOptions = {
40
+ confirmations: waitConfirmations,
41
+ timeoutMs: waitTimeoutMs,
42
+ };
43
+
44
+ return [overrides as Overrides, waitOptions];
45
+ }
46
+
47
+ protected async sendTxAndWait(
48
+ executeTx: (overrides: Overrides) => Promise<ContractTransactionResponse>,
49
+ txOptions?: TransactionOverrides
50
+ ): Promise<ContractTransactionReceipt | null> {
51
+ const [overrides, waitOptions] = this.normalizeTxOptions(txOptions);
52
+ const transactionResponse = await executeTx(overrides);
53
+
54
+ return transactionResponse.wait(
55
+ waitOptions.confirmations,
56
+ waitOptions.timeoutMs
57
+ );
58
+ }
23
59
  }
package/src/constants.ts CHANGED
@@ -34,11 +34,15 @@ export const NETWORKS: {
34
34
  stakingAddress: '0xEf6Da3aB52c33925Be3F84038193a7e1331F51E6',
35
35
  kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
36
36
  subgraphUrl:
37
- 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
37
+ 'https://api.studio.thegraph.com/query/74256/human-ethereum/version/latest',
38
38
  subgraphUrlApiKey:
39
- 'https://gateway.thegraph.com/api/deployments/id/QmeCB3KX49nRAkzgqancc3yL3VMJvt65YtL1zrLCFgr2n5',
39
+ 'https://gateway.thegraph.com/api/deployments/id/QmQZ3yL1FzydDwaB56ozgTiBESciTNFsMLyTBfHXzNd1gg',
40
40
  oldSubgraphUrl: '',
41
41
  oldFactoryAddress: '',
42
+ hmtSubgraphUrl:
43
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-ethereum/version/latest',
44
+ hmtSubgraphUrlApiKey:
45
+ 'https://gateway.thegraph.com/api/deployments/id/QmdcTW7XhgULq5yJZGA65mjTwQogdyzLJaZ69ttDJz5JeE',
42
46
  },
43
47
  [ChainId.SEPOLIA]: {
44
48
  chainId: ChainId.SEPOLIA,
@@ -49,11 +53,15 @@ export const NETWORKS: {
49
53
  stakingAddress: '0x2163e3A40032Af1C359ac731deaB48258b317890',
50
54
  kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60',
51
55
  subgraphUrl:
52
- 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
56
+ 'https://api.studio.thegraph.com/query/74256/human-sepolia/version/latest',
53
57
  subgraphUrlApiKey:
54
- 'https://gateway.thegraph.com/api/deployments/id/QmcMntqZSTh8wJddxgp2hYcdw78wZFU86LHTHzJ1bTVUDc',
58
+ 'https://gateway.thegraph.com/api/deployments/id/QmQEbyGSf8VG9pdskowsK6C977wkcyJSxw9q6EDctKEkUw',
55
59
  oldSubgraphUrl: '',
56
60
  oldFactoryAddress: '',
61
+ hmtSubgraphUrl:
62
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-sepolia/version/latest',
63
+ hmtSubgraphUrlApiKey:
64
+ 'https://gateway.thegraph.com/api/deployments/id/QmYkPnYxbZ5ZTtKz7PTyxh6x5sK2H6yzx6vXDCrErpa9gB',
57
65
  },
58
66
  [ChainId.BSC_MAINNET]: {
59
67
  chainId: ChainId.BSC_MAINNET,
@@ -64,11 +72,15 @@ export const NETWORKS: {
64
72
  stakingAddress: '0xE24e5C08E28331D24758b69A5E9f383D2bDD1c98',
65
73
  kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
66
74
  subgraphUrl:
67
- 'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
75
+ 'https://api.studio.thegraph.com/query/74256/human-bsc/version/latest',
68
76
  subgraphUrlApiKey:
69
- 'https://gateway.thegraph.com/api/deployments/id/QmRexbu8eLZ1iE7ZLMtKxAr9GJnQ1JVrXhybKq6JkJ9XLE',
77
+ 'https://gateway.thegraph.com/api/deployments/id/QmV3nZUM51NGt7F8RpZP9GxKPpKox3F24iJ8H1ekPb6ha4',
70
78
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
71
79
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
80
+ hmtSubgraphUrl:
81
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc/version/latest',
82
+ hmtSubgraphUrlApiKey:
83
+ 'https://gateway.thegraph.com/api/deployments/id/QmUnHgNShyv45S2dQ21W9jLvRA8xWT6XfeuP25fXJoNoEa',
72
84
  },
73
85
  [ChainId.BSC_TESTNET]: {
74
86
  chainId: ChainId.BSC_TESTNET,
@@ -79,12 +91,16 @@ export const NETWORKS: {
79
91
  stakingAddress: '0xD6D347ba6987519B4e42EcED43dF98eFf5465a23',
80
92
  kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
81
93
  subgraphUrl:
82
- 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
94
+ 'https://api.studio.thegraph.com/query/74256/human-bsc-testnet/version/latest',
83
95
  subgraphUrlApiKey:
84
- 'https://gateway.thegraph.com/api/deployments/id/QmfFBXsAP7nbckFx34XYcNq2hRnfoVNrfqCvuk7hmAtYJT',
96
+ 'https://gateway.thegraph.com/api/deployments/id/QmdQJog9vMghK2o39U9YJL8vpU9VZnkJa7jGg7wnsod7qV',
85
97
  oldSubgraphUrl:
86
98
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
87
99
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
100
+ hmtSubgraphUrl:
101
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-bsc-testnet/version/latest',
102
+ hmtSubgraphUrlApiKey:
103
+ 'https://gateway.thegraph.com/api/deployments/id/QmPMRbrXKp7a1i5x27dzBHbomxqKYDg5eU3djv1DXB5heq',
88
104
  },
89
105
  [ChainId.POLYGON]: {
90
106
  chainId: ChainId.POLYGON,
@@ -95,12 +111,16 @@ export const NETWORKS: {
95
111
  stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
96
112
  kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
97
113
  subgraphUrl:
98
- 'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
114
+ 'https://api.studio.thegraph.com/query/74256/human-polygon/version/latest',
99
115
  subgraphUrlApiKey:
100
- 'https://gateway.thegraph.com/api/deployments/id/QmUwHMDjnDHDB5cowGqd96SRJ1sZegoAPanjxBWUyLZghv',
116
+ 'https://gateway.thegraph.com/api/deployments/id/QmSu7B48kgGgMgXaD6Yb4fXjbnsJNmobKAU9qZgescZXid',
101
117
  oldSubgraphUrl:
102
118
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
103
119
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
120
+ hmtSubgraphUrl:
121
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-polygon/version/latest',
122
+ hmtSubgraphUrlApiKey:
123
+ 'https://gateway.thegraph.com/api/deployments/id/QmcTTTq2reYDBP5j5P2eToc5FmYbJ5ZSMhPaRB6NLriNjR',
104
124
  },
105
125
  [ChainId.POLYGON_AMOY]: {
106
126
  chainId: ChainId.POLYGON_AMOY,
@@ -111,20 +131,24 @@ export const NETWORKS: {
111
131
  stakingAddress: '0xffE496683F842a923110415b7278ded3F265f2C5',
112
132
  kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7',
113
133
  subgraphUrl:
114
- 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
134
+ 'https://api.studio.thegraph.com/query/74256/human-amoy/version/latest',
115
135
  subgraphUrlApiKey:
116
- 'https://gateway.thegraph.com/api/deployments/id/QmTJfcvVVmw8fe5CwRP6tZD5FzE2ESrm3ryygS1YZMYhM7',
136
+ 'https://gateway.thegraph.com/api/deployments/id/QmRx5WSi7o9FtENWnE5eEz8Dr7kYUazk4TNPRt65UZkKkB',
117
137
  oldSubgraphUrl: '',
118
138
  oldFactoryAddress: '',
139
+ hmtSubgraphUrl:
140
+ 'https://api.studio.thegraph.com/query/74256/hmt-stats-amoy/version/latest',
141
+ hmtSubgraphUrlApiKey:
142
+ 'https://gateway.thegraph.com/api/deployments/id/QmZze6UWMJna8dQ183TVounSfGwc9C36RgQCGWhFzgrW3y',
119
143
  },
120
144
  [ChainId.LOCALHOST]: {
121
145
  chainId: ChainId.LOCALHOST,
122
146
  title: 'Localhost',
123
147
  scanUrl: '',
124
- factoryAddress: '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9',
148
+ factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
125
149
  hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
126
150
  stakingAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
127
- kvstoreAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
151
+ kvstoreAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
128
152
  subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
129
153
  subgraphUrlApiKey: '',
130
154
  oldSubgraphUrl: '',
@@ -154,6 +178,4 @@ export const Role = {
154
178
  RecordingOracle: 'recording_oracle',
155
179
  };
156
180
 
157
- export const SUBGRAPH_API_KEY_PLACEHOLDER = '[SUBGRAPH_API_KEY]';
158
-
159
181
  export const ESCROW_BULK_PAYOUT_MAX_ITEMS = 99;