@human-protocol/sdk 4.2.0 → 5.0.0-beta.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/dist/staking.js CHANGED
@@ -8,15 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.StakingClient = void 0;
15
+ exports.StakingUtils = exports.StakingClient = void 0;
13
16
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
14
17
  const ethers_1 = require("ethers");
18
+ const graphql_request_1 = __importDefault(require("graphql-request"));
15
19
  const base_1 = require("./base");
16
20
  const constants_1 = require("./constants");
17
21
  const decorators_1 = require("./decorators");
22
+ const enums_1 = require("./enums");
18
23
  const error_1 = require("./error");
19
24
  const utils_1 = require("./utils");
25
+ const staking_1 = require("./graphql/queries/staking");
20
26
  /**
21
27
  * ## Introduction
22
28
  *
@@ -363,6 +369,7 @@ class StakingClient extends base_1.BaseEthersClient {
363
369
  }
364
370
  try {
365
371
  const stakerInfo = await this.stakingContract.stakes(stakerAddress);
372
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
366
373
  const currentBlock = await this.runner.provider.getBlockNumber();
367
374
  const tokensWithdrawable = stakerInfo.tokensLockedUntil !== 0n &&
368
375
  currentBlock >= stakerInfo.tokensLockedUntil
@@ -415,3 +422,79 @@ __decorate([
415
422
  __metadata("design:paramtypes", [String, String, String, BigInt, Object]),
416
423
  __metadata("design:returntype", Promise)
417
424
  ], StakingClient.prototype, "slash", null);
425
+ /**
426
+ * Utility class for Staking-related subgraph queries.
427
+ */
428
+ class StakingUtils {
429
+ /**
430
+ * Gets staking info for a staker from the subgraph.
431
+ *
432
+ * @param {ChainId} chainId Network in which the staking contract is deployed
433
+ * @param {string} stakerAddress Address of the staker
434
+ * @returns {Promise<IStaker>} Staker info from subgraph
435
+ */
436
+ static async getStaker(chainId, stakerAddress) {
437
+ if (!ethers_1.ethers.isAddress(stakerAddress)) {
438
+ throw error_1.ErrorInvalidStakerAddressProvided;
439
+ }
440
+ const networkData = constants_1.NETWORKS[chainId];
441
+ if (!networkData) {
442
+ throw error_1.ErrorUnsupportedChainID;
443
+ }
444
+ const { staker } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), staking_1.GET_STAKER_BY_ADDRESS_QUERY, { id: stakerAddress.toLowerCase() });
445
+ if (!staker) {
446
+ throw error_1.ErrorStakerNotFound;
447
+ }
448
+ return staker;
449
+ }
450
+ /**
451
+ * Gets all stakers from the subgraph with filters, pagination and ordering.
452
+ *
453
+ * @returns {Promise<IStaker[]>} Array of stakers
454
+ */
455
+ static async getStakers(filter) {
456
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
457
+ const skip = filter.skip || 0;
458
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
459
+ const orderBy = filter.orderBy || 'lastDepositTimestamp';
460
+ const networkData = constants_1.NETWORKS[filter.chainId];
461
+ if (!networkData) {
462
+ throw error_1.ErrorUnsupportedChainID;
463
+ }
464
+ const { stakers } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, staking_1.GET_STAKERS_QUERY)(filter), {
465
+ minStakedAmount: filter.minStakedAmount
466
+ ? filter.minStakedAmount
467
+ : undefined,
468
+ maxStakedAmount: filter.maxStakedAmount
469
+ ? filter.maxStakedAmount
470
+ : undefined,
471
+ minLockedAmount: filter.minLockedAmount
472
+ ? filter.minLockedAmount
473
+ : undefined,
474
+ maxLockedAmount: filter.maxLockedAmount
475
+ ? filter.maxLockedAmount
476
+ : undefined,
477
+ minWithdrawnAmount: filter.minWithdrawnAmount
478
+ ? filter.minWithdrawnAmount
479
+ : undefined,
480
+ maxWithdrawnAmount: filter.maxWithdrawnAmount
481
+ ? filter.maxWithdrawnAmount
482
+ : undefined,
483
+ minSlashedAmount: filter.minSlashedAmount
484
+ ? filter.minSlashedAmount
485
+ : undefined,
486
+ maxSlashedAmount: filter.maxSlashedAmount
487
+ ? filter.maxSlashedAmount
488
+ : undefined,
489
+ orderBy: orderBy,
490
+ orderDirection: orderDirection,
491
+ first: first,
492
+ skip: skip,
493
+ });
494
+ if (!stakers) {
495
+ return [];
496
+ }
497
+ return stakers;
498
+ }
499
+ }
500
+ exports.StakingUtils = StakingUtils;
package/dist/types.d.ts CHANGED
@@ -28,7 +28,11 @@ export declare enum EscrowStatus {
28
28
  /**
29
29
  * Escrow is cancelled.
30
30
  */
31
- Cancelled = 5
31
+ Cancelled = 5,
32
+ /**
33
+ * Escrow is cancelled.
34
+ */
35
+ ToCancel = 6
32
36
  }
