@human-protocol/sdk 3.0.1 → 3.0.3
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/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -14
- package/dist/escrow.d.ts +0 -6
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +0 -6
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +0 -3
- package/dist/graphql/queries/kvstore.d.ts +1 -0
- package/dist/graphql/queries/kvstore.d.ts.map +1 -1
- package/dist/graphql/queries/kvstore.js +12 -1
- package/dist/graphql/queries/operator.js +1 -1
- package/dist/graphql/queries/statistics.d.ts +2 -2
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +11 -7
- package/dist/graphql/types.d.ts +0 -5
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/interfaces.d.ts +3 -5
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +69 -106
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +123 -159
- package/dist/statistics.d.ts +72 -66
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +121 -89
- package/package.json +1 -1
- package/src/constants.ts +15 -14
- package/src/escrow.ts +0 -6
- package/src/graphql/queries/escrow.ts +0 -3
- package/src/graphql/queries/kvstore.ts +11 -0
- package/src/graphql/queries/operator.ts +1 -1
- package/src/graphql/queries/statistics.ts +13 -9
- package/src/graphql/types.ts +0 -5
- package/src/index.ts +2 -1
- package/src/interfaces.ts +3 -5
- package/src/kvstore.ts +145 -158
- package/src/statistics.ts +138 -100
package/dist/statistics.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EscrowStatistics, HMTStatistics, PaymentStatistics, WorkerStatistics, HMTHolder } from './graphql';
|
|
2
|
-
import { IHMTHoldersParams,
|
|
1
|
+
import { EscrowStatistics, HMTStatistics, PaymentStatistics, WorkerStatistics, HMTHolder, DailyHMTData } from './graphql';
|
|
2
|
+
import { IHMTHoldersParams, IStatisticsFilter } from './interfaces';
|
|
3
3
|
import { NetworkData } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* ## Introduction
|
|
@@ -54,10 +54,12 @@ export declare class StatisticsClient {
|
|
|
54
54
|
* **Input parameters**
|
|
55
55
|
*
|
|
56
56
|
* ```ts
|
|
57
|
-
* interface
|
|
57
|
+
* interface IStatisticsFilter {
|
|
58
58
|
* from?: Date;
|
|
59
59
|
* to?: Date;
|
|
60
|
-
*
|
|
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 ASC.
|
|
61
63
|
* }
|
|
62
64
|
* ```
|
|
63
65
|
*
|
|
@@ -78,7 +80,7 @@ export declare class StatisticsClient {
|
|
|
78
80
|
* ```
|
|
79
81
|
*
|
|
80
82
|
*
|
|
81
|
-
* @param {
|
|
83
|
+
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
82
84
|
* @returns {EscrowStatistics} Escrow statistics data.
|
|
83
85
|
*
|
|
84
86
|
*
|
|
@@ -96,7 +98,7 @@ export declare class StatisticsClient {
|
|
|
96
98
|
* });
|
|
97
99
|
* ```
|
|
98
100
|
*/
|
|
99
|
-
getEscrowStatistics(
|
|
101
|
+
getEscrowStatistics(filter?: IStatisticsFilter): Promise<EscrowStatistics>;
|
|
100
102
|
/**
|
|
101
103
|
* This function returns the statistical data of workers.
|
|
102
104
|
*
|
|
@@ -104,10 +106,12 @@ export declare class StatisticsClient {
|
|
|
104
106
|
* **Input parameters**
|
|
105
107
|
*
|
|
106
108
|
* ```ts
|
|
107
|
-
* interface
|
|
109
|
+
* interface IStatisticsFilter {
|
|
108
110
|
* from?: Date;
|
|
109
111
|
* to?: Date;
|
|
110
|
-
*
|
|
112
|
+
* first?: number; // (Optional) Number of transactions per page. Default is 10.
|
|
113
|
+
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
114
|
+
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
|
|
111
115
|
* }
|
|
112
116
|
* ```
|
|
113
117
|
*
|
|
@@ -123,7 +127,7 @@ export declare class StatisticsClient {
|
|
|
123
127
|
* ```
|
|
124
128
|
*
|
|
125
129
|
*
|
|
126
|
-
* @param {
|
|
130
|
+
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
127
131
|
* @returns {WorkerStatistics} Worker statistics data.
|
|
128
132
|
*
|
|
129
133
|
*
|
|
@@ -141,7 +145,7 @@ export declare class StatisticsClient {
|
|
|
141
145
|
* });
|
|
142
146
|
* ```
|
|
143
147
|
*/
|
|
144
|
-
getWorkerStatistics(
|
|
148
|
+
getWorkerStatistics(filter?: IStatisticsFilter): Promise<WorkerStatistics>;
|
|
145
149
|
/**
|
|
146
150
|
* This function returns the statistical data of payments.
|
|
147
151
|
*
|
|
@@ -149,10 +153,12 @@ export declare class StatisticsClient {
|
|
|
149
153
|
* **Input parameters**
|
|
150
154
|
*
|
|
151
155
|
* ```ts
|
|
152
|
-
* interface
|
|
156
|
+
* interface IStatisticsFilter {
|
|
153
157
|
* from?: Date;
|
|
154
158
|
* to?: Date;
|
|
155
|
-
*
|
|
159
|
+
* first?: number; // (Optional) Number of transactions per page. Default is 10.
|
|
160
|
+
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
161
|
+
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
|
|
156
162
|
* }
|
|
157
163
|
* ```
|
|
158
164
|
*
|
|
@@ -170,7 +176,7 @@ export declare class StatisticsClient {
|
|
|
170
176
|
* ```
|
|
171
177
|
*
|
|
172
178
|
*
|
|
173
|
-
* @param {
|
|
179
|
+
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
174
180
|
* @returns {PaymentStatistics} Payment statistics data.
|
|
175
181
|
*
|
|
176
182
|
*
|
|
@@ -209,44 +215,19 @@ export declare class StatisticsClient {
|
|
|
209
215
|
* );
|
|
210
216
|
* ```
|
|
211
217
|
*/
|
|
212
|
-
getPaymentStatistics(
|
|
218
|
+
getPaymentStatistics(filter?: IStatisticsFilter): Promise<PaymentStatistics>;
|
|
213
219
|
/**
|
|
214
220
|
* This function returns the statistical data of HMToken.
|
|
215
221
|
*
|
|
216
222
|
*
|
|
217
|
-
* **Input parameters**
|
|
218
|
-
*
|
|
219
|
-
* ```ts
|
|
220
|
-
* interface IStatisticsParams {
|
|
221
|
-
* from?: Date;
|
|
222
|
-
* to?: Date;
|
|
223
|
-
* limit?: number;
|
|
224
|
-
* }
|
|
225
|
-
* ```
|
|
226
|
-
*
|
|
227
|
-
* ```ts
|
|
228
|
-
* type HMTHolder = {
|
|
229
|
-
* address: string;
|
|
230
|
-
* balance: BigNumber;
|
|
231
|
-
* }
|
|
232
|
-
*
|
|
233
|
-
* type DailyHMTData = {
|
|
234
|
-
* timestamp: Date;
|
|
235
|
-
* totalTransactionAmount: BigNumber;
|
|
236
|
-
* totalTransactionCount: number;
|
|
237
|
-
* };
|
|
238
|
-
*
|
|
239
223
|
* type HMTStatistics = {
|
|
240
224
|
* totalTransferAmount: BigNumber;
|
|
241
225
|
* totalTransferCount: BigNumber;
|
|
242
226
|
* totalHolders: number;
|
|
243
|
-
* holders: HMTHolder[];
|
|
244
|
-
* dailyHMTData: DailyHMTData[];
|
|
245
227
|
* };
|
|
246
228
|
* ```
|
|
247
229
|
*
|
|
248
230
|
*
|
|
249
|
-
* @param {IStatisticsParams} params Statistics params with duration data
|
|
250
231
|
* @returns {HMTStatistics} HMToken statistics data.
|
|
251
232
|
*
|
|
252
233
|
*
|
|
@@ -262,36 +243,10 @@ export declare class StatisticsClient {
|
|
|
262
243
|
* console.log('HMT statistics:', {
|
|
263
244
|
* ...hmtStatistics,
|
|
264
245
|
* totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
|
|
265
|
-
* holders: hmtStatistics.holders.map((h) => ({
|
|
266
|
-
* ...h,
|
|
267
|
-
* balance: h.balance.toString(),
|
|
268
|
-
* })),
|
|
269
|
-
* dailyHMTData: hmtStatistics.dailyHMTData.map((d) => ({
|
|
270
|
-
* ...d,
|
|
271
|
-
* totalTransactionAmount: d.totalTransactionAmount.toString(),
|
|
272
|
-
* })),
|
|
273
|
-
* });
|
|
274
|
-
*
|
|
275
|
-
* const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
|
|
276
|
-
* from: new Date(2023, 4, 8),
|
|
277
|
-
* to: new Date(2023, 5, 8),
|
|
278
|
-
* });
|
|
279
|
-
*
|
|
280
|
-
* console.log('HMT statistics from 5/8 - 6/8:', {
|
|
281
|
-
* ...hmtStatisticsRange,
|
|
282
|
-
* totalTransferAmount: hmtStatisticsRange.totalTransferAmount.toString(),
|
|
283
|
-
* holders: hmtStatisticsRange.holders.map((h) => ({
|
|
284
|
-
* ...h,
|
|
285
|
-
* balance: h.balance.toString(),
|
|
286
|
-
* })),
|
|
287
|
-
* dailyHMTData: hmtStatisticsRange.dailyHMTData.map((d) => ({
|
|
288
|
-
* ...d,
|
|
289
|
-
* totalTransactionAmount: d.totalTransactionAmount.toString(),
|
|
290
|
-
* })),
|
|
291
246
|
* });
|
|
292
247
|
* ```
|
|
293
248
|
*/
|
|
294
|
-
getHMTStatistics(
|
|
249
|
+
getHMTStatistics(): Promise<HMTStatistics>;
|
|
295
250
|
/**
|
|
296
251
|
* This function returns the holders of the HMToken with optional filters and ordering.
|
|
297
252
|
*
|
|
@@ -318,5 +273,56 @@ export declare class StatisticsClient {
|
|
|
318
273
|
* ```
|
|
319
274
|
*/
|
|
320
275
|
getHMTHolders(params?: IHMTHoldersParams): Promise<HMTHolder[]>;
|
|
276
|
+
/**
|
|
277
|
+
* This function returns the statistical data of HMToken day by day.
|
|
278
|
+
*
|
|
279
|
+
*
|
|
280
|
+
* **Input parameters**
|
|
281
|
+
*
|
|
282
|
+
* ```ts
|
|
283
|
+
* interface IStatisticsFilter {
|
|
284
|
+
* from?: Date;
|
|
285
|
+
* to?: Date;
|
|
286
|
+
* first?: number; // (Optional) Number of transactions per page. Default is 10.
|
|
287
|
+
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
288
|
+
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* ```ts
|
|
293
|
+
* type DailyHMTData = {
|
|
294
|
+
* timestamp: Date;
|
|
295
|
+
* totalTransactionAmount: bigint;
|
|
296
|
+
* totalTransactionCount: number;
|
|
297
|
+
* dailyUniqueSenders: number;
|
|
298
|
+
* dailyUniqueReceivers: number;
|
|
299
|
+
* }
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
*
|
|
303
|
+
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
304
|
+
* @returns {DailyHMTData[]} Daily HMToken statistics data.
|
|
305
|
+
*
|
|
306
|
+
*
|
|
307
|
+
* **Code example**
|
|
308
|
+
*
|
|
309
|
+
* ```ts
|
|
310
|
+
* import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
311
|
+
*
|
|
312
|
+
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
313
|
+
*
|
|
314
|
+
* const dailyHMTStats = await statisticsClient.getHMTStatistics();
|
|
315
|
+
*
|
|
316
|
+
* console.log('Daily HMT statistics:', dailyHMTStats);
|
|
317
|
+
*
|
|
318
|
+
* const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
|
|
319
|
+
* from: new Date(2023, 4, 8),
|
|
320
|
+
* to: new Date(2023, 5, 8),
|
|
321
|
+
* });
|
|
322
|
+
*
|
|
323
|
+
* console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
getHMTDailyData(filter?: IStatisticsFilter): Promise<DailyHMTData[]>;
|
|
321
327
|
}
|
|
322
328
|
//# sourceMappingURL=statistics.d.ts.map
|
package/dist/statistics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,gBAAgB,EAGhB,aAAa,EAEb,iBAAiB,EACjB,gBAAgB,EAEhB,SAAS,
|
|
1
|
+
{"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,gBAAgB,EAGhB,aAAa,EAEb,iBAAiB,EACjB,gBAAgB,EAEhB,SAAS,EACT,YAAY,EACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,gBAAgB;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;gBACS,WAAW,EAAE,WAAW;IAKpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAqC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA4B5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoEG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAkC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;IAkBhD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,aAAa,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAwBzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACG,eAAe,CACnB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,YAAY,EAAE,CAAC;CA8B3B"}
|
package/dist/statistics.js
CHANGED
|
@@ -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
|
|
67
|
+
* interface IStatisticsFilter {
|
|
67
68
|
* from?: Date;
|
|
68
69
|
* to?: Date;
|
|
69
|
-
*
|
|
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 {
|
|
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(
|
|
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)(
|
|
112
|
-
from:
|
|
113
|
-
to:
|
|
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
|
|
147
|
+
* interface IStatisticsFilter {
|
|
139
148
|
* from?: Date;
|
|
140
149
|
* to?: Date;
|
|
141
|
-
*
|
|
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 {
|
|
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(
|
|
186
|
+
async getWorkerStatistics(filter = {}) {
|
|
176
187
|
try {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
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
|
|
216
|
+
* interface IStatisticsFilter {
|
|
200
217
|
* from?: Date;
|
|
201
218
|
* to?: Date;
|
|
202
|
-
*
|
|
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 {
|
|
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(
|
|
278
|
+
async getPaymentStatistics(filter = {}) {
|
|
260
279
|
try {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
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,39 +307,14 @@ class StatisticsClient {
|
|
|
282
307
|
* This function returns the statistical data of HMToken.
|
|
283
308
|
*
|
|
284
309
|
*
|
|
285
|
-
* **Input parameters**
|
|
286
|
-
*
|
|
287
|
-
* ```ts
|
|
288
|
-
* interface IStatisticsParams {
|
|
289
|
-
* from?: Date;
|
|
290
|
-
* to?: Date;
|
|
291
|
-
* limit?: number;
|
|
292
|
-
* }
|
|
293
|
-
* ```
|
|
294
|
-
*
|
|
295
|
-
* ```ts
|
|
296
|
-
* type HMTHolder = {
|
|
297
|
-
* address: string;
|
|
298
|
-
* balance: BigNumber;
|
|
299
|
-
* }
|
|
300
|
-
*
|
|
301
|
-
* type DailyHMTData = {
|
|
302
|
-
* timestamp: Date;
|
|
303
|
-
* totalTransactionAmount: BigNumber;
|
|
304
|
-
* totalTransactionCount: number;
|
|
305
|
-
* };
|
|
306
|
-
*
|
|
307
310
|
* type HMTStatistics = {
|
|
308
311
|
* totalTransferAmount: BigNumber;
|
|
309
312
|
* totalTransferCount: BigNumber;
|
|
310
313
|
* totalHolders: number;
|
|
311
|
-
* holders: HMTHolder[];
|
|
312
|
-
* dailyHMTData: DailyHMTData[];
|
|
313
314
|
* };
|
|
314
315
|
* ```
|
|
315
316
|
*
|
|
316
317
|
*
|
|
317
|
-
* @param {IStatisticsParams} params Statistics params with duration data
|
|
318
318
|
* @returns {HMTStatistics} HMToken statistics data.
|
|
319
319
|
*
|
|
320
320
|
*
|
|
@@ -330,58 +330,16 @@ class StatisticsClient {
|
|
|
330
330
|
* console.log('HMT statistics:', {
|
|
331
331
|
* ...hmtStatistics,
|
|
332
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
|
-
* });
|
|
342
|
-
*
|
|
343
|
-
* const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
|
|
344
|
-
* from: new Date(2023, 4, 8),
|
|
345
|
-
* to: new Date(2023, 5, 8),
|
|
346
|
-
* });
|
|
347
|
-
*
|
|
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
333
|
* });
|
|
360
334
|
* ```
|
|
361
335
|
*/
|
|
362
|
-
async getHMTStatistics(
|
|
336
|
+
async getHMTStatistics() {
|
|
363
337
|
try {
|
|
364
338
|
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, (0, 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,
|
|
369
|
-
});
|
|
370
339
|
return {
|
|
371
340
|
totalTransferAmount: ethers_1.ethers.toBigInt(hmtokenStatistics.totalValueTransfered),
|
|
372
341
|
totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
|
|
373
342
|
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
|
-
dailyUniqueSenders: +eventDayData.dailyUniqueSenders,
|
|
383
|
-
dailyUniqueReceivers: +eventDayData.dailyUniqueReceivers,
|
|
384
|
-
})),
|
|
385
343
|
};
|
|
386
344
|
}
|
|
387
345
|
catch (e) {
|
|
@@ -431,5 +389,79 @@ class StatisticsClient {
|
|
|
431
389
|
return (0, utils_1.throwError)(e);
|
|
432
390
|
}
|
|
433
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* This function returns the statistical data of HMToken day by day.
|
|
394
|
+
*
|
|
395
|
+
*
|
|
396
|
+
* **Input parameters**
|
|
397
|
+
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* interface IStatisticsFilter {
|
|
400
|
+
* from?: Date;
|
|
401
|
+
* to?: Date;
|
|
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.
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* ```ts
|
|
409
|
+
* type DailyHMTData = {
|
|
410
|
+
* timestamp: Date;
|
|
411
|
+
* totalTransactionAmount: bigint;
|
|
412
|
+
* totalTransactionCount: number;
|
|
413
|
+
* dailyUniqueSenders: number;
|
|
414
|
+
* dailyUniqueReceivers: number;
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
*
|
|
419
|
+
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
420
|
+
* @returns {DailyHMTData[]} Daily HMToken statistics data.
|
|
421
|
+
*
|
|
422
|
+
*
|
|
423
|
+
* **Code example**
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
427
|
+
*
|
|
428
|
+
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
429
|
+
*
|
|
430
|
+
* const dailyHMTStats = await statisticsClient.getHMTStatistics();
|
|
431
|
+
*
|
|
432
|
+
* console.log('Daily HMT statistics:', dailyHMTStats);
|
|
433
|
+
*
|
|
434
|
+
* const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
|
|
435
|
+
* from: new Date(2023, 4, 8),
|
|
436
|
+
* to: new Date(2023, 5, 8),
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
async getHMTDailyData(filter = {}) {
|
|
443
|
+
try {
|
|
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,
|
|
453
|
+
});
|
|
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
|
+
}));
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
return (0, utils_1.throwError)(e);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
434
466
|
}
|
|
435
467
|
exports.StatisticsClient = StatisticsClient;
|