@human-protocol/sdk 3.0.0 → 3.0.2

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 (64) hide show
  1. package/README.md +23 -80
  2. package/dist/constants.d.ts +1 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +1 -0
  5. package/dist/enums.d.ts +4 -0
  6. package/dist/enums.d.ts.map +1 -1
  7. package/dist/enums.js +6 -1
  8. package/dist/error.d.ts +7 -0
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +8 -1
  11. package/dist/escrow.d.ts +90 -11
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +153 -43
  14. package/dist/graphql/queries/escrow.d.ts +1 -0
  15. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  16. package/dist/graphql/queries/escrow.js +50 -12
  17. package/dist/graphql/queries/hmtoken.d.ts +1 -1
  18. package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
  19. package/dist/graphql/queries/hmtoken.js +23 -7
  20. package/dist/graphql/queries/kvstore.d.ts +1 -0
  21. package/dist/graphql/queries/kvstore.d.ts.map +1 -1
  22. package/dist/graphql/queries/kvstore.js +12 -1
  23. package/dist/graphql/queries/operator.js +1 -1
  24. package/dist/graphql/queries/statistics.d.ts +2 -2
  25. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  26. package/dist/graphql/queries/statistics.js +13 -7
  27. package/dist/graphql/queries/transaction.d.ts.map +1 -1
  28. package/dist/graphql/queries/transaction.js +12 -7
  29. package/dist/graphql/types.d.ts +11 -5
  30. package/dist/graphql/types.d.ts.map +1 -1
  31. package/dist/index.d.ts +3 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -1
  34. package/dist/interfaces.d.ts +16 -9
  35. package/dist/interfaces.d.ts.map +1 -1
  36. package/dist/kvstore.d.ts +69 -106
  37. package/dist/kvstore.d.ts.map +1 -1
  38. package/dist/kvstore.js +123 -159
  39. package/dist/operator.d.ts.map +1 -1
  40. package/dist/operator.js +64 -81
  41. package/dist/statistics.d.ts +91 -59
  42. package/dist/statistics.d.ts.map +1 -1
  43. package/dist/statistics.js +162 -85
  44. package/dist/transaction.d.ts +10 -4
  45. package/dist/transaction.d.ts.map +1 -1
  46. package/dist/transaction.js +36 -27
  47. package/package.json +5 -4
  48. package/src/constants.ts +1 -0
  49. package/src/enums.ts +5 -0
  50. package/src/error.ts +8 -0
  51. package/src/escrow.ts +197 -54
  52. package/src/graphql/queries/escrow.ts +53 -11
  53. package/src/graphql/queries/hmtoken.ts +23 -7
  54. package/src/graphql/queries/kvstore.ts +11 -0
  55. package/src/graphql/queries/operator.ts +1 -1
  56. package/src/graphql/queries/statistics.ts +15 -9
  57. package/src/graphql/queries/transaction.ts +12 -7
  58. package/src/graphql/types.ts +13 -5
  59. package/src/index.ts +4 -1
  60. package/src/interfaces.ts +18 -9
  61. package/src/kvstore.ts +145 -158
  62. package/src/operator.ts +79 -91
  63. package/src/statistics.ts +186 -96
  64. package/src/transaction.ts +40 -30
package/src/interfaces.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EscrowStatus } from './types';
2
- import { ChainId } from './enums';
2
+ import { ChainId, OrderDirection } from './enums';
3
3
 
