@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/dist/escrow.js CHANGED
@@ -22,71 +22,52 @@ const graphql_1 = require("./graphql");
22
22
  const types_1 = require("./types");
23
23
  const utils_1 = require("./utils");
24
24
  /**
25
- * ## Introduction
26
- *
27
- * This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
25
+ * Client to perform actions on Escrow contracts and obtain information from the contracts.
28
26
  *
29
27
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
30
- * To use this client, it is recommended to initialize it using the static `build` method.
31
- *
32
- * ```ts
33
- * static async build(runner: ContractRunner): Promise<EscrowClient>;
34
- * ```
28
+ * To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/EscrowClient/#build) method.
35
29
  *
36
30
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
37
31
  *
38
32
  * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
39
33
  * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
40
34
  *
41
- * ## Installation
42
- *
43
- * ### npm
44
- * ```bash
45
- * npm install @human-protocol/sdk
46
- * ```
47
- *
48
- * ### yarn
49
- * ```bash
50
- * yarn install @human-protocol/sdk
51
- * ```
35
+ * @example
52
36
  *
53
- * ## Code example
37
+ * ###Using Signer
54
38
  *
55
- * ### Signer
56
- *
57
- * **Using private key (backend)**
39
+ * ####Using private key (backend)
58
40
  *
59
41
  * ```ts
60
42
  * import { EscrowClient } from '@human-protocol/sdk';
61
- * import { Wallet, providers } from 'ethers';
43
+ * import { Wallet, JsonRpcProvider } from 'ethers';
62
44
  *
63
45
  * const rpcUrl = 'YOUR_RPC_URL';
64
46
  * const privateKey = 'YOUR_PRIVATE_KEY';
65
47
  *
66
- * const provider = new providers.JsonRpcProvider(rpcUrl);
48
+ * const provider = new JsonRpcProvider(rpcUrl);
67
49
  * const signer = new Wallet(privateKey, provider);
68
50
  * const escrowClient = await EscrowClient.build(signer);
69
51
  * ```
70
52
  *
71
- * **Using Wagmi (frontend)**
53
+ * ####Using Wagmi (frontend)
72
54
  *
73
55
  * ```ts
74
- * import { useSigner, useChainId } from 'wagmi';
56
+ * import { useSigner } from 'wagmi';
75
57
  * import { EscrowClient } from '@human-protocol/sdk';
76
58
  *
77
59
  * const { data: signer } = useSigner();
78
60
  * const escrowClient = await EscrowClient.build(signer);
79
61
  * ```
80
62
  *
81
- * ### Provider
63
+ * ###Using Provider
82
64
  *
83
65
  * ```ts
84
66
  * import { EscrowClient } from '@human-protocol/sdk';
85
- * import { providers } from 'ethers';
67
+ * import { JsonRpcProvider } from 'ethers';
86
68
  *
87
69
  * const rpcUrl = 'YOUR_RPC_URL';
88
- *
89
- * const provider = new providers.JsonRpcProvider(rpcUrl);
70
+ * const provider = new JsonRpcProvider(rpcUrl);
90
71
  * const escrowClient = await EscrowClient.build(provider);
91
72
  * ```
92
73
  */
