@human-protocol/sdk 2.1.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/constants.d.ts +1 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +56 -24
  4. package/dist/enums.d.ts +3 -2
  5. package/dist/enums.d.ts.map +1 -1
  6. package/dist/enums.js +2 -1
  7. package/dist/error.d.ts +9 -0
  8. package/dist/error.d.ts.map +1 -1
  9. package/dist/error.js +11 -2
  10. package/dist/escrow.d.ts +1 -2
  11. package/dist/escrow.d.ts.map +1 -1
  12. package/dist/escrow.js +3 -4
  13. package/dist/graphql/queries/kvstore.d.ts +2 -0
  14. package/dist/graphql/queries/kvstore.d.ts.map +1 -0
  15. package/dist/graphql/queries/kvstore.js +28 -0
  16. package/dist/graphql/queries/transaction.d.ts +4 -0
  17. package/dist/graphql/queries/transaction.d.ts.map +1 -0
  18. package/dist/graphql/queries/transaction.js +59 -0
  19. package/dist/graphql/types.d.ts +8 -0
  20. package/dist/graphql/types.d.ts.map +1 -1
  21. package/dist/interfaces.d.ts +23 -1
  22. package/dist/interfaces.d.ts.map +1 -1
  23. package/dist/kvstore.d.ts +84 -0
  24. package/dist/kvstore.d.ts.map +1 -1
  25. package/dist/kvstore.js +103 -1
  26. package/dist/operator.d.ts +5 -2
  27. package/dist/operator.d.ts.map +1 -1
  28. package/dist/operator.js +50 -22
  29. package/dist/statistics.d.ts +1 -0
  30. package/dist/statistics.d.ts.map +1 -1
  31. package/dist/statistics.js +8 -7
  32. package/dist/transaction.d.ts +69 -0
  33. package/dist/transaction.d.ts.map +1 -0
  34. package/dist/transaction.js +121 -0
  35. package/dist/types.d.ts +4 -0
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +9 -0
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +21 -1
  40. package/package.json +4 -4
  41. package/src/constants.ts +73 -23
  42. package/src/enums.ts +2 -1
  43. package/src/error.ts +15 -0
  44. package/src/escrow.ts +4 -5
  45. package/src/graphql/queries/kvstore.ts +23 -0
  46. package/src/graphql/queries/transaction.ts +59 -0
  47. package/src/graphql/types.ts +9 -0
  48. package/src/interfaces.ts +26 -1
  49. package/src/kvstore.ts +114 -1
  50. package/src/operator.ts +62 -29
  51. package/src/statistics.ts +10 -8
  52. package/src/transaction.ts +142 -0
  53. package/src/types.ts +4 -0
  54. package/src/utils.ts +25 -0
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,gBAAiB,WAAW,WAatD,CAAC"}
package/dist/utils.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidUrl = exports.throwError = void 0;
3
+ exports.getSubgraphUrl = exports.isValidUrl = exports.throwError = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  const ethers_1 = require("ethers");
6
6
  const error_1 = require("./error");
7
+ const constants_1 = require("./constants");
7
8
  /**
8
9
  * **Handle and throw the error.*
9
10
  *
@@ -50,3 +51,22 @@ const isValidUrl = (url) => {
50
51
  }
51
52
  };
52
53
  exports.isValidUrl = isValidUrl;
54
+ /**
55
+ * **Get the subgraph URL.*
56
+ *
57
+ * @param {NetworkData} networkData
58
+ * @param {string} apiKey
59
+ * @returns
60
+ */
61
+ const getSubgraphUrl = (networkData) => {
62
+ let subgraphUrl = networkData.subgraphUrl;
63
+ if (process.env.SUBGRAPH_API_KEY) {
64
+ subgraphUrl = networkData.subgraphUrlApiKey.replace(constants_1.SUBGRAPH_API_KEY_PLACEHOLDER, process.env.SUBGRAPH_API_KEY);
65
+ }
66
+ else {
67
+ // eslint-disable-next-line no-console
68
+ console.warn(error_1.WarnSubgraphApiKeyNotProvided);
69
+ }
70
+ return subgraphUrl;
71
+ };
72
+ exports.getSubgraphUrl = getSubgraphUrl;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "2.1.3",
4
+ "version": "3.0.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -45,15 +45,15 @@
45
45
  "graphql": "^16.8.1",
