@human-protocol/sdk 1.1.9 → 1.1.11

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.
Files changed (41) hide show
  1. package/dist/constants.js +8 -8
  2. package/dist/escrow.d.ts +12 -12
  3. package/dist/escrow.d.ts.map +1 -1
  4. package/dist/escrow.js +42 -30
  5. package/dist/graphql/queries/escrow.d.ts +2 -2
  6. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  7. package/dist/graphql/queries/escrow.js +30 -26
  8. package/dist/graphql/queries/hmtoken.d.ts +2 -0
  9. package/dist/graphql/queries/hmtoken.d.ts.map +1 -0
  10. package/dist/graphql/queries/hmtoken.js +21 -0
  11. package/dist/graphql/queries/index.d.ts +2 -0
  12. package/dist/graphql/queries/index.d.ts.map +1 -1
  13. package/dist/graphql/queries/index.js +2 -0
  14. package/dist/graphql/queries/statistics.d.ts +5 -0
  15. package/dist/graphql/queries/statistics.d.ts.map +1 -0
  16. package/dist/graphql/queries/statistics.js +87 -0
  17. package/dist/graphql/types.d.ts +91 -0
  18. package/dist/graphql/types.d.ts.map +1 -1
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3 -1
  22. package/dist/interfaces.d.ts +9 -3
  23. package/dist/interfaces.d.ts.map +1 -1
  24. package/dist/statistics.d.ts +45 -0
  25. package/dist/statistics.d.ts.map +1 -0
  26. package/dist/statistics.js +144 -0
  27. package/dist/storage.d.ts +2 -2
  28. package/dist/storage.d.ts.map +1 -1
  29. package/dist/storage.js +4 -4
  30. package/package.json +1 -1
  31. package/src/constants.ts +8 -8
  32. package/src/escrow.ts +51 -36
  33. package/src/graphql/queries/escrow.ts +31 -25
  34. package/src/graphql/queries/hmtoken.ts +17 -0
  35. package/src/graphql/queries/index.ts +2 -0
  36. package/src/graphql/queries/statistics.ts +88 -0
  37. package/src/graphql/types.ts +105 -0
  38. package/src/index.ts +8 -1
  39. package/src/interfaces.ts +16 -3
  40. package/src/statistics.ts +196 -0
  41. package/src/storage.ts +4 -4
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
17
+ exports.StatisticsClient = exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
18
18
  const staking_1 = require("./staking");
19
19
  Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
20
20
  const storage_1 = require("./storage");
@@ -23,6 +23,8 @@ const kvstore_1 = require("./kvstore");
23
23
  Object.defineProperty(exports, "KVStoreClient", { enumerable: true, get: function () { return kvstore_1.KVStoreClient; } });
24
24
  const escrow_1 = require("./escrow");
25
25
  Object.defineProperty(exports, "EscrowClient", { enumerable: true, get: function () { return escrow_1.EscrowClient; } });
26
+ const statistics_1 = require("./statistics");
27
+ Object.defineProperty(exports, "StatisticsClient", { enumerable: true, get: function () { return statistics_1.StatisticsClient; } });
26
28
  __exportStar(require("./constants"), exports);
27
29
  __exportStar(require("./types"), exports);
28
30
  __exportStar(require("./enums"), exports);
@@ -1,5 +1,4 @@
1
1
  import { BigNumber } from 'ethers';
