@human-protocol/sdk 5.2.0 → 6.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 (63) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +4 -5
  4. package/dist/constants.js +6 -6
  5. package/dist/encryption.d.ts +68 -203
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +66 -202
  8. package/dist/error.d.ts +0 -24
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +2 -26
  11. package/dist/escrow.d.ts +427 -780
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +314 -684
  14. package/dist/graphql/queries/operator.d.ts.map +1 -1
  15. package/dist/graphql/queries/operator.js +3 -1
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/kvstore.d.ts +119 -181
  21. package/dist/kvstore.d.ts.map +1 -1
  22. package/dist/kvstore.js +119 -182
  23. package/dist/operator.d.ts +59 -30
  24. package/dist/operator.d.ts.map +1 -1
  25. package/dist/operator.js +59 -30
  26. package/dist/staking.d.ts +135 -134
  27. package/dist/staking.d.ts.map +1 -1
  28. package/dist/staking.js +135 -134
  29. package/dist/statistics.d.ts +104 -134
  30. package/dist/statistics.d.ts.map +1 -1
  31. package/dist/statistics.js +119 -144
  32. package/dist/transaction.d.ts +36 -15
  33. package/dist/transaction.d.ts.map +1 -1
  34. package/dist/transaction.js +36 -15
  35. package/dist/types.d.ts +0 -54
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +31 -17
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +31 -17
  40. package/dist/worker.d.ts +35 -14
  41. package/dist/worker.d.ts.map +1 -1
  42. package/dist/worker.js +35 -14
  43. package/package.json +7 -24
  44. package/src/base.ts +4 -5
  45. package/src/constants.ts +6 -6
  46. package/src/encryption.ts +69 -203
  47. package/src/error.ts +0 -36
  48. package/src/escrow.ts +425 -780
  49. package/src/graphql/queries/operator.ts +3 -1
  50. package/src/graphql/types.ts +4 -2
  51. package/src/index.ts +4 -5
  52. package/src/kvstore.ts +120 -183
  53. package/src/operator.ts +59 -30
  54. package/src/staking.ts +135 -134
  55. package/src/statistics.ts +125 -146
  56. package/src/transaction.ts +36 -15
  57. package/src/types.ts +0 -57
  58. package/src/utils.ts +31 -17
  59. package/src/worker.ts +35 -14
  60. package/dist/storage.d.ts +0 -186
  61. package/dist/storage.d.ts.map +0 -1
  62. package/dist/storage.js +0 -319
  63. package/src/storage.ts +0 -313
package/src/escrow.ts CHANGED
@@ -77,82 +77,64 @@ import {
77
77
  } from './utils';
78
78
 
79
79
  /**
80
- * ## Introduction
81
- *
82
- * This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
80
+ * Client to perform actions on Escrow contracts and obtain information from the contracts.
83
81
  *
84
82
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
85
- * To use this client, it is recommended to initialize it using the static `build` method.
86
- *
87
- * ```ts
88
- * static async build(runner: ContractRunner): Promise<EscrowClient>;
89
- * ```
83
+ * To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/EscrowClient/#build) method.
90
84
  *
91
85
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
92
86
  *
93
87
  * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
94
88
  * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
95
89
  *
96
- * ## Installation
97
- *
98
- * ### npm
99
- * ```bash
100
- * npm install @human-protocol/sdk
101
- * ```
102
- *
103
- * ### yarn
104
- * ```bash
105
- * yarn install @human-protocol/sdk
106
- * ```
107
- *
108
- * ## Code example
90
+ * @example
109
91
  *
110
- * ### Signer
92
+ * ###Using Signer
111
93
  *
112
- * **Using private key (backend)**
94
+ * ####Using private key (backend)
113
95
  *
114
96
  * ```ts
115
97
  * import { EscrowClient } from '@human-protocol/sdk';
116
- * import { Wallet, providers } from 'ethers';
98
+ * import { Wallet, JsonRpcProvider } from 'ethers';
117
99
  *
118
100
  * const rpcUrl = 'YOUR_RPC_URL';
119
101
  * const privateKey = 'YOUR_PRIVATE_KEY';
120
102
  *
121
- * const provider = new providers.JsonRpcProvider(rpcUrl);
103
+ * const provider = new JsonRpcProvider(rpcUrl);
122
104
  * const signer = new Wallet(privateKey, provider);
123
105
  * const escrowClient = await EscrowClient.build(signer);
124
106
  * ```
125
107
  *
126
- * **Using Wagmi (frontend)**
108
+ * ####Using Wagmi (frontend)
127
109
  *
128
110
  * ```ts
129
- * import { useSigner, useChainId } from 'wagmi';
111
+ * import { useSigner } from 'wagmi';
130
112
  * import { EscrowClient } from '@human-protocol/sdk';
131
113
  *
132
114
  * const { data: signer } = useSigner();
133
115
  * const escrowClient = await EscrowClient.build(signer);
134
116
  * ```
135
117
  *
136
- * ### Provider
118
+ * ###Using Provider
137
119
  *
138
120
  * ```ts
139
121
  * import { EscrowClient } from '@human-protocol/sdk';
140
- * import { providers } from 'ethers';
122
+ * import { JsonRpcProvider } from 'ethers';
141
123
  *
142
124
  * const rpcUrl = 'YOUR_RPC_URL';
143
- *
144
- * const provider = new providers.JsonRpcProvider(rpcUrl);
125
+ * const provider = new JsonRpcProvider(rpcUrl);
145
126
  * const escrowClient = await EscrowClient.build(provider);
146
127
  * ```
147
128
  */
