@human-protocol/sdk 2.1.3 → 3.0.1
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/README.md +23 -80
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +56 -24
- package/dist/enums.d.ts +7 -2
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +8 -2
- package/dist/error.d.ts +16 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +18 -2
- package/dist/escrow.d.ts +91 -7
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +154 -39
- package/dist/graphql/queries/escrow.d.ts +1 -0
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +50 -9
- package/dist/graphql/queries/hmtoken.d.ts +1 -1
- package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
- package/dist/graphql/queries/hmtoken.js +23 -7
- package/dist/graphql/queries/kvstore.d.ts +2 -0
- package/dist/graphql/queries/kvstore.d.ts.map +1 -0
- package/dist/graphql/queries/kvstore.js +28 -0
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +2 -0
- package/dist/graphql/queries/transaction.d.ts +4 -0
- package/dist/graphql/queries/transaction.d.ts.map +1 -0
- package/dist/graphql/queries/transaction.js +64 -0
- package/dist/graphql/types.d.ts +19 -0
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +35 -4
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +84 -0
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +103 -1
- package/dist/operator.d.ts +5 -2
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +68 -57
- package/dist/statistics.d.ts +29 -2
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +53 -7
- package/dist/transaction.d.ts +75 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +130 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +21 -1
- package/package.json +7 -6
- package/src/constants.ts +73 -23
- package/src/enums.ts +7 -1
- package/src/error.ts +23 -0
- package/src/escrow.ts +199 -51
- package/src/graphql/queries/escrow.ts +53 -8
- package/src/graphql/queries/hmtoken.ts +23 -7
- package/src/graphql/queries/kvstore.ts +23 -0
- package/src/graphql/queries/statistics.ts +2 -0
- package/src/graphql/queries/transaction.ts +64 -0
- package/src/graphql/types.ts +22 -0
- package/src/index.ts +2 -0
- package/src/interfaces.ts +40 -4
- package/src/kvstore.ts +114 -1
- package/src/operator.ts +90 -69
- package/src/statistics.ts +63 -9
- package/src/transaction.ts +152 -0
- package/src/types.ts +4 -0
- package/src/utils.ts +25 -0
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EscrowStatus } from './types';
|
|
2
|
-
import { ChainId } from './enums';
|
|
2
|
+
import { ChainId, OrderDirection } from './enums';
|
|
3
3
|
export interface IAllocation {
|
|
4
4
|
escrowAddress: string;
|
|
5
5
|
staker: string;
|
|
@@ -35,7 +35,7 @@ export interface ILeaderSubgraph extends Omit<ILeader, 'jobTypes'> {
|
|
|
35
35
|
jobTypes?: string;
|
|
36
36
|
}
|
|
37
37
|
export interface ILeadersFilter {
|
|
38
|
-
|
|
38
|
+
chainId: ChainId;
|
|
39
39
|
role?: string;
|
|
40
40
|
}
|
|
41
41
|
export interface IReputationNetwork {
|
|
@@ -55,7 +55,7 @@ export interface IOperator {
|
|
|
55
55
|
export interface IOperatorSubgraph extends Omit<IOperator, 'jobTypes'> {
|
|
56
56
|
jobTypes?: string;
|
|
57
57
|
}
|
|
58
|
-
export interface IEscrowsFilter {
|
|
58
|
+
export interface IEscrowsFilter extends IPagination {
|
|
59
59
|
launcher?: string;
|
|
60
60
|
reputationOracle?: string;
|
|
61
61
|
recordingOracle?: string;
|
|
@@ -64,7 +64,7 @@ export interface IEscrowsFilter {
|
|
|
64
64
|
status?: EscrowStatus;
|
|
65
65
|
from?: Date;
|
|
66
66
|
to?: Date;
|
|
67
|
-
|
|
67
|
+
chainId: ChainId;
|
|
68
68
|
}
|
|
69
69
|
export interface IEscrowConfig {
|
|
70
70
|
recordingOracle: string;
|
|
@@ -87,10 +87,41 @@ export interface IStatisticsParams {
|
|
|
87
87
|
to?: Date;
|
|
88
88
|
limit?: number;
|
|
89
89
|
}
|
|
90
|
+
export interface IHMTHoldersParams {
|
|
91
|
+
address?: string;
|
|
92
|
+
orderDirection?: 'asc' | 'desc';
|
|
93
|
+
}
|
|
90
94
|
export interface IPayoutFilter {
|
|
91
95
|
escrowAddress?: string;
|
|
92
96
|
recipient?: string;
|
|
93
97
|
from?: Date;
|
|
94
98
|
to?: Date;
|
|
95
99
|
}
|
|
100
|
+
export interface IKVStore {
|
|
101
|
+
key: string;
|
|
102
|
+
value: string;
|
|
103
|
+
}
|
|
104
|
+
export interface ITransaction {
|
|
105
|
+
block: bigint;
|
|
106
|
+
txHash: string;
|
|
107
|
+
from: string;
|
|
108
|
+
to: string;
|
|
109
|
+
timestamp: bigint;
|
|
110
|
+
value: string;
|
|
111
|
+
method: string;
|
|
112
|
+
}
|
|
113
|
+
export interface ITransactionsFilter extends IPagination {
|
|
114
|
+
chainId: ChainId;
|
|
115
|
+
startBlock?: number;
|
|
116
|
+
endBlock?: number;
|
|
117
|
+
startDate?: Date;
|
|
118
|
+
endDate?: Date;
|
|
119
|
+
fromAddress?: string;
|
|
120
|
+
toAddress?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface IPagination {
|
|
123
|
+
first?: number;
|
|
124
|
+
skip?: number;
|
|
125
|
+
orderDirection?: OrderDirection;
|
|
126
|
+
}
|
|
96
127
|
//# sourceMappingURL=interfaces.d.ts.map
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,0BACf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC;IAC7C,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC"}
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ContractRunner, Overrides } from 'ethers';
|
|
2
2
|
import { BaseEthersClient } from './base';
|
|
3
|
+
import { ChainId } from './enums';
|
|
3
4
|
import { NetworkData } from './types';
|
|
5
|
+
import { IKVStore } from './interfaces';
|
|
4
6
|
/**
|
|
5
7
|
* ## Introduction
|
|
6
8
|
*
|
|
@@ -249,4 +251,86 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
249
251
|
*/
|
|
250
252
|
getPublicKey(address: string): Promise<string>;
|
|
251
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* ## Introduction
|
|
256
|
+
*
|
|
257
|
+
* Utility class for KVStore-related operations.
|
|
258
|
+
*
|
|
259
|
+
* ## Installation
|
|
260
|
+
*
|
|
261
|
+
* ### npm
|
|
262
|
+
* ```bash
|
|
263
|
+
* npm install @human-protocol/sdk
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* ### yarn
|
|
267
|
+
* ```bash
|
|
268
|
+
* yarn install @human-protocol/sdk
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* ## Code example
|
|
272
|
+
*
|
|
273
|
+
* ### Signer
|
|
274
|
+
*
|
|
275
|
+
* **Using private key (backend)**
|
|
276
|
+
*
|
|
277
|
+
* ```ts
|
|
278
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
279
|
+
*
|
|
280
|
+
* const KVStoreAddresses = new KVStoreUtils.getData({
|
|
281
|
+
* network: ChainId.POLYGON_AMOY
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
export declare class KVStoreUtils {
|
|
286
|
+
/**
|
|
287
|
+
* This function returns the KVStore data for a given address.
|
|
288
|
+
*
|
|
289
|
+
* > This uses Subgraph
|
|
290
|
+
*
|
|
291
|
+
* **Input parameters**
|
|
292
|
+
*
|
|
293
|
+
* ```ts
|
|
294
|
+
* enum ChainId {
|
|
295
|
+
* ALL = -1,
|
|
296
|
+
* MAINNET = 1,
|
|
297
|
+
* RINKEBY = 4,
|
|
298
|
+
* GOERLI = 5,
|
|
299
|
+
* BSC_MAINNET = 56,
|
|
300
|
+
* BSC_TESTNET = 97,
|
|
301
|
+
* POLYGON = 137,
|
|
302
|
+
* POLYGON_MUMBAI = 80001,
|
|
303
|
+
* POLYGON_AMOY = 80002,
|
|
304
|
+
* MOONBEAM = 1284,
|
|
305
|
+
* MOONBASE_ALPHA = 1287,
|
|
306
|
+
* AVALANCHE = 43114,
|
|
307
|
+
* AVALANCHE_TESTNET = 43113,
|
|
308
|
+
* CELO = 42220,
|
|
309
|
+
* CELO_ALFAJORES = 44787,
|
|
310
|
+
* LOCALHOST = 1338,
|
|
311
|
+
* }
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* interface IKVStore {
|
|
316
|
+
* key: string;
|
|
317
|
+
* value: string;
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
322
|
+
* @param {string} address Address of the KVStore
|
|
323
|
+
* @returns {Promise<IKVStore[]>} KVStore data
|
|
324
|
+
*
|
|
325
|
+
* **Code example**
|
|
326
|
+
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
329
|
+
*
|
|
330
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
331
|
+
* console.log(kvStoreData);
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
static getKVStoreData(chainId: ChainId, address: string): Promise<IKVStore[]>;
|
|
335
|
+
}
|
|
252
336
|
//# sourceMappingURL=kvstore.d.ts.map
|
package/dist/kvstore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAWlC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,OAAO,CAAC,QAAQ,CAAU;IAE1B;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAS5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc;IAiBhD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,GAAG,CACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAShB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEU,OAAO,CAClB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,iBAAiB,CAC5B,GAAG,EAAE,MAAM,EACX,MAAM,SAAQ,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAwBhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAa/D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,uBAAuB,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,SAAQ,GACb,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAc5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+CG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,QAAQ,EAAE,CAAC;CAwBvB"}
|
package/dist/kvstore.js
CHANGED
|
@@ -8,15 +8,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.KVStoreClient = void 0;
|
|
15
|
+
exports.KVStoreUtils = exports.KVStoreClient = void 0;
|
|
13
16
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
17
|
const ethers_1 = require("ethers");
|
|
15
18
|
const base_1 = require("./base");
|
|
16
19
|
const constants_1 = require("./constants");
|
|
17
20
|
const decorators_1 = require("./decorators");
|
|
18
21
|
const error_1 = require("./error");
|
|
22
|
+
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
19
23
|
const utils_1 = require("./utils");
|
|
24
|
+
const kvstore_1 = require("./graphql/queries/kvstore");
|
|
20
25
|
/**
|
|
21
26
|
* ## Introduction
|
|
22
27
|
*
|
|
@@ -383,3 +388,100 @@ __decorate([
|
|
|
383
388
|
__metadata("design:returntype", Promise)
|
|
384
389
|
], KVStoreClient.prototype, "setFileUrlAndHash", null);
|
|
385
390
|
exports.KVStoreClient = KVStoreClient;
|
|
391
|
+
/**
|
|
392
|
+
* ## Introduction
|
|
393
|
+
*
|
|
394
|
+
* Utility class for KVStore-related operations.
|
|
395
|
+
*
|
|
396
|
+
* ## Installation
|
|
397
|
+
*
|
|
398
|
+
* ### npm
|
|
399
|
+
* ```bash
|
|
400
|
+
* npm install @human-protocol/sdk
|
|
401
|
+
* ```
|
|
402
|
+
*
|
|
403
|
+
* ### yarn
|
|
404
|
+
* ```bash
|
|
405
|
+
* yarn install @human-protocol/sdk
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* ## Code example
|
|
409
|
+
*
|
|
410
|
+
* ### Signer
|
|
411
|
+
*
|
|
412
|
+
* **Using private key (backend)**
|
|
413
|
+
*
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
416
|
+
*
|
|
417
|
+
* const KVStoreAddresses = new KVStoreUtils.getData({
|
|
418
|
+
* network: ChainId.POLYGON_AMOY
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
class KVStoreUtils {
|
|
423
|
+
/**
|
|
424
|
+
* This function returns the KVStore data for a given address.
|
|
425
|
+
*
|
|
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
|
+
* @param {ChainId} chainId Network in which the KVStore is deployed
|
|
459
|
+
* @param {string} address Address of the KVStore
|
|
460
|
+
* @returns {Promise<IKVStore[]>} KVStore data
|
|
461
|
+
*
|
|
462
|
+
* **Code example**
|
|
463
|
+
*
|
|
464
|
+
* ```ts
|
|
465
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
466
|
+
*
|
|
467
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
468
|
+
* console.log(kvStoreData);
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
static async getKVStoreData(chainId, address) {
|
|
472
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
473
|
+
if (!networkData) {
|
|
474
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
475
|
+
}
|
|
476
|
+
if (address && !ethers_1.ethers.isAddress(address)) {
|
|
477
|
+
throw error_1.ErrorInvalidAddress;
|
|
478
|
+
}
|
|
479
|
+
const { kvstores } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, kvstore_1.GET_KVSTORE_BY_ADDRESS_QUERY)(), { address: address.toLowerCase() });
|
|
480
|
+
const kvStoreData = kvstores.map((item) => ({
|
|
481
|
+
key: item.key,
|
|
482
|
+
value: item.value,
|
|
483
|
+
}));
|
|
484
|
+
return kvStoreData || [];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exports.KVStoreUtils = KVStoreUtils;
|
package/dist/operator.d.ts
CHANGED
|
@@ -29,10 +29,13 @@ export declare class OperatorUtils {
|
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
31
31
|
*
|
|
32
|
-
* const
|
|
32
|
+
* const filter: ILeadersFilter = {
|
|
33
|
+
* chainId: ChainId.POLYGON
|
|
34
|
+
* };
|
|
35
|
+
* const leaders = await OperatorUtils.getLeaders(filter);
|
|
33
36
|
* ```
|
|
34
37
|
*/
|
|
35
|
-
static getLeaders(filter
|
|
38
|
+
static getLeaders(filter: ILeadersFilter): Promise<ILeader[]>;
|
|
36
39
|
/**
|
|
37
40
|
* Retrieves the reputation network operators of the specified address.
|
|
38
41
|
*
|
package/dist/operator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EAEP,cAAc,EACd,SAAS,EAET,OAAO,EACR,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EAEP,cAAc,EACd,SAAS,EAET,OAAO,EACR,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;IAkCnB;;;;;;;;;;;;;;;;;OAiBG;WACiB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAsC1E;;;;;;;;;;;;;OAaG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC;IA6BvB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC;CAuBtB"}
|
package/dist/operator.js
CHANGED
|
@@ -11,7 +11,6 @@ const operator_1 = require("./graphql/queries/operator");
|
|
|
11
11
|
const ethers_1 = require("ethers");
|
|
12
12
|
const error_1 = require("./error");
|
|
13
13
|
const utils_1 = require("./utils");
|
|
14
|
-
const enums_1 = require("./enums");
|
|
15
14
|
const constants_1 = require("./constants");
|
|
16
15
|
class OperatorUtils {
|
|
17
16
|
/**
|
|
@@ -37,18 +36,23 @@ class OperatorUtils {
|
|
|
37
36
|
if (!networkData) {
|
|
38
37
|
throw error_1.ErrorUnsupportedChainID;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
...leader,
|
|
46
|
-
jobTypes: leader.jobTypes?.split(','),
|
|
47
|
-
};
|
|
39
|
+
const { leader } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), operator_1.GET_LEADER_QUERY, {
|
|
40
|
+
address: address.toLowerCase(),
|
|
41
|
+
});
|
|
42
|
+
if (!leader) {
|
|
43
|
+
return leader || null;
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
let jobTypes = [];
|
|
46
|
+
if (typeof leader.jobTypes === 'string') {
|
|
47
|
+
jobTypes = leader.jobTypes.split(',');
|
|
51
48
|
}
|
|
49
|
+
else if (Array.isArray(leader.jobTypes)) {
|
|
50
|
+
jobTypes = leader.jobTypes;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...leader,
|
|
54
|
+
jobTypes,
|
|
55
|
+
};
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* This function returns all the leader details of the protocol.
|
|
@@ -62,30 +66,38 @@ class OperatorUtils {
|
|
|
62
66
|
* ```ts
|
|
63
67
|
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
64
68
|
*
|
|
65
|
-
* const
|
|
69
|
+
* const filter: ILeadersFilter = {
|
|
70
|
+
* chainId: ChainId.POLYGON
|
|
71
|
+
* };
|
|
72
|
+
* const leaders = await OperatorUtils.getLeaders(filter);
|
|
66
73
|
* ```
|
|
67
74
|
*/
|
|
68
|
-
static async getLeaders(filter
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!networkData) {
|
|
74
|
-
throw error_1.ErrorUnsupportedChainID;
|
|
75
|
-
}
|
|
76
|
-
const { leaders } = await (0, graphql_request_1.default)(networkData.subgraphUrl, (0, operator_1.GET_LEADERS_QUERY)(filter), {
|
|
77
|
-
role: filter.role,
|
|
78
|
-
});
|
|
79
|
-
leaders_data = leaders_data.concat(leaders.map((leader) => ({
|
|
80
|
-
...leader,
|
|
81
|
-
jobTypes: leader.jobTypes?.split(','),
|
|
82
|
-
})));
|
|
83
|
-
}
|
|
84
|
-
return leaders_data;
|
|
75
|
+
static async getLeaders(filter) {
|
|
76
|
+
let leaders_data = [];
|
|
77
|
+
const networkData = constants_1.NETWORKS[filter.chainId];
|
|
78
|
+
if (!networkData) {
|
|
79
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
85
80
|
}
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const { leaders } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, operator_1.GET_LEADERS_QUERY)(filter), {
|
|
82
|
+
role: filter?.role,
|
|
83
|
+
});
|
|
84
|
+
if (!leaders) {
|
|
85
|
+
return [];
|
|
88
86
|
}
|
|
87
|
+
leaders_data = leaders_data.concat(leaders.map((leader) => {
|
|
88
|
+
let jobTypes = [];
|
|
89
|
+
if (typeof leader.jobTypes === 'string') {
|
|
90
|
+
jobTypes = leader.jobTypes.split(',');
|
|
91
|
+
}
|
|
92
|
+
else if (Array.isArray(leader.jobTypes)) {
|
|
93
|
+
jobTypes = leader.jobTypes;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...leader,
|
|
97
|
+
jobTypes,
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
return leaders_data;
|
|
89
101
|
}
|
|
90
102
|
/**
|
|
91
103
|
* Retrieves the reputation network operators of the specified address.
|
|
@@ -106,19 +118,23 @@ class OperatorUtils {
|
|
|
106
118
|
if (!networkData) {
|
|
107
119
|
throw error_1.ErrorUnsupportedChainID;
|
|
108
120
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
const { reputationNetwork } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, operator_1.GET_REPUTATION_NETWORK_QUERY)(role), {
|
|
122
|
+
address: address.toLowerCase(),
|
|
123
|
+
role: role,
|
|
124
|
+
});
|
|
125
|
+
return reputationNetwork.operators.map((operator) => {
|
|
126
|
+
let jobTypes = [];
|
|
127
|
+
if (typeof operator.jobTypes === 'string') {
|
|
128
|
+
jobTypes = operator.jobTypes.split(',');
|
|
129
|
+
}
|
|
130
|
+
else if (Array.isArray(operator.jobTypes)) {
|
|
131
|
+
jobTypes = operator.jobTypes;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
115
134
|
...operator,
|
|
116
|
-
jobTypes
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
return (0, utils_1.throwError)(e);
|
|
121
|
-
}
|
|
135
|
+
jobTypes,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
122
138
|
}
|
|
123
139
|
/**
|
|
124
140
|
* This function returns information about the rewards for a given slasher address.
|
|
@@ -143,20 +159,15 @@ class OperatorUtils {
|
|
|
143
159
|
if (!networkData) {
|
|
144
160
|
throw error_1.ErrorUnsupportedChainID;
|
|
145
161
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
return (0, utils_1.throwError)(e);
|
|
159
|
-
}
|
|
162
|
+
const { rewardAddedEvents } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
163
|
+
slasherAddress: slasherAddress.toLowerCase(),
|
|
164
|
+
});
|
|
165
|
+
return rewardAddedEvents.map((reward) => {
|
|
166
|
+
return {
|
|
167
|
+
escrowAddress: reward.escrow,
|
|
168
|
+
amount: reward.amount,
|
|
169
|
+
};
|
|
170
|
+
});
|
|
160
171
|
}
|
|
161
172
|
}
|
|
162
173
|
exports.OperatorUtils = OperatorUtils;
|
package/dist/statistics.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EscrowStatistics, HMTStatistics, PaymentStatistics, WorkerStatistics } from './graphql';
|
|
2
|
-
import { IStatisticsParams } from './interfaces';
|
|
1
|
+
import { EscrowStatistics, HMTStatistics, PaymentStatistics, WorkerStatistics, HMTHolder } from './graphql';
|
|
2
|
+
import { IHMTHoldersParams, IStatisticsParams } from './interfaces';
|
|
3
3
|
import { NetworkData } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* ## Introduction
|
|
@@ -40,6 +40,7 @@ import { NetworkData } from './types';
|
|
|
40
40
|
*/
|
|
41
41
|
export declare class StatisticsClient {
|
|
42
42
|
networkData: NetworkData;
|
|
43
|
+
subgraphUrl: string;
|
|
43
44
|
/**
|
|
44
45
|
* **StatisticsClient constructor**
|
|
45
46
|
*
|
|
@@ -291,5 +292,31 @@ export declare class StatisticsClient {
|
|
|
291
292
|
* ```
|
|
292
293
|
*/
|
|
293
294
|
getHMTStatistics(params?: IStatisticsParams): Promise<HMTStatistics>;
|
|
295
|
+
/**
|
|
296
|
+
* This function returns the holders of the HMToken with optional filters and ordering.
|
|
297
|
+
*
|
|
298
|
+
* **Input parameters**
|
|
299
|
+
*
|
|
300
|
+
* @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
|
|
301
|
+
* @returns {HMTHolder[]} List of HMToken holders.
|
|
302
|
+
*
|
|
303
|
+
* **Code example**
|
|
304
|
+
*
|
|
305
|
+
* ```ts
|
|
306
|
+
* import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
307
|
+
*
|
|
308
|
+
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
309
|
+
*
|
|
310
|
+
* const hmtHolders = await statisticsClient.getHMTHolders({
|
|
311
|
+
* orderDirection: 'asc',
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* console.log('HMT holders:', hmtHolders.map((h) => ({
|
|
315
|
+
* ...h,
|
|
316
|
+
* balance: h.balance.toString(),
|
|
317
|
+
* })));
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
getHMTHolders(params?: IHMTHoldersParams): Promise<HMTHolder[]>;
|
|
294
321
|
}
|
|
295
322
|
//# 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,
|
|
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,EACV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,gBAAgB;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;gBACS,WAAW,EAAE,WAAW;IAKpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA6B5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAoB5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkEG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IA0B7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgFG;IACG,gBAAgB,CACpB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC;IA0CzB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,aAAa,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAuB1E"}
|
package/dist/statistics.js
CHANGED
|
@@ -54,6 +54,7 @@ class StatisticsClient {
|
|
|
54
54
|
*/
|
|
55
55
|
constructor(networkData) {
|
|
56
56
|
this.networkData = networkData;
|
|
57
|
+
this.subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* This function returns the statistical data of escrows.
|
|
@@ -106,8 +107,8 @@ class StatisticsClient {
|
|
|
106
107
|
*/
|
|
107
108
|
async getEscrowStatistics(params = {}) {
|
|
108
109
|
try {
|
|
109
|
-
const { escrowStatistics } = await (0, graphql_request_1.default)(this.
|
|
110
|
-
const { eventDayDatas } = await (0, graphql_request_1.default)(this.
|
|
110
|
+
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)(params), {
|
|
111
112
|
from: params.from ? params.from.getTime() / 1000 : undefined,
|
|
112
113
|
to: params.to ? params.to.getTime() / 1000 : undefined,
|
|
113
114
|
});
|
|
@@ -173,7 +174,7 @@ class StatisticsClient {
|
|
|
173
174
|
*/
|
|
174
175
|
async getWorkerStatistics(params = {}) {
|
|
175
176
|
try {
|
|
176
|
-
const { eventDayDatas } = await (0, graphql_request_1.default)(this.
|
|
177
|
+
const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
|
|
177
178
|
from: params.from ? params.from.getTime() / 1000 : undefined,
|
|
178
179
|
to: params.to ? params.to.getTime() / 1000 : undefined,
|
|
179
180
|
});
|
|
@@ -257,7 +258,7 @@ class StatisticsClient {
|
|
|
257
258
|
*/
|
|
258
259
|
async getPaymentStatistics(params = {}) {
|
|
259
260
|
try {
|
|
260
|
-
const { eventDayDatas } = await (0, graphql_request_1.default)(this.
|
|
261
|
+
const { eventDayDatas } = await (0, graphql_request_1.default)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
|
|
261
262
|
from: params.from ? params.from.getTime() / 1000 : undefined,
|
|
262
263
|
to: params.to ? params.to.getTime() / 1000 : undefined,
|
|
263
264
|
});
|
|
@@ -360,9 +361,9 @@ class StatisticsClient {
|
|
|
360
361
|
*/
|
|
361
362
|
async getHMTStatistics(params = {}) {
|
|
362
363
|
try {
|
|
363
|
-
const { hmtokenStatistics } = await (0, graphql_request_1.default)(this.
|
|
364
|
-
const { holders } = await (0, graphql_request_1.default)(this.
|
|
365
|
-
const { eventDayDatas } = await (0, graphql_request_1.default)(this.
|
|
364
|
+
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), {
|
|
366
367
|
from: params.from ? params.from.getTime() / 1000 : undefined,
|
|
367
368
|
to: params.to ? params.to.getTime() / 1000 : undefined,
|
|
368
369
|
});
|
|
@@ -378,6 +379,8 @@ class StatisticsClient {
|
|
|
378
379
|
timestamp: new Date(+eventDayData.timestamp * 1000),
|
|
379
380
|
totalTransactionAmount: ethers_1.ethers.toBigInt(eventDayData.dailyHMTTransferAmount),
|
|
380
381
|
totalTransactionCount: +eventDayData.dailyHMTTransferCount,
|
|
382
|
+
dailyUniqueSenders: +eventDayData.dailyUniqueSenders,
|
|
383
|
+
dailyUniqueReceivers: +eventDayData.dailyUniqueReceivers,
|
|
381
384
|
})),
|
|
382
385
|
};
|
|
383
386
|
}
|
|
@@ -385,5 +388,48 @@ class StatisticsClient {
|
|
|
385
388
|
return (0, utils_1.throwError)(e);
|
|
386
389
|
}
|
|
387
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* This function returns the holders of the HMToken with optional filters and ordering.
|
|
393
|
+
*
|
|
394
|
+
* **Input parameters**
|
|
395
|
+
*
|
|
396
|
+
* @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
|
|
397
|
+
* @returns {HMTHolder[]} List of HMToken holders.
|
|
398
|
+
*
|
|
399
|
+
* **Code example**
|
|
400
|
+
*
|
|
401
|
+
* ```ts
|
|
402
|
+
* import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
403
|
+
*
|
|
404
|
+
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
405
|
+
*
|
|
406
|
+
* const hmtHolders = await statisticsClient.getHMTHolders({
|
|
407
|
+
* orderDirection: 'asc',
|
|
408
|
+
* });
|
|
409
|
+
*
|
|
410
|
+
* console.log('HMT holders:', hmtHolders.map((h) => ({
|
|
411
|
+
* ...h,
|
|
412
|
+
* balance: h.balance.toString(),
|
|
413
|
+
* })));
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
async getHMTHolders(params = {}) {
|
|
417
|
+
try {
|
|
418
|
+
const { address, orderDirection } = params;
|
|
419
|
+
const query = (0, graphql_1.GET_HOLDERS_QUERY)(address);
|
|
420
|
+
const { holders } = await (0, graphql_request_1.default)(this.subgraphUrl, query, {
|
|
421
|
+
address,
|
|
422
|
+
orderBy: 'balance',
|
|
423
|
+
orderDirection,
|
|
424
|
+
});
|
|
425
|
+
return holders.map((holder) => ({
|
|
426
|
+
address: holder.address,
|
|
427
|
+
balance: ethers_1.ethers.toBigInt(holder.balance),
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
catch (e) {
|
|
431
|
+
return (0, utils_1.throwError)(e);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
388
434
|
}
|
|
389
435
|
exports.StatisticsClient = StatisticsClient;
|