@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/dist/statistics.js
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StatisticsUtils = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const enums_1 = require("./enums");
|
|
6
6
|
const graphql_1 = require("./graphql");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Utility class for statistics-related queries.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Unlike other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
|
|
14
|
-
* We just need to create a client object using relevant network data.
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* constructor(network: NetworkData)
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* ## Installation
|
|
21
|
-
*
|
|
22
|
-
* ### npm
|
|
23
|
-
* ```bash
|
|
24
|
-
* npm install @human-protocol/sdk
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* ### yarn
|
|
28
|
-
* ```bash
|
|
29
|
-
* yarn install @human-protocol/sdk
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* ## Code example
|
|
11
|
+
* Unlike other SDK clients, `StatisticsUtils` does not require `signer` or `provider` to be provided.
|
|
12
|
+
* We just need to pass the network data to each static method.
|
|
33
13
|
*
|
|
14
|
+
* @example
|
|
34
15
|
* ```ts
|
|
35
|
-
* import {
|
|
16
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
36
17
|
*
|
|
37
|
-
* const
|
|
18
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
19
|
+
* const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
|
|
20
|
+
* console.log('Total escrows:', escrowStats.totalEscrows);
|
|
38
21
|
* ```
|
|
39
22
|
*/
|
|
40
|
-
class
|
|
41
|
-
/**
|
|
42
|
-
* **StatisticsClient constructor**
|
|
43
|
-
*
|
|
44
|
-
* @param {NetworkData} networkData - The network information required to connect to the Statistics contract
|
|
45
|
-
*/
|
|
46
|
-
constructor(networkData) {
|
|
47
|
-
this.networkData = networkData;
|
|
48
|
-
this.subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
49
|
-
}
|
|
23
|
+
class StatisticsUtils {
|
|
50
24
|
/**
|
|
51
25
|
* This function returns the statistical data of escrows.
|
|
52
26
|
*
|
|
@@ -78,31 +52,37 @@ class StatisticsClient {
|
|
|
78
52
|
* };
|
|
79
53
|
* ```
|
|
80
54
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
* @
|
|
84
|
-
*
|
|
85
|
-
* **Code example**
|
|
55
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
56
|
+
* @param filter - Statistics params with duration data
|
|
57
|
+
* @param options - Optional configuration for subgraph requests.
|
|
58
|
+
* @returns Escrow statistics data.
|
|
86
59
|
*
|
|
60
|
+
* @example
|
|
87
61
|
* ```ts
|
|
88
|
-
* import {
|
|
89
|
-
*
|
|
90
|
-
* const
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
62
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
63
|
+
*
|
|
64
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
65
|
+
* const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
|
|
66
|
+
* console.log('Total escrows:', escrowStats.totalEscrows);
|
|
67
|
+
*
|
|
68
|
+
* const escrowStatsApril = await StatisticsUtils.getEscrowStatistics(
|
|
69
|
+
* networkData,
|
|
70
|
+
* {
|
|
71
|
+
* from: new Date('2021-04-01'),
|
|
72
|
+
* to: new Date('2021-04-30'),
|
|
73
|
+
* }
|
|
74
|
+
* );
|
|
75
|
+
* console.log('April escrows:', escrowStatsApril.totalEscrows);
|
|
97
76
|
* ```
|
|
98
77
|
*/
|
|
99
|
-
async getEscrowStatistics(filter = {}, options) {
|
|
78
|
+
static async getEscrowStatistics(networkData, filter = {}, options) {
|
|
100
79
|
try {
|
|
80
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
101
81
|
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
102
82
|
const skip = filter.skip || 0;
|
|
103
83
|
const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
|
|
104
|
-
const { escrowStatistics } = await (0, utils_1.customGqlFetch)(
|
|
105
|
-
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(
|
|
84
|
+
const { escrowStatistics } = await (0, utils_1.customGqlFetch)(subgraphUrl, graphql_1.GET_ESCROW_STATISTICS_QUERY, options);
|
|
85
|
+
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
|
|
106
86
|
from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
|
|
107
87
|
to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
|
|
108
88
|
orderDirection: orderDirection,
|
|
@@ -153,30 +133,36 @@ class StatisticsClient {
|
|
|
153
133
|
* };
|
|
154
134
|
* ```
|
|
155
135
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @
|
|
159
|
-
*
|
|
160
|
-
* **Code example**
|
|
136
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
137
|
+
* @param filter - Statistics params with duration data
|
|
138
|
+
* @param options - Optional configuration for subgraph requests.
|
|
139
|
+
* @returns Worker statistics data.
|
|
161
140
|
*
|
|
141
|
+
* @example
|
|
162
142
|
* ```ts
|
|
163
|
-
* import {
|
|
164
|
-
*
|
|
165
|
-
* const
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
143
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
144
|
+
*
|
|
145
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
146
|
+
* const workerStats = await StatisticsUtils.getWorkerStatistics(networkData);
|
|
147
|
+
* console.log('Daily workers data:', workerStats.dailyWorkersData);
|
|
148
|
+
*
|
|
149
|
+
* const workerStatsApril = await StatisticsUtils.getWorkerStatistics(
|
|
150
|
+
* networkData,
|
|
151
|
+
* {
|
|
152
|
+
* from: new Date('2021-04-01'),
|
|
153
|
+
* to: new Date('2021-04-30'),
|
|
154
|
+
* }
|
|
155
|
+
* );
|
|
156
|
+
* console.log('April workers:', workerStatsApril.dailyWorkersData.length);
|
|
172
157
|
* ```
|
|
173
158
|
*/
|
|
174
|
-
async getWorkerStatistics(filter = {}, options) {
|
|
159
|
+
static async getWorkerStatistics(networkData, filter = {}, options) {
|
|
175
160
|
try {
|
|
161
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
176
162
|
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
177
163
|
const skip = filter.skip || 0;
|
|
178
164
|
const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
|
|
179
|
-
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(
|
|
165
|
+
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
|
|
180
166
|
from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
|
|
181
167
|
to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
|
|
182
168
|
orderDirection: orderDirection,
|
|
@@ -222,51 +208,43 @@ class StatisticsClient {
|
|
|
222
208
|
* };
|
|
223
209
|
* ```
|
|
224
210
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @param
|
|
227
|
-
* @
|
|
228
|
-
*
|
|
229
|
-
* **Code example**
|
|
211
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
212
|
+
* @param filter - Statistics params with duration data
|
|
213
|
+
* @param options - Optional configuration for subgraph requests.
|
|
214
|
+
* @returns Payment statistics data.
|
|
230
215
|
*
|
|
216
|
+
* @example
|
|
231
217
|
* ```ts
|
|
232
|
-
* import {
|
|
233
|
-
*
|
|
234
|
-
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
218
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
235
219
|
*
|
|
220
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
221
|
+
* const paymentStats = await StatisticsUtils.getPaymentStatistics(networkData);
|
|
236
222
|
* console.log(
|
|
237
223
|
* 'Payment statistics:',
|
|
238
|
-
*
|
|
239
|
-
* (p) => ({
|
|
240
|
-
* ...p,
|
|
241
|
-
* totalAmountPaid: p.totalAmountPaid.toString(),
|
|
242
|
-
* averageAmountPerJob: p.averageAmountPerJob.toString(),
|
|
243
|
-
* averageAmountPerWorker: p.averageAmountPerWorker.toString(),
|
|
244
|
-
* })
|
|
245
|
-
* )
|
|
246
|
-
* );
|
|
247
|
-
*
|
|
248
|
-
* console.log(
|
|
249
|
-
* 'Payment statistics from 5/8 - 6/8:',
|
|
250
|
-
* (
|
|
251
|
-
* await statisticsClient.getPaymentStatistics({
|
|
252
|
-
* from: new Date(2023, 4, 8),
|
|
253
|
-
* to: new Date(2023, 5, 8),
|
|
254
|
-
* })
|
|
255
|
-
* ).dailyPaymentsData.map((p) => ({
|
|
224
|
+
* paymentStats.dailyPaymentsData.map((p) => ({
|
|
256
225
|
* ...p,
|
|
257
226
|
* totalAmountPaid: p.totalAmountPaid.toString(),
|
|
258
|
-
* averageAmountPerJob: p.averageAmountPerJob.toString(),
|
|
259
227
|
* averageAmountPerWorker: p.averageAmountPerWorker.toString(),
|
|
260
228
|
* }))
|
|
261
229
|
* );
|
|
230
|
+
*
|
|
231
|
+
* const paymentStatsRange = await StatisticsUtils.getPaymentStatistics(
|
|
232
|
+
* networkData,
|
|
233
|
+
* {
|
|
234
|
+
* from: new Date(2023, 4, 8),
|
|
235
|
+
* to: new Date(2023, 5, 8),
|
|
236
|
+
* }
|
|
237
|
+
* );
|
|
238
|
+
* console.log('Payment statistics from 5/8 - 6/8:', paymentStatsRange.dailyPaymentsData.length);
|
|
262
239
|
* ```
|
|
263
240
|
*/
|
|
264
|
-
async getPaymentStatistics(filter = {}, options) {
|
|
241
|
+
static async getPaymentStatistics(networkData, filter = {}, options) {
|
|
265
242
|
try {
|
|
243
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
266
244
|
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
267
245
|
const skip = filter.skip || 0;
|
|
268
246
|
const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
|
|
269
|
-
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(
|
|
247
|
+
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
|
|
270
248
|
from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
|
|
271
249
|
to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
|
|
272
250
|
orderDirection: orderDirection,
|
|
@@ -300,27 +278,26 @@ class StatisticsClient {
|
|
|
300
278
|
* };
|
|
301
279
|
* ```
|
|
302
280
|
*
|
|
303
|
-
* @param
|
|
304
|
-
* @
|
|
305
|
-
*
|
|
306
|
-
* **Code example**
|
|
281
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
282
|
+
* @param options - Optional configuration for subgraph requests.
|
|
283
|
+
* @returns HMToken statistics data.
|
|
307
284
|
*
|
|
285
|
+
* @example
|
|
308
286
|
* ```ts
|
|
309
|
-
* import {
|
|
310
|
-
*
|
|
311
|
-
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
312
|
-
*
|
|
313
|
-
* const hmtStatistics = await statisticsClient.getHMTStatistics();
|
|
287
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
314
288
|
*
|
|
289
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
290
|
+
* const hmtStats = await StatisticsUtils.getHMTStatistics(networkData);
|
|
315
291
|
* console.log('HMT statistics:', {
|
|
316
|
-
* ...
|
|
317
|
-
* totalTransferAmount:
|
|
292
|
+
* ...hmtStats,
|
|
293
|
+
* totalTransferAmount: hmtStats.totalTransferAmount.toString(),
|
|
318
294
|
* });
|
|
319
295
|
* ```
|
|
320
296
|
*/
|
|
321
|
-
async getHMTStatistics(options) {
|
|
297
|
+
static async getHMTStatistics(networkData, options) {
|
|
322
298
|
try {
|
|
323
|
-
const
|
|
299
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
300
|
+
const { hmtokenStatistics } = await (0, utils_1.customGqlFetch)(subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY, options);
|
|
324
301
|
return {
|
|
325
302
|
totalTransferAmount: BigInt(hmtokenStatistics.totalValueTransfered),
|
|
326
303
|
totalTransferCount: +hmtokenStatistics.totalTransferEventCount,
|
|
@@ -334,34 +311,31 @@ class StatisticsClient {
|
|
|
334
311
|
/**
|
|
335
312
|
* This function returns the holders of the HMToken with optional filters and ordering.
|
|
336
313
|
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* @param
|
|
340
|
-
* @
|
|
341
|
-
* @returns {Promise<IHMTHolder[]>} List of HMToken holders.
|
|
342
|
-
*
|
|
343
|
-
* **Code example**
|
|
314
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
315
|
+
* @param params - HMT Holders params with filters and ordering
|
|
316
|
+
* @param options - Optional configuration for subgraph requests.
|
|
317
|
+
* @returns List of HMToken holders.
|
|
344
318
|
*
|
|
319
|
+
* @example
|
|
345
320
|
* ```ts
|
|
346
|
-
* import {
|
|
321
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
347
322
|
*
|
|
348
|
-
* const
|
|
349
|
-
*
|
|
350
|
-
* const hmtHolders = await statisticsClient.getHMTHolders({
|
|
323
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
324
|
+
* const hmtHolders = await StatisticsUtils.getHMTHolders(networkData, {
|
|
351
325
|
* orderDirection: 'asc',
|
|
352
326
|
* });
|
|
353
|
-
*
|
|
354
327
|
* console.log('HMT holders:', hmtHolders.map((h) => ({
|
|
355
328
|
* ...h,
|
|
356
329
|
* balance: h.balance.toString(),
|
|
357
330
|
* })));
|
|
358
331
|
* ```
|
|
359
332
|
*/
|
|
360
|
-
async getHMTHolders(params = {}, options) {
|
|
333
|
+
static async getHMTHolders(networkData, params = {}, options) {
|
|
361
334
|
try {
|
|
335
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
362
336
|
const { address, orderDirection } = params;
|
|
363
337
|
const query = (0, graphql_1.GET_HOLDERS_QUERY)(address);
|
|
364
|
-
const { holders } = await (0, utils_1.customGqlFetch)(
|
|
338
|
+
const { holders } = await (0, utils_1.customGqlFetch)(subgraphUrl, query, {
|
|
365
339
|
address,
|
|
366
340
|
orderBy: 'balance',
|
|
367
341
|
orderDirection,
|
|
@@ -400,35 +374,36 @@ class StatisticsClient {
|
|
|
400
374
|
* }
|
|
401
375
|
* ```
|
|
402
376
|
*
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
405
|
-
* @
|
|
406
|
-
*
|
|
407
|
-
* **Code example**
|
|
377
|
+
* @param networkData - The network information required to connect to the subgraph
|
|
378
|
+
* @param filter - Statistics params with duration data
|
|
379
|
+
* @param options - Optional configuration for subgraph requests.
|
|
380
|
+
* @returns Daily HMToken statistics data.
|
|
408
381
|
*
|
|
382
|
+
* @example
|
|
409
383
|
* ```ts
|
|
410
|
-
* import {
|
|
411
|
-
*
|
|
412
|
-
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
413
|
-
*
|
|
414
|
-
* const dailyHMTStats = await statisticsClient.getHMTStatistics();
|
|
384
|
+
* import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
415
385
|
*
|
|
386
|
+
* const networkData = NETWORKS[ChainId.POLYGON_AMOY];
|
|
387
|
+
* const dailyHMTStats = await StatisticsUtils.getHMTDailyData(networkData);
|
|
416
388
|
* console.log('Daily HMT statistics:', dailyHMTStats);
|
|
417
389
|
*
|
|
418
|
-
* const
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
390
|
+
* const hmtStatsRange = await StatisticsUtils.getHMTDailyData(
|
|
391
|
+
* networkData,
|
|
392
|
+
* {
|
|
393
|
+
* from: new Date(2023, 4, 8),
|
|
394
|
+
* to: new Date(2023, 5, 8),
|
|
395
|
+
* }
|
|
396
|
+
* );
|
|
397
|
+
* console.log('HMT statistics from 5/8 - 6/8:', hmtStatsRange.length);
|
|
424
398
|
* ```
|
|
425
399
|
*/
|
|
426
|
-
async getHMTDailyData(filter = {}, options) {
|
|
400
|
+
static async getHMTDailyData(networkData, filter = {}, options) {
|
|
427
401
|
try {
|
|
402
|
+
const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
428
403
|
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
429
404
|
const skip = filter.skip || 0;
|
|
430
405
|
const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
|
|
431
|
-
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(
|
|
406
|
+
const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
|
|
432
407
|
from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
|
|
433
408
|
to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
|
|
434
409
|
orderDirection: orderDirection,
|
|
@@ -448,4 +423,4 @@ class StatisticsClient {
|
|
|
448
423
|
}
|
|
449
424
|
}
|
|
450
425
|
}
|
|
451
|
-
exports.
|
|
426
|
+
exports.StatisticsUtils = StatisticsUtils;
|
package/dist/transaction.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { ChainId } from './enums';
|
|
2
2
|
import { ITransaction, ITransactionsFilter, SubgraphOptions } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for transaction-related queries.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const transaction = await TransactionUtils.getTransaction(
|
|
11
|
+
* ChainId.POLYGON_AMOY,
|
|
12
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
13
|
+
* );
|
|
14
|
+
* console.log('Transaction:', transaction);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
export declare class TransactionUtils {
|
|
4
18
|
/**
|
|
5
19
|
* This function returns the transaction data for the given hash.
|
|
@@ -32,17 +46,22 @@ export declare class TransactionUtils {
|
|
|
32
46
|
* };
|
|
33
47
|
* ```
|
|
34
48
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @returns
|
|
39
|
-
*
|
|
40
|
-
*
|
|
49
|
+
* @param chainId - The chain ID.
|
|
50
|
+
* @param hash - The transaction hash.
|
|
51
|
+
* @param options - Optional configuration for subgraph requests.
|
|
52
|
+
* @returns Returns the transaction details or null if not found.
|
|
53
|
+
* @throws ErrorInvalidHashProvided If the hash is invalid
|
|
54
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
41
55
|
*
|
|
56
|
+
* @example
|
|
42
57
|
* ```ts
|
|
43
58
|
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
44
59
|
*
|
|
45
|
-
* const transaction = await TransactionUtils.getTransaction(
|
|
60
|
+
* const transaction = await TransactionUtils.getTransaction(
|
|
61
|
+
* ChainId.POLYGON_AMOY,
|
|
62
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
63
|
+
* );
|
|
64
|
+
* console.log('Transaction:', transaction);
|
|
46
65
|
* ```
|
|
47
66
|
*/
|
|
48
67
|
static getTransaction(chainId: ChainId, hash: string, options?: SubgraphOptions): Promise<ITransaction | null>;
|
|
@@ -69,7 +88,7 @@ export declare class TransactionUtils {
|
|
|
69
88
|
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
70
89
|
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
|
|
71
90
|
* }
|
|
72
|
-
*
|
|
91
|
+
* ```
|
|
73
92
|
*
|
|
74
93
|
* ```ts
|
|
75
94
|
* type InternalTransaction = {
|
|
@@ -99,17 +118,18 @@ export declare class TransactionUtils {
|
|
|
99
118
|
* };
|
|
100
119
|
* ```
|
|
101
120
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
104
|
-
* @returns
|
|
105
|
-
*
|
|
106
|
-
*
|
|
121
|
+
* @param filter - Filter for the transactions.
|
|
122
|
+
* @param options - Optional configuration for subgraph requests.
|
|
123
|
+
* @returns Returns an array with all the transaction details.
|
|
124
|
+
* @throws ErrorCannotUseDateAndBlockSimultaneously If both date and block filters are used
|
|
125
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
107
126
|
*
|
|
127
|
+
* @example
|
|
108
128
|
* ```ts
|
|
109
129
|
* import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
|
|
110
130
|
*
|
|
111
|
-
* const filter
|
|
112
|
-
* chainId: ChainId.
|
|
131
|
+
* const filter = {
|
|
132
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
113
133
|
* startDate: new Date('2022-01-01'),
|
|
114
134
|
* endDate: new Date('2022-12-31'),
|
|
115
135
|
* first: 10,
|
|
@@ -117,6 +137,7 @@ export declare class TransactionUtils {
|
|
|
117
137
|
* orderDirection: OrderDirection.DESC,
|
|
118
138
|
* };
|
|
119
139
|
* const transactions = await TransactionUtils.getTransactions(filter);
|
|
140
|
+
* console.log('Transactions:', transactions.length);
|
|
120
141
|
* ```
|
|
121
142
|
*/
|
|
122
143
|
static getTransactions(filter: ITransactionsFilter, options?: SubgraphOptions): Promise<ITransaction[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAWlD,OAAO,EAEL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB,qBAAa,gBAAgB;IAC3B
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAWlD,OAAO,EAEL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0EG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,EAAE,CAAC;CAgD3B"}
|
package/dist/transaction.js
CHANGED
|
@@ -7,6 +7,20 @@ const enums_1 = require("./enums");
|
|
|
7
7
|
const error_1 = require("./error");
|
|
8
8
|
const transaction_1 = require("./graphql/queries/transaction");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Utility class for transaction-related queries.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const transaction = await TransactionUtils.getTransaction(
|
|
18
|
+
* ChainId.POLYGON_AMOY,
|
|
19
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
20
|
+
* );
|
|
21
|
+
* console.log('Transaction:', transaction);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
10
24
|
class TransactionUtils {
|
|
11
25
|
/**
|
|
12
26
|
* This function returns the transaction data for the given hash.
|
|
@@ -39,17 +53,22 @@ class TransactionUtils {
|
|
|
39
53
|
* };
|
|
40
54
|
* ```
|
|
41
55
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
46
|
-
*
|
|
47
|
-
*
|
|
56
|
+
* @param chainId - The chain ID.
|
|
57
|
+
* @param hash - The transaction hash.
|
|
58
|
+
* @param options - Optional configuration for subgraph requests.
|
|
59
|
+
* @returns Returns the transaction details or null if not found.
|
|
60
|
+
* @throws ErrorInvalidHashProvided If the hash is invalid
|
|
61
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
48
62
|
*
|
|
63
|
+
* @example
|
|
49
64
|
* ```ts
|
|
50
65
|
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
51
66
|
*
|
|
52
|
-
* const transaction = await TransactionUtils.getTransaction(
|
|
67
|
+
* const transaction = await TransactionUtils.getTransaction(
|
|
68
|
+
* ChainId.POLYGON_AMOY,
|
|
69
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
70
|
+
* );
|
|
71
|
+
* console.log('Transaction:', transaction);
|
|
53
72
|
* ```
|
|
54
73
|
*/
|
|
55
74
|
static async getTransaction(chainId, hash, options) {
|
|
@@ -90,7 +109,7 @@ class TransactionUtils {
|
|
|
90
109
|
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
91
110
|
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
|
|
92
111
|
* }
|
|
93
|
-
*
|
|
112
|
+
* ```
|
|
94
113
|
*
|
|
95
114
|
* ```ts
|
|
96
115
|
* type InternalTransaction = {
|
|
@@ -120,17 +139,18 @@ class TransactionUtils {
|
|
|
120
139
|
* };
|
|
121
140
|
* ```
|
|
122
141
|
*
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
-
* @returns
|
|
126
|
-
*
|
|
127
|
-
*
|
|
142
|
+
* @param filter - Filter for the transactions.
|
|
143
|
+
* @param options - Optional configuration for subgraph requests.
|
|
144
|
+
* @returns Returns an array with all the transaction details.
|
|
145
|
+
* @throws ErrorCannotUseDateAndBlockSimultaneously If both date and block filters are used
|
|
146
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
128
147
|
*
|
|
148
|
+
* @example
|
|
129
149
|
* ```ts
|
|
130
150
|
* import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
|
|
131
151
|
*
|
|
132
|
-
* const filter
|
|
133
|
-
* chainId: ChainId.
|
|
152
|
+
* const filter = {
|
|
153
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
134
154
|
* startDate: new Date('2022-01-01'),
|
|
135
155
|
* endDate: new Date('2022-12-31'),
|
|
136
156
|
* first: 10,
|
|
@@ -138,6 +158,7 @@ class TransactionUtils {
|
|
|
138
158
|
* orderDirection: OrderDirection.DESC,
|
|
139
159
|
* };
|
|
140
160
|
* const transactions = await TransactionUtils.getTransactions(filter);
|
|
161
|
+
* console.log('Transactions:', transactions.length);
|
|
141
162
|
* ```
|
|
142
163
|
*/
|
|
143
164
|
static async getTransactions(filter, options) {
|
package/dist/types.d.ts
CHANGED
|
@@ -34,60 +34,6 @@ export declare enum EscrowStatus {
|
|
|
34
34
|
*/
|
|
35
35
|
ToCancel = 6
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* AWS/GCP cloud storage access data
|
|
39
|
-
* @readonly
|
|
40
|
-
* @deprecated StorageClient is deprecated. Use Minio.Client directly.
|
|
41
|
-
*/
|
|
42
|
-
export type StorageCredentials = {
|
|
43
|
-
/**
|
|
44
|
-
* Access Key
|
|
45
|
-
*/
|
|
46
|
-
accessKey: string;
|
|
47
|
-
/**
|
|
48
|
-
* Secret Key
|
|
49
|
-
*/
|
|
50
|
-
secretKey: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated StorageClient is deprecated. Use Minio.Client directly.
|
|
54
|
-
*/
|
|
55
|
-
export type StorageParams = {
|
|
56
|
-
/**
|
|
57
|
-
* Request endPoint
|
|
58
|
-
*/
|
|
59
|
-
endPoint: string;
|
|
60
|
-
/**
|
|
61
|
-
* Enable secure (HTTPS) access. Default value set to false
|
|
62
|
-
*/
|
|
63
|
-
useSSL: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Region
|
|
66
|
-
*/
|
|
67
|
-
region?: string;
|
|
68
|
-
/**
|
|
69
|
-
* TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
|
|
70
|
-
*/
|
|
71
|
-
port?: number;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Upload file data
|
|
75
|
-
* @readonly
|
|
76
|
-
*/
|
|
77
|
-
export type UploadFile = {
|
|
78
|
-
/**
|
|
79
|
-
* Uploaded object key
|
|
80
|
-
*/
|
|
81
|
-
key: string;
|
|
82
|
-
/**
|
|
83
|
-
* Uploaded object URL
|
|
84
|
-
*/
|
|
85
|
-
url: string;
|
|
86
|
-
/**
|
|
87
|
-
* Hash of uploaded object key
|
|
88
|
-
*/
|
|
89
|
-
hash: string;
|
|
90
|
-
};
|
|
91
37
|
/**
|
|
92
38
|
* Network data
|
|
93
39
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
|