148
129
  export class EscrowClient extends BaseEthersClient {
149
- private escrowFactoryContract: EscrowFactory;
130
+ public escrowFactoryContract: EscrowFactory;
150
131
 
151
132
  /**
152
133
  * **EscrowClient constructor**
153
134
  *
154
- * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
155
- * @param {NetworkData} networkData The network information required to connect to the Escrow contract
135
+ * @param runner - The Runner object to interact with the Ethereum network
136
+ * @param networkData - The network information required to connect to the Escrow contract
137
+ * @returns An instance of EscrowClient
156
138
  */
157
139
  constructor(runner: ContractRunner, networkData: NetworkData) {
158
140
  super(runner, networkData);
@@ -166,11 +148,10 @@ export class EscrowClient extends BaseEthersClient {
166
148
  /**
167
149
  * Creates an instance of EscrowClient from a Runner.
168
150
  *
169
- * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
170
- *
171
- * @returns {Promise<EscrowClient>} An instance of EscrowClient
172
- * @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
173
- * @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
151
+ * @param runner - The Runner object to interact with the Ethereum network
152
+ * @returns An instance of EscrowClient
153
+ * @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
154
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
174
155
  */
175
156
  public static async build(runner: ContractRunner): Promise<EscrowClient> {
176
157
  if (!runner.provider) {
@@ -204,28 +185,17 @@ export class EscrowClient extends BaseEthersClient {
204
185
 
205
186
  /**
206
187
  * This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
188
+ * @remarks Need to have available stake.
189
+ * @param tokenAddress - The address of the token to use for escrow funding.
190
+ * @param jobRequesterId - Identifier for the job requester.
191
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
192
+ * @returns Returns the address of the escrow created.
193
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
194
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
207
195
  *
208
- * @param {string} tokenAddress - The address of the token to use for escrow funding.
209
- * @param {string} jobRequesterId - Identifier for the job requester.
210
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
211
- * @returns {Promise<string>} Returns the address of the escrow created.
212
- *
213
- *
214
- * **Code example**
215
- *
216
- * > Need to have available stake.
196
+ * @example
217
197
  *
218
198
  * ```ts
219
- * import { Wallet, providers } from 'ethers';
220
- * import { EscrowClient } from '@human-protocol/sdk';
221
- *
222
- * const rpcUrl = 'YOUR_RPC_URL';
223
- * const privateKey = 'YOUR_PRIVATE_KEY';
224
- *
225
- * const provider = new providers.JsonRpcProvider(rpcUrl);
226
- * const signer = new Wallet(privateKey, provider);
227
- * const escrowClient = await EscrowClient.build(signer);
228
- *
229
199
  * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
230
200
  * const jobRequesterId = "job-requester-id";
231
201
  * const escrowAddress = await escrowClient.createEscrow(tokenAddress, jobRequesterId);
@@ -315,50 +285,45 @@ export class EscrowClient extends BaseEthersClient {
315
285
  /**
316
286
  * Creates, funds, and sets up a new escrow contract in a single transaction.
317
287
  *
318
- * @param {string} tokenAddress - The ERC-20 token address used to fund the escrow.
319
- * @param {bigint} amount - The token amount to fund the escrow with.
320
- * @param {string} jobRequesterId - An off-chain identifier for the job requester.
321
- * @param {IEscrowConfig} escrowConfig - Configuration parameters for escrow setup:
322
- * - `recordingOracle`: Address of the recording oracle.
323
- * - `reputationOracle`: Address of the reputation oracle.
324
- * - `exchangeOracle`: Address of the exchange oracle.
325
- * - `recordingOracleFee`: Fee (in basis points or percentage * 100) for the recording oracle.
326
- * - `reputationOracleFee`: Fee for the reputation oracle.
327
- * - `exchangeOracleFee`: Fee for the exchange oracle.
328
- * - `manifest`: URL to the manifest file.
329
- * - `manifestHash`: Hash of the manifest content.
330
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
331
- *
332
- * @returns {Promise<string>} Returns the address of the escrow created.
288
+ * @remarks Need to have available stake and approve allowance in the token contract before calling this method.
289
+ * @param tokenAddress - The ERC-20 token address used to fund the escrow.
290
+ * @param amount - The token amount to fund the escrow with.
291
+ * @param jobRequesterId - An off-chain identifier for the job requester.
292
+ * @param escrowConfig - Configuration parameters for escrow setup.
293
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
294
+ * @returns Returns the address of the escrow created.
295
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
296
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
297
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
298
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
299
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
300
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
301
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
302
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
303
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
333
304
  *
334
305
  * @example
335
- * import { Wallet, ethers } from 'ethers';
336
- * import { EscrowClient, IERC20__factory } from '@human-protocol/sdk';
337
- *
338
- * const rpcUrl = 'YOUR_RPC_URL';
339
- * const privateKey = 'YOUR_PRIVATE_KEY';
340
- * const provider = new ethers.JsonRpcProvider(rpcUrl);
341
- * const signer = new Wallet(privateKey, provider);
342
- *
343
- * const escrowClient = await EscrowClient.build(signer);
306
+ * ```ts
307
+ * import { ethers } from 'ethers';
308
+ * import { ERC20__factory } from '@human-protocol/sdk';
344
309
  *
345
- * const tokenAddress = '0xTokenAddress';
310
+ * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
346
311
  * const amount = ethers.parseUnits('1000', 18);
347
312
  * const jobRequesterId = 'requester-123';
348
313
  *
349
- * const token = IERC20__factory.connect(tokenAddress, signer);
314
+ * const token = ERC20__factory.connect(tokenAddress, signer);
350
315
  * await token.approve(escrowClient.escrowFactoryContract.target, amount);
351
316
  *
352
317
  * const escrowConfig = {
353
- * recordingOracle: '0xRecordingOracle',
354
- * reputationOracle: '0xReputationOracle',
355
- * exchangeOracle: '0xExchangeOracle',
318
+ * recordingOracle: '0xRecordingOracleAddress',
319
+ * reputationOracle: '0xReputationOracleAddress',
320
+ * exchangeOracle: '0xExchangeOracleAddress',
356
321
  * recordingOracleFee: 5n,
357
322
  * reputationOracleFee: 5n,
358
323
  * exchangeOracleFee: 5n,
359
324
  * manifest: 'https://example.com/manifest.json',
360
325
  * manifestHash: 'manifestHash-123',
361
- * } satisfies IEscrowConfig;
326
+ * };
362
327
  *
363
328
  * const escrowAddress = await escrowClient.createFundAndSetupEscrow(
364
329
  * tokenAddress,
@@ -366,8 +331,8 @@ export class EscrowClient extends BaseEthersClient {
366
331
  * jobRequesterId,
367
332
  * escrowConfig
368
333
  * );
369
- *
370
334
  * console.log('Escrow created at:', escrowAddress);
335
+ * ```
371
336
  */
372
337
  @requiresSigner
373
338
  public async createFundAndSetupEscrow(
@@ -431,35 +396,33 @@ export class EscrowClient extends BaseEthersClient {
431
396
  /**
432
397
  * This function sets up the parameters of the escrow.
433
398
  *
434
- * @param {string} escrowAddress Address of the escrow to set up.
435
- * @param {IEscrowConfig} escrowConfig Escrow configuration parameters.
436
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
437
- * @returns Returns void if successful. Throws error if any.
399
+ * @remarks Only Job Launcher or admin can call it.
400
+ *
401
+ * @param escrowAddress - Address of the escrow to set up.
402
+ * @param escrowConfig - Escrow configuration parameters.
403
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
404
+ * @returns -
405
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
406
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
407
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
408
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
409
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
410
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
411
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
412
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
413
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
438
414
  *
439
- *
440
- * **Code example**
441
- *
442
- * > Only Job Launcher or admin can call it.
415
+ * @example
443
416
  *
444
417
  * ```ts
445
- * import { Wallet, providers } from 'ethers';
446
- * import { EscrowClient } from '@human-protocol/sdk';
447
- *
448
- * const rpcUrl = 'YOUR_RPC_URL';
449
- * const privateKey = 'YOUR_PRIVATE_KEY';
450
- *
451
- * const provider = new providers.JsonRpcProvider(rpcUrl);
452
- * const signer = new Wallet(privateKey, provider);
453
- * const escrowClient = await EscrowClient.build(signer);
454
- *
455
418
  * const escrowAddress = '0x62dD51230A30401C455c8398d06F85e4EaB6309f';
456
419
  * const escrowConfig = {
457
420
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
458
421
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
459
422
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
460
- * recordingOracleFee: BigInt('10'),
461
- * reputationOracleFee: BigInt('10'),
462
- * exchangeOracleFee: BigInt('10'),
423
+ * recordingOracleFee: 10n,
424
+ * reputationOracleFee: 10n,
425
+ * exchangeOracleFee: 10n,
463
426
  * manifest: 'http://localhost/manifest.json',
464
427
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
465
428
  * };
@@ -519,26 +482,19 @@ export class EscrowClient extends BaseEthersClient {
519
482
  /**
520
483
  * This function adds funds of the chosen token to the escrow.
521
484
  *
522
- * @param {string} escrowAddress Address of the escrow to fund.
523
- * @param {bigint} amount Amount to be added as funds.
524
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
525
- * @returns Returns void if successful. Throws error if any.
526
- *
527
- *
528
- * **Code example**
485
+ * @param escrowAddress - Address of the escrow to fund.
486
+ * @param amount - Amount to be added as funds.
487
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
488
+ * @returns -
489
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
490
+ * @throws ErrorAmountMustBeGreaterThanZero If the amount is less than or equal to zero
491
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
529
492
  *
493
+ * @example
530
494
  * ```ts
531
- * import { ethers, Wallet, providers } from 'ethers';
532
- * import { EscrowClient } from '@human-protocol/sdk';
533
- *
534
- * const rpcUrl = 'YOUR_RPC_URL';
535
- * const privateKey = 'YOUR_PRIVATE_KEY';
536
- *
537
- * const provider = new providers.JsonRpcProvider(rpcUrl);
538
- * const signer = new Wallet(privateKey, provider);
539
- * const escrowClient = await EscrowClient.build(signer);
495
+ * import { ethers } from 'ethers';
540
496
  *
541
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
497
+ * const amount = ethers.parseUnits('5', 'ether');
542
498
  * await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
543
499
  * ```
544
500
  */
@@ -580,75 +536,74 @@ export class EscrowClient extends BaseEthersClient {
580
536
  }
581
537
 
582
538
  /**
583
- * This function stores the results URL and hash.
584
- *
585
- * @param {string} escrowAddress Address of the escrow.
586
- * @param {string} url Results file URL.
587
- * @param {string} hash Results file hash.
588
- * @param {bigint} fundsToReserve Funds to reserve for payouts
589
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
590
- * @returns Returns void if successful. Throws error if any.
591
- *
539
+ * Stores the result URL and result hash for an escrow.
592
540
  *
593
- * **Code example**
541
+ * @remarks Only Recording Oracle or admin can call it.
594
542
  *
595
- * > Only Recording Oracle or admin can call it.
543
+ * @param escrowAddress - The escrow address.
544
+ * @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
545
+ * @param hash - The hash of the results payload.
546
+ * @param txOptions - Optional transaction overrides.
547
+ * @returns -
548
+ * @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
549
+ * @throws ErrorInvalidUrl If the URL format is invalid.
550
+ * @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
551
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
552
+ * @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
596
553
  *
554
+ * @example
597
555
  * ```ts
598
- * import { ethers, Wallet, providers } from 'ethers';
599
- * import { EscrowClient } from '@human-protocol/sdk';
600
- *
601
- * const rpcUrl = 'YOUR_RPC_URL';
602
- * const privateKey = 'YOUR_PRIVATE_KEY';
603
- *
604
- * const provider = new providers.JsonRpcProvider(rpcUrl);
605
- * const signer = new Wallet(privateKey, provider);
606
- * const escrowClient = await EscrowClient.build(signer);
607
- *
608
- * await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079', ethers.parseEther('10'));
556
+ * await escrowClient.storeResults(
557
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
558
+ * 'https://example.com/results.json',
559
+ * '0xHASH123'
560
+ * );
609
561
  * ```
610
562
  */
611
-
612
563
  async storeResults(
613
564
  escrowAddress: string,
614
565
  url: string,
615
566
  hash: string,
616
- fundsToReserve: bigint,
617
567
  txOptions?: Overrides
618
568
  ): Promise<void>;
619
569
 
620
570
  /**
621
- * This function stores the results URL and hash.
622
- *
623
- * @param {string} escrowAddress Address of the escrow.
624
- * @param {string} url Results file URL.
625
- * @param {string} hash Results file hash.
626
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
627
- * @returns Returns void if successful. Throws error if any.
571
+ * Stores the result URL and result hash for an escrow.
628
572
  *
573
+ * @remarks Only Recording Oracle or admin can call it.
629
574
  *
630
- * **Code example**
575
+ * If `fundsToReserve` is provided, the escrow reserves the specified funds.
576
+ * When `fundsToReserve` is `0n`, an empty URL is allowed (for cases where no solutions were provided).
631
577
  *
632
- * > Only Recording Oracle or admin can call it.
578
+ * @param escrowAddress - The escrow address.
579
+ * @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
580
+ * @param hash - The hash of the results payload.
581
+ * @param fundsToReserve - Optional amount of funds to reserve (when using second overload).
582
+ * @param txOptions - Optional transaction overrides.
583
+ * @returns -
584
+ * @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
585
+ * @throws ErrorInvalidUrl If the URL format is invalid.
586
+ * @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
587
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
588
+ * @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
633
589
  *
590
+ * @example
634
591
  * ```ts
635
- * import { ethers, Wallet, providers } from 'ethers';
636
- * import { EscrowClient } from '@human-protocol/sdk';
637
- *
638
- * const rpcUrl = 'YOUR_RPC_URL';
639
- * const privateKey = 'YOUR_PRIVATE_KEY';
592
+ * import { ethers } from 'ethers';
640
593
  *
641
- * const provider = new providers.JsonRpcProvider(rpcUrl);
642
- * const signer = new Wallet(privateKey, provider);
643
- * const escrowClient = await EscrowClient.build(signer);
644
- *
645
- * await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
594
+ * await escrowClient.storeResults(
595
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
596
+ * 'https://example.com/results.json',
597
+ * '0xHASH123',
598
+ * ethers.parseEther('5')
599
+ * );
646
600
  * ```
647
601
  */
648
602
  async storeResults(
649
603
  escrowAddress: string,
650
604
  url: string,
651
605
  hash: string,
606
+ fundsToReserve: bigint,
652
607
  txOptions?: Overrides
653
608
  ): Promise<void>;
654
609
 
@@ -715,27 +670,15 @@ export class EscrowClient extends BaseEthersClient {
715
670
 
716
671
  /**
717
672
  * This function sets the status of an escrow to completed.
673
+ * @remarks Only Recording Oracle or admin can call it.
674
+ * @param escrowAddress - Address of the escrow.
675
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
676
+ * @returns -
677
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid.
678
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory.
718
679
  *
719
- * @param {string} escrowAddress Address of the escrow.
720
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
721
- * @returns Returns void if successful. Throws error if any.
722
- *
723
- *
724
- * **Code example**
725
- *
726
- * > Only Recording Oracle or admin can call it.
727
- *
680
+ * @example
728
681
  * ```ts
729
- * import { Wallet, providers } from 'ethers';
730
- * import { EscrowClient } from '@human-protocol/sdk';
731
- *
732
- * const rpcUrl = 'YOUR_RPC_URL';
733
- * const privateKey = 'YOUR_PRIVATE_KEY';
734
- *
735
- * const provider = new providers.JsonRpcProvider(rpcUrl);
736
- * const signer = new Wallet(privateKey, provider);
737
- * const escrowClient = await EscrowClient.build(signer);
738
- *
739
682
  * await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
740
683
  * ```
741
684
  */
@@ -764,40 +707,48 @@ export class EscrowClient extends BaseEthersClient {
764
707
 
765
708
  /**
766
709
  * This function pays out the amounts specified to the workers and sets the URL of the final results file.
710
+ * @remarks Only Reputation Oracle or admin can call it.
711
+ *
712
+ * @param escrowAddress - Escrow address to payout.
713
+ * @param recipients - Array of recipient addresses.
714
+ * @param amounts - Array of amounts the recipients will receive.
715
+ * @param finalResultsUrl - Final results file URL.
716
+ * @param finalResultsHash - Final results file hash.
717
+ * @param txId - Transaction ID.
718
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
719
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
720
+ * @returns -
721
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
722
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
723
+ * @throws ErrorTooManyRecipients If there are too many recipients
724
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
725
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
726
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
727
+ * @throws ErrorInvalidUrl If the final results URL is invalid
728
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
729
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
730
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
731
+ * @throws ErrorBulkPayOutVersion If using deprecated signature
767
732
  *
768
- * @param {string} escrowAddress Escrow address to payout.
769
- * @param {string[]} recipients Array of recipient addresses.
770
- * @param {bigint[]} amounts Array of amounts the recipients will receive.
771
- * @param {string} finalResultsUrl Final results file URL.
772
- * @param {string} finalResultsHash Final results file hash.
773
- * @param {number} txId Transaction ID.
774
- * @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
775
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
776
- * @returns Returns void if successful. Throws error if any.
777
- *
778
- *
779
- * **Code example**
780
- *
781
- * > Only Reputation Oracle or admin can call it.
782
- *
733
+ * @example
783
734
  * ```ts
784
- * import { ethers, Wallet, providers } from 'ethers';
785
- * import { EscrowClient } from '@human-protocol/sdk';
786
- *
787
- * const rpcUrl = 'YOUR_RPC_URL';
788
- * const privateKey = 'YOUR_PRIVATE_KEY';
789
- *
790
- * const provider = new providers.JsonRpcProvider(rpcUrl);
791
- * const signer = new Wallet(privateKey, provider);
792
- * const escrowClient = await EscrowClient.build(signer);
735
+ * import { ethers } from 'ethers';
793
736
  *
794
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
795
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
737
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
738
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
796
739
  * const resultsUrl = 'http://localhost/results.json';
797
740
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
798
741
  * const txId = 1;
799
742
  *
800
- * await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId, true);
743
+ * await escrowClient.bulkPayOut(
744
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
745
+ * recipients,
746
+ * amounts,
747
+ * resultsUrl,
748
+ * resultsHash,
749
+ * txId,
750
+ * true
751
+ * );
801
752
  * ```
802
753
  */
803
754
  async bulkPayOut(
@@ -813,41 +764,49 @@ export class EscrowClient extends BaseEthersClient {
813
764
 
814
765
  /**
815
766
  * This function pays out the amounts specified to the workers and sets the URL of the final results file.
767
+ * @remarks Only Reputation Oracle or admin can call it.
768
+ * @param escrowAddress - Escrow address to payout.
769
+ * @param recipients - Array of recipient addresses.
770
+ * @param amounts - Array of amounts the recipients will receive.
771
+ * @param finalResultsUrl - Final results file URL.
772
+ * @param finalResultsHash - Final results file hash.
773
+ * @param payoutId - Payout ID.
774
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
775
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
776
+ * @returns -
777
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
778
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
779
+ * @throws ErrorTooManyRecipients If there are too many recipients
780
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
781
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
782
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
783
+ * @throws ErrorInvalidUrl If the final results URL is invalid
784
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
785
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
786
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
787
+ * @throws ErrorBulkPayOutVersion If using deprecated signature
816
788
  *
817
- * @param {string} escrowAddress Escrow address to payout.
818
- * @param {string[]} recipients Array of recipient addresses.
819
- * @param {bigint[]} amounts Array of amounts the recipients will receive.
820
- * @param {string} finalResultsUrl Final results file URL.
821
- * @param {string} finalResultsHash Final results file hash.
822
- * @param {string} payoutId Payout ID.
823
- * @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
824
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
825
- * @returns Returns void if successful. Throws error if any.
826
- *
827
- *
828
- * **Code example**
829
- *
830
- * > Only Reputation Oracle or admin can call it.
789
+ * @example
831
790
  *
832
791
  * ```ts
833
- * import { ethers, Wallet, providers } from 'ethers';
834
- * import { EscrowClient } from '@human-protocol/sdk';
792
+ * import { ethers } from 'ethers';
835
793
  * import { v4 as uuidV4 } from 'uuid';
836
794
  *
837
- * const rpcUrl = 'YOUR_RPC_URL';
838
- * const privateKey = 'YOUR_PRIVATE_KEY';
839
- *
840
- * const provider = new providers.JsonRpcProvider(rpcUrl);
841
- * const signer = new Wallet(privateKey, provider);
842
- * const escrowClient = await EscrowClient.build(signer);
843
- *
844
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
845
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
795
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
796
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
846
797
  * const resultsUrl = 'http://localhost/results.json';
847
798
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
848
799
  * const payoutId = uuidV4();
849
800
  *
850
- * await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, payoutId, true);
801
+ * await escrowClient.bulkPayOut(
802
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
803
+ * recipients,
804
+ * amounts,
805
+ * resultsUrl,
806
+ * resultsHash,
807
+ * payoutId,
808
+ * true
809
+ * );
851
810
  * ```
852
811
  */
853
812
  async bulkPayOut(
@@ -925,26 +884,16 @@ export class EscrowClient extends BaseEthersClient {
925
884
 
926
885
  /**
927
886
  * This function cancels the specified escrow and sends the balance to the canceler.
887
+ * @remarks Only Job Launcher or admin can call it.
888
+ * @param escrowAddress - Address of the escrow to cancel.
889
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
890
+ * @returns -
891
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
892
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
928
893
  *
929
- * @param {string} escrowAddress Address of the escrow to cancel.
930
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
931
- *
932
- *
933
- * **Code example**
934
- *
935
- * > Only Job Launcher or admin can call it.
894
+ * @example
936
895
  *
937
896
  * ```ts
938
- * import { ethers, Wallet, providers } from 'ethers';
939
- * import { EscrowClient } from '@human-protocol/sdk';
940
- *
941
- * const rpcUrl = 'YOUR_RPC_URL';
942
- * const privateKey = 'YOUR_PRIVATE_KEY';
943
- *
944
- * const provider = new providers.JsonRpcProvider(rpcUrl);
945
- * const signer = new Wallet(privateKey, provider);
946
- * const escrowClient = await EscrowClient.build(signer);
947
- *
948
897
  * await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
949
898
  * ```
950
899
  */
@@ -971,26 +920,16 @@ export class EscrowClient extends BaseEthersClient {
971
920
 
972
921
  /**
973
922
  * This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
923
+ * @remarks Only Job Launcher or admin can call it.
924
+ * @param escrowAddress - Address of the escrow to request cancellation.
925
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
926
+ * @returns -
927
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
928
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
974
929
  *
975
- * @param {string} escrowAddress Address of the escrow to request cancellation.
976
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
977
- * @returns Returns void if successful. Throws error if any.
978
- *
979
- * **Code example**
980
- *
981
- * > Only Job Launcher or admin can call it.
930
+ * @example
982
931
  *
983
932
  * ```ts
984
- * import { Wallet, providers } from 'ethers';
985
- * import { EscrowClient } from '@human-protocol/sdk';
986
- *
987
- * const rpcUrl = 'YOUR_RPC_URL';
988
- * const privateKey = 'YOUR_PRIVATE_KEY';
989
- *
990
- * const provider = new providers.JsonRpcProvider(rpcUrl);
991
- * const signer = new Wallet(privateKey, provider);
992
- * const escrowClient = await EscrowClient.build(signer);
993
- *
994
933
  * await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
995
934
  * ```
996
935
  */
@@ -1017,32 +956,25 @@ export class EscrowClient extends BaseEthersClient {
1017
956
 
1018
957
  /**
1019
958
  * This function withdraws additional tokens in the escrow to the canceler.
959
+ * @remarks Only Job Launcher or admin can call it.
1020
960
  *
1021
- * @param {string} escrowAddress Address of the escrow to withdraw.
1022
- * @param {string} tokenAddress Address of the token to withdraw.
1023
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
1024
- * @returns {IEscrowWithdraw} Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.
961
+ * @param escrowAddress - Address of the escrow to withdraw.
962
+ * @param tokenAddress - Address of the token to withdraw.
963
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
964
+ * @returns Returns the escrow withdrawal data including transaction hash and withdrawal amount.
965
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
966
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
967
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
968
+ * @throws ErrorTransferEventNotFoundInTransactionLogs If the Transfer event is not found in transaction logs
1025
969
  *
1026
- *
1027
- * **Code example**
1028
- *
1029
- * > Only Job Launcher or admin can call it.
970
+ * @example
1030
971
  *
1031
972
  * ```ts
1032
- * import { ethers, Wallet, providers } from 'ethers';
1033
- * import { EscrowClient } from '@human-protocol/sdk';
1034
- *
1035
- * const rpcUrl = 'YOUR_RPC_URL';
1036
- * const privateKey = 'YOUR_PRIVATE_KEY';
1037
- *
1038
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1039
- * const signer = new Wallet(privateKey, provider);
1040
- * const escrowClient = await EscrowClient.build(signer);
1041
- *
1042
- * await escrowClient.withdraw(
973
+ * const withdrawData = await escrowClient.withdraw(
1043
974
  * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
1044
975
  * '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
1045
976
  * );
977
+ * console.log('Withdrawn amount:', withdrawData.withdrawnAmount);
1046
978
  * ```
1047
979
  */
1048
980
  @requiresSigner
@@ -1108,43 +1040,54 @@ export class EscrowClient extends BaseEthersClient {
1108
1040
 
1109
1041
  /**
1110
1042
  * Creates a prepared transaction for bulk payout without immediately sending it.
1111
- * @param {string} escrowAddress Escrow address to payout.
1112
- * @param {string[]} recipients Array of recipient addresses.
1113
- * @param {bigint[]} amounts Array of amounts the recipients will receive.
1114
- * @param {string} finalResultsUrl Final results file URL.
1115
- * @param {string} finalResultsHash Final results file hash.
1116
- * @param {string} payoutId Payout ID to identify the payout.
1117
- * @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
1118
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
1119
- * @returns Returns object with raw transaction and signed transaction hash
1043
+ * @remarks Only Reputation Oracle or admin can call it.
1044
+ *
1045
+ * @param escrowAddress - Escrow address to payout.
1046
+ * @param recipients - Array of recipient addresses.
1047
+ * @param amounts - Array of amounts the recipients will receive.
1048
+ * @param finalResultsUrl - Final results file URL.
1049
+ * @param finalResultsHash - Final results file hash.
1050
+ * @param payoutId - Payout ID to identify the payout.
1051
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
1052
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
1053
+ * @returns Returns object with raw transaction and nonce
1054
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1055
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
1056
+ * @throws ErrorTooManyRecipients If there are too many recipients
1057
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
1058
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
1059
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
1060
+ * @throws ErrorInvalidUrl If the final results URL is invalid
1061
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
1062
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
1063
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1120
1064
  *
1121
- * **Code example**
1122
- *
1123
- * > Only Reputation Oracle or admin can call it.
1065
+ * @example
1124
1066
  *
1125
1067
  * ```ts
1126
- * import { ethers, Wallet, providers } from 'ethers';
1127
- * import { EscrowClient } from '@human-protocol/sdk';
1128
- *
1129
- * const rpcUrl = 'YOUR_RPC_URL';
1130
- * const privateKey = 'YOUR_PRIVATE_KEY'
1131
- *
1132
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1133
- * const signer = new Wallet(privateKey, provider);
1134
- * const escrowClient = await EscrowClient.build(signer);
1068
+ * import { ethers } from 'ethers';
1069
+ * import { v4 as uuidV4 } from 'uuid';
1135
1070
  *
1136
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
1137
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
1071
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
1072
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
1138
1073
  * const resultsUrl = 'http://localhost/results.json';
1139
1074
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
1140
- * const payoutId = '372f6916-fe34-4711-b6e3-274f682047de';
1075
+ * const payoutId = uuidV4();
1141
1076
  *
1142
- * const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
1077
+ * const rawTransaction = await escrowClient.createBulkPayoutTransaction(
1078
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
1079
+ * recipients,
1080
+ * amounts,
1081
+ * resultsUrl,
1082
+ * resultsHash,
1083
+ * payoutId
1084
+ * );
1143
1085
  * console.log('Raw transaction:', rawTransaction);
1144
1086
  *
1145
1087
  * const signedTransaction = await signer.signTransaction(rawTransaction);
1146
1088
  * console.log('Tx hash:', ethers.keccak256(signedTransaction));
1147
- * (await signer.sendTransaction(rawTransaction)).wait();
1089
+ * await signer.sendTransaction(rawTransaction);
1090
+ * ```
1148
1091
  */
1149
1092
  @requiresSigner
1150
1093
  async createBulkPayoutTransaction(
@@ -1275,21 +1218,15 @@ export class EscrowClient extends BaseEthersClient {
1275
1218
  /**
1276
1219
  * This function returns the balance for a specified escrow address.
1277
1220
  *
1278
- * @param {string} escrowAddress Address of the escrow.
1279
- * @returns {Promise<bigint>} Balance of the escrow in the token used to fund it.
1280
- *
1281
- * **Code example**
1221
+ * @param escrowAddress - Address of the escrow.
1222
+ * @returns Balance of the escrow in the token used to fund it.
1223
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1224
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1282
1225
  *
1226
+ * @example
1283
1227
  * ```ts
1284
- * import { providers } from 'ethers';
1285
- * import { EscrowClient } from '@human-protocol/sdk';
1286
- *
1287
- * const rpcUrl = 'YOUR_RPC_URL';
1288
- *
1289
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1290
- * const escrowClient = await EscrowClient.build(provider);
1291
- *
1292
1228
  * const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1229
+ * console.log('Balance:', balance);
1293
1230
  * ```
1294
1231
  */
1295
1232
  async getBalance(escrowAddress: string): Promise<bigint> {
@@ -1319,21 +1256,15 @@ export class EscrowClient extends BaseEthersClient {
1319
1256
  /**
1320
1257
  * This function returns the reserved funds for a specified escrow address.
1321
1258
  *
1322
- * @param {string} escrowAddress Address of the escrow.
1323
- * @returns {Promise<bigint>} Reserved funds of the escrow in the token used to fund it.
1324
- *
1325
- * **Code example**
1259
+ * @param escrowAddress - Address of the escrow.
1260
+ * @returns Reserved funds of the escrow in the token used to fund it.
1261
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1262
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1326
1263
  *
1264
+ * @example
1327
1265
  * ```ts
1328
- * import { providers } from 'ethers';
1329
- * import { EscrowClient } from '@human-protocol/sdk';
1330
- *
1331
- * const rpcUrl = 'YOUR_RPC_URL';
1332
- *
1333
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1334
- * const escrowClient = await EscrowClient.build(provider);
1335
- *
1336
1266
  * const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1267
+ * console.log('Reserved funds:', reservedFunds);
1337
1268
  * ```
1338
1269
  */
1339
1270
  async getReservedFunds(escrowAddress: string): Promise<bigint> {
@@ -1356,21 +1287,15 @@ export class EscrowClient extends BaseEthersClient {
1356
1287
  /**
1357
1288
  * This function returns the manifest file hash.
1358
1289
  *
1359
- * @param {string} escrowAddress Address of the escrow.
1360
- * @returns {Promise<string>} Hash of the manifest file content.
1361
- *
1362
- * **Code example**
1290
+ * @param escrowAddress - Address of the escrow.
1291
+ * @returns Hash of the manifest file content.
1292
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1293
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1363
1294
  *
1295
+ * @example
1364
1296
  * ```ts
1365
- * import { providers } from 'ethers';
1366
- * import { EscrowClient } from '@human-protocol/sdk';
1367
- *
1368
- * const rpcUrl = 'YOUR_RPC_URL';
1369
- *
1370
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1371
- * const escrowClient = await EscrowClient.build(provider);
1372
- *
1373
1297
  * const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1298
+ * console.log('Manifest hash:', manifestHash);
1374
1299
  * ```
1375
1300
  */
1376
1301
  async getManifestHash(escrowAddress: string): Promise<string> {
@@ -1394,21 +1319,15 @@ export class EscrowClient extends BaseEthersClient {
1394
1319
  /**
1395
1320
  * This function returns the manifest. Could be a URL or a JSON string.
1396
1321
  *
1397
- * @param {string} escrowAddress Address of the escrow.
1398
- * @returns {Promise<string>} Url of the manifest.
1399
- *
1400
- * **Code example**
1322
+ * @param escrowAddress - Address of the escrow.
1323
+ * @returns Manifest URL or JSON string.
1324
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1325
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1401
1326
  *
1327
+ * @example
1402
1328
  * ```ts
1403
- * import { providers } from 'ethers';
1404
- * import { EscrowClient } from '@human-protocol/sdk';
1405
- *
1406
- * const rpcUrl = 'YOUR_RPC_URL';
1407
- *
1408
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1409
- * const escrowClient = await EscrowClient.build(provider);
1410
- *
1411
1329
  * const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1330
+ * console.log('Manifest:', manifest);
1412
1331
  * ```
1413
1332
  */
1414
1333
  async getManifest(escrowAddress: string): Promise<string> {
@@ -1432,21 +1351,15 @@ export class EscrowClient extends BaseEthersClient {
1432
1351
  /**
1433
1352
  * This function returns the results file URL.
1434
1353
  *
1435
- * @param {string} escrowAddress Address of the escrow.
1436
- * @returns {Promise<string>} Results file url.
1437
- *
1438
- * **Code example**
1354
+ * @param escrowAddress - Address of the escrow.
1355
+ * @returns Results file URL.
1356
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1357
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1439
1358
  *
1359
+ * @example
1440
1360
  * ```ts
1441
- * import { providers } from 'ethers';
1442
- * import { EscrowClient } from '@human-protocol/sdk';
1443
- *
1444
- * const rpcUrl = 'YOUR_RPC_URL';
1445
- *
1446
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1447
- * const escrowClient = await EscrowClient.build(provider);
1448
- *
1449
1361
  * const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1362
+ * console.log('Results URL:', resultsUrl);
1450
1363
  * ```
1451
1364
  */
1452
1365
  async getResultsUrl(escrowAddress: string): Promise<string> {
@@ -1470,21 +1383,15 @@ export class EscrowClient extends BaseEthersClient {
1470
1383
  /**
1471
1384
  * This function returns the intermediate results file URL.
1472
1385
  *
1473
- * @param {string} escrowAddress Address of the escrow.
1474
- * @returns {Promise<string>} Url of the file that store results from Recording Oracle.
1475
- *
1476
- * **Code example**
1386
+ * @param escrowAddress - Address of the escrow.
1387
+ * @returns URL of the file that stores results from Recording Oracle.
1388
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1389
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1477
1390
  *
1391
+ * @example
1478
1392
  * ```ts
1479
- * import { providers } from 'ethers';
1480
- * import { EscrowClient } from '@human-protocol/sdk';
1481
- *
1482
- * const rpcUrl = 'YOUR_RPC_URL';
1483
- *
1484
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1485
- * const escrowClient = await EscrowClient.build(provider);
1486
- *
1487
1393
  * const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1394
+ * console.log('Intermediate results URL:', intermediateResultsUrl);
1488
1395
  * ```
1489
1396
  */
1490
1397
  async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
@@ -1508,21 +1415,15 @@ export class EscrowClient extends BaseEthersClient {
1508
1415
  /**
1509
1416
  * This function returns the intermediate results hash.
1510
1417
  *
1511
- * @param {string} escrowAddress Address of the escrow.
1512
- * @returns {Promise<string>} Hash of the intermediate results file content.
1513
- *
1514
- * **Code example**
1418
+ * @param escrowAddress - Address of the escrow.
1419
+ * @returns Hash of the intermediate results file content.
1420
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1421
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1515
1422
  *
1423
+ * @example
1516
1424
  * ```ts
1517
- * import { providers } from 'ethers';
1518
- * import { EscrowClient } from '@human-protocol/sdk';
1519
- *
1520
- * const rpcUrl = 'YOUR_RPC_URL';
1521
- *
1522
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1523
- * const escrowClient = await EscrowClient.build(provider);
1524
- *
1525
1425
  * const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1426
+ * console.log('Intermediate results hash:', intermediateResultsHash);
1526
1427
  * ```
1527
1428
  */
1528
1429
  async getIntermediateResultsHash(escrowAddress: string): Promise<string> {
@@ -1546,21 +1447,15 @@ export class EscrowClient extends BaseEthersClient {
1546
1447
  /**
1547
1448
  * This function returns the token address used for funding the escrow.
1548
1449
  *
1549
- * @param {string} escrowAddress Address of the escrow.
1550
- * @returns {Promise<string>} Address of the token used to fund the escrow.
1551
- *
1552
- * **Code example**
1450
+ * @param escrowAddress - Address of the escrow.
1451
+ * @returns Address of the token used to fund the escrow.
1452
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1453
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1553
1454
  *
1455
+ * @example
1554
1456
  * ```ts
1555
- * import { providers } from 'ethers';
1556
- * import { EscrowClient } from '@human-protocol/sdk';
1557
- *
1558
- * const rpcUrl = 'YOUR_RPC_URL';
1559
- *
1560
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1561
- * const escrowClient = await EscrowClient.build(provider);
1562
- *
1563
1457
  * const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1458
+ * console.log('Token address:', tokenAddress);
1564
1459
  * ```
1565
1460
  */
1566
1461
  async getTokenAddress(escrowAddress: string): Promise<string> {
@@ -1584,21 +1479,17 @@ export class EscrowClient extends BaseEthersClient {
1584
1479
  /**
1585
1480
  * This function returns the current status of the escrow.
1586
1481
  *
1587
- * @param {string} escrowAddress Address of the escrow.
1588
- * @returns {Promise<EscrowStatus>} Current status of the escrow.
1589
- *
1590
- * **Code example**
1482
+ * @param escrowAddress - Address of the escrow.
1483
+ * @returns Current status of the escrow.
1484
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1485
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1591
1486
  *
1487
+ * @example
1592
1488
  * ```ts
1593
- * import { providers } from 'ethers';
1594
- * import { EscrowClient } from '@human-protocol/sdk';
1595
- *
1596
- * const rpcUrl = 'YOUR_RPC_URL';
1597
- *
1598
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1599
- * const escrowClient = await EscrowClient.build(provider);
1489
+ * import { EscrowStatus } from '@human-protocol/sdk';
1600
1490
  *
1601
1491
  * const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1492
+ * console.log('Status:', EscrowStatus[status]);
1602
1493
  * ```
1603
1494
  */
1604
1495
  async getStatus(escrowAddress: string): Promise<EscrowStatus> {
@@ -1622,21 +1513,15 @@ export class EscrowClient extends BaseEthersClient {
1622
1513
  /**
1623
1514
  * This function returns the recording oracle address for a given escrow.
1624
1515
  *
1625
- * @param {string} escrowAddress Address of the escrow.
1626
- * @returns {Promise<string>} Address of the Recording Oracle.
1627
- *
1628
- * **Code example**
1516
+ * @param escrowAddress - Address of the escrow.
1517
+ * @returns Address of the Recording Oracle.
1518
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1519
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1629
1520
  *
1521
+ * @example
1630
1522
  * ```ts
1631
- * import { providers } from 'ethers';
1632
- * import { EscrowClient } from '@human-protocol/sdk';
1633
- *
1634
- * const rpcUrl = 'YOUR_RPC_URL';
1635
- *
1636
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1637
- * const escrowClient = await EscrowClient.build(provider);
1638
- *
1639
1523
  * const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1524
+ * console.log('Recording Oracle address:', oracleAddress);
1640
1525
  * ```
1641
1526
  */
1642
1527
  async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
@@ -1660,21 +1545,15 @@ export class EscrowClient extends BaseEthersClient {
1660
1545
  /**
1661
1546
  * This function returns the job launcher address for a given escrow.
1662
1547
  *
1663
- * @param {string} escrowAddress Address of the escrow.
1664
- * @returns {Promise<string>} Address of the Job Launcher.
1665
- *
1666
- * **Code example**
1548
+ * @param escrowAddress - Address of the escrow.
1549
+ * @returns Address of the Job Launcher.
1550
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1551
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1667
1552
  *
1553
+ * @example
1668
1554
  * ```ts
1669
- * import { providers } from 'ethers';
1670
- * import { EscrowClient } from '@human-protocol/sdk';
1671
- *
1672
- * const rpcUrl = 'YOUR_RPC_URL';
1673
- *
1674
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1675
- * const escrowClient = await EscrowClient.build(provider);
1676
- *
1677
1555
  * const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1556
+ * console.log('Job Launcher address:', jobLauncherAddress);
1678
1557
  * ```
1679
1558
  */
1680
1559
  async getJobLauncherAddress(escrowAddress: string): Promise<string> {
@@ -1698,21 +1577,15 @@ export class EscrowClient extends BaseEthersClient {
1698
1577
  /**
1699
1578
  * This function returns the reputation oracle address for a given escrow.
1700
1579
  *
1701
- * @param {string} escrowAddress Address of the escrow.
1702
- * @returns {Promise<string>} Address of the Reputation Oracle.
1703
- *
1704
- * **Code example**
1580
+ * @param escrowAddress - Address of the escrow.
1581
+ * @returns Address of the Reputation Oracle.
1582
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1583
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1705
1584
  *
1585
+ * @example
1706
1586
  * ```ts
1707
- * import { providers } from 'ethers';
1708
- * import { EscrowClient } from '@human-protocol/sdk';
1709
- *
1710
- * const rpcUrl = 'YOUR_RPC_URL';
1711
- *
1712
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1713
- * const escrowClient = await EscrowClient.build(provider);
1714
- *
1715
1587
  * const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1588
+ * console.log('Reputation Oracle address:', oracleAddress);
1716
1589
  * ```
1717
1590
  */
1718
1591
  async getReputationOracleAddress(escrowAddress: string): Promise<string> {
@@ -1736,21 +1609,15 @@ export class EscrowClient extends BaseEthersClient {
1736
1609
  /**
1737
1610
  * This function returns the exchange oracle address for a given escrow.
1738
1611
  *
1739
- * @param {string} escrowAddress Address of the escrow.
1740
- * @returns {Promise<string>} Address of the Exchange Oracle.
1741
- *
1742
- * **Code example**
1612
+ * @param escrowAddress - Address of the escrow.
1613
+ * @returns Address of the Exchange Oracle.
1614
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1615
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1743
1616
  *
1617
+ * @example
1744
1618
  * ```ts
1745
- * import { providers } from 'ethers';
1746
- * import { EscrowClient } from '@human-protocol/sdk';
1747
- *
1748
- * const rpcUrl = 'YOUR_RPC_URL';
1749
- *
1750
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1751
- * const escrowClient = await EscrowClient.build(provider);
1752
- *
1753
1619
  * const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1620
+ * console.log('Exchange Oracle address:', oracleAddress);
1754
1621
  * ```
1755
1622
  */
1756
1623
  async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
@@ -1774,21 +1641,15 @@ export class EscrowClient extends BaseEthersClient {
1774
1641
  /**
1775
1642
  * This function returns the escrow factory address for a given escrow.
1776
1643
  *
1777
- * @param {string} escrowAddress Address of the escrow.
1778
- * @returns {Promise<string>} Address of the escrow factory.
1779
- *
1780
- * **Code example**
1644
+ * @param escrowAddress - Address of the escrow.
1645
+ * @returns Address of the escrow factory.
1646
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1647
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1781
1648
  *
1649
+ * @example
1782
1650
  * ```ts
1783
- * import { providers } from 'ethers';
1784
- * import { EscrowClient } from '@human-protocol/sdk';
1785
- *
1786
- * const rpcUrl = 'YOUR_RPC_URL';
1787
- *
1788
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1789
- * const escrowClient = await EscrowClient.build(provider);
1790
- *
1791
1651
  * const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1652
+ * console.log('Factory address:', factoryAddress);
1792
1653
  * ```
1793
1654
  */
1794
1655
  async getFactoryAddress(escrowAddress: string): Promise<string> {
@@ -1810,138 +1671,40 @@ export class EscrowClient extends BaseEthersClient {
1810
1671
  }
1811
1672
  }
1812
1673
  /**
1813
- * ## Introduction
1814
- *
1815
- * Utility class for escrow-related operations.
1816
- *
1817
- * ## Installation
1818
- *
1819
- * ### npm
1820
- * ```bash
1821
- * npm install @human-protocol/sdk
1822
- * ```
1823
- *
1824
- * ### yarn
1825
- * ```bash
1826
- * yarn install @human-protocol/sdk
1827
- * ```
1828
- *
1829
- * ## Code example
1830
- *
1831
- * ### Signer
1832
- *
1833
- * **Using private key(backend)**
1674
+ * Utility helpers for escrow-related queries.
1834
1675
  *
1676
+ * @example
1835
1677
  * ```ts
1836
1678
  * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1837
1679
  *
1838
- * const escrowAddresses = new EscrowUtils.getEscrows({
1680
+ * const escrows = await EscrowUtils.getEscrows({
1839
1681
  * chainId: ChainId.POLYGON_AMOY
1840
1682
  * });
1683
+ * console.log('Escrows:', escrows);
1841
1684
  * ```
1842
1685
  */
1843
1686
  export class EscrowUtils {
1844
1687
  /**
1845
1688
  * This function returns an array of escrows based on the specified filter parameters.
1846
1689
  *
1690
+ * @param filter - Filter parameters.
1691
+ * @param options - Optional configuration for subgraph requests.
1692
+ * @returns List of escrows that match the filter.
1693
+ * @throws ErrorInvalidAddress If any filter address is invalid
1694
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1847
1695
  *
1848
- * **Input parameters**
1849
- *
1850
- * ```ts
1851
- * interface IEscrowsFilter {
1852
- * chainId: ChainId;
1853
- * launcher?: string;
1854
- * reputationOracle?: string;
1855
- * recordingOracle?: string;
1856
- * exchangeOracle?: string;
1857
- * jobRequesterId?: string;
1858
- * status?: EscrowStatus;
1859
- * from?: Date;
1860
- * to?: Date;
1861
- * first?: number;
1862
- * skip?: number;
1863
- * orderDirection?: OrderDirection;
1864
- * }
1865
- * ```
1866
- *
1867
- * ```ts
1868
- * enum ChainId {
1869
- * ALL = -1,
1870
- * MAINNET = 1,
1871
- * SEPOLIA = 11155111,
1872
- * BSC_MAINNET = 56,
1873
- * BSC_TESTNET = 97,
1874
- * POLYGON = 137,
1875
- * POLYGON_AMOY=80002,
1876
- * LOCALHOST = 1338,
1877
- * }
1878
- * ```
1879
- *
1880
- * ```ts
1881
- * enum OrderDirection {
1882
- * ASC = 'asc',
1883
- * DESC = 'desc',
1884
- * }
1885
- * ```
1886
- *
1887
- * ```ts
1888
- * enum EscrowStatus {
1889
- * Launched,
1890
- * Pending,
1891
- * Partial,
1892
- * Paid,
1893
- * Complete,
1894
- * Cancelled,
1895
- * }
1896
- * ```
1897
- *
1898
- * ```ts
1899
- * interface IEscrow {
1900
- * id: string;
1901
- * address: string;
1902
- * amountPaid: bigint;
1903
- * balance: bigint;
1904
- * count: bigint;
1905
- * factoryAddress: string;
1906
- * finalResultsUrl: string | null;
1907
- * finalResultsHash: string | null;
1908
- * intermediateResultsUrl: string | null;
1909
- * intermediateResultsHash: string | null;
1910
- * launcher: string;
1911
- * jobRequesterId: string | null;
1912
- * manifestHash: string | null;
1913
- * manifest: string | null;
1914
- * recordingOracle: string | null;
1915
- * reputationOracle: string | null;
1916
- * exchangeOracle: string | null;
1917
- * recordingOracleFee: number | null;
1918
- * reputationOracleFee: number | null;
1919
- * exchangeOracleFee: number | null;
1920
- * status: string;
1921
- * token: string;
1922
- * totalFundedAmount: bigint;
1923
- * createdAt: number;
1924
- * chainId: number;
1925
- * };
1926
- * ```
1927
- *
1928
- *
1929
- * @param {IEscrowsFilter} filter Filter parameters.
1930
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1931
- * @returns {IEscrow[]} List of escrows that match the filter.
1932
- *
1933
- * **Code example**
1934
- *
1696
+ * @example
1935
1697
  * ```ts
1936
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1698
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1937
1699
  *
1938
- * const filters: IEscrowsFilter = {
1700
+ * const filters = {
1939
1701
  * status: EscrowStatus.Pending,
1940
1702
  * from: new Date(2023, 4, 8),
1941
1703
  * to: new Date(2023, 5, 8),
1942
1704
  * chainId: ChainId.POLYGON_AMOY
1943
1705
  * };
1944
1706
  * const escrows = await EscrowUtils.getEscrows(filters);
1707
+ * console.log('Found escrows:', escrows.length);
1945
1708
  * ```
1946
1709
  */
1947
1710
  public static async getEscrows(
@@ -2006,63 +1769,24 @@ export class EscrowUtils {
2006
1769
  *
2007
1770
  * > This uses Subgraph
2008
1771
  *
2009
- * **Input parameters**
2010
- *
2011
- * ```ts
2012
- * enum ChainId {
2013
- * ALL = -1,
2014
- * MAINNET = 1,
2015
- * SEPOLIA = 11155111,
2016
- * BSC_MAINNET = 56,
2017
- * BSC_TESTNET = 97,
2018
- * POLYGON = 137,
2019
- * POLYGON_AMOY = 80002,
2020
- * LOCALHOST = 1338,
2021
- * }
2022
- * ```
2023
- *
2024
- * ```ts
2025
- * interface IEscrow {
2026
- * id: string;
2027
- * address: string;
2028
- * amountPaid: bigint;
2029
- * balance: bigint;
2030
- * count: bigint;
2031
- * factoryAddress: string;
2032
- * finalResultsUrl: string | null;
2033
- * finalResultsHash: string | null;
2034
- * intermediateResultsUrl: string | null;
2035
- * intermediateResultsHash: string | null;
2036
- * launcher: string;
2037
- * jobRequesterId: string | null;
2038
- * manifestHash: string | null;
2039
- * manifest: string | null;
2040
- * recordingOracle: string | null;
2041
- * reputationOracle: string | null;
2042
- * exchangeOracle: string | null;
2043
- * recordingOracleFee: number | null;
2044
- * reputationOracleFee: number | null;
2045
- * exchangeOracleFee: number | null;
2046
- * status: string;
2047
- * token: string;
2048
- * totalFundedAmount: bigint;
2049
- * createdAt: number;
2050
- * chainId: number;
2051
- * };
2052
- * ```
2053
- *
2054
- *
2055
- * @param {ChainId} chainId Network in which the escrow has been deployed
2056
- * @param {string} escrowAddress Address of the escrow
2057
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2058
- * @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
2059
- *
2060
- * **Code example**
1772
+ * @param chainId - Network in which the escrow has been deployed
1773
+ * @param escrowAddress - Address of the escrow
1774
+ * @param options - Optional configuration for subgraph requests.
1775
+ * @returns Escrow data or null if not found.
1776
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1777
+ * @throws ErrorInvalidAddress If the escrow address is invalid
2061
1778
  *
1779
+ * @example
2062
1780
  * ```ts
2063
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1781
+ * import { ChainId } from '@human-protocol/sdk';
2064
1782
  *
2065
- * const escrow = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
1783
+ * const escrow = await EscrowUtils.getEscrow(
1784
+ * ChainId.POLYGON_AMOY,
1785
+ * "0x1234567890123456789012345678901234567890"
1786
+ * );
1787
+ * if (escrow) {
1788
+ * console.log('Escrow status:', escrow.status);
1789
+ * }
2066
1790
  * ```
2067
1791
  */
2068
1792
  public static async getEscrow(
@@ -2096,56 +1820,25 @@ export class EscrowUtils {
2096
1820
  *
2097
1821
  * > This uses Subgraph
2098
1822
  *
2099
- * **Input parameters**
2100
- *
2101
- * ```ts
2102
- * enum ChainId {
2103
- * ALL = -1,
2104
- * MAINNET = 1,
2105
- * SEPOLIA = 11155111,
2106
- * BSC_MAINNET = 56,
2107
- * BSC_TESTNET = 97,
2108
- * POLYGON = 137,
2109
- * POLYGON_AMOY = 80002,
2110
- * LOCALHOST = 1338,
2111
- * }
2112
- * ```
2113
- *
2114
- * ```ts
2115
- * enum OrderDirection {
2116
- * ASC = 'asc',
2117
- * DESC = 'desc',
2118
- * }
2119
- * ```
1823
+ * @param filter - Filter parameters.
1824
+ * @param options - Optional configuration for subgraph requests.
1825
+ * @returns Array of status events with their corresponding statuses.
1826
+ * @throws ErrorInvalidAddress If the launcher address is invalid
1827
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
2120
1828
  *
1829
+ * @example
2121
1830
  * ```ts
2122
- * type Status = {
2123
- * escrowAddress: string;
2124
- * timestamp: string;
2125
- * status: string;
2126
- * };
2127
- * ```
2128
- *
2129
- * @param {IStatusEventFilter} filter Filter parameters.
2130
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2131
- * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
1831
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
2132
1832
  *
2133
- * **Code example**
2134
- *
2135
- * ```ts
2136
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
2137
- *
2138
- * (async () => {
2139
- * const fromDate = new Date('2023-01-01');
2140
- * const toDate = new Date('2023-12-31');
2141
- * const statusEvents = await EscrowUtils.getStatusEvents({
2142
- * chainId: ChainId.POLYGON,
2143
- * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
2144
- * from: fromDate,
2145
- * to: toDate
2146
- * });
2147
- * console.log(statusEvents);
2148
- * })();
1833
+ * const fromDate = new Date('2023-01-01');
1834
+ * const toDate = new Date('2023-12-31');
1835
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1836
+ * chainId: ChainId.POLYGON,
1837
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1838
+ * from: fromDate,
1839
+ * to: toDate
1840
+ * });
1841
+ * console.log('Status events:', statusEvents.length);
2149
1842
  * ```
2150
1843
  */
2151
1844
  public static async getStatusEvents(
@@ -2218,17 +1911,15 @@ export class EscrowUtils {
2218
1911
  *
2219
1912
  * > This uses Subgraph
2220
1913
  *
2221
- * **Input parameters**
2222
- * Fetch payouts from the subgraph.
2223
- *
2224
- * @param {IPayoutFilter} filter Filter parameters.
2225
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2226
- * @returns {Promise<IPayout[]>} List of payouts matching the filters.
2227
- *
2228
- * **Code example**
1914
+ * @param filter - Filter parameters.
1915
+ * @param options - Optional configuration for subgraph requests.
1916
+ * @returns List of payouts matching the filters.
1917
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1918
+ * @throws ErrorInvalidAddress If any filter address is invalid
2229
1919
  *
1920
+ * @example
2230
1921
  * ```ts
2231
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1922
+ * import { ChainId } from '@human-protocol/sdk';
2232
1923
  *
2233
1924
  * const payouts = await EscrowUtils.getPayouts({
2234
1925
  * chainId: ChainId.POLYGON,
@@ -2237,7 +1928,7 @@ export class EscrowUtils {
2237
1928
  * from: new Date('2023-01-01'),
2238
1929
  * to: new Date('2023-12-31')
2239
1930
  * });
2240
- * console.log(payouts);
1931
+ * console.log('Payouts:', payouts.length);
2241
1932
  * ```
2242
1933
  */
2243
1934
  public static async getPayouts(
@@ -2292,48 +1983,22 @@ export class EscrowUtils {
2292
1983
  *
2293
1984
  * > This uses Subgraph
2294
1985
  *
2295
- * **Input parameters**
2296
- *
2297
- * ```ts
2298
- * enum ChainId {
2299
- * ALL = -1,
2300
- * MAINNET = 1,
2301
- * SEPOLIA = 11155111,
2302
- * BSC_MAINNET = 56,
2303
- * BSC_TESTNET = 97,
2304
- * POLYGON = 137,
2305
- * POLYGON_AMOY = 80002,
2306
- * LOCALHOST = 1338,
2307
- * }
2308
- * ```
2309
- *
2310
- * ```ts
2311
- * interface ICancellationRefund {
2312
- * id: string;
2313
- * escrowAddress: string;
2314
- * receiver: string;
2315
- * amount: bigint;
2316
- * block: number;
2317
- * timestamp: number;
2318
- * txHash: string;
2319
- * };
2320
- * ```
2321
- *
2322
- *
2323
- * @param {Object} filter Filter parameters.
2324
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2325
- * @returns {Promise<ICancellationRefund[]>} List of cancellation refunds matching the filters.
2326
- *
2327
- * **Code example**
1986
+ * @param filter - Filter parameters.
1987
+ * @param options - Optional configuration for subgraph requests.
1988
+ * @returns List of cancellation refunds matching the filters.
1989
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1990
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1991
+ * @throws ErrorInvalidAddress If the receiver address is invalid
2328
1992
  *
1993
+ * @example
2329
1994
  * ```ts
2330
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1995
+ * import { ChainId } from '@human-protocol/sdk';
2331
1996
  *
2332
1997
  * const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
2333
1998
  * chainId: ChainId.POLYGON_AMOY,
2334
1999
  * escrowAddress: '0x1234567890123456789012345678901234567890',
2335
2000
  * });
2336
- * console.log(cancellationRefunds);
2001
+ * console.log('Cancellation refunds:', cancellationRefunds.length);
2337
2002
  * ```
2338
2003
  */
2339
2004
  public static async getCancellationRefunds(
@@ -2391,45 +2056,25 @@ export class EscrowUtils {
2391
2056
  *
2392
2057
  * > This uses Subgraph
2393
2058
  *
2394
- * **Input parameters**
2395
- *
2396
- * ```ts
2397
- * enum ChainId {
2398
- * ALL = -1,
2399
- * MAINNET = 1,
2400
- * SEPOLIA = 11155111,
2401
- * BSC_MAINNET = 56,
2402
- * BSC_TESTNET = 97,
2403
- * POLYGON = 137,
2404
- * POLYGON_AMOY = 80002,
2405
- * LOCALHOST = 1338,
2406
- * }
2407
- * ```
2059
+ * @param chainId - Network in which the escrow has been deployed
2060
+ * @param escrowAddress - Address of the escrow
2061
+ * @param options - Optional configuration for subgraph requests.
2062
+ * @returns Cancellation refund data or null if not found.
2063
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
2064
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
2408
2065
  *
2066
+ * @example
2409
2067
  * ```ts
2410
- * interface ICancellationRefund {
2411
- * id: string;
2412
- * escrowAddress: string;
2413
- * receiver: string;
2414
- * amount: bigint;
2415
- * block: number;
2416
- * timestamp: number;
2417
- * txHash: string;
2418
- * };
2419
- * ```
2420
- *
2421
- *
2422
- * @param {ChainId} chainId Network in which the escrow has been deployed
2423
- * @param {string} escrowAddress Address of the escrow
2424
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2425
- * @returns {Promise<ICancellationRefund>} Cancellation refund data
2068
+ * import { ChainId } from '@human-protocol/sdk';
2426
2069
  *
2427
- * **Code example**
2428
2070
  *
2429
- * ```ts
2430
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
2431
- *
2432
- * const cancellationRefund = await EscrowUtils.getCancellationRefund(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
2071
+ * const cancellationRefund = await EscrowUtils.getCancellationRefund(
2072
+ * ChainId.POLYGON_AMOY,
2073
+ * "0x1234567890123456789012345678901234567890"
2074
+ * );
2075
+ * if (cancellationRefund) {
2076
+ * console.log('Refund amount:', cancellationRefund.amount);
2077
+ * }
2433
2078
  * ```
2434
2079
  */
2435
2080
  public static async getCancellationRefund(