@human-protocol/sdk 5.2.0 → 6.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 (63) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +4 -5
  4. package/dist/constants.js +6 -6
  5. package/dist/encryption.d.ts +68 -203
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +66 -202
  8. package/dist/error.d.ts +0 -24
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +2 -26
  11. package/dist/escrow.d.ts +427 -780
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +314 -684
  14. package/dist/graphql/queries/operator.d.ts.map +1 -1
  15. package/dist/graphql/queries/operator.js +3 -1
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/kvstore.d.ts +119 -181
  21. package/dist/kvstore.d.ts.map +1 -1
  22. package/dist/kvstore.js +119 -182
  23. package/dist/operator.d.ts +59 -30
  24. package/dist/operator.d.ts.map +1 -1
  25. package/dist/operator.js +59 -30
  26. package/dist/staking.d.ts +135 -134
  27. package/dist/staking.d.ts.map +1 -1
  28. package/dist/staking.js +135 -134
  29. package/dist/statistics.d.ts +104 -134
  30. package/dist/statistics.d.ts.map +1 -1
  31. package/dist/statistics.js +119 -144
  32. package/dist/transaction.d.ts +36 -15
  33. package/dist/transaction.d.ts.map +1 -1
  34. package/dist/transaction.js +36 -15
  35. package/dist/types.d.ts +0 -54
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +31 -17
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +31 -17
  40. package/dist/worker.d.ts +35 -14
  41. package/dist/worker.d.ts.map +1 -1
  42. package/dist/worker.js +35 -14
  43. package/package.json +7 -24
  44. package/src/base.ts +4 -5
  45. package/src/constants.ts +6 -6
  46. package/src/encryption.ts +69 -203
  47. package/src/error.ts +0 -36
  48. package/src/escrow.ts +425 -780
  49. package/src/graphql/queries/operator.ts +3 -1
  50. package/src/graphql/types.ts +4 -2
  51. package/src/index.ts +4 -5
  52. package/src/kvstore.ts +120 -183
  53. package/src/operator.ts +59 -30
  54. package/src/staking.ts +135 -134
  55. package/src/statistics.ts +125 -146
  56. package/src/transaction.ts +36 -15
  57. package/src/types.ts +0 -57
  58. package/src/utils.ts +31 -17
  59. package/src/worker.ts +35 -14
  60. package/dist/storage.d.ts +0 -186
  61. package/dist/storage.d.ts.map +0 -1
  62. package/dist/storage.js +0 -319
  63. package/src/storage.ts +0 -313
package/src/statistics.ts CHANGED
@@ -30,51 +30,21 @@ import {
30
30
  } from './utils';
31
31
 
32
32
  /**
33
- * ## Introduction
33
+ * Utility class for statistics-related queries.
34
34
  *
35
- * This client enables obtaining statistical information from the subgraph.
36
- *
37
- * Unlike other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
38
- * We just need to create a client object using relevant network data.
39
- *
40
- * ```ts
41
- * constructor(network: NetworkData)
42
- * ```
43
- *
44
- * ## Installation
45
- *
46
- * ### npm
47
- * ```bash
48
- * npm install @human-protocol/sdk
49
- * ```
50
- *
51
- * ### yarn
52
- * ```bash
53
- * yarn install @human-protocol/sdk
54
- * ```
55
- *
56
- * ## Code example
35
+ * Unlike other SDK clients, `StatisticsUtils` does not require `signer` or `provider` to be provided.
36
+ * We just need to pass the network data to each static method.
57
37
  *
38
+ * @example
58
39
  * ```ts
59
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
40
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
60
41
  *
61
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
42
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
43
+ * const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
44
+ * console.log('Total escrows:', escrowStats.totalEscrows);
62
45
  * ```
63
46
  */
