@human-protocol/sdk 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/constants.d.ts +46 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +203 -0
- package/dist/decorators.d.ts +2 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +17 -0
- package/dist/enums.d.ts +17 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +20 -0
- package/dist/error.d.ts +196 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +229 -0
- package/dist/escrow.d.ts +176 -0
- package/dist/escrow.d.ts.map +1 -0
- package/dist/escrow.js +590 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/init.d.ts +13 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +35 -0
- package/dist/interfaces.d.ts +44 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +2 -0
- package/dist/kvstore.d.ts +40 -0
- package/dist/kvstore.d.ts.map +1 -0
- package/dist/kvstore.js +106 -0
- package/dist/queries.d.ts +4 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +22 -0
- package/dist/staking.d.ts +121 -0
- package/dist/staking.d.ts.map +1 -0
- package/dist/staking.js +381 -0
- package/dist/storage.d.ts +48 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +164 -0
- package/dist/types.d.ts +123 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/utils.d.ts +32 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +99 -0
- package/package.json +4 -7
- package/src/constants.ts +221 -4
- package/src/decorators.ts +21 -0
- package/src/enums.ts +16 -0
- package/src/error.ts +295 -18
- package/src/escrow.ts +754 -0
- package/src/index.ts +14 -1
- package/src/init.ts +45 -0
- package/src/interfaces.ts +50 -0
- package/src/kvstore.ts +93 -0
- package/src/queries.ts +18 -0
- package/src/staking.ts +421 -0
- package/src/storage.ts +159 -131
- package/src/types.ts +36 -586
- package/src/utils.ts +80 -142
- package/test/escrow.test.ts +1339 -0
- package/test/init.test.ts +88 -0
- package/test/kvstore.test.ts +208 -0
- package/test/staking.test.ts +640 -0
- package/test/storage.test.ts +422 -0
- package/test/utils/constants.ts +38 -1
- package/example/simple-existing-job.ts +0 -86
- package/example/simple-new-job-public.ts +0 -74
- package/example/simple-new-job.ts +0 -72
- package/src/job.ts +0 -977
- package/src/logger.ts +0 -29
- package/test/job.test.ts +0 -716
- package/test/utils/manifest.ts +0 -33
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for escrow statuses.
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
6
|
+
export declare enum EscrowStatus {
|
|
7
|
+
/**
|
|
8
|
+
* Escrow is launched.
|
|
9
|
+
*/
|
|
10
|
+
Launched = 0,
|
|
11
|
+
/**
|
|
12
|
+
* Escrow is funded, and waiting for the results to be submitted.
|
|
13
|
+
*/
|
|
14
|
+
Pending = 1,
|
|
15
|
+
/**
|
|
16
|
+
* Escrow is partially paid out.
|
|
17
|
+
*/
|
|
18
|
+
Partial = 2,
|
|
19
|
+
/**
|
|
20
|
+
* Escrow is fully paid.
|
|
21
|
+
*/
|
|
22
|
+
Paid = 3,
|
|
23
|
+
/**
|
|
24
|
+
* Escrow is finished..
|
|
25
|
+
*/
|
|
26
|
+
Complete = 4,
|
|
27
|
+
/**
|
|
28
|
+
* Escrow is cancelled.
|
|
29
|
+
*/
|
|
30
|
+
Cancelled = 5
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* AWS/GCP cloud storage access data
|
|
34
|
+
* @readonly
|
|
35
|
+
*/
|
|
36
|
+
export type StorageCredentials = {
|
|
37
|
+
/**
|
|
38
|
+
* Access Key
|
|
39
|
+
*/
|
|
40
|
+
accessKey: string;
|
|
41
|
+
/**
|
|
42
|
+
* Secret Key
|
|
43
|
+
*/
|
|
44
|
+
secretKey: string;
|
|
45
|
+
};
|
|
46
|
+
export type StorageParams = {
|
|
47
|
+
/**
|
|
48
|
+
* Request endPoint
|
|
49
|
+
*/
|
|
50
|
+
endPoint: string;
|
|
51
|
+
/**
|
|
52
|
+
* Enable secure (HTTPS) access. Default value set to false
|
|
53
|
+
*/
|
|
54
|
+
useSSL: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Region
|
|
57
|
+
*/
|
|
58
|
+
region?: string;
|
|
59
|
+
/**
|
|
60
|
+
* TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
|
|
61
|
+
*/
|
|
62
|
+
port?: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Upload file data
|
|
66
|
+
* @readonly
|
|
67
|
+
*/
|
|
68
|
+
export type UploadFile = {
|
|
69
|
+
/**
|
|
70
|
+
* Uploaded object key
|
|
71
|
+
*/
|
|
72
|
+
key: string;
|
|
73
|
+
/**
|
|
74
|
+
* Hash of uploaded object key
|
|
75
|
+
*/
|
|
76
|
+
hash: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Network data
|
|
80
|
+
*/
|
|
81
|
+
export type NetworkData = {
|
|
82
|
+
/**
|
|
83
|
+
* Network chain id
|
|
84
|
+
*/
|
|
85
|
+
chainId: number;
|
|
86
|
+
/**
|
|
87
|
+
* Network title
|
|
88
|
+
*/
|
|
89
|
+
title: string;
|
|
90
|
+
/**
|
|
91
|
+
* Network scanner URL
|
|
92
|
+
*/
|
|
93
|
+
scanUrl: string;
|
|
94
|
+
/**
|
|
95
|
+
* HMT Token contract address
|
|
96
|
+
*/
|
|
97
|
+
hmtAddress: string;
|
|
98
|
+
/**
|
|
99
|
+
* Escrow Factory contract address
|
|
100
|
+
*/
|
|
101
|
+
factoryAddress: string;
|
|
102
|
+
/**
|
|
103
|
+
* Staking contract address
|
|
104
|
+
*/
|
|
105
|
+
stakingAddress: string;
|
|
106
|
+
/**
|
|
107
|
+
* KVStore contract address
|
|
108
|
+
*/
|
|
109
|
+
kvstoreAddress: string;
|
|
110
|
+
/**
|
|
111
|
+
* Subgraph URL
|
|
112
|
+
*/
|
|
113
|
+
subgraphUrl: string;
|
|
114
|
+
/**
|
|
115
|
+
* Old subgraph URL
|
|
116
|
+
*/
|
|
117
|
+
oldSubgraphUrl: string;
|
|
118
|
+
/**
|
|
119
|
+
* Old Escrow Factory contract address
|
|
120
|
+
*/
|
|
121
|
+
oldFactoryAddress: string;
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;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,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EscrowStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum for escrow statuses.
|
|
6
|
+
* @readonly
|
|
7
|
+
* @enum {number}
|
|
8
|
+
*/
|
|
9
|
+
var EscrowStatus;
|
|
10
|
+
(function (EscrowStatus) {
|
|
11
|
+
/**
|
|
12
|
+
* Escrow is launched.
|
|
13
|
+
*/
|
|
14
|
+
EscrowStatus[EscrowStatus["Launched"] = 0] = "Launched";
|
|
15
|
+
/**
|
|
16
|
+
* Escrow is funded, and waiting for the results to be submitted.
|
|
17
|
+
*/
|
|
18
|
+
EscrowStatus[EscrowStatus["Pending"] = 1] = "Pending";
|
|
19
|
+
/**
|
|
20
|
+
* Escrow is partially paid out.
|
|
21
|
+
*/
|
|
22
|
+
EscrowStatus[EscrowStatus["Partial"] = 2] = "Partial";
|
|
23
|
+
/**
|
|
24
|
+
* Escrow is fully paid.
|
|
25
|
+
*/
|
|
26
|
+
EscrowStatus[EscrowStatus["Paid"] = 3] = "Paid";
|
|
27
|
+
/**
|
|
28
|
+
* Escrow is finished..
|
|
29
|
+
*/
|
|
30
|
+
EscrowStatus[EscrowStatus["Complete"] = 4] = "Complete";
|
|
31
|
+
/**
|
|
32
|
+
* Escrow is cancelled.
|
|
33
|
+
*/
|
|
34
|
+
EscrowStatus[EscrowStatus["Cancelled"] = 5] = "Cancelled";
|
|
35
|
+
})(EscrowStatus = exports.EscrowStatus || (exports.EscrowStatus = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Get specific error text.*
|
|
3
|
+
*
|
|
4
|
+
* @param {any} error - An error message.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const getRevertReason: (error: any) => string;
|
|
8
|
+
/**
|
|
9
|
+
* **Handle and throw the error.*
|
|
10
|
+
*
|
|
11
|
+
* @param {any} e
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const throwError: (e: any) => never;
|
|
15
|
+
/**
|
|
16
|
+
* **URL validation.*
|
|
17
|
+
*
|
|
18
|
+
* @param {string} url
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare const isValidUrl: (url: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* **Fetching data with queries.*
|
|
24
|
+
*
|
|
25
|
+
* @param {string} url
|
|
26
|
+
* @param {string} query
|
|
27
|
+
* @param {any} variables
|
|
28
|
+
* @param {any} headers
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const gqlFetch: (url: string, query: string, variables?: any, headers?: any) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
32
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,GAAG,KAAG,MAO5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAqBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,QACd,MAAM,SACJ,MAAM,cACD,GAAG,YACL,GAAG,qDAYd,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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.gqlFetch = exports.isValidUrl = exports.throwError = exports.getRevertReason = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const error_1 = require("./error");
|
|
11
|
+
/**
|
|
12
|
+
* **Get specific error text.*
|
|
13
|
+
*
|
|
14
|
+
* @param {any} error - An error message.
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const getRevertReason = (error) => {
|
|
18
|
+
const prefix = "reverted with reason string '";
|
|
19
|
+
const suffix = "'";
|
|
20
|
+
const message = error.data.substring(error.data.indexOf(prefix) + prefix.length);
|
|
21
|
+
return message.substring(0, message.indexOf(suffix));
|
|
22
|
+
};
|
|
23
|
+
exports.getRevertReason = getRevertReason;
|
|
24
|
+
/**
|
|
25
|
+
* **Handle and throw the error.*
|
|
26
|
+
*
|
|
27
|
+
* @param {any} e
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
const throwError = (e) => {
|
|
31
|
+
if (e.code === ethers_1.ethers.utils.Logger.errors.INVALID_ARGUMENT) {
|
|
32
|
+
throw new error_1.InvalidArgumentError(e.message);
|
|
33
|
+
}
|
|
34
|
+
else if (e.code === 'OUT_OF_GAS') {
|
|
35
|
+
throw new error_1.OutOfGasError(e.message);
|
|
36
|
+
}
|
|
37
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.CALL_EXCEPTION) {
|
|
38
|
+
const reason = (0, exports.getRevertReason)(e.data);
|
|
39
|
+
throw new error_1.ContractExecutionError(reason);
|
|
40
|
+
}
|
|
41
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
|
|
42
|
+
throw new error_1.UnpredictableGasLimit(e.message);
|
|
43
|
+
}
|
|
44
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.TRANSACTION_REPLACED) {
|
|
45
|
+
throw new error_1.TransactionReplaced(e.message);
|
|
46
|
+
}
|
|
47
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.REPLACEMENT_UNDERPRICED) {
|
|
48
|
+
throw new error_1.ReplacementUnderpriced(e.message);
|
|
49
|
+
}
|
|
50
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.NUMERIC_FAULT) {
|
|
51
|
+
throw new error_1.NumericFault(e.message);
|
|
52
|
+
}
|
|
53
|
+
else if (e.code === ethers_1.ethers.utils.Logger.errors.NONCE_EXPIRED) {
|
|
54
|
+
throw new error_1.NonceExpired(e.message);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new error_1.EthereumError(e.message);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.throwError = throwError;
|
|
61
|
+
/**
|
|
62
|
+
* **URL validation.*
|
|
63
|
+
*
|
|
64
|
+
* @param {string} url
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
const isValidUrl = (url) => {
|
|
68
|
+
try {
|
|
69
|
+
new URL(url);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.isValidUrl = isValidUrl;
|
|
77
|
+
/**
|
|
78
|
+
* **Fetching data with queries.*
|
|
79
|
+
*
|
|
80
|
+
* @param {string} url
|
|
81
|
+
* @param {string} query
|
|
82
|
+
* @param {any} variables
|
|
83
|
+
* @param {any} headers
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
const gqlFetch = (url, query, variables, headers) => {
|
|
87
|
+
if (url && url.length) {
|
|
88
|
+
return axios_1.default.post(url, JSON.stringify({ query, variables }), {
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json',
|
|
91
|
+
...headers,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return Promise.reject(error_1.ErrorNoURLprovided);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.gqlFetch = gqlFetch;
|
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.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clean": "rm -rf ./dist",
|
|
15
15
|
"build": "npm run clean && tsc",
|
|
16
16
|
"prepublish": "npm run build",
|
|
17
|
-
"test": "
|
|
17
|
+
"test": "vitest -u",
|
|
18
18
|
"lint": "eslint .",
|
|
19
19
|
"lint:fix": "eslint . --fix",
|
|
20
20
|
"format": "prettier --write '**/*.{ts,json}'"
|
|
@@ -38,15 +38,12 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@human-protocol/core": "
|
|
41
|
+
"@human-protocol/core": "*",
|
|
42
42
|
"aws-sdk": "^2.1255.0",
|
|
43
43
|
"crypto": "^1.0.1",
|
|
44
|
-
"dotenv": "^16.0.3",
|
|
45
44
|
"ethers": "^5.7.2",
|
|
46
45
|
"secp256k1": "^4.0.3",
|
|
46
|
+
"vitest": "^0.30.1",
|
|
47
47
|
"winston": "^3.8.2"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"@human-protocol/core": "^1.0.11"
|
|
51
48
|
}
|
|
52
49
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
export const DEFAULT_BUCKET = 'escrow-results';
|
|
1
|
+
import { ChainId } from './enums';
|
|
2
|
+
import { NetworkData } from './types';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* @constant Default public bucket name
|
|
8
6
|
*/
|
|
9
7
|
export const DEFAULT_PUBLIC_BUCKET = 'escrow-public-results';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @constant Default storage endpoint
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_ENDPOINT = 'localhost';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @constant Default storage region
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_REGION = 'eu';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @constant Default storage port
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_PORT = 9000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @constant Default storage port
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_USE_SSL = false;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @constant Default tx Id
|
|
31
|
+
*/
|
|
32
|
+
export const DEFAULT_TX_ID = 1;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @constant Default Enum for escrow statuses.
|
|
36
|
+
*/
|
|
37
|
+
export enum HttpStatus {
|
|
38
|
+
OK = 200,
|
|
39
|
+
CREATED = 201,
|
|
40
|
+
BAD_REQUEST = 400,
|
|
41
|
+
UNAUTHORIZED = 401,
|
|
42
|
+
PAYMENT_REQUIRED = 402,
|
|
43
|
+
FORBIDDEN = 403,
|
|
44
|
+
NOT_FOUND = 404,
|
|
45
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @constant Default network parameters
|
|
50
|
+
*/
|
|
51
|
+
export const NETWORKS: {
|
|
52
|
+
[chainId in ChainId]?: NetworkData;
|
|
53
|
+
} = {
|
|
54
|
+
[ChainId.MAINNET]: {
|
|
55
|
+
chainId: ChainId.MAINNET,
|
|
56
|
+
title: 'Ethereum',
|
|
57
|
+
scanUrl: 'https://etherscan.io',
|
|
58
|
+
factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
|
|
59
|
+
hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
|
|
60
|
+
stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
|
|
61
|
+
kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
|
|
62
|
+
subgraphUrl:
|
|
63
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
|
|
64
|
+
oldSubgraphUrl: '',
|
|
65
|
+
oldFactoryAddress: '',
|
|
66
|
+
},
|
|
67
|
+
[ChainId.RINKEBY]: {
|
|
68
|
+
chainId: ChainId.RINKEBY,
|
|
69
|
+
title: 'Ethereum Rinkeby',
|
|
70
|
+
scanUrl: 'https://rinkeby.etherscan.io',
|
|
71
|
+
factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
|
|
72
|
+
hmtAddress: '0x4dCf5ac4509888714dd43A5cCc46d7ab389D9c23',
|
|
73
|
+
stakingAddress: '',
|
|
74
|
+
kvstoreAddress: '',
|
|
75
|
+
subgraphUrl: '',
|
|
76
|
+
oldSubgraphUrl: '',
|
|
77
|
+
oldFactoryAddress: '',
|
|
78
|
+
},
|
|
79
|
+
[ChainId.GOERLI]: {
|
|
80
|
+
chainId: ChainId.GOERLI,
|
|
81
|
+
title: 'Ethereum Goerli',
|
|
82
|
+
scanUrl: 'https://goerli.etherscan.io',
|
|
83
|
+
factoryAddress: '0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c',
|
|
84
|
+
hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
|
|
85
|
+
stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
|
|
86
|
+
kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
|
|
87
|
+
subgraphUrl:
|
|
88
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
|
|
89
|
+
oldSubgraphUrl:
|
|
90
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli',
|
|
91
|
+
oldFactoryAddress: '0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F',
|
|
92
|
+
},
|
|
93
|
+
[ChainId.BSC_MAINNET]: {
|
|
94
|
+
chainId: ChainId.BSC_MAINNET,
|
|
95
|
+
title: 'Binance Smart Chain',
|
|
96
|
+
scanUrl: 'https://bscscan.com',
|
|
97
|
+
factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
|
|
98
|
+
hmtAddress: '0x0d501B743F22b641B8C8dfe00F1AAb881D57DDC7',
|
|
99
|
+
stakingAddress: '0xC2163A0928034e020f0d31e1171Ba0D6d9AfFB6c',
|
|
100
|
+
kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
|
|
101
|
+
|
|
102
|
+
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
|
|
103
|
+
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
104
|
+
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
105
|
+
},
|
|
106
|
+
[ChainId.BSC_TESTNET]: {
|
|
107
|
+
chainId: ChainId.BSC_TESTNET,
|
|
108
|
+
title: 'Binance Smart Chain (Testnet)',
|
|
109
|
+
scanUrl: 'https://testnet.bscscan.com',
|
|
110
|
+
factoryAddress: '0x2bfA592DBDaF434DDcbb893B1916120d181DAD18',
|
|
111
|
+
hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
|
|
112
|
+
stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
|
|
113
|
+
kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
|
|
114
|
+
subgraphUrl:
|
|
115
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
|
|
116
|
+
oldSubgraphUrl:
|
|
117
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
118
|
+
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
119
|
+
},
|
|
120
|
+
[ChainId.POLYGON]: {
|
|
121
|
+
chainId: ChainId.POLYGON,
|
|
122
|
+
title: 'Polygon',
|
|
123
|
+
scanUrl: 'https://polygonscan.com',
|
|
124
|
+
factoryAddress: '0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB',
|
|
125
|
+
hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
|
|
126
|
+
stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
|
|
127
|
+
kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
|
|
128
|
+
subgraphUrl:
|
|
129
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
|
|
130
|
+
oldSubgraphUrl:
|
|
131
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
|
|
132
|
+
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
|
|
133
|
+
},
|
|
134
|
+
[ChainId.POLYGON_MUMBAI]: {
|
|
135
|
+
chainId: ChainId.POLYGON_MUMBAI,
|
|
136
|
+
title: 'Polygon Mumbai',
|
|
137
|
+
scanUrl: 'https://mumbai.polygonscan.com',
|
|
138
|
+
factoryAddress: '0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d',
|
|
139
|
+
hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
|
|
140
|
+
stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
|
|
141
|
+
kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
|
|
142
|
+
subgraphUrl:
|
|
143
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
|
|
144
|
+
oldSubgraphUrl:
|
|
145
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai',
|
|
146
|
+
oldFactoryAddress: '0x558cd800f9F0B02f3B149667bDe003284c867E94',
|
|
147
|
+
},
|
|
148
|
+
[ChainId.MOONBEAM]: {
|
|
149
|
+
chainId: ChainId.MOONBEAM,
|
|
150
|
+
title: 'Moonbeam',
|
|
151
|
+
scanUrl: 'https://moonbeam.moonscan.io',
|
|
152
|
+
factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
|
|
153
|
+
hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
|
|
154
|
+
stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
|
|
155
|
+
kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
|
|
156
|
+
subgraphUrl:
|
|
157
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
|
|
158
|
+
oldSubgraphUrl:
|
|
159
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
|
|
160
|
+
oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad',
|
|
161
|
+
},
|
|
162
|
+
[ChainId.MOONBASE_ALPHA]: {
|
|
163
|
+
chainId: ChainId.MOONBASE_ALPHA,
|
|
164
|
+
title: 'Moonbase Alpha',
|
|
165
|
+
scanUrl: 'https://moonbase.moonscan.io/',
|
|
166
|
+
factoryAddress: '0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed',
|
|
167
|
+
hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
|
|
168
|
+
stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
|
|
169
|
+
kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
|
|
170
|
+
subgraphUrl:
|
|
171
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
|
|
172
|
+
oldSubgraphUrl: '',
|
|
173
|
+
oldFactoryAddress: '',
|
|
174
|
+
},
|
|
175
|
+
[ChainId.AVALANCHE_TESTNET]: {
|
|
176
|
+
chainId: ChainId.AVALANCHE_TESTNET,
|
|
177
|
+
title: 'Fuji C-Chain',
|
|
178
|
+
scanUrl: 'https://testnet.snowtrace.io',
|
|
179
|
+
factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
|
|
180
|
+
hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
|
|
181
|
+
stakingAddress: '',
|
|
182
|
+
kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
|
|
183
|
+
|
|
184
|
+
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
|
|
185
|
+
oldSubgraphUrl: '',
|
|
186
|
+
oldFactoryAddress: '',
|
|
187
|
+
},
|
|
188
|
+
[ChainId.AVALANCHE]: {
|
|
189
|
+
chainId: ChainId.AVALANCHE,
|
|
190
|
+
title: 'Avalanche C-Chain Mainnet',
|
|
191
|
+
scanUrl: 'https://snowtrace.io',
|
|
192
|
+
factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
|
|
193
|
+
hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
|
|
194
|
+
stakingAddress: '',
|
|
195
|
+
kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
|
|
196
|
+
subgraphUrl:
|
|
197
|
+
'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
|
|
198
|
+
oldSubgraphUrl: '',
|
|
199
|
+
oldFactoryAddress: '',
|
|
200
|
+
},
|
|
201
|
+
[ChainId.SKALE]: {
|
|
202
|
+
chainId: ChainId.SKALE,
|
|
203
|
+
title: 'SKALE Human Protocol Chain',
|
|
204
|
+
scanUrl: 'https://wan-red-ain.explorer.mainnet.skalenodes.com/',
|
|
205
|
+
factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
|
|
206
|
+
hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
|
|
207
|
+
stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
|
|
208
|
+
kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
|
|
209
|
+
subgraphUrl:
|
|
210
|
+
'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
|
|
211
|
+
oldSubgraphUrl: '',
|
|
212
|
+
oldFactoryAddress: '0x27B423cE73d1dBdB48d2dd351398b5Ce8223117c',
|
|
213
|
+
},
|
|
214
|
+
[ChainId.LOCALHOST]: {
|
|
215
|
+
chainId: ChainId.LOCALHOST,
|
|
216
|
+
title: 'Localhost',
|
|
217
|
+
scanUrl: '',
|
|
218
|
+
factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
|
|
219
|
+
hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
|
|
220
|
+
stakingAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
|
|
221
|
+
kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
|
|
222
|
+
subgraphUrl: '',
|
|
223
|
+
oldSubgraphUrl: '',
|
|
224
|
+
oldFactoryAddress: '',
|
|
225
|
+
},
|
|
226
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Signer } from 'ethers';
|
|
3
|
+
import { ErrorSigner } from './error';
|
|
4
|
+
|
|
5
|
+
export function requiresSigner(
|
|
6
|
+
target: any,
|
|
7
|
+
propertyKey: string,
|
|
8
|
+
descriptor: PropertyDescriptor
|
|
9
|
+
) {
|
|
10
|
+
const originalMethod = descriptor.value;
|
|
11
|
+
|
|
12
|
+
descriptor.value = async function (this: any, ...args: any[]) {
|
|
13
|
+
if (!Signer.isSigner(this.signerOrProvider)) {
|
|
14
|
+
throw ErrorSigner;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return originalMethod.apply(this, args);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return descriptor;
|
|
21
|
+
}
|
package/src/enums.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export enum ChainId {
|
|
2
|
+
ALL = -1,
|
|
3
|
+
MAINNET = 1,
|
|
4
|
+
RINKEBY = 4,
|
|
5
|
+
GOERLI = 5,
|
|
6
|
+
BSC_MAINNET = 56,
|
|
7
|
+
BSC_TESTNET = 97,
|
|
8
|
+
POLYGON = 137,
|
|
9
|
+
POLYGON_MUMBAI = 80001,
|
|
10
|
+
MOONBEAM = 1284,
|
|
11
|
+
MOONBASE_ALPHA = 1287,
|
|
12
|
+
AVALANCHE_TESTNET = 43113,
|
|
13
|
+
AVALANCHE = 43114,
|
|
14
|
+
SKALE = 1273227453,
|
|
15
|
+
LOCALHOST = 1338,
|
|
16
|
+
}
|