@human-protocol/sdk 1.1.19 → 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 (53) 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/decorators.d.ts.map +1 -1
  5. package/dist/decorators.js +4 -2
  6. package/dist/error.d.ts +0 -6
  7. package/dist/error.d.ts.map +1 -1
  8. package/dist/error.js +2 -14
  9. package/dist/escrow.d.ts +23 -24
  10. package/dist/escrow.d.ts.map +1 -1
  11. package/dist/escrow.js +86 -90
  12. package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
  13. package/dist/graphql/queries/operator.d.ts.map +1 -0
  14. package/dist/graphql/queries/{staking.js → operator.js} +24 -1
  15. package/dist/graphql/types.d.ts +5 -6
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -1
  20. package/dist/interfaces.d.ts +28 -18
  21. package/dist/interfaces.d.ts.map +1 -1
  22. package/dist/kvstore.d.ts +8 -9
  23. package/dist/kvstore.d.ts.map +1 -1
  24. package/dist/kvstore.js +18 -31
  25. package/dist/operator.d.ts +68 -0
  26. package/dist/operator.d.ts.map +1 -0
  27. package/dist/operator.js +153 -0
  28. package/dist/staking.d.ts +24 -91
  29. package/dist/staking.d.ts.map +1 -1
  30. package/dist/staking.js +47 -166
  31. package/dist/statistics.d.ts.map +1 -1
  32. package/dist/statistics.js +7 -6
  33. package/dist/types.d.ts +1 -2
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils.d.ts +0 -7
  36. package/dist/utils.d.ts.map +1 -1
  37. package/dist/utils.js +8 -28
  38. package/package.json +4 -4
  39. package/src/base.ts +5 -6
  40. package/src/decorators.ts +3 -2
  41. package/src/error.ts +0 -12
  42. package/src/escrow.ts +101 -114
  43. package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
  44. package/src/graphql/types.ts +5 -7
  45. package/src/index.ts +2 -0
  46. package/src/interfaces.ts +30 -18
  47. package/src/kvstore.ts +20 -38
  48. package/src/operator.ts +192 -0
  49. package/src/staking.ts +49 -182
  50. package/src/statistics.ts +8 -9
  51. package/src/types.ts +1 -3
  52. package/src/utils.ts +7 -29
  53. package/dist/graphql/queries/staking.d.ts.map +0 -1
