@human-protocol/sdk 1.1.18 → 2.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 (61) hide show
  1. package/dist/base.d.ts +4 -13
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +3 -18
  4. package/dist/constants.d.ts +7 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +18 -11
  7. package/dist/decorators.d.ts.map +1 -1
  8. package/dist/decorators.js +4 -2
  9. package/dist/encryption.d.ts +31 -0
  10. package/dist/encryption.d.ts.map +1 -1
  11. package/dist/encryption.js +37 -0
  12. package/dist/error.d.ts +0 -10
  13. package/dist/error.d.ts.map +1 -1
  14. package/dist/error.js +2 -18
  15. package/dist/escrow.d.ts +39 -33
  16. package/dist/escrow.d.ts.map +1 -1
  17. package/dist/escrow.js +121 -137
  18. package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
  19. package/dist/graphql/queries/operator.d.ts.map +1 -0
  20. package/dist/graphql/queries/{staking.js → operator.js} +24 -1
  21. package/dist/graphql/types.d.ts +5 -6
  22. package/dist/graphql/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -1
  26. package/dist/interfaces.d.ts +28 -18
  27. package/dist/interfaces.d.ts.map +1 -1
  28. package/dist/kvstore.d.ts +14 -14
  29. package/dist/kvstore.d.ts.map +1 -1
  30. package/dist/kvstore.js +30 -48
  31. package/dist/operator.d.ts +68 -0
  32. package/dist/operator.d.ts.map +1 -0
  33. package/dist/operator.js +153 -0
  34. package/dist/staking.d.ts +35 -95
  35. package/dist/staking.d.ts.map +1 -1
  36. package/dist/staking.js +73 -201
  37. package/dist/statistics.d.ts.map +1 -1
  38. package/dist/statistics.js +7 -6
  39. package/dist/types.d.ts +1 -2
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -15
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +9 -49
  44. package/package.json +4 -4
  45. package/src/base.ts +5 -30
  46. package/src/constants.ts +18 -10
  47. package/src/decorators.ts +3 -2
  48. package/src/encryption.ts +40 -0
  49. package/src/error.ts +0 -17
  50. package/src/escrow.ts +169 -178
  51. package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
  52. package/src/graphql/types.ts +5 -7
  53. package/src/index.ts +2 -0
  54. package/src/interfaces.ts +30 -18
  55. package/src/kvstore.ts +47 -59
  56. package/src/operator.ts +192 -0
  57. package/src/staking.ts +101 -213
  58. package/src/statistics.ts +8 -9
  59. package/src/types.ts +1 -3
  60. package/src/utils.ts +8 -58
  61. package/dist/graphql/queries/staking.d.ts.map +0 -1
package/dist/staking.js CHANGED
@@ -8,31 +8,25 @@ 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
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.StakingClient = void 0;
16
13
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
17
14
  const ethers_1 = require("ethers");
18
- const graphql_request_1 = __importDefault(require("graphql-request"));
19
15
  const base_1 = require("./base");
20
16
  const constants_1 = require("./constants");
21
17
  const decorators_1 = require("./decorators");
22
18
  const error_1 = require("./error");
23
19
  const utils_1 = require("./utils");
24
- const reward_1 = require("./graphql/queries/reward");
25
- const staking_1 = require("./graphql/queries/staking");
26
20
  /**
27
21
  * ## Introduction
28
22
  *
29
23
  * This client enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph.
30
24
  *
31
- * Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
25
+ * Internally, the SDK will use one network or another according to the network ID of the `runner`.
32
26
  * To use this client, it is recommended to initialize it using the static `build` method.
33
27
  *
34
28
  * ```ts
35
- * static async build(signerOrProvider: Signer | Provider);
29
+ * static async build(runner: ContractRunner);
36
30
  * ```
37
31
  *
38
32
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
@@ -96,44 +90,37 @@ class StakingClient extends base_1.BaseEthersClient {
96
90
  /**
97
91
  * **StakingClient constructor**
98
92
  *
99
- * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
93
+ * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
100
94
  * @param {NetworkData} network - The network information required to connect to the Staking contract
101
- * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
102
95
  */
