@human-protocol/sdk 1.1.5 → 1.1.7

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 (48) hide show
  1. package/README.md +80 -1
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +24 -5
  5. package/dist/encryption.d.ts +84 -0
  6. package/dist/encryption.d.ts.map +1 -0
  7. package/dist/encryption.js +202 -0
  8. package/dist/error.d.ts +2 -2
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +3 -3
  11. package/dist/escrow.d.ts +48 -15
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +118 -37
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +10 -14
  17. package/dist/interfaces.d.ts +11 -12
  18. package/dist/interfaces.d.ts.map +1 -1
  19. package/dist/kvstore.d.ts +19 -8
  20. package/dist/kvstore.d.ts.map +1 -1
  21. package/dist/kvstore.js +38 -9
  22. package/dist/queries.d.ts +3 -2
  23. package/dist/queries.d.ts.map +1 -1
  24. package/dist/queries.js +4 -7
  25. package/dist/staking.d.ts +17 -8
  26. package/dist/staking.d.ts.map +1 -1
  27. package/dist/staking.js +44 -14
  28. package/dist/storage.d.ts +2 -1
  29. package/dist/storage.d.ts.map +1 -1
  30. package/dist/storage.js +9 -3
  31. package/dist/types.d.ts +8 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/package.json +2 -1
  34. package/src/constants.ts +24 -5
  35. package/src/encryption.ts +223 -0
  36. package/src/error.ts +2 -4
  37. package/src/escrow.ts +166 -70
  38. package/src/index.ts +6 -12
  39. package/src/interfaces.ts +11 -13
  40. package/src/kvstore.ts +51 -14
  41. package/src/queries.ts +15 -7
  42. package/src/staking.ts +64 -26
  43. package/src/storage.ts +14 -3
  44. package/src/types.ts +8 -0
  45. package/dist/init.d.ts +0 -13
  46. package/dist/init.d.ts.map +0 -1
  47. package/dist/init.js +0 -35
  48. package/src/init.ts +0 -45
package/src/escrow.ts CHANGED
@@ -1,20 +1,26 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Provider } from '@ethersproject/abstract-provider';
3
+ import { Network } from '@ethersproject/networks';
2
4
  import {
3
- HMToken__factory,
4
- HMToken,
5
5
  Escrow,
6
6
  EscrowFactory,
7
7
  EscrowFactory__factory,
8
8
  Escrow__factory,
9
+ HMToken,
10
+ HMToken__factory,
9
11
  } from '@human-protocol/core/typechain-types';
10
12
  import { BigNumber, ContractReceipt, Signer, ethers } from 'ethers';