package/src/escrow.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Provider } from '@ethersproject/abstract-provider';
3
- import { Network } from '@ethersproject/networks';
4
2
  import {
5
3
  Escrow,
6
4
  EscrowFactory,
@@ -9,7 +7,7 @@ import {
9
7
  HMToken,
10
8
  HMToken__factory,
11
9
  } from '@human-protocol/core/typechain-types';
12
- import { BigNumber, ContractReceipt, Overrides, Signer, ethers } from 'ethers';
10
+ import { ContractRunner, EventLog, Overrides, ethers } from 'ethers';
13
11
  import gqlFetch from 'graphql-request';
14
12
  import { BaseEthersClient } from './base';
15
13
  import { DEFAULT_TX_ID, NETWORKS } from './constants';
@@ -21,43 +19,43 @@ import {
21
19
  ErrorEscrowAddressIsNotProvidedByFactory,
22
20
  ErrorEscrowDoesNotHaveEnoughBalance,
23
21
  ErrorHashIsEmptyString,
24
- ErrorProviderDoesNotExist,
25
- ErrorUnsupportedChainID,
26
22
  ErrorInvalidAddress,
27
23
  ErrorInvalidEscrowAddressProvided,
24
+ ErrorInvalidExchangeOracleAddressProvided,
28
25
  ErrorInvalidRecordingOracleAddressProvided,
29
26
  ErrorInvalidReputationOracleAddressProvided,
30
27
  ErrorInvalidTokenAddress,
31
28
  ErrorInvalidUrl,
32
29
  ErrorLaunchedEventIsNotEmitted,
33
30
  ErrorListOfHandlersCannotBeEmpty,
31
+ ErrorProviderDoesNotExist,
34
32
  ErrorRecipientAndAmountsMustBeSameLength,
35
33
  ErrorRecipientCannotBeEmptyArray,
36
34
  ErrorTotalFeeMustBeLessThanHundred,
35
+ ErrorTransferEventNotFoundInTransactionLogs,
36
+ ErrorUnsupportedChainID,
37
37
  ErrorUrlIsEmptyString,
38
38
  InvalidEthereumAddressError,
39
- ErrorInvalidExchangeOracleAddressProvided,
40
- ErrorTransferEventNotFoundInTransactionLogs,
41
39
  } from './error';
42
- import { IEscrowConfig, IEscrowsFilter } from './interfaces';
43
- import { EscrowCancel, EscrowStatus, NetworkData } from './types';
44
- import { isValidUrl, throwError } from './utils';
45
40
  import {
46
41
  EscrowData,
47
42
  GET_ESCROWS_QUERY,
48
43
  GET_ESCROW_BY_ADDRESS_QUERY,
49
44
  } from './graphql';
45
+ import { IEscrowConfig, IEscrowsFilter } from './interfaces';
46
+ import { EscrowCancel, EscrowStatus, NetworkData } from './types';
47
+ import { isValidUrl, throwError } from './utils';
50
48
 
51
49
  /**
52
50
  * ## Introduction
53
51
  *
54
52
  * This client enables to perform actions on Escrow contracts and obtain information from both the contracts and subgraph.
55
53
  *
56
- * Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
54
+ * Internally, the SDK will use one network or another according to the network ID of the `runner`.
57
55
  * To use this client, it is recommended to initialize it using the static `build` method.
58
56
  *
59
57
  * ```ts
60
- * static async build(signerOrProvider: Signer | Provider);
58
+ * static async build(runner: ContractRunner);
61
59
  * ```
62
60
  *
63
61
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
@@ -123,47 +121,42 @@ export class EscrowClient extends BaseEthersClient {
123
121
  /**
124
122
  * **EscrowClient constructor**
125
123
  *
126
- * @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
124
+ * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
127
125
  * @param {NetworkData} network The network information required to connect to the Escrow contract
128
126
  */
129
- constructor(signerOrProvider: Signer | Provider, networkData: NetworkData) {
130
- super(signerOrProvider, networkData);
127
+ constructor(runner: ContractRunner, networkData: NetworkData) {
128
+ super(runner, networkData);
131
129
 
132
130
  this.escrowFactoryContract = EscrowFactory__factory.connect(
133
131
  networkData.factoryAddress,
134
- signerOrProvider
132
+ runner
135
133
  );
136
134
  }
137
135
 
138
136
  /**
139
- * Creates an instance of EscrowClient from a Signer or Provider.
137
+ * Creates an instance of EscrowClient from a Runner.
140
138
  *
141
- * @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
139
+ * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
142
140
  *
143
141
  * @returns {Promise<EscrowClient>} An instance of EscrowClient
144
142
  * @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
145
143
  * @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
146
144
  */
147
- public static async build(signerOrProvider: Signer | Provider) {
148
- let network: Network;
149
- if (Signer.isSigner(signerOrProvider)) {
150
- if (!signerOrProvider.provider) {
151
- throw ErrorProviderDoesNotExist;
152
- }
153
-
154
- network = await signerOrProvider.provider.getNetwork();
155
- } else {
156
- network = await signerOrProvider.getNetwork();
145
+ public static async build(runner: ContractRunner) {
146
+ if (!runner.provider) {
147
+ throw ErrorProviderDoesNotExist;
157
148
  }
158
149
 
159
- const chainId: ChainId = network.chainId;
150
+ const network = await runner.provider?.getNetwork();
151
+
152
+ const chainId: ChainId = Number(network?.chainId);
160
153
  const networkData = NETWORKS[chainId];
161
154
 
162
155
  if (!networkData) {
163
156
  throw ErrorUnsupportedChainID;
164
157
  }
165
158
 
166
- return new EscrowClient(signerOrProvider, networkData);
159
+ return new EscrowClient(runner, networkData);
167
160
  }
168
161
 
169
162
  /**
@@ -173,7 +166,7 @@ export class EscrowClient extends BaseEthersClient {
173
166
  */
174
167
  private getEscrowContract(escrowAddress: string): Escrow {
175
168
  try {
176
- return Escrow__factory.connect(escrowAddress, this.signerOrProvider);
169
+ return Escrow__factory.connect(escrowAddress, this.runner);
177
170
  } catch (e) {
178
171
  return throwError(e);
179
172
  }
@@ -217,18 +210,18 @@ export class EscrowClient extends BaseEthersClient {
217
210
  jobRequesterId: string,
218
211
  txOptions: Overrides = {}
219
212
  ): Promise<string> {
220
- if (!ethers.utils.isAddress(tokenAddress)) {
213
+ if (!ethers.isAddress(tokenAddress)) {
221
214
  throw ErrorInvalidTokenAddress;
222
215
  }
223
216
 
224
217
  trustedHandlers.forEach((trustedHandler) => {
225
- if (!ethers.utils.isAddress(trustedHandler)) {
218
+ if (!ethers.isAddress(trustedHandler)) {
226
219
  throw new InvalidEthereumAddressError(trustedHandler);
227
220
  }
228
221
  });
229
222
 
230
223
  try {
231
- const result: ContractReceipt = await (
224
+ const result = await (
232
225
  await this.escrowFactoryContract.createEscrow(
233
226
  tokenAddress,
234
227
  trustedHandlers,
@@ -237,8 +230,10 @@ export class EscrowClient extends BaseEthersClient {
237
230
  )
238
231
  ).wait();
239
232
 
240
- const event = result.events?.find(({ topics }) =>
241
- topics.includes(ethers.utils.id('LaunchedV2(address,address,string)'))
233
+ const event = (
234
+ result?.logs?.find(({ topics }) =>
235
+ topics.includes(ethers.id('LaunchedV2(address,address,string)'))
236
+ ) as EventLog
242
237
  )?.args;
243
238
 
244
239
  if (!event) {
@@ -280,9 +275,9 @@ export class EscrowClient extends BaseEthersClient {
280
275
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
281
276
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
282
277
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
283
- * recordingOracleFee: BigNumber.from('10'),
284
- * reputationOracleFee: BigNumber.from('10'),
285
- * exchangeOracleFee: BigNumber.from('10'),
278
+ * recordingOracleFee: bigint.from('10'),
279
+ * reputationOracleFee: bigint.from('10'),
280
+ * exchangeOracleFee: bigint.from('10'),
286
281
  * manifestUrl: 'htttp://localhost/manifest.json',
287
282
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
288
283
  * };
@@ -306,33 +301,31 @@ export class EscrowClient extends BaseEthersClient {
306
301
  manifestHash,
307
302
  } = escrowConfig;
308
303
 
309
- if (!ethers.utils.isAddress(recordingOracle)) {
304
+ if (!ethers.isAddress(recordingOracle)) {
310
305
  throw ErrorInvalidRecordingOracleAddressProvided;
311
306
  }
312
307
 
313
- if (!ethers.utils.isAddress(reputationOracle)) {
308
+ if (!ethers.isAddress(reputationOracle)) {
314
309
  throw ErrorInvalidReputationOracleAddressProvided;
315
310
  }
316
311
 
317
- if (!ethers.utils.isAddress(exchangeOracle)) {
312
+ if (!ethers.isAddress(exchangeOracle)) {
318
313
  throw ErrorInvalidExchangeOracleAddressProvided;
319
314
  }
320
315
 
321
- if (!ethers.utils.isAddress(escrowAddress)) {
316
+ if (!ethers.isAddress(escrowAddress)) {
322
317
  throw ErrorInvalidEscrowAddressProvided;
323
318
  }
324
319
 
325
320
  if (
326
- recordingOracleFee.lte(0) ||
327
- reputationOracleFee.lte(0) ||
328
- exchangeOracleFee.lte(0)
321
+ recordingOracleFee <= 0 ||
322
+ reputationOracleFee <= 0 ||
323
+ exchangeOracleFee <= 0
329
324
  ) {
330
325
  throw ErrorAmountMustBeGreaterThanZero;
331
326
  }
332
327
 
333
- if (
334
- recordingOracleFee.add(reputationOracleFee).add(exchangeOracleFee).gt(100)
335
- ) {
328
+ if (recordingOracleFee + reputationOracleFee + exchangeOracleFee > 100) {
336
329
  throw ErrorTotalFeeMustBeLessThanHundred;
337
330
  }
338
331
 
@@ -406,9 +399,9 @@ export class EscrowClient extends BaseEthersClient {
406
399
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
407
400
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
408
401
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
409
- * recordingOracleFee: BigNumber.from('10'),
410
- * reputationOracleFee: BigNumber.from('10'),
411
- * exchangeOracleFee: BigNumber.from('10'),
402
+ * recordingOracleFee: bigint.from('10'),
403
+ * reputationOracleFee: bigint.from('10'),
404
+ * exchangeOracleFee: bigint.from('10'),
412
405
  * manifestUrl: 'htttp://localhost/manifest.json',
413
406
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
414
407
  * };
@@ -442,7 +435,7 @@ export class EscrowClient extends BaseEthersClient {
442
435
  * This function adds funds of the chosen token to the escrow.
443
436
  *
444
437
  * @param {string} escrowAddress Address of the escrow to fund.
445
- * @param {BigNumber} amount Amount to be added as funds.
438
+ * @param {bigint} amount Amount to be added as funds.
446
439
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
447
440
  * @returns Returns void if successful. Throws error if any.
448
441
  *
@@ -460,21 +453,21 @@ export class EscrowClient extends BaseEthersClient {
460
453
  * const signer = new Wallet(privateKey, provider);
461
454
  * const escrowClient = await EscrowClient.build(signer);
462
455
  *
463
- * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
456
+ * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
464
457
  * await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
465
458
  * ```
466
459
  */
467
460
  @requiresSigner
468
461
  async fund(
469
462
  escrowAddress: string,
470
- amount: BigNumber,
463
+ amount: bigint,
471
464
  txOptions: Overrides = {}
472
465
  ): Promise<void> {
473
- if (!ethers.utils.isAddress(escrowAddress)) {
466
+ if (!ethers.isAddress(escrowAddress)) {
474
467
  throw ErrorInvalidEscrowAddressProvided;
475
468
  }
476
469
 
477
- if (amount.lte(0)) {
470
+ if (amount <= 0n) {
478
471
  throw ErrorAmountMustBeGreaterThanZero;
479
472
  }
480
473
 
@@ -489,7 +482,7 @@ export class EscrowClient extends BaseEthersClient {
489
482
 
490
483
  const tokenContract: HMToken = HMToken__factory.connect(
491
484
  tokenAddress,
492
- this.signerOrProvider
485
+ this.runner
493
486
  );
494
487
  await (
495
488
  await tokenContract.transfer(escrowAddress, amount, txOptions)
@@ -536,7 +529,7 @@ export class EscrowClient extends BaseEthersClient {
536
529
  hash: string,
537
530
  txOptions: Overrides = {}
538
531
  ): Promise<void> {
539
- if (!ethers.utils.isAddress(escrowAddress)) {
532
+ if (!ethers.isAddress(escrowAddress)) {
540
533
  throw ErrorInvalidEscrowAddressProvided;
541
534
  }
542
535
 
@@ -598,7 +591,7 @@ export class EscrowClient extends BaseEthersClient {
598
591
  escrowAddress: string,
599
592
  txOptions: Overrides = {}
600
593
  ): Promise<void> {
601
- if (!ethers.utils.isAddress(escrowAddress)) {
594
+ if (!ethers.isAddress(escrowAddress)) {
602
595
  throw ErrorInvalidEscrowAddressProvided;
603
596
  }
604
597
 
@@ -621,7 +614,7 @@ export class EscrowClient extends BaseEthersClient {
621
614
  *
622
615
  * @param {string} escrowAddress Escrow address to payout.
623
616
  * @param {string[]} recipients Array of recipient addresses.
624
- * @param {BigNumber[]} amounts Array of amounts the recipients will receive.
617
+ * @param {bigint[]} amounts Array of amounts the recipients will receive.
625
618
  * @param {string} finalResultsUrl Final results file url.
626
619
  * @param {string} finalResultsHash Final results file hash.
627
620
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
@@ -644,7 +637,7 @@ export class EscrowClient extends BaseEthersClient {
644
637
  * const escrowClient = await EscrowClient.build(signer);
645
638
  *
646
639
  * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
647
- * const amounts = [ethers.utils.parseUnits(5, 'ether'), ethers.utils.parseUnits(10, 'ether')];
640
+ * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
648
641
  * const resultsUrl = 'http://localhost/results.json';
649
642
  * const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
650
643
  *
@@ -655,12 +648,12 @@ export class EscrowClient extends BaseEthersClient {
655
648
  async bulkPayOut(
656
649
  escrowAddress: string,
657
650
  recipients: string[],
658
- amounts: BigNumber[],
651
+ amounts: bigint[],
659
652
  finalResultsUrl: string,
660
653
  finalResultsHash: string,
661
654
  txOptions: Overrides = {}
662
655
  ): Promise<void> {
663
- if (!ethers.utils.isAddress(escrowAddress)) {
656
+ if (!ethers.isAddress(escrowAddress)) {
664
657
  throw ErrorInvalidEscrowAddressProvided;
665
658
  }
666
659
 
@@ -677,7 +670,7 @@ export class EscrowClient extends BaseEthersClient {
677
670
  }
678
671
 
679
672
  recipients.forEach((recipient) => {
680
- if (!ethers.utils.isAddress(recipient)) {
673
+ if (!ethers.isAddress(recipient)) {
681
674
  throw new InvalidEthereumAddressError(recipient);
682
675
  }
683
676
  });
@@ -696,12 +689,12 @@ export class EscrowClient extends BaseEthersClient {
696
689
 
697
690
  const balance = await this.getBalance(escrowAddress);
698
691
 
699
- let totalAmount = BigNumber.from(0);
692
+ let totalAmount = 0n;
700
693
  amounts.forEach((amount) => {
701
- totalAmount = totalAmount.add(amount);
694
+ totalAmount = totalAmount + amount;
702
695
  });
703
696
 
704
- if (balance.lt(totalAmount)) {
697
+ if (balance < totalAmount) {
705
698
  throw ErrorEscrowDoesNotHaveEnoughBalance;
706
699
  }
707
700
 
@@ -759,7 +752,7 @@ export class EscrowClient extends BaseEthersClient {
759
752
  escrowAddress: string,
760
753
  txOptions: Overrides = {}
761
754
  ): Promise<EscrowCancel> {
762
- if (!ethers.utils.isAddress(escrowAddress)) {
755
+ if (!ethers.isAddress(escrowAddress)) {
763
756
  throw ErrorInvalidEscrowAddressProvided;
764
757
  }
765
758
 
@@ -774,32 +767,35 @@ export class EscrowClient extends BaseEthersClient {
774
767
  await escrowContract.cancel(txOptions)
775
768
  ).wait();
776
769
 
777
- let amountTransferred: BigNumber | undefined = undefined;
770
+ let amountTransferred: bigint | undefined = undefined;
778
771
  const tokenAddress = await escrowContract.token();
779
772
 
780
773
  const tokenContract: HMToken = HMToken__factory.connect(
781
774
  tokenAddress,
782
- this.signerOrProvider
775
+ this.runner
783
776
  );
784
-
785
- for (const log of transactionReceipt.logs) {
786
- if (log.address === tokenAddress) {
787
- const parsedLog = tokenContract.interface.parseLog(log);
788
-
789
- const from = parsedLog.args[0];
790
- if (parsedLog.name === 'Transfer' && from === escrowAddress) {
791
- amountTransferred = parsedLog.args[2];
792
- break;
777
+ if (transactionReceipt)
778
+ for (const log of transactionReceipt.logs) {
779
+ if (log.address === tokenAddress) {
780
+ const parsedLog = tokenContract.interface.parseLog({
781
+ topics: log.topics as string[],
782
+ data: log.data,
783
+ });
784
+
785
+ const from = parsedLog?.args[0];
786
+ if (parsedLog?.name === 'Transfer' && from === escrowAddress) {
787
+ amountTransferred = parsedLog?.args[2];
788
+ break;
789
+ }
793
790
  }
794
791
  }
795
- }
796
792
 
797
793
  if (amountTransferred === undefined) {
798
794
  throw ErrorTransferEventNotFoundInTransactionLogs;
799
795
  }
800
796
 
801
797
  const escrowCancelData: EscrowCancel = {
802
- txHash: transactionReceipt.transactionHash,
798
+ txHash: transactionReceipt?.hash || '',
803
799
  amountRefunded: amountTransferred,
804
800
  };
805
801
 
@@ -837,7 +833,7 @@ export class EscrowClient extends BaseEthersClient {
837
833
  */
838
834
  @requiresSigner
839
835
  async abort(escrowAddress: string, txOptions: Overrides = {}): Promise<void> {
840
- if (!ethers.utils.isAddress(escrowAddress)) {
836
+ if (!ethers.isAddress(escrowAddress)) {
841
837
  throw ErrorInvalidEscrowAddressProvided;
842
838
  }
843
839
 
@@ -889,7 +885,7 @@ export class EscrowClient extends BaseEthersClient {
889
885
  trustedHandlers: string[],
890
886
  txOptions: Overrides = {}
891
887
  ): Promise<void> {
892
- if (!ethers.utils.isAddress(escrowAddress)) {
888
+ if (!ethers.isAddress(escrowAddress)) {
893
889
  throw ErrorInvalidEscrowAddressProvided;
894
890
  }
895
891
 
@@ -898,7 +894,7 @@ export class EscrowClient extends BaseEthersClient {
898
894
  }
899
895
 
900
896
  trustedHandlers.forEach((trustedHandler) => {
901
- if (!ethers.utils.isAddress(trustedHandler)) {
897
+ if (!ethers.isAddress(trustedHandler)) {
902
898
  throw new InvalidEthereumAddressError(trustedHandler);
903
899
  }
904
900
  });
@@ -923,7 +919,7 @@ export class EscrowClient extends BaseEthersClient {
923
919
  * This function returns the balance for a specified escrow address.
924
920
  *
925
921
  * @param {string} escrowAddress Address of the escrow.
926
- * @returns {BigNumber} Balance of the escrow in the token used to fund it.
922
+ * @returns {bigint} Balance of the escrow in the token used to fund it.
927
923
  *
928
924
  * **Code example**
929
925
  *
@@ -939,8 +935,8 @@ export class EscrowClient extends BaseEthersClient {
939
935
  * const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
940
936
  * ```
941
937
  */
942
- async getBalance(escrowAddress: string): Promise<BigNumber> {
943
- if (!ethers.utils.isAddress(escrowAddress)) {
938
+ async getBalance(escrowAddress: string): Promise<bigint> {
939
+ if (!ethers.isAddress(escrowAddress)) {
944
940
  throw ErrorInvalidEscrowAddressProvided;
945
941
  }
946
942
 
@@ -978,7 +974,7 @@ export class EscrowClient extends BaseEthersClient {
978
974
  * ```
979
975
  */
980
976
  async getManifestHash(escrowAddress: string): Promise<string> {
981
- if (!ethers.utils.isAddress(escrowAddress)) {
977
+ if (!ethers.isAddress(escrowAddress)) {
982
978
  throw ErrorInvalidEscrowAddressProvided;
983
979
  }
984
980
 
@@ -1016,7 +1012,7 @@ export class EscrowClient extends BaseEthersClient {
1016
1012
  * ```
1017
1013
  */
1018
1014
  async getManifestUrl(escrowAddress: string): Promise<string> {
1019
- if (!ethers.utils.isAddress(escrowAddress)) {
1015
+ if (!ethers.isAddress(escrowAddress)) {
1020
1016
  throw ErrorInvalidEscrowAddressProvided;
1021
1017
  }
1022
1018
 
@@ -1054,7 +1050,7 @@ export class EscrowClient extends BaseEthersClient {
1054
1050
  * ```
1055
1051
  */
1056
1052
  async getResultsUrl(escrowAddress: string): Promise<string> {
1057
- if (!ethers.utils.isAddress(escrowAddress)) {
1053
+ if (!ethers.isAddress(escrowAddress)) {
1058
1054
  throw ErrorInvalidEscrowAddressProvided;
1059
1055
  }
1060
1056
 
@@ -1092,7 +1088,7 @@ export class EscrowClient extends BaseEthersClient {
1092
1088
  * ```
1093
1089
  */
1094
1090
  async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
1095
- if (!ethers.utils.isAddress(escrowAddress)) {
1091
+ if (!ethers.isAddress(escrowAddress)) {
1096
1092
  throw ErrorInvalidEscrowAddressProvided;
1097
1093
  }
1098
1094
 
@@ -1130,7 +1126,7 @@ export class EscrowClient extends BaseEthersClient {
1130
1126
  * ```
1131
1127
  */
1132
1128
  async getTokenAddress(escrowAddress: string): Promise<string> {
1133
- if (!ethers.utils.isAddress(escrowAddress)) {
1129
+ if (!ethers.isAddress(escrowAddress)) {
1134
1130
  throw ErrorInvalidEscrowAddressProvided;
1135
1131
  }
1136
1132
 
@@ -1168,7 +1164,7 @@ export class EscrowClient extends BaseEthersClient {
1168
1164
  * ```
1169
1165
  */
1170
1166
  async getStatus(escrowAddress: string): Promise<EscrowStatus> {
1171
- if (!ethers.utils.isAddress(escrowAddress)) {
1167
+ if (!ethers.isAddress(escrowAddress)) {
1172
1168
  throw ErrorInvalidEscrowAddressProvided;
1173
1169
  }
1174
1170
 
@@ -1179,7 +1175,7 @@ export class EscrowClient extends BaseEthersClient {
1179
1175
  try {
1180
1176
  const escrowContract = this.getEscrowContract(escrowAddress);
1181
1177
 
1182
- return escrowContract.status();
1178
+ return Number(await escrowContract.status());
1183
1179
  } catch (e) {
1184
1180
  return throwError(e);
1185
1181
  }
@@ -1206,7 +1202,7 @@ export class EscrowClient extends BaseEthersClient {
1206
1202
  * ```
1207
1203
  */
1208
1204
  async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
1209
- if (!ethers.utils.isAddress(escrowAddress)) {
1205
+ if (!ethers.isAddress(escrowAddress)) {
1210
1206
  throw ErrorInvalidEscrowAddressProvided;
1211
1207
  }
1212
1208
 
@@ -1244,7 +1240,7 @@ export class EscrowClient extends BaseEthersClient {
1244
1240
  * ```
1245
1241
  */
1246
1242
  async getJobLauncherAddress(escrowAddress: string): Promise<string> {
1247
- if (!ethers.utils.isAddress(escrowAddress)) {
1243
+ if (!ethers.isAddress(escrowAddress)) {
1248
1244
  throw ErrorInvalidEscrowAddressProvided;
1249
1245
  }
1250
1246
 
@@ -1282,7 +1278,7 @@ export class EscrowClient extends BaseEthersClient {
1282
1278
  * ```
1283
1279
  */
1284
1280
  async getReputationOracleAddress(escrowAddress: string): Promise<string> {
1285
- if (!ethers.utils.isAddress(escrowAddress)) {
1281
+ if (!ethers.isAddress(escrowAddress)) {
1286
1282
  throw ErrorInvalidEscrowAddressProvided;
1287
1283
  }
1288
1284
 
@@ -1320,7 +1316,7 @@ export class EscrowClient extends BaseEthersClient {
1320
1316
  * ```
1321
1317
  */
1322
1318
  async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
1323
- if (!ethers.utils.isAddress(escrowAddress)) {
1319
+ if (!ethers.isAddress(escrowAddress)) {
1324
1320
  throw ErrorInvalidEscrowAddressProvided;
1325
1321
  }
1326
1322
 
@@ -1358,7 +1354,7 @@ export class EscrowClient extends BaseEthersClient {
1358
1354
  * ```
1359
1355
  */
1360
1356
  async getFactoryAddress(escrowAddress: string): Promise<string> {
1361
- if (!ethers.utils.isAddress(escrowAddress)) {
1357
+ if (!ethers.isAddress(escrowAddress)) {
1362
1358
  throw ErrorInvalidEscrowAddressProvided;
1363
1359
  }
1364
1360
 
@@ -1511,28 +1507,19 @@ export class EscrowUtils {
1511
1507
  if (!filter?.networks?.length) {
1512
1508
  throw ErrorUnsupportedChainID;
1513
1509
  }
1514
- if (filter.launcher && !ethers.utils.isAddress(filter.launcher)) {
1510
+ if (filter.launcher && !ethers.isAddress(filter.launcher)) {
1515
1511
  throw ErrorInvalidAddress;
1516
1512
  }
1517
1513
 
1518
- if (
1519
- filter.recordingOracle &&
1520
- !ethers.utils.isAddress(filter.recordingOracle)
1521
- ) {
1514
+ if (filter.recordingOracle && !ethers.isAddress(filter.recordingOracle)) {
1522
1515
  throw ErrorInvalidAddress;
1523
1516
  }
1524
1517
 
1525
- if (
1526
- filter.reputationOracle &&
1527
- !ethers.utils.isAddress(filter.reputationOracle)
1528
- ) {
1518
+ if (filter.reputationOracle && !ethers.isAddress(filter.reputationOracle)) {
1529
1519
  throw ErrorInvalidAddress;
1530
1520
  }
1531
1521
 
1532
- if (
1533
- filter.exchangeOracle &&
1534
- !ethers.utils.isAddress(filter.exchangeOracle)
1535
- ) {
1522
+ if (filter.exchangeOracle && !ethers.isAddress(filter.exchangeOracle)) {
1536
1523
  throw ErrorInvalidAddress;
1537
1524
  }
1538
1525
 
@@ -1652,7 +1639,7 @@ export class EscrowUtils {
1652
1639
  throw ErrorUnsupportedChainID;
1653
1640
  }
1654
1641
 
1655
- if (escrowAddress && !ethers.utils.isAddress(escrowAddress)) {
1642
+ if (escrowAddress && !ethers.isAddress(escrowAddress)) {
1656
1643
  throw ErrorInvalidAddress;
1657
1644
  }
1658
1645
 
@@ -47,6 +47,30 @@ export const GET_LEADERS_QUERY = (filter: ILeadersFilter) => {
47
47
  `;
48
48
  };
49
49
 
50
+ export const GET_REPUTATION_NETWORK_QUERY = (role?: string) => {
51
+ const WHERE_CLAUSE = `
52
+ where: {
53
+ ${role ? `role: $role` : ''}
54
+ }
55
+ `;
56
+
57
+ return gql`
58
+ query getReputationNetwork(
59
+ $address: String,
60
+ $role: String
61
+ ) {
62
+ reputationNetwork(id: $address) {
63
+ operators(
64
+ ${WHERE_CLAUSE}
65
+ ) {
66
+ address,
67
+ role
68
+ }
69
+ }
70
+ }
71
+ `;
72
+ };
73
+
50
74
  export const GET_LEADER_QUERY = gql`
51
75
  query getLeader($address: String!) {
52
76
  leader(id: $address) {
@@ -1,5 +1,3 @@
1
- import { BigNumber } from 'ethers';
2
-
3
1
  export type EscrowData = {
4
2
  id: string;
5
3
  address: string;
@@ -108,9 +106,9 @@ export type WorkerStatistics = {
108
106
 
109
107
  export type DailyPaymentData = {
110
108
  timestamp: Date;
111
- totalAmountPaid: BigNumber;
109
+ totalAmountPaid: bigint;
112
110
  totalCount: number;
113
- averageAmountPerWorker: BigNumber;
111
+ averageAmountPerWorker: bigint;
114
112
  };
115
113
 
116
114
  export type PaymentStatistics = {
@@ -124,17 +122,17 @@ export type HMTHolderData = {
124
122
 
125
123
  export type HMTHolder = {
126
124
  address: string;
127
- balance: BigNumber;
125
+ balance: bigint;
128
126
  };
129
127
 
130
128
  export type DailyHMTData = {
131
129
  timestamp: Date;
132
- totalTransactionAmount: BigNumber;
130
+ totalTransactionAmount: bigint;
133
131
  totalTransactionCount: number;
134
132
  };
135
133
 
136
134
  export type HMTStatistics = {
137
- totalTransferAmount: BigNumber;
135
+ totalTransferAmount: bigint;
138
136
  totalTransferCount: number;
139
137
  totalHolders: number;
140
138
  holders: HMTHolder[];
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import { KVStoreClient } from './kvstore';
4
4
  import { EscrowClient, EscrowUtils } from './escrow';
5
5
  import { StatisticsClient } from './statistics';
6
6
  import { Encryption, EncryptionUtils } from './encryption';
7
+ import { OperatorUtils } from './operator';
7
8
 
8
9
  export * from './constants';
9
10
  export * from './types';
@@ -19,4 +20,5 @@ export {
19
20
  StatisticsClient,
20
21
  Encryption,
21
22
  EncryptionUtils,
23
+ OperatorUtils,
22
24
  };