@@ -94,8 +75,9 @@ class EscrowClient extends base_1.BaseEthersClient {
94
75
  /**
95
76
  * **EscrowClient constructor**
96
77
  *
97
- * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
98
- * @param {NetworkData} networkData The network information required to connect to the Escrow contract
78
+ * @param runner - The Runner object to interact with the Ethereum network
79
+ * @param networkData - The network information required to connect to the Escrow contract
80
+ * @returns An instance of EscrowClient
99
81
  */
100
82
  constructor(runner, networkData) {
101
83
  super(runner, networkData);
@@ -104,11 +86,10 @@ class EscrowClient extends base_1.BaseEthersClient {
104
86
  /**
105
87
  * Creates an instance of EscrowClient from a Runner.
106
88
  *
107
- * @param {ContractRunner} runner The Runner object to interact with the Ethereum network
108
- *
109
- * @returns {Promise<EscrowClient>} An instance of EscrowClient
110
- * @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
111
- * @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
89
+ * @param runner - The Runner object to interact with the Ethereum network
90
+ * @returns An instance of EscrowClient
91
+ * @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
92
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
112
93
  */
113
94
  static async build(runner) {
114
95
  if (!runner.provider) {
@@ -137,28 +118,17 @@ class EscrowClient extends base_1.BaseEthersClient {
137
118
  }
138
119
  /**
139
120
  * This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
121
+ * @remarks Need to have available stake.
122
+ * @param tokenAddress - The address of the token to use for escrow funding.
123
+ * @param jobRequesterId - Identifier for the job requester.
124
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
125
+ * @returns Returns the address of the escrow created.
126
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
127
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
140
128
  *
141
- * @param {string} tokenAddress - The address of the token to use for escrow funding.
142
- * @param {string} jobRequesterId - Identifier for the job requester.
143
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
144
- * @returns {Promise<string>} Returns the address of the escrow created.
145
- *
146
- *
147
- * **Code example**
148
- *
149
- * > Need to have available stake.
129
+ * @example
150
130
  *
151
131
  * ```ts
152
- * import { Wallet, providers } from 'ethers';
153
- * import { EscrowClient } from '@human-protocol/sdk';
154
- *
155
- * const rpcUrl = 'YOUR_RPC_URL';
156
- * const privateKey = 'YOUR_PRIVATE_KEY';
157
- *
158
- * const provider = new providers.JsonRpcProvider(rpcUrl);
159
- * const signer = new Wallet(privateKey, provider);
160
- * const escrowClient = await EscrowClient.build(signer);
161
- *
162
132
  * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
163
133
  * const jobRequesterId = "job-requester-id";
164
134
  * const escrowAddress = await escrowClient.createEscrow(tokenAddress, jobRequesterId);
@@ -210,50 +180,45 @@ class EscrowClient extends base_1.BaseEthersClient {
210
180
  /**
211
181
  * Creates, funds, and sets up a new escrow contract in a single transaction.
212
182
  *
213
- * @param {string} tokenAddress - The ERC-20 token address used to fund the escrow.
214
- * @param {bigint} amount - The token amount to fund the escrow with.
215
- * @param {string} jobRequesterId - An off-chain identifier for the job requester.
216
- * @param {IEscrowConfig} escrowConfig - Configuration parameters for escrow setup:
217
- * - `recordingOracle`: Address of the recording oracle.
218
- * - `reputationOracle`: Address of the reputation oracle.
219
- * - `exchangeOracle`: Address of the exchange oracle.
220
- * - `recordingOracleFee`: Fee (in basis points or percentage * 100) for the recording oracle.
221
- * - `reputationOracleFee`: Fee for the reputation oracle.
222
- * - `exchangeOracleFee`: Fee for the exchange oracle.
223
- * - `manifest`: URL to the manifest file.
224
- * - `manifestHash`: Hash of the manifest content.
225
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
226
- *
227
- * @returns {Promise<string>} Returns the address of the escrow created.
183
+ * @remarks Need to have available stake and approve allowance in the token contract before calling this method.
184
+ * @param tokenAddress - The ERC-20 token address used to fund the escrow.
185
+ * @param amount - The token amount to fund the escrow with.
186
+ * @param jobRequesterId - An off-chain identifier for the job requester.
187
+ * @param escrowConfig - Configuration parameters for escrow setup.
188
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
189
+ * @returns Returns the address of the escrow created.
190
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
191
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
192
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
193
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
194
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
195
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
196
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
197
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
198
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
228
199
  *
229
200
  * @example
230
- * import { Wallet, ethers } from 'ethers';
231
- * import { EscrowClient, IERC20__factory } from '@human-protocol/sdk';
232
- *
233
- * const rpcUrl = 'YOUR_RPC_URL';
234
- * const privateKey = 'YOUR_PRIVATE_KEY';
235
- * const provider = new ethers.JsonRpcProvider(rpcUrl);
236
- * const signer = new Wallet(privateKey, provider);
237
- *
238
- * const escrowClient = await EscrowClient.build(signer);
201
+ * ```ts
202
+ * import { ethers } from 'ethers';
203
+ * import { ERC20__factory } from '@human-protocol/sdk';
239
204
  *
240
- * const tokenAddress = '0xTokenAddress';
205
+ * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
241
206
  * const amount = ethers.parseUnits('1000', 18);
242
207
  * const jobRequesterId = 'requester-123';
243
208
  *
244
- * const token = IERC20__factory.connect(tokenAddress, signer);
209
+ * const token = ERC20__factory.connect(tokenAddress, signer);
245
210
  * await token.approve(escrowClient.escrowFactoryContract.target, amount);
246
211
  *
247
212
  * const escrowConfig = {
248
- * recordingOracle: '0xRecordingOracle',
249
- * reputationOracle: '0xReputationOracle',
250
- * exchangeOracle: '0xExchangeOracle',
213
+ * recordingOracle: '0xRecordingOracleAddress',
214
+ * reputationOracle: '0xReputationOracleAddress',
215
+ * exchangeOracle: '0xExchangeOracleAddress',
251
216
  * recordingOracleFee: 5n,
252
217
  * reputationOracleFee: 5n,
253
218
  * exchangeOracleFee: 5n,
254
219
  * manifest: 'https://example.com/manifest.json',
255
220
  * manifestHash: 'manifestHash-123',
256
- * } satisfies IEscrowConfig;
221
+ * };
257
222
  *
258
223
  * const escrowAddress = await escrowClient.createFundAndSetupEscrow(
259
224
  * tokenAddress,
@@ -261,8 +226,8 @@ class EscrowClient extends base_1.BaseEthersClient {
261
226
  * jobRequesterId,
262
227
  * escrowConfig
263
228
  * );
264
- *
265
229
  * console.log('Escrow created at:', escrowAddress);
230
+ * ```
266
231
  */
267
232
  async createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, escrowConfig, txOptions = {}) {
268
233
  if (!ethers_1.ethers.isAddress(tokenAddress)) {
@@ -285,35 +250,33 @@ class EscrowClient extends base_1.BaseEthersClient {
285
250
  /**
286
251
  * This function sets up the parameters of the escrow.
287
252
  *
288
- * @param {string} escrowAddress Address of the escrow to set up.
289
- * @param {IEscrowConfig} escrowConfig Escrow configuration parameters.
290
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
291
- * @returns Returns void if successful. Throws error if any.
292
- *
253
+ * @remarks Only Job Launcher or admin can call it.
254
+ *
255
+ * @param escrowAddress - Address of the escrow to set up.
256
+ * @param escrowConfig - Escrow configuration parameters.
257
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
258
+ * @returns -
259
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
260
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
261
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
262
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
263
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
264
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
265
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
266
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
267
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
293
268
  *
294
- * **Code example**
295
- *
296
- * > Only Job Launcher or admin can call it.
269
+ * @example
297
270
  *
298
271
  * ```ts
299
- * import { Wallet, providers } from 'ethers';
300
- * import { EscrowClient } from '@human-protocol/sdk';
301
- *
302
- * const rpcUrl = 'YOUR_RPC_URL';
303
- * const privateKey = 'YOUR_PRIVATE_KEY';
304
- *
305
- * const provider = new providers.JsonRpcProvider(rpcUrl);
306
- * const signer = new Wallet(privateKey, provider);
307
- * const escrowClient = await EscrowClient.build(signer);
308
- *
309
272
  * const escrowAddress = '0x62dD51230A30401C455c8398d06F85e4EaB6309f';
310
273
  * const escrowConfig = {
311
274
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
312
275
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
313
276
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
314
- * recordingOracleFee: BigInt('10'),
315
- * reputationOracleFee: BigInt('10'),
316
- * exchangeOracleFee: BigInt('10'),
277
+ * recordingOracleFee: 10n,
278
+ * reputationOracleFee: 10n,
279
+ * exchangeOracleFee: 10n,
317
280
  * manifest: 'http://localhost/manifest.json',
318
281
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
319
282
  * };
@@ -341,26 +304,19 @@ class EscrowClient extends base_1.BaseEthersClient {
341
304
  /**
342
305
  * This function adds funds of the chosen token to the escrow.
343
306
  *
344
- * @param {string} escrowAddress Address of the escrow to fund.
345
- * @param {bigint} amount Amount to be added as funds.
346
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
347
- * @returns Returns void if successful. Throws error if any.
348
- *
349
- *
350
- * **Code example**
307
+ * @param escrowAddress - Address of the escrow to fund.
308
+ * @param amount - Amount to be added as funds.
309
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
310
+ * @returns -
311
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
312
+ * @throws ErrorAmountMustBeGreaterThanZero If the amount is less than or equal to zero
313
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
351
314
  *
315
+ * @example
352
316
  * ```ts
353
- * import { ethers, Wallet, providers } from 'ethers';
354
- * import { EscrowClient } from '@human-protocol/sdk';
355
- *
356
- * const rpcUrl = 'YOUR_RPC_URL';
357
- * const privateKey = 'YOUR_PRIVATE_KEY';
317
+ * import { ethers } from 'ethers';
358
318
  *
359
- * const provider = new providers.JsonRpcProvider(rpcUrl);
360
- * const signer = new Wallet(privateKey, provider);
361
- * const escrowClient = await EscrowClient.build(signer);
362
- *
363
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
319
+ * const amount = ethers.parseUnits('5', 'ether');
364
320
  * await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
365
321
  * ```
366
322
  */
@@ -424,27 +380,15 @@ class EscrowClient extends base_1.BaseEthersClient {
424
380
  }
425
381
  /**
426
382
  * This function sets the status of an escrow to completed.
383
+ * @remarks Only Recording Oracle or admin can call it.
384
+ * @param escrowAddress - Address of the escrow.
385
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
386
+ * @returns -
387
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid.
388
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory.
427
389
  *
428
- * @param {string} escrowAddress Address of the escrow.
429
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
430
- * @returns Returns void if successful. Throws error if any.
431
- *
432
- *
433
- * **Code example**
434
- *
435
- * > Only Recording Oracle or admin can call it.
436
- *
390
+ * @example
437
391
  * ```ts
438
- * import { Wallet, providers } from 'ethers';
439
- * import { EscrowClient } from '@human-protocol/sdk';
440
- *
441
- * const rpcUrl = 'YOUR_RPC_URL';
442
- * const privateKey = 'YOUR_PRIVATE_KEY';
443
- *
444
- * const provider = new providers.JsonRpcProvider(rpcUrl);
445
- * const signer = new Wallet(privateKey, provider);
446
- * const escrowClient = await EscrowClient.build(signer);
447
- *
448
392
  * await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
449
393
  * ```
450
394
  */
@@ -487,26 +431,16 @@ class EscrowClient extends base_1.BaseEthersClient {
487
431
  }
488
432
  /**
489
433
  * This function cancels the specified escrow and sends the balance to the canceler.
434
+ * @remarks Only Job Launcher or admin can call it.
435
+ * @param escrowAddress - Address of the escrow to cancel.
436
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
437
+ * @returns -
438
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
439
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
490
440
  *
491
- * @param {string} escrowAddress Address of the escrow to cancel.
492
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
493
- *
494
- *
495
- * **Code example**
496
- *
497
- * > Only Job Launcher or admin can call it.
441
+ * @example
498
442
  *
499
443
  * ```ts
500
- * import { ethers, Wallet, providers } from 'ethers';
501
- * import { EscrowClient } from '@human-protocol/sdk';
502
- *
503
- * const rpcUrl = 'YOUR_RPC_URL';
504
- * const privateKey = 'YOUR_PRIVATE_KEY';
505
- *
506
- * const provider = new providers.JsonRpcProvider(rpcUrl);
507
- * const signer = new Wallet(privateKey, provider);
508
- * const escrowClient = await EscrowClient.build(signer);
509
- *
510
444
  * await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
511
445
  * ```
512
446
  */
@@ -527,26 +461,16 @@ class EscrowClient extends base_1.BaseEthersClient {
527
461
  }
528
462
  /**
529
463
  * This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
464
+ * @remarks Only Job Launcher or admin can call it.
465
+ * @param escrowAddress - Address of the escrow to request cancellation.
466
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
467
+ * @returns -
468
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
469
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
530
470
  *
531
- * @param {string} escrowAddress Address of the escrow to request cancellation.
532
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
533
- * @returns Returns void if successful. Throws error if any.
534
- *
535
- * **Code example**
536
- *
537
- * > Only Job Launcher or admin can call it.
471
+ * @example
538
472
  *
539
473
  * ```ts
540
- * import { Wallet, providers } from 'ethers';
541
- * import { EscrowClient } from '@human-protocol/sdk';
542
- *
543
- * const rpcUrl = 'YOUR_RPC_URL';
544
- * const privateKey = 'YOUR_PRIVATE_KEY';
545
- *
546
- * const provider = new providers.JsonRpcProvider(rpcUrl);
547
- * const signer = new Wallet(privateKey, provider);
548
- * const escrowClient = await EscrowClient.build(signer);
549
- *
550
474
  * await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
551
475
  * ```
552
476
  */
@@ -567,32 +491,25 @@ class EscrowClient extends base_1.BaseEthersClient {
567
491
  }
568
492
  /**
569
493
  * This function withdraws additional tokens in the escrow to the canceler.
494
+ * @remarks Only Job Launcher or admin can call it.
570
495
  *
571
- * @param {string} escrowAddress Address of the escrow to withdraw.
572
- * @param {string} tokenAddress Address of the token to withdraw.
573
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
574
- * @returns {IEscrowWithdraw} Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.
575
- *
496
+ * @param escrowAddress - Address of the escrow to withdraw.
497
+ * @param tokenAddress - Address of the token to withdraw.
498
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
499
+ * @returns Returns the escrow withdrawal data including transaction hash and withdrawal amount.
500
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
501
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
502
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
503
+ * @throws ErrorTransferEventNotFoundInTransactionLogs If the Transfer event is not found in transaction logs
576
504
  *
577
- * **Code example**
578
- *
579
- * > Only Job Launcher or admin can call it.
505
+ * @example
580
506
  *
581
507
  * ```ts
582
- * import { ethers, Wallet, providers } from 'ethers';
583
- * import { EscrowClient } from '@human-protocol/sdk';
584
- *
585
- * const rpcUrl = 'YOUR_RPC_URL';
586
- * const privateKey = 'YOUR_PRIVATE_KEY';
587
- *
588
- * const provider = new providers.JsonRpcProvider(rpcUrl);
589
- * const signer = new Wallet(privateKey, provider);
590
- * const escrowClient = await EscrowClient.build(signer);
591
- *
592
- * await escrowClient.withdraw(
508
+ * const withdrawData = await escrowClient.withdraw(
593
509
  * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
594
510
  * '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
595
511
  * );
512
+ * console.log('Withdrawn amount:', withdrawData.withdrawnAmount);
596
513
  * ```
597
514
  */
598
515
  async withdraw(escrowAddress, tokenAddress, txOptions = {}) {
@@ -639,43 +556,54 @@ class EscrowClient extends base_1.BaseEthersClient {
639
556
  }
640
557
  /**
641
558
  * Creates a prepared transaction for bulk payout without immediately sending it.
642
- * @param {string} escrowAddress Escrow address to payout.
643
- * @param {string[]} recipients Array of recipient addresses.
644
- * @param {bigint[]} amounts Array of amounts the recipients will receive.
645
- * @param {string} finalResultsUrl Final results file URL.
646
- * @param {string} finalResultsHash Final results file hash.
647
- * @param {string} payoutId Payout ID to identify the payout.
648
- * @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
649
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
650
- * @returns Returns object with raw transaction and signed transaction hash
651
- *
652
- * **Code example**
559
+ * @remarks Only Reputation Oracle or admin can call it.
560
+ *
561
+ * @param escrowAddress - Escrow address to payout.
562
+ * @param recipients - Array of recipient addresses.
563
+ * @param amounts - Array of amounts the recipients will receive.
564
+ * @param finalResultsUrl - Final results file URL.
565
+ * @param finalResultsHash - Final results file hash.
566
+ * @param payoutId - Payout ID to identify the payout.
567
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
568
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
569
+ * @returns Returns object with raw transaction and nonce
570
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
571
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
572
+ * @throws ErrorTooManyRecipients If there are too many recipients
573
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
574
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
575
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
576
+ * @throws ErrorInvalidUrl If the final results URL is invalid
577
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
578
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
579
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
653
580
  *
654
- * > Only Reputation Oracle or admin can call it.
581
+ * @example
655
582
  *
656
583
  * ```ts
657
- * import { ethers, Wallet, providers } from 'ethers';
658
- * import { EscrowClient } from '@human-protocol/sdk';
659
- *
660
- * const rpcUrl = 'YOUR_RPC_URL';
661
- * const privateKey = 'YOUR_PRIVATE_KEY'
584
+ * import { ethers } from 'ethers';
585
+ * import { v4 as uuidV4 } from 'uuid';
662
586
  *
663
- * const provider = new providers.JsonRpcProvider(rpcUrl);
664
- * const signer = new Wallet(privateKey, provider);
665
- * const escrowClient = await EscrowClient.build(signer);
666
- *
667
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
668
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
587
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
588
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
669
589
  * const resultsUrl = 'http://localhost/results.json';
670
590
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
671
- * const payoutId = '372f6916-fe34-4711-b6e3-274f682047de';
672
- *
673
- * const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
591
+ * const payoutId = uuidV4();
592
+ *
593
+ * const rawTransaction = await escrowClient.createBulkPayoutTransaction(
594
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
595
+ * recipients,
596
+ * amounts,
597
+ * resultsUrl,
598
+ * resultsHash,
599
+ * payoutId
600
+ * );
674
601
  * console.log('Raw transaction:', rawTransaction);
675
602
  *
676
603
  * const signedTransaction = await signer.signTransaction(rawTransaction);
677
604
  * console.log('Tx hash:', ethers.keccak256(signedTransaction));
678
- * (await signer.sendTransaction(rawTransaction)).wait();
605
+ * await signer.sendTransaction(rawTransaction);
606
+ * ```
679
607
  */
680
608
  async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete = false, txOptions = {}) {
681
609
  await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
@@ -757,21 +685,15 @@ class EscrowClient extends base_1.BaseEthersClient {
757
685
  /**
758
686
  * This function returns the balance for a specified escrow address.
759
687
  *
760
- * @param {string} escrowAddress Address of the escrow.
761
- * @returns {Promise<bigint>} Balance of the escrow in the token used to fund it.
762
- *
763
- * **Code example**
688
+ * @param escrowAddress - Address of the escrow.
689
+ * @returns Balance of the escrow in the token used to fund it.
690
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
691
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
764
692
  *
693
+ * @example
765
694
  * ```ts
766
- * import { providers } from 'ethers';
767
- * import { EscrowClient } from '@human-protocol/sdk';
768
- *
769
- * const rpcUrl = 'YOUR_RPC_URL';
770
- *
771
- * const provider = new providers.JsonRpcProvider(rpcUrl);
772
- * const escrowClient = await EscrowClient.build(provider);
773
- *
774
695
  * const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
696
+ * console.log('Balance:', balance);
775
697
  * ```
776
698
  */
777
699
  async getBalance(escrowAddress) {
@@ -798,21 +720,15 @@ class EscrowClient extends base_1.BaseEthersClient {
798
720
  /**
799
721
  * This function returns the reserved funds for a specified escrow address.
800
722
  *
801
- * @param {string} escrowAddress Address of the escrow.
802
- * @returns {Promise<bigint>} Reserved funds of the escrow in the token used to fund it.
803
- *
804
- * **Code example**
723
+ * @param escrowAddress - Address of the escrow.
724
+ * @returns Reserved funds of the escrow in the token used to fund it.
725
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
726
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
805
727
  *
728
+ * @example
806
729
  * ```ts
807
- * import { providers } from 'ethers';
808
- * import { EscrowClient } from '@human-protocol/sdk';
809
- *
810
- * const rpcUrl = 'YOUR_RPC_URL';
811
- *
812
- * const provider = new providers.JsonRpcProvider(rpcUrl);
813
- * const escrowClient = await EscrowClient.build(provider);
814
- *
815
730
  * const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
731
+ * console.log('Reserved funds:', reservedFunds);
816
732
  * ```
817
733
  */
818
734
  async getReservedFunds(escrowAddress) {
@@ -833,21 +749,15 @@ class EscrowClient extends base_1.BaseEthersClient {
833
749
  /**
834
750
  * This function returns the manifest file hash.
835
751
  *
836
- * @param {string} escrowAddress Address of the escrow.
837
- * @returns {Promise<string>} Hash of the manifest file content.
838
- *
839
- * **Code example**
752
+ * @param escrowAddress - Address of the escrow.
753
+ * @returns Hash of the manifest file content.
754
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
755
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
840
756
  *
757
+ * @example
841
758
  * ```ts
842
- * import { providers } from 'ethers';
843
- * import { EscrowClient } from '@human-protocol/sdk';
844
- *
845
- * const rpcUrl = 'YOUR_RPC_URL';
846
- *
847
- * const provider = new providers.JsonRpcProvider(rpcUrl);
848
- * const escrowClient = await EscrowClient.build(provider);
849
- *
850
759
  * const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
760
+ * console.log('Manifest hash:', manifestHash);
851
761
  * ```
852
762
  */
853
763
  async getManifestHash(escrowAddress) {
@@ -868,21 +778,15 @@ class EscrowClient extends base_1.BaseEthersClient {
868
778
  /**
869
779
  * This function returns the manifest. Could be a URL or a JSON string.
870
780
  *
871
- * @param {string} escrowAddress Address of the escrow.
872
- * @returns {Promise<string>} Url of the manifest.
873
- *
874
- * **Code example**
781
+ * @param escrowAddress - Address of the escrow.
782
+ * @returns Manifest URL or JSON string.
783
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
784
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
875
785
  *
786
+ * @example
876
787
  * ```ts
877
- * import { providers } from 'ethers';
878
- * import { EscrowClient } from '@human-protocol/sdk';
879
- *
880
- * const rpcUrl = 'YOUR_RPC_URL';
881
- *
882
- * const provider = new providers.JsonRpcProvider(rpcUrl);
883
- * const escrowClient = await EscrowClient.build(provider);
884
- *
885
788
  * const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
789
+ * console.log('Manifest:', manifest);
886
790
  * ```
887
791
  */
888
792
  async getManifest(escrowAddress) {
@@ -903,21 +807,15 @@ class EscrowClient extends base_1.BaseEthersClient {
903
807
  /**
904
808
  * This function returns the results file URL.
905
809
  *
906
- * @param {string} escrowAddress Address of the escrow.
907
- * @returns {Promise<string>} Results file url.
908
- *
909
- * **Code example**
810
+ * @param escrowAddress - Address of the escrow.
811
+ * @returns Results file URL.
812
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
813
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
910
814
  *
815
+ * @example
911
816
  * ```ts
912
- * import { providers } from 'ethers';
913
- * import { EscrowClient } from '@human-protocol/sdk';
914
- *
915
- * const rpcUrl = 'YOUR_RPC_URL';
916
- *
917
- * const provider = new providers.JsonRpcProvider(rpcUrl);
918
- * const escrowClient = await EscrowClient.build(provider);
919
- *
920
817
  * const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
818
+ * console.log('Results URL:', resultsUrl);
921
819
  * ```
922
820
  */
923
821
  async getResultsUrl(escrowAddress) {
@@ -938,21 +836,15 @@ class EscrowClient extends base_1.BaseEthersClient {
938
836
  /**
939
837
  * This function returns the intermediate results file URL.
940
838
  *
941
- * @param {string} escrowAddress Address of the escrow.
942
- * @returns {Promise<string>} Url of the file that store results from Recording Oracle.
943
- *
944
- * **Code example**
839
+ * @param escrowAddress - Address of the escrow.
840
+ * @returns URL of the file that stores results from Recording Oracle.
841
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
842
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
945
843
  *
844
+ * @example
946
845
  * ```ts
947
- * import { providers } from 'ethers';
948
- * import { EscrowClient } from '@human-protocol/sdk';
949
- *
950
- * const rpcUrl = 'YOUR_RPC_URL';
951
- *
952
- * const provider = new providers.JsonRpcProvider(rpcUrl);
953
- * const escrowClient = await EscrowClient.build(provider);
954
- *
955
846
  * const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
847
+ * console.log('Intermediate results URL:', intermediateResultsUrl);
956
848
  * ```
957
849
  */
958
850
  async getIntermediateResultsUrl(escrowAddress) {
@@ -973,21 +865,15 @@ class EscrowClient extends base_1.BaseEthersClient {
973
865
  /**
974
866
  * This function returns the intermediate results hash.
975
867
  *
976
- * @param {string} escrowAddress Address of the escrow.
977
- * @returns {Promise<string>} Hash of the intermediate results file content.
978
- *
979
- * **Code example**
868
+ * @param escrowAddress - Address of the escrow.
869
+ * @returns Hash of the intermediate results file content.
870
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
871
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
980
872
  *
873
+ * @example
981
874
  * ```ts
982
- * import { providers } from 'ethers';
983
- * import { EscrowClient } from '@human-protocol/sdk';
984
- *
985
- * const rpcUrl = 'YOUR_RPC_URL';
986
- *
987
- * const provider = new providers.JsonRpcProvider(rpcUrl);
988
- * const escrowClient = await EscrowClient.build(provider);
989
- *
990
875
  * const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
876
+ * console.log('Intermediate results hash:', intermediateResultsHash);
991
877
  * ```
992
878
  */
993
879
  async getIntermediateResultsHash(escrowAddress) {
@@ -1008,21 +894,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1008
894
  /**
1009
895
  * This function returns the token address used for funding the escrow.
1010
896
  *
1011
- * @param {string} escrowAddress Address of the escrow.
1012
- * @returns {Promise<string>} Address of the token used to fund the escrow.
1013
- *
1014
- * **Code example**
897
+ * @param escrowAddress - Address of the escrow.
898
+ * @returns Address of the token used to fund the escrow.
899
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
900
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1015
901
  *
902
+ * @example
1016
903
  * ```ts
1017
- * import { providers } from 'ethers';
1018
- * import { EscrowClient } from '@human-protocol/sdk';
1019
- *
1020
- * const rpcUrl = 'YOUR_RPC_URL';
1021
- *
1022
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1023
- * const escrowClient = await EscrowClient.build(provider);
1024
- *
1025
904
  * const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
905
+ * console.log('Token address:', tokenAddress);
1026
906
  * ```
1027
907
  */
1028
908
  async getTokenAddress(escrowAddress) {
@@ -1043,21 +923,17 @@ class EscrowClient extends base_1.BaseEthersClient {
1043
923
  /**
1044
924
  * This function returns the current status of the escrow.
1045
925
  *
1046
- * @param {string} escrowAddress Address of the escrow.
1047
- * @returns {Promise<EscrowStatus>} Current status of the escrow.
1048
- *
1049
- * **Code example**
926
+ * @param escrowAddress - Address of the escrow.
927
+ * @returns Current status of the escrow.
928
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
929
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1050
930
  *
931
+ * @example
1051
932
  * ```ts
1052
- * import { providers } from 'ethers';
1053
- * import { EscrowClient } from '@human-protocol/sdk';
1054
- *
1055
- * const rpcUrl = 'YOUR_RPC_URL';
1056
- *
1057
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1058
- * const escrowClient = await EscrowClient.build(provider);
933
+ * import { EscrowStatus } from '@human-protocol/sdk';
1059
934
  *
1060
935
  * const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
936
+ * console.log('Status:', EscrowStatus[status]);
1061
937
  * ```
1062
938
  */
1063
939
  async getStatus(escrowAddress) {
@@ -1078,21 +954,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1078
954
  /**
1079
955
  * This function returns the recording oracle address for a given escrow.
1080
956
  *
1081
- * @param {string} escrowAddress Address of the escrow.
1082
- * @returns {Promise<string>} Address of the Recording Oracle.
1083
- *
1084
- * **Code example**
957
+ * @param escrowAddress - Address of the escrow.
958
+ * @returns Address of the Recording Oracle.
959
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
960
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1085
961
  *
962
+ * @example
1086
963
  * ```ts
1087
- * import { providers } from 'ethers';
1088
- * import { EscrowClient } from '@human-protocol/sdk';
1089
- *
1090
- * const rpcUrl = 'YOUR_RPC_URL';
1091
- *
1092
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1093
- * const escrowClient = await EscrowClient.build(provider);
1094
- *
1095
964
  * const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
965
+ * console.log('Recording Oracle address:', oracleAddress);
1096
966
  * ```
1097
967
  */
1098
968
  async getRecordingOracleAddress(escrowAddress) {
@@ -1113,21 +983,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1113
983
  /**
1114
984
  * This function returns the job launcher address for a given escrow.
1115
985
  *
1116
- * @param {string} escrowAddress Address of the escrow.
1117
- * @returns {Promise<string>} Address of the Job Launcher.
1118
- *
1119
- * **Code example**
986
+ * @param escrowAddress - Address of the escrow.
987
+ * @returns Address of the Job Launcher.
988
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
989
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1120
990
  *
991
+ * @example
1121
992
  * ```ts
1122
- * import { providers } from 'ethers';
1123
- * import { EscrowClient } from '@human-protocol/sdk';
1124
- *
1125
- * const rpcUrl = 'YOUR_RPC_URL';
1126
- *
1127
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1128
- * const escrowClient = await EscrowClient.build(provider);
1129
- *
1130
993
  * const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
994
+ * console.log('Job Launcher address:', jobLauncherAddress);
1131
995
  * ```
1132
996
  */
1133
997
  async getJobLauncherAddress(escrowAddress) {
@@ -1148,21 +1012,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1148
1012
  /**
1149
1013
  * This function returns the reputation oracle address for a given escrow.
1150
1014
  *
1151
- * @param {string} escrowAddress Address of the escrow.
1152
- * @returns {Promise<string>} Address of the Reputation Oracle.
1153
- *
1154
- * **Code example**
1015
+ * @param escrowAddress - Address of the escrow.
1016
+ * @returns Address of the Reputation Oracle.
1017
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1018
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1155
1019
  *
1020
+ * @example
1156
1021
  * ```ts
1157
- * import { providers } from 'ethers';
1158
- * import { EscrowClient } from '@human-protocol/sdk';
1159
- *
1160
- * const rpcUrl = 'YOUR_RPC_URL';
1161
- *
1162
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1163
- * const escrowClient = await EscrowClient.build(provider);
1164
- *
1165
1022
  * const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1023
+ * console.log('Reputation Oracle address:', oracleAddress);
1166
1024
  * ```
1167
1025
  */
1168
1026
  async getReputationOracleAddress(escrowAddress) {
@@ -1183,21 +1041,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1183
1041
  /**
1184
1042
  * This function returns the exchange oracle address for a given escrow.
1185
1043
  *
1186
- * @param {string} escrowAddress Address of the escrow.
1187
- * @returns {Promise<string>} Address of the Exchange Oracle.
1188
- *
1189
- * **Code example**
1044
+ * @param escrowAddress - Address of the escrow.
1045
+ * @returns Address of the Exchange Oracle.
1046
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1047
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1190
1048
  *
1049
+ * @example
1191
1050
  * ```ts
1192
- * import { providers } from 'ethers';
1193
- * import { EscrowClient } from '@human-protocol/sdk';
1194
- *
1195
- * const rpcUrl = 'YOUR_RPC_URL';
1196
- *
1197
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1198
- * const escrowClient = await EscrowClient.build(provider);
1199
- *
1200
1051
  * const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1052
+ * console.log('Exchange Oracle address:', oracleAddress);
1201
1053
  * ```
1202
1054
  */
1203
1055
  async getExchangeOracleAddress(escrowAddress) {
@@ -1218,21 +1070,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1218
1070
  /**
1219
1071
  * This function returns the escrow factory address for a given escrow.
1220
1072
  *
1221
- * @param {string} escrowAddress Address of the escrow.
1222
- * @returns {Promise<string>} Address of the escrow factory.
1223
- *
1224
- * **Code example**
1073
+ * @param escrowAddress - Address of the escrow.
1074
+ * @returns Address of the escrow factory.
1075
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1076
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1225
1077
  *
1078
+ * @example
1226
1079
  * ```ts
1227
- * import { providers } from 'ethers';
1228
- * import { EscrowClient } from '@human-protocol/sdk';
1229
- *
1230
- * const rpcUrl = 'YOUR_RPC_URL';
1231
- *
1232
- * const provider = new providers.JsonRpcProvider(rpcUrl);
1233
- * const escrowClient = await EscrowClient.build(provider);
1234
- *
1235
1080
  * const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1081
+ * console.log('Factory address:', factoryAddress);
1236
1082
  * ```
1237
1083
  */
1238
1084
  async getFactoryAddress(escrowAddress) {
@@ -1319,138 +1165,40 @@ __decorate([
1319
1165
  __metadata("design:returntype", Promise)
1320
1166
  ], EscrowClient.prototype, "createBulkPayoutTransaction", null);
1321
1167
  /**
1322
- * ## Introduction
1323
- *
1324
- * Utility class for escrow-related operations.
1325
- *
1326
- * ## Installation
1327
- *
1328
- * ### npm
1329
- * ```bash
1330
- * npm install @human-protocol/sdk
1331
- * ```
1332
- *
1333
- * ### yarn
1334
- * ```bash
1335
- * yarn install @human-protocol/sdk
1336
- * ```
1337
- *
1338
- * ## Code example
1339
- *
1340
- * ### Signer
1341
- *
1342
- * **Using private key(backend)**
1168
+ * Utility helpers for escrow-related queries.
1343
1169
  *
1170
+ * @example
1344
1171
  * ```ts
1345
1172
  * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1346
1173
  *
1347
- * const escrowAddresses = new EscrowUtils.getEscrows({
1174
+ * const escrows = await EscrowUtils.getEscrows({
1348
1175
  * chainId: ChainId.POLYGON_AMOY
1349
1176
  * });
1177
+ * console.log('Escrows:', escrows);
1350
1178
  * ```
1351
1179
  */
1352
1180
  class EscrowUtils {
1353
1181
  /**
1354
1182
  * This function returns an array of escrows based on the specified filter parameters.
1355
1183
  *
1184
+ * @param filter - Filter parameters.
1185
+ * @param options - Optional configuration for subgraph requests.
1186
+ * @returns List of escrows that match the filter.
1187
+ * @throws ErrorInvalidAddress If any filter address is invalid
1188
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1356
1189
  *
1357
- * **Input parameters**
1358
- *
1359
- * ```ts
1360
- * interface IEscrowsFilter {
1361
- * chainId: ChainId;
1362
- * launcher?: string;
1363
- * reputationOracle?: string;
1364
- * recordingOracle?: string;
1365
- * exchangeOracle?: string;
1366
- * jobRequesterId?: string;
1367
- * status?: EscrowStatus;
1368
- * from?: Date;
1369
- * to?: Date;
1370
- * first?: number;
1371
- * skip?: number;
1372
- * orderDirection?: OrderDirection;
1373
- * }
1374
- * ```
1375
- *
1376
- * ```ts
1377
- * enum ChainId {
1378
- * ALL = -1,
1379
- * MAINNET = 1,
1380
- * SEPOLIA = 11155111,
1381
- * BSC_MAINNET = 56,
1382
- * BSC_TESTNET = 97,
1383
- * POLYGON = 137,
1384
- * POLYGON_AMOY=80002,
1385
- * LOCALHOST = 1338,
1386
- * }
1387
- * ```
1388
- *
1389
- * ```ts
1390
- * enum OrderDirection {
1391
- * ASC = 'asc',
1392
- * DESC = 'desc',
1393
- * }
1394
- * ```
1395
- *
1396
- * ```ts
1397
- * enum EscrowStatus {
1398
- * Launched,
1399
- * Pending,
1400
- * Partial,
1401
- * Paid,
1402
- * Complete,
1403
- * Cancelled,
1404
- * }
1405
- * ```
1406
- *
1407
- * ```ts
1408
- * interface IEscrow {
1409
- * id: string;
1410
- * address: string;
1411
- * amountPaid: bigint;
1412
- * balance: bigint;
1413
- * count: bigint;
1414
- * factoryAddress: string;
1415
- * finalResultsUrl: string | null;
1416
- * finalResultsHash: string | null;
1417
- * intermediateResultsUrl: string | null;
1418
- * intermediateResultsHash: string | null;
1419
- * launcher: string;
1420
- * jobRequesterId: string | null;
1421
- * manifestHash: string | null;
1422
- * manifest: string | null;
1423
- * recordingOracle: string | null;
1424
- * reputationOracle: string | null;
1425
- * exchangeOracle: string | null;
1426
- * recordingOracleFee: number | null;
1427
- * reputationOracleFee: number | null;
1428
- * exchangeOracleFee: number | null;
1429
- * status: string;
1430
- * token: string;
1431
- * totalFundedAmount: bigint;
1432
- * createdAt: number;
1433
- * chainId: number;
1434
- * };
1435
- * ```
1436
- *
1437
- *
1438
- * @param {IEscrowsFilter} filter Filter parameters.
1439
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1440
- * @returns {IEscrow[]} List of escrows that match the filter.
1441
- *
1442
- * **Code example**
1443
- *
1190
+ * @example
1444
1191
  * ```ts
1445
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1192
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1446
1193
  *
1447
- * const filters: IEscrowsFilter = {
1194
+ * const filters = {
1448
1195
  * status: EscrowStatus.Pending,
1449
1196
  * from: new Date(2023, 4, 8),
1450
1197
  * to: new Date(2023, 5, 8),
1451
1198
  * chainId: ChainId.POLYGON_AMOY
1452
1199
  * };
1453
1200
  * const escrows = await EscrowUtils.getEscrows(filters);
1201
+ * console.log('Found escrows:', escrows.length);
1454
1202
  * ```
1455
1203
  */
1456
1204
  static async getEscrows(filter, options) {
@@ -1498,63 +1246,24 @@ class EscrowUtils {
1498
1246
  *
1499
1247
  * > This uses Subgraph
1500
1248
  *
1501
- * **Input parameters**
1502
- *
1503
- * ```ts
1504
- * enum ChainId {
1505
- * ALL = -1,
1506
- * MAINNET = 1,
1507
- * SEPOLIA = 11155111,
1508
- * BSC_MAINNET = 56,
1509
- * BSC_TESTNET = 97,
1510
- * POLYGON = 137,
1511
- * POLYGON_AMOY = 80002,
1512
- * LOCALHOST = 1338,
1513
- * }
1514
- * ```
1515
- *
1516
- * ```ts
1517
- * interface IEscrow {
1518
- * id: string;
1519
- * address: string;
1520
- * amountPaid: bigint;
1521
- * balance: bigint;
1522
- * count: bigint;
1523
- * factoryAddress: string;
1524
- * finalResultsUrl: string | null;
1525
- * finalResultsHash: string | null;
1526
- * intermediateResultsUrl: string | null;
1527
- * intermediateResultsHash: string | null;
1528
- * launcher: string;
1529
- * jobRequesterId: string | null;
1530
- * manifestHash: string | null;
1531
- * manifest: string | null;
1532
- * recordingOracle: string | null;
1533
- * reputationOracle: string | null;
1534
- * exchangeOracle: string | null;
1535
- * recordingOracleFee: number | null;
1536
- * reputationOracleFee: number | null;
1537
- * exchangeOracleFee: number | null;
1538
- * status: string;
1539
- * token: string;
1540
- * totalFundedAmount: bigint;
1541
- * createdAt: number;
1542
- * chainId: number;
1543
- * };
1544
- * ```
1545
- *
1546
- *
1547
- * @param {ChainId} chainId Network in which the escrow has been deployed
1548
- * @param {string} escrowAddress Address of the escrow
1549
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1550
- * @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
1551
- *
1552
- * **Code example**
1249
+ * @param chainId - Network in which the escrow has been deployed
1250
+ * @param escrowAddress - Address of the escrow
1251
+ * @param options - Optional configuration for subgraph requests.
1252
+ * @returns Escrow data or null if not found.
1253
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1254
+ * @throws ErrorInvalidAddress If the escrow address is invalid
1553
1255
  *
1256
+ * @example
1554
1257
  * ```ts
1555
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1258
+ * import { ChainId } from '@human-protocol/sdk';
1556
1259
  *
1557
- * const escrow = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
1260
+ * const escrow = await EscrowUtils.getEscrow(
1261
+ * ChainId.POLYGON_AMOY,
1262
+ * "0x1234567890123456789012345678901234567890"
1263
+ * );
1264
+ * if (escrow) {
1265
+ * console.log('Escrow status:', escrow.status);
1266
+ * }
1558
1267
  * ```
1559
1268
  */
1560
1269
  static async getEscrow(chainId, escrowAddress, options) {
@@ -1575,56 +1284,25 @@ class EscrowUtils {
1575
1284
  *
1576
1285
  * > This uses Subgraph
1577
1286
  *
1578
- * **Input parameters**
1579
- *
1580
- * ```ts
1581
- * enum ChainId {
1582
- * ALL = -1,
1583
- * MAINNET = 1,
1584
- * SEPOLIA = 11155111,
1585
- * BSC_MAINNET = 56,
1586
- * BSC_TESTNET = 97,
1587
- * POLYGON = 137,
1588
- * POLYGON_AMOY = 80002,
1589
- * LOCALHOST = 1338,
1590
- * }
1591
- * ```
1592
- *
1593
- * ```ts
1594
- * enum OrderDirection {
1595
- * ASC = 'asc',
1596
- * DESC = 'desc',
1597
- * }
1598
- * ```
1287
+ * @param filter - Filter parameters.
1288
+ * @param options - Optional configuration for subgraph requests.
1289
+ * @returns Array of status events with their corresponding statuses.
1290
+ * @throws ErrorInvalidAddress If the launcher address is invalid
1291
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1599
1292
  *
1293
+ * @example
1600
1294
  * ```ts
1601
- * type Status = {
1602
- * escrowAddress: string;
1603
- * timestamp: string;
1604
- * status: string;
1605
- * };
1606
- * ```
1607
- *
1608
- * @param {IStatusEventFilter} filter Filter parameters.
1609
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1610
- * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
1611
- *
1612
- * **Code example**
1295
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1613
1296
  *
1614
- * ```ts
1615
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1616
- *
1617
- * (async () => {
1618
- * const fromDate = new Date('2023-01-01');
1619
- * const toDate = new Date('2023-12-31');
1620
- * const statusEvents = await EscrowUtils.getStatusEvents({
1621
- * chainId: ChainId.POLYGON,
1622
- * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1623
- * from: fromDate,
1624
- * to: toDate
1625
- * });
1626
- * console.log(statusEvents);
1627
- * })();
1297
+ * const fromDate = new Date('2023-01-01');
1298
+ * const toDate = new Date('2023-12-31');
1299
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1300
+ * chainId: ChainId.POLYGON,
1301
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1302
+ * from: fromDate,
1303
+ * to: toDate
1304
+ * });
1305
+ * console.log('Status events:', statusEvents.length);
1628
1306
  * ```
1629
1307
  */
1630
1308
  static async getStatusEvents(filter, options) {
@@ -1670,17 +1348,15 @@ class EscrowUtils {
1670
1348
  *
1671
1349
  * > This uses Subgraph
1672
1350
  *
1673
- * **Input parameters**
1674
- * Fetch payouts from the subgraph.
1675
- *
1676
- * @param {IPayoutFilter} filter Filter parameters.
1677
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1678
- * @returns {Promise<IPayout[]>} List of payouts matching the filters.
1679
- *
1680
- * **Code example**
1351
+ * @param filter - Filter parameters.
1352
+ * @param options - Optional configuration for subgraph requests.
1353
+ * @returns List of payouts matching the filters.
1354
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1355
+ * @throws ErrorInvalidAddress If any filter address is invalid
1681
1356
  *
1357
+ * @example
1682
1358
  * ```ts
1683
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1359
+ * import { ChainId } from '@human-protocol/sdk';
1684
1360
  *
1685
1361
  * const payouts = await EscrowUtils.getPayouts({
1686
1362
  * chainId: ChainId.POLYGON,
@@ -1689,7 +1365,7 @@ class EscrowUtils {
1689
1365
  * from: new Date('2023-01-01'),
1690
1366
  * to: new Date('2023-12-31')
1691
1367
  * });
1692
- * console.log(payouts);
1368
+ * console.log('Payouts:', payouts.length);
1693
1369
  * ```
1694
1370
  */
1695
1371
  static async getPayouts(filter, options) {
@@ -1731,48 +1407,22 @@ class EscrowUtils {
1731
1407
  *
1732
1408
  * > This uses Subgraph
1733
1409
  *
1734
- * **Input parameters**
1735
- *
1736
- * ```ts
1737
- * enum ChainId {
1738
- * ALL = -1,
1739
- * MAINNET = 1,
1740
- * SEPOLIA = 11155111,
1741
- * BSC_MAINNET = 56,
1742
- * BSC_TESTNET = 97,
1743
- * POLYGON = 137,
1744
- * POLYGON_AMOY = 80002,
1745
- * LOCALHOST = 1338,
1746
- * }
1747
- * ```
1748
- *
1749
- * ```ts
1750
- * interface ICancellationRefund {
1751
- * id: string;
1752
- * escrowAddress: string;
1753
- * receiver: string;
1754
- * amount: bigint;
1755
- * block: number;
1756
- * timestamp: number;
1757
- * txHash: string;
1758
- * };
1759
- * ```
1760
- *
1761
- *
1762
- * @param {Object} filter Filter parameters.
1763
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1764
- * @returns {Promise<ICancellationRefund[]>} List of cancellation refunds matching the filters.
1765
- *
1766
- * **Code example**
1410
+ * @param filter - Filter parameters.
1411
+ * @param options - Optional configuration for subgraph requests.
1412
+ * @returns List of cancellation refunds matching the filters.
1413
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1414
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1415
+ * @throws ErrorInvalidAddress If the receiver address is invalid
1767
1416
  *
1417
+ * @example
1768
1418
  * ```ts
1769
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1419
+ * import { ChainId } from '@human-protocol/sdk';
1770
1420
  *
1771
1421
  * const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
1772
1422
  * chainId: ChainId.POLYGON_AMOY,
1773
1423
  * escrowAddress: '0x1234567890123456789012345678901234567890',
1774
1424
  * });
1775
- * console.log(cancellationRefunds);
1425
+ * console.log('Cancellation refunds:', cancellationRefunds.length);
1776
1426
  * ```
1777
1427
  */
1778
1428
  static async getCancellationRefunds(filter, options) {
@@ -1815,45 +1465,25 @@ class EscrowUtils {
1815
1465
  *
1816
1466
  * > This uses Subgraph
1817
1467
  *
1818
- * **Input parameters**
1819
- *
1820
- * ```ts
1821
- * enum ChainId {
1822
- * ALL = -1,
1823
- * MAINNET = 1,
1824
- * SEPOLIA = 11155111,
1825
- * BSC_MAINNET = 56,
1826
- * BSC_TESTNET = 97,
1827
- * POLYGON = 137,
1828
- * POLYGON_AMOY = 80002,
1829
- * LOCALHOST = 1338,
1830
- * }
1831
- * ```
1468
+ * @param chainId - Network in which the escrow has been deployed
1469
+ * @param escrowAddress - Address of the escrow
1470
+ * @param options - Optional configuration for subgraph requests.
1471
+ * @returns Cancellation refund data or null if not found.
1472
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1473
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1832
1474
  *
1475
+ * @example
1833
1476
  * ```ts
1834
- * interface ICancellationRefund {
1835
- * id: string;
1836
- * escrowAddress: string;
1837
- * receiver: string;
1838
- * amount: bigint;
1839
- * block: number;
1840
- * timestamp: number;
1841
- * txHash: string;
1842
- * };
1843
- * ```
1844
- *
1477
+ * import { ChainId } from '@human-protocol/sdk';
1845
1478
  *
1846
- * @param {ChainId} chainId Network in which the escrow has been deployed
1847
- * @param {string} escrowAddress Address of the escrow
1848
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1849
- * @returns {Promise<ICancellationRefund>} Cancellation refund data
1850
1479
  *
1851
- * **Code example**
1852
- *
1853
- * ```ts
1854
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1855
- *
1856
- * const cancellationRefund = await EscrowUtils.getCancellationRefund(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
1480
+ * const cancellationRefund = await EscrowUtils.getCancellationRefund(
1481
+ * ChainId.POLYGON_AMOY,
1482
+ * "0x1234567890123456789012345678901234567890"
1483
+ * );
1484
+ * if (cancellationRefund) {
1485
+ * console.log('Refund amount:', cancellationRefund.amount);
1486
+ * }
1857
1487
  * ```
1858
1488
  */
1859
1489
  static async getCancellationRefund(chainId, escrowAddress, options) {