@human-protocol/sdk 1.1.2 → 1.1.5

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