33
37
  /**
34
38
  * AWS/GCP cloud storage access data
@@ -133,19 +137,6 @@ export type NetworkData = {
133
137
  */
134
138
  oldFactoryAddress: string;
135
139
  };
136
- /**
137
- * Represents the response data for an escrow cancellation.
138
- */
139
- export type EscrowCancel = {
140
- /**
141
- * The hash of the transaction associated with the escrow cancellation.
142
- */
143
- txHash: string;
144
- /**
145
- * The amount refunded in the escrow cancellation.
146
- */
147
- amountRefunded: bigint;
148
- };
149
140
  /**
150
141
  * Represents the response data for an escrow withdrawal.
151
142
  */
@@ -161,7 +152,7 @@ export type EscrowWithdraw = {
161
152
  /**
162
153
  * The amount withdrawn from the escrow.
163
154
  */
164
- amountWithdrawn: bigint;
155
+ withdrawnAmount: bigint;
165
156
  };
166
157
  /**
167
158
  * Represents a payout from an escrow.
@@ -188,6 +179,39 @@ export type Payout = {
188
179
  */
189
180
  createdAt: number;
190
181
  };
182
+ /**
183
+ * Represents a cancellation refund event.
184
+ */
185
+ export type CancellationRefund = {
186
+ /**
187
+ * Unique identifier of the cancellation refund event.
188
+ */
189
+ id: string;
190
+ /**
191
+ * The address of the escrow associated with the cancellation refund.
192
+ */
193
+ escrowAddress: string;
194
+ /**
195
+ * The address of the receiver who received the refund.
196
+ */
197
+ receiver: string;
198
+ /**
199
+ * The amount refunded to the receiver.
200
+ */
201
+ amount: bigint;
202
+ /**
203
+ * The block number in which the cancellation refund event occurred.
204
+ */
205
+ block: number;
206
+ /**
207
+ * The timestamp when the cancellation refund event occurred (in UNIX format).
208
+ */
209
+ timestamp: number;
210
+ /**
211
+ * The transaction hash of the cancellation refund event.
212
+ */
213
+ txHash: string;
214
+ };
191
215
  export type TransactionLikeWithNonce = TransactionLike & {
192
216
  nonce: number;
193
217
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;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;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,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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Status["Cancelled"] = 5] = "Cancelled";
35
+ /**
36
+ * Escrow is cancelled.
37
+ */
38
+ EscrowStatus[EscrowStatus["ToCancel"] = 6] = "ToCancel";
35
39
  })(EscrowStatus || (exports.EscrowStatus = EscrowStatus = {}));
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.2.0",
4
+ "version": "5.0.0-beta.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@human-protocol/core": "x",
42
42
  "axios": "^1.4.0",
43
- "ethers": "~6.13.5",
43
+ "ethers": "~6.15.0",
44
44
  "graphql": "^16.8.1",
