@human-protocol/sdk 1.1.3 → 1.1.5

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 (47) hide show
  1. package/dist/constants.d.ts +46 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/dist/constants.js +203 -0
  4. package/dist/decorators.d.ts +2 -0
  5. package/dist/decorators.d.ts.map +1 -0
  6. package/dist/decorators.js +17 -0
  7. package/dist/enums.d.ts +17 -0
  8. package/dist/enums.d.ts.map +1 -0
  9. package/dist/enums.js +20 -0
  10. package/dist/error.d.ts +196 -0
  11. package/dist/error.d.ts.map +1 -0
  12. package/dist/error.js +229 -0
  13. package/dist/escrow.d.ts +184 -0
  14. package/dist/escrow.d.ts.map +1 -0
  15. package/dist/escrow.js +614 -0
  16. package/dist/index.d.ts +10 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +33 -0
  19. package/dist/init.d.ts +13 -0
  20. package/dist/init.d.ts.map +1 -0
  21. package/dist/init.js +35 -0
  22. package/dist/interfaces.d.ts +44 -0
  23. package/dist/interfaces.d.ts.map +1 -0
  24. package/dist/interfaces.js +2 -0
  25. package/dist/kvstore.d.ts +40 -0
  26. package/dist/kvstore.d.ts.map +1 -0
  27. package/dist/kvstore.js +106 -0
  28. package/dist/queries.d.ts +4 -0
  29. package/dist/queries.d.ts.map +1 -0
  30. package/dist/queries.js +22 -0
  31. package/dist/staking.d.ts +121 -0
  32. package/dist/staking.d.ts.map +1 -0
  33. package/dist/staking.js +381 -0
  34. package/dist/storage.d.ts +48 -0
  35. package/dist/storage.d.ts.map +1 -0
  36. package/dist/storage.js +165 -0
  37. package/dist/types.d.ts +123 -0
  38. package/dist/types.d.ts.map +1 -0
  39. package/dist/types.js +35 -0
  40. package/dist/utils.d.ts +32 -0
  41. package/dist/utils.d.ts.map +1 -0
  42. package/dist/utils.js +99 -0
  43. package/package.json +3 -1
  44. package/src/constants.ts +1 -1
  45. package/src/escrow.ts +8 -4
  46. package/src/staking.ts +1 -0
  47. package/src/storage.ts +1 -0
@@ -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 = {}));
@@ -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.1.3",
4
+ "version": "1.1.5",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -38,8 +38,10 @@
38
38
  "dependencies": {
39
39
  "@human-protocol/core": "*",
40
40
  "aws-sdk": "^2.1255.0",
41
+ "axios": "^1.4.0",
41
42
  "crypto": "^1.0.1",
42
43
  "ethers": "^5.7.2",
44
+ "minio": "^7.0.32",
43
45
  "secp256k1": "^4.0.3",
44
46
  "vitest": "^0.30.1",
45
47
  "winston": "^3.8.2"
package/src/constants.ts CHANGED
@@ -217,7 +217,7 @@ export const NETWORKS: {
217
217
  scanUrl: '',
218
218
  factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
219
219
  hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
220
- stakingAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
220
+ stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
221
221
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
222
222
  subgraphUrl: '',
223
223
  oldSubgraphUrl: '',
package/src/escrow.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import {
2
3
  HMToken__factory,
3
4
  HMToken,
@@ -6,7 +7,7 @@ import {
6
7
  EscrowFactory__factory,
7
8
  Escrow__factory,
8
9
  } from '@human-protocol/core/typechain-types';
9
- import { BigNumber, ContractReceipt, Signer, ethers, providers } from 'ethers';
10
+ import { BigNumber, ContractReceipt, Signer, ethers } from 'ethers';
10
11
  import { Provider } from '@ethersproject/abstract-provider';
11
12
  import {
12
13
  ErrorAmountMustBeGreaterThanZero,
@@ -24,7 +25,6 @@ import {
24
25
  ErrorListOfHandlersCannotBeEmpty,
25
26
  ErrorRecipientAndAmountsMustBeSameLength,
26
27
  ErrorRecipientCannotBeEmptyArray,
27
- ErrorSigner,
28
28
  ErrorTotalFeeMustBeLessThanHundred,
29
29
  ErrorUrlIsEmptyString,
30
30
  InvalidEthereumAddressError,
@@ -96,11 +96,15 @@ export default class EscrowClient {
96
96
  )
97
97
  ).wait();
98
98
 
99
- if (!result.events || !result.events[0] || !result.events[0].args) {
99
+ const event = result.events?.find(({ topics }) =>
100
+ topics.includes(ethers.utils.id('Launched(address,address)'))
101
+ )?.args;
102
+
103
+ if (!event) {
100
104
  throw ErrorLaunchedEventIsNotEmitted;
101
105
  }
102
106
 
103
- return result.events[0].args[1];
107
+ return event.escrow;
104
108
  } catch (e: any) {
105
109
  return throwError(e);
106
110
  }
package/src/staking.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { Provider } from '@ethersproject/abstract-provider';
2
3
  import {
3
4
  Staking__factory,
package/src/storage.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import axios from 'axios';
2
3
  import crypto from 'crypto';
3
4
  import * as Minio from 'minio';