@human-protocol/sdk 1.1.19 → 2.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 (55) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +3 -3
  4. package/dist/constants.js +3 -3
  5. package/dist/decorators.d.ts.map +1 -1
  6. package/dist/decorators.js +4 -2
  7. package/dist/error.d.ts +0 -6
  8. package/dist/error.d.ts.map +1 -1
  9. package/dist/error.js +2 -14
  10. package/dist/escrow.d.ts +23 -24
  11. package/dist/escrow.d.ts.map +1 -1
  12. package/dist/escrow.js +86 -90
  13. package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
  14. package/dist/graphql/queries/operator.d.ts.map +1 -0
  15. package/dist/graphql/queries/{staking.js → operator.js} +24 -1
  16. package/dist/graphql/types.d.ts +5 -6
  17. package/dist/graphql/types.d.ts.map +1 -1
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -1
  21. package/dist/interfaces.d.ts +28 -18
  22. package/dist/interfaces.d.ts.map +1 -1
  23. package/dist/kvstore.d.ts +41 -20
  24. package/dist/kvstore.d.ts.map +1 -1
  25. package/dist/kvstore.js +61 -45
  26. package/dist/operator.d.ts +68 -0
  27. package/dist/operator.d.ts.map +1 -0
  28. package/dist/operator.js +153 -0
  29. package/dist/staking.d.ts +24 -91
  30. package/dist/staking.d.ts.map +1 -1
  31. package/dist/staking.js +47 -166
  32. package/dist/statistics.d.ts.map +1 -1
  33. package/dist/statistics.js +7 -6
  34. package/dist/types.d.ts +1 -2
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils.d.ts +0 -7
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js +8 -28
  39. package/package.json +4 -4
  40. package/src/base.ts +5 -6
  41. package/src/constants.ts +3 -3
  42. package/src/decorators.ts +3 -2
  43. package/src/error.ts +0 -12
  44. package/src/escrow.ts +101 -114
  45. package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
  46. package/src/graphql/types.ts +5 -7
  47. package/src/index.ts +2 -0
  48. package/src/interfaces.ts +30 -18
  49. package/src/kvstore.ts +73 -52
  50. package/src/operator.ts +192 -0
  51. package/src/staking.ts +49 -182
  52. package/src/statistics.ts +8 -9
  53. package/src/types.ts +1 -3
  54. package/src/utils.ts +7 -29
  55. 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,43 +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
95
  */
102
- constructor(signerOrProvider, networkData) {
103
- super(signerOrProvider, networkData);
104
- this.stakingContract = typechain_types_1.Staking__factory.connect(networkData.stakingAddress, signerOrProvider);
105
- this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(networkData.factoryAddress, signerOrProvider);
106
- this.tokenContract = typechain_types_1.HMToken__factory.connect(networkData.hmtAddress, signerOrProvider);
107
- 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);
108
102
  }
109
103
  /**
110
- * Creates an instance of StakingClient from a Signer or Provider.
104
+ * Creates an instance of StakingClient from a Runner.
111
105
  *
112
- * @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
113
107
  * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
114
108
  *
115
109
  * @returns {Promise<StakingClient>} - An instance of StakingClient
116
110
  * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
117
111
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
118
112
  */
119
- static async build(signerOrProvider) {
120
- let network;
121
- if (ethers_1.Signer.isSigner(signerOrProvider)) {
122
- if (!signerOrProvider.provider) {
123
- throw error_1.ErrorProviderDoesNotExist;
124
- }
125
- network = await signerOrProvider.provider.getNetwork();
126
- }
127
- else {
128
- network = await signerOrProvider.getNetwork();
129
- }
130
- 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);
131
119
  const networkData = constants_1.NETWORKS[chainId];
132
120
  if (!networkData) {
133
121
  throw error_1.ErrorUnsupportedChainID;
134
122
  }
135
- return new StakingClient(signerOrProvider, networkData);
123
+ return new StakingClient(runner, networkData);
136
124
  }
