@human-protocol/sdk 5.0.0-beta.3 → 5.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 (52) hide show
  1. package/dist/base.d.ts +1 -10
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +0 -21
  4. package/dist/constants.d.ts +0 -1
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +7 -22
  7. package/dist/enums.d.ts +0 -1
  8. package/dist/enums.d.ts.map +1 -1
  9. package/dist/enums.js +0 -1
  10. package/dist/error.d.ts +4 -0
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/error.js +5 -1
  13. package/dist/escrow.d.ts +75 -19
  14. package/dist/escrow.d.ts.map +1 -1
  15. package/dist/escrow.js +144 -58
  16. package/dist/interfaces.d.ts +9 -0
  17. package/dist/interfaces.d.ts.map +1 -1
  18. package/dist/kvstore.d.ts +9 -5
  19. package/dist/kvstore.d.ts.map +1 -1
  20. package/dist/kvstore.js +15 -15
  21. package/dist/operator.d.ts +9 -5
  22. package/dist/operator.d.ts.map +1 -1
  23. package/dist/operator.js +16 -16
  24. package/dist/staking.d.ts +6 -3
  25. package/dist/staking.d.ts.map +1 -1
  26. package/dist/staking.js +13 -14
  27. package/dist/statistics.d.ts +13 -7
  28. package/dist/statistics.d.ts.map +1 -1
  29. package/dist/statistics.js +24 -22
  30. package/dist/transaction.d.ts +5 -3
  31. package/dist/transaction.d.ts.map +1 -1
  32. package/dist/transaction.js +8 -10
  33. package/dist/utils.d.ts +7 -0
  34. package/dist/utils.d.ts.map +1 -1
  35. package/dist/utils.js +51 -1
  36. package/dist/worker.d.ts +5 -3
  37. package/dist/worker.d.ts.map +1 -1
  38. package/dist/worker.js +8 -10
  39. package/package.json +3 -2
  40. package/src/base.ts +1 -23
  41. package/src/constants.ts +6 -24
  42. package/src/enums.ts +0 -1
  43. package/src/error.ts +7 -0
  44. package/src/escrow.ts +232 -97
  45. package/src/interfaces.ts +10 -0
  46. package/src/kvstore.ts +26 -24
  47. package/src/operator.ts +54 -26
  48. package/src/staking.ts +27 -26
  49. package/src/statistics.ts +87 -47
  50. package/src/transaction.ts +39 -25
  51. package/src/utils.ts +64 -0
  52. package/src/worker.ts +32 -17
package/src/error.ts CHANGED
@@ -306,6 +306,13 @@ export const ErrorBulkPayOutVersion = new Error(
306
306
  'Invalid bulkPayOut parameters for the contract version of the specified escrow address'
307
307
  );
308
308
 
309
+ /**
310
+ * @constant {Error} - Retry configuration is missing required parameters.
311
+ */
312
+ export const ErrorRetryParametersMissing = new Error(
313
+ 'Retry configuration must include both maxRetries and baseDelay'
314
+ );
315
+
309
316
  /**
310
317
  * @constant {Warning} - Possible version mismatch.
311
318
  */
package/src/escrow.ts CHANGED
@@ -10,7 +10,6 @@ import {
10
10
  HMToken__factory,
11
11
  } from '@human-protocol/core/typechain-types';
12
12
  import { ContractRunner, EventLog, Overrides, Signer, ethers } from 'ethers';
13
- import gqlFetch from 'graphql-request';
14
13
  import { BaseEthersClient } from './base';
15
14
  import { ESCROW_BULK_PAYOUT_MAX_ITEMS, NETWORKS } from './constants';
16
15
  import { requiresSigner } from './decorators';
@@ -62,13 +61,16 @@ import {
62
61
  IStatusEventFilter,
63
62
  IStatusEvent,
64
63
  ICancellationRefund,
64
+ ICancellationRefundFilter,
65
65
  IPayout,
66
66
  IEscrowWithdraw,
67
+ SubgraphOptions,
67
68
  } from './interfaces';
68
69
  import { EscrowStatus, NetworkData, TransactionLikeWithNonce } from './types';