46
46
  "graphql-request": "^6.1.0",
47
47
  "graphql-tag": "^2.12.6",
48
- "minio": "^7.0.32",
48
+ "minio": "7.1.3",
49
49
  "openpgp": "^5.11.1",
50
50
  "secp256k1": "^4.0.3",
51
- "vitest": "^0.30.1",
51
+ "vitest": "^1.6.0",
52
52
  "winston": "^3.13.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "typedoc": "^0.25.1",
56
- "typedoc-plugin-markdown": "^3.16.0"
56
+ "typedoc-plugin-markdown": "^4.0.3"
57
57
  },
58
58
  "typedocOptions": {
59
59
  "entryPoints": [
package/src/constants.ts CHANGED
@@ -61,7 +61,9 @@ export const NETWORKS: {
61
61
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
62
62
  kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
63
63
  subgraphUrl:
64
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v2',
64
+ 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
65
+ subgraphUrlApiKey:
66
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BtC96WCK6ZpZ35v94MK6rZNiBzDEZYHFzDmhMYyZ369D',
65
67
  oldSubgraphUrl: '',
66
68
  oldFactoryAddress: '',
67
69
  },
@@ -75,6 +77,7 @@ export const NETWORKS: {
75
77
  rewardPoolAddress: '',
76
78
  kvstoreAddress: '',
77
79
  subgraphUrl: '',
80
+ subgraphUrlApiKey: '',
78
81
  oldSubgraphUrl: '',
79
82
  oldFactoryAddress: '',
80
83
  },
@@ -89,6 +92,7 @@ export const NETWORKS: {
89
92
  kvstoreAddress: '0x19Fc3e859C1813ac9427a7a78BeB9ae102CE96d3',
90
93
  subgraphUrl:
91
94
  'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v2',
95
+ subgraphUrlApiKey: '',
92
96
  oldSubgraphUrl:
93
97
  'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli',
94
98
  oldFactoryAddress: '0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F',
@@ -103,7 +107,9 @@ export const NETWORKS: {
103
107
  rewardPoolAddress: '0xAFf5a986A530ff839d49325A5dF69F96627E8D29',
104
108
  kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60',
105
109
  subgraphUrl:
106
- 'https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-sepolia/api',
110
+ 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
111
+ subgraphUrlApiKey:
112
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/UMLaZHtLE9LxzDyvBLBgfWj4erzYzYMeGUbQtxtyMaE',
107
113
  oldSubgraphUrl: '',
108
114
  oldFactoryAddress: '',
109
115
  },
@@ -116,7 +122,10 @@ export const NETWORKS: {
116
122
  stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
117
123
  rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
118
124
  kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
119
- subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v2',
125
+ subgraphUrl:
126
+ 'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
127
+ subgraphUrlApiKey:
128
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/JBJPC3YmRSNjyjRTTpazhhSX5CCZ4CeBx6ptRsM8PCBb',
120
129
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
121
130
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
122
131
  },
@@ -130,7 +139,9 @@ export const NETWORKS: {
130
139
  rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
131
140
  kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
132
141
  subgraphUrl:
133
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v2',
142
+ 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
143
+ subgraphUrlApiKey:
144
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BnaC4CDqgdbGvcgM7KoZ6d7Yeebsm7NvLFrr61Lxg6Ao',
134
145
  oldSubgraphUrl:
135
146
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
136
147
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
@@ -145,7 +156,9 @@ export const NETWORKS: {
145
156
  rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
146
157
  kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
147
158
  subgraphUrl:
148
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2',
159
+ 'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
160
+ subgraphUrlApiKey:
161
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HHYwCHBvDrjckpNB4jbB8k63pSot6rGtBYLBygGji3vD',
149
162
  oldSubgraphUrl:
150
163
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
151
164
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
@@ -161,6 +174,7 @@ export const NETWORKS: {
161
174
  kvstoreAddress: '0xD96158c7267Ea658a4688F4aEf1c85659851625d',
162
175
  subgraphUrl:
163
176
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v2',
177
+ subgraphUrlApiKey: '',
164
178
  oldSubgraphUrl:
165
179
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai',
166
180
  oldFactoryAddress: '0x558cd800f9F0B02f3B149667bDe003284c867E94',
@@ -175,7 +189,9 @@ export const NETWORKS: {
175
189
  rewardPoolAddress: '0xd866bCEFf6D0F77E1c3EAE28230AE6C79b03fDa7',
176
190
  kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7',
177
191
  subgraphUrl:
178
- 'https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-amoy/api',
192
+ 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
193
+ subgraphUrlApiKey:
194
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FmdCVzHV3bB4abPVYtBALtBHr7ZRZmZ67m5c432S7GZH',
179
195
  oldSubgraphUrl: '',
180
196
  oldFactoryAddress: '',
181
197
  },
@@ -189,7 +205,9 @@ export const NETWORKS: {
189
205
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
190
206
  kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
191
207
  subgraphUrl:
192
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v2',
208
+ 'https://api.studio.thegraph.com/query/74256/moonbeam/version/latest',
209
+ subgraphUrlApiKey:
210
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BH5Sm6exn76o5frV5VeCufChB43DCfMXCQsdtWt4AuQP',
193
211
  oldSubgraphUrl:
194
212
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam',
195
213
  oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad',
@@ -204,7 +222,9 @@ export const NETWORKS: {
204
222
  rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
205
223
  kvstoreAddress: '0xcC561f4482f4Ff051D2Dcc65c2cE1A0f291bbA46',
206
224
  subgraphUrl:
207
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v2',
225
+ 'https://api.studio.thegraph.com/query/74256/moonbase-alpha/version/latest',
226
+ subgraphUrlApiKey:
227
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/AmmRkJszUbjfUwHubcRkU6CfG1Q9psRWRbbHADVmsLjE',
208
228
  oldSubgraphUrl: '',
209
229
  oldFactoryAddress: '',
210
230
  },
@@ -218,7 +238,9 @@ export const NETWORKS: {
218
238
  rewardPoolAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
219
239
  kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
220
240
  subgraphUrl:
221
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji-v2',
241
+ 'https://api.studio.thegraph.com/query/74256/fuji/version/latest',
242
+ subgraphUrlApiKey:
243
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CnZCDsWziQF3jNoqgQMkmJbF9frof5osM3hN5eUgyL5u',
222
244
  oldSubgraphUrl:
223
245
  'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
224
246
  oldFactoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
@@ -233,7 +255,9 @@ export const NETWORKS: {
233
255
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
234
256
  kvstoreAddress: '0x9Bc7bff35B2Be2413708d48c3B0aEF5c43646728',
235
257
  subgraphUrl:
236
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche-v2',
258
+ 'https://api.studio.thegraph.com/query/74256/avalanche/version/latest',
259
+ subgraphUrlApiKey:
260
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FweDaDWZ6ZDcsA63wsjnWgdgw4aCbkiVQYMYvtcP5p2u',
237
261
  oldSubgraphUrl:
238
262
  'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
239
263
  oldFactoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
@@ -248,7 +272,9 @@ export const NETWORKS: {
248
272
  rewardPoolAddress: '0xA9545C2530BD5bdb464d5E274F59ACceAa73eD86',
249
273
  kvstoreAddress: '0x938335006ea6F9Eb0e8020969cFF94404425e298',
250
274
  subgraphUrl:
251
- 'https://api.thegraph.com/subgraphs/name/humanprotocol/celo-alfajores',
275
+ 'https://api.studio.thegraph.com/query/74256/celo-alfajores/version/latest',
276
+ subgraphUrlApiKey:
277
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/EGWCWuzBNkbypW8ipRKuyGwq8azoCy6LKKosGgSPMGRD',
252
278
  oldSubgraphUrl: '',
253
279
  oldFactoryAddress: '',
254
280
  },
@@ -261,23 +287,44 @@ export const NETWORKS: {
261
287
  stakingAddress: '0x34cD3Bd6B16c559f321799b516dE61E12017fFd1',
262
288
  rewardPoolAddress: '0xb9344bAD98E3d26a4d83900922baf395a2Ec154c',
263
289
  kvstoreAddress: '0x86Af9f6Cd34B69Db1B202223C6d6D109f2491569',
264
- subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/celo',
290
+ subgraphUrl:
291
+ 'https://api.studio.thegraph.com/query/74256/celo/version/latest',
292
+ subgraphUrlApiKey:
293
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HTgMnYWGsdsw41o8dyph1bwhotuXh6va3L8r8DGgLjsA',
265
294
  oldSubgraphUrl: '',
266
295
  oldFactoryAddress: '',
267
296
  },
268
- [ChainId.SKALE]: {
269
- chainId: ChainId.SKALE,
270
- title: 'SKALE Human Protocol Chain',
271
- scanUrl: 'https://wan-red-ain.explorer.mainnet.skalenodes.com/',
272
- factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
273
- hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
274
- stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
275
- rewardPoolAddress: '0x881218246c25C6898aE96145259584340153aDA2',
276
- kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
297
+ [ChainId.XLAYER]: {
298
+ chainId: ChainId.XLAYER,
299
+ title: 'XLayer',
300
+ scanUrl: 'https://www.oklink.com/xlayer',
301
+ factoryAddress: '0x4949C9DFFD83F0D5Ab0AB24C57C4D403D5c20C15',
302
+ hmtAddress: '0x10acbe3b9e6a2ff7f341e5cbf4b6617741ff44aa',
303
+ stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
304
+ rewardPoolAddress: '0x7ABa5F75b2b530cB0c8927C86591c21dF44f06b6',
305
+ kvstoreAddress: '0x6512d894cc3d3FE93Da9d0420430136fA889FaB9',
277
306
  subgraphUrl:
278
- 'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
307
+ 'https://api.studio.thegraph.com/query/74256/xlayer/version/latest',
308
+ subgraphUrlApiKey:
309
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CrratkbjCraj1BZLgJmck1GGxbMb2Y2iPZiW4Lh5DdcX',
279
310
  oldSubgraphUrl: '',
280
- oldFactoryAddress: '0x27B423cE73d1dBdB48d2dd351398b5Ce8223117c',
311
+ oldFactoryAddress: '',
312
+ },
313
+ [ChainId.XLAYER_TESTNET]: {
314
+ chainId: ChainId.XLAYER_TESTNET,
315
+ title: 'XLayer Testnet',
316
+ scanUrl: 'https://www.okx.com/explorer/xlayer-test',
317
+ factoryAddress: '0x6Cd3ecAD36ee88E9ef3665CF381D9dAE0FE0a32e',
318
+ hmtAddress: '0x792abbcC99c01dbDec49c9fa9A828a186Da45C33',
319
+ stakingAddress: '0x819069fEd50581587fAB9E583b5488fc2D33B7ea',
320
+ rewardPoolAddress: '0x6daccd1f3a68945f8a7ac6d20260953f7a97fae4',
321
+ kvstoreAddress: '0xdE8BE9E3C12E9F546309A429cd88d026a25EaF8C',
322
+ subgraphUrl:
323
+ 'https://api.studio.thegraph.com/query/74256/xlayer-testnet/version/latest',
324
+ subgraphUrlApiKey:
325
+ 'https://gateway-testnet-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/9zd1LcywWjuSUtde4ofC8oyyzpawPwGUiPsvqTq247xk',
326
+ oldSubgraphUrl: '',
327
+ oldFactoryAddress: '',
281
328
  },
282
329
  [ChainId.LOCALHOST]: {
283
330
  chainId: ChainId.LOCALHOST,
@@ -289,6 +336,7 @@ export const NETWORKS: {
289
336
  rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
290
337
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
291
338
  subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
339
+ subgraphUrlApiKey: '',
292
340
  oldSubgraphUrl: '',
293
341
  oldFactoryAddress: '',
294
342
  },
@@ -309,3 +357,5 @@ export const Role = {
309
357
  ReputationOracle: 'Reputation Oracle',
310
358
  RecordingOracle: 'Recording Oracle',
311
359
  };
360
+
361
+ export const SUBGRAPH_API_KEY_PLACEHOLDER = '[SUBGRAPH_API_KEY]';
package/src/enums.ts CHANGED
@@ -13,8 +13,9 @@ export enum ChainId {
13
13
  MOONBASE_ALPHA = 1287,
14
14
  AVALANCHE_TESTNET = 43113,
15
15
  AVALANCHE = 43114,
16
- SKALE = 1273227453,
17
16
  CELO = 42220,
18
17
  CELO_ALFAJORES = 44787,
18
+ XLAYER_TESTNET = 195,
19
19
  LOCALHOST = 1338,
20
+ XLAYER = 196,
20
21
  }
package/src/error.ts CHANGED
@@ -117,6 +117,18 @@ export const ErrorInvalidStakerAddressProvided = new Error(
117
117
  'Invalid staker address provided'
118
118
  );
119
119
 
120
+ /**
121
+ * @constant {Error} - Invalid hash provided.
122
+ */
123
+ export const ErrorInvalidHahsProvided = new Error('Invalid hash provided');
124
+
125
+ /**
126
+ * @constant {Error} - Cannot use both date and block filters simultaneously.
127
+ */
128
+ export const ErrorCannotUseDateAndBlockSimultaneously = new Error(
129
+ 'Cannot use both date and block filters simultaneously'
130
+ );
131
+
120
132
  /**
121
133
  * @constant {Error} - Invalid escrow address provided.
122
134
  */
@@ -322,3 +334,6 @@ export class InvalidEthereumAddressError extends Error {
322
334
  * @constant {Error} - The Hash does not match
323
335
  */
324
336
  export const ErrorInvalidHash = new Error('Invalid hash');
337
+
338
+ export const WarnSubgraphApiKeyNotProvided =
339
+ '"SUBGRAPH_API_KEY" is not being provided. It might cause issues with the subgraph.';
package/src/escrow.ts CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  } from './graphql';
45
45
  import { IEscrowConfig, IEscrowsFilter } from './interfaces';
46
46
  import { EscrowCancel, EscrowStatus, NetworkData } from './types';
47
- import { isValidUrl, throwError } from './utils';
47
+ import { getSubgraphUrl, isValidUrl, throwError } from './utils';
48
48
 
49
49
  /**
50
50
  * ## Introduction
@@ -1441,7 +1441,7 @@ export class EscrowUtils {
1441
1441
  * AVALANCHE_TESTNET = 43113,
1442
1442
  * CELO = 42220,
1443
1443
  * CELO_ALFAJORES = 44787,
1444
- * SKALE = 1273227453,
1444
+ * = 1273227453,
1445
1445
  * LOCALHOST = 1338,
1446
1446
  * }
1447
1447
  * ```
@@ -1534,7 +1534,7 @@ export class EscrowUtils {
1534
1534
  }
1535
1535
 
1536
1536
  const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
1537
- networkData.subgraphUrl,
1537
+ getSubgraphUrl(networkData),
1538
1538
  GET_ESCROWS_QUERY(filter),
1539
1539
  {
1540
1540
  ...filter,
@@ -1586,7 +1586,6 @@ export class EscrowUtils {
1586
1586
  * AVALANCHE_TESTNET = 43113,
1587
1587
  * CELO = 42220,
1588
1588
  * CELO_ALFAJORES = 44787,
1589
- * SKALE = 1273227453,
1590
1589
  * LOCALHOST = 1338,
1591
1590
  * }
1592
1591
  * ```
@@ -1647,7 +1646,7 @@ export class EscrowUtils {
1647
1646
 
1648
1647
  try {
1649
1648
  const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
1650
- networkData.subgraphUrl,
1649
+ getSubgraphUrl(networkData),
1651
1650
  GET_ESCROW_BY_ADDRESS_QUERY(),
1652
1651
  { escrowAddress: escrowAddress.toLowerCase() }
1653
1652
  );
@@ -0,0 +1,23 @@
1
+ import gql from 'graphql-tag';
2
+
3
+ const KVSTORE_FRAGMENT = gql`
4
+ fragment KVStoreFields on KVStore {
5
+ id
6
+ block
7
+ timestamp
8
+ address
9
+ key
10
+ value
11
+ }
12
+ `;
13
+
14
+ export const GET_KVSTORE_BY_ADDRESS_QUERY = () => {
15
+ return gql`
16
+ query getKVStoreData($address: String!) {
17
+ kvstores(where: { address: $address }) {
18
+ ...KVStoreFields
19
+ }
20
+ }
21
+ ${KVSTORE_FRAGMENT}
22
+ `;
23
+ };
@@ -0,0 +1,59 @@
1
+ import gql from 'graphql-tag';
2
+ import { ITransactionsFilter } from '../../../src/interfaces';
3
+
4
+ const TRANSACTION_FRAGMENT = gql`
5
+ fragment TransactionFields on Transaction {
6
+ block
7
+ txHash
8
+ from
9
+ to
10
+ timestamp
11
+ value
12
+ method
13
+ }
14
+ `;
15
+
16
+ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
17
+ const { startDate, endDate, startBlock, endBlock, fromAddress, toAddress } =
18
+ filter;
19
+
20
+ const WHERE_CLAUSE = `
21
+ where: {
22
+ ${fromAddress ? `from: $fromAddress` : ''}
23
+ ${toAddress ? `to: $toAddress` : ''}
24
+ ${startDate ? `timestamp_gte: $startDate` : ''}
25
+ ${endDate ? `timestamp_lte: $endDate` : ''}
26
+ ${startBlock ? `block_gte: $startBlock` : ''}
27
+ ${endBlock ? `block_lte: $endBlock` : ''}
28
+ }
29
+ `;
30
+
31
+ return gql`
32
+ query getTransactions(
33
+ $fromAddress: String
34
+ $toAddress: String
35
+ $startDate: Int
36
+ $endDate: Int
37
+ $startBlock: Int
38
+ $endBlock: Int
39
+ ) {
40
+ transactions(
41
+ ${WHERE_CLAUSE}
42
+ orderBy: timestamp,
43
+ orderDirection: asc,
44
+ ) {
45
+ ...TransactionFields
46
+ }
47
+ }
48
+ ${TRANSACTION_FRAGMENT}
49
+ `;
50
+ };
51
+
52
+ export const GET_TRANSACTION_QUERY = gql`
53
+ query getTransaction($hash: String!) {
54
+ transaction(id: $hash) {
55
+ ...TransactionFields
56
+ }
57
+ }
58
+ ${TRANSACTION_FRAGMENT}
59
+ `;
@@ -155,3 +155,12 @@ export type DailyTaskData = {
155
155
  export type TaskStatistics = {
156
156
  dailyTasksData: DailyTaskData[];
157
157
  };
158
+
159
+ export type KVStoreData = {
160
+ id: string;
161
+ address: string;
162
+ key: string;
163
+ value: string;
164
+ timestamp: Date;
165
+ block: number;
166
+ };
package/src/interfaces.ts CHANGED
@@ -40,7 +40,7 @@ export interface ILeaderSubgraph extends Omit<ILeader, 'jobTypes'> {
40
40
  }
41
41
 
42
42
  export interface ILeadersFilter {
43
- networks: ChainId[];
43
+ chainId: ChainId;
44
44
  role?: string;
45
45
  }
46
46
 
@@ -108,3 +108,28 @@ export interface IPayoutFilter {
108
108
  from?: Date;
109
109
  to?: Date;
110
110
  }
111
+
112
+ export interface IKVStore {
113
+ key: string;
114
+ value: string;
115
+ }
116
+
117
+ export interface ITransaction {
118
+ block: bigint;
119
+ hash: string;
120
+ from: string;
121
+ to: string;
122
+ timestamp: bigint;
123
+ value: string;
124
+ method: string;
125
+ }
126
+
127
+ export interface ITransactionsFilter {
128
+ networks: ChainId[];
129
+ startBlock?: number;
130
+ endBlock?: number;
131
+ startDate?: Date;
132
+ endDate?: Date;
133
+ fromAddress?: string;
134
+ toAddress?: string;
135
+ }
package/src/kvstore.ts CHANGED
@@ -16,8 +16,12 @@ import {
16
16
  ErrorProviderDoesNotExist,
17
17
  ErrorUnsupportedChainID,
18
18
  } from './error';
19
+ import gqlFetch from 'graphql-request';
19
20
  import { NetworkData } from './types';
20
- import { isValidUrl } from './utils';
21
+ import { getSubgraphUrl, isValidUrl } from './utils';
22
+ import { GET_KVSTORE_BY_ADDRESS_QUERY } from './graphql/queries/kvstore';
23
+ import { KVStoreData } from './graphql';
24
+ import { IKVStore } from './interfaces';
21
25
  /**
22
26
  * ## Introduction
23
27
  *
@@ -410,3 +414,112 @@ export class KVStoreClient extends BaseEthersClient {
410
414
  return publicKey;
411
415
  }
412
416
  }
417
+
418
+ /**
419
+ * ## Introduction
420
+ *
421
+ * Utility class for KVStore-related operations.
422
+ *
423
+ * ## Installation
424
+ *
425
+ * ### npm
426
+ * ```bash
427
+ * npm install @human-protocol/sdk
428
+ * ```
429
+ *
430
+ * ### yarn
431
+ * ```bash
432
+ * yarn install @human-protocol/sdk
433
+ * ```
434
+ *
435
+ * ## Code example
436
+ *
437
+ * ### Signer
438
+ *
439
+ * **Using private key (backend)**
440
+ *
441
+ * ```ts
442
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
443
+ *
444
+ * const KVStoreAddresses = new KVStoreUtils.getData({
445
+ * networks: [ChainId.POLYGON_AMOY]
446
+ * });
447
+ * ```
448
+ */
449
+ export class KVStoreUtils {
450
+ /**
451
+ * This function returns the KVStore data for a given address.
452
+ *
453
+ * > This uses Subgraph
454
+ *
455
+ * **Input parameters**
456
+ *
457
+ * ```ts
458
+ * enum ChainId {
459
+ * ALL = -1,
460
+ * MAINNET = 1,
461
+ * RINKEBY = 4,
462
+ * GOERLI = 5,
463
+ * BSC_MAINNET = 56,
464
+ * BSC_TESTNET = 97,
465
+ * POLYGON = 137,
466
+ * POLYGON_MUMBAI = 80001,
467
+ * POLYGON_AMOY = 80002,
468
+ * MOONBEAM = 1284,
469
+ * MOONBASE_ALPHA = 1287,
470
+ * AVALANCHE = 43114,
471
+ * AVALANCHE_TESTNET = 43113,
472
+ * CELO = 42220,
473
+ * CELO_ALFAJORES = 44787,
474
+ * LOCALHOST = 1338,
475
+ * }
476
+ * ```
477
+ *
478
+ * ```ts
479
+ * interface IKVStore {
480
+ * key: string;
481
+ * value: string;
482
+ * }
483
+ * ```
484
+ *
485
+ * @param {ChainId} chainId Network in which the KVStore is deployed
486
+ * @param {string} address Address of the KVStore
487
+ * @returns {Promise<IKVStore[]>} KVStore data
488
+ *
489
+ * **Code example**
490
+ *
491
+ * ```ts
492
+ * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
493
+ *
494
+ * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
495
+ * console.log(kvStoreData);
496
+ * ```
497
+ */
498
+ public static async getKVStoreData(
499
+ chainId: ChainId,
500
+ address: string
501
+ ): Promise<IKVStore[]> {
502
+ const networkData = NETWORKS[chainId];
503
+
504
+ if (!networkData) {
505
+ throw ErrorUnsupportedChainID;
506
+ }
507
+
508
+ if (address && !ethers.isAddress(address)) {
509
+ throw ErrorInvalidAddress;
510
+ }
511
+
512
+ const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
513
+ getSubgraphUrl(networkData),
514
+ GET_KVSTORE_BY_ADDRESS_QUERY(),
515
+ { address: address.toLowerCase() }
516
+ );
517
+
518
+ const kvStoreData = kvstores.map((item) => ({
519
+ key: item.key,
520
+ value: item.value,
521
+ }));
522
+
523
+ return kvStoreData || [];
524
+ }
525
+ }