64
- export class StatisticsClient {
65
- public networkData: NetworkData;
66
- public subgraphUrl: string;
67
-
68
- /**
69
- * **StatisticsClient constructor**
70
- *
71
- * @param {NetworkData} networkData - The network information required to connect to the Statistics contract
72
- */
73
- constructor(networkData: NetworkData) {
74
- this.networkData = networkData;
75
- this.subgraphUrl = getSubgraphUrl(networkData);
76
- }
77
-
47
+ export class StatisticsUtils {
78
48
  /**
79
49
  * This function returns the statistical data of escrows.
80
50
  *
@@ -106,29 +76,36 @@ export class StatisticsClient {
106
76
  * };
107
77
  * ```
108
78
  *
109
- * @param {IStatisticsFilter} filter Statistics params with duration data
110
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
111
- * @returns {Promise<IEscrowStatistics>} Escrow statistics data.
112
- *
113
- * **Code example**
79
+ * @param networkData - The network information required to connect to the subgraph
80
+ * @param filter - Statistics params with duration data
81
+ * @param options - Optional configuration for subgraph requests.
82
+ * @returns Escrow statistics data.
114
83
  *
84
+ * @example
115
85
  * ```ts
116
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
117
- *
118
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
119
- *
120
- * const escrowStatistics = await statisticsClient.getEscrowStatistics();
121
- * const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({
122
- * from: new Date('2021-04-01'),
123
- * to: new Date('2021-04-30'),
124
- * });
86
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
87
+ *
88
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
89
+ * const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
90
+ * console.log('Total escrows:', escrowStats.totalEscrows);
91
+ *
92
+ * const escrowStatsApril = await StatisticsUtils.getEscrowStatistics(
93
+ * networkData,
94
+ * {
95
+ * from: new Date('2021-04-01'),
96
+ * to: new Date('2021-04-30'),
97
+ * }
98
+ * );
99
+ * console.log('April escrows:', escrowStatsApril.totalEscrows);
125
100
  * ```
126
101
  */
127
- async getEscrowStatistics(
102
+ static async getEscrowStatistics(
103
+ networkData: NetworkData,
128
104
  filter: IStatisticsFilter = {},
129
105
  options?: SubgraphOptions
130
106
  ): Promise<IEscrowStatistics> {
131
107
  try {
108
+ const subgraphUrl = getSubgraphUrl(networkData);
132
109
  const first =
133
110
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
134
111
  const skip = filter.skip || 0;
@@ -136,12 +113,12 @@ export class StatisticsClient {
136
113
 
137
114
  const { escrowStatistics } = await customGqlFetch<{
138
115
  escrowStatistics: EscrowStatisticsData;
139
- }>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY, options);
116
+ }>(subgraphUrl, GET_ESCROW_STATISTICS_QUERY, options);
140
117
 
141
118
  const { eventDayDatas } = await customGqlFetch<{
142
119
  eventDayDatas: EventDayData[];
143
120
  }>(
144
- this.subgraphUrl,
121
+ subgraphUrl,
145
122
  GET_EVENT_DAY_DATA_QUERY(filter),
146
123
  {
147
124
  from: filter.from ? getUnixTimestamp(filter.from) : undefined,
@@ -197,29 +174,36 @@ export class StatisticsClient {
197
174
  * };
198
175
  * ```
199
176
  *
200
- * @param {IStatisticsFilter} filter Statistics params with duration data
201
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
202
- * @returns {Promise<IWorkerStatistics>} Worker statistics data.
203
- *
204
- * **Code example**
177
+ * @param networkData - The network information required to connect to the subgraph
178
+ * @param filter - Statistics params with duration data
179
+ * @param options - Optional configuration for subgraph requests.
180
+ * @returns Worker statistics data.
205
181
  *
182
+ * @example
206
183
  * ```ts
207
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
208
- *
209
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
210
- *
211
- * const workerStatistics = await statisticsClient.getWorkerStatistics();
212
- * const workerStatisticsApril = await statisticsClient.getWorkerStatistics({
213
- * from: new Date('2021-04-01'),
214
- * to: new Date('2021-04-30'),
215
- * });
184
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
185
+ *
186
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
187
+ * const workerStats = await StatisticsUtils.getWorkerStatistics(networkData);
188
+ * console.log('Daily workers data:', workerStats.dailyWorkersData);
189
+ *
190
+ * const workerStatsApril = await StatisticsUtils.getWorkerStatistics(
191
+ * networkData,
192
+ * {
193
+ * from: new Date('2021-04-01'),
194
+ * to: new Date('2021-04-30'),
195
+ * }
196
+ * );
197
+ * console.log('April workers:', workerStatsApril.dailyWorkersData.length);
216
198
  * ```
217
199
  */
218
- async getWorkerStatistics(
200
+ static async getWorkerStatistics(
201
+ networkData: NetworkData,
219
202
  filter: IStatisticsFilter = {},
220
203
  options?: SubgraphOptions
221
204
  ): Promise<IWorkerStatistics> {
222
205
  try {
206
+ const subgraphUrl = getSubgraphUrl(networkData);
223
207
  const first =
224
208
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
225
209
  const skip = filter.skip || 0;
@@ -228,7 +212,7 @@ export class StatisticsClient {
228
212
  const { eventDayDatas } = await customGqlFetch<{
229
213
  eventDayDatas: EventDayData[];
230
214
  }>(
231
- this.subgraphUrl,
215
+ subgraphUrl,
232
216
  GET_EVENT_DAY_DATA_QUERY(filter),
233
217
  {
234
218
  from: filter.from ? getUnixTimestamp(filter.from) : undefined,
@@ -279,50 +263,43 @@ export class StatisticsClient {
279
263
  * };
280
264
  * ```
281
265
  *
282
- * @param {IStatisticsFilter} filter Statistics params with duration data
283
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
284
- * @returns {Promise<IPaymentStatistics>} Payment statistics data.
285
- *
286
- * **Code example**
266
+ * @param networkData - The network information required to connect to the subgraph
267
+ * @param filter - Statistics params with duration data
268
+ * @param options - Optional configuration for subgraph requests.
269
+ * @returns Payment statistics data.
287
270
  *
271
+ * @example
288
272
  * ```ts
289
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
290
- *
291
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
273
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
292
274
  *
275
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
276
+ * const paymentStats = await StatisticsUtils.getPaymentStatistics(networkData);
293
277
  * console.log(
294
278
  * 'Payment statistics:',
295
- * (await statisticsClient.getPaymentStatistics()).dailyPaymentsData.map(
296
- * (p) => ({
297
- * ...p,
298
- * totalAmountPaid: p.totalAmountPaid.toString(),
299
- * averageAmountPerJob: p.averageAmountPerJob.toString(),
300
- * averageAmountPerWorker: p.averageAmountPerWorker.toString(),
301
- * })
302
- * )
303
- * );
304
- *
305
- * console.log(
306
- * 'Payment statistics from 5/8 - 6/8:',
307
- * (
308
- * await statisticsClient.getPaymentStatistics({
309
- * from: new Date(2023, 4, 8),
310
- * to: new Date(2023, 5, 8),
311
- * })
312
- * ).dailyPaymentsData.map((p) => ({
279
+ * paymentStats.dailyPaymentsData.map((p) => ({
313
280
  * ...p,
314
281
  * totalAmountPaid: p.totalAmountPaid.toString(),
315
- * averageAmountPerJob: p.averageAmountPerJob.toString(),
316
282
  * averageAmountPerWorker: p.averageAmountPerWorker.toString(),
317
283
  * }))
318
284
  * );
285
+ *
286
+ * const paymentStatsRange = await StatisticsUtils.getPaymentStatistics(
287
+ * networkData,
288
+ * {
289
+ * from: new Date(2023, 4, 8),
290
+ * to: new Date(2023, 5, 8),
291
+ * }
292
+ * );
293
+ * console.log('Payment statistics from 5/8 - 6/8:', paymentStatsRange.dailyPaymentsData.length);
319
294
  * ```
320
295
  */
321
- async getPaymentStatistics(
296
+ static async getPaymentStatistics(
297
+ networkData: NetworkData,
322
298
  filter: IStatisticsFilter = {},
323
299
  options?: SubgraphOptions
324
300
  ): Promise<IPaymentStatistics> {
325
301
  try {
302
+ const subgraphUrl = getSubgraphUrl(networkData);
326
303
  const first =
327
304
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
328
305
  const skip = filter.skip || 0;
@@ -331,7 +308,7 @@ export class StatisticsClient {
331
308
  const { eventDayDatas } = await customGqlFetch<{
332
309
  eventDayDatas: EventDayData[];
333
310
  }>(
334
- this.subgraphUrl,
311
+ subgraphUrl,
335
312
  GET_EVENT_DAY_DATA_QUERY(filter),
336
313
  {
337
314
  from: filter.from ? getUnixTimestamp(filter.from) : undefined,
@@ -371,29 +348,31 @@ export class StatisticsClient {
371
348
  * };
372
349
  * ```
373
350
  *
374
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
375
- * @returns {Promise<IHMTStatistics>} HMToken statistics data.
376
- *
377
- * **Code example**
351
+ * @param networkData - The network information required to connect to the subgraph
352
+ * @param options - Optional configuration for subgraph requests.
353
+ * @returns HMToken statistics data.
378
354
  *
355
+ * @example
379
356
  * ```ts
380
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
381
- *
382
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
383
- *
384
- * const hmtStatistics = await statisticsClient.getHMTStatistics();
357
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
385
358
  *
359
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
360
+ * const hmtStats = await StatisticsUtils.getHMTStatistics(networkData);
386
361
  * console.log('HMT statistics:', {
387
- * ...hmtStatistics,
388
- * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
362
+ * ...hmtStats,
363
+ * totalTransferAmount: hmtStats.totalTransferAmount.toString(),
389
364
  * });
390
365
  * ```
391
366
  */
392
- async getHMTStatistics(options?: SubgraphOptions): Promise<IHMTStatistics> {
367
+ static async getHMTStatistics(
368
+ networkData: NetworkData,
369
+ options?: SubgraphOptions
370
+ ): Promise<IHMTStatistics> {
393
371
  try {
372
+ const subgraphUrl = getSubgraphUrl(networkData);
394
373
  const { hmtokenStatistics } = await customGqlFetch<{
395
374
  hmtokenStatistics: HMTStatisticsData;
396
- }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY, options);
375
+ }>(subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY, options);
397
376
 
398
377
  return {
399
378
  totalTransferAmount: BigInt(hmtokenStatistics.totalValueTransfered),
@@ -408,39 +387,37 @@ export class StatisticsClient {
408
387
  /**
409
388
  * This function returns the holders of the HMToken with optional filters and ordering.
410
389
  *
411
- * **Input parameters**
412
- *
413
- * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
414
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
415
- * @returns {Promise<IHMTHolder[]>} List of HMToken holders.
416
- *
417
- * **Code example**
390
+ * @param networkData - The network information required to connect to the subgraph
391
+ * @param params - HMT Holders params with filters and ordering
392
+ * @param options - Optional configuration for subgraph requests.
393
+ * @returns List of HMToken holders.
418
394
  *
395
+ * @example
419
396
  * ```ts
420
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
421
- *
422
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
397
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
423
398
  *
424
- * const hmtHolders = await statisticsClient.getHMTHolders({
399
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
400
+ * const hmtHolders = await StatisticsUtils.getHMTHolders(networkData, {
425
401
  * orderDirection: 'asc',
426
402
  * });
427
- *
428
403
  * console.log('HMT holders:', hmtHolders.map((h) => ({
429
404
  * ...h,
430
405
  * balance: h.balance.toString(),
431
406
  * })));
432
407
  * ```
433
408
  */
434
- async getHMTHolders(
409
+ static async getHMTHolders(
410
+ networkData: NetworkData,
435
411
  params: IHMTHoldersParams = {},
436
412
  options?: SubgraphOptions
437
413
  ): Promise<IHMTHolder[]> {
438
414
  try {
415
+ const subgraphUrl = getSubgraphUrl(networkData);
439
416
  const { address, orderDirection } = params;
440
417
  const query = GET_HOLDERS_QUERY(address);
441
418
 
442
419
  const { holders } = await customGqlFetch<{ holders: HMTHolderData[] }>(
443
- this.subgraphUrl,
420
+ subgraphUrl,
444
421
  query,
445
422
  {
446
423
  address,
@@ -484,34 +461,36 @@ export class StatisticsClient {
484
461
  * }
485
462
  * ```
486
463
  *
487
- * @param {IStatisticsFilter} filter Statistics params with duration data
488
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
489
- * @returns {Promise<IDailyHMT[]>} Daily HMToken statistics data.
490
- *
491
- * **Code example**
464
+ * @param networkData - The network information required to connect to the subgraph
465
+ * @param filter - Statistics params with duration data
466
+ * @param options - Optional configuration for subgraph requests.
467
+ * @returns Daily HMToken statistics data.
492
468
  *
469
+ * @example
493
470
  * ```ts
494
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
495
- *
496
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
497
- *
498
- * const dailyHMTStats = await statisticsClient.getHMTStatistics();
471
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
499
472
  *
473
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
474
+ * const dailyHMTStats = await StatisticsUtils.getHMTDailyData(networkData);
500
475
  * console.log('Daily HMT statistics:', dailyHMTStats);
501
476
  *
502
- * const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
503
- * from: new Date(2023, 4, 8),
504
- * to: new Date(2023, 5, 8),
505
- * });
506
- *
507
- * console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
477
+ * const hmtStatsRange = await StatisticsUtils.getHMTDailyData(
478
+ * networkData,
479
+ * {
480
+ * from: new Date(2023, 4, 8),
481
+ * to: new Date(2023, 5, 8),
482
+ * }
483
+ * );
484
+ * console.log('HMT statistics from 5/8 - 6/8:', hmtStatsRange.length);
508
485
  * ```
509
486
  */
510
- async getHMTDailyData(
487
+ static async getHMTDailyData(
488
+ networkData: NetworkData,
511
489
  filter: IStatisticsFilter = {},
512
490
  options?: SubgraphOptions
513
491
  ): Promise<IDailyHMT[]> {
514
492
  try {
493
+ const subgraphUrl = getSubgraphUrl(networkData);
515
494
  const first =
516
495
  filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
517
496
  const skip = filter.skip || 0;
@@ -520,7 +499,7 @@ export class StatisticsClient {
520
499
  const { eventDayDatas } = await customGqlFetch<{
521
500
  eventDayDatas: EventDayData[];
522
501
  }>(
523
- this.subgraphUrl,
502
+ subgraphUrl,
524
503
  GET_EVENT_DAY_DATA_QUERY(filter),
525
504
  {
526
505
  from: filter.from ? getUnixTimestamp(filter.from) : undefined,
@@ -19,6 +19,20 @@ import {
19
19
  } from './interfaces';
20
20
  import { getSubgraphUrl, getUnixTimestamp, customGqlFetch } from './utils';
21
21
 
22
+ /**
23
+ * Utility class for transaction-related queries.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
28
+ *
29
+ * const transaction = await TransactionUtils.getTransaction(
30
+ * ChainId.POLYGON_AMOY,
31
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
32
+ * );
33
+ * console.log('Transaction:', transaction);
34
+ * ```
35
+ */
22
36
  export class TransactionUtils {
23
37
  /**
24
38
  * This function returns the transaction data for the given hash.
@@ -51,17 +65,22 @@ export class TransactionUtils {
51
65
  * };
52
66
  * ```
53
67
  *
54
- * @param {ChainId} chainId The chain ID.
55
- * @param {string} hash The transaction hash.
56
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
57
- * @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
58
- *
59
- * **Code example**
68
+ * @param chainId - The chain ID.
69
+ * @param hash - The transaction hash.
70
+ * @param options - Optional configuration for subgraph requests.
71
+ * @returns Returns the transaction details or null if not found.
72
+ * @throws ErrorInvalidHashProvided If the hash is invalid
73
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
60
74
  *
75
+ * @example
61
76
  * ```ts
62
77
  * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
63
78
  *
64
- * const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
79
+ * const transaction = await TransactionUtils.getTransaction(
80
+ * ChainId.POLYGON_AMOY,
81
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
82
+ * );
83
+ * console.log('Transaction:', transaction);
65
84
  * ```
66
85
  */
67
86
  public static async getTransaction(
@@ -116,7 +135,7 @@ export class TransactionUtils {
116
135
  * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
117
136
  * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
118
137
  * }
119
- *
138
+ * ```
120
139
  *
121
140
  * ```ts
122
141
  * type InternalTransaction = {
@@ -146,17 +165,18 @@ export class TransactionUtils {
146
165
  * };
147
166
  * ```
148
167
  *
149
- * @param {ITransactionsFilter} filter Filter for the transactions.
150
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
151
- * @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
152
- *
153
- * **Code example**
168
+ * @param filter - Filter for the transactions.
169
+ * @param options - Optional configuration for subgraph requests.
170
+ * @returns Returns an array with all the transaction details.
171
+ * @throws ErrorCannotUseDateAndBlockSimultaneously If both date and block filters are used
172
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
154
173
  *
174
+ * @example
155
175
  * ```ts
156
176
  * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
157
177
  *
158
- * const filter: ITransactionsFilter = {
159
- * chainId: ChainId.POLYGON,
178
+ * const filter = {
179
+ * chainId: ChainId.POLYGON_AMOY,
160
180
  * startDate: new Date('2022-01-01'),
161
181
  * endDate: new Date('2022-12-31'),
162
182
  * first: 10,
@@ -164,6 +184,7 @@ export class TransactionUtils {
164
184
  * orderDirection: OrderDirection.DESC,
165
185
  * };
166
186
  * const transactions = await TransactionUtils.getTransactions(filter);
187
+ * console.log('Transactions:', transactions.length);
167
188
  * ```
168
189
  */
169
190
  public static async getTransactions(
package/src/types.ts CHANGED
@@ -36,63 +36,6 @@ export enum EscrowStatus {
36
36
  ToCancel,
37
37
  }
38
38
 
39
- /**
40
- * AWS/GCP cloud storage access data
41
- * @readonly
42
- * @deprecated StorageClient is deprecated. Use Minio.Client directly.
43
- */
44
- export type StorageCredentials = {
45
- /**
46
- * Access Key
47
- */
48
- accessKey: string;
49
- /**
50
- * Secret Key
51
- */
52
- secretKey: string;
53
- };
54
-
55
- /**
56
- * @deprecated StorageClient is deprecated. Use Minio.Client directly.
57
- */
58
- export type StorageParams = {
59
- /**
60
- * Request endPoint
61
- */
62
- endPoint: string;
63
- /**
64
- * Enable secure (HTTPS) access. Default value set to false
65
- */
66
- useSSL: boolean;
67
- /**
68
- * Region
69
- */
70
- region?: string;
71
- /**
72
- * TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
73
- */
74
- port?: number;
75
- };
76
-
77
- /**
78
- * Upload file data
79
- * @readonly
80
- */
81
- export type UploadFile = {
82
- /**
83
- * Uploaded object key
84
- */
85
- key: string;
86
- /**
87
- * Uploaded object URL
88
- */
89
- url: string;
90
- /**
91
- * Hash of uploaded object key
92
- */
93
- hash: string;
94
- };
95
-
96
39
  /**
97
40
  * Network data
98
41
  */
package/src/utils.ts CHANGED
@@ -21,10 +21,16 @@ import { NetworkData } from './types';
21
21
  import { SubgraphOptions } from './interfaces';
22
22
 
23
23
  /**
24
- * **Handle and throw the error.*
24
+ * Handles and throws appropriate error types based on the Ethereum error.
25
25
  *
26
- * @param {any} e
27
- * @returns
26
+ * @param e - The error to handle
27
+ * @throws {InvalidArgumentError} If the error is an invalid argument error
28
+ * @throws {ContractExecutionError} If the error is a contract execution error
29
+ * @throws {TransactionReplaced} If the transaction was replaced
30
+ * @throws {ReplacementUnderpriced} If the replacement transaction was underpriced
31
+ * @throws {NumericFault} If there's a numeric fault
32
+ * @throws {NonceExpired} If the nonce has expired
33
+ * @throws {EthereumError} For any other Ethereum-related error
28
34
  */
29
35
  export const throwError = (e: any) => {
30
36
  if (ethers.isError(e, 'INVALID_ARGUMENT')) {
@@ -45,10 +51,10 @@ export const throwError = (e: any) => {
45
51
  };
46
52
 
47
53
  /**
48
- * **URL validation.*
54
+ * Validates if a string is a valid URL.
49
55
  *
50
- * @param {string} url
51
- * @returns
56
+ * @param url - The URL string to validate
57
+ * @returns True if the URL is valid, false otherwise
52
58
  */
53
59
  export const isValidUrl = (url: string): boolean => {
54
60
  return isURL(url, {
@@ -59,10 +65,10 @@ export const isValidUrl = (url: string): boolean => {
59
65
  };
60
66
 
61
67
  /**
62
- * **Check if a string is a valid JSON.*
68
+ * Checks if a string is valid JSON.
63
69
  *
64
- * @param {string} input
65
- * @returns {boolean}
70
+ * @param input - The string to check
71
+ * @returns True if the string is valid JSON, false otherwise
66
72
  */
67
73
  export const isValidJson = (input: string): boolean => {
68
74
  try {
@@ -74,10 +80,10 @@ export const isValidJson = (input: string): boolean => {
74
80
  };
75
81
 
76
82
  /**
77
- * **Get the subgraph URL.*
83
+ * Gets the subgraph URL for the given network, using API key if available.
78
84
  *
79
- * @param {NetworkData} networkData
80
- * @returns
85
+ * @param networkData - The network data containing subgraph URLs
86
+ * @returns The subgraph URL with API key if available
81
87
  */
82
88
  export const getSubgraphUrl = (networkData: NetworkData) => {
83
89
  let subgraphUrl = networkData.subgraphUrl;
@@ -95,10 +101,10 @@ export const getSubgraphUrl = (networkData: NetworkData) => {
95
101
  };
96
102
 
97
103
  /**
98
- * **Convert a date to Unix timestamp (seconds since epoch).*
104
+ * Converts a Date object to Unix timestamp (seconds since epoch).
99
105
  *
100
- * @param {Date} date
101
- * @returns {number}
106
+ * @param date - The date to convert
107
+ * @returns Unix timestamp in seconds
102
108
  */
103
109
  export const getUnixTimestamp = (date: Date): number => {
104
110
  return Math.floor(date.getTime() / 1000);
@@ -127,8 +133,16 @@ const buildIndexerUrl = (baseUrl: string, indexerId?: string): string => {
127
133
  };
128
134
 
129
135
  /**
130
- * Execute a GraphQL request with automatic retry logic for bad indexer errors.
131
- * Only retries if options is provided.
136
+ * Executes a GraphQL request with automatic retry logic for bad indexer errors.
137
+ * Only retries if options is provided with maxRetries and baseDelay.
138
+ *
139
+ * @param url - The GraphQL endpoint URL
140
+ * @param query - The GraphQL query to execute
141
+ * @param variables - Variables for the GraphQL query (optional)
142
+ * @param options - Optional configuration for subgraph requests including retry logic
143
+ * @returns The response data from the GraphQL query
144
+ * @throws ErrorRetryParametersMissing If only one of maxRetries or baseDelay is provided
145
+ * @throws ErrorRoutingRequestsToIndexerRequiresApiKey If indexerId is provided without API key
132
146
  */
133
147
  export const customGqlFetch = async <T = any>(
134
148
  url: string,