@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
@@ -9,6 +9,7 @@ const ethers_1 = require("ethers");
9
9
  const graphql_request_1 = __importDefault(require("graphql-request"));
10
10
  const graphql_1 = require("./graphql");
11
11
  const utils_1 = require("./utils");
12
+ const enums_1 = require("./enums");
12
13
  /**
13
14
  * ## Introduction
14
15
  *
@@ -63,10 +64,12 @@ class StatisticsClient {
63
64
  * **Input parameters**
64
65
  *
65
66
  * ```ts
66
- * interface IStatisticsParams {
67
+ * interface IStatisticsFilter {
67
68
  * from?: Date;
68
69
  * to?: Date;
69
- * limit?: number;
70
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
71
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
72
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
70
73
  * }
71
74
  * ```
72
75
  *
@@ -87,7 +90,7 @@ class StatisticsClient {
87
90
  * ```
88
91
  *
89
92
  *
90
- * @param {IStatisticsParams} params Statistics params with duration data
93
+ * @param {IStatisticsFilter} filter Statistics params with duration data
91
94
  * @returns {EscrowStatistics} Escrow statistics data.
92
95
  *
93
96
  *
@@ -105,12 +108,18 @@ class StatisticsClient {
105
108
  * });
106
109
  * ```
107
110
  */
