@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/base.d.ts +8 -7
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +18 -5
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +7 -8
  8. package/dist/encryption.d.ts +68 -203
  9. package/dist/encryption.d.ts.map +1 -1
  10. package/dist/encryption.js +66 -202
  11. package/dist/error.d.ts +0 -24
  12. package/dist/error.d.ts.map +1 -1
  13. package/dist/error.js +2 -26
  14. package/dist/escrow.d.ts +438 -791
  15. package/dist/escrow.d.ts.map +1 -1
  16. package/dist/escrow.js +331 -705
  17. package/dist/graphql/queries/operator.d.ts.map +1 -1
  18. package/dist/graphql/queries/operator.js +3 -1
  19. package/dist/graphql/types.d.ts.map +1 -1
  20. package/dist/index.d.ts +3 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -4
  23. package/dist/interfaces.d.ts +2 -2
  24. package/dist/interfaces.d.ts.map +1 -1
  25. package/dist/kvstore.d.ts +124 -186
  26. package/dist/kvstore.d.ts.map +1 -1
  27. package/dist/kvstore.js +122 -185
  28. package/dist/operator.d.ts +59 -30
  29. package/dist/operator.d.ts.map +1 -1
  30. package/dist/operator.js +59 -30
  31. package/dist/staking.d.ts +142 -141
  32. package/dist/staking.d.ts.map +1 -1
  33. package/dist/staking.js +140 -139
  34. package/dist/statistics.d.ts +104 -134
  35. package/dist/statistics.d.ts.map +1 -1
  36. package/dist/statistics.js +119 -144
  37. package/dist/transaction.d.ts +38 -17
  38. package/dist/transaction.d.ts.map +1 -1
  39. package/dist/transaction.js +40 -19
  40. package/dist/types.d.ts +14 -55
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils.d.ts +32 -18
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js +32 -19
  45. package/dist/worker.d.ts +35 -14
  46. package/dist/worker.d.ts.map +1 -1
  47. package/dist/worker.js +35 -14
  48. package/package.json +8 -25
  49. package/src/base.ts +42 -7
  50. package/src/constants.ts +6 -8
  51. package/src/encryption.ts +69 -203
  52. package/src/error.ts +0 -36
  53. package/src/escrow.ts +548 -891
  54. package/src/graphql/queries/operator.ts +3 -1
  55. package/src/graphql/types.ts +4 -2
  56. package/src/index.ts +4 -5
  57. package/src/interfaces.ts +2 -2
  58. package/src/kvstore.ts +142 -197
  59. package/src/operator.ts +59 -30
  60. package/src/staking.ts +177 -160
  61. package/src/statistics.ts +125 -146
  62. package/src/transaction.ts +40 -19
  63. package/src/types.ts +16 -58
  64. package/src/utils.ts +33 -23
  65. package/src/worker.ts +35 -14
  66. package/dist/storage.d.ts +0 -186
  67. package/dist/storage.d.ts.map +0 -1
  68. package/dist/storage.js +0 -319
  69. package/src/storage.ts +0 -313
package/src/operator.ts CHANGED
@@ -26,21 +26,40 @@ import { getSubgraphUrl, customGqlFetch } from './utils';
26
26
  import { ChainId, OrderDirection } from './enums';
27
27
  import { NETWORKS } from './constants';
28
28
 
