@human-protocol/sdk 5.0.0 → 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 +1 -16
  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 +14 -17
  14. package/dist/escrow.d.ts.map +1 -1
  15. package/dist/escrow.js +34 -33
  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 +2 -1
  40. package/src/base.ts +1 -23
  41. package/src/constants.ts +0 -18
  42. package/src/enums.ts +0 -1
  43. package/src/error.ts +7 -0
  44. package/src/escrow.ts +69 -64
  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/base.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { ContractRunner, Overrides } from 'ethers';
1
+ import { ContractRunner } from 'ethers';
2
2
  import { NetworkData } from './types';
3
- import { ChainId } from './enums';
4
- import { DEFAULT_AURORA_GAS_PRICE } from './constants';
5
3
 
6
4
  /**
7
5
  * ## Introduction
@@ -23,24 +21,4 @@ export abstract class BaseEthersClient {
23
21
  this.networkData = networkData;
24
22
  this.runner = runner;
25
23
  }
26
-
27
- /**
28
- * Internal helper to enrich transaction overrides with network specific defaults.
29
- *
30
- * Aurora networks use a fixed gas price. We always override any user provided
31
- * gasPrice with the canonical DEFAULT_AURORA_GAS_PRICE to avoid mismatches
32
- * or tx failures due to an unexpected value. For other networks the user
33
- * supplied fee parameters are left untouched.
34
- */
35
- protected applyTxDefaults(txOptions: Overrides = {}): Overrides {
36
- if (this.networkData.chainId === ChainId.AURORA_TESTNET) {
37
- return {
38
- ...txOptions,
39
- gasPrice: DEFAULT_AURORA_GAS_PRICE,
40
- maxFeePerGas: undefined,
41
- maxPriorityFeePerGas: undefined,
42
- } as Overrides;
43
- }
44
- return txOptions;
45
- }
46
24
  }
package/src/constants.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { ethers } from 'ethers';
2
1
  import { ChainId } from './enums';
3
2
  import { NetworkData } from './types';
4
3
 
@@ -12,8 +11,6 @@ export const DEFAULT_PORT = 9000;
12
11
 
13
12
  export const DEFAULT_USE_SSL = false;
14
13
 
15
- export const DEFAULT_AURORA_GAS_PRICE = ethers.parseUnits('0.07', 'gwei');
16
-
17
14
  export enum HttpStatus {
18
15
  OK = 200,
19
16
  CREATED = 201,
@@ -120,21 +117,6 @@ export const NETWORKS: {
120
117
  oldSubgraphUrl: '',
121
118
  oldFactoryAddress: '',
122
119
  },
123
- [ChainId.AURORA_TESTNET]: {
124
- chainId: ChainId.AURORA_TESTNET,
125
- title: 'Aurora Testnet',
126
- scanUrl: 'https://explorer.testnet.aurora.dev/',
127
- factoryAddress: '0xbA537fEF2442cD48f60686FE1Bbbe40F964a7940',
128
- hmtAddress: '0x792abbcC99c01dbDec49c9fa9A828a186Da45C33',
129
- stakingAddress: '0x7457d26a3C70Bd71F7557C773b303c1dB82BBB68',
130
- kvstoreAddress: '0xD6D347ba6987519B4e42EcED43dF98eFf5465a23',
131
- subgraphUrl:
132
- 'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
133
- subgraphUrlApiKey:
134
- 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmVHYvjbsgAroR9EMgqqGTQ7aKPRFMVekY6evU6mFPUU7J',
135
- oldSubgraphUrl: '',
136
- oldFactoryAddress: '',
137
- },
138
120
  [ChainId.LOCALHOST]: {
139
121
  chainId: ChainId.LOCALHOST,
140
122
  title: 'Localhost',
package/src/enums.ts CHANGED
@@ -6,7 +6,6 @@ export enum ChainId {
6
6
  BSC_TESTNET = 97,
7
7
  POLYGON = 137,
8
8
  POLYGON_AMOY = 80002,
9
- AURORA_TESTNET = 1313161555,
10
9
  LOCALHOST = 1338,
11
10
  }
12
11
 
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,
@@ -244,7 +246,7 @@ export class EscrowClient extends BaseEthersClient {
244
246
  await this.escrowFactoryContract.createEscrow(
245
247
  tokenAddress,
246
248
  jobRequesterId,
247
- this.applyTxDefaults(txOptions)
249
+ txOptions
248
250
  )
249
251
  ).wait();
250
252
 
@@ -405,7 +407,7 @@ export class EscrowClient extends BaseEthersClient {
405
407
  exchangeOracleFee,
406
408
  manifest,
407
409
  manifestHash,
408
- this.applyTxDefaults(txOptions)
410
+ txOptions
409
411
  )
410
412
  ).wait();
411
413
 
@@ -503,7 +505,7 @@ export class EscrowClient extends BaseEthersClient {
503
505
  exchangeOracleFee,
504
506
  manifest,
505
507
  manifestHash,
506
- this.applyTxDefaults(txOptions)
508
+ txOptions
507
509
  )
508
510
  ).wait();
