@human-protocol/sdk 3.0.8 → 4.0.1

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 (60) hide show
  1. package/dist/constants.d.ts +4 -1
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +11 -151
  4. package/dist/decorators.js +1 -1
  5. package/dist/encryption.d.ts +21 -29
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +17 -29
  8. package/dist/enums.d.ts +5 -12
  9. package/dist/enums.d.ts.map +1 -1
  10. package/dist/enums.js +6 -12
  11. package/dist/error.d.ts +31 -28
  12. package/dist/error.d.ts.map +1 -1
  13. package/dist/error.js +36 -33
  14. package/dist/escrow.d.ts +104 -88
  15. package/dist/escrow.d.ts.map +1 -1
  16. package/dist/escrow.js +192 -131
  17. package/dist/graphql/queries/operator.d.ts.map +1 -1
  18. package/dist/graphql/queries/operator.js +15 -5
  19. package/dist/interfaces.d.ts +12 -2
  20. package/dist/interfaces.d.ts.map +1 -1
  21. package/dist/kvstore.d.ts +15 -15
  22. package/dist/kvstore.d.ts.map +1 -1
  23. package/dist/kvstore.js +15 -15
  24. package/dist/operator.d.ts +11 -10
  25. package/dist/operator.d.ts.map +1 -1
  26. package/dist/operator.js +23 -11
  27. package/dist/staking.d.ts +38 -21
  28. package/dist/staking.d.ts.map +1 -1
  29. package/dist/staking.js +62 -21
  30. package/dist/statistics.d.ts +10 -29
  31. package/dist/statistics.d.ts.map +1 -1
  32. package/dist/statistics.js +18 -37
  33. package/dist/storage.d.ts +13 -18
  34. package/dist/storage.d.ts.map +1 -1
  35. package/dist/storage.js +13 -18
  36. package/dist/transaction.d.ts.map +1 -1
  37. package/dist/transaction.js +3 -5
  38. package/dist/types.d.ts +6 -2
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js +1 -1
  41. package/dist/utils.d.ts +7 -1
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +11 -2
  44. package/package.json +1 -1
  45. package/src/constants.ts +11 -174
  46. package/src/decorators.ts +1 -1
  47. package/src/encryption.ts +21 -29
  48. package/src/enums.ts +5 -11
  49. package/src/error.ts +39 -37
  50. package/src/escrow.ts +257 -151
  51. package/src/graphql/queries/operator.ts +15 -5
  52. package/src/interfaces.ts +13 -2
  53. package/src/kvstore.ts +16 -16
  54. package/src/operator.ts +26 -12
  55. package/src/staking.ts +71 -22
  56. package/src/statistics.ts +19 -38
  57. package/src/storage.ts +13 -18
  58. package/src/transaction.ts +5 -7
  59. package/src/types.ts +6 -2
  60. package/src/utils.ts +10 -1
package/dist/staking.d.ts CHANGED
@@ -2,22 +2,23 @@ import { EscrowFactory, HMToken, Staking } from '@human-protocol/core/typechain-
2
2
  import { ContractRunner, Overrides } from 'ethers';
3
3
  import { BaseEthersClient } from './base';
4
4
  import { NetworkData } from './types';