11
- import { Provider } from '@ethersproject/abstract-provider';
13
+ import { DEFAULT_TX_ID, NETWORKS } from './constants';
14
+ import { requiresSigner } from './decorators';
15
+ import { ChainId } from './enums';
12
16
  import {
13
17
  ErrorAmountMustBeGreaterThanZero,
14
18
  ErrorAmountsCannotBeEmptyArray,
15
19
  ErrorEscrowAddressIsNotProvidedByFactory,
16
20
  ErrorEscrowDoesNotHaveEnoughBalance,
17
21
  ErrorHashIsEmptyString,
22
+ ErrorProviderDoesNotExist,
23
+ ErrorUnsupportedChainID,
18
24
  ErrorInvalidAddress,
19
25
  ErrorInvalidEscrowAddressProvided,
20
26
  ErrorInvalidRecordingOracleAddressProvided,
@@ -29,40 +35,63 @@ import {
29
35
  ErrorUrlIsEmptyString,
30
36
  InvalidEthereumAddressError,
31
37
  } from './error';
32
- import {
33
- IClientParams,
34
- IEscrowConfig,
35
- IEscrowsFilter,
36
- ILauncherEscrowsResult,
37
- } from './interfaces';
38
- import { gqlFetch, isValidUrl, throwError } from './utils';
39
- import { DEFAULT_TX_ID } from './constants';
38
+ import { IEscrowConfig, IEscrowsFilter } from './interfaces';
40
39
  import {
41
40
  RAW_LAUNCHED_ESCROWS_FILTERED_QUERY,
42
41
  RAW_LAUNCHED_ESCROWS_QUERY,
43
42
  } from './queries';
44
43
  import { EscrowStatus, NetworkData } from './types';
45
- import { requiresSigner } from './decorators';
44
+ import { gqlFetch, isValidUrl, throwError } from './utils';
46
45
 
47
- export default class EscrowClient {
46
+ export class EscrowClient {
48
47
  private escrowFactoryContract: EscrowFactory;
49
48
  private escrowContract?: Escrow;
50
49
  private signerOrProvider: Signer | Provider;
51
50
  public network: NetworkData;
52
51
 
53
52
  /**
54
- * **Escrow constructor**
53
+ * **EscrowClient constructor**
55
54
  *
56
- * * @param {IClientParams} clientParams - Init client parameters
55
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
56
+ * @param {NetworkData} network - The network information required to connect to the Escrow contract
57
57
  */
58
- constructor(readonly clientParams: IClientParams) {
59
- this.network = clientParams.network;
60
-
58
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData) {
61
59
  this.escrowFactoryContract = EscrowFactory__factory.connect(
62
- clientParams.network.factoryAddress,
63
- clientParams.signerOrProvider
60
+ network.factoryAddress,
61
+ signerOrProvider
64
62
  );
65
- this.signerOrProvider = clientParams.signerOrProvider;
63
+ this.network = network;
64
+ this.signerOrProvider = signerOrProvider;
65
+ }
66
+
67
+ /**
68
+ * Creates an instance of EscrowClient from a Signer or Provider.
69
+ *
70
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
71
+ * @returns {Promise<EscrowClient>} - An instance of EscrowClient
72
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
73
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
74
+ */
75
+ public static async build(signerOrProvider: Signer | Provider) {
76
+ let network: Network;
77
+ if (Signer.isSigner(signerOrProvider)) {
78
+ if (!signerOrProvider.provider) {
79
+ throw ErrorProviderDoesNotExist;
80
+ }
81
+
82
+ network = await signerOrProvider.provider.getNetwork();
83
+ } else {
84
+ network = await signerOrProvider.getNetwork();
85
+ }
86
+
87
+ const chainId: ChainId = network.chainId;
88
+ const networkData = NETWORKS[chainId];
89
+
90
+ if (!networkData) {
91
+ throw ErrorUnsupportedChainID;
92
+ }
93
+
94
+ return new EscrowClient(signerOrProvider, networkData);
66
95
  }
67
96
 
68
97
  /**
@@ -129,7 +158,7 @@ export default class EscrowClient {
129
158
  recordingOracleFee,
130
159
  reputationOracleFee,
131
160
  manifestUrl,
132
- hash,
161
+ manifestHash,
133
162
  } = escrowConfig;
134
163
 
135
164
  if (!ethers.utils.isAddress(recordingOracle)) {
@@ -160,7 +189,7 @@ export default class EscrowClient {
160
189
  throw ErrorInvalidUrl;
161
190
  }
162
191
 
163
- if (!hash) {
192
+ if (!manifestHash) {
164
193
  throw ErrorHashIsEmptyString;
165
194
  }
166
195
 
@@ -174,16 +203,16 @@ export default class EscrowClient {
174
203
  this.signerOrProvider
175
204
  );
176
205
  await this.escrowContract.setup(
177
- recordingOracle,
178
206
  reputationOracle,
179
- recordingOracleFee,
207
+ recordingOracle,
180
208
  reputationOracleFee,
209
+ recordingOracleFee,
181
210
  manifestUrl,
182
- hash
211
+ manifestHash
183
212
  );
184
213
 
185
214
  return;
186
- } catch (e: any) {
215
+ } catch (e) {
187
216
  return throwError(e);
188
217
  }
189
218
  }
@@ -213,7 +242,7 @@ export default class EscrowClient {
213
242
  await this.setup(escrowAddress, escrowConfig);
214
243
 
215
244
  return escrowAddress;
216
- } catch (e: any) {
245
+ } catch (e) {
217
246
  return throwError(e);
218
247
  }
219
248
  }
@@ -256,7 +285,7 @@ export default class EscrowClient {
256
285
  await tokenContract.transfer(escrowAddress, amount);
257
286
 
258
287
  return;
259
- } catch (e: any) {
288
+ } catch (e) {
260
289
  return throwError(e);
261
290
  }
262
291
  }
@@ -305,7 +334,7 @@ export default class EscrowClient {
305
334
  await this.escrowContract.storeResults(url, hash);
306
335
 
307
336
  return;
308
- } catch (e: any) {
337
+ } catch (e) {
309
338
  return throwError(e);
310
339
  }
311
340
  }
@@ -334,7 +363,7 @@ export default class EscrowClient {
334
363
  );
335
364
  await this.escrowContract.complete();
336
365
  return;
337
- } catch (e: any) {
366
+ } catch (e) {
338
367
  return throwError(e);
339
368
  }
340
369
  }
@@ -421,7 +450,7 @@ export default class EscrowClient {
421
450
  DEFAULT_TX_ID
422
451
  );
423
452
  return;
424
- } catch (e: any) {
453
+ } catch (e) {
425
454
  return throwError(e);
426
455
  }
427
456
  }
@@ -450,7 +479,7 @@ export default class EscrowClient {
450
479
  );
451
480
  await this.escrowContract.cancel();
452
481
  return;
453
- } catch (e: any) {
482
+ } catch (e) {
454
483
  return throwError(e);
455
484
  }
456
485
  }
@@ -479,7 +508,7 @@ export default class EscrowClient {
479
508
  );
480
509
  await this.escrowContract.abort();
481
510
  return;
482
- } catch (e: any) {
511
+ } catch (e) {
483
512
  return throwError(e);
484
513
  }
485
514
  }
@@ -522,7 +551,7 @@ export default class EscrowClient {
522
551
  );
523
552
  await this.escrowContract.addTrustedHandlers(trustedHandlers);
524
553
  return;
525
- } catch (e: any) {
554
+ } catch (e) {
526
555
  return throwError(e);
527
556
  }
528
557
  }
@@ -549,7 +578,7 @@ export default class EscrowClient {
549
578
  this.signerOrProvider
550
579
  );
551
580
  return this.escrowContract.getBalance();
552
- } catch (e: any) {
581
+ } catch (e) {
553
582
  return throwError(e);
554
583
  }
555
584
  }
@@ -576,7 +605,7 @@ export default class EscrowClient {
576
605
  this.signerOrProvider
577
606
  );
578
607
  return this.escrowContract.manifestUrl();
579
- } catch (e: any) {
608
+ } catch (e) {
580
609
  return throwError(e);
581
610
  }
582
611
  }
@@ -603,6 +632,33 @@ export default class EscrowClient {
603
632
  this.signerOrProvider
604
633
  );
605
634
  return this.escrowContract.finalResultsUrl();
635
+ } catch (e) {
636
+ return throwError(e);
637
+ }
638
+ }
639
+
640
+ /**
641
+ * Returns the intermediate results file URL.
642
+ *
643
+ * @param {string} escrowAddress - Address of the escrow.
644
+ * @returns {Promise<void>}
645
+ * @throws {Error} - An error object if an error occurred.
646
+ */
647
+ async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
648
+ if (!ethers.utils.isAddress(escrowAddress)) {
649
+ throw ErrorInvalidEscrowAddressProvided;
650
+ }
651
+
652
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
653
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
654
+ }
655
+
656
+ try {
657
+ this.escrowContract = Escrow__factory.connect(
658
+ escrowAddress,
659
+ this.signerOrProvider
660
+ );
661
+ return this.escrowContract.intermediateResultsUrl();
606
662
  } catch (e: any) {
607
663
  return throwError(e);
608
664
  }
@@ -630,7 +686,7 @@ export default class EscrowClient {
630
686
  this.signerOrProvider
631
687
  );
632
688
  return this.escrowContract.token();
633
- } catch (e: any) {
689
+ } catch (e) {
634
690
  return throwError(e);
635
691
  }
636
692
  }
