@human-protocol/sdk 5.2.0 → 6.1.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 (69) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/base.d.ts +8 -7
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +18 -5
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +7 -8
  8. package/dist/encryption.d.ts +68 -203
  9. package/dist/encryption.d.ts.map +1 -1
  10. package/dist/encryption.js +66 -202
  11. package/dist/error.d.ts +0 -24
  12. package/dist/error.d.ts.map +1 -1
  13. package/dist/error.js +2 -26
  14. package/dist/escrow.d.ts +438 -791
  15. package/dist/escrow.d.ts.map +1 -1
  16. package/dist/escrow.js +331 -705
  17. package/dist/graphql/queries/operator.d.ts.map +1 -1
  18. package/dist/graphql/queries/operator.js +3 -1
  19. package/dist/graphql/types.d.ts.map +1 -1
  20. package/dist/index.d.ts +3 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -4
  23. package/dist/interfaces.d.ts +2 -2
  24. package/dist/interfaces.d.ts.map +1 -1
  25. package/dist/kvstore.d.ts +124 -186
  26. package/dist/kvstore.d.ts.map +1 -1
  27. package/dist/kvstore.js +122 -185
  28. package/dist/operator.d.ts +59 -30
  29. package/dist/operator.d.ts.map +1 -1
  30. package/dist/operator.js +59 -30
  31. package/dist/staking.d.ts +142 -141
  32. package/dist/staking.d.ts.map +1 -1
  33. package/dist/staking.js +140 -139
  34. package/dist/statistics.d.ts +104 -134
  35. package/dist/statistics.d.ts.map +1 -1
  36. package/dist/statistics.js +119 -144
  37. package/dist/transaction.d.ts +38 -17
  38. package/dist/transaction.d.ts.map +1 -1
  39. package/dist/transaction.js +40 -19
  40. package/dist/types.d.ts +14 -55
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils.d.ts +32 -18
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js +32 -19
  45. package/dist/worker.d.ts +35 -14
  46. package/dist/worker.d.ts.map +1 -1
  47. package/dist/worker.js +35 -14
  48. package/package.json +8 -25
  49. package/src/base.ts +42 -7
  50. package/src/constants.ts +6 -8
  51. package/src/encryption.ts +69 -203
  52. package/src/error.ts +0 -36
  53. package/src/escrow.ts +548 -891
  54. package/src/graphql/queries/operator.ts +3 -1
  55. package/src/graphql/types.ts +4 -2
  56. package/src/index.ts +4 -5
  57. package/src/interfaces.ts +2 -2
  58. package/src/kvstore.ts +142 -197
  59. package/src/operator.ts +59 -30
  60. package/src/staking.ts +177 -160
  61. package/src/statistics.ts +125 -146
  62. package/src/transaction.ts +40 -19
  63. package/src/types.ts +16 -58
  64. package/src/utils.ts +33 -23
  65. package/src/worker.ts +35 -14
  66. package/dist/storage.d.ts +0 -186
  67. package/dist/storage.d.ts.map +0 -1
  68. package/dist/storage.js +0 -319
  69. package/src/storage.ts +0 -313
package/src/escrow.ts CHANGED
@@ -66,7 +66,12 @@ import {
66
66
  IEscrowWithdraw,
67
67
  SubgraphOptions,
68
68
  } from './interfaces';
