@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/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);
@@ -169,7 +139,7 @@ class EscrowClient extends base_1.BaseEthersClient {
169
139
  throw error_1.ErrorInvalidTokenAddress;
170
140
  }
171
141
  try {
172
- const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress, jobRequesterId, txOptions)).wait();
142
+ const result = await this.sendTxAndWait((overrides) => this.escrowFactoryContract.createEscrow(tokenAddress, jobRequesterId, overrides), txOptions);
173
143
  const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
174
144
  if (!event) {
175
145
  throw error_1.ErrorLaunchedEventIsNotEmitted;
@@ -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)) {
@@ -271,7 +236,7 @@ class EscrowClient extends base_1.BaseEthersClient {
271
236
  this.verifySetupParameters(escrowConfig);
272
237
  const { recordingOracle, reputationOracle, exchangeOracle, recordingOracleFee, reputationOracleFee, exchangeOracleFee, manifest, manifestHash, } = escrowConfig;
273
238
  try {
274
- const result = await (await this.escrowFactoryContract.createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, txOptions)).wait();
239
+ const result = await this.sendTxAndWait((overrides) => this.escrowFactoryContract.createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, overrides), txOptions);
275
240
  const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
276
241
  if (!event) {
277
242
  throw error_1.ErrorLaunchedEventIsNotEmitted;
@@ -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
- *
293
- *
294
- * **Code example**
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
295
268
  *
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
  * };
@@ -331,7 +294,7 @@ class EscrowClient extends base_1.BaseEthersClient {
331
294
  }
332
295
  try {
333
296
  const escrowContract = this.getEscrowContract(escrowAddress);
334
- await (await escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, txOptions)).wait();
297
+ await this.sendTxAndWait((overrides) => escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, overrides), txOptions);
335
298
  return;
336
299
  }