108
- async getEscrowStatistics(params = {}) {
111
+ async getEscrowStatistics(filter = {}) {
109
112
  try {
113
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
114
+ const skip = filter.skip || 0;
115
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
110
116
  const { escrowStatistics } = await (0, graphql_request_1.default)(this.subgraphUrl, graphql_1.GET_ESCROW_STATISTICS_QUERY);
111
- const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
112
- from: params.from ? params.from.getTime() / 1000 : undefined,
113
- to: params.to ? params.to.getTime() / 1000 : undefined,
117
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
118
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
119
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
120
+ orderDirection: orderDirection,
121
+ first: first,
122
+ skip: skip,
114
123
  });
115
124
  return {
116
125
  totalEscrows: +escrowStatistics.totalEscrowCount,
@@ -135,10 +144,12 @@ class StatisticsClient {
135
144
  * **Input parameters**
136
145
  *
137
146
  * ```ts
138
- * interface IStatisticsParams {
147
+ * interface IStatisticsFilter {
139
148
  * from?: Date;
140
149
  * to?: Date;
141
- * limit?: number;
150
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
151
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
152
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
142
153
  * }
143
154
  * ```
144
155
  *
@@ -154,7 +165,7 @@ class StatisticsClient {
154
165
  * ```
155
166
  *
156
167
  *
157
- * @param {IStatisticsParams} params Statistics params with duration data
168
+ * @param {IStatisticsFilter} filter Statistics params with duration data
158
169
  * @returns {WorkerStatistics} Worker statistics data.
159
170
  *
160
171
  *
@@ -172,11 +183,17 @@ class StatisticsClient {
172
183
  * });
173
184
  * ```
174
185
  */
175
- async getWorkerStatistics(params = {}) {
186
+ async getWorkerStatistics(filter = {}) {
176
187
  try {
177
- const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
178
- from: params.from ? params.from.getTime() / 1000 : undefined,
179
- to: params.to ? params.to.getTime() / 1000 : undefined,
188
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
189
+ const skip = filter.skip || 0;
190
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
191
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
192
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
193
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
194
+ orderDirection: orderDirection,
195
+ first: first,
196
+ skip: skip,
180
197
  });
181
198
  return {
182
199
  dailyWorkersData: eventDayDatas.map((eventDayData) => ({
@@ -196,10 +213,12 @@ class StatisticsClient {
196
213
  * **Input parameters**
197
214
  *
198
215
  * ```ts
199
- * interface IStatisticsParams {
216
+ * interface IStatisticsFilter {
200
217
  * from?: Date;
201
218
  * to?: Date;
202
- * limit?: number;
219
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
220
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
221
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
203
222
  * }
204
223
  * ```
205
224
  *
@@ -217,7 +236,7 @@ class StatisticsClient {
217
236
  * ```
218
237
  *
219
238
  *
220
- * @param {IStatisticsParams} params Statistics params with duration data
239
+ * @param {IStatisticsFilter} filter Statistics params with duration data
221
240
  * @returns {PaymentStatistics} Payment statistics data.
222
241
  *
223
242
  *
@@ -256,11 +275,17 @@ class StatisticsClient {
256
275
  * );
257
276
  * ```
258
277
  */
259
- async getPaymentStatistics(params = {}) {
278
+ async getPaymentStatistics(filter = {}) {
260
279
  try {
261
- const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
262
- from: params.from ? params.from.getTime() / 1000 : undefined,
263
- to: params.to ? params.to.getTime() / 1000 : undefined,
280
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
281
+ const skip = filter.skip || 0;
282
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
283
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
284
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
285
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
286
+ orderDirection: orderDirection,
287
+ first: first,
288
+ skip: skip,
264
289
  });
265
290
  return {
266
291
  dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
@@ -282,40 +307,117 @@ class StatisticsClient {
282
307
  * This function returns the statistical data of HMToken.
283
308
  *
284
309
  *
310
+ * type HMTStatistics = {
311
+ * totalTransferAmount: BigNumber;
312
+ * totalTransferCount: BigNumber;
313
+ * totalHolders: number;
314
+ * };
315
+ * ```
316
+ *
317
+ *
318
+ * @returns {HMTStatistics} HMToken statistics data.
319
+ *
320
+ *
321
+ * **Code example**
322
+ *
323
+ * ```ts
324
+ * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
325
+ *
326
+ * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
327
+ *
328
+ * const hmtStatistics = await statisticsClient.getHMTStatistics();
329
+ *
330
+ * console.log('HMT statistics:', {
331
+ * ...hmtStatistics,
332
+ * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
333
+ * });
334
+ * ```
335
+ */
336
+ async getHMTStatistics() {
337
+ try {
338
+ const { hmtokenStatistics } = await (0, graphql_request_1.default)(this.subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY);
339
+ return {
340
+ totalTransferAmount: ethers_1.ethers.toBigInt(hmtokenStatistics.totalValueTransfered),
341
+ totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
342
+ totalHolders: +hmtokenStatistics.holders,
343
+ };
344
+ }
345
+ catch (e) {
346
+ return (0, utils_1.throwError)(e);
347
+ }
348
+ }
349
+ /**
350
+ * This function returns the holders of the HMToken with optional filters and ordering.
351
+ *
352
+ * **Input parameters**
353
+ *
354
+ * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
355
+ * @returns {HMTHolder[]} List of HMToken holders.
356
+ *
357
+ * **Code example**
358
+ *
359
+ * ```ts
360
+ * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
361
+ *
362
+ * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
363
+ *
364
+ * const hmtHolders = await statisticsClient.getHMTHolders({
365
+ * orderDirection: 'asc',
366
+ * });
367
+ *
368
+ * console.log('HMT holders:', hmtHolders.map((h) => ({
369
+ * ...h,
370
+ * balance: h.balance.toString(),
371
+ * })));
372
+ * ```
373
+ */
374
+ async getHMTHolders(params = {}) {
375
+ try {
376
+ const { address, orderDirection } = params;
377
+ const query = (0, graphql_1.GET_HOLDERS_QUERY)(address);
378
+ const { holders } = await (0, graphql_request_1.default)(this.subgraphUrl, query, {
379
+ address,
380
+ orderBy: 'balance',
381
+ orderDirection,
382
+ });
383
+ return holders.map((holder) => ({
384
+ address: holder.address,
385
+ balance: ethers_1.ethers.toBigInt(holder.balance),
386
+ }));
387
+ }
388
+ catch (e) {
389
+ return (0, utils_1.throwError)(e);
390
+ }
391
+ }
392
+ /**
393
+ * This function returns the statistical data of HMToken day by day.
394
+ *
395
+ *
285
396
  * **Input parameters**
286
397
  *
287
398
  * ```ts
288
- * interface IStatisticsParams {
399
+ * interface IStatisticsFilter {
289
400
  * from?: Date;
290
401
  * to?: Date;
291
- * limit?: number;
402
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
403
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
404
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
292
405
  * }
293
406
  * ```
294
407
  *
295
408
  * ```ts
296
- * type HMTHolder = {
297
- * address: string;
298
- * balance: BigNumber;
299
- * }
300
- *
301
409
  * type DailyHMTData = {
302
410
  * timestamp: Date;
303
- * totalTransactionAmount: BigNumber;
411
+ * totalTransactionAmount: bigint;
304
412
  * totalTransactionCount: number;
305
- * };
306
- *
307
- * type HMTStatistics = {
308
- * totalTransferAmount: BigNumber;
309
- * totalTransferCount: BigNumber;
310
- * totalHolders: number;
311
- * holders: HMTHolder[];
312
- * dailyHMTData: DailyHMTData[];
313
- * };
413
+ * dailyUniqueSenders: number;
414
+ * dailyUniqueReceivers: number;
415
+ * }
314
416
  * ```
315
417
  *
316
418
  *
317
- * @param {IStatisticsParams} params Statistics params with duration data
318
- * @returns {HMTStatistics} HMToken statistics data.
419
+ * @param {IStatisticsFilter} filter Statistics params with duration data
420
+ * @returns {DailyHMTData[]} Daily HMToken statistics data.
319
421
  *
320
422
  *
321
423
  * **Code example**
@@ -325,62 +427,37 @@ class StatisticsClient {
325
427
  *
326
428
  * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
327
429
  *
328
- * const hmtStatistics = await statisticsClient.getHMTStatistics();
430
+ * const dailyHMTStats = await statisticsClient.getHMTStatistics();
329
431
  *
330
- * console.log('HMT statistics:', {
331
- * ...hmtStatistics,
332
- * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
333
- * holders: hmtStatistics.holders.map((h) => ({
334
- * ...h,
335
- * balance: h.balance.toString(),
336
- * })),
337
- * dailyHMTData: hmtStatistics.dailyHMTData.map((d) => ({
338
- * ...d,
339
- * totalTransactionAmount: d.totalTransactionAmount.toString(),
340
- * })),
341
- * });
432
+ * console.log('Daily HMT statistics:', dailyHMTStats);
342
433
  *
343
434
  * const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
344
435
  * from: new Date(2023, 4, 8),
345
436
  * to: new Date(2023, 5, 8),
346
437
  * });
347
438
  *
348
- * console.log('HMT statistics from 5/8 - 6/8:', {
349
- * ...hmtStatisticsRange,
350
- * totalTransferAmount: hmtStatisticsRange.totalTransferAmount.toString(),
351
- * holders: hmtStatisticsRange.holders.map((h) => ({
352
- * ...h,
353
- * balance: h.balance.toString(),
354
- * })),
355
- * dailyHMTData: hmtStatisticsRange.dailyHMTData.map((d) => ({
356
- * ...d,
357
- * totalTransactionAmount: d.totalTransactionAmount.toString(),
358
- * })),
359
- * });
439
+ * console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
360
440
  * ```
361
441
  */
362
- async getHMTStatistics(params = {}) {
442
+ async getHMTDailyData(filter = {}) {
363
443
  try {
364
- const { hmtokenStatistics } = await (0, graphql_request_1.default)(this.subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY);
365
- const { holders } = await (0, graphql_request_1.default)(this.subgraphUrl, graphql_1.GET_HOLDERS_QUERY);
366
- const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
367
- from: params.from ? params.from.getTime() / 1000 : undefined,
368
- to: params.to ? params.to.getTime() / 1000 : undefined,
444
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
445
+ const skip = filter.skip || 0;
446
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
447
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
448
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
449
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
450
+ orderDirection: orderDirection,
451
+ first: first,
452
+ skip: skip,
369
453
  });
370
- return {
371
- totalTransferAmount: ethers_1.ethers.toBigInt(hmtokenStatistics.totalValueTransfered),
372
- totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
373
- totalHolders: +hmtokenStatistics.holders,
374
- holders: holders.map((holder) => ({
375
- address: holder.address,
376
- balance: ethers_1.ethers.toBigInt(holder.balance),
377
- })),
378
- dailyHMTData: eventDayDatas.map((eventDayData) => ({
379
- timestamp: new Date(+eventDayData.timestamp * 1000),
380
- totalTransactionAmount: ethers_1.ethers.toBigInt(eventDayData.dailyHMTTransferAmount),
381
- totalTransactionCount: +eventDayData.dailyHMTTransferCount,
382
- })),
383
- };
454
+ return eventDayDatas.map((eventDayData) => ({
455
+ timestamp: new Date(+eventDayData.timestamp * 1000),
456
+ totalTransactionAmount: ethers_1.ethers.toBigInt(eventDayData.dailyHMTTransferAmount),
457
+ totalTransactionCount: +eventDayData.dailyHMTTransferCount,
458
+ dailyUniqueSenders: +eventDayData.dailyUniqueSenders,
459
+ dailyUniqueReceivers: +eventDayData.dailyUniqueReceivers,
460
+ }));
384
461
  }
385
462
  catch (e) {
386
463
  return (0, utils_1.throwError)(e);
@@ -26,13 +26,16 @@ export declare class TransactionUtils {
26
26
  *
27
27
  * ```ts
28
28
  * interface ITransactionsFilter {
29
- * networks: ChainId[]; // List of chain IDs to query.
29
+ * chainId: ChainId; // List of chain IDs to query.
30
30
  * fromAddress?: string; // (Optional) The address from which transactions are sent.
31
31
  * toAddress?: string; // (Optional) The address to which transactions are sent.
32
32
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
33
33
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
34
34
  * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
35
35
  * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
36
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
37
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
38
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
36
39
  * }
37
40
  * ```
38
41
  *
@@ -54,12 +57,15 @@ export declare class TransactionUtils {
54
57
  * **Code example**
55
58
  *
56
59
  * ```ts
57
- * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
60
+ * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
58
61
  *
59
62
  * const filter: ITransactionsFilter = {
60
- * networks: [ChainId.POLYGON],
63
+ * chainId: ChainId.POLYGON,
61
64
  * startDate: new Date('2022-01-01'),
62
- * endDate: new Date('2022-12-31')
65
+ * endDate: new Date('2022-12-31'),
66
+ * first: 10,
67
+ * skip: 0,
68
+ * orderDirection: OrderDirection.DESC,
63
69
  * };
64
70
  * const transactions = await TransactionUtils.getTransactions(filter);
65
71
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAUlC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjE,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC;IAmBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,EAAE,CAAC;CAqC3B"}
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAUlD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjE,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC;IAmBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,EAAE,CAAC;CAyC3B"}
@@ -8,6 +8,7 @@ exports.TransactionUtils = void 0;
8
8
  const ethers_1 = require("ethers");
9
9
  const graphql_request_1 = __importDefault(require("graphql-request"));
10
10
  const constants_1 = require("./constants");
11
+ const enums_1 = require("./enums");
11
12
  const error_1 = require("./error");
12
13
  const transaction_1 = require("./graphql/queries/transaction");
13
14
  const utils_1 = require("./utils");
@@ -49,13 +50,16 @@ class TransactionUtils {
49
50
  *
50
51
  * ```ts
51
52
  * interface ITransactionsFilter {
52
- * networks: ChainId[]; // List of chain IDs to query.
53
+ * chainId: ChainId; // List of chain IDs to query.
53
54
  * fromAddress?: string; // (Optional) The address from which transactions are sent.
54
55
  * toAddress?: string; // (Optional) The address to which transactions are sent.
55
56
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
56
57
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
57
58
  * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
58
59
  * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
60
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
61
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
62
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
59
63
  * }
60
64
  * ```
61
65
  *
@@ -77,12 +81,15 @@ class TransactionUtils {
77
81
  * **Code example**
78
82
  *
79
83
  * ```ts
80
- * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
84
+ * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
81
85
  *
82
86
  * const filter: ITransactionsFilter = {
83
- * networks: [ChainId.POLYGON],
87
+ * chainId: ChainId.POLYGON,
84
88
  * startDate: new Date('2022-01-01'),
85
- * endDate: new Date('2022-12-31')
89
+ * endDate: new Date('2022-12-31'),
90
+ * first: 10,
91
+ * skip: 0,
92
+ * orderDirection: OrderDirection.DESC,
86
93
  * };
87
94
  * const transactions = await TransactionUtils.getTransactions(filter);
88
95
  * ```
@@ -92,30 +99,32 @@ class TransactionUtils {
92
99
  (!!filter.startBlock || !!filter.endBlock)) {
93
100
  throw error_1.ErrorCannotUseDateAndBlockSimultaneously;
94
101
  }
95
- const transactions_data = [];
96
- for (const chainId of filter.networks) {
97
- const networkData = constants_1.NETWORKS[chainId];
98
- if (!networkData) {
99
- throw error_1.ErrorUnsupportedChainID;
100
- }
101
- const { transactions } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, transaction_1.GET_TRANSACTIONS_QUERY)(filter), {
102
- fromAddress: filter?.fromAddress,
103
- toAddress: filter?.toAddress,
104
- startDate: filter?.startDate
105
- ? Math.floor(filter?.startDate.getTime() / 1000)
106
- : undefined,
107
- endDate: filter.endDate
108
- ? Math.floor(filter.endDate.getTime() / 1000)
109
- : undefined,
110
- startBlock: filter.startBlock ? filter.startBlock : undefined,
111
- endBlock: filter.endBlock ? filter.endBlock : undefined,
112
- });
113
- if (!transactions) {
114
- continue;
115
- }
116
- transactions_data.push(...transactions);
102
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
103
+ const skip = filter.skip || 0;
104
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
105
+ const networkData = constants_1.NETWORKS[filter.chainId];
106
+ if (!networkData) {
107
+ throw error_1.ErrorUnsupportedChainID;
108
+ }
109
+ const { transactions } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, transaction_1.GET_TRANSACTIONS_QUERY)(filter), {
110
+ fromAddress: filter?.fromAddress,
111
+ toAddress: filter?.toAddress,
112
+ startDate: filter?.startDate
113
+ ? Math.floor(filter?.startDate.getTime() / 1000)
114
+ : undefined,
115
+ endDate: filter.endDate
116
+ ? Math.floor(filter.endDate.getTime() / 1000)
117
+ : undefined,
118
+ startBlock: filter.startBlock ? filter.startBlock : undefined,
119
+ endBlock: filter.endBlock ? filter.endBlock : undefined,
120
+ orderDirection: orderDirection,
121
+ first: first,
122
+ skip: skip,
123
+ });
124
+ if (!transactions) {
125
+ return [];
117
126
  }
118
- return transactions_data;
127
+ return transactions;
119
128
  }
120
129
  }
121
130
  exports.TransactionUtils = TransactionUtils;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -52,8 +52,8 @@
52
52
  "winston": "^3.13.0"
53
53
  },
54
54
  "devDependencies": {
55
- "typedoc": "^0.25.1",
56
- "typedoc-plugin-markdown": "^4.0.3"
55
+ "typedoc": "^0.26.5",
56
+ "typedoc-plugin-markdown": "^4.2.3"
57
57
  },
58
58
  "typedocOptions": {
59
59
  "entryPoints": [
@@ -64,7 +64,8 @@
64
64
  "./src/operator.ts",
65
65
  "./src/staking.ts",
66
66
  "./src/storage.ts",
67
- "./src/statistics.ts"
67
+ "./src/statistics.ts",
68
+ "./src/transaction.ts"
68
69
  ]
69
70
  }
70
71
  }
package/src/constants.ts CHANGED
@@ -349,6 +349,7 @@ export const KVStoreKeys = {
349
349
  webhookUrl: 'webhook_url',
350
350
  url: 'url',
351
351
  jobTypes: 'job_types',
352
+ registrationNeeded: 'registration_needed',
352
353
  };
353
354
 
354
355
  export const Role = {
package/src/enums.ts CHANGED
@@ -19,3 +19,8 @@ export enum ChainId {
19
19
  LOCALHOST = 1338,
20
20
  XLAYER = 196,
21
21
  }
22
+
23
+ export enum OrderDirection {
24
+ ASC = 'asc',
25
+ DESC = 'desc',
26
+ }
package/src/error.ts CHANGED
@@ -335,5 +335,13 @@ export class InvalidEthereumAddressError extends Error {
335
335
  */
336
336
  export const ErrorInvalidHash = new Error('Invalid hash');
337
337
 
338
+ /**
339
+ * @constant {Error} - The Status is not supported
340
+ */
341
+ export const ErrorUnsupportedStatus = new Error('Unsupported status for query');
342
+
343
+ /**
344
+ * @constant {Error} - The SUBGRAPH_API_KEY is not being provided
345
+ */
338
346
  export const WarnSubgraphApiKeyNotProvided =
339
347
  '"SUBGRAPH_API_KEY" is not being provided. It might cause issues with the subgraph.';