69
70
  import {
70
71
  getSubgraphUrl,
71
72
  getUnixTimestamp,
73
+ customGqlFetch,
72
74
  isValidJson,
73
75
  isValidUrl,
74
76
  throwError,
@@ -203,8 +205,8 @@ export class EscrowClient extends BaseEthersClient {
203
205
  /**
204
206
  * This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
205
207
  *
206
- * @param {string} tokenAddress Token address to use for payouts.
207
- * @param {string} jobRequesterId Job Requester Id
208
+ * @param {string} tokenAddress - The address of the token to use for escrow funding.
209
+ * @param {string} jobRequesterId - Identifier for the job requester.
208
210
  * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
209
211
  * @returns {Promise<string>} Returns the address of the escrow created.
210
212
  *
@@ -244,7 +246,168 @@ export class EscrowClient extends BaseEthersClient {
244
246
  await this.escrowFactoryContract.createEscrow(
245
247
  tokenAddress,
246
248
  jobRequesterId,
247
- this.applyTxDefaults(txOptions)
249
+ txOptions
250
+ )
251
+ ).wait();
252
+
253
+ const event = (
254
+ result?.logs?.find(({ topics }) =>
255
+ topics.includes(ethers.id('LaunchedV2(address,address,string)'))
256
+ ) as EventLog
257
+ )?.args;
258
+
259
+ if (!event) {
260
+ throw ErrorLaunchedEventIsNotEmitted;
261
+ }
262
+
263
+ return event.escrow;
264
+ } catch (e: any) {
265
+ return throwError(e);
266
+ }
267
+ }
268
+ private verifySetupParameters(escrowConfig: IEscrowConfig) {
269
+ const {
270
+ recordingOracle,
271
+ reputationOracle,
272
+ exchangeOracle,
273
+ recordingOracleFee,
274
+ reputationOracleFee,
275
+ exchangeOracleFee,
276
+ manifest,
277
+ manifestHash,
278
+ } = escrowConfig;
279
+
280
+ if (!ethers.isAddress(recordingOracle)) {
281
+ throw ErrorInvalidRecordingOracleAddressProvided;
282
+ }
283
+
284
+ if (!ethers.isAddress(reputationOracle)) {
285
+ throw ErrorInvalidReputationOracleAddressProvided;
286
+ }
287
+
288
+ if (!ethers.isAddress(exchangeOracle)) {
289
+ throw ErrorInvalidExchangeOracleAddressProvided;
290
+ }
291
+
292
+ if (
293
+ recordingOracleFee <= 0 ||
294
+ reputationOracleFee <= 0 ||
295
+ exchangeOracleFee <= 0
296
+ ) {
297
+ throw ErrorAmountMustBeGreaterThanZero;
298
+ }
299
+
300
+ if (recordingOracleFee + reputationOracleFee + exchangeOracleFee > 100) {
301
+ throw ErrorTotalFeeMustBeLessThanHundred;
302
+ }
303
+
304
+ const isManifestValid = isValidUrl(manifest) || isValidJson(manifest);
305
+ if (!isManifestValid) {
306
+ throw ErrorInvalidManifest;
307
+ }
308
+
309
+ if (!manifestHash) {
310
+ throw ErrorHashIsEmptyString;
311
+ }
312
+ }
313
+
314
+ /**
315
+ * Creates, funds, and sets up a new escrow contract in a single transaction.
316
+ *
317
+ * @param {string} tokenAddress - The ERC-20 token address used to fund the escrow.
318
+ * @param {bigint} amount - The token amount to fund the escrow with.
319
+ * @param {string} jobRequesterId - An off-chain identifier for the job requester.
320
+ * @param {IEscrowConfig} escrowConfig - Configuration parameters for escrow setup:
321
+ * - `recordingOracle`: Address of the recording oracle.
322
+ * - `reputationOracle`: Address of the reputation oracle.
323
+ * - `exchangeOracle`: Address of the exchange oracle.
324
+ * - `recordingOracleFee`: Fee (in basis points or percentage * 100) for the recording oracle.
325
+ * - `reputationOracleFee`: Fee for the reputation oracle.
326
+ * - `exchangeOracleFee`: Fee for the exchange oracle.
327
+ * - `manifest`: URL to the manifest file.
328
+ * - `manifestHash`: Hash of the manifest content.
329
+ * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
330
+ *
331
+ * @returns {Promise<string>} Returns the address of the escrow created.
332
+ *
333
+ * @example
334
+ * import { Wallet, ethers } from 'ethers';
335
+ * import { EscrowClient, IERC20__factory } from '@human-protocol/sdk';
336
+ *
337
+ * const rpcUrl = 'YOUR_RPC_URL';
338
+ * const privateKey = 'YOUR_PRIVATE_KEY';
339
+ * const provider = new ethers.JsonRpcProvider(rpcUrl);
340
+ * const signer = new Wallet(privateKey, provider);
341
+ *
342
+ * const escrowClient = await EscrowClient.build(signer);
343
+ *
344
+ * const tokenAddress = '0xTokenAddress';
345
+ * const amount = ethers.parseUnits('1000', 18);
346
+ * const jobRequesterId = 'requester-123';
347
+ *
348
+ * const token = IERC20__factory.connect(tokenAddress, signer);
349
+ * await token.approve(escrowClient.escrowFactoryContract.target, amount);
350
+ *
351
+ * const escrowConfig = {
352
+ * recordingOracle: '0xRecordingOracle',
353
+ * reputationOracle: '0xReputationOracle',
354
+ * exchangeOracle: '0xExchangeOracle',
355
+ * recordingOracleFee: 5n,
356
+ * reputationOracleFee: 5n,
357
+ * exchangeOracleFee: 5n,
358
+ * manifest: 'https://example.com/manifest.json',
359
+ * manifestHash: 'manifestHash-123',
360
+ * } satisfies IEscrowConfig;
361
+ *
362
+ * const escrowAddress = await escrowClient.createFundAndSetupEscrow(
363
+ * tokenAddress,
364
+ * amount,
365
+ * jobRequesterId,
366
+ * escrowConfig
367
+ * );
368
+ *
369
+ * console.log('Escrow created at:', escrowAddress);
370
+ */
371
+ @requiresSigner
372
+ public async createFundAndSetupEscrow(
373
+ tokenAddress: string,
374
+ amount: bigint,
375
+ jobRequesterId: string,
376
+ escrowConfig: IEscrowConfig,
377
+ txOptions: Overrides = {}
378
+ ): Promise<string> {
379
+ if (!ethers.isAddress(tokenAddress)) {
380
+ throw ErrorInvalidTokenAddress;
381
+ }
382
+
383
+ this.verifySetupParameters(escrowConfig);
384
+
385
+ const {
386
+ recordingOracle,
387
+ reputationOracle,
388
+ exchangeOracle,
389
+ recordingOracleFee,
390
+ reputationOracleFee,
391
+ exchangeOracleFee,
392
+ manifest,
393
+ manifestHash,
394
+ } = escrowConfig;
395
+
396
+ try {
397
+ const result = await (
398
+ await this.escrowFactoryContract.createFundAndSetupEscrow(
399
+ tokenAddress,
400
+ amount,
401
+ jobRequesterId,
402
+ reputationOracle,
403
+ recordingOracle,
404
+ exchangeOracle,
405
+ reputationOracleFee,
406
+ recordingOracleFee,
407
+ exchangeOracleFee,
408
+ manifest,
409
+ manifestHash,
410
+ txOptions
248
411
  )
249
412
  ).wait();
250
413
 
@@ -319,43 +482,12 @@ export class EscrowClient extends BaseEthersClient {
319
482
  manifestHash,
320
483
  } = escrowConfig;
321
484
 
322
- if (!ethers.isAddress(recordingOracle)) {
323
- throw ErrorInvalidRecordingOracleAddressProvided;
324
- }
325
-
326
- if (!ethers.isAddress(reputationOracle)) {
327
- throw ErrorInvalidReputationOracleAddressProvided;
328
- }
329
-
330
- if (!ethers.isAddress(exchangeOracle)) {
331
- throw ErrorInvalidExchangeOracleAddressProvided;
332
- }
485
+ this.verifySetupParameters(escrowConfig);
333
486
 
334
487
  if (!ethers.isAddress(escrowAddress)) {
335
488
  throw ErrorInvalidEscrowAddressProvided;
336
489
  }
337
490
 
338
- if (
339
- recordingOracleFee <= 0 ||
340
- reputationOracleFee <= 0 ||
341
- exchangeOracleFee <= 0
342
- ) {
343
- throw ErrorAmountMustBeGreaterThanZero;
344
- }
345
-
346
- if (recordingOracleFee + reputationOracleFee + exchangeOracleFee > 100) {
347
- throw ErrorTotalFeeMustBeLessThanHundred;
348
- }
349
-
350
- const isManifestValid = isValidUrl(manifest) || isValidJson(manifest);
351
- if (!isManifestValid) {
352
- throw ErrorInvalidManifest;
353
- }
354
-
355
- if (!manifestHash) {
356
- throw ErrorHashIsEmptyString;
357
- }
358
-
359
491
  if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
360
492
  throw ErrorEscrowAddressIsNotProvidedByFactory;
361
493
  }
@@ -373,7 +505,7 @@ export class EscrowClient extends BaseEthersClient {
373
505
  exchangeOracleFee,
374
506
  manifest,
375
507
  manifestHash,
376
- this.applyTxDefaults(txOptions)
508
+ txOptions
377
509
  )
378
510
  ).wait();
379
511
 
@@ -437,11 +569,7 @@ export class EscrowClient extends BaseEthersClient {
437
569
  this.runner
438
570
  );
439
571
  await (
440
- await tokenContract.transfer(
441
- escrowAddress,
442
- amount,
443
- this.applyTxDefaults(txOptions)
444
- )
572
+ await tokenContract.transfer(escrowAddress, amount, txOptions)
445
573
  ).wait();
446
574
 
447
575
  return;
@@ -562,7 +690,7 @@ export class EscrowClient extends BaseEthersClient {
562
690
  url,
563
691
  hash,
564
692
  fundsToReserve,
565
- this.applyTxDefaults(txOptions)
693
+ txOptions
566
694
  )
567
695
  ).wait();
568
696
  } else {
@@ -570,7 +698,7 @@ export class EscrowClient extends BaseEthersClient {
570
698
  await escrowContract['storeResults(string,string)'](
571
699
  url,
572
700
  hash,
573
- this.applyTxDefaults(txOptions)
701
+ txOptions
574
702
  )
575
703
  ).wait();
576
704
  }