5
+ import { StakerInfo } from './interfaces';
5
6
  /**
6
7
  * ## Introduction
7
8
  *
8
- * This client enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph.
9
+ * This client enables performing actions on staking contracts and obtaining staking information from both the contracts and subgraph.
9
10
  *
10
11
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
11
12
  * To use this client, it is recommended to initialize it using the static `build` method.
12
13
  *
13
14
  * ```ts
14
- * static async build(runner: ContractRunner);
15
+ * static async build(runner: ContractRunner): Promise<StakingClient>;
15
16
  * ```
16
17
  *
17
18
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
18
19
  *
19
- * - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
20
- * - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
20
+ * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
21
+ * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
21
22
  *
22
23
  * ## Installation
23
24
  *
@@ -35,21 +36,21 @@ import { NetworkData } from './types';
35
36
  *
36
37
  * ### Signer
37
38
  *
38
- * **Using private key(backend)**
39
+ * **Using private key (backend)**
39
40
  *
40
41
  * ```ts
41
42
  * import { StakingClient } from '@human-protocol/sdk';
42
43
  * import { Wallet, providers } from 'ethers';
43
44
  *
44
45
  * const rpcUrl = 'YOUR_RPC_URL';
45
- * const privateKey = 'YOUR_PRIVATE_KEY'
46
+ * const privateKey = 'YOUR_PRIVATE_KEY';
46
47
  *
47
48
  * const provider = new providers.JsonRpcProvider(rpcUrl);
48
49
  * const signer = new Wallet(privateKey, provider);
49
50
  * const stakingClient = await StakingClient.build(signer);
50
51
  * ```
51
52
  *
52
- * **Using Wagmi(frontend)**
53
+ * **Using Wagmi (frontend)**
53
54
  *
54
55
  * ```ts
55
56
  * import { useSigner, useChainId } from 'wagmi';
@@ -105,7 +106,6 @@ export declare class StakingClient extends BaseEthersClient {
105
106
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
106
107
  * @returns Returns void if successful. Throws error if any.
107
108
  *
108
- *
109
109
  * **Code example**
110
110
  *
111
111
  * ```ts
@@ -113,7 +113,7 @@ export declare class StakingClient extends BaseEthersClient {
113
113
  * import { StakingClient } from '@human-protocol/sdk';
114
114
  *
115
115
  * const rpcUrl = 'YOUR_RPC_URL';
116
- * const privateKey = 'YOUR_PRIVATE_KEY'
116
+ * const privateKey = 'YOUR_PRIVATE_KEY';
117
117
  *
118
118
  * const provider = new providers.JsonRpcProvider(rpcUrl);
119
119
  * const signer = new Wallet(privateKey, provider);
@@ -133,7 +133,6 @@ export declare class StakingClient extends BaseEthersClient {
133
133
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
134
134
  * @returns Returns void if successful. Throws error if any.
135
135
  *
136
- *
137
136
  * **Code example**
138
137
  *
139
138
  * ```ts
@@ -141,7 +140,7 @@ export declare class StakingClient extends BaseEthersClient {
141
140
  * import { StakingClient } from '@human-protocol/sdk';
142
141
  *
143
142
  * const rpcUrl = 'YOUR_RPC_URL';
144
- * const privateKey = 'YOUR_PRIVATE_KEY'
143
+ * const privateKey = 'YOUR_PRIVATE_KEY';
145
144
  *
146
145
  * const provider = new providers.JsonRpcProvider(rpcUrl);
147
146
  * const signer = new Wallet(privateKey, provider);
@@ -149,7 +148,7 @@ export declare class StakingClient extends BaseEthersClient {
149
148
  *
150
149
  * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
151
150
  * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
152
- * await stakingClient.approveStake(amount);
151
+ * await stakingClient.stake(amount);
153
152
  * ```
154
153
  */
155
154
  stake(amount: bigint, txOptions?: Overrides): Promise<void>;