29
+ /**
30
+ * Utility helpers for operator-related queries.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
35
+ *
36
+ * const operator = await OperatorUtils.getOperator(
37
+ * ChainId.POLYGON_AMOY,
38
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
39
+ * );
40
+ * console.log('Operator:', operator);
41
+ * ```
42
+ */
29
43
  export class OperatorUtils {
30
44
  /**
31
45
  * This function returns the operator data for the given address.
32
46
  *
33
- * @param {ChainId} chainId Network in which the operator is deployed
34
- * @param {string} address Operator address.
35
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
36
- * @returns {Promise<IOperator | null>} - Returns the operator details or null if not found.
37
- *
38
- * **Code example**
47
+ * @param chainId - Network in which the operator is deployed
48
+ * @param address - Operator address.
49
+ * @param options - Optional configuration for subgraph requests.
50
+ * @returns Returns the operator details or null if not found.
51
+ * @throws ErrorInvalidStakerAddressProvided If the address is invalid
52
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
39
53
  *
54
+ * @example
40
55
  * ```ts
41
56
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
42
57
  *
43
- * const operator = await OperatorUtils.getOperator(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
58
+ * const operator = await OperatorUtils.getOperator(
59
+ * ChainId.POLYGON_AMOY,
60
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
61
+ * );
62
+ * console.log('Operator:', operator);
44
63
  * ```
45
64
  */
46
65
  public static async getOperator(
@@ -74,19 +93,20 @@ export class OperatorUtils {
74
93
  /**
75
94
  * This function returns all the operator details of the protocol.
76
95
  *
77
- * @param {IOperatorsFilter} filter Filter for the operators.
78
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
79
- * @returns {Promise<IOperator[]>} Returns an array with all the operator details.
80
- *
81
- * **Code example**
96
+ * @param filter - Filter for the operators.
97
+ * @param options - Optional configuration for subgraph requests.
98
+ * @returns Returns an array with all the operator details.
99
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
82
100
  *
101
+ * @example
83
102
  * ```ts
84
- * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
103
+ * import { ChainId } from '@human-protocol/sdk';
85
104
  *
86
- * const filter: IOperatorsFilter = {
87
- * chainId: ChainId.POLYGON
105
+ * const filter = {
106
+ * chainId: ChainId.POLYGON_AMOY
88
107
  * };
89
108
  * const operators = await OperatorUtils.getOperators(filter);
109
+ * console.log('Operators:', operators.length);
90
110
  * ```
91
111
  */
92
112
  public static async getOperators(
@@ -142,18 +162,22 @@ export class OperatorUtils {
142
162
  /**
143
163
  * Retrieves the reputation network operators of the specified address.
144
164
  *
145
- * @param {ChainId} chainId Network in which the reputation network is deployed
146
- * @param {string} address Address of the reputation oracle.
147
- * @param {string} [role] - (Optional) Role of the operator.
148
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
149
- * @returns {Promise<IOperator[]>} - Returns an array of operator details.
150
- *
151
- * **Code example**
165
+ * @param chainId - Network in which the reputation network is deployed
166
+ * @param address - Address of the reputation oracle.
167
+ * @param role - Role of the operator (optional).
168
+ * @param options - Optional configuration for subgraph requests.
169
+ * @returns Returns an array of operator details.
170
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
152
171
  *
172
+ * @example
153
173
  * ```ts
154
174
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
155
175
  *
156
- * const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
176
+ * const operators = await OperatorUtils.getReputationNetworkOperators(
177
+ * ChainId.POLYGON_AMOY,
178
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
179
+ * );
180
+ * console.log('Operators:', operators.length);
157
181
  * ```
158
182
  */
159
183
  public static async getReputationNetworkOperators(
@@ -189,17 +213,22 @@ export class OperatorUtils {
189
213
  /**
190
214
  * This function returns information about the rewards for a given slasher address.
191
215
  *
192
- * @param {ChainId} chainId Network in which the rewards are deployed
193
- * @param {string} slasherAddress Slasher address.
194
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
195
- * @returns {Promise<IReward[]>} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
196
- *
197
- * **Code example**
216
+ * @param chainId - Network in which the rewards are deployed
217
+ * @param slasherAddress - Slasher address.
218
+ * @param options - Optional configuration for subgraph requests.
219
+ * @returns Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
220
+ * @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
221
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
198
222
  *
223
+ * @example
199
224
  * ```ts
200
225
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
201
226
  *
202
- * const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
227
+ * const rewards = await OperatorUtils.getRewards(
228
+ * ChainId.POLYGON_AMOY,
229
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
230
+ * );
231
+ * console.log('Rewards:', rewards.length);
203
232
  * ```
204
233
  */
205
234
  public static async getRewards(
package/src/staking.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  Staking,
7
7
  Staking__factory,
8
8
  } from '@human-protocol/core/typechain-types';
9
- import { ContractRunner, Overrides, ethers } from 'ethers';
9
+ import { ContractRunner, ethers } from 'ethers';
10
10
  import { BaseEthersClient } from './base';
11
11
  import { NETWORKS } from './constants';
12
12
  import { requiresSigner } from './decorators';
@@ -29,7 +29,7 @@ import {
29
29
  SubgraphOptions,
30
30
  } from './interfaces';
31
31
  import { StakerData } from './graphql';
32
- import { NetworkData } from './types';
32
+ import { NetworkData, TransactionOverrides } from './types';
33
33
  import { getSubgraphUrl, customGqlFetch, throwError } from './utils';
34
34
  import {
35
35
  GET_STAKER_BY_ADDRESS_QUERY,
@@ -37,9 +37,7 @@ import {
37
37
  } from './graphql/queries/staking';
38
38
 
39
39
  /**
40
- * ## Introduction
41
- *
42
- * This client enables performing actions on staking contracts and obtaining staking information from both the contracts and subgraph.
40
+ * Client for staking actions on HUMAN Protocol.
43
41
  *
44
42
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
45
43
  * To use this client, it is recommended to initialize it using the static `build` method.
@@ -53,37 +51,25 @@ import {
53
51
  * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
54
52
  * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
55
53
  *
56
- * ## Installation
57
- *
58
- * ### npm
59
- * ```bash
60
- * npm install @human-protocol/sdk
61
- * ```
62
- *
63
- * ### yarn
64
- * ```bash
65
- * yarn install @human-protocol/sdk
66
- * ```
67
- *
68
- * ## Code example
54
+ * @example
69
55
  *
70
- * ### Signer
56
+ * ###Using Signer
71
57
  *
72
- * **Using private key (backend)**
58
+ * ####Using private key (backend)
73
59
  *
74
60
  * ```ts
75
61
  * import { StakingClient } from '@human-protocol/sdk';
76
- * import { Wallet, providers } from 'ethers';
62
+ * import { Wallet, JsonRpcProvider } from 'ethers';
77
63
  *
78
64
  * const rpcUrl = 'YOUR_RPC_URL';
79
65
  * const privateKey = 'YOUR_PRIVATE_KEY';
80
66
  *
81
- * const provider = new providers.JsonRpcProvider(rpcUrl);
67
+ * const provider = new JsonRpcProvider(rpcUrl);
82
68
  * const signer = new Wallet(privateKey, provider);
83
69
  * const stakingClient = await StakingClient.build(signer);
84
70
  * ```
85
71
  *
86
- * **Using Wagmi (frontend)**
72
+ * ####Using Wagmi (frontend)
87
73
  *
88
74
  * ```ts
89
75
  * import { useSigner, useChainId } from 'wagmi';
@@ -93,15 +79,15 @@ import {
93
79
  * const stakingClient = await StakingClient.build(signer);
94
80
  * ```
95
81
  *
96
- * ### Provider
82
+ * ###Using Provider
97
83
  *
98
84
  * ```ts
99
85
  * import { StakingClient } from '@human-protocol/sdk';
100
- * import { providers } from 'ethers';
86
+ * import { JsonRpcProvider } from 'ethers';
101
87
  *
102
88
  * const rpcUrl = 'YOUR_RPC_URL';
103
89
  *
104
- * const provider = new providers.JsonRpcProvider(rpcUrl);
90
+ * const provider = new JsonRpcProvider(rpcUrl);
105
91
  * const stakingClient = await StakingClient.build(provider);
106
92
  * ```
107
93
  */
@@ -113,8 +99,8 @@ export class StakingClient extends BaseEthersClient {
113
99
  /**
114
100
  * **StakingClient constructor**
115
101
  *
116
- * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
117
- * @param {NetworkData} networkData - The network information required to connect to the Staking contract
102
+ * @param runner - The Runner object to interact with the Ethereum network
103
+ * @param networkData - The network information required to connect to the Staking contract
118
104
  */
119
105
  constructor(runner: ContractRunner, networkData: NetworkData) {
120
106
  super(runner, networkData);
@@ -138,11 +124,23 @@ export class StakingClient extends BaseEthersClient {
138
124
  /**
139
125
  * Creates an instance of StakingClient from a Runner.
140
126
  *
141
- * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
127
+ * @param runner - The Runner object to interact with the Ethereum network
128
+ * @returns An instance of StakingClient
129
+ * @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
130
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import { StakingClient } from '@human-protocol/sdk';
135
+ * import { Wallet, JsonRpcProvider } from 'ethers';
136
+ *
137
+ * const rpcUrl = 'YOUR_RPC_URL';
138
+ * const privateKey = 'YOUR_PRIVATE_KEY';
142
139
  *
143
- * @returns {Promise<StakingClient>} - An instance of StakingClient
144
- * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
145
- * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
140
+ * const provider = new JsonRpcProvider(rpcUrl);
141
+ * const signer = new Wallet(privateKey, provider);
142
+ * const stakingClient = await StakingClient.build(signer);
143
+ * ```
146
144
  */
147
145
  public static async build(runner: ContractRunner): Promise<StakingClient> {
148
146
  if (!runner.provider) {
@@ -179,31 +177,24 @@ export class StakingClient extends BaseEthersClient {
179
177
  /**
180
178
  * This function approves the staking contract to transfer a specified amount of tokens when the user stakes. It increases the allowance for the staking contract.
181
179
  *
182
- * @param {bigint} amount Amount in WEI of tokens to approve for stake.
183
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
184
- * @returns Returns void if successful. Throws error if any.
185
- *
186
- * **Code example**
180
+ * @param amount - Amount in WEI of tokens to approve for stake.
181
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
182
+ * @returns -
183
+ * @throws ErrorInvalidStakingValueType If the amount is not a bigint
184
+ * @throws ErrorInvalidStakingValueSign If the amount is negative
187
185
  *
186
+ * @example
188
187
  * ```ts
189
- * import { ethers, Wallet, providers } from 'ethers';
190
- * import { StakingClient } from '@human-protocol/sdk';
191
- *
192
- * const rpcUrl = 'YOUR_RPC_URL';
193
- * const privateKey = 'YOUR_PRIVATE_KEY';
188
+ * import { ethers } from 'ethers';
194
189
  *
195
- * const provider = new providers.JsonRpcProvider(rpcUrl);
196
- * const signer = new Wallet(privateKey, provider);
197
- * const stakingClient = await StakingClient.build(signer);
198
- *
199
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
190
+ * const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
200
191
  * await stakingClient.approveStake(amount);
201
192
  * ```
202
193
  */
203
194
  @requiresSigner
204
195
  public async approveStake(
205
196
  amount: bigint,
206
- txOptions: Overrides = {}
197
+ txOptions: TransactionOverrides = {}
207
198
  ): Promise<void> {
208
199
  if (typeof amount !== 'bigint') {
209
200
  throw ErrorInvalidStakingValueType;
@@ -214,13 +205,15 @@ export class StakingClient extends BaseEthersClient {
214
205
  }
215
206
 
216
207
  try {
217
- await (
218
- await this.tokenContract.approve(
219
- await this.stakingContract.getAddress(),
220
- amount,
221
- txOptions
222
- )
223
- ).wait();
208
+ await this.sendTxAndWait(
209
+ async (overrides) =>
210
+ this.tokenContract.approve(
211
+ await this.stakingContract.getAddress(),
212
+ amount,
213
+ overrides
214
+ ),
215
+ txOptions
216
+ );
224
217
  return;
225
218
  } catch (e) {
226
219
  return throwError(e);
@@ -230,32 +223,29 @@ export class StakingClient extends BaseEthersClient {
230
223
  /**
231
224
  * This function stakes a specified amount of tokens on a specific network.
232
225
  *
233
- * > `approveStake` must be called before
226
+ * !!! note
227
+ * `approveStake` must be called before
234
228
  *
235
- * @param {bigint} amount Amount in WEI of tokens to stake.
236
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
237
- * @returns Returns void if successful. Throws error if any.
238
- *
239
- * **Code example**
229
+ * @param amount - Amount in WEI of tokens to stake.
230
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
231
+ * @returns -
232
+ * @throws ErrorInvalidStakingValueType If the amount is not a bigint
233
+ * @throws ErrorInvalidStakingValueSign If the amount is negative
240
234
  *
235
+ * @example
241
236
  * ```ts
242
- * import { ethers, Wallet, providers } from 'ethers';
243
- * import { StakingClient } from '@human-protocol/sdk';
237
+ * import { ethers } from 'ethers';
244
238
  *
245
- * const rpcUrl = 'YOUR_RPC_URL';
246
- * const privateKey = 'YOUR_PRIVATE_KEY';
247
- *
248
- * const provider = new providers.JsonRpcProvider(rpcUrl);
249
- * const signer = new Wallet(privateKey, provider);
250
- * const stakingClient = await StakingClient.build(signer);
251
- *
252
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
239
+ * const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
253
240
  * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
254
241
  * await stakingClient.stake(amount);
255
242
  * ```
256
243
  */
257
244
  @requiresSigner
258
- public async stake(amount: bigint, txOptions: Overrides = {}): Promise<void> {
245
+ public async stake(
246
+ amount: bigint,
247
+ txOptions: TransactionOverrides = {}
248
+ ): Promise<void> {
259
249
  if (typeof amount !== 'bigint') {
260
250
  throw ErrorInvalidStakingValueType;
261
251
  }
@@ -265,7 +255,10 @@ export class StakingClient extends BaseEthersClient {
265
255
  }
266
256
 
267
257
  try {
268
- await (await this.stakingContract.stake(amount, txOptions)).wait();
258
+ await this.sendTxAndWait(
259
+ (overrides) => this.stakingContract.stake(amount, overrides),
260
+ txOptions
261
+ );
269
262
  return;
270
263
  } catch (e) {
271
264
  return throwError(e);
@@ -275,33 +268,27 @@ export class StakingClient extends BaseEthersClient {
275
268
  /**
276
269
  * This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time.
277
270
  *
278
- * > Must have tokens available to unstake
271
+ * !!! note
272
+ * Must have tokens available to unstake
279
273
  *
280
- * @param {bigint} amount Amount in WEI of tokens to unstake.
281
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
282
- * @returns Returns void if successful. Throws error if any.
283
- *
284
- * **Code example**
274
+ * @param amount - Amount in WEI of tokens to unstake.
275
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
276
+ * @returns -
277
+ * @throws ErrorInvalidStakingValueType If the amount is not a bigint
278
+ * @throws ErrorInvalidStakingValueSign If the amount is negative
285
279
  *
280
+ * @example
286
281
  * ```ts
287
- * import { ethers, Wallet, providers } from 'ethers';
288
- * import { StakingClient } from '@human-protocol/sdk';
289
- *
290
- * const rpcUrl = 'YOUR_RPC_URL';
291
- * const privateKey = 'YOUR_PRIVATE_KEY';
292
- *
293
- * const provider = new providers.JsonRpcProvider(rpcUrl);
294
- * const signer = new Wallet(privateKey, provider);
295
- * const stakingClient = await StakingClient.build(signer);
282
+ * import { ethers } from 'ethers';
296
283
  *
297
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
284
+ * const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
298
285
  * await stakingClient.unstake(amount);
299
286
  * ```
300
287
  */
301
288
  @requiresSigner
302
289
  public async unstake(
303
290
  amount: bigint,
304
- txOptions: Overrides = {}
291
+ txOptions: TransactionOverrides = {}
305
292
  ): Promise<void> {
306
293
  if (typeof amount !== 'bigint') {
307
294
  throw ErrorInvalidStakingValueType;
@@ -312,7 +299,10 @@ export class StakingClient extends BaseEthersClient {
312
299
  }
313
300
 
314
301
  try {
315
- await (await this.stakingContract.unstake(amount, txOptions)).wait();
302
+ await this.sendTxAndWait(
303
+ (overrides) => this.stakingContract.unstake(amount, overrides),
304
+ txOptions
305
+ );
316
306
  return;
317
307
  } catch (e) {
318
308
  return throwError(e);
@@ -321,32 +311,24 @@ export class StakingClient extends BaseEthersClient {
321
311
 
322
312
  /**
323
313
  * This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
314
+ * !!! note
315
+ * Must have tokens available to withdraw
324
316
  *
325
- * > Must have tokens available to withdraw
326
- *
327
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
328
- * @returns Returns void if successful. Throws error if any.
329
- *
330
- * **Code example**
317
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
318
+ * @returns -
331
319
  *
320
+ * @example
332
321
  * ```ts
333
- * import { Wallet, providers } from 'ethers';
334
- * import { StakingClient } from '@human-protocol/sdk';
335
- *
336
- * const rpcUrl = 'YOUR_RPC_URL';
337
- * const privateKey = 'YOUR_PRIVATE_KEY';
338
- *
339
- * const provider = new providers.JsonRpcProvider(rpcUrl);
340
- * const signer = new Wallet(privateKey, provider);
341
- * const stakingClient = await StakingClient.build(signer);
342
- *
343
322
  * await stakingClient.withdraw();
344
323
  * ```
345
324
  */
346
325
  @requiresSigner
347
- public async withdraw(txOptions: Overrides = {}): Promise<void> {
326
+ public async withdraw(txOptions: TransactionOverrides = {}): Promise<void> {
348
327
  try {
349
- await (await this.stakingContract.withdraw(txOptions)).wait();
328
+ await this.sendTxAndWait(
329
+ (overrides) => this.stakingContract.withdraw(overrides),
330
+ txOptions
331
+ );
350
332
  return;
351
333
  } catch (e) {
352
334
  return throwError(e);
@@ -356,28 +338,30 @@ export class StakingClient extends BaseEthersClient {
356
338
  /**
357
339
  * This function reduces the allocated amount by a staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
358
340
  *
359
- * @param {string} slasher Wallet address from who requested the slash
360
- * @param {string} staker Wallet address from who is going to be slashed
361
- * @param {string} escrowAddress Address of the escrow that the slash is made
362
- * @param {bigint} amount Amount in WEI of tokens to slash.
363
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
364
- * @returns Returns void if successful. Throws error if any.
365
- *
366
- * **Code example**
367
- *
341
+ * @param slasher - Wallet address from who requested the slash
342
+ * @param staker - Wallet address from who is going to be slashed
343
+ * @param escrowAddress - Address of the escrow that the slash is made
344
+ * @param amount - Amount in WEI of tokens to slash.
345
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
346
+ * @returns -
347
+ * @throws ErrorInvalidStakingValueType If the amount is not a bigint
348
+ * @throws ErrorInvalidStakingValueSign If the amount is negative
349
+ * @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
350
+ * @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
351
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
352
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
353
+ *
354
+ * @example
368
355
  * ```ts
369
- * import { ethers, Wallet, providers } from 'ethers';
370
- * import { StakingClient } from '@human-protocol/sdk';
371
- *
372
- * const rpcUrl = 'YOUR_RPC_URL';
373
- * const privateKey = 'YOUR_PRIVATE_KEY';
374
- *
375
- * const provider = new providers.JsonRpcProvider(rpcUrl);
376
- * const signer = new Wallet(privateKey, provider);
377
- * const stakingClient = await StakingClient.build(signer);
378
- *
379
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
380
- * await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
356
+ * import { ethers } from 'ethers';
357
+ *
358
+ * const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
359
+ * await stakingClient.slash(
360
+ * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
361
+ * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
362
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
363
+ * amount
364
+ * );
381
365
  * ```
382
366
  */
383
367
  @requiresSigner
@@ -386,7 +370,7 @@ export class StakingClient extends BaseEthersClient {
386
370
  staker: string,
387
371
  escrowAddress: string,
388
372
  amount: bigint,
389
- txOptions: Overrides = {}
373
+ txOptions: TransactionOverrides = {}
390
374
  ): Promise<void> {
391
375
  if (typeof amount !== 'bigint') {
392
376
  throw ErrorInvalidStakingValueType;
@@ -407,15 +391,17 @@ export class StakingClient extends BaseEthersClient {
407
391
  await this.checkValidEscrow(escrowAddress);
408
392
 
409
393
  try {
410
- await (
411
- await this.stakingContract.slash(
412
- slasher,
413
- staker,
414
- escrowAddress,
415
- amount,
416
- txOptions
417
- )
418
- ).wait();
394
+ await this.sendTxAndWait(
395
+ (overrides) =>
396
+ this.stakingContract.slash(
397
+ slasher,
398
+ staker,
399
+ escrowAddress,
400
+ amount,
401
+ overrides
402
+ ),
403
+ txOptions
404
+ );
419
405
 
420
406
  return;
421
407
  } catch (e) {
@@ -426,21 +412,14 @@ export class StakingClient extends BaseEthersClient {
426
412
  /**
427
413
  * Retrieves comprehensive staking information for a staker.
428
414
  *
429
- * @param {string} stakerAddress - The address of the staker.
430
- * @returns {Promise<StakerInfo>}
431
- *
432
- * **Code example**
415
+ * @param stakerAddress - The address of the staker.
416
+ * @returns Staking information for the staker
417
+ * @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
433
418
  *
419
+ * @example
434
420
  * ```ts
435
- * import { StakingClient } from '@human-protocol/sdk';
436
- *
437
- * const rpcUrl = 'YOUR_RPC_URL';
438
- *
439
- * const provider = new providers.JsonRpcProvider(rpcUrl);
440
- * const stakingClient = await StakingClient.build(provider);
441
- *
442
421
  * const stakingInfo = await stakingClient.getStakerInfo('0xYourStakerAddress');
443
- * console.log(stakingInfo.tokensStaked);
422
+ * console.log('Tokens staked:', stakingInfo.stakedAmount);
444
423
  * ```
445
424
  */
446
425
  public async getStakerInfo(stakerAddress: string): Promise<StakerInfo> {
@@ -479,16 +458,41 @@ export class StakingClient extends BaseEthersClient {
479
458
  }
480
459
 
481
460
  /**
482
- * Utility class for Staking-related subgraph queries.
461
+ * Utility helpers for Staking-related queries.
462
+ *
463
+ * @example
464
+ * ```ts
465
+ * import { StakingUtils, ChainId } from '@human-protocol/sdk';
466
+ *
467
+ * const staker = await StakingUtils.getStaker(
468
+ * ChainId.POLYGON_AMOY,
469
+ * '0xYourStakerAddress'
470
+ * );
471
+ * console.log('Staked amount:', staker.stakedAmount);
472
+ * ```
483
473
  */
484
474
  export class StakingUtils {
485
475
  /**
486
476
  * Gets staking info for a staker from the subgraph.
487
477
  *
488
- * @param {ChainId} chainId Network in which the staking contract is deployed
489
- * @param {string} stakerAddress Address of the staker
490
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
491
- * @returns {Promise<IStaker>} Staker info from subgraph
478
+ * @param chainId - Network in which the staking contract is deployed
479
+ * @param stakerAddress - Address of the staker
480
+ * @param options - Optional configuration for subgraph requests.
481
+ * @returns Staker info from subgraph
482
+ * @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
483
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
484
+ * @throws ErrorStakerNotFound If the staker is not found
485
+ *
486
+ * @example
487
+ * ```ts
488
+ * import { StakingUtils, ChainId } from '@human-protocol/sdk';
489
+ *
490
+ * const staker = await StakingUtils.getStaker(
491
+ * ChainId.POLYGON_AMOY,
492
+ * '0xYourStakerAddress'
493
+ * );
494
+ * console.log('Staked amount:', staker.stakedAmount);
495
+ * ```
492
496
  */
493
497
  public static async getStaker(
494
498
  chainId: ChainId,
@@ -521,9 +525,22 @@ export class StakingUtils {
521
525
  /**
522
526
  * Gets all stakers from the subgraph with filters, pagination and ordering.
523
527
  *
524
- * @param {IStakersFilter} filter Stakers filter with pagination and ordering
525
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
526
- * @returns {Promise<IStaker[]>} Array of stakers
528
+ * @param filter - Stakers filter with pagination and ordering
529
+ * @param options - Optional configuration for subgraph requests.
530
+ * @returns Array of stakers
531
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * import { ChainId } from '@human-protocol/sdk';
536
+ *
537
+ * const filter = {
538
+ * chainId: ChainId.POLYGON_AMOY,
539
+ * minStakedAmount: '1000000000000000000', // 1 token in WEI
540
+ * };
541
+ * const stakers = await StakingUtils.getStakers(filter);
542
+ * console.log('Stakers:', stakers.length);
543
+ * ```
527
544
  */
528
545
  public static async getStakers(
529
546
  filter: IStakersFilter,