@human-protocol/sdk 5.0.0-beta.3 → 5.1.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 (52) hide show
  1. package/dist/base.d.ts +1 -10
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +0 -21
  4. package/dist/constants.d.ts +0 -1
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +7 -22
  7. package/dist/enums.d.ts +0 -1
  8. package/dist/enums.d.ts.map +1 -1
  9. package/dist/enums.js +0 -1
  10. package/dist/error.d.ts +4 -0
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/error.js +5 -1
  13. package/dist/escrow.d.ts +75 -19
  14. package/dist/escrow.d.ts.map +1 -1
  15. package/dist/escrow.js +144 -58
  16. package/dist/interfaces.d.ts +9 -0
  17. package/dist/interfaces.d.ts.map +1 -1
  18. package/dist/kvstore.d.ts +9 -5
  19. package/dist/kvstore.d.ts.map +1 -1
  20. package/dist/kvstore.js +15 -15
  21. package/dist/operator.d.ts +9 -5
  22. package/dist/operator.d.ts.map +1 -1
  23. package/dist/operator.js +16 -16
  24. package/dist/staking.d.ts +6 -3
  25. package/dist/staking.d.ts.map +1 -1
  26. package/dist/staking.js +13 -14
  27. package/dist/statistics.d.ts +13 -7
  28. package/dist/statistics.d.ts.map +1 -1
  29. package/dist/statistics.js +24 -22
  30. package/dist/transaction.d.ts +5 -3
  31. package/dist/transaction.d.ts.map +1 -1
  32. package/dist/transaction.js +8 -10
  33. package/dist/utils.d.ts +7 -0
  34. package/dist/utils.d.ts.map +1 -1
  35. package/dist/utils.js +51 -1
  36. package/dist/worker.d.ts +5 -3
  37. package/dist/worker.d.ts.map +1 -1
  38. package/dist/worker.js +8 -10
  39. package/package.json +3 -2
  40. package/src/base.ts +1 -23
  41. package/src/constants.ts +6 -24
  42. package/src/enums.ts +0 -1
  43. package/src/error.ts +7 -0
  44. package/src/escrow.ts +232 -97
  45. package/src/interfaces.ts +10 -0
  46. package/src/kvstore.ts +26 -24
  47. package/src/operator.ts +54 -26
  48. package/src/staking.ts +27 -26
  49. package/src/statistics.ts +87 -47
  50. package/src/transaction.ts +39 -25
  51. package/src/utils.ts +64 -0
  52. package/src/worker.ts +32 -17
package/src/statistics.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import gqlFetch from 'graphql-request';
3
-
4
2
  import { OrderDirection } from './enums';