137
125
  /**
138
126
  * Check if escrow exists
@@ -140,7 +128,7 @@ class StakingClient extends base_1.BaseEthersClient {
140
128
  * @param escrowAddress Escrow address to check against
141
129
  */
142
130
  async checkValidEscrow(escrowAddress) {
143
- if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
131
+ if (!ethers_1.ethers.isAddress(escrowAddress)) {
144
132
  throw error_1.ErrorInvalidEscrowAddressProvided;
145
133
  }
146
134
  if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
@@ -150,7 +138,7 @@ class StakingClient extends base_1.BaseEthersClient {
150
138
  /**
151
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.
152
140
  *
153
- * @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.
154
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
  *
@@ -168,19 +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
163
  async approveStake(amount, txOptions = {}) {
176
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
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 (await this.tokenContract.approve(this.stakingContract.address, amount, txOptions)).wait();
171
+ await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, txOptions)).wait();
184
172
  return;
185
173
  }
186
174
  catch (e) {
@@ -192,7 +180,7 @@ class StakingClient extends base_1.BaseEthersClient {
192
180
  *
193
181
  * > `approveStake` must be called before
194
182
  *
195
- * @param {BigNumber} amount Amount in WEI of tokens to stake.
183
+ * @param {bigint} amount Amount in WEI of tokens to stake.
196
184
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
197
185
  * @returns Returns void if successful. Throws error if any.
198
186
  *
@@ -210,16 +198,16 @@ class StakingClient extends base_1.BaseEthersClient {
210
198
  * const signer = new Wallet(privateKey, provider);
211
199
  * const stakingClient = await StakingClient.build(signer);
212
200
  *
213
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
201
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
214
202
  * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
215
203
  * await stakingClient.approveStake(amount);
216
204
  * ```
217
205
  */
218
206
  async stake(amount, txOptions = {}) {
219
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
207
+ if (typeof amount !== 'bigint') {
220
208
  throw error_1.ErrorInvalidStakingValueType;
221
209
  }
222
- if (amount.isNegative()) {
210
+ if (amount < 0n) {
223
211
  throw error_1.ErrorInvalidStakingValueSign;
224
212
  }
225
213
  try {
@@ -235,7 +223,7 @@ class StakingClient extends base_1.BaseEthersClient {
235
223
  *
236
224
  * > Must have tokens available to unstake
237
225
  *
238
- * @param {BigNumber} amount Amount in WEI of tokens to unstake.
226
+ * @param {bigint} amount Amount in WEI of tokens to unstake.
239
227
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
240
228
  * @returns Returns void if successful. Throws error if any.
241
229
  *
@@ -253,15 +241,15 @@ class StakingClient extends base_1.BaseEthersClient {
253
241
  * const signer = new Wallet(privateKey, provider);
254
242
  * const stakingClient = await StakingClient.build(signer);
255
243
  *
256
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
244
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
257
245
  * await stakingClient.unstake(amount);
258
246
  * ```
259
247
  */
260
248
  async unstake(amount, txOptions = {}) {
261
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
249
+ if (typeof amount !== 'bigint') {
262
250
  throw error_1.ErrorInvalidStakingValueType;
263
251
  }
264
- if (amount.isNegative()) {
252
+ if (amount < 0n) {
265
253
  throw error_1.ErrorInvalidStakingValueSign;
266
254
  }
267
255
  try {
@@ -313,7 +301,7 @@ class StakingClient extends base_1.BaseEthersClient {
313
301
  * @param {string} staker Wallet address from who is going to be slashed
314
302
  * @param {string} escrowAddress Address of the escrow which allocation will be slashed
315
303
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
316
- * @param {BigNumber} amount Amount in WEI of tokens to unstake.
304
+ * @param {bigint} amount Amount in WEI of tokens to unstake.
317
305
  * @returns Returns void if successful. Throws error if any.
318
306
  *
319
307
  *
@@ -330,21 +318,21 @@ class StakingClient extends base_1.BaseEthersClient {
330
318
  * const signer = new Wallet(privateKey, provider);
331
319
  * const stakingClient = await StakingClient.build(signer);
332
320
  *
333
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
321
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
334
322
  * await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
335
323
  * ```
336
324
  */
337
325
  async slash(slasher, staker, escrowAddress, amount, txOptions = {}) {
338
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
326
+ if (typeof amount !== 'bigint') {
339
327
  throw error_1.ErrorInvalidStakingValueType;
340
328
  }
341
- if (amount.isNegative()) {
329
+ if (amount < 0n) {
342
330
  throw error_1.ErrorInvalidStakingValueSign;
343
331
  }
344
- if (!ethers_1.ethers.utils.isAddress(slasher)) {
332
+ if (!ethers_1.ethers.isAddress(slasher)) {
345
333
  throw error_1.ErrorInvalidSlasherAddressProvided;
346
334
  }
347
- if (!ethers_1.ethers.utils.isAddress(staker)) {
335
+ if (!ethers_1.ethers.isAddress(staker)) {
348
336
  throw error_1.ErrorInvalidStakerAddressProvided;
349
337
  }
350
338
  await this.checkValidEscrow(escrowAddress);
@@ -363,7 +351,7 @@ class StakingClient extends base_1.BaseEthersClient {
363
351
  *
364
352
  * @param {string} escrowAddress Address of the escrow contract to allocate in.
365
353
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
366
- * @param {BigNumber} amount Amount in WEI of tokens to allocate.
354
+ * @param {bigint} amount Amount in WEI of tokens to allocate.
367
355
  * @returns Returns void if successful. Throws error if any.
368
356
  *
369
357
  *
@@ -380,15 +368,15 @@ class StakingClient extends base_1.BaseEthersClient {
380
368
  * const signer = new Wallet(privateKey, provider);
381
369
  * const stakingClient = await StakingClient.build(signer);
382
370
  *
383
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
371
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
384
372
  * await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
385
373
  * ```
386
374
  */
387
375
  async allocate(escrowAddress, amount, txOptions = {}) {
388
- if (!ethers_1.BigNumber.isBigNumber(amount)) {
376
+ if (typeof amount !== 'bigint') {
389
377
  throw error_1.ErrorInvalidStakingValueType;
390
378
  }
391
- if (amount.isNegative()) {
379
+ if (amount < 0n) {
392
380
  throw error_1.ErrorInvalidStakingValueSign;
393
381
  }
394
382
  await this.checkValidEscrow(escrowAddress);
@@ -473,73 +461,6 @@ class StakingClient extends base_1.BaseEthersClient {
473
461
  return (0, utils_1.throwError)(e);
474
462
  }
475
463
  }
476
- /**
477
- * This function returns all the leader details of the protocol.
478
- *
479
- * @param {ILeadersFilter} filter Filter for the leaders.
480
- * @returns {ILeader[]} Returns an array with all the leader details.
481
- *
482
- *
483
- * **Code example**
484
- *
485
- * ```ts
486
- * import { StakingClient } from '@human-protocol/sdk';
487
- * import { providers } from 'ethers';
488
- *
489
- * const rpcUrl = 'YOUR_RPC_URL';
490
- *
491
- * const provider = new providers.JsonRpcProvider(rpcUrl);
492
- * const stakingClient = await StakingClient.build(provider);
493
- *
494
- * const leaders = await stakingClient.getLeaders();
495
- * ```
496
- */
497
- async getLeader(address) {
498
- if (!ethers_1.ethers.utils.isAddress(address)) {
499
- throw error_1.ErrorInvalidStakerAddressProvided;
500
- }
501
- try {
502
- const { leader } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, staking_1.GET_LEADER_QUERY, {
503
- address: address.toLowerCase(),
504
- });
505
- return leader;
506
- }
507
- catch (e) {
508
- return (0, utils_1.throwError)(e);
509
- }
510
- }
511
- /**
512
- * This function returns the leader data for the given address.
513
- *
514
- * @param {string} address Leader address.
515
- * @returns {ILeader} Returns the leader details.
516
- *
517
- *
518
- * **Code example**
519
- *
520
- * ```ts
521
- * import { StakingClient } from '@human-protocol/sdk';
522
- * import { providers } from 'ethers';
523
- *
524
- * const rpcUrl = 'YOUR_RPC_URL';
525
- *
526
- * const provider = new providers.JsonRpcProvider(rpcUrl);
527
- * const stakingClient = await StakingClient.build(provider);
528
- *
529
- * const leader = await stakingClient.getLeader('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
530
- * ```
531
- */
532
- async getLeaders(filter = {}) {
533
- try {
534
- const { leaders } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, (0, staking_1.GET_LEADERS_QUERY)(filter), {
535
- role: filter.role,
536
- });
537
- return leaders;
538
- }
539
- catch (e) {
540
- return (0, utils_1.throwError)(e);
541
- }
542
- }
543
464
  /**
544
465
  * This function returns information about the allocation of the specified escrow.
545
466
  *
@@ -571,63 +492,23 @@ class StakingClient extends base_1.BaseEthersClient {
571
492
  return (0, utils_1.throwError)(e);
572
493
  }
573
494
  }
574
- /**
575
- * This function returns information about the rewards for a given slasher address.
576
- *
577
- * @param {string} slasherAddress Slasher address.
578
- * @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
579
- *
580
- *
581
- * **Code example**
582
- *
583
- * ```ts
584
- * import { StakingClient } from '@human-protocol/sdk';
585
- * import { providers } from 'ethers';
586
- *
587
- * const rpcUrl = 'YOUR_RPC_URL';
588
- *
589
- * const provider = new providers.JsonRpcProvider(rpcUrl);
590
- * const stakingClient = await StakingClient.build(provider);
591
- *
592
- * const rewards = await stakingClient.getRewards('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
593
- * ```
594
- */
595
- async getRewards(slasherAddress) {
596
- if (!ethers_1.ethers.utils.isAddress(slasherAddress)) {
597
- throw error_1.ErrorInvalidSlasherAddressProvided;
598
- }
599
- try {
600
- const { rewardAddedEvents } = await (0, graphql_request_1.default)(this.networkData.subgraphUrl, reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
601
- slasherAddress: slasherAddress.toLowerCase(),
602
- });
603
- return rewardAddedEvents.map((reward) => {
604
- return {
605
- escrowAddress: reward.escrow,
606
- amount: reward.amount,
607
- };
608
- });
609
- }
610
- catch (e) {
611
- return (0, utils_1.throwError)(e);
612
- }
613
- }
614
495
  }
615
496
  __decorate([
616
497
  decorators_1.requiresSigner,
617
498
  __metadata("design:type", Function),
618
- __metadata("design:paramtypes", [ethers_1.BigNumber, Object]),
499
+ __metadata("design:paramtypes", [BigInt, Object]),
619
500
  __metadata("design:returntype", Promise)
620
501
  ], StakingClient.prototype, "approveStake", null);
621
502
  __decorate([
622
503
  decorators_1.requiresSigner,
623
504
  __metadata("design:type", Function),
624
- __metadata("design:paramtypes", [ethers_1.BigNumber, Object]),
505
+ __metadata("design:paramtypes", [BigInt, Object]),
625
506
  __metadata("design:returntype", Promise)
626
507
  ], StakingClient.prototype, "stake", null);
627
508
  __decorate([
628
509
  decorators_1.requiresSigner,
629
510
  __metadata("design:type", Function),
630
- __metadata("design:paramtypes", [ethers_1.BigNumber, Object]),
511
+ __metadata("design:paramtypes", [BigInt, Object]),
631
512
  __metadata("design:returntype", Promise)
632
513
  ], StakingClient.prototype, "unstake", null);
633
514
  __decorate([
@@ -639,13 +520,13 @@ __decorate([
639
520
  __decorate([
640
521
  decorators_1.requiresSigner,
641
522
  __metadata("design:type", Function),
642
- __metadata("design:paramtypes", [String, String, String, ethers_1.BigNumber, Object]),
523
+ __metadata("design:paramtypes", [String, String, String, BigInt, Object]),
643
524
  __metadata("design:returntype", Promise)
644
525
  ], StakingClient.prototype, "slash", null);
645
526
  __decorate([
646
527
  decorators_1.requiresSigner,
647
528
  __metadata("design:type", Function),
648
- __metadata("design:paramtypes", [String, ethers_1.BigNumber, Object]),
529
+ __metadata("design:paramtypes", [String, BigInt, Object]),
649
530
  __metadata("design:returntype", Promise)
650
531
  ], StakingClient.prototype, "allocate", null);
651
532
  __decorate([
@@ -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;;;;;;;;;;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;;;;;;;;;;;;;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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C;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,10 +1,3 @@
1
- /**
2
- * **Get specific error text.*
3
- *
4
- * @param {any} error - An error message.
5
- * @returns
6
- */
7
- export declare const getRevertReason: (error: any) => string;
8
1
  /**
9
2
  * **Handle and throw the error.*
10
3
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAeA;;;;;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"}
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"}
package/dist/utils.js CHANGED
@@ -1,22 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidUrl = exports.throwError = exports.getRevertReason = void 0;
3
+ exports.isValidUrl = exports.throwError = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  const ethers_1 = require("ethers");
6
6
  const error_1 = require("./error");
7
- /**
8
- * **Get specific error text.*
9
- *
10
- * @param {any} error - An error message.
11
- * @returns
12
- */
13
- const getRevertReason = (error) => {
14
- const prefix = "reverted with reason string '";
15
- const suffix = "'";
16
- const message = error.data.substring(error.data.indexOf(prefix) + prefix.length);
17
- return message.substring(0, message.indexOf(suffix));
18
- };
19
- exports.getRevertReason = getRevertReason;
20
7
  /**
21
8
  * **Handle and throw the error.*
22
9
  *
@@ -24,29 +11,22 @@ exports.getRevertReason = getRevertReason;
24
11
  * @returns
25
12
  */
26
13
  const throwError = (e) => {
27
- if (e.code === ethers_1.ethers.utils.Logger.errors.INVALID_ARGUMENT) {
14
+ if (ethers_1.ethers.isError(e, 'INVALID_ARGUMENT')) {
28
15
  throw new error_1.InvalidArgumentError(e.message);
29
16
  }
30
- else if (e.code === 'OUT_OF_GAS') {
31
- throw new error_1.OutOfGasError(e.message);
32
- }
33
- else if (e.code === ethers_1.ethers.utils.Logger.errors.CALL_EXCEPTION) {
34
- const reason = (0, exports.getRevertReason)(e.data);
35
- throw new error_1.ContractExecutionError(reason);
36
- }
37
- else if (e.code === ethers_1.ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
38
- throw new error_1.UnpredictableGasLimit(e.message);
17
+ else if (ethers_1.ethers.isError(e, 'CALL_EXCEPTION')) {
18
+ throw new error_1.ContractExecutionError(e.reason);
39
19
  }
40
- else if (e.code === ethers_1.ethers.utils.Logger.errors.TRANSACTION_REPLACED) {
20
+ else if (ethers_1.ethers.isError(e, 'TRANSACTION_REPLACED')) {
41
21
  throw new error_1.TransactionReplaced(e.message);
42
22
  }
43
- else if (e.code === ethers_1.ethers.utils.Logger.errors.REPLACEMENT_UNDERPRICED) {
23
+ else if (ethers_1.ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {
44
24
  throw new error_1.ReplacementUnderpriced(e.message);
45
25
  }
46
- else if (e.code === ethers_1.ethers.utils.Logger.errors.NUMERIC_FAULT) {
26
+ else if (ethers_1.ethers.isError(e, 'NUMERIC_FAULT')) {
47
27
  throw new error_1.NumericFault(e.message);
48
28
  }
49
- else if (e.code === ethers_1.ethers.utils.Logger.errors.NONCE_EXPIRED) {
29
+ else if (ethers_1.ethers.isError(e, 'NONCE_EXPIRED')) {
50
30
  throw new error_1.NonceExpired(e.message);
51
31
  }
52
32
  else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "1.1.19",
4
+ "version": "2.1.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -40,11 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@human-protocol/core": "*",
43
- "aws-sdk": "^2.1255.0",
43
+ "aws-sdk": "^2.1528.0",
44
44
  "axios": "^1.4.0",
45
45
  "crypto": "^1.0.1",
46
- "ethers": "^5.7.2",
47
- "graphql": "^16.7.1",
46
+ "graphql": "^16.8.1",
48
47
  "graphql-request": "^6.1.0",
49
48
  "graphql-tag": "^2.12.6",
50
49
  "minio": "^7.0.32",
@@ -63,6 +62,7 @@
63
62
  "./src/encryption.ts",
64
63
  "./src/escrow.ts",
65
64
  "./src/kvstore.ts",
65
+ "./src/operator.ts",
66
66
  "./src/staking.ts",
67
67
  "./src/storage.ts",
68
68
  "./src/statistics.ts"
package/src/base.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Provider } from '@ethersproject/abstract-provider';
2
- import { Signer } from 'ethers';
1
+ import { ContractRunner } from 'ethers';
3
2
  import { NetworkData } from './types';
4
3
 
5
4
  /**
@@ -9,17 +8,17 @@ import { NetworkData } from './types';
9
8
  *
10
9
  */
11
10
  export abstract class BaseEthersClient {
12
- protected signerOrProvider: Signer | Provider;
11
+ protected runner: ContractRunner;
13
12
  public networkData: NetworkData;
14
13
 
15
14
  /**
16
15
  * **BaseClient constructor**
17
16
  *
18
- * @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
17
+ * @param {ContractRunner} runner The Signer or Provider object to interact with the Ethereum network
19
18
  * @param {NetworkData} networkData The network information required to connect to the contracts
20
19
  */
21
- constructor(signerOrProvider: Signer | Provider, networkData: NetworkData) {
20
+ constructor(runner: ContractRunner, networkData: NetworkData) {
22
21
  this.networkData = networkData;
23
- this.signerOrProvider = signerOrProvider;
22
+ this.runner = runner;
24
23
  }
25
24
  }
package/src/constants.ts CHANGED
@@ -260,7 +260,7 @@ export const NETWORKS: {
260
260
  stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
261
261
  rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
262
262
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
263
- subgraphUrl: '',
263
+ subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
264
264
  oldSubgraphUrl: '',
265
265
  oldFactoryAddress: '',
266
266
  },
@@ -269,8 +269,8 @@ export const NETWORKS: {
269
269
  export const KVStoreKeys = {
270
270
  role: 'role',
271
271
  fee: 'fee',
272
- publicKey: 'publicKey',
273
- webhookUrl: 'webhookUrl',
272
+ publicKey: 'public_key',
273
+ webhookUrl: 'webhook_url',
274
274
  url: 'url',
275
275
  };
276
276
 
package/src/decorators.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Signer } from 'ethers';
3
2
  import { ErrorSigner } from './error';
4
3
 
5
4
  export function requiresSigner(
@@ -10,7 +9,9 @@ export function requiresSigner(
10
9
  const originalMethod = descriptor.value;
11
10
 
12
11
  descriptor.value = async function (this: any, ...args: any[]) {
13
- if (!Signer.isSigner(this.signerOrProvider)) {
12
+ try {
13
+ !this.runner.getAddress();
14
+ } catch {
14
15
  throw ErrorSigner;
15
16
  }
16
17