2
- import { EscrowStatus } from './types';
3
2
  export interface IAllocation {
4
3
  escrowAddress: string;
5
4
  staker: string;
@@ -19,9 +18,11 @@ export interface IStaker {
19
18
  tokensLockedUntil: BigNumber;
20
19
  tokensAvailable: BigNumber;
21
20
  }
21
+ type EscrowStatus = 'Launched' | 'Pending' | 'Partial' | 'Paid' | 'Complete' | 'Cancelled';
22
22
  export interface IEscrowsFilter {
23
- launcherAddress?: string;
24
- role?: number;
23
+ launcher?: string;
24
+ reputationOracle?: string;
25
+ recordingOracle?: string;
25
26
  status?: EscrowStatus;
26
27
  from?: Date;
27
28
  to?: Date;
@@ -40,4 +41,9 @@ export interface IKeyPair {
40
41
  passphrase: string;
41
42
  revocationCertificate?: string;
42
43
  }
44
+ export interface IStatisticsParams {
45
+ from?: Date;
46
+ to?: Date;
47
+ }
48
+ export {};
43
49
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,SAAS,CAAC;IACxB,eAAe,EAAE,SAAS,CAAC;IAC3B,YAAY,EAAE,SAAS,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,SAAS,CAAC;IAC9B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,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"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,SAAS,CAAC;IACxB,eAAe,EAAE,SAAS,CAAC;IAC3B,YAAY,EAAE,SAAS,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,KAAK,YAAY,GACb,UAAU,GACV,SAAS,GACT,SAAS,GACT,MAAM,GACN,UAAU,GACV,WAAW,CAAC;AAEhB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,SAAS,CAAC;IAC9B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,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;CACX"}
@@ -0,0 +1,45 @@
1
+ import { EscrowStatistics, HMTStatistics, PaymentStatistics, WorkerStatistics } from './graphql';
2
+ import { IStatisticsParams } from './interfaces';
3
+ import { NetworkData } from './types';
4
+ export declare class StatisticsClient {
5
+ network: NetworkData;
6
+ /**
7
+ * **StatisticsClient constructor**
8
+ *
9
+ * @param {NetworkData} network - The network information required to connect to the Statistics contract
10
+ */
11
+ constructor(network: NetworkData);
12
+ /**
13
+ * Returns the escrow statistics data for the given date range
14
+ *
15
+ * @param {IStatisticsParams} params - Filter parameters.
16
+ * @returns {Promise<EscrowStatistics>}
17
+ * @throws {Error} - An error object if an error occurred.
18
+ */
19
+ getEscrowStatistics(params?: IStatisticsParams): Promise<EscrowStatistics>;
20
+ /**
21
+ * Returns the worker statistics data for the given date range
22
+ *
23
+ * @param {IStatisticsParams} params - Filter parameters.
24
+ * @returns {Promise<WorkerStatistics>}
25
+ * @throws {Error} - An error object if an error occurred.
26
+ */
27
+ getWorkerStatistics(params?: IStatisticsParams): Promise<WorkerStatistics>;
28
+ /**
29
+ * Returns the payment statistics data for the given date range
30
+ *
31
+ * @param {IStatisticsParams} params - Filter parameters.
32
+ * @returns {Promise<PaymentStatistics>}
33
+ * @throws {Error} - An error object if an error occurred.
34
+ */
35
+ getPaymentStatistics(params?: IStatisticsParams): Promise<PaymentStatistics>;
36
+ /**
37
+ * Returns the HMToken statistics data for the given date range
38
+ *
39
+ * @param {IStatisticsParams} params - Filter parameters.
40
+ * @returns {Promise<HMTStatistics>}
41
+ * @throws {Error} - An error object if an error occurred.
42
+ */
43
+ getHMTStatistics(params?: IStatisticsParams): Promise<HMTStatistics>;
44
+ }
45
+ //# sourceMappingURL=statistics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,gBAAgB,EAGhB,aAAa,EAEb,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC,qBAAa,gBAAgB;IACpB,OAAO,EAAE,WAAW,CAAC;IAE5B;;;;OAIG;gBACS,OAAO,EAAE,WAAW;IAIhC;;;;;;OAMG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA6B5B;;;;;;OAMG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAyB5B;;;;;;OAMG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAiC7B;;;;;;OAMG;IACG,gBAAgB,CACpB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC;CAsC1B"}
@@ -0,0 +1,144 @@
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.StatisticsClient = void 0;
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ const graphql_request_1 = __importDefault(require("graphql-request"));
9
+ const graphql_1 = require("./graphql");
10
+ const utils_1 = require("./utils");
11
+ const ethers_1 = require("ethers");
12
+ class StatisticsClient {
13
+ /**
14
+ * **StatisticsClient constructor**
15
+ *
16
+ * @param {NetworkData} network - The network information required to connect to the Statistics contract
17
+ */
18
+ constructor(network) {
19
+ this.network = network;
20
+ }
21
+ /**
22
+ * Returns the escrow statistics data for the given date range
23
+ *
24
+ * @param {IStatisticsParams} params - Filter parameters.
25
+ * @returns {Promise<EscrowStatistics>}
26
+ * @throws {Error} - An error object if an error occurred.
27
+ */
28
+ async getEscrowStatistics(params = {}) {
29
+ try {
30
+ const { escrowStatistics } = await (0, graphql_request_1.default)(this.network.subgraphUrl, graphql_1.GET_ESCROW_STATISTICS_QUERY);
31
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.network.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
32
+ from: params.from ? params.from.getTime() / 1000 : undefined,
33
+ to: params.to ? params.to.getTime() / 1000 : undefined,
34
+ });
35
+ return {
36
+ totalEscrows: +escrowStatistics.totalEscrowCount,
37
+ dailyEscrowsData: eventDayDatas.map((eventDayData) => ({
38
+ timestamp: new Date(+eventDayData.timestamp * 1000),
39
+ escrowsTotal: +eventDayData.dailyEscrowCount,
40
+ escrowsPending: +eventDayData.dailyPendingStatusEventCount,
41
+ escrowsSolved: +eventDayData.dailyCompletedStatusEventCount,
42
+ escrowsPaid: +eventDayData.dailyPaidStatusEventCount,
43
+ escrowsCancelled: +eventDayData.dailyCancelledStatusEventCount,
44
+ })),
45
+ };
46
+ }
47
+ catch (e) {
48
+ return (0, utils_1.throwError)(e);
49
+ }
50
+ }
51
+ /**
52
+ * Returns the worker statistics data for the given date range
53
+ *
54
+ * @param {IStatisticsParams} params - Filter parameters.
55
+ * @returns {Promise<WorkerStatistics>}
56
+ * @throws {Error} - An error object if an error occurred.
57
+ */
58
+ async getWorkerStatistics(params = {}) {
59
+ try {
60
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.network.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
61
+ from: params.from ? params.from.getTime() / 1000 : undefined,
62
+ to: params.to ? params.to.getTime() / 1000 : undefined,
63
+ });
64
+ return {
65
+ dailyWorkersData: eventDayDatas.map((eventDayData) => ({
66
+ timestamp: new Date(+eventDayData.timestamp * 1000),
67
+ activeWorkers: +eventDayData.dailyWorkerCount,
68
+ averageJobsSolved: eventDayData.dailyWorkerCount === '0'
69
+ ? 0
70
+ : +eventDayData.dailyBulkPayoutEventCount /
71
+ +eventDayData.dailyWorkerCount,
72
+ })),
73
+ };
74
+ }
75
+ catch (e) {
76
+ return (0, utils_1.throwError)(e);
77
+ }
78
+ }
79
+ /**
80
+ * Returns the payment statistics data for the given date range
81
+ *
82
+ * @param {IStatisticsParams} params - Filter parameters.
83
+ * @returns {Promise<PaymentStatistics>}
84
+ * @throws {Error} - An error object if an error occurred.
85
+ */
86
+ async getPaymentStatistics(params = {}) {
87
+ try {
88
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.network.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
89
+ from: params.from ? params.from.getTime() / 1000 : undefined,
90
+ to: params.to ? params.to.getTime() / 1000 : undefined,
91
+ });
92
+ return {
93
+ dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
94
+ timestamp: new Date(+eventDayData.timestamp * 1000),
95
+ totalAmountPaid: ethers_1.BigNumber.from(eventDayData.dailyPayoutAmount),
96
+ totalCount: +eventDayData.dailyPayoutCount,
97
+ averageAmountPerJob: eventDayData.dailyBulkPayoutEventCount === '0'
98
+ ? ethers_1.BigNumber.from(0)
99
+ : ethers_1.BigNumber.from(eventDayData.dailyPayoutAmount).div(eventDayData.dailyBulkPayoutEventCount),
100
+ averageAmountPerWorker: eventDayData.dailyWorkerCount === '0'
101
+ ? ethers_1.BigNumber.from(0)
102
+ : ethers_1.BigNumber.from(eventDayData.dailyPayoutAmount).div(eventDayData.dailyWorkerCount),
103
+ })),
104
+ };
105
+ }
106
+ catch (e) {
107
+ return (0, utils_1.throwError)(e);
108
+ }
109
+ }
110
+ /**
111
+ * Returns the HMToken statistics data for the given date range
112
+ *
113
+ * @param {IStatisticsParams} params - Filter parameters.
114
+ * @returns {Promise<HMTStatistics>}
115
+ * @throws {Error} - An error object if an error occurred.
116
+ */
117
+ async getHMTStatistics(params = {}) {
118
+ try {
119
+ const { hmtokenStatistics } = await (0, graphql_request_1.default)(this.network.subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY);
120
+ const { holders } = await (0, graphql_request_1.default)(this.network.subgraphUrl, graphql_1.GET_HOLDERS_QUERY);
121
+ const { eventDayDatas } = await (0, graphql_request_1.default)(this.network.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(params), {
122
+ from: params.from ? params.from.getTime() / 1000 : undefined,
123
+ to: params.to ? params.to.getTime() / 1000 : undefined,
124
+ });
125
+ return {
126
+ totalTransferAmount: ethers_1.BigNumber.from(hmtokenStatistics.totalValueTransfered),
127
+ totalHolders: +hmtokenStatistics.holders,
128
+ holders: holders.map((holder) => ({
129
+ address: holder.address,
130
+ balance: ethers_1.BigNumber.from(holder.balance),
131
+ })),
132
+ dailyHMTData: eventDayDatas.map((eventDayData) => ({
133
+ timestamp: new Date(+eventDayData.timestamp * 1000),
134
+ totalTransactionAmount: ethers_1.BigNumber.from(eventDayData.dailyHMTTransferAmount),
135
+ totalTransactionCount: +eventDayData.dailyHMTTransferCount,
136
+ })),
137
+ };
138
+ }
139
+ catch (e) {
140
+ return (0, utils_1.throwError)(e);
141
+ }
142
+ }
143
+ }
144
+ exports.StatisticsClient = StatisticsClient;
package/dist/storage.d.ts CHANGED
@@ -5,10 +5,10 @@ export declare class StorageClient {
5
5
  /**
6
6
  * **Storage client constructor**
7
7
  *
8
- * @param {StorageCredentials} credentials - Cloud storage access data
9
8
  * @param {StorageParams} params - Cloud storage params
9
+ * @param {StorageCredentials} credentials - Optional. Cloud storage access data. If credentials is not provided - use an anonymous access to the bucket
10
10
  */
11
- constructor(credentials: StorageCredentials, params: StorageParams);
11
+ constructor(params: StorageParams, credentials?: StorageCredentials);
12
12
  /**
13
13
  * **Download files from cloud storage**
14
14
  *
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa;IAclE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,kBAAkB;IAcnE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
package/dist/storage.js CHANGED
@@ -38,16 +38,16 @@ class StorageClient {
38
38
  /**
39
39
  * **Storage client constructor**
40
40
  *
41
- * @param {StorageCredentials} credentials - Cloud storage access data
42
41
  * @param {StorageParams} params - Cloud storage params
42
+ * @param {StorageCredentials} credentials - Optional. Cloud storage access data. If credentials is not provided - use an anonymous access to the bucket
43
43
  */
44
- constructor(credentials, params) {
44
+ constructor(params, credentials) {
45
45
  try {
46
46
  this.clientParams = params;
47
47
  this.client = new Minio.Client({
48
48
  ...params,
49
- accessKey: credentials.accessKey,
50
- secretKey: credentials.secretKey,
49
+ accessKey: credentials?.accessKey ?? '',
50
+ secretKey: credentials?.secretKey ?? '',
51
51
  });
52
52
  }
53
53
  catch (e) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "1.1.9",
4
+ "version": "1.1.11",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
package/src/constants.ts CHANGED
@@ -61,7 +61,7 @@ export const NETWORKS: {
61
61
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
62
62
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
63
63
  subgraphUrl:
64
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
64
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v2',
65
65
  oldSubgraphUrl: '',
66
66
  oldFactoryAddress: '',
67
67
  },
@@ -88,7 +88,7 @@ export const NETWORKS: {
88
88
  rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
89
89
  kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
90
90
  subgraphUrl:
91
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
91
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v2',
92
92
  oldSubgraphUrl:
93
93
  'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli',
94
94
  oldFactoryAddress: '0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F',
@@ -102,7 +102,7 @@ export const NETWORKS: {
102
102
  stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
103
103
  rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
104
104
  kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
105
- subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
105
+ subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v2',
106
106
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
107
107
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
108
108
  },
@@ -116,7 +116,7 @@ export const NETWORKS: {
116
116
  rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
117
117
  kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
118
118
  subgraphUrl:
119
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
119
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v2',
120
120
  oldSubgraphUrl:
121
121
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
122
122
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
@@ -131,7 +131,7 @@ export const NETWORKS: {
131
131
  rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
132
132
  kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
133
133
  subgraphUrl:
134
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
134
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2',
135
135
  oldSubgraphUrl:
136
136
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
137
137
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
@@ -146,7 +146,7 @@ export const NETWORKS: {
146
146
  rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
147
147
  kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
148
148
  subgraphUrl:
149
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
149
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v2',
150
150
  oldSubgraphUrl:
151
151
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai',
152
152
  oldFactoryAddress: '0x558cd800f9F0B02f3B149667bDe003284c867E94',
@@ -161,7 +161,7 @@ export const NETWORKS: {
161
161
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
162
162
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
163
163
  subgraphUrl:
164
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
164
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v2',
165
165
  oldSubgraphUrl:
166
166
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
167
167
  oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad',
@@ -176,7 +176,7 @@ export const NETWORKS: {
176
176
  rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
177
177
  kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
178
178
  subgraphUrl:
179
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
179
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v2',
180
180
  oldSubgraphUrl: '',
181
181
  oldFactoryAddress: '',
182
182
  },
package/src/escrow.ts CHANGED
@@ -39,11 +39,7 @@ import {
39
39
  import { IEscrowConfig, IEscrowsFilter } from './interfaces';
40
40
  import { EscrowStatus, NetworkData } from './types';
41
41
  import { isValidUrl, throwError } from './utils';
42
- import {
43
- EscrowData,
44
- GET_ESCROWS_BY_LAUNCHER_QUERY,
45
- GET_FILTERED_ESCROWS_QUERY,
46
- } from './graphql';
42
+ import { EscrowData, GET_ESCROWS_QUERY } from './graphql';
47
43
 
48
44
  export class EscrowClient {
49
45
  private escrowFactoryContract: EscrowFactory;
@@ -107,7 +103,8 @@ export class EscrowClient {
107
103
  @requiresSigner
108
104
  public async createEscrow(
109
105
  tokenAddress: string,
110
- trustedHandlers: string[]
106
+ trustedHandlers: string[],
107
+ jobRequesterId: string
111
108
  ): Promise<string> {
112
109
  if (!ethers.utils.isAddress(tokenAddress)) {
113
110
  throw ErrorInvalidTokenAddress;
@@ -123,12 +120,13 @@ export class EscrowClient {
123
120
  const result: ContractReceipt = await (
124
121
  await this.escrowFactoryContract.createEscrow(
125
122
  tokenAddress,
126
- trustedHandlers
123
+ trustedHandlers,
124
+ jobRequesterId
127
125
  )
128
126
  ).wait();
129
127
 
130
128
  const event = result.events?.find(({ topics }) =>
131
- topics.includes(ethers.utils.id('Launched(address,address)'))
129
+ topics.includes(ethers.utils.id('LaunchedV2(address,address,string)'))
132
130
  )?.args;
133
131
 
134
132
  if (!event) {
@@ -233,12 +231,14 @@ export class EscrowClient {
233
231
  async createAndSetupEscrow(
234
232
  tokenAddress: string,
235
233
  trustedHandlers: string[],
234
+ jobRequesterId: string,
236
235
  escrowConfig: IEscrowConfig
237
236
  ): Promise<string> {
238
237
  try {
239
238
  const escrowAddress = await this.createEscrow(
240
239
  tokenAddress,
241
- trustedHandlers
240
+ trustedHandlers,
241
+ jobRequesterId
242
242
  );
243
243
 
244
244
  await this.setup(escrowAddress, escrowConfig);
@@ -585,6 +585,33 @@ export class EscrowClient {
585
585
  }
586
586
  }
587
587
 
588
+ /**
589
+ * Returns the manifest file hash.
590
+ *
591
+ * @param {string} escrowAddress - Address of the escrow.
592
+ * @returns {Promise<void>}
593
+ * @throws {Error} - An error object if an error occurred.
594
+ */
595
+ async getManifestHash(escrowAddress: string): Promise<string> {
596
+ if (!ethers.utils.isAddress(escrowAddress)) {
597
+ throw ErrorInvalidEscrowAddressProvided;
598
+ }
599
+
600
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
601
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
602
+ }
603
+
604
+ try {
605
+ this.escrowContract = Escrow__factory.connect(
606
+ escrowAddress,
607
+ this.signerOrProvider
608
+ );
609
+ return this.escrowContract.manifestHash();
610
+ } catch (e) {
611
+ return throwError(e);
612
+ }
613
+ }
614
+
588
615
  /**
589
616
  * Returns the manifest file URL.
590
617
  *
@@ -721,41 +748,27 @@ export class EscrowClient {
721
748
  }
722
749
 
723
750
  /**
724
- * Returns the escrow addresses created by a job requester.
751
+ * Returns the list of escrows for given filter
725
752
  *
726
- * @param {IEscrowsFilter} requesterAddress - Address of the requester.
727
- * @returns {Promise<string[]>}
753
+ * @param {IEscrowsFilter} filter - Filter parameters.
754
+ * @returns {Promise<EscrowData[]>}
728
755
  * @throws {Error} - An error object if an error occurred.
729
756
  */
730
- async getLaunchedEscrows(launcherAddress: string): Promise<EscrowData[]> {
731
- if (!ethers.utils.isAddress(launcherAddress)) {
757
+ async getEscrows(filter: IEscrowsFilter = {}): Promise<EscrowData[]> {
758
+ if (filter.launcher && !ethers.utils.isAddress(filter.launcher)) {
732
759
  throw ErrorInvalidAddress;
733
760
  }
734
761
 
735
- try {
736
- const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
737
- this.network.subgraphUrl,
738
- GET_ESCROWS_BY_LAUNCHER_QUERY,
739
- { launcherAddress }
740
- );
741
-
742
- return escrows;
743
- } catch (e: any) {
744
- return throwError(e);
762
+ if (
763
+ filter.recordingOracle &&
764
+ !ethers.utils.isAddress(filter.recordingOracle)
765
+ ) {
766
+ throw ErrorInvalidAddress;
745
767
  }
746
- }
747
768
 
748
- /**
749
- * Returns the escrow addresses based on a specified filter.
750
- *
751
- * @param {IEscrowsFilter} filter - Filter parameters.
752
- * @returns {Promise<EscrowData[]>}
753
- * @throws {Error} - An error object if an error occurred.
754
- */
755
- async getEscrowsFiltered(filter: IEscrowsFilter): Promise<EscrowData[]> {
756
769
  if (
757
- filter?.launcherAddress &&
758
- !ethers.utils.isAddress(filter?.launcherAddress)
770
+ filter.reputationOracle &&
771
+ !ethers.utils.isAddress(filter.reputationOracle)
759
772
  ) {
760
773
  throw ErrorInvalidAddress;
761
774
  }
@@ -763,9 +776,11 @@ export class EscrowClient {
763
776
  try {
764
777
  const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
765
778
  this.network.subgraphUrl,
766
- GET_FILTERED_ESCROWS_QUERY,
779
+ GET_ESCROWS_QUERY(filter),
767
780
  {
768
781
  ...filter,
782
+ from: filter.from ? +filter.from.getTime() / 1000 : undefined,
783
+ to: filter.to ? +filter.to.getTime() / 1000 : undefined,
769
784
  }
770
785
  );
771
786
 
@@ -1,4 +1,5 @@
1
1
  import gql from 'graphql-tag';
2
+ import { IEscrowsFilter } from '../../interfaces';
2
3
 
3
4
  const ESCROW_FRAGMENT = gql`
4
5
  fragment EscrowFields on Escrow {
@@ -20,35 +21,40 @@ const ESCROW_FRAGMENT = gql`
20
21
  status
21
22
  token
22
23
  totalFundedAmount
24
+ createdAt
23
25
  }
24
26
  `;
25
27
 
26
- export const GET_ESCROWS_BY_LAUNCHER_QUERY = gql`
27
- query GetEscrowByLauncher($launcherAddress: String!) {
28
- escrows(where: { launcher: $launcherAddress }) {
29
- ...EscrowFields
28
+ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
29
+ const { launcher, reputationOracle, recordingOracle, status, from, to } =
30
+ filter;
31
+
32
+ const WHERE_CLAUSE = `
33
+ where: {
34
+ ${launcher ? `launcher: $launcher` : ''}
35
+ ${reputationOracle ? `reputationOracle: $reputationOracle` : ''}
36
+ ${recordingOracle ? `recordingOracle: $recordingOracle` : ''}
37
+ ${status ? `status: $status` : ''}
38
+ ${from ? `createdAt_gte: $from` : ''}
39
+ ${to ? `createdAt_lte: $to` : ''}
30
40
  }
31
- }
32
- ${ESCROW_FRAGMENT}
33
- `;
41
+ `;
34
42
 
35
- export const GET_FILTERED_ESCROWS_QUERY = gql`
36
- query GetFilteredEscrows(
37
- $launcherAddress: String
38
- $status: EscrowStatus
39
- $from: Int
40
- $to: Int
41
- ) {
42
- escrows(
43
- where: {
44
- launcher: $launcherAddress
45
- status: $status
46
- createdAt_gte: $from
47
- createdAt_lte: $to
48
- }
43
+ return gql`
44
+ query getEscrows(
45
+ $launcher: String
46
+ $reputationOracle: String
47
+ $recordingOracle: String
48
+ $status: String
49
+ $from: Int
50
+ $to: Int
49
51
  ) {
50
- ...EscrowFields
52
+ escrows(
53
+ ${WHERE_CLAUSE}
54
+ ) {
55
+ ...EscrowFields
56
+ }
51
57
  }
52
- }
53
- ${ESCROW_FRAGMENT}
54
- `;
58
+ ${ESCROW_FRAGMENT}
59
+ `;
60
+ };
@@ -0,0 +1,17 @@
1
+ import gql from 'graphql-tag';
2
+
3
+ const HOLDER_FRAGMENT = gql`
4
+ fragment HolderFields on Holder {
5
+ address
6
+ balance
7
+ }
8
+ `;
9
+
10
+ export const GET_HOLDERS_QUERY = gql`
11
+ query GetHolders {
12
+ holders {
13
+ ...HolderFields
14
+ }
15
+ }
16
+ ${HOLDER_FRAGMENT}
17
+ `;
@@ -1,2 +1,4 @@
1
1
  export * from './escrow';
2
+ export * from './hmtoken';
2
3
  export * from './reward';
4
+ export * from './statistics';