@@ -657,21 +713,19 @@ export default class EscrowClient {
657
713
  this.signerOrProvider
658
714
  );
659
715
  return this.escrowContract.status();
660
- } catch (e: any) {
716
+ } catch (e) {
661
717
  return throwError(e);
662
718
  }
663
719
  }
664
720
 
665
721
  /**
666
- * Returns the current status of the escrow.
722
+ * Returns the escrow addresses created by a job requester.
667
723
  *
668
724
  * @param {IEscrowsFilter} requesterAddress - Address of the requester.
669
- * @returns {Promise<void>}
725
+ * @returns {Promise<string[]>}
670
726
  * @throws {Error} - An error object if an error occurred.
671
727
  */
672
- async getLaunchedEscrows(
673
- requesterAddress: string
674
- ): Promise<ILauncherEscrowsResult[]> {
728
+ async getLaunchedEscrows(requesterAddress: string): Promise<string[]> {
675
729
  if (!ethers.utils.isAddress(requesterAddress)) {
676
730
  throw ErrorInvalidAddress;
677
731
  }
@@ -679,51 +733,39 @@ export default class EscrowClient {
679
733
  try {
680
734
  const { data } = await gqlFetch(
681
735
  this.network.subgraphUrl,
682
- RAW_LAUNCHED_ESCROWS_QUERY(),
683
- {
684
- address: requesterAddress,
685
- }
736
+ RAW_LAUNCHED_ESCROWS_QUERY(requesterAddress)
686
737
  );
687
738
 
688
- return data;
739
+ return data.data.launchedEscrows.map((escrow: any) => escrow.id);
689
740
  } catch (e: any) {
690
741
  return throwError(e);
691
742
  }
692
743
  }
693
744
 
694
745
  /**
695
- * Returns the escrows addresses created by a job requester.
746
+ * Returns the escrow addresses based on a specified filter.
696
747
  *
697
- * @param {string} escrowAddress - Address of the escrow.
698
- * @param {IEscrowsFilter} filer - Filter parameters.
699
- * @returns {Promise<void>}
748
+ * @param {IEscrowsFilter} filter - Filter parameters.
749
+ * @returns {Promise<string[]>}
700
750
  * @throws {Error} - An error object if an error occurred.
701
751
  */
702
- async getEscrowsFiltered(
703
- escrowAddress: string,
704
- filter: IEscrowsFilter
705
- ): Promise<ILauncherEscrowsResult[]> {
706
- if (!ethers.utils.isAddress(escrowAddress)) {
752
+ async getEscrowsFiltered(filter: IEscrowsFilter): Promise<string[]> {
753
+ if (filter?.address && !ethers.utils.isAddress(filter?.address)) {
707
754
  throw ErrorInvalidAddress;
708
755
  }
709
756
 
710
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
711
- throw ErrorEscrowAddressIsNotProvidedByFactory;
712
- }
713
-
714
757
  try {
715
758
  const { data } = await gqlFetch(
716
759
  this.network.subgraphUrl,
717
- RAW_LAUNCHED_ESCROWS_FILTERED_QUERY(),
718
- {
719
- address: filter.address,
720
- status: filter.status,
721
- from: filter.from,
722
- tro: filter.to,
723
- }
760
+ RAW_LAUNCHED_ESCROWS_FILTERED_QUERY(
761
+ filter.address,
762
+ filter.status,
763
+ filter.from,
764
+ filter.to
765
+ )
724
766
  );
725
767
 
726
- return data;
768
+ return data.data.launchedEscrows.map((escrow: any) => escrow.id);
727
769
  } catch (e: any) {
728
770
  return throwError(e);
729
771
  }
@@ -756,6 +798,33 @@ export default class EscrowClient {
756
798
  }
757
799
  }
758
800
 
801
+ /**
802
+ * Returns the job launcher address of given escrow
803
+ *
804
+ * @param {string} escrowAddress - Address of the escrow.
805
+ * @returns {Promise<string>} - Address of the job launcher.
806
+ * @throws {Error} - An error object if an error occurred.
807
+ */
808
+ async getJobLauncherAddress(escrowAddress: string): Promise<string> {
809
+ if (!ethers.utils.isAddress(escrowAddress)) {
810
+ throw ErrorInvalidEscrowAddressProvided;
811
+ }
812
+
813
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
814
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
815
+ }
816
+
817
+ try {
818
+ this.escrowContract = Escrow__factory.connect(
819
+ escrowAddress,
820
+ this.signerOrProvider
821
+ );
822
+ return this.escrowContract.launcher();
823
+ } catch (e: any) {
824
+ return throwError(e);
825
+ }
826
+ }
827
+
759
828
  /**
760
829
  * Returns the reputation oracle address of given escrow
761
830
  *
@@ -782,4 +851,31 @@ export default class EscrowClient {
782
851
  return throwError(e);
783
852
  }
784
853
  }
854
+
855
+ /**
856
+ * Returns the escrow factory address of given escrow
857
+ *
858
+ * @param {string} escrowAddress - Address of the escrow.
859
+ * @returns {Promise<string>} - Address of the escrow factory.
860
+ * @throws {Error} - An error object if an error occurred.
861
+ */
862
+ async getFactoryAddress(escrowAddress: string): Promise<string> {
863
+ if (!ethers.utils.isAddress(escrowAddress)) {
864
+ throw ErrorInvalidEscrowAddressProvided;
865
+ }
866
+
867
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
868
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
869
+ }
870
+
871
+ try {
872
+ this.escrowContract = Escrow__factory.connect(
873
+ escrowAddress,
874
+ this.signerOrProvider
875
+ );
876
+ return this.escrowContract.escrowFactory();
877
+ } catch (e: any) {
878
+ return throwError(e);
879
+ }
880
+ }
785
881
  }