69
- import { EscrowStatus, NetworkData, TransactionLikeWithNonce } from './types';
69
+ import {
70
+ EscrowStatus,
71
+ NetworkData,
72
+ TransactionLikeWithNonce,
73
+ TransactionOverrides,
74
+ } from './types';
70
75
  import {
71
76
  getSubgraphUrl,
72
77
  getUnixTimestamp,
@@ -77,82 +82,64 @@ import {
77
82
  } from './utils';
78
83
 
79
84
  /**
80
- * ## Introduction
81
- *
82
- * This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
85
+ * Client to perform actions on Escrow contracts and obtain information from the contracts.
83
86
  *
84
87
  * 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
- * ```
88
+ * To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/EscrowClient/#build) method.
90
89
  *
91
90
  * A `Signer` or a `Provider` should be passed depending on the use case of this module:
92
91
  *
93
92
  * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
94
93
  * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
95
94
  *
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
95
+ * @example
109
96
  *
110
- * ### Signer
97
+ * ###Using Signer
111
98
  *
112
- * **Using private key (backend)**
99
+ * ####Using private key (backend)
113
100
  *
114
101
  * ```ts
115
102
  * import { EscrowClient } from '@human-protocol/sdk';
116
- * import { Wallet, providers } from 'ethers';
103
+ * import { Wallet, JsonRpcProvider } from 'ethers';
117
104
  *
118
105
  * const rpcUrl = 'YOUR_RPC_URL';
119
106
  * const privateKey = 'YOUR_PRIVATE_KEY';
120
107
  *
121
- * const provider = new providers.JsonRpcProvider(rpcUrl);
108
+ * const provider = new JsonRpcProvider(rpcUrl);
122
109
  * const signer = new Wallet(privateKey, provider);
123
110
  * const escrowClient = await EscrowClient.build(signer);
124
111
  * ```
125
112
  *
126
- * **Using Wagmi (frontend)**
113
+ * ####Using Wagmi (frontend)
127
114
  *
128
115
  * ```ts
129
- * import { useSigner, useChainId } from 'wagmi';
116
+ * import { useSigner } from 'wagmi';
130
117
  * import { EscrowClient } from '@human-protocol/sdk';
131
118
  *
132
119
  * const { data: signer } = useSigner();
133
120
  * const escrowClient = await EscrowClient.build(signer);
134
121
  * ```
135
122
  *
136
- * ### Provider
123
+ * ###Using Provider
137
124
  *
138
125
  * ```ts
139
126
  * import { EscrowClient } from '@human-protocol/sdk';
140
- * import { providers } from 'ethers';
127
+ * import { JsonRpcProvider } from 'ethers';
141
128
  *
142
129
  * const rpcUrl = 'YOUR_RPC_URL';
143
- *
144
- * const provider = new providers.JsonRpcProvider(rpcUrl);
130
+ * const provider = new JsonRpcProvider(rpcUrl);
145
131
  * const escrowClient = await EscrowClient.build(provider);
146
132
  * ```
147
133
  */
148
134
  export class EscrowClient extends BaseEthersClient {
149
- private escrowFactoryContract: EscrowFactory;
135
+ public escrowFactoryContract: EscrowFactory;
150
136
 
151
137
  /**
152
138
  * **EscrowClient constructor**
153
139
  *
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
140
+ * @param runner - The Runner object to interact with the Ethereum network
141
+ * @param networkData - The network information required to connect to the Escrow contract
142
+ * @returns An instance of EscrowClient
156
143
  */
157
144
  constructor(runner: ContractRunner, networkData: NetworkData) {
158
145
  super(runner, networkData);
@@ -166,11 +153,10 @@ export class EscrowClient extends BaseEthersClient {
166
153
  /**
167
154
  * Creates an instance of EscrowClient from a Runner.
168
155
  *
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
156
+ * @param runner - The Runner object to interact with the Ethereum network
157
+ * @returns An instance of EscrowClient
158
+ * @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
159
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
174
160
  */
175
161
  public static async build(runner: ContractRunner): Promise<EscrowClient> {
176
162
  if (!runner.provider) {
@@ -204,28 +190,17 @@ export class EscrowClient extends BaseEthersClient {
204
190
 
205
191
  /**
206
192
  * This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
193
+ * @remarks Need to have available stake.
194
+ * @param tokenAddress - The address of the token to use for escrow funding.
195
+ * @param jobRequesterId - Identifier for the job requester.
196
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
197
+ * @returns Returns the address of the escrow created.
198
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
199
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
207
200
  *
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.
201
+ * @example
217
202
  *
218
203
  * ```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
204
  * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
230
205
  * const jobRequesterId = "job-requester-id";
231
206
  * const escrowAddress = await escrowClient.createEscrow(tokenAddress, jobRequesterId);
@@ -235,20 +210,22 @@ export class EscrowClient extends BaseEthersClient {
235
210
  public async createEscrow(
236
211
  tokenAddress: string,
237
212
  jobRequesterId: string,
238
- txOptions: Overrides = {}
213
+ txOptions: TransactionOverrides = {}
239
214
  ): Promise<string> {
240
215
  if (!ethers.isAddress(tokenAddress)) {
241
216
  throw ErrorInvalidTokenAddress;
242
217
  }
243
218
 
244
219
  try {
245
- const result = await (
246
- await this.escrowFactoryContract.createEscrow(
247
- tokenAddress,
248
- jobRequesterId,
249
- txOptions
250
- )
251
- ).wait();
220
+ const result = await this.sendTxAndWait(
221
+ (overrides) =>
222
+ this.escrowFactoryContract.createEscrow(
223
+ tokenAddress,
224
+ jobRequesterId,
225
+ overrides
226
+ ),
227
+ txOptions
228
+ );
252
229
 
253
230
  const event = (
254
231
  result?.logs?.find(({ topics }) =>
@@ -315,50 +292,45 @@ export class EscrowClient extends BaseEthersClient {
315
292
  /**
316
293
  * Creates, funds, and sets up a new escrow contract in a single transaction.
317
294
  *
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.
295
+ * @remarks Need to have available stake and approve allowance in the token contract before calling this method.
296
+ * @param tokenAddress - The ERC-20 token address used to fund the escrow.
297
+ * @param amount - The token amount to fund the escrow with.
298
+ * @param jobRequesterId - An off-chain identifier for the job requester.
299
+ * @param escrowConfig - Configuration parameters for escrow setup.
300
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
301
+ * @returns Returns the address of the escrow created.
302
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
303
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
304
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
305
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
306
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
307
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
308
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
309
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
310
+ * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
333
311
  *
334
312
  * @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);
313
+ * ```ts
314
+ * import { ethers } from 'ethers';
315
+ * import { ERC20__factory } from '@human-protocol/sdk';
344
316
  *
345
- * const tokenAddress = '0xTokenAddress';
317
+ * const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
346
318
  * const amount = ethers.parseUnits('1000', 18);
347
319
  * const jobRequesterId = 'requester-123';
348
320
  *
349
- * const token = IERC20__factory.connect(tokenAddress, signer);
321
+ * const token = ERC20__factory.connect(tokenAddress, signer);
350
322
  * await token.approve(escrowClient.escrowFactoryContract.target, amount);
351
323
  *
352
324
  * const escrowConfig = {
353
- * recordingOracle: '0xRecordingOracle',
354
- * reputationOracle: '0xReputationOracle',
355
- * exchangeOracle: '0xExchangeOracle',
325
+ * recordingOracle: '0xRecordingOracleAddress',
326
+ * reputationOracle: '0xReputationOracleAddress',
327
+ * exchangeOracle: '0xExchangeOracleAddress',
356
328
  * recordingOracleFee: 5n,
357
329
  * reputationOracleFee: 5n,
358
330
  * exchangeOracleFee: 5n,
359
331
  * manifest: 'https://example.com/manifest.json',
360
332
  * manifestHash: 'manifestHash-123',
361
- * } satisfies IEscrowConfig;
333
+ * };
362
334
  *
363
335
  * const escrowAddress = await escrowClient.createFundAndSetupEscrow(
364
336
  * tokenAddress,
@@ -366,8 +338,8 @@ export class EscrowClient extends BaseEthersClient {
366
338
  * jobRequesterId,
367
339
  * escrowConfig
368
340
  * );
369
- *
370
341
  * console.log('Escrow created at:', escrowAddress);
342
+ * ```
371
343
  */
372
344
  @requiresSigner
373
345
  public async createFundAndSetupEscrow(
@@ -375,7 +347,7 @@ export class EscrowClient extends BaseEthersClient {
375
347
  amount: bigint,
376
348
  jobRequesterId: string,
377
349
  escrowConfig: IEscrowConfig,
378
- txOptions: Overrides = {}
350
+ txOptions: TransactionOverrides = {}
379
351
  ): Promise<string> {
380
352
  if (!ethers.isAddress(tokenAddress)) {
381
353
  throw ErrorInvalidTokenAddress;
@@ -395,22 +367,24 @@ export class EscrowClient extends BaseEthersClient {
395
367
  } = escrowConfig;
396
368
 
397
369
  try {
398
- const result = await (
399
- await this.escrowFactoryContract.createFundAndSetupEscrow(
400
- tokenAddress,
401
- amount,
402
- jobRequesterId,
403
- reputationOracle,
404
- recordingOracle,
405
- exchangeOracle,
406
- reputationOracleFee,
407
- recordingOracleFee,
408
- exchangeOracleFee,
409
- manifest,
410
- manifestHash,
411
- txOptions
412
- )
413
- ).wait();
370
+ const result = await this.sendTxAndWait(
371
+ (overrides) =>
372
+ this.escrowFactoryContract.createFundAndSetupEscrow(
373
+ tokenAddress,
374
+ amount,
375
+ jobRequesterId,
376
+ reputationOracle,
377
+ recordingOracle,
378
+ exchangeOracle,
379
+ reputationOracleFee,
380
+ recordingOracleFee,
381
+ exchangeOracleFee,
382
+ manifest,
383
+ manifestHash,
384
+ overrides
385
+ ),
386
+ txOptions
387
+ );
414
388
 
415
389
  const event = (
416
390
  result?.logs?.find(({ topics }) =>
@@ -431,35 +405,33 @@ export class EscrowClient extends BaseEthersClient {
431
405
  /**
432
406
  * This function sets up the parameters of the escrow.
433
407
  *
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.
438
- *
408
+ * @remarks Only Job Launcher or admin can call it.
409
+ *
410
+ * @param escrowAddress - Address of the escrow to set up.
411
+ * @param escrowConfig - Escrow configuration parameters.
412
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
413
+ * @returns -
414
+ * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
415
+ * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
416
+ * @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
417
+ * @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
418
+ * @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
419
+ * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
420
+ * @throws ErrorHashIsEmptyString If the manifest hash is empty
421
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
422
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
439
423
  *
440
- * **Code example**
441
- *
442
- * > Only Job Launcher or admin can call it.
424
+ * @example
443
425
  *
444
426
  * ```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
427
  * const escrowAddress = '0x62dD51230A30401C455c8398d06F85e4EaB6309f';
456
428
  * const escrowConfig = {
457
429
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
458
430
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
459
431
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
460
- * recordingOracleFee: BigInt('10'),
461
- * reputationOracleFee: BigInt('10'),
462
- * exchangeOracleFee: BigInt('10'),
432
+ * recordingOracleFee: 10n,
433
+ * reputationOracleFee: 10n,
434
+ * exchangeOracleFee: 10n,
463
435
  * manifest: 'http://localhost/manifest.json',
464
436
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
465
437
  * };
@@ -470,7 +442,7 @@ export class EscrowClient extends BaseEthersClient {
470
442
  async setup(
471
443
  escrowAddress: string,
472
444
  escrowConfig: IEscrowConfig,
473
- txOptions: Overrides = {}
445
+ txOptions: TransactionOverrides = {}
474
446
  ): Promise<void> {
475
447
  const {
476
448
  recordingOracle,
@@ -496,19 +468,21 @@ export class EscrowClient extends BaseEthersClient {
496
468
  try {
497
469
  const escrowContract = this.getEscrowContract(escrowAddress);
498
470
 
499
- await (
500
- await escrowContract.setup(
501
- reputationOracle,
502
- recordingOracle,
503
- exchangeOracle,
504
- reputationOracleFee,
505
- recordingOracleFee,
506
- exchangeOracleFee,
507
- manifest,
508
- manifestHash,
509
- txOptions
510
- )
511
- ).wait();
471
+ await this.sendTxAndWait(
472
+ (overrides) =>
473
+ escrowContract.setup(
474
+ reputationOracle,
475
+ recordingOracle,
476
+ exchangeOracle,
477
+ reputationOracleFee,
478
+ recordingOracleFee,
479
+ exchangeOracleFee,
480
+ manifest,
481
+ manifestHash,
482
+ overrides
483
+ ),
484
+ txOptions
485
+ );
512
486
 
513
487
  return;
514
488
  } catch (e) {
@@ -519,26 +493,19 @@ export class EscrowClient extends BaseEthersClient {
519
493
  /**
520
494
  * This function adds funds of the chosen token to the escrow.
521
495
  *
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**
496
+ * @param escrowAddress - Address of the escrow to fund.
497
+ * @param amount - Amount to be added as funds.
498
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
499
+ * @returns -
500
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
501
+ * @throws ErrorAmountMustBeGreaterThanZero If the amount is less than or equal to zero
502
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
529
503
  *
504
+ * @example
530
505
  * ```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';
506
+ * import { ethers } from 'ethers';
536
507
  *
537
- * const provider = new providers.JsonRpcProvider(rpcUrl);
538
- * const signer = new Wallet(privateKey, provider);
539
- * const escrowClient = await EscrowClient.build(signer);
540
- *
541
- * const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
508
+ * const amount = ethers.parseUnits('5', 'ether');
542
509
  * await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
543
510
  * ```
544
511
  */
@@ -546,7 +513,7 @@ export class EscrowClient extends BaseEthersClient {
546
513
  async fund(
547
514
  escrowAddress: string,
548
515
  amount: bigint,
549
- txOptions: Overrides = {}
516
+ txOptions: TransactionOverrides = {}
550
517
  ): Promise<void> {
551
518
  if (!ethers.isAddress(escrowAddress)) {
552
519
  throw ErrorInvalidEscrowAddressProvided;
@@ -569,9 +536,10 @@ export class EscrowClient extends BaseEthersClient {
569
536
  tokenAddress,
570
537
  this.runner
571
538
  );
572
- await (
573
- await tokenContract.transfer(escrowAddress, amount, txOptions)
574
- ).wait();
539
+ await this.sendTxAndWait(
540
+ (overrides) => tokenContract.transfer(escrowAddress, amount, overrides),
541
+ txOptions
542
+ );
575
543
 
576
544
  return;
577
545
  } catch (e) {
@@ -580,76 +548,75 @@ export class EscrowClient extends BaseEthersClient {
580
548
  }
581
549
 
582
550
  /**
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.
551
+ * Stores the result URL and result hash for an escrow.
591
552
  *
553
+ * @remarks Only Recording Oracle or admin can call it.
592
554
  *
593
- * **Code example**
594
- *
595
- * > Only Recording Oracle or admin can call it.
555
+ * @param escrowAddress - The escrow address.
556
+ * @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
557
+ * @param hash - The hash of the results payload.
558
+ * @param txOptions - Optional transaction overrides.
559
+ * @returns -
560
+ * @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
561
+ * @throws ErrorInvalidUrl If the URL format is invalid.
562
+ * @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
563
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
564
+ * @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
596
565
  *
566
+ * @example
597
567
  * ```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'));
568
+ * await escrowClient.storeResults(
569
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
570
+ * 'https://example.com/results.json',
571
+ * '0xHASH123'
572
+ * );
609
573
  * ```
610
574
  */
611
-
612
575
  async storeResults(
613
576
  escrowAddress: string,
614
577
  url: string,
615
578
  hash: string,
616
- fundsToReserve: bigint,
617
- txOptions?: Overrides
579
+ txOptions?: TransactionOverrides
618
580
  ): Promise<void>;
619
581
 
620
582
  /**
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.
583
+ * Stores the result URL and result hash for an escrow.
628
584
  *
585
+ * @remarks Only Recording Oracle or admin can call it.
629
586
  *
630
- * **Code example**
587
+ * If `fundsToReserve` is provided, the escrow reserves the specified funds.
588
+ * When `fundsToReserve` is `0n`, an empty URL is allowed (for cases where no solutions were provided).
631
589
  *
632
- * > Only Recording Oracle or admin can call it.
590
+ * @param escrowAddress - The escrow address.
591
+ * @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
592
+ * @param hash - The hash of the results payload.
593
+ * @param fundsToReserve - Optional amount of funds to reserve (when using second overload).
594
+ * @param txOptions - Optional transaction overrides.
595
+ * @returns -
596
+ * @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
597
+ * @throws ErrorInvalidUrl If the URL format is invalid.
598
+ * @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
599
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
600
+ * @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
633
601
  *
602
+ * @example
634
603
  * ```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';
604
+ * import { ethers } from 'ethers';
640
605
  *
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');
606
+ * await escrowClient.storeResults(
607
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
608
+ * 'https://example.com/results.json',
609
+ * '0xHASH123',
610
+ * ethers.parseEther('5')
611
+ * );
646
612
  * ```
647
613
  */
648
614
  async storeResults(
649
615
  escrowAddress: string,
650
616
  url: string,
651
617
  hash: string,
652
- txOptions?: Overrides
618
+ fundsToReserve: bigint,
619
+ txOptions?: TransactionOverrides
653
620
  ): Promise<void>;
654
621
 
655
622
  @requiresSigner
@@ -657,14 +624,16 @@ export class EscrowClient extends BaseEthersClient {
657
624
  escrowAddress: string,
658
625
  url: string,
659
626
  hash: string,
660
- a?: bigint | Overrides,
661
- b?: Overrides
627
+ a?: bigint | TransactionOverrides,
628
+ b?: TransactionOverrides
662
629
  ): Promise<void> {
663
630
  const escrowContract = this.getEscrowContract(escrowAddress);
664
631
 
665
632
  const hasFundsToReserveParam = typeof a === 'bigint';
666
633
  const fundsToReserve = hasFundsToReserveParam ? (a as bigint) : null;
667
- const txOptions = (hasFundsToReserveParam ? b : a) || {};
634
+ const txOptions = (hasFundsToReserveParam ? b : a) as
635
+ | TransactionOverrides
636
+ | undefined;
668
637
  // When fundsToReserve is provided and is 0, allow empty URL.
669
638
  // In this situation not solutions might have been provided so the escrow can be straight cancelled.
670
639
  const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
@@ -685,24 +654,17 @@ export class EscrowClient extends BaseEthersClient {
685
654
  }
686
655
 
687
656
  try {
688
- if (fundsToReserve !== null) {
689
- await (
690
- await escrowContract['storeResults(string,string,uint256)'](
691
- url,
692
- hash,
693
- fundsToReserve,
694
- txOptions
695
- )
696
- ).wait();
697
- } else {
698
- await (
699
- await escrowContract['storeResults(string,string)'](
700
- url,
701
- hash,
702
- txOptions
703
- )
704
- ).wait();
705
- }
657
+ const txFactory = (overrides: Overrides) =>
658
+ fundsToReserve !== null
659
+ ? escrowContract['storeResults(string,string,uint256)'](
660
+ url,
661
+ hash,
662
+ fundsToReserve,
663
+ overrides
664
+ )
665
+ : escrowContract['storeResults(string,string)'](url, hash, overrides);
666
+
667
+ await this.sendTxAndWait(txFactory, txOptions);
706
668
  } catch (e) {
707
669
  if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
708
670
  throw ErrorStoreResultsVersion;
@@ -715,34 +677,22 @@ export class EscrowClient extends BaseEthersClient {
715
677
 
716
678
  /**
717
679
  * This function sets the status of an escrow to completed.
680
+ * @remarks Only Recording Oracle or admin can call it.
681
+ * @param escrowAddress - Address of the escrow.
682
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
683
+ * @returns -
684
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid.
685
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory.
718
686
  *
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
- *
687
+ * @example
728
688
  * ```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
689
  * await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
740
690
  * ```
741
691
  */
742
692
  @requiresSigner
743
693
  async complete(
744
694
  escrowAddress: string,
745
- txOptions: Overrides = {}
695
+ txOptions: TransactionOverrides = {}
746
696
  ): Promise<void> {
747
697
  if (!ethers.isAddress(escrowAddress)) {
748
698
  throw ErrorInvalidEscrowAddressProvided;
@@ -754,8 +704,10 @@ export class EscrowClient extends BaseEthersClient {
754
704
 
755
705
  try {
756
706
  const escrowContract = this.getEscrowContract(escrowAddress);
757
-
758
- await (await escrowContract.complete(txOptions)).wait();
707
+ await this.sendTxAndWait(
708
+ (overrides) => escrowContract.complete(overrides),
709
+ txOptions
710
+ );
759
711
  return;
760
712
  } catch (e) {
761
713
  return throwError(e);
@@ -764,40 +716,48 @@ export class EscrowClient extends BaseEthersClient {
764
716
 
765
717
  /**
766
718
  * This function pays out the amounts specified to the workers and sets the URL of the final results file.
719
+ * @remarks Only Reputation Oracle or admin can call it.
720
+ *
721
+ * @param escrowAddress - Escrow address to payout.
722
+ * @param recipients - Array of recipient addresses.
723
+ * @param amounts - Array of amounts the recipients will receive.
724
+ * @param finalResultsUrl - Final results file URL.
725
+ * @param finalResultsHash - Final results file hash.
726
+ * @param txId - Transaction ID.
727
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
728
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
729
+ * @returns -
730
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
731
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
732
+ * @throws ErrorTooManyRecipients If there are too many recipients
733
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
734
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
735
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
736
+ * @throws ErrorInvalidUrl If the final results URL is invalid
737
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
738
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
739
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
740
+ * @throws ErrorBulkPayOutVersion If using deprecated signature
767
741
  *
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
- *
742
+ * @example
783
743
  * ```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';
744
+ * import { ethers } from 'ethers';
789
745
  *
790
- * const provider = new providers.JsonRpcProvider(rpcUrl);
791
- * const signer = new Wallet(privateKey, provider);
792
- * const escrowClient = await EscrowClient.build(signer);
793
- *
794
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
795
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
746
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
747
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
796
748
  * const resultsUrl = 'http://localhost/results.json';
797
749
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
798
750
  * const txId = 1;
799
751
  *
800
- * await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId, true);
752
+ * await escrowClient.bulkPayOut(
753
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
754
+ * recipients,
755
+ * amounts,
756
+ * resultsUrl,
757
+ * resultsHash,
758
+ * txId,
759
+ * true
760
+ * );
801
761
  * ```
802
762
  */
803
763
  async bulkPayOut(
@@ -808,46 +768,54 @@ export class EscrowClient extends BaseEthersClient {
808
768
  finalResultsHash: string,
809
769
  txId: number,
810
770
  forceComplete: boolean,
811
- txOptions: Overrides
771
+ txOptions: TransactionOverrides
812
772
  ): Promise<void>;
813
773
 
814
774
  /**
815
775
  * This function pays out the amounts specified to the workers and sets the URL of the final results file.
776
+ * @remarks Only Reputation Oracle or admin can call it.
777
+ * @param escrowAddress - Escrow address to payout.
778
+ * @param recipients - Array of recipient addresses.
779
+ * @param amounts - Array of amounts the recipients will receive.
780
+ * @param finalResultsUrl - Final results file URL.
781
+ * @param finalResultsHash - Final results file hash.
782
+ * @param payoutId - Payout ID.
783
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
784
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
785
+ * @returns -
786
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
787
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
788
+ * @throws ErrorTooManyRecipients If there are too many recipients
789
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
790
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
791
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
792
+ * @throws ErrorInvalidUrl If the final results URL is invalid
793
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
794
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
795
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
796
+ * @throws ErrorBulkPayOutVersion If using deprecated signature
816
797
  *
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.
798
+ * @example
831
799
  *
832
800
  * ```ts
833
- * import { ethers, Wallet, providers } from 'ethers';
834
- * import { EscrowClient } from '@human-protocol/sdk';
801
+ * import { ethers } from 'ethers';
835
802
  * import { v4 as uuidV4 } from 'uuid';
836
803
  *
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')];
804
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
805
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
846
806
  * const resultsUrl = 'http://localhost/results.json';
847
807
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
848
808
  * const payoutId = uuidV4();
849
809
  *
850
- * await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, payoutId, true);
810
+ * await escrowClient.bulkPayOut(
811
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
812
+ * recipients,
813
+ * amounts,
814
+ * resultsUrl,
815
+ * resultsHash,
816
+ * payoutId,
817
+ * true
818
+ * );
851
819
  * ```
852
820
  */
853
821
  async bulkPayOut(
@@ -858,7 +826,7 @@ export class EscrowClient extends BaseEthersClient {
858
826
  finalResultsHash: string,
859
827
  payoutId: string,
860
828
  forceComplete: boolean,
861
- txOptions: Overrides
829
+ txOptions: TransactionOverrides
862
830
  ): Promise<void>;
863
831
 
864
832
  @requiresSigner
@@ -870,7 +838,7 @@ export class EscrowClient extends BaseEthersClient {
870
838
  finalResultsHash: string,
871
839
  id: number | string,
872
840
  forceComplete: boolean,
873
- txOptions: Overrides = {}
841
+ txOptions: TransactionOverrides = {}
874
842
  ): Promise<void> {
875
843
  await this.ensureCorrectBulkPayoutInput(
876
844
  escrowAddress,
@@ -884,35 +852,32 @@ export class EscrowClient extends BaseEthersClient {
884
852
  const idIsString = typeof id === 'string';
885
853
 
886
854
  try {
887
- if (idIsString) {
888
- await (
889
- await escrowContract[
890
- 'bulkPayOut(address[],uint256[],string,string,string,bool)'
891
- ](
892
- recipients,
893
- amounts,
894
- finalResultsUrl,
895
- finalResultsHash,
896
- id,
897
- forceComplete,
898
- txOptions
899
- )
900
- ).wait();
901
- } else {
902
- await (
903
- await escrowContract[
904
- 'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
905
- ](
906
- recipients,
907
- amounts,
908
- finalResultsUrl,
909
- finalResultsHash,
910
- id,
911
- forceComplete,
912
- txOptions
913
- )
914
- ).wait();
915
- }
855
+ const txFactory = (overrides: Overrides) =>
856
+ idIsString
857
+ ? escrowContract[
858
+ 'bulkPayOut(address[],uint256[],string,string,string,bool)'
859
+ ](
860
+ recipients,
861
+ amounts,
862
+ finalResultsUrl,
863
+ finalResultsHash,
864
+ id,
865
+ forceComplete,
866
+ overrides
867
+ )
868
+ : escrowContract[
869
+ 'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
870
+ ](
871
+ recipients,
872
+ amounts,
873
+ finalResultsUrl,
874
+ finalResultsHash,
875
+ id,
876
+ forceComplete,
877
+ overrides
878
+ );
879
+
880
+ await this.sendTxAndWait(txFactory, txOptions);
916
881
  } catch (e) {
917
882
  if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
918
883
  throw ErrorBulkPayOutVersion;
@@ -925,33 +890,23 @@ export class EscrowClient extends BaseEthersClient {
925
890
 
926
891
  /**
927
892
  * This function cancels the specified escrow and sends the balance to the canceler.
893
+ * @remarks Only Job Launcher or admin can call it.
894
+ * @param escrowAddress - Address of the escrow to cancel.
895
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
896
+ * @returns -
897
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
898
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
928
899
  *
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.
900
+ * @example
936
901
  *
937
902
  * ```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
903
  * await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
949
904
  * ```
950
905
  */
951
906
  @requiresSigner
952
907
  async cancel(
953
908
  escrowAddress: string,
954
- txOptions: Overrides = {}
909
+ txOptions: TransactionOverrides = {}
955
910
  ): Promise<void> {
956
911
  if (!ethers.isAddress(escrowAddress)) {
957
912
  throw ErrorInvalidEscrowAddressProvided;
@@ -963,7 +918,10 @@ export class EscrowClient extends BaseEthersClient {
963
918
 
964
919
  try {
965
920
  const escrowContract = this.getEscrowContract(escrowAddress);
966
- await (await escrowContract.cancel(txOptions)).wait();
921
+ await this.sendTxAndWait(
922
+ (overrides) => escrowContract.cancel(overrides),
923
+ txOptions
924
+ );
967
925
  } catch (e) {
968
926
  return throwError(e);
969
927
  }
@@ -971,33 +929,23 @@ export class EscrowClient extends BaseEthersClient {
971
929
 
972
930
  /**
973
931
  * This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
932
+ * @remarks Only Job Launcher or admin can call it.
933
+ * @param escrowAddress - Address of the escrow to request cancellation.
934
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
935
+ * @returns -
936
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
937
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
974
938
  *
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.
939
+ * @example
982
940
  *
983
941
  * ```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
942
  * await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
995
943
  * ```
996
944
  */
997
945
  @requiresSigner
998
946
  async requestCancellation(
999
947
  escrowAddress: string,
1000
- txOptions: Overrides = {}
948
+ txOptions: TransactionOverrides = {}
1001
949
  ): Promise<void> {
1002
950
  if (!ethers.isAddress(escrowAddress)) {
1003
951
  throw ErrorInvalidEscrowAddressProvided;
@@ -1009,7 +957,10 @@ export class EscrowClient extends BaseEthersClient {
1009
957
 
1010
958
  try {
1011
959
  const escrowContract = this.getEscrowContract(escrowAddress);
1012
- await (await escrowContract.requestCancellation(txOptions)).wait();
960
+ await this.sendTxAndWait(
961
+ (overrides) => escrowContract.requestCancellation(overrides),
962
+ txOptions
963
+ );
1013
964
  } catch (e) {
1014
965
  return throwError(e);
1015
966
  }
@@ -1017,39 +968,32 @@ export class EscrowClient extends BaseEthersClient {
1017
968
 
1018
969
  /**
1019
970
  * This function withdraws additional tokens in the escrow to the canceler.
971
+ * @remarks Only Job Launcher or admin can call it.
1020
972
  *
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.
1025
- *
973
+ * @param escrowAddress - Address of the escrow to withdraw.
974
+ * @param tokenAddress - Address of the token to withdraw.
975
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
976
+ * @returns Returns the escrow withdrawal data including transaction hash and withdrawal amount.
977
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
978
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
979
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
980
+ * @throws ErrorTransferEventNotFoundInTransactionLogs If the Transfer event is not found in transaction logs
1026
981
  *
1027
- * **Code example**
1028
- *
1029
- * > Only Job Launcher or admin can call it.
982
+ * @example
1030
983
  *
1031
984
  * ```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(
985
+ * const withdrawData = await escrowClient.withdraw(
1043
986
  * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
1044
987
  * '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
1045
988
  * );
989
+ * console.log('Withdrawn amount:', withdrawData.withdrawnAmount);
1046
990
  * ```
1047
991
  */
1048
992
  @requiresSigner
1049
993
  async withdraw(
1050
994
  escrowAddress: string,
1051
995
  tokenAddress: string,
1052
- txOptions: Overrides = {}
996
+ txOptions: TransactionOverrides = {}
1053
997
  ): Promise<IEscrowWithdraw> {
1054
998
  if (!ethers.isAddress(escrowAddress)) {
1055
999
  throw ErrorInvalidEscrowAddressProvided;
@@ -1065,10 +1009,10 @@ export class EscrowClient extends BaseEthersClient {
1065
1009
 
1066
1010
  try {
1067
1011
  const escrowContract = this.getEscrowContract(escrowAddress);
1068
-
1069
- const transactionReceipt = await (
1070
- await escrowContract.withdraw(tokenAddress, txOptions)
1071
- ).wait();
1012
+ const transactionReceipt = await this.sendTxAndWait(
1013
+ (overrides) => escrowContract.withdraw(tokenAddress, overrides),
1014
+ txOptions
1015
+ );
1072
1016
 
1073
1017
  let amountTransferred: bigint | undefined = undefined;
1074
1018
 
@@ -1108,43 +1052,54 @@ export class EscrowClient extends BaseEthersClient {
1108
1052
 
1109
1053
  /**
1110
1054
  * 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
1055
+ * @remarks Only Reputation Oracle or admin can call it.
1056
+ *
1057
+ * @param escrowAddress - Escrow address to payout.
1058
+ * @param recipients - Array of recipient addresses.
1059
+ * @param amounts - Array of amounts the recipients will receive.
1060
+ * @param finalResultsUrl - Final results file URL.
1061
+ * @param finalResultsHash - Final results file hash.
1062
+ * @param payoutId - Payout ID to identify the payout.
1063
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
1064
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
1065
+ * @returns Returns object with raw transaction and nonce
1066
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1067
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
1068
+ * @throws ErrorTooManyRecipients If there are too many recipients
1069
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
1070
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
1071
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
1072
+ * @throws ErrorInvalidUrl If the final results URL is invalid
1073
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
1074
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
1075
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1120
1076
  *
1121
- * **Code example**
1122
- *
1123
- * > Only Reputation Oracle or admin can call it.
1077
+ * @example
1124
1078
  *
1125
1079
  * ```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);
1080
+ * import { ethers } from 'ethers';
1081
+ * import { v4 as uuidV4 } from 'uuid';
1135
1082
  *
1136
- * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
1137
- * const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
1083
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
1084
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
1138
1085
  * const resultsUrl = 'http://localhost/results.json';
1139
1086
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
1140
- * const payoutId = '372f6916-fe34-4711-b6e3-274f682047de';
1087
+ * const payoutId = uuidV4();
1141
1088
  *
1142
- * const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
1089
+ * const rawTransaction = await escrowClient.createBulkPayoutTransaction(
1090
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
1091
+ * recipients,
1092
+ * amounts,
1093
+ * resultsUrl,
1094
+ * resultsHash,
1095
+ * payoutId
1096
+ * );
1143
1097
  * console.log('Raw transaction:', rawTransaction);
1144
1098
  *
1145
1099
  * const signedTransaction = await signer.signTransaction(rawTransaction);
1146
1100
  * console.log('Tx hash:', ethers.keccak256(signedTransaction));
1147
- * (await signer.sendTransaction(rawTransaction)).wait();
1101
+ * await signer.sendTransaction(rawTransaction);
1102
+ * ```
1148
1103
  */
1149
1104
  @requiresSigner
1150
1105
  async createBulkPayoutTransaction(
@@ -1275,21 +1230,15 @@ export class EscrowClient extends BaseEthersClient {
1275
1230
  /**
1276
1231
  * This function returns the balance for a specified escrow address.
1277
1232
  *
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**
1233
+ * @param escrowAddress - Address of the escrow.
1234
+ * @returns Balance of the escrow in the token used to fund it.
1235
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1236
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1282
1237
  *
1238
+ * @example
1283
1239
  * ```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
1240
  * const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1241
+ * console.log('Balance:', balance);
1293
1242
  * ```
1294
1243
  */
1295
1244
  async getBalance(escrowAddress: string): Promise<bigint> {
@@ -1319,21 +1268,15 @@ export class EscrowClient extends BaseEthersClient {
1319
1268
  /**
1320
1269
  * This function returns the reserved funds for a specified escrow address.
1321
1270
  *
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**
1271
+ * @param escrowAddress - Address of the escrow.
1272
+ * @returns Reserved funds of the escrow in the token used to fund it.
1273
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1274
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1326
1275
  *
1276
+ * @example
1327
1277
  * ```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
1278
  * const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1279
+ * console.log('Reserved funds:', reservedFunds);
1337
1280
  * ```
1338
1281
  */
1339
1282
  async getReservedFunds(escrowAddress: string): Promise<bigint> {
@@ -1356,21 +1299,15 @@ export class EscrowClient extends BaseEthersClient {
1356
1299
  /**
1357
1300
  * This function returns the manifest file hash.
1358
1301
  *
1359
- * @param {string} escrowAddress Address of the escrow.
1360
- * @returns {Promise<string>} Hash of the manifest file content.
1361
- *
1362
- * **Code example**
1302
+ * @param escrowAddress - Address of the escrow.
1303
+ * @returns Hash of the manifest file content.
1304
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1305
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1363
1306
  *
1307
+ * @example
1364
1308
  * ```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
1309
  * const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1310
+ * console.log('Manifest hash:', manifestHash);
1374
1311
  * ```
1375
1312
  */
1376
1313
  async getManifestHash(escrowAddress: string): Promise<string> {
@@ -1394,21 +1331,15 @@ export class EscrowClient extends BaseEthersClient {
1394
1331
  /**
1395
1332
  * This function returns the manifest. Could be a URL or a JSON string.
1396
1333
  *
1397
- * @param {string} escrowAddress Address of the escrow.
1398
- * @returns {Promise<string>} Url of the manifest.
1399
- *
1400
- * **Code example**
1334
+ * @param escrowAddress - Address of the escrow.
1335
+ * @returns Manifest URL or JSON string.
1336
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1337
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1401
1338
  *
1339
+ * @example
1402
1340
  * ```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
1341
  * const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1342
+ * console.log('Manifest:', manifest);
1412
1343
  * ```
1413
1344
  */
1414
1345
  async getManifest(escrowAddress: string): Promise<string> {
@@ -1432,21 +1363,15 @@ export class EscrowClient extends BaseEthersClient {
1432
1363
  /**
1433
1364
  * This function returns the results file URL.
1434
1365
  *
1435
- * @param {string} escrowAddress Address of the escrow.
1436
- * @returns {Promise<string>} Results file url.
1437
- *
1438
- * **Code example**
1366
+ * @param escrowAddress - Address of the escrow.
1367
+ * @returns Results file URL.
1368
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1369
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1439
1370
  *
1371
+ * @example
1440
1372
  * ```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
1373
  * const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1374
+ * console.log('Results URL:', resultsUrl);
1450
1375
  * ```
1451
1376
  */
1452
1377
  async getResultsUrl(escrowAddress: string): Promise<string> {
@@ -1470,21 +1395,15 @@ export class EscrowClient extends BaseEthersClient {
1470
1395
  /**
1471
1396
  * This function returns the intermediate results file URL.
1472
1397
  *
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**
1398
+ * @param escrowAddress - Address of the escrow.
1399
+ * @returns URL of the file that stores results from Recording Oracle.
1400
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1401
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1477
1402
  *
1403
+ * @example
1478
1404
  * ```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
1405
  * const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1406
+ * console.log('Intermediate results URL:', intermediateResultsUrl);
1488
1407
  * ```
1489
1408
  */
1490
1409
  async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
@@ -1508,21 +1427,15 @@ export class EscrowClient extends BaseEthersClient {
1508
1427
  /**
1509
1428
  * This function returns the intermediate results hash.
1510
1429
  *
1511
- * @param {string} escrowAddress Address of the escrow.
1512
- * @returns {Promise<string>} Hash of the intermediate results file content.
1513
- *
1514
- * **Code example**
1430
+ * @param escrowAddress - Address of the escrow.
1431
+ * @returns Hash of the intermediate results file content.
1432
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1433
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1515
1434
  *
1435
+ * @example
1516
1436
  * ```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
1437
  * const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1438
+ * console.log('Intermediate results hash:', intermediateResultsHash);
1526
1439
  * ```
1527
1440
  */
1528
1441
  async getIntermediateResultsHash(escrowAddress: string): Promise<string> {
@@ -1546,21 +1459,15 @@ export class EscrowClient extends BaseEthersClient {
1546
1459
  /**
1547
1460
  * This function returns the token address used for funding the escrow.
1548
1461
  *
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**
1462
+ * @param escrowAddress - Address of the escrow.
1463
+ * @returns Address of the token used to fund the escrow.
1464
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1465
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1553
1466
  *
1467
+ * @example
1554
1468
  * ```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
1469
  * const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1470
+ * console.log('Token address:', tokenAddress);
1564
1471
  * ```
1565
1472
  */
1566
1473
  async getTokenAddress(escrowAddress: string): Promise<string> {
@@ -1584,21 +1491,17 @@ export class EscrowClient extends BaseEthersClient {
1584
1491
  /**
1585
1492
  * This function returns the current status of the escrow.
1586
1493
  *
1587
- * @param {string} escrowAddress Address of the escrow.
1588
- * @returns {Promise<EscrowStatus>} Current status of the escrow.
1589
- *
1590
- * **Code example**
1494
+ * @param escrowAddress - Address of the escrow.
1495
+ * @returns Current status of the escrow.
1496
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1497
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1591
1498
  *
1499
+ * @example
1592
1500
  * ```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);
1501
+ * import { EscrowStatus } from '@human-protocol/sdk';
1600
1502
  *
1601
1503
  * const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1504
+ * console.log('Status:', EscrowStatus[status]);
1602
1505
  * ```
1603
1506
  */
1604
1507
  async getStatus(escrowAddress: string): Promise<EscrowStatus> {
@@ -1622,21 +1525,15 @@ export class EscrowClient extends BaseEthersClient {
1622
1525
  /**
1623
1526
  * This function returns the recording oracle address for a given escrow.
1624
1527
  *
1625
- * @param {string} escrowAddress Address of the escrow.
1626
- * @returns {Promise<string>} Address of the Recording Oracle.
1627
- *
1628
- * **Code example**
1528
+ * @param escrowAddress - Address of the escrow.
1529
+ * @returns Address of the Recording Oracle.
1530
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1531
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1629
1532
  *
1533
+ * @example
1630
1534
  * ```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
1535
  * const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1536
+ * console.log('Recording Oracle address:', oracleAddress);
1640
1537
  * ```
1641
1538
  */
1642
1539
  async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
@@ -1660,21 +1557,15 @@ export class EscrowClient extends BaseEthersClient {
1660
1557
  /**
1661
1558
  * This function returns the job launcher address for a given escrow.
1662
1559
  *
1663
- * @param {string} escrowAddress Address of the escrow.
1664
- * @returns {Promise<string>} Address of the Job Launcher.
1665
- *
1666
- * **Code example**
1560
+ * @param escrowAddress - Address of the escrow.
1561
+ * @returns Address of the Job Launcher.
1562
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1563
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1667
1564
  *
1565
+ * @example
1668
1566
  * ```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
1567
  * const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1568
+ * console.log('Job Launcher address:', jobLauncherAddress);
1678
1569
  * ```
1679
1570
  */
1680
1571
  async getJobLauncherAddress(escrowAddress: string): Promise<string> {
@@ -1698,21 +1589,15 @@ export class EscrowClient extends BaseEthersClient {
1698
1589
  /**
1699
1590
  * This function returns the reputation oracle address for a given escrow.
1700
1591
  *
1701
- * @param {string} escrowAddress Address of the escrow.
1702
- * @returns {Promise<string>} Address of the Reputation Oracle.
1703
- *
1704
- * **Code example**
1592
+ * @param escrowAddress - Address of the escrow.
1593
+ * @returns Address of the Reputation Oracle.
1594
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1595
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1705
1596
  *
1597
+ * @example
1706
1598
  * ```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
1599
  * const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1600
+ * console.log('Reputation Oracle address:', oracleAddress);
1716
1601
  * ```
1717
1602
  */
1718
1603
  async getReputationOracleAddress(escrowAddress: string): Promise<string> {
@@ -1736,21 +1621,15 @@ export class EscrowClient extends BaseEthersClient {
1736
1621
  /**
1737
1622
  * This function returns the exchange oracle address for a given escrow.
1738
1623
  *
1739
- * @param {string} escrowAddress Address of the escrow.
1740
- * @returns {Promise<string>} Address of the Exchange Oracle.
1741
- *
1742
- * **Code example**
1624
+ * @param escrowAddress - Address of the escrow.
1625
+ * @returns Address of the Exchange Oracle.
1626
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1627
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1743
1628
  *
1629
+ * @example
1744
1630
  * ```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
1631
  * const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1632
+ * console.log('Exchange Oracle address:', oracleAddress);
1754
1633
  * ```
1755
1634
  */
1756
1635
  async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
@@ -1774,21 +1653,15 @@ export class EscrowClient extends BaseEthersClient {
1774
1653
  /**
1775
1654
  * This function returns the escrow factory address for a given escrow.
1776
1655
  *
1777
- * @param {string} escrowAddress Address of the escrow.
1778
- * @returns {Promise<string>} Address of the escrow factory.
1779
- *
1780
- * **Code example**
1656
+ * @param escrowAddress - Address of the escrow.
1657
+ * @returns Address of the escrow factory.
1658
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1659
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1781
1660
  *
1661
+ * @example
1782
1662
  * ```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
1663
  * const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1664
+ * console.log('Factory address:', factoryAddress);
1792
1665
  * ```
1793
1666
  */
1794
1667
  async getFactoryAddress(escrowAddress: string): Promise<string> {
@@ -1810,138 +1683,40 @@ export class EscrowClient extends BaseEthersClient {
1810
1683
  }
1811
1684
  }
1812
1685
  /**
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)**
1686
+ * Utility helpers for escrow-related queries.
1834
1687
  *
1688
+ * @example
1835
1689
  * ```ts
1836
1690
  * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1837
1691
  *
1838
- * const escrowAddresses = new EscrowUtils.getEscrows({
1692
+ * const escrows = await EscrowUtils.getEscrows({
1839
1693
  * chainId: ChainId.POLYGON_AMOY
1840
1694
  * });
1695
+ * console.log('Escrows:', escrows);
1841
1696
  * ```
1842
1697
  */
1843
1698
  export class EscrowUtils {
1844
1699
  /**
1845
1700
  * This function returns an array of escrows based on the specified filter parameters.
1846
1701
  *
1702
+ * @param filter - Filter parameters.
1703
+ * @param options - Optional configuration for subgraph requests.
1704
+ * @returns List of escrows that match the filter.
1705
+ * @throws ErrorInvalidAddress If any filter address is invalid
1706
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1847
1707
  *
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
- *
1708
+ * @example
1935
1709
  * ```ts
1936
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1710
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1937
1711
  *
1938
- * const filters: IEscrowsFilter = {
1712
+ * const filters = {
1939
1713
  * status: EscrowStatus.Pending,
1940
1714
  * from: new Date(2023, 4, 8),
1941
1715
  * to: new Date(2023, 5, 8),
1942
1716
  * chainId: ChainId.POLYGON_AMOY
1943
1717
  * };
1944
1718
  * const escrows = await EscrowUtils.getEscrows(filters);
1719
+ * console.log('Found escrows:', escrows.length);
1945
1720
  * ```
1946
1721
  */
1947
1722
  public static async getEscrows(
@@ -2006,63 +1781,24 @@ export class EscrowUtils {
2006
1781
  *
2007
1782
  * > This uses Subgraph
2008
1783
  *
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**
1784
+ * @param chainId - Network in which the escrow has been deployed
1785
+ * @param escrowAddress - Address of the escrow
1786
+ * @param options - Optional configuration for subgraph requests.
1787
+ * @returns Escrow data or null if not found.
1788
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1789
+ * @throws ErrorInvalidAddress If the escrow address is invalid
2061
1790
  *
1791
+ * @example
2062
1792
  * ```ts
2063
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1793
+ * import { ChainId } from '@human-protocol/sdk';
2064
1794
  *
2065
- * const escrow = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
1795
+ * const escrow = await EscrowUtils.getEscrow(
1796
+ * ChainId.POLYGON_AMOY,
1797
+ * "0x1234567890123456789012345678901234567890"
1798
+ * );
1799
+ * if (escrow) {
1800
+ * console.log('Escrow status:', escrow.status);
1801
+ * }
2066
1802
  * ```
2067
1803
  */
2068
1804
  public static async getEscrow(
@@ -2096,56 +1832,25 @@ export class EscrowUtils {
2096
1832
  *
2097
1833
  * > This uses Subgraph
2098
1834
  *
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
- * ```
1835
+ * @param filter - Filter parameters.
1836
+ * @param options - Optional configuration for subgraph requests.
1837
+ * @returns Array of status events with their corresponding statuses.
1838
+ * @throws ErrorInvalidAddress If the launcher address is invalid
1839
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
2120
1840
  *
1841
+ * @example
2121
1842
  * ```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.
2132
- *
2133
- * **Code example**
1843
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
2134
1844
  *
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
- * })();
1845
+ * const fromDate = new Date('2023-01-01');
1846
+ * const toDate = new Date('2023-12-31');
1847
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1848
+ * chainId: ChainId.POLYGON,
1849
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1850
+ * from: fromDate,
1851
+ * to: toDate
1852
+ * });
1853
+ * console.log('Status events:', statusEvents.length);
2149
1854
  * ```
2150
1855
  */
2151
1856
  public static async getStatusEvents(
@@ -2218,17 +1923,15 @@ export class EscrowUtils {
2218
1923
  *
2219
1924
  * > This uses Subgraph
2220
1925
  *
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**
1926
+ * @param filter - Filter parameters.
1927
+ * @param options - Optional configuration for subgraph requests.
1928
+ * @returns List of payouts matching the filters.
1929
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1930
+ * @throws ErrorInvalidAddress If any filter address is invalid
2229
1931
  *
1932
+ * @example
2230
1933
  * ```ts
2231
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1934
+ * import { ChainId } from '@human-protocol/sdk';
2232
1935
  *
2233
1936
  * const payouts = await EscrowUtils.getPayouts({
2234
1937
  * chainId: ChainId.POLYGON,
@@ -2237,7 +1940,7 @@ export class EscrowUtils {
2237
1940
  * from: new Date('2023-01-01'),
2238
1941
  * to: new Date('2023-12-31')
2239
1942
  * });
2240
- * console.log(payouts);
1943
+ * console.log('Payouts:', payouts.length);
2241
1944
  * ```
2242
1945
  */
2243
1946
  public static async getPayouts(
@@ -2292,48 +1995,22 @@ export class EscrowUtils {
2292
1995
  *
2293
1996
  * > This uses Subgraph
2294
1997
  *
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**
1998
+ * @param filter - Filter parameters.
1999
+ * @param options - Optional configuration for subgraph requests.
2000
+ * @returns List of cancellation refunds matching the filters.
2001
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
2002
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
2003
+ * @throws ErrorInvalidAddress If the receiver address is invalid
2328
2004
  *
2005
+ * @example
2329
2006
  * ```ts
2330
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
2007
+ * import { ChainId } from '@human-protocol/sdk';
2331
2008
  *
2332
2009
  * const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
2333
2010
  * chainId: ChainId.POLYGON_AMOY,
2334
2011
  * escrowAddress: '0x1234567890123456789012345678901234567890',
2335
2012
  * });
2336
- * console.log(cancellationRefunds);
2013
+ * console.log('Cancellation refunds:', cancellationRefunds.length);
2337
2014
  * ```
2338
2015
  */
2339
2016
  public static async getCancellationRefunds(
@@ -2391,45 +2068,25 @@ export class EscrowUtils {
2391
2068
  *
2392
2069
  * > This uses Subgraph
2393
2070
  *
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
- * ```
2071
+ * @param chainId - Network in which the escrow has been deployed
2072
+ * @param escrowAddress - Address of the escrow
2073
+ * @param options - Optional configuration for subgraph requests.
2074
+ * @returns Cancellation refund data or null if not found.
2075
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
2076
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
2408
2077
  *
2078
+ * @example
2409
2079
  * ```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
2080
+ * import { ChainId } from '@human-protocol/sdk';
2426
2081
  *
2427
- * **Code example**
2428
2082
  *
2429
- * ```ts
2430
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
2431
- *
2432
- * const cancellationRefund = await EscrowUtils.getCancellationRefund(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
2083
+ * const cancellationRefund = await EscrowUtils.getCancellationRefund(
2084
+ * ChainId.POLYGON_AMOY,
2085
+ * "0x1234567890123456789012345678901234567890"
2086
+ * );
2087
+ * if (cancellationRefund) {
2088
+ * console.log('Refund amount:', cancellationRefund.amount);
2089
+ * }
2433
2090
  * ```
2434
2091
  */
2435
2092
  public static async getCancellationRefund(