@@ -162,7 +161,6 @@ export declare class StakingClient extends BaseEthersClient {
162
161
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
163
162
  * @returns Returns void if successful. Throws error if any.
164
163
  *
165
- *
166
164
  * **Code example**
167
165
  *
168
166
  * ```ts
@@ -170,7 +168,7 @@ export declare class StakingClient extends BaseEthersClient {
170
168
  * import { StakingClient } from '@human-protocol/sdk';
171
169
  *
172
170
  * const rpcUrl = 'YOUR_RPC_URL';
173
- * const privateKey = 'YOUR_PRIVATE_KEY'
171
+ * const privateKey = 'YOUR_PRIVATE_KEY';
174
172
  *
175
173
  * const provider = new providers.JsonRpcProvider(rpcUrl);
176
174
  * const signer = new Wallet(privateKey, provider);
@@ -182,14 +180,13 @@ export declare class StakingClient extends BaseEthersClient {
182
180
  */
183
181
  unstake(amount: bigint, txOptions?: Overrides): Promise<void>;
184
182
  /**
185
- * This function withdraws unstaked and non locked tokens form staking contract to the user wallet.
183
+ * This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
186
184
  *
187
185
  * > Must have tokens available to withdraw
188
186
  *
189
187
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
190
188
  * @returns Returns void if successful. Throws error if any.
191
189
  *
192
- *
193
190
  * **Code example**
194
191
  *
195
192
  * ```ts
@@ -197,7 +194,7 @@ export declare class StakingClient extends BaseEthersClient {
197
194
  * import { StakingClient } from '@human-protocol/sdk';
198
195
  *
199
196
  * const rpcUrl = 'YOUR_RPC_URL';
200
- * const privateKey = 'YOUR_PRIVATE_KEY'
197
+ * const privateKey = 'YOUR_PRIVATE_KEY';
201
198
  *
202
199
  * const provider = new providers.JsonRpcProvider(rpcUrl);
203
200
  * const signer = new Wallet(privateKey, provider);
@@ -208,16 +205,15 @@ export declare class StakingClient extends BaseEthersClient {
208
205
  */
209
206
  withdraw(txOptions?: Overrides): Promise<void>;
210
207
  /**
211
- * This function reduces the allocated amount by an staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
208
+ * 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.
212
209
  *
213
210
  * @param {string} slasher Wallet address from who requested the slash
214
211
  * @param {string} staker Wallet address from who is going to be slashed
215
212
  * @param {string} escrowAddress Address of the escrow that the slash is made
213
+ * @param {bigint} amount Amount in WEI of tokens to slash.
216
214
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
217
- * @param {bigint} amount Amount in WEI of tokens to unstake.
218
215
  * @returns Returns void if successful. Throws error if any.
219
216
  *
220
- *
221
217
  * **Code example**
222
218
  *
223
219
  * ```ts
@@ -225,7 +221,7 @@ export declare class StakingClient extends BaseEthersClient {
225
221
  * import { StakingClient } from '@human-protocol/sdk';
226
222
  *
227
223
  * const rpcUrl = 'YOUR_RPC_URL';
228
- * const privateKey = 'YOUR_PRIVATE_KEY'
224
+ * const privateKey = 'YOUR_PRIVATE_KEY';
229
225
  *
230
226
  * const provider = new providers.JsonRpcProvider(rpcUrl);
231
227
  * const signer = new Wallet(privateKey, provider);
@@ -236,5 +232,26 @@ export declare class StakingClient extends BaseEthersClient {
236
232
  * ```
237
233
  */
238
234
  slash(slasher: string, staker: string, escrowAddress: string, amount: bigint, txOptions?: Overrides): Promise<void>;
235
+ /**
236
+ * Retrieves comprehensive staking information for a staker.
237
+ *
238
+ * @param {string} stakerAddress - The address of the staker.
239
+ * @returns {Promise<StakerInfo>}
240
+ *
241
+ * **Code example**
242
+ *
243
+ * ```ts
244
+ * import { StakingClient } from '@human-protocol/sdk';
245
+ *
246
+ * const rpcUrl = 'YOUR_RPC_URL';
247
+ *
248
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
249
+ * const stakingClient = await StakingClient.build(provider);
250
+ *
251
+ * const stakingInfo = await stakingClient.getStakerInfo('0xYourStakerAddress');
252
+ * console.log(stakingInfo.tokensStaked);
253
+ * ```
254
+ */
255
+ getStakerInfo(stakerAddress: string): Promise<StakerInfo>;
239
256
  }
240
257
  //# sourceMappingURL=staking.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAc1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IAC1C,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAmB5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc;IAiBhD;;;;OAIG;YACW,gBAAgB;IAU9B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IAEU,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;;;;;;;;;;;;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OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBzE;;;;OAIG;YACW,gBAAgB;IAU9B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEU,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB5E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAiBhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEU,QAAQ,CAAC,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/D;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAoChB;;;;;;;;;;;;;;;;;;;OAmBG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAgCvE"}
package/dist/staking.js CHANGED
@@ -20,19 +20,19 @@ const utils_1 = require("./utils");
20
20
  /**
21
21
  * ## Introduction
22
22
  *
23
- * This client enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph.
23
+ * This client enables performing actions on staking contracts and obtaining staking information from both the contracts and subgraph.
24
24
  *
25
25
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
26
26
  * To use this client, it is recommended to initialize it using the static `build` method.
27
27
  *
28
28
  * ```ts
29
- * static async build(runner: ContractRunner);
29
+ * static async build(runner: ContractRunner): Promise<StakingClient>;
30
30
  * ```
31
31
  *
32
32
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
33
33
  *
34
- * - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
35
- * - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
34
+ * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
35
+ * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
36
36
  *
37
37
  * ## Installation
38
38
  *
@@ -50,21 +50,21 @@ const utils_1 = require("./utils");
50
50
  *
51
51
  * ### Signer
52
52
  *
53
- * **Using private key(backend)**
53
+ * **Using private key (backend)**
54
54
  *
55
55
  * ```ts
56
56
  * import { StakingClient } from '@human-protocol/sdk';
57
57
  * import { Wallet, providers } from 'ethers';
58
58
  *
59
59
  * const rpcUrl = 'YOUR_RPC_URL';
60
- * const privateKey = 'YOUR_PRIVATE_KEY'
60
+ * const privateKey = 'YOUR_PRIVATE_KEY';
61
61
  *
62
62
  * const provider = new providers.JsonRpcProvider(rpcUrl);
63
63
  * const signer = new Wallet(privateKey, provider);
64
64
  * const stakingClient = await StakingClient.build(signer);
65
65
  * ```
66
66
  *
67
- * **Using Wagmi(frontend)**
67
+ * **Using Wagmi (frontend)**
68
68
  *
69
69
  * ```ts
70
70
  * import { useSigner, useChainId } from 'wagmi';
@@ -140,7 +140,6 @@ class StakingClient extends base_1.BaseEthersClient {
140
140
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
141
141
  * @returns Returns void if successful. Throws error if any.
142
142
  *
143
- *
144
143
  * **Code example**
145
144
  *
146
145
  * ```ts
@@ -148,7 +147,7 @@ class StakingClient extends base_1.BaseEthersClient {
148
147
  * import { StakingClient } from '@human-protocol/sdk';
149
148
  *
150
149
  * const rpcUrl = 'YOUR_RPC_URL';
151
- * const privateKey = 'YOUR_PRIVATE_KEY'
150
+ * const privateKey = 'YOUR_PRIVATE_KEY';
152
151
  *
153
152
  * const provider = new providers.JsonRpcProvider(rpcUrl);
154
153
  * const signer = new Wallet(privateKey, provider);
@@ -182,7 +181,6 @@ class StakingClient extends base_1.BaseEthersClient {
182
181
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
183
182
  * @returns Returns void if successful. Throws error if any.
184
183
  *
185
- *
186
184
  * **Code example**
187
185
  *
188
186
  * ```ts
@@ -190,7 +188,7 @@ class StakingClient extends base_1.BaseEthersClient {
190
188
  * import { StakingClient } from '@human-protocol/sdk';
191
189
  *
192
190
  * const rpcUrl = 'YOUR_RPC_URL';
193
- * const privateKey = 'YOUR_PRIVATE_KEY'
191
+ * const privateKey = 'YOUR_PRIVATE_KEY';
194
192
  *
195
193
  * const provider = new providers.JsonRpcProvider(rpcUrl);
196
194
  * const signer = new Wallet(privateKey, provider);
@@ -198,7 +196,7 @@ class StakingClient extends base_1.BaseEthersClient {
198
196
  *
199
197
  * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
200
198
  * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
201
- * await stakingClient.approveStake(amount);
199
+ * await stakingClient.stake(amount);
202
200
  * ```
203
201
  */
204
202
  async stake(amount, txOptions = {}) {
@@ -225,7 +223,6 @@ class StakingClient extends base_1.BaseEthersClient {
225
223
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
226
224
  * @returns Returns void if successful. Throws error if any.
227
225
  *
228
- *
229
226
  * **Code example**
230
227
  *
231
228
  * ```ts
@@ -233,7 +230,7 @@ class StakingClient extends base_1.BaseEthersClient {
233
230
  * import { StakingClient } from '@human-protocol/sdk';
234
231
  *
235
232
  * const rpcUrl = 'YOUR_RPC_URL';
236
- * const privateKey = 'YOUR_PRIVATE_KEY'
233
+ * const privateKey = 'YOUR_PRIVATE_KEY';
237
234
  *
238
235
  * const provider = new providers.JsonRpcProvider(rpcUrl);
239
236
  * const signer = new Wallet(privateKey, provider);
@@ -259,14 +256,13 @@ class StakingClient extends base_1.BaseEthersClient {
259
256
  }
260
257
  }
261
258
  /**
262
- * This function withdraws unstaked and non locked tokens form staking contract to the user wallet.
259
+ * This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
263
260
  *
264
261
  * > Must have tokens available to withdraw
265
262
  *
266
263
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
267
264
  * @returns Returns void if successful. Throws error if any.
268
265
  *
269
- *
270
266
  * **Code example**
271
267
  *
272
268
  * ```ts
@@ -274,7 +270,7 @@ class StakingClient extends base_1.BaseEthersClient {
274
270
  * import { StakingClient } from '@human-protocol/sdk';
275
271
  *
276
272
  * const rpcUrl = 'YOUR_RPC_URL';
277
- * const privateKey = 'YOUR_PRIVATE_KEY'
273
+ * const privateKey = 'YOUR_PRIVATE_KEY';
278
274
  *
279
275
  * const provider = new providers.JsonRpcProvider(rpcUrl);
280
276
  * const signer = new Wallet(privateKey, provider);
@@ -293,16 +289,15 @@ class StakingClient extends base_1.BaseEthersClient {
293
289
  }
294
290
  }
295
291
  /**
296
- * This function reduces the allocated amount by an staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
292
+ * 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.
297
293
  *
298
294
  * @param {string} slasher Wallet address from who requested the slash
299
295
  * @param {string} staker Wallet address from who is going to be slashed
300
296
  * @param {string} escrowAddress Address of the escrow that the slash is made
297
+ * @param {bigint} amount Amount in WEI of tokens to slash.
301
298
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
302
- * @param {bigint} amount Amount in WEI of tokens to unstake.
303
299
  * @returns Returns void if successful. Throws error if any.
304
300
  *
305
- *
306
301
  * **Code example**
307
302
  *
308
303
  * ```ts
@@ -310,7 +305,7 @@ class StakingClient extends base_1.BaseEthersClient {
310
305
  * import { StakingClient } from '@human-protocol/sdk';
311
306
  *
312
307
  * const rpcUrl = 'YOUR_RPC_URL';
313
- * const privateKey = 'YOUR_PRIVATE_KEY'
308
+ * const privateKey = 'YOUR_PRIVATE_KEY';
314
309
  *
315
310
  * const provider = new providers.JsonRpcProvider(rpcUrl);
316
311
  * const signer = new Wallet(privateKey, provider);
@@ -342,6 +337,52 @@ class StakingClient extends base_1.BaseEthersClient {
342
337
  return (0, utils_1.throwError)(e);
343
338
  }
344
339
  }
340
+ /**
341
+ * Retrieves comprehensive staking information for a staker.
342
+ *
343
+ * @param {string} stakerAddress - The address of the staker.
344
+ * @returns {Promise<StakerInfo>}
345
+ *
346
+ * **Code example**
347
+ *
348
+ * ```ts
349
+ * import { StakingClient } from '@human-protocol/sdk';
350
+ *
351
+ * const rpcUrl = 'YOUR_RPC_URL';
352
+ *
353
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
354
+ * const stakingClient = await StakingClient.build(provider);
355
+ *
356
+ * const stakingInfo = await stakingClient.getStakerInfo('0xYourStakerAddress');
357
+ * console.log(stakingInfo.tokensStaked);
358
+ * ```
359
+ */
360
+ async getStakerInfo(stakerAddress) {
361
+ if (!ethers_1.ethers.isAddress(stakerAddress)) {
362
+ throw error_1.ErrorInvalidStakerAddressProvided;
363
+ }
364
+ try {
365
+ const stakerInfo = await this.stakingContract.stakes(stakerAddress);
366
+ const currentBlock = await this.runner.provider.getBlockNumber();
367
+ const tokensWithdrawable = stakerInfo.tokensLockedUntil !== 0n &&
368
+ currentBlock >= stakerInfo.tokensLockedUntil
369
+ ? stakerInfo.tokensLocked
370
+ : 0n;
371
+ const adjustedLockedAmount = stakerInfo.tokensLockedUntil !== 0n &&
372
+ currentBlock >= stakerInfo.tokensLockedUntil
373
+ ? 0n
374
+ : stakerInfo.tokensLocked;
375
+ return {
376
+ stakedAmount: stakerInfo.tokensStaked,
377
+ lockedAmount: adjustedLockedAmount,
378
+ lockedUntil: adjustedLockedAmount === 0n ? 0n : stakerInfo.tokensLockedUntil,
379
+ withdrawableAmount: tokensWithdrawable,
380
+ };
381
+ }
382
+ catch (error) {
383
+ return (0, utils_1.throwError)(error);
384
+ }
385
+ }
345
386
  }
346
387
  exports.StakingClient = StakingClient;
347
388
  __decorate([
@@ -4,20 +4,15 @@ import { NetworkData } from './types';
4
4
  /**
5
5
  * ## Introduction
6
6
  *
7
- * This client enables to obtain statistical information from the subgraph.
7
+ * This client enables obtaining statistical information from the subgraph.
8
8
  *
9
- * Unlikely from the other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
10
- * We just need to create client object using relevant network data.
9
+ * Unlike other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
10
+ * We just need to create a client object using relevant network data.
11
11
  *
12
12
  * ```ts
13
13
  * constructor(network: NetworkData)
14
14
  * ```
15
15
  *
16
- * A `Signer` or a `Provider` should be passed depending on the use case of this module:
17
- *
18
- * - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
19
- * - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
20
- *
21
16
  * ## Installation
22
17
  *
23
18
  * ### npm
@@ -50,7 +45,6 @@ export declare class StatisticsClient {
50
45
  /**
51
46
  * This function returns the statistical data of escrows.
52
47
  *
53
- *
54
48
  * **Input parameters**
55
49
  *
56
50
  * ```ts
@@ -79,10 +73,8 @@ export declare class StatisticsClient {
79
73
  * };
80
74
  * ```
81
75
  *
82
- *
83
76
  * @param {IStatisticsFilter} filter Statistics params with duration data
84
- * @returns {EscrowStatistics} Escrow statistics data.
85
- *
77
+ * @returns {Promise<EscrowStatistics>} Escrow statistics data.
86
78
  *
87
79
  * **Code example**
88
80
  *
@@ -102,7 +94,6 @@ export declare class StatisticsClient {
102
94
  /**
103
95
  * This function returns the statistical data of workers.
104
96
  *
105
- *
106
97
  * **Input parameters**
107
98
  *
108
99
  * ```ts
@@ -126,10 +117,8 @@ export declare class StatisticsClient {
126
117
  * };
127
118
  * ```
128
119
  *
129
- *
130
120
  * @param {IStatisticsFilter} filter Statistics params with duration data
131
- * @returns {WorkerStatistics} Worker statistics data.
132
- *
121
+ * @returns {Promise<WorkerStatistics>} Worker statistics data.
133
122
  *
134
123
  * **Code example**
135
124
  *
@@ -149,7 +138,6 @@ export declare class StatisticsClient {
149
138
  /**
150
139
  * This function returns the statistical data of payments.
151
140
  *
152
- *
153
141
  * **Input parameters**
154
142
  *
155
143
  * ```ts
@@ -175,10 +163,8 @@ export declare class StatisticsClient {
175
163
  * };
176
164
  * ```
177
165
  *
178
- *
179
166
  * @param {IStatisticsFilter} filter Statistics params with duration data
180
- * @returns {PaymentStatistics} Payment statistics data.
181
- *
167
+ * @returns {Promise<PaymentStatistics>} Payment statistics data.
182
168
  *
183
169
  * **Code example**
184
170
  *
@@ -219,7 +205,7 @@ export declare class StatisticsClient {
219
205
  /**
220
206
  * This function returns the statistical data of HMToken.
221
207
  *
222
- *
208
+ * ```ts
223
209
  * type HMTStatistics = {
224
210
  * totalTransferAmount: BigNumber;
225
211
  * totalTransferCount: BigNumber;
@@ -227,9 +213,7 @@ export declare class StatisticsClient {
227
213
  * };
228
214
  * ```
229
215
  *
230
- *
231
- * @returns {HMTStatistics} HMToken statistics data.
232
- *
216
+ * @returns {Promise<HMTStatistics>} HMToken statistics data.
233
217
  *
234
218
  * **Code example**
235
219
  *
@@ -253,7 +237,7 @@ export declare class StatisticsClient {
253
237
  * **Input parameters**
254
238
  *
255
239
  * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
256
- * @returns {HMTHolder[]} List of HMToken holders.
240
+ * @returns {Promise<HMTHolder[]>} List of HMToken holders.
257
241
  *
258
242
  * **Code example**
259
243
  *
@@ -276,7 +260,6 @@ export declare class StatisticsClient {
276
260
  /**
277
261
  * This function returns the statistical data of HMToken day by day.
278
262
  *
279
- *
280
263
  * **Input parameters**
281
264
  *
282
265
  * ```ts
@@ -299,10 +282,8 @@ export declare class StatisticsClient {
299
282
  * }
300
283
  * ```
301
284
  *
302
- *
303
285
  * @param {IStatisticsFilter} filter Statistics params with duration data
304
- * @returns {DailyHMTData[]} Daily HMToken statistics data.
305
- *
286
+ * @returns {Promise<DailyHMTData[]>} Daily HMToken statistics data.
306
287
  *
307
288
  * **Code example**
308
289
  *
@@ -1 +1 @@
1
- {"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,gBAAgB,EAGhB,aAAa,EAEb,iBAAiB,EACjB,gBAAgB,EAEhB,SAAS,EACT,YAAY,EACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,gBAAgB;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;gBACS,WAAW,EAAE,WAAW;IAKpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAuC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA4B5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoEG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAkC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;IAkBhD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,aAAa,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAwBzE;;;;;;;;;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