@human-protocol/sdk 5.2.0 → 6.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 (69) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/base.d.ts +8 -7
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +18 -5
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +7 -8
  8. package/dist/encryption.d.ts +68 -203
  9. package/dist/encryption.d.ts.map +1 -1
  10. package/dist/encryption.js +66 -202
  11. package/dist/error.d.ts +0 -24
  12. package/dist/error.d.ts.map +1 -1
  13. package/dist/error.js +2 -26
  14. package/dist/escrow.d.ts +438 -791
  15. package/dist/escrow.d.ts.map +1 -1
  16. package/dist/escrow.js +331 -705
  17. package/dist/graphql/queries/operator.d.ts.map +1 -1
  18. package/dist/graphql/queries/operator.js +3 -1
  19. package/dist/graphql/types.d.ts.map +1 -1
  20. package/dist/index.d.ts +3 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -4
  23. package/dist/interfaces.d.ts +2 -2
  24. package/dist/interfaces.d.ts.map +1 -1
  25. package/dist/kvstore.d.ts +124 -186
  26. package/dist/kvstore.d.ts.map +1 -1
  27. package/dist/kvstore.js +122 -185
  28. package/dist/operator.d.ts +59 -30
  29. package/dist/operator.d.ts.map +1 -1
  30. package/dist/operator.js +59 -30
  31. package/dist/staking.d.ts +142 -141
  32. package/dist/staking.d.ts.map +1 -1
  33. package/dist/staking.js +140 -139
  34. package/dist/statistics.d.ts +104 -134
  35. package/dist/statistics.d.ts.map +1 -1
  36. package/dist/statistics.js +119 -144
  37. package/dist/transaction.d.ts +38 -17
  38. package/dist/transaction.d.ts.map +1 -1
  39. package/dist/transaction.js +40 -19
  40. package/dist/types.d.ts +14 -55
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils.d.ts +32 -18
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js +32 -19
  45. package/dist/worker.d.ts +35 -14
  46. package/dist/worker.d.ts.map +1 -1
  47. package/dist/worker.js +35 -14
  48. package/package.json +8 -25
  49. package/src/base.ts +42 -7
  50. package/src/constants.ts +6 -8
  51. package/src/encryption.ts +69 -203
  52. package/src/error.ts +0 -36
  53. package/src/escrow.ts +548 -891
  54. package/src/graphql/queries/operator.ts +3 -1
  55. package/src/graphql/types.ts +4 -2
  56. package/src/index.ts +4 -5
  57. package/src/interfaces.ts +2 -2
  58. package/src/kvstore.ts +142 -197
  59. package/src/operator.ts +59 -30
  60. package/src/staking.ts +177 -160
  61. package/src/statistics.ts +125 -146
  62. package/src/transaction.ts +40 -19
  63. package/src/types.ts +16 -58
  64. package/src/utils.ts +33 -23
  65. package/src/worker.ts +35 -14
  66. package/dist/storage.d.ts +0 -186
  67. package/dist/storage.d.ts.map +0 -1
  68. package/dist/storage.js +0 -319
  69. 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(
@@ -110,13 +129,13 @@ export class TransactionUtils {
110
129
  * token?: string; // (Optional) The token address to filter transactions.
111
130
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
112
131
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
113
- * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
114
- * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
132
+ * startBlock?: bigint | number; // (Optional) The start block to filter transactions (inclusive).
133
+ * endBlock?: bigint | number; // (Optional) The end block to filter transactions (inclusive).
115
134
  * first?: number; // (Optional) Number of transactions per page. Default is 10.
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(
@@ -199,8 +220,8 @@ export class TransactionUtils {
199
220
  ? getUnixTimestamp(filter?.startDate)
200
221
  : undefined,
201
222
  endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
202
- startBlock: filter.startBlock ? filter.startBlock : undefined,
203
- endBlock: filter.endBlock ? filter.endBlock : undefined,
223
+ startBlock: filter.startBlock ? Number(filter.startBlock) : undefined,
224
+ endBlock: filter.endBlock ? Number(filter.endBlock) : undefined,
204
225
  method: filter.method ? filter.method : undefined,
205
226
  escrow: filter.escrow ? filter.escrow : undefined,
206
227
  token: filter.token ? filter.token : undefined,
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TransactionLike } from 'ethers';
1
+ import { Overrides, TransactionLike } from 'ethers';
2
2
 
3
3
  /**
4
4
  * Enum for escrow statuses.
@@ -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
  */
@@ -143,4 +86,19 @@ export type NetworkData = {
143
86
  oldFactoryAddress: string;
144
87
  };
145
88
 
89
+ /**
90
+ * Options that configure how long to wait for transaction confirmations.
91
+ */
92
+ export type WaitOptions = {
93
+ /** Number of block confirmations to wait for. */
94
+ confirmations?: number;
95
+ /** Milliseconds to wait before aborting `tx.wait()`. */
96
+ timeoutMs?: number;
97
+ };
98
+
99
+ /**
100
+ * Extends ethers overrides with `wait()` options that control confirmation count and timeout.
101
+ */
102
+ export type TransactionOverrides = Overrides & WaitOptions;
103
+
146
104
  export type TransactionLikeWithNonce = TransactionLike & { nonce: number };