@human-protocol/sdk 2.1.2 → 3.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/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +68 -23
- package/dist/enums.d.ts +4 -2
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +3 -1
- package/dist/error.d.ts +9 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +11 -2
- package/dist/escrow.d.ts +1 -2
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +4 -5
- 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/transaction.d.ts +4 -0
- package/dist/graphql/queries/transaction.d.ts.map +1 -0
- package/dist/graphql/queries/transaction.js +59 -0
- package/dist/graphql/types.d.ts +8 -0
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/interfaces.d.ts +33 -1
- 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 +54 -17
- package/dist/statistics.d.ts +1 -0
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +8 -7
- package/dist/transaction.d.ts +69 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +121 -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 +4 -4
- package/src/constants.ts +86 -22
- package/src/enums.ts +3 -1
- package/src/error.ts +15 -0
- package/src/escrow.ts +5 -6
- package/src/graphql/queries/kvstore.ts +23 -0
- package/src/graphql/queries/transaction.ts +59 -0
- package/src/graphql/types.ts +9 -0
- package/src/interfaces.ts +40 -1
- package/src/kvstore.ts +114 -1
- package/src/operator.ts +69 -24
- package/src/statistics.ts +10 -8
- package/src/transaction.ts +142 -0
- package/src/types.ts +4 -0
- package/src/utils.ts +25 -0
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;AAElC,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;
|
|
1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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,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,IAAI,EAAE,MAAM,CAAC;IACb,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,mBAAmB;IAClC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,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"}
|
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
|
+
* networks: [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
|
+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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
|
+
* networks: [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,
|
|
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;IA0C1E;;;;;;;;;;;;;OAaG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC;IAiCvB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC;CA2BtB"}
|
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
|
/**
|
|
@@ -38,10 +37,20 @@ class OperatorUtils {
|
|
|
38
37
|
throw error_1.ErrorUnsupportedChainID;
|
|
39
38
|
}
|
|
40
39
|
try {
|
|
41
|
-
const { leader } = await (0, graphql_request_1.default)(networkData
|
|
40
|
+
const { leader } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), operator_1.GET_LEADER_QUERY, {
|
|
42
41
|
address: address.toLowerCase(),
|
|
43
42
|
});
|
|
44
|
-
|
|
43
|
+
let jobTypes = [];
|
|
44
|
+
if (typeof leader.jobTypes === 'string') {
|
|
45
|
+
jobTypes = leader.jobTypes.split(',');
|
|
46
|
+
}
|
|
47
|
+
else if (Array.isArray(leader.jobTypes)) {
|
|
48
|
+
jobTypes = leader.jobTypes;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...leader,
|
|
52
|
+
jobTypes,
|
|
53
|
+
};
|
|
45
54
|
}
|
|
46
55
|
catch (e) {
|
|
47
56
|
return (0, utils_1.throwError)(e);
|
|
@@ -59,22 +68,38 @@ class OperatorUtils {
|
|
|
59
68
|
* ```ts
|
|
60
69
|
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
61
70
|
*
|
|
62
|
-
* const
|
|
71
|
+
* const filter: ILeadersFilter = {
|
|
72
|
+
* chainId: ChainId.POLYGON
|
|
73
|
+
* };
|
|
74
|
+
* const leaders = await OperatorUtils.getLeaders(filter);
|
|
63
75
|
* ```
|
|
64
76
|
*/
|
|
65
|
-
static async getLeaders(filter
|
|
77
|
+
static async getLeaders(filter) {
|
|
66
78
|
try {
|
|
67
79
|
let leaders_data = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw error_1.ErrorUnsupportedChainID;
|
|
72
|
-
}
|
|
73
|
-
const { leaders } = await (0, graphql_request_1.default)(networkData.subgraphUrl, (0, operator_1.GET_LEADERS_QUERY)(filter), {
|
|
74
|
-
role: filter.role,
|
|
75
|
-
});
|
|
76
|
-
leaders_data = leaders_data.concat(leaders);
|
|
80
|
+
const networkData = constants_1.NETWORKS[filter.chainId];
|
|
81
|
+
if (!networkData) {
|
|
82
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
77
83
|
}
|
|
84
|
+
const { leaders } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, operator_1.GET_LEADERS_QUERY)(filter), {
|
|
85
|
+
role: filter?.role,
|
|
86
|
+
});
|
|
87
|
+
if (!leaders) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
leaders_data = leaders_data.concat(leaders.map((leader) => {
|
|
91
|
+
let jobTypes = [];
|
|
92
|
+
if (typeof leader.jobTypes === 'string') {
|
|
93
|
+
jobTypes = leader.jobTypes.split(',');
|
|
94
|
+
}
|
|
95
|
+
else if (Array.isArray(leader.jobTypes)) {
|
|
96
|
+
jobTypes = leader.jobTypes;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...leader,
|
|
100
|
+
jobTypes,
|
|
101
|
+
};
|
|
102
|
+
}));
|
|
78
103
|
return leaders_data;
|
|
79
104
|
}
|
|
80
105
|
catch (e) {
|
|
@@ -101,11 +126,23 @@ class OperatorUtils {
|
|
|
101
126
|
throw error_1.ErrorUnsupportedChainID;
|
|
102
127
|
}
|
|
103
128
|
try {
|
|
104
|
-
const { reputationNetwork } = await (0, graphql_request_1.default)(networkData
|
|
129
|
+
const { reputationNetwork } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, operator_1.GET_REPUTATION_NETWORK_QUERY)(role), {
|
|
105
130
|
address: address.toLowerCase(),
|
|
106
131
|
role: role,
|
|
107
132
|
});
|
|
108
|
-
return reputationNetwork.operators
|
|
133
|
+
return reputationNetwork.operators.map((operator) => {
|
|
134
|
+
let jobTypes = [];
|
|
135
|
+
if (typeof operator.jobTypes === 'string') {
|
|
136
|
+
jobTypes = operator.jobTypes.split(',');
|
|
137
|
+
}
|
|
138
|
+
else if (Array.isArray(operator.jobTypes)) {
|
|
139
|
+
jobTypes = operator.jobTypes;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
...operator,
|
|
143
|
+
jobTypes,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
109
146
|
}
|
|
110
147
|
catch (e) {
|
|
111
148
|
return (0, utils_1.throwError)(e);
|
|
@@ -135,7 +172,7 @@ class OperatorUtils {
|
|
|
135
172
|
throw error_1.ErrorUnsupportedChainID;
|
|
136
173
|
}
|
|
137
174
|
try {
|
|
138
|
-
const { rewardAddedEvents } = await (0, graphql_request_1.default)(networkData
|
|
175
|
+
const { rewardAddedEvents } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
139
176
|
slasherAddress: slasherAddress.toLowerCase(),
|
|
140
177
|
});
|
|
141
178
|
return rewardAddedEvents.map((reward) => {
|
package/dist/statistics.d.ts
CHANGED
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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgFG;IACG,gBAAgB,CACpB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC;CAuC1B"}
|
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, 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
|
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ChainId } from './enums';
|
|
2
|
+
import { ITransaction, ITransactionsFilter } from './interfaces';
|
|
3
|
+
export declare class TransactionUtils {
|
|
4
|
+
/**
|
|
5
|
+
* This function returns the transaction data for the given hash.
|
|
6
|
+
*
|
|
7
|
+
* @param {ChainId} chainId The chain ID.
|
|
8
|
+
* @param {string} hash The transaction hash.
|
|
9
|
+
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
10
|
+
*
|
|
11
|
+
* **Code example**
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
15
|
+
*
|
|
16
|
+
* const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
static getTransaction(chainId: ChainId, hash: string): Promise<ITransaction>;
|
|
20
|
+
/**
|
|
21
|
+
* This function returns all transaction details based on the provided filter.
|
|
22
|
+
*
|
|
23
|
+
* > This uses Subgraph
|
|
24
|
+
*
|
|
25
|
+
* **Input parameters**
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* interface ITransactionsFilter {
|
|
29
|
+
* networks: ChainId[]; // List of chain IDs to query.
|
|
30
|
+
* fromAddress?: string; // (Optional) The address from which transactions are sent.
|
|
31
|
+
* toAddress?: string; // (Optional) The address to which transactions are sent.
|
|
32
|
+
* startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
|
|
33
|
+
* endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
|
|
34
|
+
* startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
|
|
35
|
+
* endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* type ITransaction = {
|
|
41
|
+
* block: number;
|
|
42
|
+
* txHash: string;
|
|
43
|
+
* from: string;
|
|
44
|
+
* to: string;
|
|
45
|
+
* timestamp: number;
|
|
46
|
+
* value: string;
|
|
47
|
+
* method: string;
|
|
48
|
+
* };
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param {ITransactionsFilter} filter Filter for the transactions.
|
|
52
|
+
* @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
|
|
53
|
+
*
|
|
54
|
+
* **Code example**
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
58
|
+
*
|
|
59
|
+
* const filter: ITransactionsFilter = {
|
|
60
|
+
* networks: [ChainId.POLYGON],
|
|
61
|
+
* startDate: new Date('2022-01-01'),
|
|
62
|
+
* endDate: new Date('2022-12-31')
|
|
63
|
+
* };
|
|
64
|
+
* const transactions = await TransactionUtils.getTransactions(filter);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static getTransactions(filter: ITransactionsFilter): Promise<ITransaction[]>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAUlC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjE,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC;IAmBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,EAAE,CAAC;CAqC3B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TransactionUtils = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const error_1 = require("./error");
|
|
12
|
+
const transaction_1 = require("./graphql/queries/transaction");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class TransactionUtils {
|
|
15
|
+
/**
|
|
16
|
+
* This function returns the transaction data for the given hash.
|
|
17
|
+
*
|
|
18
|
+
* @param {ChainId} chainId The chain ID.
|
|
19
|
+
* @param {string} hash The transaction hash.
|
|
20
|
+
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
21
|
+
*
|
|
22
|
+
* **Code example**
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
26
|
+
*
|
|
27
|
+
* const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
static async getTransaction(chainId, hash) {
|
|
31
|
+
if (!ethers_1.ethers.isHexString(hash)) {
|
|
32
|
+
throw error_1.ErrorInvalidHahsProvided;
|
|
33
|
+
}
|
|
34
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
35
|
+
if (!networkData) {
|
|
36
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
37
|
+
}
|
|
38
|
+
const { transaction } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), transaction_1.GET_TRANSACTION_QUERY, {
|
|
39
|
+
hash: hash.toLowerCase(),
|
|
40
|
+
});
|
|
41
|
+
return transaction;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This function returns all transaction details based on the provided filter.
|
|
45
|
+
*
|
|
46
|
+
* > This uses Subgraph
|
|
47
|
+
*
|
|
48
|
+
* **Input parameters**
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* interface ITransactionsFilter {
|
|
52
|
+
* networks: ChainId[]; // List of chain IDs to query.
|
|
53
|
+
* fromAddress?: string; // (Optional) The address from which transactions are sent.
|
|
54
|
+
* toAddress?: string; // (Optional) The address to which transactions are sent.
|
|
55
|
+
* startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
|
|
56
|
+
* endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
|
|
57
|
+
* startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
|
|
58
|
+
* endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* type ITransaction = {
|
|
64
|
+
* block: number;
|
|
65
|
+
* txHash: string;
|
|
66
|
+
* from: string;
|
|
67
|
+
* to: string;
|
|
68
|
+
* timestamp: number;
|
|
69
|
+
* value: string;
|
|
70
|
+
* method: string;
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param {ITransactionsFilter} filter Filter for the transactions.
|
|
75
|
+
* @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
|
|
76
|
+
*
|
|
77
|
+
* **Code example**
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
81
|
+
*
|
|
82
|
+
* const filter: ITransactionsFilter = {
|
|
83
|
+
* networks: [ChainId.POLYGON],
|
|
84
|
+
* startDate: new Date('2022-01-01'),
|
|
85
|
+
* endDate: new Date('2022-12-31')
|
|
86
|
+
* };
|
|
87
|
+
* const transactions = await TransactionUtils.getTransactions(filter);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
static async getTransactions(filter) {
|
|
91
|
+
if ((!!filter.startDate || !!filter.endDate) &&
|
|
92
|
+
(!!filter.startBlock || !!filter.endBlock)) {
|
|
93
|
+
throw error_1.ErrorCannotUseDateAndBlockSimultaneously;
|
|
94
|
+
}
|
|
95
|
+
const transactions_data = [];
|
|
96
|
+
for (const chainId of filter.networks) {
|
|
97
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
98
|
+
if (!networkData) {
|
|
99
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
100
|
+
}
|
|
101
|
+
const { transactions } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, transaction_1.GET_TRANSACTIONS_QUERY)(filter), {
|
|
102
|
+
fromAddress: filter?.fromAddress,
|
|
103
|
+
toAddress: filter?.toAddress,
|
|
104
|
+
startDate: filter?.startDate
|
|
105
|
+
? Math.floor(filter?.startDate.getTime() / 1000)
|
|
106
|
+
: undefined,
|
|
107
|
+
endDate: filter.endDate
|
|
108
|
+
? Math.floor(filter.endDate.getTime() / 1000)
|
|
109
|
+
: undefined,
|
|
110
|
+
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
111
|
+
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
112
|
+
});
|
|
113
|
+
if (!transactions) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
transactions_data.push(...transactions);
|
|
117
|
+
}
|
|
118
|
+
return transactions_data;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.TransactionUtils = TransactionUtils;
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;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;CACV;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;I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