@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/statistics.ts CHANGED
@@ -15,10 +15,13 @@ import {
15
15
  PaymentStatistics,
16
16
  WorkerStatistics,
17
17
  HMTHolderData,
18
+ HMTHolder,
19
+ DailyHMTData,
18
20
  } from './graphql';
19
- import { IStatisticsParams } from './interfaces';
21
+ import { IHMTHoldersParams, IStatisticsFilter } from './interfaces';
20
22
  import { NetworkData } from './types';
21
23
  import { getSubgraphUrl, throwError } from './utils';
24
+ import { OrderDirection } from './enums';
22
25
 
23
26
  /**
24
27
  * ## Introduction
@@ -78,10 +81,12 @@ export class StatisticsClient {
78
81
  * **Input parameters**
79
82
  *
80
83
  * ```ts
81
- * interface IStatisticsParams {
84
+ * interface IStatisticsFilter {
82
85
  * from?: Date;
83
86
  * to?: Date;
84
- * limit?: number;
87
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
88
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
89
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
85
90
  * }
86
91
  * ```
87
92
  *
@@ -102,7 +107,7 @@ export class StatisticsClient {
102
107
  * ```
103
108
  *
104
109
  *
105
- * @param {IStatisticsParams} params Statistics params with duration data
110
+ * @param {IStatisticsFilter} filter Statistics params with duration data
106
111
  * @returns {EscrowStatistics} Escrow statistics data.
107
112
  *
108
113
  *
@@ -121,18 +126,26 @@ export class StatisticsClient {
121
126
  * ```
122
127
  */
123
128
  async getEscrowStatistics(
124
- params: IStatisticsParams = {}
129
+ filter: IStatisticsFilter = {}
125
130
  ): Promise<EscrowStatistics> {
126
131
  try {
132
+ const first =
133
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
134
+ const skip = filter.skip || 0;
135
+ const orderDirection = filter.orderDirection || OrderDirection.ASC;
136
+
127
137
  const { escrowStatistics } = await gqlFetch<{
128
138
  escrowStatistics: EscrowStatisticsData;
129
139
  }>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY);
130
140
 
131
141
  const { eventDayDatas } = await gqlFetch<{
132
142
  eventDayDatas: EventDayData[];
133
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
134
- from: params.from ? params.from.getTime() / 1000 : undefined,
135
- to: params.to ? params.to.getTime() / 1000 : undefined,
143
+ }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
144
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
145
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
146
+ orderDirection: orderDirection,
147
+ first: first,
148
+ skip: skip,
136
149
  });
137
150
 