5
3
  import {
6
4
  EscrowStatisticsData,
@@ -21,9 +19,15 @@ import {
21
19
  IPaymentStatistics,
22
20
  IStatisticsFilter,
23
21
  IWorkerStatistics,
22
+ SubgraphOptions,
24
23
  } from './interfaces';
25
24
  import { NetworkData } from './types';
26
- import { getSubgraphUrl, getUnixTimestamp, throwError } from './utils';
25
+ import {
26
+ getSubgraphUrl,
27
+ getUnixTimestamp,
28
+ customGqlFetch,
29
+ throwError,
30
+ } from './utils';
27
31
 
28
32
  /**
29
33
  * ## Introduction
@@ -103,6 +107,7 @@ export class StatisticsClient {
103
107
  * ```
104
108
  *
105
109
  * @param {IStatisticsFilter} filter Statistics params with duration data
110
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
106
111
  * @returns {Promise<IEscrowStatistics>} Escrow statistics data.
107
112
  *
108
113
  * **Code example**
@@ -120,7 +125,8 @@ export class StatisticsClient {
120
125
  * ```
121
126
  */
122
127
  async getEscrowStatistics(
123
- filter: IStatisticsFilter = {}
128
+ filter: IStatisticsFilter = {},
129
+ options?: SubgraphOptions
124
130
  ): Promise<IEscrowStatistics> {
125
131
  try {
126
132
  const first =
@@ -128,19 +134,24 @@ export class StatisticsClient {
128
134
  const skip = filter.skip || 0;
129
135
  const orderDirection = filter.orderDirection || OrderDirection.ASC;
130
136
 
131
- const { escrowStatistics } = await gqlFetch<{
137
+ const { escrowStatistics } = await customGqlFetch<{
132
138
  escrowStatistics: EscrowStatisticsData;
133
- }>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY);
139
+ }>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY, options);
134
140
 
135
- const { eventDayDatas } = await gqlFetch<{
141
+ const { eventDayDatas } = await customGqlFetch<{
136
142
  eventDayDatas: EventDayData[];
137
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
138
- from: filter.from ? getUnixTimestamp(filter.from) : undefined,
139
- to: filter.to ? getUnixTimestamp(filter.to) : undefined,
140
- orderDirection: orderDirection,
141
- first: first,
142
- skip: skip,
143
- });
143
+ }>(
144
+ this.subgraphUrl,
145
+ GET_EVENT_DAY_DATA_QUERY(filter),
146
+ {
147
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
148
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
149
+ orderDirection: orderDirection,
150
+ first: first,
151
+ skip: skip,
152
+ },
153
+ options
154
+ );
144
155
 
145
156
  return {
146
157
  totalEscrows: escrowStatistics?.totalEscrowCount
@@ -187,6 +198,7 @@ export class StatisticsClient {
187
198
  * ```
188
199
  *
189
200
  * @param {IStatisticsFilter} filter Statistics params with duration data
201
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
190
202
  * @returns {Promise<IWorkerStatistics>} Worker statistics data.
191
203
  *
192
204
  * **Code example**
@@ -204,7 +216,8 @@ export class StatisticsClient {
204
216
  * ```
205
217
  */
206
218
  async getWorkerStatistics(
207
- filter: IStatisticsFilter = {}
219
+ filter: IStatisticsFilter = {},
220
+ options?: SubgraphOptions
208
221
  ): Promise<IWorkerStatistics> {
209
222
  try {
210
223
  const first =
@@ -212,15 +225,20 @@ export class StatisticsClient {
212
225
  const skip = filter.skip || 0;
213
226
  const orderDirection = filter.orderDirection || OrderDirection.ASC;
214
227
 
215
- const { eventDayDatas } = await gqlFetch<{
228
+ const { eventDayDatas } = await customGqlFetch<{
216
229
  eventDayDatas: EventDayData[];
217
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
218
- from: filter.from ? getUnixTimestamp(filter.from) : undefined,
219
- to: filter.to ? getUnixTimestamp(filter.to) : undefined,
220
- orderDirection: orderDirection,
221
- first: first,
222
- skip: skip,
223
- });
230
+ }>(
231
+ this.subgraphUrl,
232
+ GET_EVENT_DAY_DATA_QUERY(filter),
233
+ {
234
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
235
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
236
+ orderDirection: orderDirection,
237
+ first: first,
238
+ skip: skip,
239
+ },
240
+ options
241
+ );
224
242
 
225
243
  return {
226
244
  dailyWorkersData: eventDayDatas.map((eventDayData) => ({
@@ -262,6 +280,7 @@ export class StatisticsClient {
262
280
  * ```
263
281
  *
264
282
  * @param {IStatisticsFilter} filter Statistics params with duration data
283
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
265
284
  * @returns {Promise<IPaymentStatistics>} Payment statistics data.
266
285
  *
267
286
  * **Code example**
@@ -300,7 +319,8 @@ export class StatisticsClient {
300
319
  * ```
301
320
  */
302
321
  async getPaymentStatistics(
303
- filter: IStatisticsFilter = {}
322
+ filter: IStatisticsFilter = {},
323
+ options?: SubgraphOptions
304
324
  ): Promise<IPaymentStatistics> {
305
325
  try {
306
326
  const first =
@@ -308,15 +328,20 @@ export class StatisticsClient {
308
328
  const skip = filter.skip || 0;
309
329
  const orderDirection = filter.orderDirection || OrderDirection.ASC;
310
330
 
311
- const { eventDayDatas } = await gqlFetch<{
331
+ const { eventDayDatas } = await customGqlFetch<{
312
332
  eventDayDatas: EventDayData[];
313
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
314
- from: filter.from ? getUnixTimestamp(filter.from) : undefined,
315
- to: filter.to ? getUnixTimestamp(filter.to) : undefined,
316
- orderDirection: orderDirection,
317
- first: first,
318
- skip: skip,
319
- });
333
+ }>(
334
+ this.subgraphUrl,
335
+ GET_EVENT_DAY_DATA_QUERY(filter),
336
+ {
337
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
338
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
339
+ orderDirection: orderDirection,
340
+ first: first,
341
+ skip: skip,
342
+ },
343
+ options
344
+ );
320
345
 
321
346
  return {
322
347
  dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
@@ -346,6 +371,7 @@ export class StatisticsClient {
346
371
  * };
347
372
  * ```
348
373
  *
374
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
349
375
  * @returns {Promise<IHMTStatistics>} HMToken statistics data.
350
376
  *
351
377
  * **Code example**
@@ -363,11 +389,11 @@ export class StatisticsClient {
363
389
  * });
364
390
  * ```
365
391
  */
366
- async getHMTStatistics(): Promise<IHMTStatistics> {
392
+ async getHMTStatistics(options?: SubgraphOptions): Promise<IHMTStatistics> {
367
393
  try {
368
- const { hmtokenStatistics } = await gqlFetch<{
394
+ const { hmtokenStatistics } = await customGqlFetch<{
369
395
  hmtokenStatistics: HMTStatisticsData;
370
- }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
396
+ }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY, options);
371
397
 
372
398
  return {
373
399
  totalTransferAmount: BigInt(hmtokenStatistics.totalValueTransfered),
@@ -385,6 +411,7 @@ export class StatisticsClient {
385
411
  * **Input parameters**
386
412
  *
387
413
  * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
414
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
388
415
  * @returns {Promise<IHMTHolder[]>} List of HMToken holders.
389
416
  *
390
417
  * **Code example**
@@ -404,19 +431,23 @@ export class StatisticsClient {
404
431
  * })));
405
432
  * ```
406
433
  */
407
- async getHMTHolders(params: IHMTHoldersParams = {}): Promise<IHMTHolder[]> {
434
+ async getHMTHolders(
435
+ params: IHMTHoldersParams = {},
436
+ options?: SubgraphOptions
437
+ ): Promise<IHMTHolder[]> {
408
438
  try {
409
439
  const { address, orderDirection } = params;
410
440
  const query = GET_HOLDERS_QUERY(address);
411
441
 
412
- const { holders } = await gqlFetch<{ holders: HMTHolderData[] }>(
442
+ const { holders } = await customGqlFetch<{ holders: HMTHolderData[] }>(
413
443
  this.subgraphUrl,
414
444
  query,
415
445
  {
416
446
  address,
417
447
  orderBy: 'balance',
418
448
  orderDirection,
419
- }
449
+ },
450
+ options
420
451
  );
421
452
 
422
453
  return holders.map((holder) => ({
@@ -454,6 +485,7 @@ export class StatisticsClient {
454
485
  * ```
455
486
  *
456
487
  * @param {IStatisticsFilter} filter Statistics params with duration data
488
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
457
489
  * @returns {Promise<IDailyHMT[]>} Daily HMToken statistics data.
458
490
  *
459
491
  * **Code example**
@@ -475,22 +507,30 @@ export class StatisticsClient {
475
507
  * console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
476
508
  * ```
477
509
  */
478
- async getHMTDailyData(filter: IStatisticsFilter = {}): Promise<IDailyHMT[]> {
510
+ async getHMTDailyData(
511
+ filter: IStatisticsFilter = {},
512
+ options?: SubgraphOptions
513
+ ): Promise<IDailyHMT[]> {
479
514
  try {
480
515
  const first =
481
516
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
482
517
  const skip = filter.skip || 0;
483
518
  const orderDirection = filter.orderDirection || OrderDirection.ASC;
484
519
 
485
- const { eventDayDatas } = await gqlFetch<{
520
+ const { eventDayDatas } = await customGqlFetch<{
486
521
  eventDayDatas: EventDayData[];
487
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
488
- from: filter.from ? getUnixTimestamp(filter.from) : undefined,
489
- to: filter.to ? getUnixTimestamp(filter.to) : undefined,
490
- orderDirection: orderDirection,
491
- first: first,
492
- skip: skip,
493
- });
522
+ }>(
523
+ this.subgraphUrl,
524
+ GET_EVENT_DAY_DATA_QUERY(filter),
525
+ {
526
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
527
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
528
+ orderDirection: orderDirection,
529
+ first: first,
530
+ skip: skip,
531
+ },
532
+ options
533
+ );
494
534
 
495
535
  return eventDayDatas.map((eventDayData) => ({
496
536
  timestamp: +eventDayData.timestamp * 1000,
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { ethers } from 'ethers';
3
- import gqlFetch from 'graphql-request';
4
3
  import { NETWORKS } from './constants';
5
4
  import { ChainId, OrderDirection } from './enums';
6
5
  import {
@@ -17,8 +16,9 @@ import {
17
16
  InternalTransaction,
18
17
  ITransaction,
19
18
  ITransactionsFilter,
19
+ SubgraphOptions,
20
20
  } from './interfaces';
21
- import { getSubgraphUrl, getUnixTimestamp } from './utils';
21
+ import { getSubgraphUrl, getUnixTimestamp, customGqlFetch } from './utils';
22
22
 
23
23
  export class TransactionUtils {
24
24
  /**
@@ -54,6 +54,7 @@ export class TransactionUtils {
54
54
  *
55
55
  * @param {ChainId} chainId The chain ID.
56
56
  * @param {string} hash The transaction hash.
57
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
57
58
  * @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
58
59
  *
59
60
  * **Code example**
@@ -66,7 +67,8 @@ export class TransactionUtils {
66
67
  */
67
68
  public static async getTransaction(
68
69
  chainId: ChainId,
69
- hash: string
70
+ hash: string,
71
+ options?: SubgraphOptions
70
72
  ): Promise<ITransaction | null> {
71
73
  if (!ethers.isHexString(hash)) {
72
74
  throw ErrorInvalidHashProvided;
@@ -77,11 +79,16 @@ export class TransactionUtils {
77
79
  throw ErrorUnsupportedChainID;
78
80
  }
79
81
 
80
- const { transaction } = await gqlFetch<{
82
+ const { transaction } = await customGqlFetch<{
81
83
  transaction: TransactionData | null;
82
- }>(getSubgraphUrl(networkData), GET_TRANSACTION_QUERY, {
83
- hash: hash.toLowerCase(),
84
- });
84
+ }>(
85
+ getSubgraphUrl(networkData),
86
+ GET_TRANSACTION_QUERY,
87
+ {
88
+ hash: hash.toLowerCase(),
89
+ },
90
+ options
91
+ );
85
92
  if (!transaction) return null;
86
93
 
87
94
  return mapTransaction(transaction);
@@ -141,6 +148,7 @@ export class TransactionUtils {
141
148
  * ```
142
149
  *
143
150
  * @param {ITransactionsFilter} filter Filter for the transactions.
151
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
144
152
  * @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
145
153
  *
146
154
  * **Code example**
@@ -160,7 +168,8 @@ export class TransactionUtils {
160
168
  * ```
161
169
  */
162
170
  public static async getTransactions(
163
- filter: ITransactionsFilter
171
+ filter: ITransactionsFilter,
172
+ options?: SubgraphOptions
164
173
  ): Promise<ITransaction[]> {
165
174
  if (
166
175
  (!!filter.startDate || !!filter.endDate) &&
@@ -179,24 +188,29 @@ export class TransactionUtils {
179
188
  throw ErrorUnsupportedChainID;
180
189
  }
181
190
 
182
- const { transactions } = await gqlFetch<{
191
+ const { transactions } = await customGqlFetch<{
183
192
  transactions: TransactionData[];
184
- }>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), {
185
- fromAddress: filter?.fromAddress,
186
- toAddress: filter?.toAddress,
187
- startDate: filter?.startDate
188
- ? getUnixTimestamp(filter?.startDate)
189
- : undefined,
190
- endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
191
- startBlock: filter.startBlock ? filter.startBlock : undefined,
192
- endBlock: filter.endBlock ? filter.endBlock : undefined,
193
- method: filter.method ? filter.method : undefined,
194
- escrow: filter.escrow ? filter.escrow : undefined,
195
- token: filter.token ? filter.token : undefined,
196
- orderDirection: orderDirection,
197
- first: first,
198
- skip: skip,
199
- });
193
+ }>(
194
+ getSubgraphUrl(networkData),
195
+ GET_TRANSACTIONS_QUERY(filter),
196
+ {
197
+ fromAddress: filter?.fromAddress,
198
+ toAddress: filter?.toAddress,
199
+ startDate: filter?.startDate
200
+ ? getUnixTimestamp(filter?.startDate)
201
+ : undefined,
202
+ endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
203
+ startBlock: filter.startBlock ? filter.startBlock : undefined,
204
+ endBlock: filter.endBlock ? filter.endBlock : undefined,
205
+ method: filter.method ? filter.method : undefined,
206
+ escrow: filter.escrow ? filter.escrow : undefined,
207
+ token: filter.token ? filter.token : undefined,
208
+ orderDirection: orderDirection,
209
+ first: first,
210
+ skip: skip,
211
+ },
212
+ options
213
+ );
200
214
 
201
215
  if (!transactions) {
202
216
  return [];
package/src/utils.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { ethers } from 'ethers';
3
+ import gqlFetch from 'graphql-request';
3
4
 
4
5
  import { isURL } from 'validator';
5
6
  import { SUBGRAPH_API_KEY_PLACEHOLDER } from './constants';
6
7
  import { ChainId } from './enums';
7
8
  import {
8
9
  ContractExecutionError,
10
+ ErrorRetryParametersMissing,
9
11
  EthereumError,
10
12
  InvalidArgumentError,
11
13
  NonceExpired,
@@ -15,6 +17,7 @@ import {
15
17
  WarnSubgraphApiKeyNotProvided,
16
18
  } from './error';
17
19
  import { NetworkData } from './types';
20
+ import { SubgraphOptions } from './interfaces';
18
21
 
19
22
  /**
20
23
  * **Handle and throw the error.*
@@ -99,3 +102,64 @@ export const getSubgraphUrl = (networkData: NetworkData) => {
99
102
  export const getUnixTimestamp = (date: Date): number => {
100
103
  return Math.floor(date.getTime() / 1000);
101
104
  };
105
+
106
+ export const isIndexerError = (error: any): boolean => {
107
+ if (!error) return false;
108
+
109
+ const errorMessage =
110
+ error.response?.errors?.[0]?.message ||
111
+ error.message ||
112
+ error.toString() ||
113
+ '';
114
+ return errorMessage.toLowerCase().includes('bad indexers');
115
+ };
116
+
117
+ const sleep = (ms: number): Promise<void> => {
118
+ return new Promise((resolve) => setTimeout(resolve, ms));
119
+ };
120
+
121
+ /**
122
+ * Execute a GraphQL request with automatic retry logic for bad indexer errors.
123
+ * Only retries if options is provided.
124
+ */
125
+ export const customGqlFetch = async <T = any>(
126
+ url: string,
127
+ query: any,
128
+ variables?: any,
129
+ options?: SubgraphOptions
130
+ ): Promise<T> => {
131
+ if (!options) {
132
+ return await gqlFetch<T>(url, query, variables);
133
+ }
134
+
135
+ if (
136
+ (options.maxRetries && options.baseDelay === undefined) ||
137
+ (options.baseDelay && options.maxRetries === undefined)
138
+ ) {
139
+ throw ErrorRetryParametersMissing;
140
+ }
141
+
142
+ let lastError: any;
143
+
144
+ for (let attempt = 0; attempt <= (options.maxRetries as number); attempt++) {
145
+ try {
146
+ const result = await gqlFetch<T>(url, query, variables);
147
+ return result;
148
+ } catch (error) {
149
+ lastError = error;
150
+
151
+ if (attempt === options.maxRetries) {
152
+ throw error;
153
+ }
154
+
155
+ if (!isIndexerError(error)) {
156
+ throw error;
157
+ }
158
+
159
+ const delay = (options.baseDelay as number) * attempt;
160
+ await sleep(delay);
161
+ }
162
+ }
163
+
164
+ throw lastError;
165
+ };
package/src/worker.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { ethers } from 'ethers';
2
- import gqlFetch from 'graphql-request';
3
2
  import { NETWORKS } from './constants';
4
3
  import { ChainId, OrderDirection } from './enums';
5
4
  import { ErrorInvalidAddress, ErrorUnsupportedChainID } from './error';
6
5
  import { WorkerData } from './graphql';
7
6
  import { GET_WORKER_QUERY, GET_WORKERS_QUERY } from './graphql/queries/worker';
8
- import { IWorker, IWorkersFilter } from './interfaces';
9
- import { getSubgraphUrl } from './utils';
7
+ import { IWorker, IWorkersFilter, SubgraphOptions } from './interfaces';
8
+ import { getSubgraphUrl, customGqlFetch } from './utils';
10
9
 
11
10
  export class WorkerUtils {
12
11
  /**
@@ -14,6 +13,7 @@ export class WorkerUtils {
14
13
  *
15
14
  * @param {ChainId} chainId The chain ID.
16
15
  * @param {string} address The worker address.
16
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
17
17
  * @returns {Promise<IWorker | null>} - Returns the worker details or null if not found.
18
18
  *
19
19
  * **Code example**
@@ -26,7 +26,8 @@ export class WorkerUtils {
26
26
  */
27
27
  public static async getWorker(
28
28
  chainId: ChainId,
29
- address: string
29
+ address: string,
30
+ options?: SubgraphOptions
30
31
  ): Promise<IWorker | null> {
31
32
  const networkData = NETWORKS[chainId];
32
33
 
@@ -37,11 +38,16 @@ export class WorkerUtils {
37
38
  throw ErrorInvalidAddress;
38
39
  }
39
40
 
40
- const { worker } = await gqlFetch<{
41
+ const { worker } = await customGqlFetch<{
41
42
  worker: WorkerData | null;
42
- }>(getSubgraphUrl(networkData), GET_WORKER_QUERY, {
43
- address: address.toLowerCase(),
44
- });
43
+ }>(
44
+ getSubgraphUrl(networkData),
45
+ GET_WORKER_QUERY,
46
+ {
47
+ address: address.toLowerCase(),
48
+ },
49
+ options
50
+ );
45
51
 
46
52
  if (!worker) return null;
47
53
 
@@ -74,6 +80,7 @@ export class WorkerUtils {
74
80
  * ```
75
81
  *
76
82
  * @param {IWorkersFilter} filter Filter for the workers.
83
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
77
84
  * @returns {Promise<IWorker[]>} Returns an array with all the worker details.
78
85
  *
79
86
  * **Code example**
@@ -89,7 +96,10 @@ export class WorkerUtils {
89
96
  * const workers = await WorkerUtils.getWorkers(filter);
90
97
  * ```
91
98
  */
92
- public static async getWorkers(filter: IWorkersFilter): Promise<IWorker[]> {
99
+ public static async getWorkers(
100
+ filter: IWorkersFilter,
101
+ options?: SubgraphOptions
102
+ ): Promise<IWorker[]> {
93
103
  const first =
94
104
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
95
105
  const skip = filter.skip || 0;
@@ -104,15 +114,20 @@ export class WorkerUtils {
104
114
  throw ErrorInvalidAddress;
105
115
  }
106
116
 
107
- const { workers } = await gqlFetch<{
117
+ const { workers } = await customGqlFetch<{
108
118
  workers: WorkerData[];
109
- }>(getSubgraphUrl(networkData), GET_WORKERS_QUERY(filter), {
110
- address: filter?.address?.toLowerCase(),
111
- first: first,
112
- skip: skip,
113
- orderBy: orderBy,
114
- orderDirection: orderDirection,
115
- });
119
+ }>(
120
+ getSubgraphUrl(networkData),
121
+ GET_WORKERS_QUERY(filter),
122
+ {
123
+ address: filter?.address?.toLowerCase(),
124
+ first: first,
125
+ skip: skip,
126
+ orderBy: orderBy,
127
+ orderDirection: orderDirection,
128
+ },
129
+ options
130
+ );
116
131
 
117
132
  if (!workers) {
118
133
  return [];