@human-protocol/sdk 5.2.0 → 6.1.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/CHANGELOG.md +13 -0
- package/dist/base.d.ts +8 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +18 -5
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -8
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +66 -202
- package/dist/error.d.ts +0 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -26
- package/dist/escrow.d.ts +438 -791
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +331 -705
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/interfaces.d.ts +2 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +124 -186
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +122 -185
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +142 -141
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +140 -139
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +38 -17
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +40 -19
- package/dist/types.d.ts +14 -55
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +32 -18
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +32 -19
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +8 -25
- package/src/base.ts +42 -7
- package/src/constants.ts +6 -8
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +548 -891
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/interfaces.ts +2 -2
- package/src/kvstore.ts +142 -197
- package/src/operator.ts +59 -30
- package/src/staking.ts +177 -160
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +40 -19
- package/src/types.ts +16 -58
- package/src/utils.ts +33 -23
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- package/src/storage.ts +0 -313
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionLike } from 'ethers';
|
|
1
|
+
import { Overrides, TransactionLike } from 'ethers';
|
|
2
2
|
/**
|
|
3
3
|
* Enum for escrow statuses.
|
|
4
4
|
* @readonly
|
|
@@ -34,60 +34,6 @@ export declare enum EscrowStatus {
|
|
|
34
34
|
*/
|
|
35
35
|
ToCancel = 6
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* AWS/GCP cloud storage access data
|
|
39
|
-
* @readonly
|
|
40
|
-
* @deprecated StorageClient is deprecated. Use Minio.Client directly.
|
|
41
|
-
*/
|
|
42
|
-
export type StorageCredentials = {
|
|
43
|
-
/**
|
|
44
|
-
* Access Key
|
|
45
|
-
*/
|
|
46
|
-
accessKey: string;
|
|
47
|
-
/**
|
|
48
|
-
* Secret Key
|
|
49
|
-
*/
|
|
50
|
-
secretKey: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated StorageClient is deprecated. Use Minio.Client directly.
|
|
54
|
-
*/
|
|
55
|
-
export type StorageParams = {
|
|
56
|
-
/**
|
|
57
|
-
* Request endPoint
|
|
58
|
-
*/
|
|
59
|
-
endPoint: string;
|
|
60
|
-
/**
|
|
61
|
-
* Enable secure (HTTPS) access. Default value set to false
|
|
62
|
-
*/
|
|
63
|
-
useSSL: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Region
|
|
66
|
-
*/
|
|
67
|
-
region?: string;
|
|
68
|
-
/**
|
|
69
|
-
* TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
|
|
70
|
-
*/
|
|
71
|
-
port?: number;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Upload file data
|
|
75
|
-
* @readonly
|
|
76
|
-
*/
|
|
77
|
-
export type UploadFile = {
|
|
78
|
-
/**
|
|
79
|
-
* Uploaded object key
|
|
80
|
-
*/
|
|
81
|
-
key: string;
|
|
82
|
-
/**
|
|
83
|
-
* Uploaded object URL
|
|
84
|
-
*/
|
|
85
|
-
url: string;
|
|
86
|
-
/**
|
|
87
|
-
* Hash of uploaded object key
|
|
88
|
-
*/
|
|
89
|
-
hash: string;
|
|
90
|
-
};
|
|
91
37
|
/**
|
|
92
38
|
* Network data
|
|
93
39
|
*/
|
|
@@ -137,6 +83,19 @@ export type NetworkData = {
|
|
|
137
83
|
*/
|
|
138
84
|
oldFactoryAddress: string;
|
|
139
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Options that configure how long to wait for transaction confirmations.
|
|
88
|
+
*/
|
|
89
|
+
export type WaitOptions = {
|
|
90
|
+
/** Number of block confirmations to wait for. */
|
|
91
|
+
confirmations?: number;
|
|
92
|
+
/** Milliseconds to wait before aborting `tx.wait()`. */
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Extends ethers overrides with `wait()` options that control confirmation count and timeout.
|
|
97
|
+
*/
|
|
98
|
+
export type TransactionOverrides = Overrides & WaitOptions;
|
|
140
99
|
export type TransactionLikeWithNonce = TransactionLike & {
|
|
141
100
|
nonce: number;
|
|
142
101
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEpD;;;;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;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,CAAC;AAE3D,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,44 +1,58 @@
|
|
|
1
|
-
import { NetworkData } from './types';
|
|
2
1
|
import { SubgraphOptions } from './interfaces';
|
|
2
|
+
import { NetworkData } from './types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Handles and throws appropriate error types based on the Ethereum error.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
6
|
+
* @param e - The error to handle
|
|
7
|
+
* @throws {InvalidArgumentError} If the error is an invalid argument error
|
|
8
|
+
* @throws {ContractExecutionError} If the error is a contract execution error
|
|
9
|
+
* @throws {TransactionReplaced} If the transaction was replaced
|
|
10
|
+
* @throws {ReplacementUnderpriced} If the replacement transaction was underpriced
|
|
11
|
+
* @throws {NumericFault} If there's a numeric fault
|
|
12
|
+
* @throws {NonceExpired} If the nonce has expired
|
|
13
|
+
* @throws {EthereumError} For any other Ethereum-related error
|
|
8
14
|
*/
|
|
9
15
|
export declare const throwError: (e: any) => never;
|
|
10
16
|
/**
|
|
11
|
-
*
|
|
17
|
+
* Validates if a string is a valid URL.
|
|
12
18
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @returns
|
|
19
|
+
* @param url - The URL string to validate
|
|
20
|
+
* @returns True if the URL is valid, false otherwise
|
|
15
21
|
*/
|
|
16
22
|
export declare const isValidUrl: (url: string) => boolean;
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
24
|
+
* Checks if a string is valid JSON.
|
|
19
25
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @returns
|
|
26
|
+
* @param input - The string to check
|
|
27
|
+
* @returns True if the string is valid JSON, false otherwise
|
|
22
28
|
*/
|
|
23
29
|
export declare const isValidJson: (input: string) => boolean;
|
|
24
30
|
/**
|
|
25
|
-
*
|
|
31
|
+
* Gets the subgraph URL for the given network, using API key if available.
|
|
26
32
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @returns
|
|
33
|
+
* @param networkData - The network data containing subgraph URLs
|
|
34
|
+
* @returns The subgraph URL with API key if available
|
|
29
35
|
*/
|
|
30
36
|
export declare const getSubgraphUrl: (networkData: NetworkData) => string;
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
38
|
+
* Converts a Date object to Unix timestamp (seconds since epoch).
|
|
33
39
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @returns
|
|
40
|
+
* @param date - The date to convert
|
|
41
|
+
* @returns Unix timestamp in seconds
|
|
36
42
|
*/
|
|
37
43
|
export declare const getUnixTimestamp: (date: Date) => number;
|
|
38
44
|
export declare const isIndexerError: (error: any) => boolean;
|
|
39
45
|
/**
|
|
40
|
-
*
|
|
41
|
-
* Only retries if options is provided.
|
|
46
|
+
* Executes a GraphQL request with automatic retry logic for bad indexer errors.
|
|
47
|
+
* Only retries if options is provided with maxRetries and baseDelay.
|
|
48
|
+
*
|
|
49
|
+
* @param url - The GraphQL endpoint URL
|
|
50
|
+
* @param query - The GraphQL query to execute
|
|
51
|
+
* @param variables - Variables for the GraphQL query (optional)
|
|
52
|
+
* @param options - Optional configuration for subgraph requests including retry logic
|
|
53
|
+
* @returns The response data from the GraphQL query
|
|
54
|
+
* @throws ErrorRetryParametersMissing If only one of maxRetries or baseDelay is provided
|
|
55
|
+
* @throws ErrorRoutingRequestsToIndexerRequiresApiKey If indexerId is provided without API key
|
|
42
56
|
*/
|
|
43
57
|
export declare const customGqlFetch: <T = any>(url: string, query: any, variables?: any, options?: SubgraphOptions) => Promise<T>;
|
|
44
58
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAUtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CA4CX,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -8,14 +8,19 @@ exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exp
|
|
|
8
8
|
const ethers_1 = require("ethers");
|
|
9
9
|
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
10
10
|
const validator_1 = require("validator");
|
|
11
|
-
const constants_1 = require("./constants");
|
|
12
11
|
const enums_1 = require("./enums");
|
|
13
12
|
const error_1 = require("./error");
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* Handles and throws appropriate error types based on the Ethereum error.
|
|
16
15
|
*
|
|
17
|
-
* @param
|
|
18
|
-
* @
|
|
16
|
+
* @param e - The error to handle
|
|
17
|
+
* @throws {InvalidArgumentError} If the error is an invalid argument error
|
|
18
|
+
* @throws {ContractExecutionError} If the error is a contract execution error
|
|
19
|
+
* @throws {TransactionReplaced} If the transaction was replaced
|
|
20
|
+
* @throws {ReplacementUnderpriced} If the replacement transaction was underpriced
|
|
21
|
+
* @throws {NumericFault} If there's a numeric fault
|
|
22
|
+
* @throws {NonceExpired} If the nonce has expired
|
|
23
|
+
* @throws {EthereumError} For any other Ethereum-related error
|
|
19
24
|
*/
|
|
20
25
|
const throwError = (e) => {
|
|
21
26
|
if (ethers_1.ethers.isError(e, 'INVALID_ARGUMENT')) {
|
|
@@ -42,10 +47,10 @@ const throwError = (e) => {
|
|
|
42
47
|
};
|
|
43
48
|
exports.throwError = throwError;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
50
|
+
* Validates if a string is a valid URL.
|
|
46
51
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @returns
|
|
52
|
+
* @param url - The URL string to validate
|
|
53
|
+
* @returns True if the URL is valid, false otherwise
|
|
49
54
|
*/
|
|
50
55
|
const isValidUrl = (url) => {
|
|
51
56
|
return (0, validator_1.isURL)(url, {
|
|
@@ -56,10 +61,10 @@ const isValidUrl = (url) => {
|
|
|
56
61
|
};
|
|
57
62
|
exports.isValidUrl = isValidUrl;
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
64
|
+
* Checks if a string is valid JSON.
|
|
60
65
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @returns
|
|
66
|
+
* @param input - The string to check
|
|
67
|
+
* @returns True if the string is valid JSON, false otherwise
|
|
63
68
|
*/
|
|
64
69
|
const isValidJson = (input) => {
|
|
65
70
|
try {
|
|
@@ -72,15 +77,15 @@ const isValidJson = (input) => {
|
|
|
72
77
|
};
|
|
73
78
|
exports.isValidJson = isValidJson;
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
80
|
+
* Gets the subgraph URL for the given network, using API key if available.
|
|
76
81
|
*
|
|
77
|
-
* @param
|
|
78
|
-
* @returns
|
|
82
|
+
* @param networkData - The network data containing subgraph URLs
|
|
83
|
+
* @returns The subgraph URL with API key if available
|
|
79
84
|
*/
|
|
80
85
|
const getSubgraphUrl = (networkData) => {
|
|
81
86
|
let subgraphUrl = networkData.subgraphUrl;
|
|
82
87
|
if (process.env.SUBGRAPH_API_KEY) {
|
|
83
|
-
subgraphUrl = networkData.subgraphUrlApiKey
|
|
88
|
+
subgraphUrl = networkData.subgraphUrlApiKey;
|
|
84
89
|
}
|
|
85
90
|
else if (networkData.chainId !== enums_1.ChainId.LOCALHOST) {
|
|
86
91
|
// eslint-disable-next-line no-console
|
|
@@ -90,10 +95,10 @@ const getSubgraphUrl = (networkData) => {
|
|
|
90
95
|
};
|
|
91
96
|
exports.getSubgraphUrl = getSubgraphUrl;
|
|
92
97
|
/**
|
|
93
|
-
*
|
|
98
|
+
* Converts a Date object to Unix timestamp (seconds since epoch).
|
|
94
99
|
*
|
|
95
|
-
* @param
|
|
96
|
-
* @returns
|
|
100
|
+
* @param date - The date to convert
|
|
101
|
+
* @returns Unix timestamp in seconds
|
|
97
102
|
*/
|
|
98
103
|
const getUnixTimestamp = (date) => {
|
|
99
104
|
return Math.floor(date.getTime() / 1000);
|
|
@@ -119,8 +124,16 @@ const buildIndexerUrl = (baseUrl, indexerId) => {
|
|
|
119
124
|
return `${baseUrl}/indexers/id/${indexerId}`;
|
|
120
125
|
};
|
|
121
126
|
/**
|
|
122
|
-
*
|
|
123
|
-
* Only retries if options is provided.
|
|
127
|
+
* Executes a GraphQL request with automatic retry logic for bad indexer errors.
|
|
128
|
+
* Only retries if options is provided with maxRetries and baseDelay.
|
|
129
|
+
*
|
|
130
|
+
* @param url - The GraphQL endpoint URL
|
|
131
|
+
* @param query - The GraphQL query to execute
|
|
132
|
+
* @param variables - Variables for the GraphQL query (optional)
|
|
133
|
+
* @param options - Optional configuration for subgraph requests including retry logic
|
|
134
|
+
* @returns The response data from the GraphQL query
|
|
135
|
+
* @throws ErrorRetryParametersMissing If only one of maxRetries or baseDelay is provided
|
|
136
|
+
* @throws ErrorRoutingRequestsToIndexerRequiresApiKey If indexerId is provided without API key
|
|
124
137
|
*/
|
|
125
138
|
const customGqlFetch = async (url, query, variables, options) => {
|
|
126
139
|
const apiKey = process.env.SUBGRAPH_API_KEY;
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
import { ChainId } from './enums';
|
|
2
2
|
import { IWorker, IWorkersFilter, SubgraphOptions } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for worker-related operations.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const worker = await WorkerUtils.getWorker(
|
|
11
|
+
* ChainId.POLYGON_AMOY,
|
|
12
|
+
* '0x1234567890abcdef1234567890abcdef12345678'
|
|
13
|
+
* );
|
|
14
|
+
* console.log('Worker:', worker);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
export declare class WorkerUtils {
|
|
4
18
|
/**
|
|
5
19
|
* This function returns the worker data for the given address.
|
|
6
20
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* @param chainId - The chain ID.
|
|
22
|
+
* @param address - The worker address.
|
|
23
|
+
* @param options - Optional configuration for subgraph requests.
|
|
24
|
+
* @returns Returns the worker details or null if not found.
|
|
25
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
26
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
13
27
|
*
|
|
28
|
+
* @example
|
|
14
29
|
* ```ts
|
|
15
30
|
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
16
31
|
*
|
|
17
|
-
* const worker = await WorkerUtils.getWorker(
|
|
32
|
+
* const worker = await WorkerUtils.getWorker(
|
|
33
|
+
* ChainId.POLYGON_AMOY,
|
|
34
|
+
* '0x1234567890abcdef1234567890abcdef12345678'
|
|
35
|
+
* );
|
|
36
|
+
* console.log('Worker:', worker);
|
|
18
37
|
* ```
|
|
19
38
|
*/
|
|
20
39
|
static getWorker(chainId: ChainId, address: string, options?: SubgraphOptions): Promise<IWorker | null>;
|
|
@@ -43,21 +62,23 @@ export declare class WorkerUtils {
|
|
|
43
62
|
* };
|
|
44
63
|
* ```
|
|
45
64
|
*
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @returns
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* @param filter - Filter for the workers.
|
|
66
|
+
* @param options - Optional configuration for subgraph requests.
|
|
67
|
+
* @returns Returns an array with all the worker details.
|
|
68
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
69
|
+
* @throws ErrorInvalidAddress If the filter address is invalid
|
|
51
70
|
*
|
|
71
|
+
* @example
|
|
52
72
|
* ```ts
|
|
53
73
|
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
54
74
|
*
|
|
55
|
-
* const filter
|
|
56
|
-
* chainId: ChainId.
|
|
75
|
+
* const filter = {
|
|
76
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
57
77
|
* first: 10,
|
|
58
78
|
* skip: 0,
|
|
59
79
|
* };
|
|
60
80
|
* const workers = await WorkerUtils.getWorkers(filter);
|
|
81
|
+
* console.log('Workers:', workers.length);
|
|
61
82
|
* ```
|
|
62
83
|
*/
|
|
63
84
|
static getWorkers(filter: IWorkersFilter, options?: SubgraphOptions): Promise<IWorker[]>;
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGxE,qBAAa,WAAW;IACtB
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGxE;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW;IACtB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IA0B1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACiB,UAAU,CAC5B,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CAoCtB"}
|
package/dist/worker.js
CHANGED
|
@@ -7,21 +7,40 @@ const enums_1 = require("./enums");
|
|
|
7
7
|
const error_1 = require("./error");
|
|
8
8
|
const worker_1 = require("./graphql/queries/worker");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Utility class for worker-related operations.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const worker = await WorkerUtils.getWorker(
|
|
18
|
+
* ChainId.POLYGON_AMOY,
|
|
19
|
+
* '0x1234567890abcdef1234567890abcdef12345678'
|
|
20
|
+
* );
|
|
21
|
+
* console.log('Worker:', worker);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
10
24
|
class WorkerUtils {
|
|
11
25
|
/**
|
|
12
26
|
* This function returns the worker data for the given address.
|
|
13
27
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* @param chainId - The chain ID.
|
|
29
|
+
* @param address - The worker address.
|
|
30
|
+
* @param options - Optional configuration for subgraph requests.
|
|
31
|
+
* @returns Returns the worker details or null if not found.
|
|
32
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
33
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
20
34
|
*
|
|
35
|
+
* @example
|
|
21
36
|
* ```ts
|
|
22
37
|
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
23
38
|
*
|
|
24
|
-
* const worker = await WorkerUtils.getWorker(
|
|
39
|
+
* const worker = await WorkerUtils.getWorker(
|
|
40
|
+
* ChainId.POLYGON_AMOY,
|
|
41
|
+
* '0x1234567890abcdef1234567890abcdef12345678'
|
|
42
|
+
* );
|
|
43
|
+
* console.log('Worker:', worker);
|
|
25
44
|
* ```
|
|
26
45
|
*/
|
|
27
46
|
static async getWorker(chainId, address, options) {
|
|
@@ -64,21 +83,23 @@ class WorkerUtils {
|
|
|
64
83
|
* };
|
|
65
84
|
* ```
|
|
66
85
|
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
70
|
-
*
|
|
71
|
-
*
|
|
86
|
+
* @param filter - Filter for the workers.
|
|
87
|
+
* @param options - Optional configuration for subgraph requests.
|
|
88
|
+
* @returns Returns an array with all the worker details.
|
|
89
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
90
|
+
* @throws ErrorInvalidAddress If the filter address is invalid
|
|
72
91
|
*
|
|
92
|
+
* @example
|
|
73
93
|
* ```ts
|
|
74
94
|
* import { WorkerUtils, ChainId } from '@human-protocol/sdk';
|
|
75
95
|
*
|
|
76
|
-
* const filter
|
|
77
|
-
* chainId: ChainId.
|
|
96
|
+
* const filter = {
|
|
97
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
78
98
|
* first: 10,
|
|
79
99
|
* skip: 0,
|
|
80
100
|
* };
|
|
81
101
|
* const workers = await WorkerUtils.getWorkers(filter);
|
|
102
|
+
* console.log('Workers:', workers.length);
|
|
82
103
|
* ```
|
|
83
104
|
*/
|
|
84
105
|
static async getWorkers(filter, options) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.1.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist"
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "tsc --build --clean && rm -rf ./dist",
|
|
13
|
-
"clean:doc": "rm -rf ../../../../docs/sdk/typescript/",
|
|
14
13
|
"build": "yarn clean && tsc --build",
|
|
15
|
-
"
|
|
14
|
+
"docs:post": "ts-node scripts/postprocess-docs.ts",
|
|
15
|
+
"build:doc": "typedoc && yarn docs:post",
|
|
16
16
|
"test": "vitest -u",
|
|
17
17
|
"lint": "eslint .",
|
|
18
18
|
"lint:fix": "eslint . --fix",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"graphql": "^16.8.1",
|
|
45
45
|
"graphql-request": "^7.3.4",
|
|
46
46
|
"graphql-tag": "^2.12.6",
|
|
47
|
-
"minio": "7.1.3",
|
|
48
47
|
"openpgp": "^6.2.2",
|
|
49
48
|
"secp256k1": "^5.0.1",
|
|
50
49
|
"validator": "^13.12.0",
|
|
@@ -54,28 +53,12 @@
|
|
|
54
53
|
"@types/validator": "^13.15.4",
|
|
55
54
|
"eslint": "^9.39.1",
|
|
56
55
|
"eslint-plugin-jest": "^28.9.0",
|
|
57
|
-
"eslint-plugin-prettier": "^5.
|
|
58
|
-
"
|
|
56
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
57
|
+
"glob": "^13.0.0",
|
|
58
|
+
"prettier": "^3.7.4",
|
|
59
59
|
"ts-node": "^10.9.2",
|
|
60
|
-
"typedoc": "^0.28.
|
|
61
|
-
"typedoc-plugin-markdown": "^4.
|
|
60
|
+
"typedoc": "^0.28.15",
|
|
61
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
62
62
|
"typescript": "^5.8.3"
|
|
63
|
-
},
|
|
64
|
-
"typedocOptions": {
|
|
65
|
-
"entryPoints": [
|
|
66
|
-
"./src/base.ts",
|
|
67
|
-
"./src/encryption.ts",
|
|
68
|
-
"./src/escrow.ts",
|
|
69
|
-
"./src/kvstore.ts",
|
|
70
|
-
"./src/operator.ts",
|
|
71
|
-
"./src/staking.ts",
|
|
72
|
-
"./src/storage.ts",
|
|
73
|
-
"./src/statistics.ts",
|
|
74
|
-
"./src/transaction.ts",
|
|
75
|
-
"./src/enums.ts",
|
|
76
|
-
"./src/graphql/types.ts",
|
|
77
|
-
"./src/interfaces.ts",
|
|
78
|
-
"./src/types.ts"
|
|
79
|
-
]
|
|
80
63
|
}
|
|
81
64
|
}
|
package/src/base.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ContractRunner,
|
|
3
|
+
ContractTransactionReceipt,
|
|
4
|
+
ContractTransactionResponse,
|
|
5
|
+
Overrides,
|
|
6
|
+
} from 'ethers';
|
|
7
|
+
import { NetworkData, TransactionOverrides, WaitOptions } from './types';
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This class is used as a base class for other clients making on-chain calls.
|
|
10
|
+
* Base class for clients making on-chain calls.
|
|
8
11
|
*
|
|
12
|
+
* This class provides common functionality for interacting with Ethereum contracts.
|
|
9
13
|
*/
|
|
10
14
|
export abstract class BaseEthersClient {
|
|
11
15
|
protected runner: ContractRunner;
|
|
@@ -14,11 +18,42 @@ export abstract class BaseEthersClient {
|
|
|
14
18
|
/**
|
|
15
19
|
* **BaseClient constructor**
|
|
16
20
|
*
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
21
|
+
* @param runner - The Signer or Provider object to interact with the Ethereum network
|
|
22
|
+
* @param networkData - The network information required to connect to the contracts
|
|
19
23
|
*/
|
|
20
24
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
21
25
|
this.networkData = networkData;
|
|
22
26
|
this.runner = runner;
|
|
23
27
|
}
|
|
28
|
+
|
|
29
|
+
protected normalizeTxOptions(
|
|
30
|
+
txOptions?: TransactionOverrides
|
|
31
|
+
): [Overrides, WaitOptions] {
|
|
32
|
+
const options = txOptions ?? {};
|
|
33
|
+
const {
|
|
34
|
+
confirmations: waitConfirmations,
|
|
35
|
+
timeoutMs: waitTimeoutMs,
|
|
36
|
+
...overrides
|
|
37
|
+
} = options;
|
|
38
|
+
|
|
39
|
+
const waitOptions: WaitOptions = {
|
|
40
|
+
confirmations: waitConfirmations,
|
|
41
|
+
timeoutMs: waitTimeoutMs,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return [overrides as Overrides, waitOptions];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async sendTxAndWait(
|
|
48
|
+
executeTx: (overrides: Overrides) => Promise<ContractTransactionResponse>,
|
|
49
|
+
txOptions?: TransactionOverrides
|
|
50
|
+
): Promise<ContractTransactionReceipt | null> {
|
|
51
|
+
const [overrides, waitOptions] = this.normalizeTxOptions(txOptions);
|
|
52
|
+
const transactionResponse = await executeTx(overrides);
|
|
53
|
+
|
|
54
|
+
return transactionResponse.wait(
|
|
55
|
+
waitOptions.confirmations,
|
|
56
|
+
waitOptions.timeoutMs
|
|
57
|
+
);
|
|
58
|
+
}
|
|
24
59
|
}
|
package/src/constants.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const NETWORKS: {
|
|
|
36
36
|
subgraphUrl:
|
|
37
37
|
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
|
|
38
38
|
subgraphUrlApiKey:
|
|
39
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
39
|
+
'https://gateway.thegraph.com/api/deployments/id/QmNhLQEfBJQ46fngBh4YCttk8kNkveFy5uvAeUmyAdX1kD',
|
|
40
40
|
oldSubgraphUrl: '',
|
|
41
41
|
oldFactoryAddress: '',
|
|
42
42
|
},
|
|
@@ -51,7 +51,7 @@ export const NETWORKS: {
|
|
|
51
51
|
subgraphUrl:
|
|
52
52
|
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
|
|
53
53
|
subgraphUrlApiKey:
|
|
54
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
54
|
+
'https://gateway.thegraph.com/api/deployments/id/QmQghdr7hxqrjFde8DN15TzfrJLCfwvzmUH9RzWwH1mKzk',
|
|
55
55
|
oldSubgraphUrl: '',
|
|
56
56
|
oldFactoryAddress: '',
|
|
57
57
|
},
|
|
@@ -66,7 +66,7 @@ export const NETWORKS: {
|
|
|
66
66
|
subgraphUrl:
|
|
67
67
|
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
|
|
68
68
|
subgraphUrlApiKey:
|
|
69
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
69
|
+
'https://gateway.thegraph.com/api/deployments/id/QmTioC9Z1HzKSCnEKL3BP9iHqbgZt1ceLU2VE4Mv6sxNkd',
|
|
70
70
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
71
71
|
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
72
72
|
},
|
|
@@ -81,7 +81,7 @@ export const NETWORKS: {
|
|
|
81
81
|
subgraphUrl:
|
|
82
82
|
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
|
|
83
83
|
subgraphUrlApiKey:
|
|
84
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
84
|
+
'https://gateway.thegraph.com/api/deployments/id/QmPyUYRjAvzDdeenXMGHcCRD2v4qwZbKMEkVkY3Jq6VLwn',
|
|
85
85
|
oldSubgraphUrl:
|
|
86
86
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
87
87
|
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
@@ -97,7 +97,7 @@ export const NETWORKS: {
|
|
|
97
97
|
subgraphUrl:
|
|
98
98
|
'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
|
|
99
99
|
subgraphUrlApiKey:
|
|
100
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
100
|
+
'https://gateway.thegraph.com/api/deployments/id/QmQNkWNE5FPtqbtSkdtR6AEBJz9N7WDz1X7pfvQqYAcUZJ',
|
|
101
101
|
oldSubgraphUrl:
|
|
102
102
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
|
|
103
103
|
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
|
|
@@ -113,7 +113,7 @@ export const NETWORKS: {
|
|
|
113
113
|
subgraphUrl:
|
|
114
114
|
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
|
|
115
115
|
subgraphUrlApiKey:
|
|
116
|
-
'https://gateway.thegraph.com/api/deployments/id/
|
|
116
|
+
'https://gateway.thegraph.com/api/deployments/id/QmcLwLMw3UzCSbNbjegrpNu6PB3kAd67xquuyaVWvc5Q7Q',
|
|
117
117
|
oldSubgraphUrl: '',
|
|
118
118
|
oldFactoryAddress: '',
|
|
119
119
|
},
|
|
@@ -154,6 +154,4 @@ export const Role = {
|
|
|
154
154
|
RecordingOracle: 'recording_oracle',
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
-
export const SUBGRAPH_API_KEY_PLACEHOLDER = '[SUBGRAPH_API_KEY]';
|
|
158
|
-
|
|
159
157
|
export const ESCROW_BULK_PAYOUT_MAX_ITEMS = 99;
|