138
151
  return {
@@ -158,10 +171,12 @@ export class StatisticsClient {
158
171
  * **Input parameters**
159
172
  *
160
173
  * ```ts
161
- * interface IStatisticsParams {
174
+ * interface IStatisticsFilter {
162
175
  * from?: Date;
163
176
  * to?: Date;
164
- * limit?: number;
177
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
178
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
179
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
165
180
  * }
166
181
  * ```
167
182
  *
@@ -177,7 +192,7 @@ export class StatisticsClient {
177
192
  * ```
178
193
  *
179
194
  *
180
- * @param {IStatisticsParams} params Statistics params with duration data
195
+ * @param {IStatisticsFilter} filter Statistics params with duration data
181
196
  * @returns {WorkerStatistics} Worker statistics data.
182
197
  *
183
198
  *
@@ -196,14 +211,22 @@ export class StatisticsClient {
196
211
  * ```
197
212
  */
198
213
  async getWorkerStatistics(
199
- params: IStatisticsParams = {}
214
+ filter: IStatisticsFilter = {}
200
215
  ): Promise<WorkerStatistics> {
201
216
  try {
217
+ const first =
218
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
219
+ const skip = filter.skip || 0;
220
+ const orderDirection = filter.orderDirection || OrderDirection.ASC;
221
+
202
222
  const { eventDayDatas } = await gqlFetch<{
203
223
  eventDayDatas: EventDayData[];
204
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
205
- from: params.from ? params.from.getTime() / 1000 : undefined,
206
- to: params.to ? params.to.getTime() / 1000 : undefined,
224
+ }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
225
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
226
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
227
+ orderDirection: orderDirection,
228
+ first: first,
229
+ skip: skip,
207
230
  });
208
231
 
209
232
  return {
@@ -224,10 +247,12 @@ export class StatisticsClient {
224
247
  * **Input parameters**
225
248
  *
226
249
  * ```ts
227
- * interface IStatisticsParams {
250
+ * interface IStatisticsFilter {
228
251
  * from?: Date;
229
252
  * to?: Date;
230
- * limit?: number;
253
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
254
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
255
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
231
256
  * }
232
257
  * ```
233
258
  *
@@ -245,7 +270,7 @@ export class StatisticsClient {
245
270
  * ```
246
271
  *
247
272
  *
248
- * @param {IStatisticsParams} params Statistics params with duration data
273
+ * @param {IStatisticsFilter} filter Statistics params with duration data
249
274
  * @returns {PaymentStatistics} Payment statistics data.
250
275
  *
251
276
  *
@@ -285,14 +310,22 @@ export class StatisticsClient {
285
310
  * ```
286
311
  */
287
312
  async getPaymentStatistics(
288
- params: IStatisticsParams = {}
313
+ filter: IStatisticsFilter = {}
289
314
  ): Promise<PaymentStatistics> {
290
315
  try {
316
+ const first =
317
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
318
+ const skip = filter.skip || 0;
319
+ const orderDirection = filter.orderDirection || OrderDirection.ASC;
320
+
291
321
  const { eventDayDatas } = await gqlFetch<{
292
322
  eventDayDatas: EventDayData[];
293
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
294
- from: params.from ? params.from.getTime() / 1000 : undefined,
295
- to: params.to ? params.to.getTime() / 1000 : undefined,
323
+ }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
324
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
325
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
326
+ orderDirection: orderDirection,
327
+ first: first,
328
+ skip: skip,
296
329
  });
297
330
 
298
331
  return {
@@ -316,40 +349,128 @@ export class StatisticsClient {
316
349
  * This function returns the statistical data of HMToken.
317
350
  *
318
351
  *
352
+ * type HMTStatistics = {
353
+ * totalTransferAmount: BigNumber;
354
+ * totalTransferCount: BigNumber;
355
+ * totalHolders: number;
356
+ * };
357
+ * ```
358
+ *
359
+ *
360
+ * @returns {HMTStatistics} HMToken statistics data.
361
+ *
362
+ *
363
+ * **Code example**
364
+ *
365
+ * ```ts
366
+ * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
367
+ *
368
+ * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
369
+ *
370
+ * const hmtStatistics = await statisticsClient.getHMTStatistics();
371
+ *
372
+ * console.log('HMT statistics:', {
373
+ * ...hmtStatistics,
374
+ * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
375
+ * });
376
+ * ```
377
+ */
378
+ async getHMTStatistics(): Promise<HMTStatistics> {
379
+ try {
380
+ const { hmtokenStatistics } = await gqlFetch<{
381
+ hmtokenStatistics: HMTStatisticsData;
382
+ }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
383
+
384
+ return {
385
+ totalTransferAmount: ethers.toBigInt(
386
+ hmtokenStatistics.totalValueTransfered
387
+ ),
388
+ totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
389
+ totalHolders: +hmtokenStatistics.holders,
390
+ };
391
+ } catch (e: any) {
392
+ return throwError(e);
393
+ }
394
+ }
395
+
396
+ /**
397
+ * This function returns the holders of the HMToken with optional filters and ordering.
398
+ *
319
399
  * **Input parameters**
320
400
  *
401
+ * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
402
+ * @returns {HMTHolder[]} List of HMToken holders.
403
+ *
404
+ * **Code example**
405
+ *
321
406
  * ```ts
322
- * interface IStatisticsParams {
407
+ * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
408
+ *
409
+ * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
410
+ *
411
+ * const hmtHolders = await statisticsClient.getHMTHolders({
412
+ * orderDirection: 'asc',
413
+ * });
414
+ *
415
+ * console.log('HMT holders:', hmtHolders.map((h) => ({
416
+ * ...h,
417
+ * balance: h.balance.toString(),
418
+ * })));
419
+ * ```
420
+ */
421
+ async getHMTHolders(params: IHMTHoldersParams = {}): Promise<HMTHolder[]> {
422
+ try {
423
+ const { address, orderDirection } = params;
424
+ const query = GET_HOLDERS_QUERY(address);
425
+
426
+ const { holders } = await gqlFetch<{ holders: HMTHolderData[] }>(
427
+ this.subgraphUrl,
428
+ query,
429
+ {
430
+ address,
431
+ orderBy: 'balance',
432
+ orderDirection,
433
+ }
434
+ );
435
+
436
+ return holders.map((holder) => ({
437
+ address: holder.address,
438
+ balance: ethers.toBigInt(holder.balance),
439
+ }));
440
+ } catch (e: any) {
441
+ return throwError(e);
442
+ }
443
+ }
444
+
445
+ /**
446
+ * This function returns the statistical data of HMToken day by day.
447
+ *
448
+ *
449
+ * **Input parameters**
450
+ *
451
+ * ```ts
452
+ * interface IStatisticsFilter {
323
453
  * from?: Date;
324
454
  * to?: Date;
325
- * limit?: number;
455
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
456
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
457
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
326
458
  * }
327
459
  * ```
328
460
  *
329
461
  * ```ts
330
- * type HMTHolder = {
331
- * address: string;
332
- * balance: BigNumber;
333
- * }
334
- *
335
462
  * type DailyHMTData = {
336
463
  * timestamp: Date;
337
- * totalTransactionAmount: BigNumber;
464
+ * totalTransactionAmount: bigint;
338
465
  * totalTransactionCount: number;
339
- * };
340
- *
341
- * type HMTStatistics = {
342
- * totalTransferAmount: BigNumber;
343
- * totalTransferCount: BigNumber;
344
- * totalHolders: number;
345
- * holders: HMTHolder[];
346
- * dailyHMTData: DailyHMTData[];
347
- * };
466
+ * dailyUniqueSenders: number;
467
+ * dailyUniqueReceivers: number;
468
+ * }
348
469
  * ```
349
470
  *
350
471
  *
351
- * @param {IStatisticsParams} params Statistics params with duration data
352
- * @returns {HMTStatistics} HMToken statistics data.
472
+ * @param {IStatisticsFilter} filter Statistics params with duration data
473
+ * @returns {DailyHMTData[]} Daily HMToken statistics data.
353
474
  *
354
475
  *
355
476
  * **Code example**
@@ -359,77 +480,46 @@ export class StatisticsClient {
359
480
  *
360
481
  * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
361
482
  *
362
- * const hmtStatistics = await statisticsClient.getHMTStatistics();
483
+ * const dailyHMTStats = await statisticsClient.getHMTStatistics();
363
484
  *
364
- * console.log('HMT statistics:', {
365
- * ...hmtStatistics,
366
- * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
367
- * holders: hmtStatistics.holders.map((h) => ({
368
- * ...h,
369
- * balance: h.balance.toString(),
370
- * })),
371
- * dailyHMTData: hmtStatistics.dailyHMTData.map((d) => ({
372
- * ...d,
373
- * totalTransactionAmount: d.totalTransactionAmount.toString(),
374
- * })),
375
- * });
485
+ * console.log('Daily HMT statistics:', dailyHMTStats);
376
486
  *
377
487
  * const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
378
488
  * from: new Date(2023, 4, 8),
379
489
  * to: new Date(2023, 5, 8),
380
490
  * });
381
491
  *
382
- * console.log('HMT statistics from 5/8 - 6/8:', {
383
- * ...hmtStatisticsRange,
384
- * totalTransferAmount: hmtStatisticsRange.totalTransferAmount.toString(),
385
- * holders: hmtStatisticsRange.holders.map((h) => ({
386
- * ...h,
387
- * balance: h.balance.toString(),
388
- * })),
389
- * dailyHMTData: hmtStatisticsRange.dailyHMTData.map((d) => ({
390
- * ...d,
391
- * totalTransactionAmount: d.totalTransactionAmount.toString(),
392
- * })),
393
- * });
492
+ * console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
394
493
  * ```
395
494
  */
396
- async getHMTStatistics(
397
- params: IStatisticsParams = {}
398
- ): Promise<HMTStatistics> {
495
+ async getHMTDailyData(
496
+ filter: IStatisticsFilter = {}
497
+ ): Promise<DailyHMTData[]> {
399
498
  try {
400
- const { hmtokenStatistics } = await gqlFetch<{
401
- hmtokenStatistics: HMTStatisticsData;
402
- }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
403
-
404
- const { holders } = await gqlFetch<{
405
- holders: HMTHolderData[];
406
- }>(this.subgraphUrl, GET_HOLDERS_QUERY);
499
+ const first =
500
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
501
+ const skip = filter.skip || 0;
502
+ const orderDirection = filter.orderDirection || OrderDirection.ASC;
407
503
 
408
504
  const { eventDayDatas } = await gqlFetch<{
409
505
  eventDayDatas: EventDayData[];
410
- }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
411
- from: params.from ? params.from.getTime() / 1000 : undefined,
412
- to: params.to ? params.to.getTime() / 1000 : undefined,
506
+ }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
507
+ from: filter.from ? filter.from.getTime() / 1000 : undefined,
508
+ to: filter.to ? filter.to.getTime() / 1000 : undefined,
509
+ orderDirection: orderDirection,
510
+ first: first,
511
+ skip: skip,
413
512
  });
414
513
 
415
- return {
416
- totalTransferAmount: ethers.toBigInt(
417
- hmtokenStatistics.totalValueTransfered
514
+ return eventDayDatas.map((eventDayData) => ({
515
+ timestamp: new Date(+eventDayData.timestamp * 1000),
516
+ totalTransactionAmount: ethers.toBigInt(
517
+ eventDayData.dailyHMTTransferAmount
418
518
  ),
419
- totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
420
- totalHolders: +hmtokenStatistics.holders,
421
- holders: holders.map((holder) => ({
422
- address: holder.address,
423
- balance: ethers.toBigInt(holder.balance),
424
- })),
425
- dailyHMTData: eventDayDatas.map((eventDayData) => ({
426
- timestamp: new Date(+eventDayData.timestamp * 1000),
427
- totalTransactionAmount: ethers.toBigInt(
428
- eventDayData.dailyHMTTransferAmount
429
- ),
430
- totalTransactionCount: +eventDayData.dailyHMTTransferCount,
431
- })),
432
- };
519
+ totalTransactionCount: +eventDayData.dailyHMTTransferCount,
520
+ dailyUniqueSenders: +eventDayData.dailyUniqueSenders,
521
+ dailyUniqueReceivers: +eventDayData.dailyUniqueReceivers,
522
+ }));
433
523
  } catch (e: any) {
434
524
  return throwError(e);
435
525
  }
@@ -2,7 +2,7 @@
2
2
  import { ethers } from 'ethers';
3
3
  import gqlFetch from 'graphql-request';
4
4
  import { NETWORKS } from './constants';
5
- import { ChainId } from './enums';
5
+ import { ChainId, OrderDirection } from './enums';
6
6
  import {
7
7
  ErrorCannotUseDateAndBlockSimultaneously,
8
8
  ErrorInvalidHahsProvided,
@@ -62,13 +62,16 @@ export class TransactionUtils {
62
62
  *
63
63
  * ```ts
64
64
  * interface ITransactionsFilter {
65
- * networks: ChainId[]; // List of chain IDs to query.
65
+ * chainId: ChainId; // List of chain IDs to query.
66
66
  * fromAddress?: string; // (Optional) The address from which transactions are sent.
67
67
  * toAddress?: string; // (Optional) The address to which transactions are sent.
68
68
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
69
69
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
70
70
  * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
71
71
  * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
72
+ * first?: number; // (Optional) Number of transactions per page. Default is 10.
73
+ * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
74
+ * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
72
75
  * }
73
76
  * ```
74
77
  *
@@ -90,12 +93,15 @@ export class TransactionUtils {
90
93
  * **Code example**
91
94
  *
92
95
  * ```ts
93
- * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
96
+ * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
94
97
  *
95
98
  * const filter: ITransactionsFilter = {
96
- * networks: [ChainId.POLYGON],
99
+ * chainId: ChainId.POLYGON,
97
100
  * startDate: new Date('2022-01-01'),
98
- * endDate: new Date('2022-12-31')
101
+ * endDate: new Date('2022-12-31'),
102
+ * first: 10,
103
+ * skip: 0,
104
+ * orderDirection: OrderDirection.DESC,
99
105
  * };
100
106
  * const transactions = await TransactionUtils.getTransactions(filter);
101
107
  * ```
@@ -110,33 +116,37 @@ export class TransactionUtils {
110
116
  throw ErrorCannotUseDateAndBlockSimultaneously;
111
117
  }
112
118
 
113
- const transactions_data: ITransaction[] = [];
114
- for (const chainId of filter.networks) {
115
- const networkData = NETWORKS[chainId];
116
- if (!networkData) {
117
- throw ErrorUnsupportedChainID;
118
- }
119
- const { transactions } = await gqlFetch<{
120
- transactions: ITransaction[];
121
- }>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), {
122
- fromAddress: filter?.fromAddress,
123
- toAddress: filter?.toAddress,
124
- startDate: filter?.startDate
125
- ? Math.floor(filter?.startDate.getTime() / 1000)
126
- : undefined,
127
- endDate: filter.endDate
128
- ? Math.floor(filter.endDate.getTime() / 1000)
129
- : undefined,
130
- startBlock: filter.startBlock ? filter.startBlock : undefined,
131
- endBlock: filter.endBlock ? filter.endBlock : undefined,
132
- });
119
+ const first =
120
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
121
+ const skip = filter.skip || 0;
122
+ const orderDirection = filter.orderDirection || OrderDirection.DESC;
133
123
 
134
- if (!transactions) {
135
- continue;
136
- }
124
+ const networkData = NETWORKS[filter.chainId];
125
+ if (!networkData) {
126
+ throw ErrorUnsupportedChainID;
127
+ }
128
+ const { transactions } = await gqlFetch<{
129
+ transactions: ITransaction[];
130
+ }>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), {
131
+ fromAddress: filter?.fromAddress,
132
+ toAddress: filter?.toAddress,
133
+ startDate: filter?.startDate
134
+ ? Math.floor(filter?.startDate.getTime() / 1000)
135
+ : undefined,
136
+ endDate: filter.endDate
137
+ ? Math.floor(filter.endDate.getTime() / 1000)
138
+ : undefined,
139
+ startBlock: filter.startBlock ? filter.startBlock : undefined,
140
+ endBlock: filter.endBlock ? filter.endBlock : undefined,
141
+ orderDirection: orderDirection,
142
+ first: first,
143
+ skip: skip,
144
+ });
137
145
 
138
- transactions_data.push(...transactions);
146
+ if (!transactions) {
147
+ return [];
139
148
  }
140
- return transactions_data;
149
+
150
+ return transactions;
141
151
  }
142
152
  }