45
45
  "graphql-request": "^6.1.0",
46
46
  "graphql-tag": "^2.12.6",
package/src/constants.ts CHANGED
@@ -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-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmURrhnEXimGnRzjeN3B4VMmioUeBHUBg4WJ7KZzJ7em8g',
54
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmVYn12ZqBeZf9J9orq9RYV1C9iQ9uyWWF5vsWFJiKR68e',
55
55
  oldSubgraphUrl: '',
56
56
  oldFactoryAddress: '',
57
57
  },
@@ -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-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZHqbiyAAwrmqsVJLhTEdejVGYJpXfJAkJXUw7C2VV1TD',
84
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmfRiMaGaL224Z5ii4JAJjfyT64KysYM9gFFWbkDW9QwK1',
85
85
  oldSubgraphUrl:
86
86
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
87
87
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
@@ -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-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmeeE9bVkat1mkbQg1R6SXLuLadXxoNCY5b7CEQkmu6cQi',
116
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmRHsvZo2wW2Y3fDHz6xsHd6wBQyacbzKmFfNYQ8Zy3KLy',
117
117
  oldSubgraphUrl: '',
118
118
  oldFactoryAddress: '',
119
119
  },
@@ -128,7 +128,7 @@ export const NETWORKS: {
128
128
  subgraphUrl:
129
129
  'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
130
130
  subgraphUrlApiKey:
131
- 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmQiLaFKusXLzKrpZvQDg7vETLhdfPgzWJN3Uxp3bE9K9W',
131
+ 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmVHYvjbsgAroR9EMgqqGTQ7aKPRFMVekY6evU6mFPUU7J',
132
132
  oldSubgraphUrl: '',
133
133
  oldFactoryAddress: '',
134
134
  },
package/src/error.ts CHANGED
@@ -170,6 +170,11 @@ export const ErrorProviderDoesNotExist = new Error('Provider does not exist');
170
170
  */
171
171
  export const ErrorUnsupportedChainID = new Error('Unsupported chain ID');
172
172
 
173
+ /**
174
+ * @constant {Error} - Staker not found.
175
+ */
176
+ export const ErrorStakerNotFound = new Error('Staker not found');
177
+
173
178
  /**
174
179
  * @constant {Error} - Sending a transaction requires a signer.
175
180
  */
@@ -206,13 +211,6 @@ export const ErrorInvalidUrl = new Error('Invalid URL string');
206
211
  */
207
212
  export const ErrorInvalidManifest = new Error('Invalid manifest');
208
213
 
209
- /**
210
- * @constant {Error} - List of handlers cannot be empty.
211
- */
212
- export const ErrorListOfHandlersCannotBeEmpty = new Error(
213
- 'List of handlers cannot be empty'
214
- );
215
-
216
214
  /**
217
215
  * @constant {Error} - No URL provided.
218
216
  */
@@ -294,6 +292,26 @@ export const ErrorInvalidHash = new Error('Invalid hash');
294
292
  */
295
293
  export const ErrorUnsupportedStatus = new Error('Unsupported status for query');
296
294
 
295
+ /**
296
+ * @constant {Error} - Invalid storeResults parameters for the escrow version
297
+ */
298
+ export const ErrorStoreResultsVersion = new Error(
299
+ 'Invalid storeResults parameters for the contract version of the specified escrow address'
300
+ );
301
+
302
+ /**
303
+ * @constant {Error} - Invalid bulkPayOut parameters for the escrow version
304
+ */
305
+ export const ErrorBulkPayOutVersion = new Error(
306
+ 'Invalid bulkPayOut parameters for the contract version of the specified escrow address'
307
+ );
308
+
309
+ /**
310
+ * @constant {Warning} - Possible version mismatch.
311
+ */
312
+ export const WarnVersionMismatch =
313
+ 'There may be a mismatch between the parameters passed and the expected parameters of the escrow contract version';
314
+
297
315
  /**
298
316
  * @constant {Warning} - The SUBGRAPH_API_KEY is not being provided.
299
317
  */