4
4
  export interface IAllocation {
5
5
  escrowAddress: string;
@@ -26,7 +26,7 @@ export interface ILeader {
26
26
  amountSlashed: bigint;
27
27
  reputation: bigint;
28
28
  reward: bigint;
29
- amountJobsLaunched: bigint;
29
+ amountJobsProcessed: bigint;
30
30
  role?: string;
31
31
  fee?: bigint;
32
32
  publicKey?: string;
@@ -66,7 +66,7 @@ export interface IOperatorSubgraph extends Omit<IOperator, 'jobTypes'> {
66
66
  jobTypes?: string;
67
67
  }
68
68
 
69
- export interface IEscrowsFilter {
69
+ export interface IEscrowsFilter extends IPagination {
70
70
  launcher?: string;
71
71
  reputationOracle?: string;
72
72
  recordingOracle?: string;
@@ -75,7 +75,7 @@ export interface IEscrowsFilter {
75
75
  status?: EscrowStatus;
76
76
  from?: Date;
77
77
  to?: Date;
78
- networks: ChainId[];
78
+ chainId: ChainId;
79
79
  }
80
80
 
81
81
  export interface IEscrowConfig {
@@ -96,10 +96,13 @@ export interface IKeyPair {
96
96
  revocationCertificate?: string;
97
97
  }
98
98
 
99
- export interface IStatisticsParams {
99
+ export interface IStatisticsFilter extends IPagination {
100
100
  from?: Date;
101
101
  to?: Date;
102
- limit?: number;
102
+ }
103
+
104
+ export interface IHMTHoldersParams extends IPagination {
105
+ address?: string;
103
106
  }
104
107
 
105
108
  export interface IPayoutFilter {
@@ -116,7 +119,7 @@ export interface IKVStore {
116
119
 
117
120
  export interface ITransaction {
118
121
  block: bigint;
119
- hash: string;
122
+ txHash: string;
120
123
  from: string;
121
124
  to: string;
122
125
  timestamp: bigint;
@@ -124,8 +127,8 @@ export interface ITransaction {
124
127
  method: string;
125
128
  }
126
129
 
127
- export interface ITransactionsFilter {
128
- networks: ChainId[];
130
+ export interface ITransactionsFilter extends IPagination {
131
+ chainId: ChainId;
129
132
  startBlock?: number;
130
133
  endBlock?: number;
131
134
  startDate?: Date;
@@ -133,3 +136,9 @@ export interface ITransactionsFilter {
133
136
  fromAddress?: string;
134
137
  toAddress?: string;
135
138
  }
139
+
140
+ export interface IPagination {
141
+ first?: number;
142
+ skip?: number;
143
+ orderDirection?: OrderDirection;
144
+ }
package/src/kvstore.ts CHANGED
@@ -19,7 +19,10 @@ import {
19
19
  import gqlFetch from 'graphql-request';
20
20
  import { NetworkData } from './types';
21
21
  import { getSubgraphUrl, isValidUrl } from './utils';
22
- import { GET_KVSTORE_BY_ADDRESS_QUERY } from './graphql/queries/kvstore';
22
+ import {
23
+ GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY,
24
+ GET_KVSTORE_BY_ADDRESS_QUERY,
25
+ } from './graphql/queries/kvstore';
23
26
  import { KVStoreData } from './graphql';
24
27
  import { IKVStore } from './interfaces';
25
28
  /**
@@ -277,71 +280,162 @@ export class KVStoreClient extends BaseEthersClient {
277
280
  throw Error(`Failed to set URL and hash: ${e.message}`);
278
281
  }
279
282
  }
283
+ }
284
+
285
+ /**
286
+ * ## Introduction
287
+ *
288
+ * Utility class for KVStore-related operations.
289
+ *
290
+ * ## Installation
291
+ *
292
+ * ### npm
293
+ * ```bash
294
+ * npm install @human-protocol/sdk
295
+ * ```
296
+ *
297
+ * ### yarn
298
+ * ```bash
299
+ * yarn install @human-protocol/sdk
300
+ * ```
301
+ *
302
+ * ## Code example
303
+ *
304
+ * ### Signer
305
+ *
306
+ * **Using private key (backend)**
307
+ *
308
+ * ```ts
309
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
310
+ *
311
+ * const KVStoreAddresses = new KVStoreUtils.getKVStoreData({
312
+ * ChainId.POLYGON_AMOY,
313
+ * "0x1234567890123456789012345678901234567890",
314
+ * );
315
+ * ```
316
+ */
317
+ export class KVStoreUtils {
318
+ /**
319
+ * This function returns the KVStore data for a given address.
320
+ *
321
+ * @param {ChainId} chainId Network in which the KVStore is deployed
322
+ * @param {string} address Address of the KVStore
323
+ * @returns {Promise<IKVStore[]>} KVStore data
324
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
325
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
326
+ *
327
+ * **Code example**
328
+ *
329
+ * ```ts
330
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
331
+ *
332
+ * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
333
+ * console.log(kvStoreData);
334
+ * ```
335
+ */
336
+ public static async getKVStoreData(
337
+ chainId: ChainId,
338
+ address: string
339
+ ): Promise<IKVStore[]> {
340
+ const networkData = NETWORKS[chainId];
341
+
342
+ if (!networkData) {
343
+ throw ErrorUnsupportedChainID;
344
+ }
345
+
346
+ if (address && !ethers.isAddress(address)) {
347
+ throw ErrorInvalidAddress;
348
+ }
349
+
350
+ const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
351
+ getSubgraphUrl(networkData),
352
+ GET_KVSTORE_BY_ADDRESS_QUERY(),
353
+ { address: address.toLowerCase() }
354
+ );
355
+
356
+ const kvStoreData = kvstores.map((item) => ({
357
+ key: item.key,
358
+ value: item.value,
359
+ }));
360
+
361
+ return kvStoreData || [];
362
+ }
280
363
 
281
364
  /**
282
- * Gets the value of a key-value pair in the contract.
365
+ * Gets the value of a key-value pair in the KVStore using the subgraph.
283
366
  *
367
+ * @param {ChainId} chainId Network in which the KVStore is deployed
284
368
  * @param {string} address Address from which to get the key value.
285
369
  * @param {string} key Key to obtain the value.
286
- * @returns {string} Value of the key.
287
- *
370
+ * @returns {Promise<string>} Value of the key.
371
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
372
+ * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
373
+ * @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
288
374
  *
289
375
  * **Code example**
290
376
  *
291
- * > Need to have available stake.
292
- *
293
377
  * ```ts
294
- * import { providers } from 'ethers';
295
- * import { KVStoreClient } from '@human-protocol/sdk';
296
- *
297
- * const rpcUrl = 'YOUR_RPC_URL';
378
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
298
379
  *
299
- * const provider = new providers.JsonRpcProvider(rpcUrl);
300
- * const kvstoreClient = await KVStoreClient.build(provider);
380
+ * const chainId = ChainId.POLYGON_AMOY;
381
+ * const address = '0x1234567890123456789012345678901234567890';
382
+ * const key = 'role';
301
383
  *
302
- * const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
384
+ * const value = await KVStoreUtils.get(chainId, address, key);
385
+ * console.log(value);
303
386
  * ```
304
387
  */
305
- public async get(address: string, key: string): Promise<string> {
388
+ public static async get(
389
+ chainId: ChainId,
390
+ address: string,
391
+ key: string
392
+ ): Promise<string> {
306
393
  if (key === '') throw ErrorKVStoreEmptyKey;
307
394
  if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
308
395
 
309
- try {
310
- const result = await this.contract?.get(address, key);
311
- return result;
312
- } catch (e) {
313
- if (e instanceof Error) throw Error(`Failed to get value: ${e.message}`);
314
- return e;
396
+ const networkData = NETWORKS[chainId];
397
+
398
+ if (!networkData) {
399
+ throw ErrorUnsupportedChainID;
400
+ }
401
+
402
+ const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
403
+ getSubgraphUrl(networkData),
404
+ GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY(),
405
+ { address: address.toLowerCase(), key }
406
+ );
407
+
408
+ if (!kvstores || kvstores.length === 0) {
409
+ throw new Error(`Key "${key}" not found for address ${address}`);
315
410
  }
411
+
412
+ const value = kvstores[0].value;
413
+
414
+ return value;
316
415
  }
317
416
 
318
417
  /**
319
- * Gets the URL value of the given entity, and verify its hash.
418
+ * Gets the URL value of the given entity, and verifies its hash.
320
419
  *
420
+ * @param {ChainId} chainId Network in which the KVStore is deployed
321
421
  * @param {string} address Address from which to get the URL value.
322
- * @param {string} urlKey Configurable URL key. `url` by default.
323
- * @returns {string} URL value for the given address if exists, and the content is valid
324
- *
422
+ * @param {string} urlKey Configurable URL key. `url` by default.
423
+ * @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
325
424
  *
326
425
  * **Code example**
327
426
  *
328
427
  * ```ts
329
- * import { providers } from 'ethers';
330
- * import { KVStoreClient } from '@human-protocol/sdk';
428
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
331
429
  *
332
- * const rpcUrl = 'YOUR_RPC_URL';
430
+ * const chainId = ChainId.POLYGON_AMOY;
431
+ * const address = '0x1234567890123456789012345678901234567890';
333
432
  *
334
- * const provider = new providers.JsonRpcProvider(rpcUrl);
335
- * const kvstoreClient = await KVStoreClient.build(provider);
336
- *
337
- * const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
338
- * const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
339
- * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
340
- * 'linkedin_url'
341
- * );
433
+ * const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
434
+ * console.log(url);
342
435
  * ```
343
436
  */
344
- public async getFileUrlAndVerifyHash(
437
+ public static async getFileUrlAndVerifyHash(
438
+ chainId: ChainId,
345
439
  address: string,
346
440
  urlKey = 'url'
347
441
  ): Promise<string> {
@@ -352,7 +446,7 @@ export class KVStoreClient extends BaseEthersClient {
352
446
  hash = '';
353
447
 
354
448
  try {
355
- url = await this.contract?.get(address, urlKey);
449
+ url = await this.get(chainId, address, urlKey);
356
450
  } catch (e) {
357
451
  if (e instanceof Error) throw Error(`Failed to get URL: ${e.message}`);
358
452
  }
@@ -363,7 +457,7 @@ export class KVStoreClient extends BaseEthersClient {
363
457
  }
364
458
 
365
459
  try {
366
- hash = await this.contract?.get(address, hashKey);
460
+ hash = await this.get(chainId, address, hashKey);
367
461
  } catch (e) {
368
462
  if (e instanceof Error) throw Error(`Failed to get Hash: ${e.message}`);
369
463
  }
@@ -379,28 +473,30 @@ export class KVStoreClient extends BaseEthersClient {
379
473
  }
380
474
 
381
475
  /**
382
- * Gets the public key of the given entity, and verify its hash.
476
+ * Gets the public key of the given entity, and verifies its hash.
383
477
  *
478
+ * @param {ChainId} chainId Network in which the KVStore is deployed
384
479
  * @param {string} address Address from which to get the public key.
385
- * @returns {string} Public key for the given address if exists, and the content is valid
386
- *
480
+ * @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
387
481
  *
388
482
  * **Code example**
389
483
  *
390
484
  * ```ts
391
- * import { providers } from 'ethers';
392
- * import { KVStoreClient } from '@human-protocol/sdk';
393
- *
394
- * const rpcUrl = 'YOUR_RPC_URL';
485
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
395
486
  *
396
- * const provider = new providers.JsonRpcProvider(rpcUrl);
397
- * const kvstoreClient = await KVStoreClient.build(provider);
487
+ * const chainId = ChainId.POLYGON_AMOY;
488
+ * const address = '0x1234567890123456789012345678901234567890';
398
489
  *
399
- * const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
490
+ * const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
491
+ * console.log(publicKey);
400
492
  * ```
401
493
  */
402
- public async getPublicKey(address: string): Promise<string> {
494
+ public static async getPublicKey(
495
+ chainId: ChainId,
496
+ address: string
497
+ ): Promise<string> {
403
498
  const publicKeyUrl = await this.getFileUrlAndVerifyHash(
499
+ chainId,
404
500
  address,
405
501
  KVStoreKeys.publicKey
406
502
  );
@@ -414,112 +510,3 @@ export class KVStoreClient extends BaseEthersClient {
414
510
  return publicKey;
415
511
  }
416
512
  }
417
-
418
- /**
419
- * ## Introduction
420
- *
421
- * Utility class for KVStore-related operations.
422
- *
423
- * ## Installation
424
- *
425
- * ### npm
426
- * ```bash
427
- * npm install @human-protocol/sdk
428
- * ```
429
- *
430
- * ### yarn
431
- * ```bash
432
- * yarn install @human-protocol/sdk
433
- * ```
434
- *
435
- * ## Code example
436
- *
437
- * ### Signer
438
- *
439
- * **Using private key (backend)**
440
- *
441
- * ```ts
442
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
443
- *
444
- * const KVStoreAddresses = new KVStoreUtils.getData({
445
- * networks: [ChainId.POLYGON_AMOY]
446
- * });
447
- * ```
448
- */
449
- export class KVStoreUtils {
450
- /**
451
- * This function returns the KVStore data for a given address.
452
- *
453
- * > This uses Subgraph
454
- *
455
- * **Input parameters**
456
- *
457
- * ```ts
458
- * enum ChainId {
459
- * ALL = -1,
460
- * MAINNET = 1,
461
- * RINKEBY = 4,
462
- * GOERLI = 5,
463
- * BSC_MAINNET = 56,
464
- * BSC_TESTNET = 97,
465
- * POLYGON = 137,
466
- * POLYGON_MUMBAI = 80001,
467
- * POLYGON_AMOY = 80002,
468
- * MOONBEAM = 1284,
469
- * MOONBASE_ALPHA = 1287,
470
- * AVALANCHE = 43114,
471
- * AVALANCHE_TESTNET = 43113,
472
- * CELO = 42220,
473
- * CELO_ALFAJORES = 44787,
474
- * LOCALHOST = 1338,
475
- * }
476
- * ```
477
- *
478
- * ```ts
479
- * interface IKVStore {
480
- * key: string;
481
- * value: string;
482
- * }
483
- * ```
484
- *
485
- * @param {ChainId} chainId Network in which the KVStore is deployed
486
- * @param {string} address Address of the KVStore
487
- * @returns {Promise<IKVStore[]>} KVStore data
488
- *
489
- * **Code example**
490
- *
491
- * ```ts
492
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
493
- *
494
- * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
495
- * console.log(kvStoreData);
496
- * ```
497
- */
498
- public static async getKVStoreData(
499
- chainId: ChainId,
500
- address: string
501
- ): Promise<IKVStore[]> {
502
- const networkData = NETWORKS[chainId];
503
-
504
- if (!networkData) {
505
- throw ErrorUnsupportedChainID;
506
- }
507
-
508
- if (address && !ethers.isAddress(address)) {
509
- throw ErrorInvalidAddress;
510
- }
511
-
512
- const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
513
- getSubgraphUrl(networkData),
514
- GET_KVSTORE_BY_ADDRESS_QUERY(),
515
- { address: address.toLowerCase() }
516
- );
517
-
518
- const kvStoreData = kvstores.map((item) => ({
519
- key: item.key,
520
- value: item.value,
521
- }));
522
-
523
- return kvStoreData || [];
524
- }
525
- }
package/src/operator.ts CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  ErrorInvalidStakerAddressProvided,
22
22
  ErrorUnsupportedChainID,
23
23
  } from './error';
24
- import { getSubgraphUrl, throwError } from './utils';
24
+ import { getSubgraphUrl } from './utils';
25
25
  import { ChainId } from './enums';
26
26
  import { NETWORKS } from './constants';
27
27
 
@@ -54,28 +54,28 @@ export class OperatorUtils {
54
54
  throw ErrorUnsupportedChainID;
55
55
  }
56
56
 
57
- try {
58
- const { leader } = await gqlFetch<{
59
- leader: ILeaderSubgraph;
60
- }>(getSubgraphUrl(networkData), GET_LEADER_QUERY, {
61
- address: address.toLowerCase(),
62
- });
57
+ const { leader } = await gqlFetch<{
58
+ leader: ILeaderSubgraph;
59
+ }>(getSubgraphUrl(networkData), GET_LEADER_QUERY, {
60
+ address: address.toLowerCase(),
61
+ });
63
62
 
64
- let jobTypes: string[] = [];
63
+ if (!leader) {
64
+ return (leader as ILeader) || null;
65
+ }
65
66
 
66
- if (typeof leader.jobTypes === 'string') {
67
- jobTypes = leader.jobTypes.split(',');
68
- } else if (Array.isArray(leader.jobTypes)) {
69
- jobTypes = leader.jobTypes;
70
- }
67
+ let jobTypes: string[] = [];
71
68
 
72
- return {
73
- ...leader,
74
- jobTypes,
75
- };
76
- } catch (e) {
77
- return throwError(e);
69
+ if (typeof leader.jobTypes === 'string') {
70
+ jobTypes = leader.jobTypes.split(',');
71
+ } else if (Array.isArray(leader.jobTypes)) {
72
+ jobTypes = leader.jobTypes;
78
73
  }
74
+
75
+ return {
76
+ ...leader,
77
+ jobTypes,
78
+ };
79
79
  }
80
80
 
81
81
  /**
@@ -97,45 +97,41 @@ export class OperatorUtils {
97
97
  * ```
98
98
  */
99
99
  public static async getLeaders(filter: ILeadersFilter): Promise<ILeader[]> {
100
- try {
101
- let leaders_data: ILeader[] = [];
100
+ let leaders_data: ILeader[] = [];
102
101
 
103
- const networkData = NETWORKS[filter.chainId];
102
+ const networkData = NETWORKS[filter.chainId];
104
103
 
105
- if (!networkData) {
106
- throw ErrorUnsupportedChainID;
107
- }
108
-
109
- const { leaders } = await gqlFetch<{
110
- leaders: ILeaderSubgraph[];
111
- }>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), {
112
- role: filter?.role,
113
- });
104
+ if (!networkData) {
105
+ throw ErrorUnsupportedChainID;
106
+ }
114
107
 
115
- if (!leaders) {
116
- return [];
117
- }
108
+ const { leaders } = await gqlFetch<{
109
+ leaders: ILeaderSubgraph[];
110
+ }>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), {
111
+ role: filter?.role,
112
+ });
118
113
 
119
- leaders_data = leaders_data.concat(
120
- leaders.map((leader) => {
121
- let jobTypes: string[] = [];
122
-
123
- if (typeof leader.jobTypes === 'string') {
124
- jobTypes = leader.jobTypes.split(',');
125
- } else if (Array.isArray(leader.jobTypes)) {
126
- jobTypes = leader.jobTypes;
127
- }
128
-
129
- return {
130
- ...leader,
131
- jobTypes,
132
- };
133
- })
134
- );
135
- return leaders_data;
136
- } catch (e) {
137
- return throwError(e);
114
+ if (!leaders) {
115
+ return [];
138
116
  }
117
+
118
+ leaders_data = leaders_data.concat(
119
+ leaders.map((leader) => {
120
+ let jobTypes: string[] = [];
121
+
122
+ if (typeof leader.jobTypes === 'string') {
123
+ jobTypes = leader.jobTypes.split(',');
124
+ } else if (Array.isArray(leader.jobTypes)) {
125
+ jobTypes = leader.jobTypes;
126
+ }
127
+
128
+ return {
129
+ ...leader,
130
+ jobTypes,
131
+ };
132
+ })
133
+ );
134
+ return leaders_data;
139
135
  }
140
136
 
141
137
  /**
@@ -162,31 +158,27 @@ export class OperatorUtils {
162
158
  if (!networkData) {
163
159
  throw ErrorUnsupportedChainID;
164
160
  }
165
- try {
166
- const { reputationNetwork } = await gqlFetch<{
167
- reputationNetwork: IReputationNetworkSubgraph;
168
- }>(getSubgraphUrl(networkData), GET_REPUTATION_NETWORK_QUERY(role), {
169
- address: address.toLowerCase(),
170
- role: role,
171
- });
172
-
173
- return reputationNetwork.operators.map((operator) => {
174
- let jobTypes: string[] = [];
161
+ const { reputationNetwork } = await gqlFetch<{
162
+ reputationNetwork: IReputationNetworkSubgraph;
163
+ }>(getSubgraphUrl(networkData), GET_REPUTATION_NETWORK_QUERY(role), {
164
+ address: address.toLowerCase(),
165
+ role: role,
166
+ });
167
+
168
+ return reputationNetwork.operators.map((operator) => {
169
+ let jobTypes: string[] = [];
175
170
 
176
- if (typeof operator.jobTypes === 'string') {
177
- jobTypes = operator.jobTypes.split(',');
178
- } else if (Array.isArray(operator.jobTypes)) {
179
- jobTypes = operator.jobTypes;
180
- }
171
+ if (typeof operator.jobTypes === 'string') {
172
+ jobTypes = operator.jobTypes.split(',');
173
+ } else if (Array.isArray(operator.jobTypes)) {
174
+ jobTypes = operator.jobTypes;
175
+ }
181
176
 
182
- return {
183
- ...operator,
184
- jobTypes,
185
- };
186
- });
187
- } catch (e) {
188
- return throwError(e);
189
- }
177
+ return {
178
+ ...operator,
179
+ jobTypes,
180
+ };
181
+ });
190
182
  }
191
183
 
192
184
  /**
@@ -217,21 +209,17 @@ export class OperatorUtils {
217
209
  throw ErrorUnsupportedChainID;
218
210
  }
219
211
 
220
- try {
221
- const { rewardAddedEvents } = await gqlFetch<{
222
- rewardAddedEvents: RewardAddedEventData[];
223
- }>(getSubgraphUrl(networkData), GET_REWARD_ADDED_EVENTS_QUERY, {
224
- slasherAddress: slasherAddress.toLowerCase(),
225
- });
212
+ const { rewardAddedEvents } = await gqlFetch<{
213
+ rewardAddedEvents: RewardAddedEventData[];
214
+ }>(getSubgraphUrl(networkData), GET_REWARD_ADDED_EVENTS_QUERY, {
215
+ slasherAddress: slasherAddress.toLowerCase(),
216
+ });
226
217
 
227
- return rewardAddedEvents.map((reward: any) => {
228
- return {
229
- escrowAddress: reward.escrow,
230
- amount: reward.amount,
231
- };
232
- });
233
- } catch (e) {
234
- return throwError(e);
235
- }
218
+ return rewardAddedEvents.map((reward: any) => {
219
+ return {
220
+ escrowAddress: reward.escrow,
221
+ amount: reward.amount,
222
+ };
223
+ });
236
224
  }
237
225
  }