@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.
- package/dist/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +4 -5
- package/dist/constants.js +6 -6
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +66 -202
- package/dist/error.d.ts +0 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -26
- package/dist/escrow.d.ts +427 -780
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +314 -684
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/kvstore.d.ts +119 -181
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +119 -182
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +135 -134
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +135 -134
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +36 -15
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -15
- package/dist/types.d.ts +0 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -17
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -17
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +7 -24
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +425 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +135 -134
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -15
- package/src/types.ts +0 -57
- package/src/utils.ts +31 -17
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- 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
|
-
*
|
|
33
|
+
* Utility class for statistics-related queries.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
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 {
|
|
40
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
60
41
|
*
|
|
61
|
-
* const
|
|
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
|
|
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
|
|
110
|
-
* @param
|
|
111
|
-
* @
|
|
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 {
|
|
117
|
-
*
|
|
118
|
-
* const
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
-
}>(
|
|
116
|
+
}>(subgraphUrl, GET_ESCROW_STATISTICS_QUERY, options);
|
|
140
117
|
|
|
141
118
|
const { eventDayDatas } = await customGqlFetch<{
|
|
142
119
|
eventDayDatas: EventDayData[];
|
|
143
120
|
}>(
|
|
144
|
-
|
|
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
|
|
201
|
-
* @param
|
|
202
|
-
* @
|
|
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 {
|
|
208
|
-
*
|
|
209
|
-
* const
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
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
|
-
|
|
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
|
|
283
|
-
* @param
|
|
284
|
-
* @
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
375
|
-
* @
|
|
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 {
|
|
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
|
-
* ...
|
|
388
|
-
* totalTransferAmount:
|
|
362
|
+
* ...hmtStats,
|
|
363
|
+
* totalTransferAmount: hmtStats.totalTransferAmount.toString(),
|
|
389
364
|
* });
|
|
390
365
|
* ```
|
|
391
366
|
*/
|
|
392
|
-
async getHMTStatistics(
|
|
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
|
-
}>(
|
|
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
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* @param
|
|
414
|
-
* @
|
|
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 {
|
|
421
|
-
*
|
|
422
|
-
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
397
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
423
398
|
*
|
|
424
|
-
* const
|
|
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
|
-
|
|
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
|
|
488
|
-
* @param
|
|
489
|
-
* @
|
|
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 {
|
|
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
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
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
|
-
|
|
502
|
+
subgraphUrl,
|
|
524
503
|
GET_EVENT_DAY_DATA_QUERY(filter),
|
|
525
504
|
{
|
|
526
505
|
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
package/src/transaction.ts
CHANGED
|
@@ -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
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
* @returns
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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(
|
|
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
|
|
150
|
-
* @param
|
|
151
|
-
* @returns
|
|
152
|
-
*
|
|
153
|
-
*
|
|
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
|
|
159
|
-
* chainId: ChainId.
|
|
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
|
-
*
|
|
24
|
+
* Handles and throws appropriate error types based on the Ethereum error.
|
|
25
25
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @
|
|
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
|
-
*
|
|
54
|
+
* Validates if a string is a valid URL.
|
|
49
55
|
*
|
|
50
|
-
* @param
|
|
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
|
-
*
|
|
68
|
+
* Checks if a string is valid JSON.
|
|
63
69
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @returns
|
|
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
|
-
*
|
|
83
|
+
* Gets the subgraph URL for the given network, using API key if available.
|
|
78
84
|
*
|
|
79
|
-
* @param
|
|
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
|
-
*
|
|
104
|
+
* Converts a Date object to Unix timestamp (seconds since epoch).
|
|
99
105
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @returns
|
|
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
|
-
*
|
|
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,
|