@human-protocol/sdk 3.0.1 → 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.
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- 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 +1 -0
- 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/kvstore.js
CHANGED
|
@@ -244,130 +244,6 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
244
244
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Gets the value of a key-value pair in the contract.
|
|
249
|
-
*
|
|
250
|
-
* @param {string} address Address from which to get the key value.
|
|
251
|
-
* @param {string} key Key to obtain the value.
|
|
252
|
-
* @returns {string} Value of the key.
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* **Code example**
|
|
256
|
-
*
|
|
257
|
-
* > Need to have available stake.
|
|
258
|
-
*
|
|
259
|
-
* ```ts
|
|
260
|
-
* import { providers } from 'ethers';
|
|
261
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
262
|
-
*
|
|
263
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
264
|
-
*
|
|
265
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
266
|
-
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
267
|
-
*
|
|
268
|
-
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
async get(address, key) {
|
|
272
|
-
if (key === '')
|
|
273
|
-
throw error_1.ErrorKVStoreEmptyKey;
|
|
274
|
-
if (!ethers_1.ethers.isAddress(address))
|
|
275
|
-
throw error_1.ErrorInvalidAddress;
|
|
276
|
-
try {
|
|
277
|
-
const result = await this.contract?.get(address, key);
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
if (e instanceof Error)
|
|
282
|
-
throw Error(`Failed to get value: ${e.message}`);
|
|
283
|
-
return e;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Gets the URL value of the given entity, and verify its hash.
|
|
288
|
-
*
|
|
289
|
-
* @param {string} address Address from which to get the URL value.
|
|
290
|
-
* @param {string} urlKey Configurable URL key. `url` by default.
|
|
291
|
-
* @returns {string} URL value for the given address if exists, and the content is valid
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* **Code example**
|
|
295
|
-
*
|
|
296
|
-
* ```ts
|
|
297
|
-
* import { providers } from 'ethers';
|
|
298
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
299
|
-
*
|
|
300
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
301
|
-
*
|
|
302
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
303
|
-
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
304
|
-
*
|
|
305
|
-
* const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
306
|
-
* const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
|
|
307
|
-
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
308
|
-
* 'linkedin_url'
|
|
309
|
-
* );
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
async getFileUrlAndVerifyHash(address, urlKey = 'url') {
|
|
313
|
-
if (!ethers_1.ethers.isAddress(address))
|
|
314
|
-
throw error_1.ErrorInvalidAddress;
|
|
315
|
-
const hashKey = urlKey + '_hash';
|
|
316
|
-
let url = '', hash = '';
|
|
317
|
-
try {
|
|
318
|
-
url = await this.contract?.get(address, urlKey);
|
|
319
|
-
}
|
|
320
|
-
catch (e) {
|
|
321
|
-
if (e instanceof Error)
|
|
322
|
-
throw Error(`Failed to get URL: ${e.message}`);
|
|
323
|
-
}
|
|
324
|
-
// Return empty string
|
|
325
|
-
if (!url?.length) {
|
|
326
|
-
return '';
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
hash = await this.contract?.get(address, hashKey);
|
|
330
|
-
}
|
|
331
|
-
catch (e) {
|
|
332
|
-
if (e instanceof Error)
|
|
333
|
-
throw Error(`Failed to get Hash: ${e.message}`);
|
|
334
|
-
}
|
|
335
|
-
const content = await fetch(url).then((res) => res.text());
|
|
336
|
-
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
337
|
-
if (hash !== contentHash) {
|
|
338
|
-
throw error_1.ErrorInvalidHash;
|
|
339
|
-
}
|
|
340
|
-
return url;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Gets the public key of the given entity, and verify its hash.
|
|
344
|
-
*
|
|
345
|
-
* @param {string} address Address from which to get the public key.
|
|
346
|
-
* @returns {string} Public key for the given address if exists, and the content is valid
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* **Code example**
|
|
350
|
-
*
|
|
351
|
-
* ```ts
|
|
352
|
-
* import { providers } from 'ethers';
|
|
353
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
354
|
-
*
|
|
355
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
356
|
-
*
|
|
357
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
358
|
-
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
359
|
-
*
|
|
360
|
-
* const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
async getPublicKey(address) {
|
|
364
|
-
const publicKeyUrl = await this.getFileUrlAndVerifyHash(address, constants_1.KVStoreKeys.publicKey);
|
|
365
|
-
if (publicKeyUrl === '') {
|
|
366
|
-
return '';
|
|
367
|
-
}
|
|
368
|
-
const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
|
|
369
|
-
return publicKey;
|
|
370
|
-
}
|
|
371
247
|
}
|
|
372
248
|
__decorate([
|
|
373
249
|
decorators_1.requiresSigner,
|
|
@@ -414,50 +290,21 @@ exports.KVStoreClient = KVStoreClient;
|
|
|
414
290
|
* ```ts
|
|
415
291
|
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
416
292
|
*
|
|
417
|
-
* const KVStoreAddresses = new KVStoreUtils.
|
|
418
|
-
*
|
|
419
|
-
*
|
|
293
|
+
* const KVStoreAddresses = new KVStoreUtils.getKVStoreData({
|
|
294
|
+
* ChainId.POLYGON_AMOY,
|
|
295
|
+
* "0x1234567890123456789012345678901234567890",
|
|
296
|
+
* );
|
|
420
297
|
* ```
|
|
421
298
|
*/
|
|
422
299
|
class KVStoreUtils {
|
|
423
300
|
/**
|
|
424
301
|
* This function returns the KVStore data for a given address.
|
|
425
302
|
*
|
|
426
|
-
* > This uses Subgraph
|
|
427
|
-
*
|
|
428
|
-
* **Input parameters**
|
|
429
|
-
*
|
|
430
|
-
* ```ts
|
|
431
|
-
* enum ChainId {
|
|
432
|
-
* ALL = -1,
|
|
433
|
-
* MAINNET = 1,
|
|
434
|
-
* RINKEBY = 4,
|
|
435
|
-
* GOERLI = 5,
|
|
436
|
-
* BSC_MAINNET = 56,
|
|
437
|
-
* BSC_TESTNET = 97,
|
|
438
|
-
* POLYGON = 137,
|
|
439
|
-
* POLYGON_MUMBAI = 80001,
|
|
440
|
-
* POLYGON_AMOY = 80002,
|
|
441
|
-
* MOONBEAM = 1284,
|
|
442
|
-
* MOONBASE_ALPHA = 1287,
|
|
443
|
-
* AVALANCHE = 43114,
|
|
444
|
-
* AVALANCHE_TESTNET = 43113,
|
|
445
|
-
* CELO = 42220,
|
|
446
|
-
* CELO_ALFAJORES = 44787,
|
|
447
|
-
* LOCALHOST = 1338,
|
|
448
|
-
* }
|
|
449
|
-
* ```
|
|
450
|
-
*
|
|
451
|
-
* ```ts
|
|
452
|
-
* interface IKVStore {
|
|
453
|
-
* key: string;
|
|
454
|
-
* value: string;
|
|
455
|
-
* }
|
|
456
|
-
* ```
|
|
457
|
-
*
|
|
458
303
|
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
459
304
|
* @param {string} address Address of the KVStore
|
|
460
305
|
* @returns {Promise<IKVStore[]>} KVStore data
|
|
306
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
307
|
+
* @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
|
|
461
308
|
*
|
|
462
309
|
* **Code example**
|
|
463
310
|
*
|
|
@@ -483,5 +330,122 @@ class KVStoreUtils {
|
|
|
483
330
|
}));
|
|
484
331
|
return kvStoreData || [];
|
|
485
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
335
|
+
*
|
|
336
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
337
|
+
* @param {string} address Address from which to get the key value.
|
|
338
|
+
* @param {string} key Key to obtain the value.
|
|
339
|
+
* @returns {Promise<string>} Value of the key.
|
|
340
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
341
|
+
* @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
|
|
342
|
+
* @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
|
|
343
|
+
*
|
|
344
|
+
* **Code example**
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
348
|
+
*
|
|
349
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
350
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
351
|
+
* const key = 'role';
|
|
352
|
+
*
|
|
353
|
+
* const value = await KVStoreUtils.get(chainId, address, key);
|
|
354
|
+
* console.log(value);
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
static async get(chainId, address, key) {
|
|
358
|
+
if (key === '')
|
|
359
|
+
throw error_1.ErrorKVStoreEmptyKey;
|
|
360
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
361
|
+
throw error_1.ErrorInvalidAddress;
|
|
362
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
363
|
+
if (!networkData) {
|
|
364
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
365
|
+
}
|
|
366
|
+
const { kvstores } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, kvstore_1.GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY)(), { address: address.toLowerCase(), key });
|
|
367
|
+
if (!kvstores || kvstores.length === 0) {
|
|
368
|
+
throw new Error(`Key "${key}" not found for address ${address}`);
|
|
369
|
+
}
|
|
370
|
+
const value = kvstores[0].value;
|
|
371
|
+
return value;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Gets the URL value of the given entity, and verifies its hash.
|
|
375
|
+
*
|
|
376
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
377
|
+
* @param {string} address Address from which to get the URL value.
|
|
378
|
+
* @param {string} urlKey Configurable URL key. `url` by default.
|
|
379
|
+
* @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
|
|
380
|
+
*
|
|
381
|
+
* **Code example**
|
|
382
|
+
*
|
|
383
|
+
* ```ts
|
|
384
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
385
|
+
*
|
|
386
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
387
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
388
|
+
*
|
|
389
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
|
|
390
|
+
* console.log(url);
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
static async getFileUrlAndVerifyHash(chainId, address, urlKey = 'url') {
|
|
394
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
395
|
+
throw error_1.ErrorInvalidAddress;
|
|
396
|
+
const hashKey = urlKey + '_hash';
|
|
397
|
+
let url = '', hash = '';
|
|
398
|
+
try {
|
|
399
|
+
url = await this.get(chainId, address, urlKey);
|
|
400
|
+
}
|
|
401
|
+
catch (e) {
|
|
402
|
+
if (e instanceof Error)
|
|
403
|
+
throw Error(`Failed to get URL: ${e.message}`);
|
|
404
|
+
}
|
|
405
|
+
// Return empty string
|
|
406
|
+
if (!url?.length) {
|
|
407
|
+
return '';
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
hash = await this.get(chainId, address, hashKey);
|
|
411
|
+
}
|
|
412
|
+
catch (e) {
|
|
413
|
+
if (e instanceof Error)
|
|
414
|
+
throw Error(`Failed to get Hash: ${e.message}`);
|
|
415
|
+
}
|
|
416
|
+
const content = await fetch(url).then((res) => res.text());
|
|
417
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
418
|
+
if (hash !== contentHash) {
|
|
419
|
+
throw error_1.ErrorInvalidHash;
|
|
420
|
+
}
|
|
421
|
+
return url;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Gets the public key of the given entity, and verifies its hash.
|
|
425
|
+
*
|
|
426
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
427
|
+
* @param {string} address Address from which to get the public key.
|
|
428
|
+
* @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
|
|
429
|
+
*
|
|
430
|
+
* **Code example**
|
|
431
|
+
*
|
|
432
|
+
* ```ts
|
|
433
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
434
|
+
*
|
|
435
|
+
* const chainId = ChainId.POLYGON_AMOY;
|
|
436
|
+
* const address = '0x1234567890123456789012345678901234567890';
|
|
437
|
+
*
|
|
438
|
+
* const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
|
|
439
|
+
* console.log(publicKey);
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
static async getPublicKey(chainId, address) {
|
|
443
|
+
const publicKeyUrl = await this.getFileUrlAndVerifyHash(chainId, address, constants_1.KVStoreKeys.publicKey);
|
|
444
|
+
if (publicKeyUrl === '') {
|
|
445
|
+
return '';
|
|
446
|
+
}
|
|
447
|
+
const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
|
|
448
|
+
return publicKey;
|
|
449
|
+
}
|
|
486
450
|
}
|
|
487
451
|
exports.KVStoreUtils = KVStoreUtils;
|
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"}
|