package/src/index.ts CHANGED
@@ -1,17 +1,11 @@
1
- import InitClient from './init';
2
- import StakingClient from './staking';
3
- import StorageClient from './storage';
4
- import KVStoreClient from './kvstore';
5
- import EscrowClient from './escrow';
1
+ import { StakingClient } from './staking';
2
+ import { StorageClient } from './storage';
3
+ import { KVStoreClient } from './kvstore';
4
+ import { EscrowClient } from './escrow';
6
5
 
7
6
  export * from './constants';
8
7
  export * from './types';
9
8
  export * from './enums';
9
+ export * from './interfaces';
10
10
 
11
- export {
12
- InitClient,
13
- StakingClient,
14
- StorageClient,
15
- KVStoreClient,
16
- EscrowClient,
17
- };
11
+ export { StakingClient, StorageClient, KVStoreClient, EscrowClient };
package/src/interfaces.ts CHANGED
@@ -1,11 +1,5 @@
1
- import { BigNumber, Signer } from 'ethers';
2
- import { Provider } from '@ethersproject/abstract-provider';
3
- import { NetworkData } from './types';
4
-
5
- export interface IClientParams {
6
- signerOrProvider: Signer | Provider;
7
- network: NetworkData;
8
- }
1
+ import { BigNumber } from 'ethers';
2
+ import { EscrowStatus } from './types';
9
3
 