509
511
 
@@ -567,11 +569,7 @@ export class EscrowClient extends BaseEthersClient {
567
569
  this.runner
568
570
  );
569
571
  await (
570
- await tokenContract.transfer(
571
- escrowAddress,
572
- amount,
573
- this.applyTxDefaults(txOptions)
574
- )
572
+ await tokenContract.transfer(escrowAddress, amount, txOptions)
575
573
  ).wait();
576
574
 
577
575
  return;
@@ -692,7 +690,7 @@ export class EscrowClient extends BaseEthersClient {
692
690
  url,
693
691
  hash,
694
692
  fundsToReserve,
695
- this.applyTxDefaults(txOptions)
693
+ txOptions
696
694
  )
697
695
  ).wait();
698
696
  } else {
@@ -700,7 +698,7 @@ export class EscrowClient extends BaseEthersClient {
700
698
  await escrowContract['storeResults(string,string)'](
701
699
  url,
702
700
  hash,
703
- this.applyTxDefaults(txOptions)
701
+ txOptions
704
702
  )
705
703
  ).wait();
706
704
  }
@@ -756,9 +754,7 @@ export class EscrowClient extends BaseEthersClient {
756
754
  try {
757
755
  const escrowContract = this.getEscrowContract(escrowAddress);
758
756
 
759
- await (
760
- await escrowContract.complete(this.applyTxDefaults(txOptions))
761
- ).wait();
757
+ await (await escrowContract.complete(txOptions)).wait();
762
758
  return;
763
759
  } catch (e) {
764
760
  return throwError(e);
@@ -898,7 +894,7 @@ export class EscrowClient extends BaseEthersClient {
898
894
  finalResultsHash,
899
895
  id,
900
896
  forceComplete,
901
- this.applyTxDefaults(txOptions)
897
+ txOptions
902
898
  )
903
899
  ).wait();
904
900
  } else {
@@ -912,7 +908,7 @@ export class EscrowClient extends BaseEthersClient {
912
908
  finalResultsHash,
913
909
  id,
914
910
  forceComplete,
915
- this.applyTxDefaults(txOptions)
911
+ txOptions
916
912
  )
917
913
  ).wait();
918
914
  }