@@ -626,9 +754,7 @@ export class EscrowClient extends BaseEthersClient {
626
754
  try {
627
755
  const escrowContract = this.getEscrowContract(escrowAddress);
628
756
 
629
- await (
630
- await escrowContract.complete(this.applyTxDefaults(txOptions))
631
- ).wait();
757
+ await (await escrowContract.complete(txOptions)).wait();
632
758
  return;
633
759
  } catch (e) {
634
760
  return throwError(e);
@@ -768,7 +894,7 @@ export class EscrowClient extends BaseEthersClient {
768
894
  finalResultsHash,
769
895
  id,
770
896
  forceComplete,
771
- this.applyTxDefaults(txOptions)
897
+ txOptions
772
898
  )
773
899
  ).wait();
774
900
  } else {
@@ -782,7 +908,7 @@ export class EscrowClient extends BaseEthersClient {
782
908
  finalResultsHash,
783
909
  id,
784
910
  forceComplete,
785
- this.applyTxDefaults(txOptions)
911
+ txOptions
786
912
  )
787
913
  ).wait();
788
914
  }
@@ -836,9 +962,7 @@ export class EscrowClient extends BaseEthersClient {
836
962
 
837
963
  try {
838
964
  const escrowContract = this.getEscrowContract(escrowAddress);
839
- await (
840
- await escrowContract.cancel(this.applyTxDefaults(txOptions))
841
- ).wait();
965
+ await (await escrowContract.cancel(txOptions)).wait();
842
966
  } catch (e) {
843
967
  return throwError(e);
844
968
  }
@@ -884,11 +1008,7 @@ export class EscrowClient extends BaseEthersClient {
884
1008
 
885
1009
  try {
886
1010
  const escrowContract = this.getEscrowContract(escrowAddress);
887
- await (
888
- await escrowContract.requestCancellation(
889
- this.applyTxDefaults(txOptions)
890
- )
891
- ).wait();
1011
+ await (await escrowContract.requestCancellation(txOptions)).wait();
892
1012
  } catch (e) {
893
1013
  return throwError(e);
894
1014
  }
@@ -946,10 +1066,7 @@ export class EscrowClient extends BaseEthersClient {
946
1066
  const escrowContract = this.getEscrowContract(escrowAddress);
947
1067
 
948
1068
  const transactionReceipt = await (
949
- await escrowContract.withdraw(
950
- tokenAddress,
951
- this.applyTxDefaults(txOptions)
952
- )
1069
+ await escrowContract.withdraw(tokenAddress, txOptions)
953
1070
  ).wait();
954
1071
 
955
1072
  let amountTransferred: bigint | undefined = undefined;
@@ -1039,7 +1156,6 @@ export class EscrowClient extends BaseEthersClient {
1039
1156
  forceComplete = false,
1040
1157
  txOptions: Overrides = {}
1041
1158
  ): Promise<TransactionLikeWithNonce> {
1042
- txOptions = this.applyTxDefaults(txOptions);
1043
1159
  await this.ensureCorrectBulkPayoutInput(
1044
1160
  escrowAddress,
1045
1161
  recipients,
@@ -1810,6 +1926,7 @@ export class EscrowUtils {
1810
1926
  *
1811
1927
  *
1812
1928
  * @param {IEscrowsFilter} filter Filter parameters.
1929
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1813
1930
  * @returns {IEscrow[]} List of escrows that match the filter.
1814
1931
  *
1815
1932
  * **Code example**
@@ -1826,7 +1943,10 @@ export class EscrowUtils {
1826
1943
  * const escrows = await EscrowUtils.getEscrows(filters);
1827
1944
  * ```
1828
1945
  */
1829
- public static async getEscrows(filter: IEscrowsFilter): Promise<IEscrow[]> {
1946
+ public static async getEscrows(
1947
+ filter: IEscrowsFilter,
1948
+ options?: SubgraphOptions
1949
+ ): Promise<IEscrow[]> {
1830
1950
  if (filter.launcher && !ethers.isAddress(filter.launcher)) {
1831
1951
  throw ErrorInvalidAddress;
1832
1952
  }
@@ -1859,7 +1979,7 @@ export class EscrowUtils {
1859
1979
  statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
1860
1980
  statuses = statuses.map((status) => EscrowStatus[status]);
1861
1981
  }
1862
- const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
1982
+ const { escrows } = await customGqlFetch<{ escrows: EscrowData[] }>(
1863
1983
  getSubgraphUrl(networkData),
1864
1984
  GET_ESCROWS_QUERY(filter),
1865
1985
  {
@@ -1874,7 +1994,8 @@ export class EscrowUtils {
1874
1994
  orderDirection: orderDirection,
1875
1995
  first: first,
1876
1996
  skip: skip,
1877
- }
1997
+ },
1998
+ options
1878
1999
  );
1879
2000
  return (escrows || []).map((e) => mapEscrow(e, networkData.chainId));
1880
2001
  }
@@ -1932,6 +2053,7 @@ export class EscrowUtils {
1932
2053
  *
1933
2054
  * @param {ChainId} chainId Network in which the escrow has been deployed
1934
2055
  * @param {string} escrowAddress Address of the escrow
2056
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1935
2057
  * @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
1936
2058
  *
1937
2059
  * **Code example**
@@ -1944,7 +2066,8 @@ export class EscrowUtils {
1944
2066
  */
1945
2067
  public static async getEscrow(
1946
2068
  chainId: ChainId,
1947
- escrowAddress: string
2069
+ escrowAddress: string,
2070
+ options?: SubgraphOptions
1948
2071
  ): Promise<IEscrow | null> {
1949
2072
  const networkData = NETWORKS[chainId];
1950
2073
 
@@ -1956,10 +2079,11 @@ export class EscrowUtils {
1956
2079
  throw ErrorInvalidAddress;
1957
2080
  }
1958
2081
 
1959
- const { escrow } = await gqlFetch<{ escrow: EscrowData | null }>(
2082
+ const { escrow } = await customGqlFetch<{ escrow: EscrowData | null }>(
1960
2083
  getSubgraphUrl(networkData),
1961
2084
  GET_ESCROW_BY_ADDRESS_QUERY(),
1962
- { escrowAddress: escrowAddress.toLowerCase() }
2085
+ { escrowAddress: escrowAddress.toLowerCase() },
2086
+ options
1963
2087
  );
1964
2088
  if (!escrow) return null;
1965
2089
 
@@ -2002,6 +2126,7 @@ export class EscrowUtils {
2002
2126
  * ```
2003
2127
  *
2004
2128
  * @param {IStatusEventFilter} filter Filter parameters.
2129
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2005
2130
  * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
2006
2131
  *
2007
2132
  * **Code example**
@@ -2023,7 +2148,8 @@ export class EscrowUtils {
2023
2148
  * ```
2024
2149
  */
2025
2150
  public static async getStatusEvents(
2026
- filter: IStatusEventFilter
2151
+ filter: IStatusEventFilter,
2152
+ options?: SubgraphOptions
2027
2153
  ): Promise<IStatusEvent[]> {
2028
2154
  const {
2029
2155
  chainId,
@@ -2057,7 +2183,7 @@ export class EscrowUtils {
2057
2183
 
2058
2184
  const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
2059
2185
 
2060
- const data = await gqlFetch<{
2186
+ const data = await customGqlFetch<{
2061
2187
  escrowStatusEvents: StatusEvent[];
2062
2188
  }>(
2063
2189
  getSubgraphUrl(networkData),
@@ -2070,7 +2196,8 @@ export class EscrowUtils {
2070
2196
  orderDirection,
2071
2197
  first: Math.min(first, 1000),
2072
2198
  skip,
2073
- }
2199
+ },
2200
+ options
2074
2201
  );
2075
2202
 
2076
2203
  if (!data || !data['escrowStatusEvents']) {
@@ -2094,6 +2221,7 @@ export class EscrowUtils {
2094
2221
  * Fetch payouts from the subgraph.
2095
2222
  *
2096
2223
  * @param {IPayoutFilter} filter Filter parameters.
2224
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2097
2225
  * @returns {Promise<IPayout[]>} List of payouts matching the filters.
2098
2226
  *
2099
2227
  * **Code example**
@@ -2111,7 +2239,10 @@ export class EscrowUtils {
2111
2239
  * console.log(payouts);
2112
2240
  * ```
2113
2241
  */
2114
- public static async getPayouts(filter: IPayoutFilter): Promise<IPayout[]> {
2242
+ public static async getPayouts(
2243
+ filter: IPayoutFilter,
2244
+ options?: SubgraphOptions
2245
+ ): Promise<IPayout[]> {
2115
2246
  const networkData = NETWORKS[filter.chainId];
2116
2247
  if (!networkData) {
2117
2248
  throw ErrorUnsupportedChainID;
@@ -2128,7 +2259,7 @@ export class EscrowUtils {
2128
2259
  const skip = filter.skip || 0;
2129
2260
  const orderDirection = filter.orderDirection || OrderDirection.DESC;
2130
2261
 
2131
- const { payouts } = await gqlFetch<{ payouts: PayoutData[] }>(
2262
+ const { payouts } = await customGqlFetch<{ payouts: PayoutData[] }>(
2132
2263
  getSubgraphUrl(networkData),
2133
2264
  GET_PAYOUTS_QUERY(filter),
2134
2265
  {
@@ -2139,7 +2270,8 @@ export class EscrowUtils {
2139
2270
  first: Math.min(first, 1000),
2140
2271
  skip,
2141
2272
  orderDirection,
2142
- }
2273
+ },
2274
+ options
2143
2275
  );
2144
2276
  if (!payouts) {
2145
2277
  return [];
@@ -2188,6 +2320,7 @@ export class EscrowUtils {
2188
2320
  *
2189
2321
  *
2190
2322
  * @param {Object} filter Filter parameters.
2323
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2191
2324
  * @returns {Promise<ICancellationRefund[]>} List of cancellation refunds matching the filters.
2192
2325
  *
2193
2326
  * **Code example**
@@ -2202,16 +2335,10 @@ export class EscrowUtils {
2202
2335
  * console.log(cancellationRefunds);
2203
2336
  * ```
2204
2337
  */
2205
- public static async getCancellationRefunds(filter: {
2206
- chainId: ChainId;
2207
- escrowAddress?: string;
2208
- receiver?: string;
2209
- from?: Date;
2210
- to?: Date;
2211
- first?: number;
2212
- skip?: number;
2213
- orderDirection?: OrderDirection;
2214
- }): Promise<ICancellationRefund[]> {
2338
+ public static async getCancellationRefunds(
2339
+ filter: ICancellationRefundFilter,
2340
+ options?: SubgraphOptions
2341
+ ): Promise<ICancellationRefund[]> {
2215
2342
  const networkData = NETWORKS[filter.chainId];
2216
2343
  if (!networkData) throw ErrorUnsupportedChainID;
2217
2344
  if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
@@ -2226,17 +2353,22 @@ export class EscrowUtils {
2226
2353
  const skip = filter.skip || 0;
2227
2354
  const orderDirection = filter.orderDirection || OrderDirection.DESC;
2228
2355
 
2229
- const { cancellationRefundEvents } = await gqlFetch<{
2356
+ const { cancellationRefundEvents } = await customGqlFetch<{
2230
2357
  cancellationRefundEvents: CancellationRefundData[];
2231
- }>(getSubgraphUrl(networkData), GET_CANCELLATION_REFUNDS_QUERY(filter), {
2232
- escrowAddress: filter.escrowAddress?.toLowerCase(),
2233
- receiver: filter.receiver?.toLowerCase(),
2234
- from: filter.from ? getUnixTimestamp(filter.from) : undefined,
2235
- to: filter.to ? getUnixTimestamp(filter.to) : undefined,
2236
- first,
2237
- skip,
2238
- orderDirection,
2239
- });
2358
+ }>(
2359
+ getSubgraphUrl(networkData),
2360
+ GET_CANCELLATION_REFUNDS_QUERY(filter),
2361
+ {
2362
+ escrowAddress: filter.escrowAddress?.toLowerCase(),
2363
+ receiver: filter.receiver?.toLowerCase(),
2364
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
2365
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
2366
+ first,
2367
+ skip,
2368
+ orderDirection,
2369
+ },
2370
+ options
2371
+ );
2240
2372
 
2241
2373
  if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
2242
2374
  return [];
@@ -2288,6 +2420,7 @@ export class EscrowUtils {
2288
2420
  *
2289
2421
  * @param {ChainId} chainId Network in which the escrow has been deployed
2290
2422
  * @param {string} escrowAddress Address of the escrow
2423
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2291
2424
  * @returns {Promise<ICancellationRefund>} Cancellation refund data
2292
2425
  *
2293
2426
  * **Code example**
@@ -2300,7 +2433,8 @@ export class EscrowUtils {
2300
2433
  */
2301
2434
  public static async getCancellationRefund(
2302
2435
  chainId: ChainId,
2303
- escrowAddress: string
2436
+ escrowAddress: string,
2437
+ options?: SubgraphOptions
2304
2438
  ): Promise<ICancellationRefund | null> {
2305
2439
  const networkData = NETWORKS[chainId];
2306
2440
  if (!networkData) throw ErrorUnsupportedChainID;
@@ -2309,12 +2443,13 @@ export class EscrowUtils {
2309
2443
  throw ErrorInvalidEscrowAddressProvided;
2310
2444
  }
2311
2445
 
2312
- const { cancellationRefundEvents } = await gqlFetch<{
2446
+ const { cancellationRefundEvents } = await customGqlFetch<{
2313
2447
  cancellationRefundEvents: CancellationRefundData[];
2314
2448
  }>(
2315
2449
  getSubgraphUrl(networkData),
2316
2450
  GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY(),
2317
- { escrowAddress: escrowAddress.toLowerCase() }
2451
+ { escrowAddress: escrowAddress.toLowerCase() },
2452
+ options
2318
2453
  );
2319
2454
 
2320
2455
  if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
package/src/interfaces.ts CHANGED
@@ -312,3 +312,13 @@ export interface IEscrowWithdraw {
312
312
  tokenAddress: string;
313
313
  withdrawnAmount: bigint;
314
314
  }
315
+
316
+ /**
317
+ * Configuration options for subgraph requests with retry logic.
318
+ */
319
+ export interface SubgraphOptions {
320
+ /** Maximum number of retry attempts */
321
+ maxRetries?: number;
322
+ /** Base delay between retries in milliseconds */
323
+ baseDelay?: number;
324
+ }