@human-protocol/sdk 1.1.2 → 1.1.3

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.
package/src/escrow.ts ADDED
@@ -0,0 +1,781 @@
1
+ import {
2
+ HMToken__factory,
3
+ HMToken,
4
+ Escrow,
5
+ EscrowFactory,
6
+ EscrowFactory__factory,
7
+ Escrow__factory,
8
+ } from '@human-protocol/core/typechain-types';
9
+ import { BigNumber, ContractReceipt, Signer, ethers, providers } from 'ethers';
10
+ import { Provider } from '@ethersproject/abstract-provider';
11
+ import {
12
+ ErrorAmountMustBeGreaterThanZero,
13
+ ErrorAmountsCannotBeEmptyArray,
14
+ ErrorEscrowAddressIsNotProvidedByFactory,
15
+ ErrorEscrowDoesNotHaveEnoughBalance,
16
+ ErrorHashIsEmptyString,
17
+ ErrorInvalidAddress,
18
+ ErrorInvalidEscrowAddressProvided,
19
+ ErrorInvalidRecordingOracleAddressProvided,
20
+ ErrorInvalidReputationOracleAddressProvided,
21
+ ErrorInvalidTokenAddress,
22
+ ErrorInvalidUrl,
23
+ ErrorLaunchedEventIsNotEmitted,
24
+ ErrorListOfHandlersCannotBeEmpty,
25
+ ErrorRecipientAndAmountsMustBeSameLength,
26
+ ErrorRecipientCannotBeEmptyArray,
27
+ ErrorSigner,
28
+ ErrorTotalFeeMustBeLessThanHundred,
29
+ ErrorUrlIsEmptyString,
30
+ InvalidEthereumAddressError,
31
+ } 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';
40
+ import {
41
+ RAW_LAUNCHED_ESCROWS_FILTERED_QUERY,
42
+ RAW_LAUNCHED_ESCROWS_QUERY,
43
+ } from './queries';
44
+ import { EscrowStatus, NetworkData } from './types';
45
+ import { requiresSigner } from './decorators';
46
+
47
+ export default class EscrowClient {
48
+ private escrowFactoryContract: EscrowFactory;
49
+ private escrowContract?: Escrow;
50
+ private signerOrProvider: Signer | Provider;
51
+ public network: NetworkData;
52
+
53
+ /**
54
+ * **Escrow constructor**
55
+ *
56
+ * * @param {IClientParams} clientParams - Init client parameters
57
+ */
58
+ constructor(readonly clientParams: IClientParams) {
59
+ this.network = clientParams.network;
60
+
61
+ this.escrowFactoryContract = EscrowFactory__factory.connect(
62
+ clientParams.network.factoryAddress,
63
+ clientParams.signerOrProvider
64
+ );
65
+ this.signerOrProvider = clientParams.signerOrProvider;
66
+ }
67
+
68
+ /**
69
+ * Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
70
+ *
71
+ * @param {string} tokenAddress - Token address to use for pay outs.
72
+ * @param {string[]} trustedHandlers - Array of addresses that can perform actions on the contract.
73
+ * @returns {Promise<string>} - Return the address of the escrow created.
74
+ * @throws {Error} - An error object if an error occurred.
75
+ */
76
+ @requiresSigner
77
+ public async createEscrow(
78
+ tokenAddress: string,
79
+ trustedHandlers: string[]
80
+ ): Promise<string> {
81
+ if (!ethers.utils.isAddress(tokenAddress)) {
82
+ throw ErrorInvalidTokenAddress;
83
+ }
84
+
85
+ trustedHandlers.forEach((trustedHandler) => {
86
+ if (!ethers.utils.isAddress(trustedHandler)) {
87
+ throw new InvalidEthereumAddressError(trustedHandler);
88
+ }
89
+ });
90
+
91
+ try {
92
+ const result: ContractReceipt = await (
93
+ await this.escrowFactoryContract.createEscrow(
94
+ tokenAddress,
95
+ trustedHandlers
96
+ )
97
+ ).wait();
98
+
99
+ if (!result.events || !result.events[0] || !result.events[0].args) {
100
+ throw ErrorLaunchedEventIsNotEmitted;
101
+ }
102
+
103
+ return result.events[0].args[1];
104
+ } catch (e: any) {
105
+ return throwError(e);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Sets up the parameters of the escrow.
111
+ *
112
+ * @param {string} escrowAddress - Address of the escrow to set up.
113
+ * @param {IEscrowConfig} escrowConfig - Configuration object with escrow settings.
114
+ * @returns {Promise<void>}
115
+ * @throws {Error} - An error object if an error occurred.
116
+ */
117
+ @requiresSigner
118
+ async setup(
119
+ escrowAddress: string,
120
+ escrowConfig: IEscrowConfig
121
+ ): Promise<void> {
122
+ const {
123
+ recordingOracle,
124
+ reputationOracle,
125
+ recordingOracleFee,
126
+ reputationOracleFee,
127
+ manifestUrl,
128
+ hash,
129
+ } = escrowConfig;
130
+
131
+ if (!ethers.utils.isAddress(recordingOracle)) {
132
+ throw ErrorInvalidRecordingOracleAddressProvided;
133
+ }
134
+
135
+ if (!ethers.utils.isAddress(reputationOracle)) {
136
+ throw ErrorInvalidReputationOracleAddressProvided;
137
+ }
138
+
139
+ if (!ethers.utils.isAddress(escrowAddress)) {
140
+ throw ErrorInvalidEscrowAddressProvided;
141
+ }
142
+
143
+ if (recordingOracleFee.lte(0) || reputationOracleFee.lte(0)) {
144
+ throw ErrorAmountMustBeGreaterThanZero;
145
+ }
146
+
147
+ if (recordingOracleFee.add(reputationOracleFee).gt(100)) {
148
+ throw ErrorTotalFeeMustBeLessThanHundred;
149
+ }
150
+
151
+ if (!manifestUrl) {
152
+ throw ErrorUrlIsEmptyString;
153
+ }
154
+
155
+ if (!isValidUrl(manifestUrl)) {
156
+ throw ErrorInvalidUrl;
157
+ }
158
+
159
+ if (!hash) {
160
+ throw ErrorHashIsEmptyString;
161
+ }
162
+
163
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
164
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
165
+ }
166
+
167
+ try {
168
+ this.escrowContract = Escrow__factory.connect(
169
+ escrowAddress,
170
+ this.signerOrProvider
171
+ );
172
+ await this.escrowContract.setup(
173
+ recordingOracle,
174
+ reputationOracle,
175
+ recordingOracleFee,
176
+ reputationOracleFee,
177
+ manifestUrl,
178
+ hash
179
+ );
180
+
181
+ return;
182
+ } catch (e: any) {
183
+ return throwError(e);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * **Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.*
189
+ * **Sets up the parameters of the escrow.*
190
+ *
191
+ * @param {string} tokenAddress - Token address to use for pay outs.
192
+ * @param {string[]} trustedHandlers - Array of addresses that can perform actions on the contract.
193
+ * @param {IEscrowConfig} escrowConfig - Configuration object with escrow settings.
194
+ * @returns {Promise<string>}
195
+ * @throws {Error} - An error object if an error occurred.
196
+ */
197
+ @requiresSigner
198
+ async createAndSetupEscrow(
199
+ tokenAddress: string,
200
+ trustedHandlers: string[],
201
+ escrowConfig: IEscrowConfig
202
+ ): Promise<string> {
203
+ try {
204
+ const escrowAddress = await this.createEscrow(
205
+ tokenAddress,
206
+ trustedHandlers
207
+ );
208
+
209
+ await this.setup(escrowAddress, escrowConfig);
210
+
211
+ return escrowAddress;
212
+ } catch (e: any) {
213
+ return throwError(e);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * **Adds funds of the chosen token to the escrow.*
219
+ *
220
+ * @param {string} escrowAddress - Address of the escrow to fund.
221
+ * @param {BigNumber} amount - Amount to be added as funds.
222
+ * @returns {Promise<void>}
223
+ * @throws {Error} - An error object if an error occurred.
224
+ */
225
+ @requiresSigner
226
+ async fund(escrowAddress: string, amount: BigNumber): Promise<void> {
227
+ if (!ethers.utils.isAddress(escrowAddress)) {
228
+ throw ErrorInvalidEscrowAddressProvided;
229
+ }
230
+
231
+ if (amount.lte(0)) {
232
+ throw ErrorAmountMustBeGreaterThanZero;
233
+ }
234
+
235
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
236
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
237
+ }
238
+
239
+ try {
240
+ this.escrowContract = Escrow__factory.connect(
241
+ escrowAddress,
242
+ this.signerOrProvider
243
+ );
244
+
245
+ const tokenAddress = await this.escrowContract.token();
246
+
247
+ const tokenContract: HMToken = HMToken__factory.connect(
248
+ tokenAddress,
249
+ this.signerOrProvider
250
+ );
251
+
252
+ await tokenContract.transfer(escrowAddress, amount);
253
+
254
+ return;
255
+ } catch (e: any) {
256
+ return throwError(e);
257
+ }
258
+ }
259
+
260
+ /**
261
+ * **Stores the results.*
262
+ *
263
+ * @param {string} escrowAddress - Address of the escrow.
264
+ * @param {string} sender - Address of the sender.
265
+ * @param {string} url - Results file url.
266
+ * @param {string} hash - Results file hash.
267
+ * @returns {Promise<void>}
268
+ * @throws {Error} - An error object if an error occurred.
269
+ */
270
+ @requiresSigner
271
+ async storeResults(
272
+ escrowAddress: string,
273
+ url: string,
274
+ hash: string
275
+ ): Promise<void> {
276
+ if (!ethers.utils.isAddress(escrowAddress)) {
277
+ throw ErrorInvalidEscrowAddressProvided;
278
+ }
279
+
280
+ if (!url) {
281
+ throw ErrorUrlIsEmptyString;
282
+ }
283
+
284
+ if (!isValidUrl(url)) {
285
+ throw ErrorInvalidUrl;
286
+ }
287
+
288
+ if (!hash) {
289
+ throw ErrorHashIsEmptyString;
290
+ }
291
+
292
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
293
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
294
+ }
295
+
296
+ try {
297
+ this.escrowContract = Escrow__factory.connect(
298
+ escrowAddress,
299
+ this.signerOrProvider
300
+ );
301
+ await this.escrowContract.storeResults(url, hash);
302
+
303
+ return;
304
+ } catch (e: any) {
305
+ return throwError(e);
306
+ }
307
+ }
308
+
309
+ /**
310
+ * **Sets the status of an escrow to completed.*
311
+ *
312
+ * @param {string} escrowAddress - Address of the escrow.
313
+ * @returns {Promise<void>}
314
+ * @throws {Error} - An error object if an error occurred.
315
+ */
316
+ @requiresSigner
317
+ async complete(escrowAddress: string): Promise<void> {
318
+ if (!ethers.utils.isAddress(escrowAddress)) {
319
+ throw ErrorInvalidEscrowAddressProvided;
320
+ }
321
+
322
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
323
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
324
+ }
325
+
326
+ try {
327
+ this.escrowContract = Escrow__factory.connect(
328
+ escrowAddress,
329
+ this.signerOrProvider
330
+ );
331
+ await this.escrowContract.complete();
332
+ return;
333
+ } catch (e: any) {
334
+ return throwError(e);
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Pays out the amounts specified to the workers and sets the URL of the final results file.
340
+ *
341
+ * @param {string} escrowAddress - Address of the escrow.
342
+ * @param {string[]} recipients - Array of recipient addresses.
343
+ * @param {BigNumber[]} amounts - Array of amounts the recipients will receive.
344
+ * @param {string} finalResultsUrl - Final results file url.
345
+ * @param {string} finalResultsHash - Final results file hash.
346
+ * @returns {Promise<void>}
347
+ * @throws {Error} - An error object if an error occurred.
348
+ */
349
+ @requiresSigner
350
+ async bulkPayOut(
351
+ escrowAddress: string,
352
+ recipients: string[],
353
+ amounts: BigNumber[],
354
+ finalResultsUrl: string,
355
+ finalResultsHash: string
356
+ ): Promise<void> {
357
+ if (!ethers.utils.isAddress(escrowAddress)) {
358
+ throw ErrorInvalidEscrowAddressProvided;
359
+ }
360
+
361
+ if (recipients.length === 0) {
362
+ throw ErrorRecipientCannotBeEmptyArray;
363
+ }
364
+
365
+ if (amounts.length === 0) {
366
+ throw ErrorAmountsCannotBeEmptyArray;
367
+ }
368
+
369
+ if (recipients.length !== amounts.length) {
370
+ throw ErrorRecipientAndAmountsMustBeSameLength;
371
+ }
372
+
373
+ recipients.forEach((recipient) => {
374
+ if (!ethers.utils.isAddress(recipient)) {
375
+ throw new InvalidEthereumAddressError(recipient);
376
+ }
377
+ });
378
+
379
+ if (!finalResultsUrl) {
380
+ throw ErrorUrlIsEmptyString;
381
+ }
382
+
383
+ if (!isValidUrl(finalResultsUrl)) {
384
+ throw ErrorInvalidUrl;
385
+ }
386
+
387
+ if (!finalResultsHash) {
388
+ throw ErrorHashIsEmptyString;
389
+ }
390
+
391
+ const balance = await this.getBalance(escrowAddress);
392
+
393
+ let totalAmount = BigNumber.from(0);
394
+ amounts.forEach((amount) => {
395
+ totalAmount = totalAmount.add(amount);
396
+ });
397
+
398
+ if (balance.lt(totalAmount)) {
399
+ throw ErrorEscrowDoesNotHaveEnoughBalance;
400
+ }
401
+
402
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
403
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
404
+ }
405
+
406
+ try {
407
+ this.escrowContract = Escrow__factory.connect(
408
+ escrowAddress,
409
+ this.signerOrProvider
410
+ );
411
+
412
+ await this.escrowContract.bulkPayOut(
413
+ recipients,
414
+ amounts,
415
+ finalResultsUrl,
416
+ finalResultsHash,
417
+ DEFAULT_TX_ID
418
+ );
419
+ return;
420
+ } catch (e: any) {
421
+ return throwError(e);
422
+ }
423
+ }
424
+
425
+ /**
426
+ * Cancels the specified escrow and sends the balance to the canceler.
427
+ *
428
+ * @param {string} escrowAddress - Address of the escrow.
429
+ * @returns {Promise<void>}
430
+ * @throws {Error} - An error object if an error occurred.
431
+ */
432
+ @requiresSigner
433
+ async cancel(escrowAddress: string): Promise<void> {
434
+ if (!ethers.utils.isAddress(escrowAddress)) {
435
+ throw ErrorInvalidEscrowAddressProvided;
436
+ }
437
+
438
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
439
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
440
+ }
441
+
442
+ try {
443
+ this.escrowContract = Escrow__factory.connect(
444
+ escrowAddress,
445
+ this.signerOrProvider
446
+ );
447
+ await this.escrowContract.cancel();
448
+ return;
449
+ } catch (e: any) {
450
+ return throwError(e);
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Cancels the specified escrow, sends the balance to the canceler and selfdestructs the escrow contract.
456
+ *
457
+ * @param {string} escrowAddress - Address of the escrow.
458
+ * @returns {Promise<void>}
459
+ * @throws {Error} - An error object if an error occurred.
460
+ */
461
+ @requiresSigner
462
+ async abort(escrowAddress: string): Promise<void> {
463
+ if (!ethers.utils.isAddress(escrowAddress)) {
464
+ throw ErrorInvalidEscrowAddressProvided;
465
+ }
466
+
467
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
468
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
469
+ }
470
+
471
+ try {
472
+ this.escrowContract = Escrow__factory.connect(
473
+ escrowAddress,
474
+ this.signerOrProvider
475
+ );
476
+ await this.escrowContract.abort();
477
+ return;
478
+ } catch (e: any) {
479
+ return throwError(e);
480
+ }
481
+ }
482
+
483
+ /**
484
+ * Adds an array of addresses to the trusted handlers list.
485
+ *
486
+ * @param {string} escrowAddress - Address of the escrow.
487
+ * @param {string[]} trustedHandlers - List of trusted handler addresses.
488
+ * @returns {Promise<void>}
489
+ * @throws {Error} - An error object if an error occurred.
490
+ */
491
+ @requiresSigner
492
+ async addTrustedHandlers(
493
+ escrowAddress: string,
494
+ trustedHandlers: string[]
495
+ ): Promise<void> {
496
+ if (!ethers.utils.isAddress(escrowAddress)) {
497
+ throw ErrorInvalidEscrowAddressProvided;
498
+ }
499
+
500
+ if (trustedHandlers.length === 0) {
501
+ throw ErrorListOfHandlersCannotBeEmpty;
502
+ }
503
+
504
+ trustedHandlers.forEach((trustedHandler) => {
505
+ if (!ethers.utils.isAddress(trustedHandler)) {
506
+ throw new InvalidEthereumAddressError(trustedHandler);
507
+ }
508
+ });
509
+
510
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
511
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
512
+ }
513
+
514
+ try {
515
+ this.escrowContract = Escrow__factory.connect(
516
+ escrowAddress,
517
+ this.signerOrProvider
518
+ );
519
+ await this.escrowContract.addTrustedHandlers(trustedHandlers);
520
+ return;
521
+ } catch (e: any) {
522
+ return throwError(e);
523
+ }
524
+ }
525
+
526
+ /**
527
+ * Returns the balance for a specified escrow address.
528
+ *
529
+ * @param {string} escrowAddress - Address of the escrow.
530
+ * @returns {Promise<BigNumber>}
531
+ * @throws {Error} - An error object if an error occurred.
532
+ */
533
+ async getBalance(escrowAddress: string): Promise<BigNumber> {
534
+ if (!ethers.utils.isAddress(escrowAddress)) {
535
+ throw ErrorInvalidEscrowAddressProvided;
536
+ }
537
+
538
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
539
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
540
+ }
541
+
542
+ try {
543
+ this.escrowContract = Escrow__factory.connect(
544
+ escrowAddress,
545
+ this.signerOrProvider
546
+ );
547
+ return this.escrowContract.getBalance();
548
+ } catch (e: any) {
549
+ return throwError(e);
550
+ }
551
+ }
552
+
553
+ /**
554
+ * Returns the manifest file URL.
555
+ *
556
+ * @param {string} escrowAddress - Address of the escrow.
557
+ * @returns {Promise<void>}
558
+ * @throws {Error} - An error object if an error occurred.
559
+ */
560
+ async getManifestUrl(escrowAddress: string): Promise<string> {
561
+ if (!ethers.utils.isAddress(escrowAddress)) {
562
+ throw ErrorInvalidEscrowAddressProvided;
563
+ }
564
+
565
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
566
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
567
+ }
568
+
569
+ try {
570
+ this.escrowContract = Escrow__factory.connect(
571
+ escrowAddress,
572
+ this.signerOrProvider
573
+ );
574
+ return this.escrowContract.manifestUrl();
575
+ } catch (e: any) {
576
+ return throwError(e);
577
+ }
578
+ }
579
+
580
+ /**
581
+ * Returns the results file URL.
582
+ *
583
+ * @param {string} escrowAddress - Address of the escrow.
584
+ * @returns {Promise<void>}
585
+ * @throws {Error} - An error object if an error occurred.
586
+ */
587
+ async getResultsUrl(escrowAddress: string): Promise<string> {
588
+ if (!ethers.utils.isAddress(escrowAddress)) {
589
+ throw ErrorInvalidEscrowAddressProvided;
590
+ }
591
+
592
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
593
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
594
+ }
595
+
596
+ try {
597
+ this.escrowContract = Escrow__factory.connect(
598
+ escrowAddress,
599
+ this.signerOrProvider
600
+ );
601
+ return this.escrowContract.finalResultsUrl();
602
+ } catch (e: any) {
603
+ return throwError(e);
604
+ }
605
+ }
606
+
607
+ /**
608
+ * Returns the value for a specified key and address
609
+ *
610
+ * @param {string} escrowAddress - Address of the escrow.
611
+ * @returns {Promise<void>}
612
+ * @throws {Error} - An error object if an error occurred.
613
+ */
614
+ async getTokenAddress(escrowAddress: string): Promise<string> {
615
+ if (!ethers.utils.isAddress(escrowAddress)) {
616
+ throw ErrorInvalidEscrowAddressProvided;
617
+ }
618
+
619
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
620
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
621
+ }
622
+
623
+ try {
624
+ this.escrowContract = Escrow__factory.connect(
625
+ escrowAddress,
626
+ this.signerOrProvider
627
+ );
628
+ return this.escrowContract.token();
629
+ } catch (e: any) {
630
+ return throwError(e);
631
+ }
632
+ }
633
+
634
+ /**
635
+ * Returns the current status of the escrow.
636
+ *
637
+ * @param {string} escrowAddress - Address of the escrow.
638
+ * @returns {Promise<void>}
639
+ * @throws {Error} - An error object if an error occurred.
640
+ */
641
+ async getStatus(escrowAddress: string): Promise<EscrowStatus> {
642
+ if (!ethers.utils.isAddress(escrowAddress)) {
643
+ throw ErrorInvalidEscrowAddressProvided;
644
+ }
645
+
646
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
647
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
648
+ }
649
+
650
+ try {
651
+ this.escrowContract = Escrow__factory.connect(
652
+ escrowAddress,
653
+ this.signerOrProvider
654
+ );
655
+ return this.escrowContract.status();
656
+ } catch (e: any) {
657
+ return throwError(e);
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Returns the current status of the escrow.
663
+ *
664
+ * @param {IEscrowsFilter} requesterAddress - Address of the requester.
665
+ * @returns {Promise<void>}
666
+ * @throws {Error} - An error object if an error occurred.
667
+ */
668
+ async getLaunchedEscrows(
669
+ requesterAddress: string
670
+ ): Promise<ILauncherEscrowsResult[]> {
671
+ if (!ethers.utils.isAddress(requesterAddress)) {
672
+ throw ErrorInvalidAddress;
673
+ }
674
+
675
+ try {
676
+ const { data } = await gqlFetch(
677
+ this.network.subgraphUrl,
678
+ RAW_LAUNCHED_ESCROWS_QUERY(),
679
+ {
680
+ address: requesterAddress,
681
+ }
682
+ );
683
+
684
+ return data;
685
+ } catch (e: any) {
686
+ return throwError(e);
687
+ }
688
+ }
689
+
690
+ /**
691
+ * Returns the escrows addresses created by a job requester.
692
+ *
693
+ * @param {string} escrowAddress - Address of the escrow.
694
+ * @param {IEscrowsFilter} filer - Filter parameters.
695
+ * @returns {Promise<void>}
696
+ * @throws {Error} - An error object if an error occurred.
697
+ */
698
+ async getEscrowsFiltered(
699
+ escrowAddress: string,
700
+ filter: IEscrowsFilter
701
+ ): Promise<ILauncherEscrowsResult[]> {
702
+ if (!ethers.utils.isAddress(escrowAddress)) {
703
+ throw ErrorInvalidAddress;
704
+ }
705
+
706
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
707
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
708
+ }
709
+
710
+ try {
711
+ const { data } = await gqlFetch(
712
+ this.network.subgraphUrl,
713
+ RAW_LAUNCHED_ESCROWS_FILTERED_QUERY(),
714
+ {
715
+ address: filter.address,
716
+ status: filter.status,
717
+ from: filter.from,
718
+ tro: filter.to,
719
+ }
720
+ );
721
+
722
+ return data;
723
+ } catch (e: any) {
724
+ return throwError(e);
725
+ }
726
+ }
727
+
728
+ /**
729
+ * Returns the recording oracle address of given escrow
730
+ *
731
+ * @param {string} escrowAddress - Address of the escrow.
732
+ * @returns {Promise<string>} - Address of the recording oracle.
733
+ * @throws {Error} - An error object if an error occurred.
734
+ */
735
+ async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
736
+ if (!ethers.utils.isAddress(escrowAddress)) {
737
+ throw ErrorInvalidEscrowAddressProvided;
738
+ }
739
+
740
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
741
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
742
+ }
743
+
744
+ try {
745
+ this.escrowContract = Escrow__factory.connect(
746
+ escrowAddress,
747
+ this.signerOrProvider
748
+ );
749
+ return this.escrowContract.recordingOracle();
750
+ } catch (e: any) {
751
+ return throwError(e);
752
+ }
753
+ }
754
+
755
+ /**
756
+ * Returns the reputation oracle address of given escrow
757
+ *
758
+ * @param {string} escrowAddress - Address of the escrow.
759
+ * @returns {Promise<string>} - Address of the reputation oracle.
760
+ * @throws {Error} - An error object if an error occurred.
761
+ */
762
+ async getReputationOracleAddress(escrowAddress: string): Promise<string> {
763
+ if (!ethers.utils.isAddress(escrowAddress)) {
764
+ throw ErrorInvalidEscrowAddressProvided;
765
+ }
766
+
767
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
768
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
769
+ }
770
+
771
+ try {
772
+ this.escrowContract = Escrow__factory.connect(
773
+ escrowAddress,
774
+ this.signerOrProvider
775
+ );
776
+ return this.escrowContract.reputationOracle();
777
+ } catch (e: any) {
778
+ return throwError(e);
779
+ }
780
+ }
781
+ }