10
4
  export interface IAllocation {
11
5
  escrowAddress: string;
@@ -21,6 +15,7 @@ export interface IReward {
21
15
  }
22
16
 
23
17
  export interface IStaker {
18
+ staker: string;
24
19
  tokensStaked: BigNumber;
25
20
  tokensAllocated: BigNumber;
26
21
  tokensLocked: BigNumber;
@@ -29,9 +24,9 @@ export interface IStaker {
29
24
  }
30
25
 
31
26
  export interface IEscrowsFilter {
32
- address: string;
27
+ address?: string;
33
28
  role?: number;
34
- status?: number;
29
+ status?: EscrowStatus;
35
30
  from?: Date;
36
31
  to?: Date;
37
32
  }
@@ -42,9 +37,12 @@ export interface IEscrowConfig {
42
37
  recordingOracleFee: BigNumber;
43
38
  reputationOracleFee: BigNumber;
44
39
  manifestUrl: string;
45
- hash: string;
40
+ manifestHash: string;
46
41
  }
47
42
 
48
- export interface ILauncherEscrowsResult {
49
- id: string;
43
+ export interface IKeyPair {
44
+ privateKey: string;
45
+ publicKey: string;
46
+ passphrase: string;
47
+ revocationCertificate?: string;
50
48
  }
package/src/kvstore.ts CHANGED
@@ -1,33 +1,69 @@
1
+ import { Provider } from '@ethersproject/abstract-provider';
2
+ import { Network } from '@ethersproject/networks';
1
3
  import {
2
4
  KVStore,
3
5
  KVStore__factory,
4
6
  } from '@human-protocol/core/typechain-types';
5
7
  import { Signer, ethers } from 'ethers';
6
- import { Provider } from '@ethersproject/abstract-provider';
8
+ import { NETWORKS } from './constants';
9
+ import { requiresSigner } from './decorators';
10
+ import { ChainId } from './enums';
7
11
  import {
8
12
  ErrorInvalidAddress,
9
13
  ErrorKVStoreArrayLength,
10
14
  ErrorKVStoreEmptyKey,
15
+ ErrorProviderDoesNotExist,
11
16
  ErrorSigner,
17
+ ErrorUnsupportedChainID,
12
18
  } from './error';
13
- import { IClientParams } from './interfaces';
14
- import { requiresSigner } from './decorators';
19
+ import { NetworkData } from './types';
15
20
 
16
- export default class KVStoreClient {
21
+ export class KVStoreClient {
17
22
  private contract: KVStore;
18
23
  private signerOrProvider: Signer | Provider;
19
24
 
20
25
  /**
21
- * **KVStore constructor**
26
+ * **KVStoreClient constructor**
22
27
  *
23
- * * @param {IClientParams} clientParams - Init client parameters
28
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
29
+ * @param {NetworkData} network - The network information required to connect to the KVStore contract
24
30
  */
25
- constructor(readonly clientParams: IClientParams) {
31
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData) {
26
32
  this.contract = KVStore__factory.connect(
27
- clientParams.network.kvstoreAddress,
28
- clientParams.signerOrProvider
33
+ network.factoryAddress,
34
+ signerOrProvider
29
35
  );
30
- this.signerOrProvider = clientParams.signerOrProvider;
36
+ this.signerOrProvider = signerOrProvider;
37
+ }
38
+
39
+ /**
40
+ * Creates an instance of KVStoreClient from a Signer or Provider.
41
+ *
42
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
43
+ * @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
44
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
45
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
46
+ */
47
+ public static async build(signerOrProvider: Signer | Provider) {
48
+ let network: Network;
49
+ if (Signer.isSigner(signerOrProvider)) {
50
+ if (!signerOrProvider.provider) {
51
+ throw ErrorProviderDoesNotExist;
52
+ }
53
+
54
+ network = await signerOrProvider.provider.getNetwork();
55
+ } else {
56
+ network = await signerOrProvider.getNetwork();
57
+ }
58
+
59
+ const chainId: ChainId = network.chainId;
60
+ const networkData = NETWORKS[chainId];
61
+
62
+ if (!networkData) {
63
+ throw ErrorUnsupportedChainID;
64
+ }
65
+
66
+ return new KVStoreClient(signerOrProvider, networkData);
31
67
  }
32
68
 
33
69
  /**
@@ -39,7 +75,7 @@ export default class KVStoreClient {
39
75
  * @throws {Error} - An error object if an error occurred
40
76
  */
41
77
  @requiresSigner
42
- public async set(key: string, value: string) {
78
+ public async set(key: string, value: string): Promise<void> {
43
79
  if (!Signer.isSigner(this.signerOrProvider)) throw ErrorSigner;
44
80
  if (key === '') throw ErrorKVStoreEmptyKey;
45
81
  try {
@@ -58,7 +94,7 @@ export default class KVStoreClient {
58
94
  * @throws {Error} - An error object if an error occurred
59
95
  */
60
96
  @requiresSigner
61
- public async setBulk(keys: string[], values: string[]) {
97
+ public async setBulk(keys: string[], values: string[]): Promise<void> {
62
98
  if (!Signer.isSigner(this.signerOrProvider)) throw ErrorSigner;
63
99
  if (keys.length !== values.length) throw ErrorKVStoreArrayLength;
64
100
  if (keys.includes('')) throw ErrorKVStoreEmptyKey;
@@ -76,10 +112,10 @@ export default class KVStoreClient {
76
112
  *
77
113
  * @param {string} address - The Ethereum address associated with the key-value pair
78
114
  * @param {string} key - The key of the key-value pair to get
79
- * @returns {string} - The value of the key-value pair if it exists
115
+ * @returns {Promise<string>} - The value of the key-value pair if it exists
80
116
  * @throws {Error} - An error object if an error occurred
81
117
  */
82
- public async get(address: string, key: string) {
118
+ public async get(address: string, key: string): Promise<string> {
83
119
  if (key === '') throw ErrorKVStoreEmptyKey;
84
120
  if (!ethers.utils.isAddress(address)) throw ErrorInvalidAddress;
85
121
 
@@ -88,6 +124,7 @@ export default class KVStoreClient {
88
124
  return result;
89
125
  } catch (e) {
90
126
  if (e instanceof Error) throw Error(`Failed to get value: ${e.message}`);
127
+ return e;
91
128
  }
92
129
  }
93
130
  }
package/src/queries.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { EscrowStatus } from './types';
2
+
1
3
  export const RAW_REWARDS_QUERY = (slasherAddress: string) => `{
2
4
  rewardAddedEvents(id: "${slasherAddress}") {
3
5
  escrow,
@@ -5,14 +7,20 @@ export const RAW_REWARDS_QUERY = (slasherAddress: string) => `{
5
7
  }
6
8
  }`;
7
9
 
8
- export const RAW_LAUNCHED_ESCROWS_QUERY = () => `{
9
- launchedEscrows(where: { from: $address }) {
10
+ export const RAW_LAUNCHED_ESCROWS_QUERY = (requesterAddress: string) => `{
11
+ launchedEscrows(where: { from: ${requesterAddress} }) {
10
12
  id
11
13
  }
12
14
  }`;
13
15
 
14
- export const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = () => `{
15
- launchedEscrows(where: { from: $address, status: $status, timestamp_gte: $from, timestamp_lte: $to }) {
16
- id
17
- }
18
- }`;
16
+ export const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = (
17
+ address?: string,
18
+ status?: EscrowStatus,
19
+ from?: Date,
20
+ to?: Date
21
+ ) =>
22
+ `{ launchedEscrows(where: { ${address ? 'from: "' + address + '", ' : ''}${
23
+ status ? 'status: "' + EscrowStatus[status] + '", ' : ''
24
+ }${from ? 'timestamp_gte: "' + from?.valueOf() + '", ' : ''}${
25
+ to ? 'timestamp_lte: "' + to?.valueOf() + '"' : ''
26
+ }}) { id }}`;