337
300
  catch (e) {
@@ -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';
317
+ * import { ethers } from 'ethers';
355
318
  *
356
- * const rpcUrl = 'YOUR_RPC_URL';
357
- * const privateKey = 'YOUR_PRIVATE_KEY';
358
- *
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
  */
@@ -378,7 +334,7 @@ class EscrowClient extends base_1.BaseEthersClient {
378
334
  const escrowContract = this.getEscrowContract(escrowAddress);
379
335
  const tokenAddress = await escrowContract.token();
380
336
  const tokenContract = typechain_types_1.HMToken__factory.connect(tokenAddress, this.runner);
381
- await (await tokenContract.transfer(escrowAddress, amount, txOptions)).wait();
337
+ await this.sendTxAndWait((overrides) => tokenContract.transfer(escrowAddress, amount, overrides), txOptions);
382
338
  return;
383
339
  }
384
340
  catch (e) {
@@ -389,7 +345,7 @@ class EscrowClient extends base_1.BaseEthersClient {
389
345
  const escrowContract = this.getEscrowContract(escrowAddress);
390
346
  const hasFundsToReserveParam = typeof a === 'bigint';
391
347
  const fundsToReserve = hasFundsToReserveParam ? a : null;
392
- const txOptions = (hasFundsToReserveParam ? b : a) || {};
348
+ const txOptions = (hasFundsToReserveParam ? b : a);
393
349
  // When fundsToReserve is provided and is 0, allow empty URL.
394
350
  // In this situation not solutions might have been provided so the escrow can be straight cancelled.
395
351
  const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
@@ -406,12 +362,10 @@ class EscrowClient extends base_1.BaseEthersClient {
406
362
  throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
407
363
  }
408
364
  try {
409
- if (fundsToReserve !== null) {
410
- await (await escrowContract['storeResults(string,string,uint256)'](url, hash, fundsToReserve, txOptions)).wait();
411
- }
412
- else {
413
- await (await escrowContract['storeResults(string,string)'](url, hash, txOptions)).wait();
414
- }
365
+ const txFactory = (overrides) => fundsToReserve !== null
366
+ ? escrowContract['storeResults(string,string,uint256)'](url, hash, fundsToReserve, overrides)
367
+ : escrowContract['storeResults(string,string)'](url, hash, overrides);
368
+ await this.sendTxAndWait(txFactory, txOptions);
415
369
  }
416
370
  catch (e) {
417
371
  if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
@@ -424,27 +378,15 @@ class EscrowClient extends base_1.BaseEthersClient {
424
378
  }
425
379
  /**
426
380
  * This function sets the status of an escrow to completed.
381
+ * @remarks Only Recording Oracle or admin can call it.
382
+ * @param escrowAddress - Address of the escrow.
383
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
384
+ * @returns -
385
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid.
386
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory.
427
387
  *
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
- *
388
+ * @example
437
389
  * ```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
390
  * await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
449
391
  * ```
450
392
  */
@@ -457,7 +399,7 @@ class EscrowClient extends base_1.BaseEthersClient {
457
399
  }
458
400
  try {
459
401
  const escrowContract = this.getEscrowContract(escrowAddress);
460
- await (await escrowContract.complete(txOptions)).wait();
402
+ await this.sendTxAndWait((overrides) => escrowContract.complete(overrides), txOptions);
461
403
  return;
462
404
  }
463
405
  catch (e) {
@@ -469,12 +411,10 @@ class EscrowClient extends base_1.BaseEthersClient {
469
411
  const escrowContract = this.getEscrowContract(escrowAddress);
470
412
  const idIsString = typeof id === 'string';
471
413
  try {
472
- if (idIsString) {
473
- await (await escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
474
- }
475
- else {
476
- await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
477
- }
414
+ const txFactory = (overrides) => idIsString
415
+ ? escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, overrides)
416
+ : escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, overrides);
417
+ await this.sendTxAndWait(txFactory, txOptions);
478
418
  }
479
419
  catch (e) {
480
420
  if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
@@ -487,26 +427,16 @@ class EscrowClient extends base_1.BaseEthersClient {
487
427
  }
488
428
  /**
489
429
  * This function cancels the specified escrow and sends the balance to the canceler.
430
+ * @remarks Only Job Launcher or admin can call it.
431
+ * @param escrowAddress - Address of the escrow to cancel.
432
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
433
+ * @returns -
434
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
435
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
490
436
  *
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.
437
+ * @example
498
438
  *
499
439
  * ```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
440
  * await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
511
441
  * ```
512
442
  */
@@ -519,7 +449,7 @@ class EscrowClient extends base_1.BaseEthersClient {
519
449
  }
520
450
  try {
521
451
  const escrowContract = this.getEscrowContract(escrowAddress);
522
- await (await escrowContract.cancel(txOptions)).wait();
452
+ await this.sendTxAndWait((overrides) => escrowContract.cancel(overrides), txOptions);
523
453
  }
524
454
  catch (e) {
525
455
  return (0, utils_1.throwError)(e);
@@ -527,26 +457,16 @@ class EscrowClient extends base_1.BaseEthersClient {
527
457
  }
528
458
  /**
529
459
  * This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
460
+ * @remarks Only Job Launcher or admin can call it.
461
+ * @param escrowAddress - Address of the escrow to request cancellation.
462
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
463
+ * @returns -
464
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
465
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
530
466
  *
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.
467
+ * @example
538
468
  *
539
469
  * ```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
470
  * await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
551
471
  * ```
552
472
  */
@@ -559,7 +479,7 @@ class EscrowClient extends base_1.BaseEthersClient {
559
479
  }
560
480
  try {
561
481
  const escrowContract = this.getEscrowContract(escrowAddress);
562
- await (await escrowContract.requestCancellation(txOptions)).wait();
482
+ await this.sendTxAndWait((overrides) => escrowContract.requestCancellation(overrides), txOptions);
563
483
  }
564
484
  catch (e) {
565
485
  return (0, utils_1.throwError)(e);
@@ -567,32 +487,25 @@ class EscrowClient extends base_1.BaseEthersClient {
567
487
  }
568
488
  /**
569
489
  * This function withdraws additional tokens in the escrow to the canceler.
490
+ * @remarks Only Job Launcher or admin can call it.
570
491
  *
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
- *
492
+ * @param escrowAddress - Address of the escrow to withdraw.
493
+ * @param tokenAddress - Address of the token to withdraw.
494
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
495
+ * @returns Returns the escrow withdrawal data including transaction hash and withdrawal amount.
496
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
497
+ * @throws ErrorInvalidTokenAddress If the token address is invalid
498
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
499
+ * @throws ErrorTransferEventNotFoundInTransactionLogs If the Transfer event is not found in transaction logs
576
500
  *
577
- * **Code example**
578
- *
579
- * > Only Job Launcher or admin can call it.
501
+ * @example
580
502
  *
581
503
  * ```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(
504
+ * const withdrawData = await escrowClient.withdraw(
593
505
  * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
594
506
  * '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
595
507
  * );
508
+ * console.log('Withdrawn amount:', withdrawData.withdrawnAmount);
596
509
  * ```
597
510
  */
598
511
  async withdraw(escrowAddress, tokenAddress, txOptions = {}) {
@@ -607,7 +520,7 @@ class EscrowClient extends base_1.BaseEthersClient {
607
520
  }
608
521
  try {
609
522
  const escrowContract = this.getEscrowContract(escrowAddress);
610
- const transactionReceipt = await (await escrowContract.withdraw(tokenAddress, txOptions)).wait();
523
+ const transactionReceipt = await this.sendTxAndWait((overrides) => escrowContract.withdraw(tokenAddress, overrides), txOptions);
611
524
  let amountTransferred = undefined;
612
525
  const tokenContract = typechain_types_1.ERC20__factory.connect(tokenAddress, this.runner);
613
526
  if (transactionReceipt)
@@ -639,43 +552,54 @@ class EscrowClient extends base_1.BaseEthersClient {
639
552
  }
640
553
  /**
641
554
  * 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**
555
+ * @remarks Only Reputation Oracle or admin can call it.
556
+ *
557
+ * @param escrowAddress - Escrow address to payout.
558
+ * @param recipients - Array of recipient addresses.
559
+ * @param amounts - Array of amounts the recipients will receive.
560
+ * @param finalResultsUrl - Final results file URL.
561
+ * @param finalResultsHash - Final results file hash.
562
+ * @param payoutId - Payout ID to identify the payout.
563
+ * @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
564
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
565
+ * @returns Returns object with raw transaction and nonce
566
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
567
+ * @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
568
+ * @throws ErrorTooManyRecipients If there are too many recipients
569
+ * @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
570
+ * @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
571
+ * @throws InvalidEthereumAddressError If any recipient address is invalid
572
+ * @throws ErrorInvalidUrl If the final results URL is invalid
573
+ * @throws ErrorHashIsEmptyString If the final results hash is empty
574
+ * @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
575
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
653
576
  *
654
- * > Only Reputation Oracle or admin can call it.
577
+ * @example
655
578
  *
656
579
  * ```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'
580
+ * import { ethers } from 'ethers';
581
+ * import { v4 as uuidV4 } from 'uuid';
662
582
  *
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')];
583
+ * const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
584
+ * const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
669
585
  * const resultsUrl = 'http://localhost/results.json';
670
586
  * const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
671
- * const payoutId = '372f6916-fe34-4711-b6e3-274f682047de';
672
- *
673
- * const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
587
+ * const payoutId = uuidV4();
588
+ *
589
+ * const rawTransaction = await escrowClient.createBulkPayoutTransaction(
590
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
591
+ * recipients,
592
+ * amounts,
593
+ * resultsUrl,
594
+ * resultsHash,
595
+ * payoutId
596
+ * );
674
597
  * console.log('Raw transaction:', rawTransaction);
675
598
  *
676
599
  * const signedTransaction = await signer.signTransaction(rawTransaction);
677
600
  * console.log('Tx hash:', ethers.keccak256(signedTransaction));
678
- * (await signer.sendTransaction(rawTransaction)).wait();
601
+ * await signer.sendTransaction(rawTransaction);
602
+ * ```
679
603
  */
680
604
  async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete = false, txOptions = {}) {
681
605
  await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
@@ -757,21 +681,15 @@ class EscrowClient extends base_1.BaseEthersClient {
757
681
  /**
758
682
  * This function returns the balance for a specified escrow address.
759
683
  *
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**
684
+ * @param escrowAddress - Address of the escrow.
685
+ * @returns Balance of the escrow in the token used to fund it.
686
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
687
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
764
688
  *
689
+ * @example
765
690
  * ```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
691
  * const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
692
+ * console.log('Balance:', balance);
775
693
  * ```
776
694
  */
777
695
  async getBalance(escrowAddress) {
@@ -798,21 +716,15 @@ class EscrowClient extends base_1.BaseEthersClient {
798
716
  /**
799
717
  * This function returns the reserved funds for a specified escrow address.
800
718
  *
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**
719
+ * @param escrowAddress - Address of the escrow.
720
+ * @returns Reserved funds of the escrow in the token used to fund it.
721
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
722
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
805
723
  *
724
+ * @example
806
725
  * ```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
726
  * const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
727
+ * console.log('Reserved funds:', reservedFunds);
816
728
  * ```
817
729
  */
818
730
  async getReservedFunds(escrowAddress) {
@@ -833,21 +745,15 @@ class EscrowClient extends base_1.BaseEthersClient {
833
745
  /**
834
746
  * This function returns the manifest file hash.
835
747
  *
836
- * @param {string} escrowAddress Address of the escrow.
837
- * @returns {Promise<string>} Hash of the manifest file content.
838
- *
839
- * **Code example**
748
+ * @param escrowAddress - Address of the escrow.
749
+ * @returns Hash of the manifest file content.
750
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
751
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
840
752
  *
753
+ * @example
841
754
  * ```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
755
  * const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
756
+ * console.log('Manifest hash:', manifestHash);
851
757
  * ```
852
758
  */
853
759
  async getManifestHash(escrowAddress) {
@@ -868,21 +774,15 @@ class EscrowClient extends base_1.BaseEthersClient {
868
774
  /**
869
775
  * This function returns the manifest. Could be a URL or a JSON string.
870
776
  *
871
- * @param {string} escrowAddress Address of the escrow.
872
- * @returns {Promise<string>} Url of the manifest.
873
- *
874
- * **Code example**
777
+ * @param escrowAddress - Address of the escrow.
778
+ * @returns Manifest URL or JSON string.
779
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
780
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
875
781
  *
782
+ * @example
876
783
  * ```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
784
  * const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
785
+ * console.log('Manifest:', manifest);
886
786
  * ```
887
787
  */
888
788
  async getManifest(escrowAddress) {
@@ -903,21 +803,15 @@ class EscrowClient extends base_1.BaseEthersClient {
903
803
  /**
904
804
  * This function returns the results file URL.
905
805
  *
906
- * @param {string} escrowAddress Address of the escrow.
907
- * @returns {Promise<string>} Results file url.
908
- *
909
- * **Code example**
806
+ * @param escrowAddress - Address of the escrow.
807
+ * @returns Results file URL.
808
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
809
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
910
810
  *
811
+ * @example
911
812
  * ```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
813
  * const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
814
+ * console.log('Results URL:', resultsUrl);
921
815
  * ```
922
816
  */
923
817
  async getResultsUrl(escrowAddress) {
@@ -938,21 +832,15 @@ class EscrowClient extends base_1.BaseEthersClient {
938
832
  /**
939
833
  * This function returns the intermediate results file URL.
940
834
  *
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**
835
+ * @param escrowAddress - Address of the escrow.
836
+ * @returns URL of the file that stores results from Recording Oracle.
837
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
838
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
945
839
  *
840
+ * @example
946
841
  * ```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
842
  * const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
843
+ * console.log('Intermediate results URL:', intermediateResultsUrl);
956
844
  * ```
957
845
  */
958
846
  async getIntermediateResultsUrl(escrowAddress) {
@@ -973,21 +861,15 @@ class EscrowClient extends base_1.BaseEthersClient {
973
861
  /**
974
862
  * This function returns the intermediate results hash.
975
863
  *
976
- * @param {string} escrowAddress Address of the escrow.
977
- * @returns {Promise<string>} Hash of the intermediate results file content.
978
- *
979
- * **Code example**
864
+ * @param escrowAddress - Address of the escrow.
865
+ * @returns Hash of the intermediate results file content.
866
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
867
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
980
868
  *
869
+ * @example
981
870
  * ```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
871
  * const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
872
+ * console.log('Intermediate results hash:', intermediateResultsHash);
991
873
  * ```
992
874
  */
993
875
  async getIntermediateResultsHash(escrowAddress) {
@@ -1008,21 +890,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1008
890
  /**
1009
891
  * This function returns the token address used for funding the escrow.
1010
892
  *
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**
893
+ * @param escrowAddress - Address of the escrow.
894
+ * @returns Address of the token used to fund the escrow.
895
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
896
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1015
897
  *
898
+ * @example
1016
899
  * ```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
900
  * const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
901
+ * console.log('Token address:', tokenAddress);
1026
902
  * ```
1027
903
  */
1028
904
  async getTokenAddress(escrowAddress) {
@@ -1043,21 +919,17 @@ class EscrowClient extends base_1.BaseEthersClient {
1043
919
  /**
1044
920
  * This function returns the current status of the escrow.
1045
921
  *
1046
- * @param {string} escrowAddress Address of the escrow.
1047
- * @returns {Promise<EscrowStatus>} Current status of the escrow.
1048
- *
1049
- * **Code example**
922
+ * @param escrowAddress - Address of the escrow.
923
+ * @returns Current status of the escrow.
924
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
925
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1050
926
  *
927
+ * @example
1051
928
  * ```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);
929
+ * import { EscrowStatus } from '@human-protocol/sdk';
1059
930
  *
1060
931
  * const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
932
+ * console.log('Status:', EscrowStatus[status]);
1061
933
  * ```
1062
934
  */
1063
935
  async getStatus(escrowAddress) {
@@ -1078,21 +950,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1078
950
  /**
1079
951
  * This function returns the recording oracle address for a given escrow.
1080
952
  *
1081
- * @param {string} escrowAddress Address of the escrow.
1082
- * @returns {Promise<string>} Address of the Recording Oracle.
1083
- *
1084
- * **Code example**
953
+ * @param escrowAddress - Address of the escrow.
954
+ * @returns Address of the Recording Oracle.
955
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
956
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1085
957
  *
958
+ * @example
1086
959
  * ```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
960
  * const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
961
+ * console.log('Recording Oracle address:', oracleAddress);
1096
962
  * ```
1097
963
  */
1098
964
  async getRecordingOracleAddress(escrowAddress) {
@@ -1113,21 +979,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1113
979
  /**
1114
980
  * This function returns the job launcher address for a given escrow.
1115
981
  *
1116
- * @param {string} escrowAddress Address of the escrow.
1117
- * @returns {Promise<string>} Address of the Job Launcher.
1118
- *
1119
- * **Code example**
982
+ * @param escrowAddress - Address of the escrow.
983
+ * @returns Address of the Job Launcher.
984
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
985
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1120
986
  *
987
+ * @example
1121
988
  * ```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
989
  * const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
990
+ * console.log('Job Launcher address:', jobLauncherAddress);
1131
991
  * ```
1132
992
  */
1133
993
  async getJobLauncherAddress(escrowAddress) {
@@ -1148,21 +1008,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1148
1008
  /**
1149
1009
  * This function returns the reputation oracle address for a given escrow.
1150
1010
  *
1151
- * @param {string} escrowAddress Address of the escrow.
1152
- * @returns {Promise<string>} Address of the Reputation Oracle.
1153
- *
1154
- * **Code example**
1011
+ * @param escrowAddress - Address of the escrow.
1012
+ * @returns Address of the Reputation Oracle.
1013
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1014
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1155
1015
  *
1016
+ * @example
1156
1017
  * ```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
1018
  * const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1019
+ * console.log('Reputation Oracle address:', oracleAddress);
1166
1020
  * ```
1167
1021
  */
1168
1022
  async getReputationOracleAddress(escrowAddress) {
@@ -1183,21 +1037,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1183
1037
  /**
1184
1038
  * This function returns the exchange oracle address for a given escrow.
1185
1039
  *
1186
- * @param {string} escrowAddress Address of the escrow.
1187
- * @returns {Promise<string>} Address of the Exchange Oracle.
1188
- *
1189
- * **Code example**
1040
+ * @param escrowAddress - Address of the escrow.
1041
+ * @returns Address of the Exchange Oracle.
1042
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1043
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1190
1044
  *
1045
+ * @example
1191
1046
  * ```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
1047
  * const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1048
+ * console.log('Exchange Oracle address:', oracleAddress);
1201
1049
  * ```
1202
1050
  */
1203
1051
  async getExchangeOracleAddress(escrowAddress) {
@@ -1218,21 +1066,15 @@ class EscrowClient extends base_1.BaseEthersClient {
1218
1066
  /**
1219
1067
  * This function returns the escrow factory address for a given escrow.
1220
1068
  *
1221
- * @param {string} escrowAddress Address of the escrow.
1222
- * @returns {Promise<string>} Address of the escrow factory.
1223
- *
1224
- * **Code example**
1069
+ * @param escrowAddress - Address of the escrow.
1070
+ * @returns Address of the escrow factory.
1071
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1072
+ * @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
1225
1073
  *
1074
+ * @example
1226
1075
  * ```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
1076
  * const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
1077
+ * console.log('Factory address:', factoryAddress);
1236
1078
  * ```
1237
1079
  */
1238
1080
  async getFactoryAddress(escrowAddress) {
@@ -1319,138 +1161,40 @@ __decorate([
1319
1161
  __metadata("design:returntype", Promise)
1320
1162
  ], EscrowClient.prototype, "createBulkPayoutTransaction", null);
1321
1163
  /**
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)**
1164
+ * Utility helpers for escrow-related queries.
1343
1165
  *
1166
+ * @example
1344
1167
  * ```ts
1345
1168
  * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1346
1169
  *
1347
- * const escrowAddresses = new EscrowUtils.getEscrows({
1170
+ * const escrows = await EscrowUtils.getEscrows({
1348
1171
  * chainId: ChainId.POLYGON_AMOY
1349
1172
  * });
1173
+ * console.log('Escrows:', escrows);
1350
1174
  * ```
1351
1175
  */
1352
1176
  class EscrowUtils {
1353
1177
  /**
1354
1178
  * This function returns an array of escrows based on the specified filter parameters.
1355
1179
  *
1180
+ * @param filter - Filter parameters.
1181
+ * @param options - Optional configuration for subgraph requests.
1182
+ * @returns List of escrows that match the filter.
1183
+ * @throws ErrorInvalidAddress If any filter address is invalid
1184
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1356
1185
  *
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
- *
1186
+ * @example
1444
1187
  * ```ts
1445
- * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1188
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1446
1189
  *
1447
- * const filters: IEscrowsFilter = {
1190
+ * const filters = {
1448
1191
  * status: EscrowStatus.Pending,
1449
1192
  * from: new Date(2023, 4, 8),
1450
1193
  * to: new Date(2023, 5, 8),
1451
1194
  * chainId: ChainId.POLYGON_AMOY
1452
1195
  * };
1453
1196
  * const escrows = await EscrowUtils.getEscrows(filters);
1197
+ * console.log('Found escrows:', escrows.length);
1454
1198
  * ```
1455
1199
  */
1456
1200
  static async getEscrows(filter, options) {
@@ -1498,63 +1242,24 @@ class EscrowUtils {
1498
1242
  *
1499
1243
  * > This uses Subgraph
1500
1244
  *
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**
1245
+ * @param chainId - Network in which the escrow has been deployed
1246
+ * @param escrowAddress - Address of the escrow
1247
+ * @param options - Optional configuration for subgraph requests.
1248
+ * @returns Escrow data or null if not found.
1249
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1250
+ * @throws ErrorInvalidAddress If the escrow address is invalid
1553
1251
  *
1252
+ * @example
1554
1253
  * ```ts
1555
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1254
+ * import { ChainId } from '@human-protocol/sdk';
1556
1255
  *
1557
- * const escrow = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
1256
+ * const escrow = await EscrowUtils.getEscrow(
1257
+ * ChainId.POLYGON_AMOY,
1258
+ * "0x1234567890123456789012345678901234567890"
1259
+ * );
1260
+ * if (escrow) {
1261
+ * console.log('Escrow status:', escrow.status);
1262
+ * }
1558
1263
  * ```
1559
1264
  */
1560
1265
  static async getEscrow(chainId, escrowAddress, options) {
@@ -1575,56 +1280,25 @@ class EscrowUtils {
1575
1280
  *
1576
1281
  * > This uses Subgraph
1577
1282
  *
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
- * ```
1283
+ * @param filter - Filter parameters.
1284
+ * @param options - Optional configuration for subgraph requests.
1285
+ * @returns Array of status events with their corresponding statuses.
1286
+ * @throws ErrorInvalidAddress If the launcher address is invalid
1287
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1599
1288
  *
1289
+ * @example
1600
1290
  * ```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.
1291
+ * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1611
1292
  *
1612
- * **Code example**
1613
- *
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
- * })();
1293
+ * const fromDate = new Date('2023-01-01');
1294
+ * const toDate = new Date('2023-12-31');
1295
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1296
+ * chainId: ChainId.POLYGON,
1297
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1298
+ * from: fromDate,
1299
+ * to: toDate
1300
+ * });
1301
+ * console.log('Status events:', statusEvents.length);
1628
1302
  * ```
1629
1303
  */
1630
1304
  static async getStatusEvents(filter, options) {
@@ -1670,17 +1344,15 @@ class EscrowUtils {
1670
1344
  *
1671
1345
  * > This uses Subgraph
1672
1346
  *
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**
1347
+ * @param filter - Filter parameters.
1348
+ * @param options - Optional configuration for subgraph requests.
1349
+ * @returns List of payouts matching the filters.
1350
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1351
+ * @throws ErrorInvalidAddress If any filter address is invalid
1681
1352
  *
1353
+ * @example
1682
1354
  * ```ts
1683
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1355
+ * import { ChainId } from '@human-protocol/sdk';
1684
1356
  *
1685
1357
  * const payouts = await EscrowUtils.getPayouts({
1686
1358
  * chainId: ChainId.POLYGON,
@@ -1689,7 +1361,7 @@ class EscrowUtils {
1689
1361
  * from: new Date('2023-01-01'),
1690
1362
  * to: new Date('2023-12-31')
1691
1363
  * });
1692
- * console.log(payouts);
1364
+ * console.log('Payouts:', payouts.length);
1693
1365
  * ```
1694
1366
  */
1695
1367
  static async getPayouts(filter, options) {
@@ -1731,48 +1403,22 @@ class EscrowUtils {
1731
1403
  *
1732
1404
  * > This uses Subgraph
1733
1405
  *
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**
1406
+ * @param filter - Filter parameters.
1407
+ * @param options - Optional configuration for subgraph requests.
1408
+ * @returns List of cancellation refunds matching the filters.
1409
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1410
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1411
+ * @throws ErrorInvalidAddress If the receiver address is invalid
1767
1412
  *
1413
+ * @example
1768
1414
  * ```ts
1769
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1415
+ * import { ChainId } from '@human-protocol/sdk';
1770
1416
  *
1771
1417
  * const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
1772
1418
  * chainId: ChainId.POLYGON_AMOY,
1773
1419
  * escrowAddress: '0x1234567890123456789012345678901234567890',
1774
1420
  * });
1775
- * console.log(cancellationRefunds);
1421
+ * console.log('Cancellation refunds:', cancellationRefunds.length);
1776
1422
  * ```
1777
1423
  */
1778
1424
  static async getCancellationRefunds(filter, options) {
@@ -1815,45 +1461,25 @@ class EscrowUtils {
1815
1461
  *
1816
1462
  * > This uses Subgraph
1817
1463
  *
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
- * ```
1464
+ * @param chainId - Network in which the escrow has been deployed
1465
+ * @param escrowAddress - Address of the escrow
1466
+ * @param options - Optional configuration for subgraph requests.
1467
+ * @returns Cancellation refund data or null if not found.
1468
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
1469
+ * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1832
1470
  *
1471
+ * @example
1833
1472
  * ```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
- *
1473
+ * import { ChainId } from '@human-protocol/sdk';
1845
1474
  *
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
1475
  *
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");
1476
+ * const cancellationRefund = await EscrowUtils.getCancellationRefund(
1477
+ * ChainId.POLYGON_AMOY,
1478
+ * "0x1234567890123456789012345678901234567890"
1479
+ * );
1480
+ * if (cancellationRefund) {
1481
+ * console.log('Refund amount:', cancellationRefund.amount);
1482
+ * }
1857
1483
  * ```
1858
1484
  */
1859
1485
  static async getCancellationRefund(chainId, escrowAddress, options) {