@@ -966,9 +962,7 @@ export class EscrowClient extends BaseEthersClient {
966
962
 
967
963
  try {
968
964
  const escrowContract = this.getEscrowContract(escrowAddress);
969
- await (
970
- await escrowContract.cancel(this.applyTxDefaults(txOptions))
971
- ).wait();
965
+ await (await escrowContract.cancel(txOptions)).wait();
972
966
  } catch (e) {
973
967
  return throwError(e);
974
968
  }
@@ -1014,11 +1008,7 @@ export class EscrowClient extends BaseEthersClient {
1014
1008
 
1015
1009
  try {
1016
1010
  const escrowContract = this.getEscrowContract(escrowAddress);
1017
- await (
1018
- await escrowContract.requestCancellation(
1019
- this.applyTxDefaults(txOptions)
1020
- )
1021
- ).wait();
1011
+ await (await escrowContract.requestCancellation(txOptions)).wait();
1022
1012
  } catch (e) {
1023
1013
  return throwError(e);
1024
1014
  }
@@ -1076,10 +1066,7 @@ export class EscrowClient extends BaseEthersClient {
1076
1066
  const escrowContract = this.getEscrowContract(escrowAddress);
1077
1067
 
1078
1068
  const transactionReceipt = await (
1079
- await escrowContract.withdraw(
1080
- tokenAddress,
1081
- this.applyTxDefaults(txOptions)
1082
- )
1069
+ await escrowContract.withdraw(tokenAddress, txOptions)
1083
1070
  ).wait();
1084
1071
 
1085
1072
  let amountTransferred: bigint | undefined = undefined;
@@ -1169,7 +1156,6 @@ export class EscrowClient extends BaseEthersClient {
1169
1156
  forceComplete = false,
1170
1157
  txOptions: Overrides = {}
1171
1158
  ): Promise<TransactionLikeWithNonce> {
1172
- txOptions = this.applyTxDefaults(txOptions);
1173
1159
  await this.ensureCorrectBulkPayoutInput(
1174
1160
  escrowAddress,
1175
1161
  recipients,
@@ -1940,6 +1926,7 @@ export class EscrowUtils {
1940
1926
  *
1941
1927
  *
1942
1928
  * @param {IEscrowsFilter} filter Filter parameters.
1929
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
1943
1930
  * @returns {IEscrow[]} List of escrows that match the filter.
1944
1931
  *
1945
1932
  * **Code example**
@@ -1956,7 +1943,10 @@ export class EscrowUtils {
1956
1943
  * const escrows = await EscrowUtils.getEscrows(filters);
1957
1944
  * ```
1958
1945
  */
1959
- public static async getEscrows(filter: IEscrowsFilter): Promise<IEscrow[]> {
1946
+ public static async getEscrows(
1947
+ filter: IEscrowsFilter,
1948
+ options?: SubgraphOptions
1949
+ ): Promise<IEscrow[]> {
1960
1950
  if (filter.launcher && !ethers.isAddress(filter.launcher)) {
1961
1951
  throw ErrorInvalidAddress;
1962
1952
  }
@@ -1989,7 +1979,7 @@ export class EscrowUtils {
1989
1979
  statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
1990
1980
  statuses = statuses.map((status) => EscrowStatus[status]);
1991
1981
  }
1992
- const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
1982
+ const { escrows } = await customGqlFetch<{ escrows: EscrowData[] }>(
1993
1983
  getSubgraphUrl(networkData),
1994
1984
  GET_ESCROWS_QUERY(filter),
1995
1985
  {
@@ -2004,7 +1994,8 @@ export class EscrowUtils {
2004
1994
  orderDirection: orderDirection,
2005
1995
  first: first,
2006
1996
  skip: skip,
2007
- }
1997
+ },
1998
+ options
2008
1999
  );
2009
2000
  return (escrows || []).map((e) => mapEscrow(e, networkData.chainId));
2010
2001
  }
@@ -2062,6 +2053,7 @@ export class EscrowUtils {
2062
2053
  *
2063
2054
  * @param {ChainId} chainId Network in which the escrow has been deployed
2064
2055
  * @param {string} escrowAddress Address of the escrow
2056
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2065
2057
  * @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
2066
2058
  *
2067
2059
  * **Code example**
@@ -2074,7 +2066,8 @@ export class EscrowUtils {
2074
2066
  */
2075
2067
  public static async getEscrow(
2076
2068
  chainId: ChainId,
2077
- escrowAddress: string
2069
+ escrowAddress: string,
2070
+ options?: SubgraphOptions
2078
2071
  ): Promise<IEscrow | null> {
2079
2072
  const networkData = NETWORKS[chainId];
2080
2073
 
@@ -2086,10 +2079,11 @@ export class EscrowUtils {
2086
2079
  throw ErrorInvalidAddress;
2087
2080
  }
2088
2081
 
2089
- const { escrow } = await gqlFetch<{ escrow: EscrowData | null }>(
2082
+ const { escrow } = await customGqlFetch<{ escrow: EscrowData | null }>(
2090
2083
  getSubgraphUrl(networkData),
2091
2084
  GET_ESCROW_BY_ADDRESS_QUERY(),
2092
- { escrowAddress: escrowAddress.toLowerCase() }
2085
+ { escrowAddress: escrowAddress.toLowerCase() },
2086
+ options
2093
2087
  );
2094
2088
  if (!escrow) return null;
2095
2089
 
@@ -2132,6 +2126,7 @@ export class EscrowUtils {
2132
2126
  * ```
2133
2127
  *
2134
2128
  * @param {IStatusEventFilter} filter Filter parameters.
2129
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2135
2130
  * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
2136
2131
  *
2137
2132
  * **Code example**
@@ -2153,7 +2148,8 @@ export class EscrowUtils {
2153
2148
  * ```
2154
2149
  */
2155
2150
  public static async getStatusEvents(
2156
- filter: IStatusEventFilter
2151
+ filter: IStatusEventFilter,
2152
+ options?: SubgraphOptions
2157
2153
  ): Promise<IStatusEvent[]> {
2158
2154
  const {
2159
2155
  chainId,
@@ -2187,7 +2183,7 @@ export class EscrowUtils {
2187
2183
 
2188
2184
  const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
2189
2185
 
2190
- const data = await gqlFetch<{
2186
+ const data = await customGqlFetch<{
2191
2187
  escrowStatusEvents: StatusEvent[];
2192
2188
  }>(
2193
2189
  getSubgraphUrl(networkData),
@@ -2200,7 +2196,8 @@ export class EscrowUtils {
2200
2196
  orderDirection,
2201
2197
  first: Math.min(first, 1000),
2202
2198
  skip,
2203
- }
2199
+ },
2200
+ options
2204
2201
  );
2205
2202
 
2206
2203
  if (!data || !data['escrowStatusEvents']) {
@@ -2224,6 +2221,7 @@ export class EscrowUtils {
2224
2221
  * Fetch payouts from the subgraph.
2225
2222
  *
2226
2223
  * @param {IPayoutFilter} filter Filter parameters.
2224
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2227
2225
  * @returns {Promise<IPayout[]>} List of payouts matching the filters.
2228
2226
  *
2229
2227
  * **Code example**
@@ -2241,7 +2239,10 @@ export class EscrowUtils {
2241
2239
  * console.log(payouts);
2242
2240
  * ```
2243
2241
  */
2244
- public static async getPayouts(filter: IPayoutFilter): Promise<IPayout[]> {
2242
+ public static async getPayouts(
2243
+ filter: IPayoutFilter,
2244
+ options?: SubgraphOptions
2245
+ ): Promise<IPayout[]> {
2245
2246
  const networkData = NETWORKS[filter.chainId];
2246
2247
  if (!networkData) {
2247
2248
  throw ErrorUnsupportedChainID;
@@ -2258,7 +2259,7 @@ export class EscrowUtils {
2258
2259
  const skip = filter.skip || 0;
2259
2260
  const orderDirection = filter.orderDirection || OrderDirection.DESC;
2260
2261
 
2261
- const { payouts } = await gqlFetch<{ payouts: PayoutData[] }>(
2262
+ const { payouts } = await customGqlFetch<{ payouts: PayoutData[] }>(
2262
2263
  getSubgraphUrl(networkData),
2263
2264
  GET_PAYOUTS_QUERY(filter),
2264
2265
  {
@@ -2269,7 +2270,8 @@ export class EscrowUtils {
2269
2270
  first: Math.min(first, 1000),
2270
2271
  skip,
2271
2272
  orderDirection,
2272
- }
2273
+ },
2274
+ options
2273
2275
  );
2274
2276
  if (!payouts) {
2275
2277
  return [];
@@ -2318,6 +2320,7 @@ export class EscrowUtils {
2318
2320
  *
2319
2321
  *
2320
2322
  * @param {Object} filter Filter parameters.
2323
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2321
2324
  * @returns {Promise<ICancellationRefund[]>} List of cancellation refunds matching the filters.
2322
2325
  *
2323
2326
  * **Code example**
@@ -2332,16 +2335,10 @@ export class EscrowUtils {
2332
2335
  * console.log(cancellationRefunds);
2333
2336
  * ```
2334
2337
  */
2335
- public static async getCancellationRefunds(filter: {
2336
- chainId: ChainId;
2337
- escrowAddress?: string;
2338
- receiver?: string;
2339
- from?: Date;
2340
- to?: Date;
2341
- first?: number;
2342
- skip?: number;
2343
- orderDirection?: OrderDirection;
2344
- }): Promise<ICancellationRefund[]> {
2338
+ public static async getCancellationRefunds(
2339
+ filter: ICancellationRefundFilter,
2340
+ options?: SubgraphOptions
2341
+ ): Promise<ICancellationRefund[]> {
2345
2342
  const networkData = NETWORKS[filter.chainId];
2346
2343
  if (!networkData) throw ErrorUnsupportedChainID;
2347
2344
  if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
@@ -2356,17 +2353,22 @@ export class EscrowUtils {
2356
2353
  const skip = filter.skip || 0;
2357
2354
  const orderDirection = filter.orderDirection || OrderDirection.DESC;
2358
2355
 
2359
- const { cancellationRefundEvents } = await gqlFetch<{
2356
+ const { cancellationRefundEvents } = await customGqlFetch<{
2360
2357
  cancellationRefundEvents: CancellationRefundData[];
2361
- }>(getSubgraphUrl(networkData), GET_CANCELLATION_REFUNDS_QUERY(filter), {
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
- });
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
+ );
2370
2372
 
2371
2373
  if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
2372
2374
  return [];
@@ -2418,6 +2420,7 @@ export class EscrowUtils {
2418
2420
  *
2419
2421
  * @param {ChainId} chainId Network in which the escrow has been deployed
2420
2422
  * @param {string} escrowAddress Address of the escrow
2423
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
2421
2424
  * @returns {Promise<ICancellationRefund>} Cancellation refund data
2422
2425
  *
2423
2426
  * **Code example**
@@ -2430,7 +2433,8 @@ export class EscrowUtils {
2430
2433
  */
2431
2434
  public static async getCancellationRefund(
2432
2435
  chainId: ChainId,
2433
- escrowAddress: string
2436
+ escrowAddress: string,
2437
+ options?: SubgraphOptions
2434
2438
  ): Promise<ICancellationRefund | null> {
2435
2439
  const networkData = NETWORKS[chainId];
2436
2440
  if (!networkData) throw ErrorUnsupportedChainID;
@@ -2439,12 +2443,13 @@ export class EscrowUtils {
2439
2443
  throw ErrorInvalidEscrowAddressProvided;
2440
2444
  }
2441
2445
 
2442
- const { cancellationRefundEvents } = await gqlFetch<{
2446
+ const { cancellationRefundEvents } = await customGqlFetch<{
2443
2447
  cancellationRefundEvents: CancellationRefundData[];
2444
2448
  }>(
2445
2449
  getSubgraphUrl(networkData),
2446
2450
  GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY(),
2447
- { escrowAddress: escrowAddress.toLowerCase() }
2451
+ { escrowAddress: escrowAddress.toLowerCase() },
2452
+ options
2448
2453
  );
2449
2454
 
2450
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
+ }
package/src/kvstore.ts CHANGED
@@ -17,15 +17,14 @@ import {
17
17
  ErrorUnsupportedChainID,
18
18
  InvalidKeyError,
19
19
  } from './error';
20
- import gqlFetch from 'graphql-request';
21
20
  import { NetworkData } from './types';
22
- import { getSubgraphUrl, isValidUrl } from './utils';
21
+ import { getSubgraphUrl, customGqlFetch, isValidUrl } from './utils';
23
22
  import {
24
23
  GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY,
25
24
  GET_KVSTORE_BY_ADDRESS_QUERY,
26
25
  } from './graphql/queries/kvstore';
27
26
  import { KVStoreData } from './graphql';
28
- import { IKVStore } from './interfaces';
27
+ import { IKVStore, SubgraphOptions } from './interfaces';
29
28
  /**
30
29
  * ## Introduction
31
30
  *
@@ -175,9 +174,7 @@ export class KVStoreClient extends BaseEthersClient {
175
174
  ): Promise<void> {
176
175
  if (key === '') throw ErrorKVStoreEmptyKey;
177
176
  try {
178
- await (
179
- await this.contract.set(key, value, this.applyTxDefaults(txOptions))
180
- ).wait();
177
+ await (await this.contract.set(key, value, txOptions)).wait();
181
178
  } catch (e) {
182
179
  if (e instanceof Error) throw Error(`Failed to set value: ${e.message}`);
183
180
  }
@@ -222,13 +219,7 @@ export class KVStoreClient extends BaseEthersClient {
222
219
  if (keys.includes('')) throw ErrorKVStoreEmptyKey;
223
220
 
224
221
  try {
225
- await (
226
- await this.contract.setBulk(
227
- keys,
228
- values,
229
- this.applyTxDefaults(txOptions)
230
- )
231
- ).wait();
222
+ await (await this.contract.setBulk(keys, values, txOptions)).wait();
232
223
  } catch (e) {
233
224
  if (e instanceof Error)
234
225
  throw Error(`Failed to set bulk values: ${e.message}`);
@@ -281,7 +272,7 @@ export class KVStoreClient extends BaseEthersClient {
281
272
  await this.contract.setBulk(
282
273
  [urlKey, hashKey],
283
274
  [url, contentHash],
284
- this.applyTxDefaults(txOptions)
275
+ txOptions
285
276
  )
286
277
  ).wait();
287
278
  } catch (e) {
@@ -294,6 +285,7 @@ export class KVStoreClient extends BaseEthersClient {
294
285
  *
295
286
  * @param {string} address Address from which to get the key value.
296
287
  * @param {string} key Key to obtain the value.
288
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
297
289
  * @returns {string} Value of the key.
298
290
  *
299
291
  *
@@ -365,6 +357,7 @@ export class KVStoreUtils {
365
357
  *
366
358
  * @param {ChainId} chainId Network in which the KVStore is deployed
367
359
  * @param {string} address Address of the KVStore
360
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
368
361
  * @returns {Promise<IKVStore[]>} KVStore data
369
362
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
370
363
  * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
@@ -380,7 +373,8 @@ export class KVStoreUtils {
380
373
  */
381
374
  public static async getKVStoreData(
382
375
  chainId: ChainId,
383
- address: string
376
+ address: string,
377
+ options?: SubgraphOptions
384
378
  ): Promise<IKVStore[]> {
385
379
  const networkData = NETWORKS[chainId];
386
380
 
@@ -392,10 +386,11 @@ export class KVStoreUtils {
392
386
  throw ErrorInvalidAddress;
393
387
  }
394
388
 
395
- const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
389
+ const { kvstores } = await customGqlFetch<{ kvstores: KVStoreData[] }>(
396
390
  getSubgraphUrl(networkData),
397
391
  GET_KVSTORE_BY_ADDRESS_QUERY(),
398
- { address: address.toLowerCase() }
392
+ { address: address.toLowerCase() },
393
+ options
399
394
  );
400
395
 
401
396
  const kvStoreData = kvstores.map((item) => ({
@@ -412,6 +407,7 @@ export class KVStoreUtils {
412
407
  * @param {ChainId} chainId Network in which the KVStore is deployed
413
408
  * @param {string} address Address from which to get the key value.
414
409
  * @param {string} key Key to obtain the value.
410
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
415
411
  * @returns {Promise<string>} Value of the key.
416
412
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
417
413
  * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
@@ -433,7 +429,8 @@ export class KVStoreUtils {
433
429
  public static async get(
434
430
  chainId: ChainId,
435
431
  address: string,
436
- key: string
432
+ key: string,
433
+ options?: SubgraphOptions
437
434
  ): Promise<string> {
438
435
  if (key === '') throw ErrorKVStoreEmptyKey;
439
436
  if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
@@ -444,10 +441,11 @@ export class KVStoreUtils {
444
441
  throw ErrorUnsupportedChainID;
445
442
  }
446
443
 
447
- const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>(
444
+ const { kvstores } = await customGqlFetch<{ kvstores: KVStoreData[] }>(
448
445
  getSubgraphUrl(networkData),
449
446
  GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY(),
450
- { address: address.toLowerCase(), key }
447
+ { address: address.toLowerCase(), key },
448
+ options
451
449
  );
452
450
 
453
451
  if (!kvstores || kvstores.length === 0) {
@@ -463,6 +461,7 @@ export class KVStoreUtils {
463
461
  * @param {ChainId} chainId Network in which the KVStore is deployed
464
462
  * @param {string} address Address from which to get the URL value.
465
463
  * @param {string} urlKey Configurable URL key. `url` by default.
464
+ * @param {SubgraphOptions} options Optional configuration for subgraph requests.
466
465
  * @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
467
466
  *
468
467
  * **Code example**
@@ -480,7 +479,8 @@ export class KVStoreUtils {
480
479
  public static async getFileUrlAndVerifyHash(
481
480
  chainId: ChainId,
482
481
  address: string,
483
- urlKey = 'url'
482
+ urlKey = 'url',
483
+ options?: SubgraphOptions
484
484
  ): Promise<string> {
485
485
  if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
486
486
  const hashKey = urlKey + '_hash';
@@ -489,7 +489,7 @@ export class KVStoreUtils {
489
489
  hash = '';
490
490
 
491
491
  try {
492
- url = await this.get(chainId, address, urlKey);
492
+ url = await this.get(chainId, address, urlKey, options);
493
493
  } catch (e) {
494
494
  if (e instanceof Error) throw Error(`Failed to get URL: ${e.message}`);
495
495
  }
@@ -539,12 +539,14 @@ export class KVStoreUtils {
539
539
  */
540
540
  public static async getPublicKey(
541
541
  chainId: ChainId,
542
- address: string
542
+ address: string,
543
+ options?: SubgraphOptions
543
544
  ): Promise<string> {
544
545
  const publicKeyUrl = await this.getFileUrlAndVerifyHash(
545
546
  chainId,
546
547
  address,
547
- KVStoreKeys.publicKey
548
+ KVStoreKeys.publicKey,
549
+ options
548
550
  );
549
551
 
550
552
  if (publicKeyUrl === '') {