103
- constructor(signerOrProvider, networkData, gasPriceMultiplier) {
104
- super(signerOrProvider, networkData, gasPriceMultiplier);
105
- this.stakingContract = typechain_types_1.Staking__factory.connect(networkData.stakingAddress, signerOrProvider);
106
- this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(networkData.factoryAddress, signerOrProvider);
107
- this.tokenContract = typechain_types_1.HMToken__factory.connect(networkData.hmtAddress, signerOrProvider);
108
- this.rewardPoolContract = typechain_types_1.RewardPool__factory.connect(networkData.rewardPoolAddress, this.signerOrProvider);
96
+ constructor(runner, networkData) {
97
+ super(runner, networkData);
98
+ this.stakingContract = typechain_types_1.Staking__factory.connect(networkData.stakingAddress, runner);
99
+ this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(networkData.factoryAddress, runner);
100
+ this.tokenContract = typechain_types_1.HMToken__factory.connect(networkData.hmtAddress, runner);
101
+ this.rewardPoolContract = typechain_types_1.RewardPool__factory.connect(networkData.rewardPoolAddress, this.runner);
109
102
  }
110
103
  /**
111
- * Creates an instance of StakingClient from a Signer or Provider.
104
+ * Creates an instance of StakingClient from a Runner.
112
105
  *
113
- * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
106
+ * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
114
107
  * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
115
108
  *
116
109
  * @returns {Promise<StakingClient>} - An instance of StakingClient
117
110
  * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
118
111
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
119
112
  */
120
- static async build(signerOrProvider, gasPriceMultiplier) {
121
- let network;
122
- if (ethers_1.Signer.isSigner(signerOrProvider)) {
123
- if (!signerOrProvider.provider) {
124
- throw error_1.ErrorProviderDoesNotExist;
125
- }
126
- network = await signerOrProvider.provider.getNetwork();
127
- }
128
- else {
129
- network = await signerOrProvider.getNetwork();
130
- }
131
- const chainId = network.chainId;
113
+ static async build(runner) {
114
+ if (!runner.provider) {
115
+ throw error_1.ErrorProviderDoesNotExist;
116
+ }
117
+ const network = await runner.provider?.getNetwork();
118
+ const chainId = Number(network?.chainId);
132
119
  const networkData = constants_1.NETWORKS[chainId];
133
120
  if (!networkData) {
134
121
  throw error_1.ErrorUnsupportedChainID;
135
122
  }
136
- return new StakingClient(signerOrProvider, networkData, gasPriceMultiplier);
123
+ return new StakingClient(runner, networkData);
137
124
  }
138
125
  /**
139
126
  * Check if escrow exists
@@ -141,7 +128,7 @@ class StakingClient extends base_1.BaseEthersClient {
141
128
  * @param escrowAddress Escrow address to check against
142
129
  */
143
130
  async checkValidEscrow(escrowAddress) {
144
- if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
131
+ if (!ethers_1.ethers.isAddress(escrowAddress)) {
145
132
  throw error_1.ErrorInvalidEscrowAddressProvided;
146
133
  }
147
134
  if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
@@ -151,7 +138,8 @@ class StakingClient extends base_1.BaseEthersClient {
151
138
  /**
152
139
  * 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.
153
140
  *
154
- * @param {BigNumber} amount Amount in WEI of tokens to approve for stake.
141
+ * @param {bigint} amount Amount in WEI of tokens to approve for stake.
142
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
155
143
  * @returns Returns void if successful. Throws error if any.
156
144
  *
157
145
  *
@@ -168,21 +156,19 @@ class StakingClient extends base_1.BaseEthersClient {
168
156
  * const signer = new Wallet(privateKey, provider);
169
157
  * const stakingClient = await StakingClient.build(signer);
170
158
  *
171
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
159
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
172
160
  * await stakingClient.approveStake(amount);
173
161
  * ```
174
162
  */
175
- async approveStake(amount) {
176
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
163
+ async approveStake(amount, txOptions = {}) {
164
+ if (typeof amount !== 'bigint') {
177
165
  throw error_1.ErrorInvalidStakingValueType;
178
166
  }
179
- if (amount.isNegative()) {
167
+ if (amount < 0n) {
180
168
  throw error_1.ErrorInvalidStakingValueSign;
181
169
  }
182
170
  try {
183
- await this.tokenContract.approve(this.stakingContract.address, amount, {
184
- ...(await this.gasPriceOptions()),
185
- });
171
+ await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, txOptions)).wait();
186
172
  return;
187
173
  }
188
174
  catch (e) {
@@ -194,7 +180,8 @@ class StakingClient extends base_1.BaseEthersClient {
194
180
  *
195
181
  * > `approveStake` must be called before
196
182
  *
197
- * @param {BigNumber} amount Amount in WEI of tokens to stake.
183
+ * @param {bigint} amount Amount in WEI of tokens to stake.
184
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
198
185
  * @returns Returns void if successful. Throws error if any.
199
186
  *
200
187
  *
@@ -211,22 +198,20 @@ class StakingClient extends base_1.BaseEthersClient {
211
198
  * const signer = new Wallet(privateKey, provider);
212
199
  * const stakingClient = await StakingClient.build(signer);
213
200
  *
214
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
201
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
215
202
  * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
216
203
  * await stakingClient.approveStake(amount);
217
204
  * ```
218
205
  */
219
- async stake(amount) {
220
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
206
+ async stake(amount, txOptions = {}) {
207
+ if (typeof amount !== 'bigint') {
221
208
  throw error_1.ErrorInvalidStakingValueType;
222
209
  }
223
- if (amount.isNegative()) {
210
+ if (amount < 0n) {
224
211
  throw error_1.ErrorInvalidStakingValueSign;
225
212
  }
226
213
  try {
227
- await this.stakingContract.stake(amount, {
228
- ...(await this.gasPriceOptions()),
229
- });
214
+ await (await this.stakingContract.stake(amount, txOptions)).wait();
230
215
  return;
231
216
  }
232
217
  catch (e) {
@@ -238,7 +223,8 @@ class StakingClient extends base_1.BaseEthersClient {
238
223
  *
239
224
  * > Must have tokens available to unstake
240
225
  *
241
- * @param {BigNumber} amount Amount in WEI of tokens to unstake.
226
+ * @param {bigint} amount Amount in WEI of tokens to unstake.
227
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
242
228
  * @returns Returns void if successful. Throws error if any.
243
229
  *
244
230
  *
@@ -255,21 +241,19 @@ class StakingClient extends base_1.BaseEthersClient {
255
241
  * const signer = new Wallet(privateKey, provider);
256
242
  * const stakingClient = await StakingClient.build(signer);
257
243
  *
258
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
244
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
259
245
  * await stakingClient.unstake(amount);
260
246
  * ```
261
247
  */
262
- async unstake(amount) {
263
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
248
+ async unstake(amount, txOptions = {}) {
249
+ if (typeof amount !== 'bigint') {
264
250
  throw error_1.ErrorInvalidStakingValueType;
265
251
  }
266
- if (amount.isNegative()) {
252
+ if (amount < 0n) {
267
253
  throw error_1.ErrorInvalidStakingValueSign;
268
254
  }
269
255
  try {
270
- await this.stakingContract.unstake(amount, {
271
- ...(await this.gasPriceOptions()),
272
- });
256
+ await (await this.stakingContract.unstake(amount, txOptions)).wait();
273
257
  return;
274
258
  }
275
259
  catch (e) {
@@ -281,6 +265,7 @@ class StakingClient extends base_1.BaseEthersClient {
281
265
  *
282
266
  * > Must have tokens available to withdraw
283
267
  *
268
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
284
269
  * @returns Returns void if successful. Throws error if any.
285
270
  *
286
271
  *
@@ -300,11 +285,9 @@ class StakingClient extends base_1.BaseEthersClient {
300
285
  * await stakingClient.withdraw();
301
286
  * ```
302
287
  */
303
- async withdraw() {
288
+ async withdraw(txOptions = {}) {
304
289
  try {
305
- await this.stakingContract.withdraw({
306
- ...(await this.gasPriceOptions()),
307
- });
290
+ await (await this.stakingContract.withdraw(txOptions)).wait();
308
291
  return;
309
292
  }
310
293
  catch (e) {
@@ -317,7 +300,8 @@ class StakingClient extends base_1.BaseEthersClient {
317
300
  * @param {string} slasher Wallet address from who requested the slash
318
301
  * @param {string} staker Wallet address from who is going to be slashed
319
302
  * @param {string} escrowAddress Address of the escrow which allocation will be slashed
320
- * @param {BigNumber} amount Amount in WEI of tokens to unstake.
303
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
304
+ * @param {bigint} amount Amount in WEI of tokens to unstake.
321
305
  * @returns Returns void if successful. Throws error if any.
322
306
  *
323
307
  *
@@ -334,28 +318,26 @@ class StakingClient extends base_1.BaseEthersClient {
334
318
  * const signer = new Wallet(privateKey, provider);
335
319
  * const stakingClient = await StakingClient.build(signer);
336
320
  *
337
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
321
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
338
322
  * await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
339
323
  * ```
340
324
  */
341
- async slash(slasher, staker, escrowAddress, amount) {
342
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
325
+ async slash(slasher, staker, escrowAddress, amount, txOptions = {}) {
326
+ if (typeof amount !== 'bigint') {
343
327
  throw error_1.ErrorInvalidStakingValueType;
344
328
  }
345
- if (amount.isNegative()) {
329
+ if (amount < 0n) {
346
330
  throw error_1.ErrorInvalidStakingValueSign;
347
331
  }
348
- if (!ethers_1.ethers.utils.isAddress(slasher)) {
332
+ if (!ethers_1.ethers.isAddress(slasher)) {
349
333
  throw error_1.ErrorInvalidSlasherAddressProvided;
350
334
  }
351
- if (!ethers_1.ethers.utils.isAddress(staker)) {
335
+ if (!ethers_1.ethers.isAddress(staker)) {
352
336
  throw error_1.ErrorInvalidStakerAddressProvided;
353
337
  }
354
338
  await this.checkValidEscrow(escrowAddress);
355
339
  try {
356
- await this.stakingContract.slash(slasher, staker, escrowAddress, amount, {
357
- ...(await this.gasPriceOptions()),
358
- });
340
+ await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, txOptions)).wait();
359
341
  return;
360
342
  }
361
343
  catch (e) {
@@ -368,7 +350,8 @@ class StakingClient extends base_1.BaseEthersClient {
368
350
  * > Must have tokens staked
369
351
  *
370
352
  * @param {string} escrowAddress Address of the escrow contract to allocate in.
371
- * @param {BigNumber} amount Amount in WEI of tokens to allocate.
353
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
354
+ * @param {bigint} amount Amount in WEI of tokens to allocate.
372
355
  * @returns Returns void if successful. Throws error if any.
373
356
  *
374
357
  *
@@ -385,22 +368,20 @@ class StakingClient extends base_1.BaseEthersClient {
385
368
  * const signer = new Wallet(privateKey, provider);
386
369
  * const stakingClient = await StakingClient.build(signer);
387
370
  *
388
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
371
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
389
372
  * await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
390
373
  * ```
391
374
  */
392
- async allocate(escrowAddress, amount) {
393
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
375
+ async allocate(escrowAddress, amount, txOptions = {}) {
376
+ if (typeof amount !== 'bigint') {
394
377
  throw error_1.ErrorInvalidStakingValueType;
395
378
  }
396
- if (amount.isNegative()) {
379
+ if (amount < 0n) {
397
380
  throw error_1.ErrorInvalidStakingValueSign;
398
381
  }
399
382
  await this.checkValidEscrow(escrowAddress);
400
383
  try {
401
- await this.stakingContract.allocate(escrowAddress, amount, {
402
- ...(await this.gasPriceOptions()),
403
- });
384
+ await (await this.stakingContract.allocate(escrowAddress, amount, txOptions)).wait();
404
385
  return;
405
386
  }
406
387
  catch (e) {
@@ -414,6 +395,7 @@ class StakingClient extends base_1.BaseEthersClient {
414
395
  * > The escrow must be cancelled or completed.
415
396
  *
416
397
  * @param {string} escrowAddress Address of the escrow contract to close allocation from.
398
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
417
399
  * @returns Returns void if successful. Throws error if any.
418
400
  *
419
401
  *
@@ -433,12 +415,10 @@ class StakingClient extends base_1.BaseEthersClient {
433
415
  * await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
434
416
  * ```
435
417
  */
436
- async closeAllocation(escrowAddress) {
418
+ async closeAllocation(escrowAddress, txOptions = {}) {
437
419
  await this.checkValidEscrow(escrowAddress);
438
420
  try {
439
- await this.stakingContract.closeAllocation(escrowAddress, {
440
- ...(await this.gasPriceOptions()),
441
- });
421
+ await (await this.stakingContract.closeAllocation(escrowAddress, txOptions)).wait();
442
422
  return;
443
423
  }
444
424
  catch (e) {
@@ -451,6 +431,7 @@ class StakingClient extends base_1.BaseEthersClient {
451
431
  * > The escrow must have rewards added
452
432
  *
453
433
  * @param {string} escrowAddress Escrow address from which rewards are distributed.
434
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
454
435
  * @returns Returns void if successful. Throws error if any.
455
436
  *
456
437
  *
@@ -470,85 +451,16 @@ class StakingClient extends base_1.BaseEthersClient {
470
451
  * await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
471
452
  * ```
472
453
  */
473
- async distributeReward(escrowAddress) {
454
+ async distributeReward(escrowAddress, txOptions = {}) {
474
455
  await this.checkValidEscrow(escrowAddress);
475
456
  try {
476
- this.rewardPoolContract.distributeReward(escrowAddress, {
477
- ...(await this.gasPriceOptions()),
478
- });
457
+ (await this.rewardPoolContract.distributeReward(escrowAddress, txOptions)).wait();
479
458
  return;
480
459
  }
481
460
  catch (e) {
482
461
  return (0, utils_1.throwError)(e);
483
462
  }
484
463
  }
485
- /**
486
- * This function returns all the leader details of the protocol.
487
- *
488
- * @param {ILeadersFilter} filter Filter for the leaders.
489
- * @returns {ILeader[]} Returns an array with all the leader details.
490
- *
491
- *
492
- * **Code example**
493
- *
494
- * ```ts
495
- * import { StakingClient } from '@human-protocol/sdk';
496
- * import { providers } from 'ethers';
497
- *
498
- * const rpcUrl = 'YOUR_RPC_URL';
499
- *
500
- * const provider = new providers.JsonRpcProvider(rpcUrl);
501
- * const stakingClient = await StakingClient.build(provider);
502
- *
503
- * const leaders = await stakingClient.getLeaders();
504
- * ```
505
- */
506
- async getLeader(address) {
507
- if (!ethers_1.ethers.utils.isAddress(address)) {
508
- throw error_1.ErrorInvalidStakerAddressProvided;
509
- }
510
- try {
511
- const { leader } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, staking_1.GET_LEADER_QUERY, {
512
- address: address.toLowerCase(),
513
- });
514
- return leader;
515
- }
516
- catch (e) {
517
- return (0, utils_1.throwError)(e);
518
- }
519
- }
520
- /**
521
- * This function returns the leader data for the given address.
522
- *
523
- * @param {string} address Leader address.
524
- * @returns {ILeader} Returns the leader details.
525
- *
526
- *
527
- * **Code example**
528
- *
529
- * ```ts
530
- * import { StakingClient } from '@human-protocol/sdk';
531
- * import { providers } from 'ethers';
532
- *
533
- * const rpcUrl = 'YOUR_RPC_URL';
534
- *
535
- * const provider = new providers.JsonRpcProvider(rpcUrl);
536
- * const stakingClient = await StakingClient.build(provider);
537
- *
538
- * const leader = await stakingClient.getLeader('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
539
- * ```
540
- */
541
- async getLeaders(filter = {}) {
542
- try {
543
- const { leaders } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, (0, staking_1.GET_LEADERS_QUERY)(filter), {
544
- role: filter.role,
545
- });
546
- return leaders;
547
- }
548
- catch (e) {
549
- return (0, utils_1.throwError)(e);
550
- }
551
- }
552
464
  /**
553
465
  * This function returns information about the allocation of the specified escrow.
554
466
  *
@@ -580,93 +492,53 @@ class StakingClient extends base_1.BaseEthersClient {
580
492
  return (0, utils_1.throwError)(e);
581
493
  }
582
494
  }
583
- /**
584
- * This function returns information about the rewards for a given slasher address.
585
- *
586
- * @param {string} slasherAddress Slasher address.
587
- * @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
588
- *
589
- *
590
- * **Code example**
591
- *
592
- * ```ts
593
- * import { StakingClient } from '@human-protocol/sdk';
594
- * import { providers } from 'ethers';
595
- *
596
- * const rpcUrl = 'YOUR_RPC_URL';
597
- *
598
- * const provider = new providers.JsonRpcProvider(rpcUrl);
599
- * const stakingClient = await StakingClient.build(provider);
600
- *
601
- * const rewards = await stakingClient.getRewards('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
602
- * ```
603
- */
604
- async getRewards(slasherAddress) {
605
- if (!ethers_1.ethers.utils.isAddress(slasherAddress)) {
606
- throw error_1.ErrorInvalidSlasherAddressProvided;
607
- }
608
- try {
609
- const { rewardAddedEvents } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
610
- slasherAddress: slasherAddress.toLowerCase(),
611
- });
612
- return rewardAddedEvents.map((reward) => {
613
- return {
614
- escrowAddress: reward.escrow,
615
- amount: reward.amount,
616
- };
617
- });
618
- }
619
- catch (e) {
620
- return (0, utils_1.throwError)(e);
621
- }
622
- }
623
495
  }
624
496
  __decorate([
625
497
  decorators_1.requiresSigner,
626
498
  __metadata("design:type", Function),
627
- __metadata("design:paramtypes", [ethers_1.BigNumber]),
499
+ __metadata("design:paramtypes", [BigInt, Object]),
628
500
  __metadata("design:returntype", Promise)
629
501
  ], StakingClient.prototype, "approveStake", null);
630
502
  __decorate([
631
503
  decorators_1.requiresSigner,
632
504
  __metadata("design:type", Function),
633
- __metadata("design:paramtypes", [ethers_1.BigNumber]),
505
+ __metadata("design:paramtypes", [BigInt, Object]),
634
506
  __metadata("design:returntype", Promise)
635
507
  ], StakingClient.prototype, "stake", null);
636
508
  __decorate([
637
509
  decorators_1.requiresSigner,
638
510
  __metadata("design:type", Function),
639
- __metadata("design:paramtypes", [ethers_1.BigNumber]),
511
+ __metadata("design:paramtypes", [BigInt, Object]),
640
512
  __metadata("design:returntype", Promise)
641
513
  ], StakingClient.prototype, "unstake", null);
642
514
  __decorate([
643
515
  decorators_1.requiresSigner,
644
516
  __metadata("design:type", Function),
645
- __metadata("design:paramtypes", []),
517
+ __metadata("design:paramtypes", [Object]),
646
518
  __metadata("design:returntype", Promise)
647
519
  ], StakingClient.prototype, "withdraw", null);
648
520
  __decorate([
649
521
  decorators_1.requiresSigner,
650
522
  __metadata("design:type", Function),
651
- __metadata("design:paramtypes", [String, String, String, ethers_1.BigNumber]),
523
+ __metadata("design:paramtypes", [String, String, String, BigInt, Object]),
652
524
  __metadata("design:returntype", Promise)
653
525
  ], StakingClient.prototype, "slash", null);
654
526
  __decorate([
655
527
  decorators_1.requiresSigner,
656
528
  __metadata("design:type", Function),
657
- __metadata("design:paramtypes", [String, ethers_1.BigNumber]),
529
+ __metadata("design:paramtypes", [String, BigInt, Object]),
658
530
  __metadata("design:returntype", Promise)
659
531
  ], StakingClient.prototype, "allocate", null);
660
532
  __decorate([
661
533
  decorators_1.requiresSigner,
662
534
  __metadata("design:type", Function),
663
- __metadata("design:paramtypes", [String]),
535
+ __metadata("design:paramtypes", [String, Object]),
664
536
  __metadata("design:returntype", Promise)
665
537
  ], StakingClient.prototype, "closeAllocation", null);
666
538
  __decorate([
667
539
  decorators_1.requiresSigner,
668
540
  __metadata("design:type", Function),
669
- __metadata("design:paramtypes", [String]),
541
+ __metadata("design:paramtypes", [String, Object]),
670
542
  __metadata("design:returntype", Promise)
671
543
  ], StakingClient.prototype, "distributeReward", null);
672
544
  exports.StakingClient = StakingClient;
@@ -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,EAEjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,gBAAgB;IACpB,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;OAIG;gBACS,WAAW,EAAE,WAAW;IAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA6B5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAoB5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkEG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IA2B7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgFG;IACG,gBAAgB,CACpB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC;CAuC1B"}
1
+ {"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,gBAAgB,EAGhB,aAAa,EAEb,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,gBAAgB;IACpB,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;OAIG;gBACS,WAAW,EAAE,WAAW;IAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA6B5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACG,mBAAmB,CACvB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAoB5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkEG;IACG,oBAAoB,CACxB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IA0B7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgFG;IACG,gBAAgB,CACpB,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,aAAa,CAAC;CAuC1B"}
@@ -264,11 +264,12 @@ class StatisticsClient {
264
264
  return {
265
265
  dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
266
266
  timestamp: new Date(+eventDayData.timestamp * 1000),
267
- totalAmountPaid: ethers_1.BigNumber.from(eventDayData.dailyPayoutAmount),
267
+ totalAmountPaid: ethers_1.ethers.toBigInt(eventDayData.dailyPayoutAmount),
268
268
  totalCount: +eventDayData.dailyPayoutCount,
269
269
  averageAmountPerWorker: eventDayData.dailyWorkerCount === '0'
270
- ? ethers_1.BigNumber.from(0)
271
- : ethers_1.BigNumber.from(eventDayData.dailyPayoutAmount).div(eventDayData.dailyWorkerCount),
270
+ ? ethers_1.ethers.toBigInt(0)
271
+ : ethers_1.ethers.toBigInt(eventDayData.dailyPayoutAmount) /
272
+ ethers_1.ethers.toBigInt(eventDayData.dailyWorkerCount),
272
273
  })),
273
274
  };
274
275
  }
@@ -366,16 +367,16 @@ class StatisticsClient {
366
367
  to: params.to ? params.to.getTime() / 1000 : undefined,
367
368
  });
368
369
  return {
369
- totalTransferAmount: ethers_1.BigNumber.from(hmtokenStatistics.totalValueTransfered),
370
+ totalTransferAmount: ethers_1.ethers.toBigInt(hmtokenStatistics.totalValueTransfered),
370
371
  totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
371
372
  totalHolders: +hmtokenStatistics.holders,
372
373
  holders: holders.map((holder) => ({
373
374
  address: holder.address,
374
- balance: ethers_1.BigNumber.from(holder.balance),
375
+ balance: ethers_1.ethers.toBigInt(holder.balance),
375
376
  })),
376
377
  dailyHMTData: eventDayDatas.map((eventDayData) => ({
377
378
  timestamp: new Date(+eventDayData.timestamp * 1000),
378
- totalTransactionAmount: ethers_1.BigNumber.from(eventDayData.dailyHMTTransferAmount),
379
+ totalTransactionAmount: ethers_1.ethers.toBigInt(eventDayData.dailyHMTTransferAmount),
379
380
  totalTransactionCount: +eventDayData.dailyHMTTransferCount,
380
381
  })),
381
382
  };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { BigNumber } from 'ethers';
2
1
  /**
3
2
  * Enum for escrow statuses.
4
3
  * @readonly
@@ -144,6 +143,6 @@ export type EscrowCancel = {
144
143
  /**
145
144
  * The amount refunded in the escrow cancellation.
146
145
  */
147
- amountRefunded: BigNumber;
146
+ amountRefunded: bigint;
148
147
  };
149
148
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;;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,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,SAAS,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;CACV;AAED;;;;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,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,3 @@
1
- import { Provider } from '@ethersproject/abstract-provider';
2
- import { BigNumber, Signer } from 'ethers';
3
- /**
4
- * **Get specific error text.*
5
- *
6
- * @param {any} error - An error message.
7
- * @returns
8
- */
9
- export declare const getRevertReason: (error: any) => string;
10
1
  /**
11
2
  * **Handle and throw the error.*
12
3
  *
@@ -21,10 +12,4 @@ export declare const throwError: (e: any) => never;
21
12
  * @returns
22
13
  */
23
14
  export declare const isValidUrl: (url: string) => boolean;
24
- /**
25
- * Increase/Decrease gas price
26
- *
27
- * @returns {Promise<BigNumber>} Returns the adjusted gas price
28
- */
29
- export declare const gasPriceAdjusted: (signerOrProvider: Signer | Provider, gasPriceMultiplier: number) => Promise<BigNumber>;
30
15
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAenD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,GAAG,KAAG,MAO5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAqBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,qBACT,MAAM,GAAG,QAAQ,sBACf,MAAM,KACzB,QAAQ,SAAS,CAgBnB,CAAC"}
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"}