@human-protocol/sdk 6.0.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.
package/dist/staking.js CHANGED
@@ -158,7 +158,7 @@ class StakingClient extends base_1.BaseEthersClient {
158
158
  throw error_1.ErrorInvalidStakingValueSign;
159
159
  }
160
160
  try {
161
- await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, txOptions)).wait();
161
+ await this.sendTxAndWait(async (overrides) => this.tokenContract.approve(await this.stakingContract.getAddress(), amount, overrides), txOptions);
162
162
  return;
163
163
  }
164
164
  catch (e) {
@@ -194,7 +194,7 @@ class StakingClient extends base_1.BaseEthersClient {
194
194
  throw error_1.ErrorInvalidStakingValueSign;
195
195
  }
196
196
  try {
197
- await (await this.stakingContract.stake(amount, txOptions)).wait();
197
+ await this.sendTxAndWait((overrides) => this.stakingContract.stake(amount, overrides), txOptions);
198
198
  return;
199
199
  }
200
200
  catch (e) {
@@ -229,7 +229,7 @@ class StakingClient extends base_1.BaseEthersClient {
229
229
  throw error_1.ErrorInvalidStakingValueSign;
230
230
  }
231
231
  try {
232
- await (await this.stakingContract.unstake(amount, txOptions)).wait();
232
+ await this.sendTxAndWait((overrides) => this.stakingContract.unstake(amount, overrides), txOptions);
233
233
  return;
234
234
  }
235
235
  catch (e) {
@@ -251,7 +251,7 @@ class StakingClient extends base_1.BaseEthersClient {
251
251
  */
252
252
  async withdraw(txOptions = {}) {
253
253
  try {
254
- await (await this.stakingContract.withdraw(txOptions)).wait();
254
+ await this.sendTxAndWait((overrides) => this.stakingContract.withdraw(overrides), txOptions);
255
255
  return;
256
256
  }
257
257
  catch (e) {
@@ -302,7 +302,7 @@ class StakingClient extends base_1.BaseEthersClient {
302
302
  }
303
303
  await this.checkValidEscrow(escrowAddress);
304
304
  try {
305
- await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, txOptions)).wait();
305
+ await this.sendTxAndWait((overrides) => this.stakingContract.slash(slasher, staker, escrowAddress, amount, overrides), txOptions);
306
306
  return;
307
307
  }
308
308
  catch (e) {
@@ -82,8 +82,8 @@ export declare class TransactionUtils {
82
82
  * token?: string; // (Optional) The token address to filter transactions.
83
83
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
84
84
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
85
- * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
86
- * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
85
+ * startBlock?: bigint | number; // (Optional) The start block to filter transactions (inclusive).
86
+ * endBlock?: bigint | number; // (Optional) The end block to filter transactions (inclusive).
87
87
  * first?: number; // (Optional) Number of transactions per page. Default is 10.
88
88
  * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
89
89
  * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
@@ -103,8 +103,8 @@ class TransactionUtils {
103
103
  * token?: string; // (Optional) The token address to filter transactions.
104
104
  * startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
105
105
  * endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
106
- * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
107
- * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
106
+ * startBlock?: bigint | number; // (Optional) The start block to filter transactions (inclusive).
107
+ * endBlock?: bigint | number; // (Optional) The end block to filter transactions (inclusive).
108
108
  * first?: number; // (Optional) Number of transactions per page. Default is 10.
109
109
  * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
110
110
  * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
@@ -180,8 +180,8 @@ class TransactionUtils {
180
180
  ? (0, utils_1.getUnixTimestamp)(filter?.startDate)
181
181
  : undefined,
182
182
  endDate: filter.endDate ? (0, utils_1.getUnixTimestamp)(filter.endDate) : undefined,
183
- startBlock: filter.startBlock ? filter.startBlock : undefined,
184
- endBlock: filter.endBlock ? filter.endBlock : undefined,
183
+ startBlock: filter.startBlock ? Number(filter.startBlock) : undefined,
184
+ endBlock: filter.endBlock ? Number(filter.endBlock) : undefined,
185
185
  method: filter.method ? filter.method : undefined,
186
186
  escrow: filter.escrow ? filter.escrow : undefined,
187
187
  token: filter.token ? filter.token : undefined,
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TransactionLike } from 'ethers';
1
+ import { Overrides, TransactionLike } from 'ethers';
2
2
  /**
3
3
  * Enum for escrow statuses.
4
4
  * @readonly
@@ -83,6 +83,19 @@ export type NetworkData = {
83
83
  */
84
84
  oldFactoryAddress: string;
85
85
  };
86
+ /**
87
+ * Options that configure how long to wait for transaction confirmations.
88
+ */
89
+ export type WaitOptions = {
90
+ /** Number of block confirmations to wait for. */
91
+ confirmations?: number;
92
+ /** Milliseconds to wait before aborting `tx.wait()`. */
93
+ timeoutMs?: number;
94
+ };
95
+ /**
96
+ * Extends ethers overrides with `wait()` options that control confirmation count and timeout.
97
+ */
98
+ export type TransactionOverrides = Overrides & WaitOptions;
86
99
  export type TransactionLikeWithNonce = TransactionLike & {
87
100
  nonce: number;
88
101
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,QAAQ,IAAA;CACT;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,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ACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,CAAC;AAE3D,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { NetworkData } from './types';
2
1
  import { SubgraphOptions } from './interfaces';
2
+ import { NetworkData } from './types';
3
3
  /**
4
4
  * Handles and throws appropriate error types based on the Ethereum error.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAatD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CA4CX,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAUtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,OAS3C,CAAC;AAaF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,GAAG,EAC1C,KAAK,MAAM,EACX,OAAO,GAAG,EACV,YAAY,GAAG,EACf,UAAU,eAAe,KACxB,OAAO,CAAC,CAAC,CA4CX,CAAC"}
package/dist/utils.js CHANGED
@@ -8,7 +8,6 @@ exports.customGqlFetch = exports.isIndexerError = exports.getUnixTimestamp = exp
8
8
  const ethers_1 = require("ethers");
9
9
  const graphql_request_1 = __importDefault(require("graphql-request"));
10
10
  const validator_1 = require("validator");
11
- const constants_1 = require("./constants");
12
11
  const enums_1 = require("./enums");
13
12
  const error_1 = require("./error");
14
13
  /**
@@ -86,7 +85,7 @@ exports.isValidJson = isValidJson;
86
85
  const getSubgraphUrl = (networkData) => {
87
86
  let subgraphUrl = networkData.subgraphUrl;
88
87
  if (process.env.SUBGRAPH_API_KEY) {
89
- subgraphUrl = networkData.subgraphUrlApiKey.replace(constants_1.SUBGRAPH_API_KEY_PLACEHOLDER, process.env.SUBGRAPH_API_KEY);
88
+ subgraphUrl = networkData.subgraphUrlApiKey;
90
89
  }
91
90
  else if (networkData.chainId !== enums_1.ChainId.LOCALHOST) {
92
91
  // eslint-disable-next-line no-console
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "6.0.0",
4
+ "version": "6.1.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -53,7 +53,7 @@
53
53
  "@types/validator": "^13.15.4",
54
54
  "eslint": "^9.39.1",
55
55
  "eslint-plugin-jest": "^28.9.0",
56
- "eslint-plugin-prettier": "^5.2.1",
56
+ "eslint-plugin-prettier": "^5.5.5",
57
57
  "glob": "^13.0.0",
58
58
  "prettier": "^3.7.4",
59
59
  "ts-node": "^10.9.2",
package/src/base.ts CHANGED
@@ -1,5 +1,10 @@
1
- import { ContractRunner } from 'ethers';
2
- import { NetworkData } from './types';
1
+ import {
2
+ ContractRunner,
3
+ ContractTransactionReceipt,
4
+ ContractTransactionResponse,
5
+ Overrides,
6
+ } from 'ethers';
7
+ import { NetworkData, TransactionOverrides, WaitOptions } from './types';
3
8
 
4
9
  /**
5
10
  * Base class for clients making on-chain calls.
@@ -20,4 +25,35 @@ export abstract class BaseEthersClient {
20
25
  this.networkData = networkData;
21
26
  this.runner = runner;
22
27
  }
28
+
29
+ protected normalizeTxOptions(
30
+ txOptions?: TransactionOverrides
31
+ ): [Overrides, WaitOptions] {
32
+ const options = txOptions ?? {};
33
+ const {
34
+ confirmations: waitConfirmations,
35
+ timeoutMs: waitTimeoutMs,
36
+ ...overrides
37
+ } = options;
38
+
39
+ const waitOptions: WaitOptions = {
40
+ confirmations: waitConfirmations,
41
+ timeoutMs: waitTimeoutMs,
42
+ };
43
+
44
+ return [overrides as Overrides, waitOptions];
45
+ }
46
+
47
+ protected async sendTxAndWait(
48
+ executeTx: (overrides: Overrides) => Promise<ContractTransactionResponse>,
49
+ txOptions?: TransactionOverrides
50
+ ): Promise<ContractTransactionReceipt | null> {
51
+ const [overrides, waitOptions] = this.normalizeTxOptions(txOptions);
52
+ const transactionResponse = await executeTx(overrides);
53
+
54
+ return transactionResponse.wait(
55
+ waitOptions.confirmations,
56
+ waitOptions.timeoutMs
57
+ );
58
+ }
23
59
  }
package/src/constants.ts CHANGED
@@ -36,7 +36,7 @@ export const NETWORKS: {
36
36
  subgraphUrl:
37
37
  'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
38
38
  subgraphUrlApiKey:
39
- 'https://gateway.thegraph.com/api/deployments/id/QmeCB3KX49nRAkzgqancc3yL3VMJvt65YtL1zrLCFgr2n5',
39
+ 'https://gateway.thegraph.com/api/deployments/id/QmNhLQEfBJQ46fngBh4YCttk8kNkveFy5uvAeUmyAdX1kD',
40
40
  oldSubgraphUrl: '',
41
41
  oldFactoryAddress: '',
42
42
  },
@@ -51,7 +51,7 @@ export const NETWORKS: {
51
51
  subgraphUrl:
52
52
  'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
53
53
  subgraphUrlApiKey:
54
- 'https://gateway.thegraph.com/api/deployments/id/QmcMntqZSTh8wJddxgp2hYcdw78wZFU86LHTHzJ1bTVUDc',
54
+ 'https://gateway.thegraph.com/api/deployments/id/QmQghdr7hxqrjFde8DN15TzfrJLCfwvzmUH9RzWwH1mKzk',
55
55
  oldSubgraphUrl: '',
56
56
  oldFactoryAddress: '',
57
57
  },
@@ -66,7 +66,7 @@ export const NETWORKS: {
66
66
  subgraphUrl:
67
67
  'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
68
68
  subgraphUrlApiKey:
69
- 'https://gateway.thegraph.com/api/deployments/id/QmRexbu8eLZ1iE7ZLMtKxAr9GJnQ1JVrXhybKq6JkJ9XLE',
69
+ 'https://gateway.thegraph.com/api/deployments/id/QmTioC9Z1HzKSCnEKL3BP9iHqbgZt1ceLU2VE4Mv6sxNkd',
70
70
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
71
71
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
72
72
  },
@@ -81,7 +81,7 @@ export const NETWORKS: {
81
81
  subgraphUrl:
82
82
  'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
83
83
  subgraphUrlApiKey:
84
- 'https://gateway.thegraph.com/api/deployments/id/QmfFBXsAP7nbckFx34XYcNq2hRnfoVNrfqCvuk7hmAtYJT',
84
+ 'https://gateway.thegraph.com/api/deployments/id/QmPyUYRjAvzDdeenXMGHcCRD2v4qwZbKMEkVkY3Jq6VLwn',
85
85
  oldSubgraphUrl:
86
86
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
87
87
  oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
@@ -97,7 +97,7 @@ export const NETWORKS: {
97
97
  subgraphUrl:
98
98
  'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
99
99
  subgraphUrlApiKey:
100
- 'https://gateway.thegraph.com/api/deployments/id/QmUwHMDjnDHDB5cowGqd96SRJ1sZegoAPanjxBWUyLZghv',
100
+ 'https://gateway.thegraph.com/api/deployments/id/QmQNkWNE5FPtqbtSkdtR6AEBJz9N7WDz1X7pfvQqYAcUZJ',
101
101
  oldSubgraphUrl:
102
102
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
103
103
  oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
@@ -113,7 +113,7 @@ export const NETWORKS: {
113
113
  subgraphUrl:
114
114
  'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
115
115
  subgraphUrlApiKey:
116
- 'https://gateway.thegraph.com/api/deployments/id/QmTJfcvVVmw8fe5CwRP6tZD5FzE2ESrm3ryygS1YZMYhM7',
116
+ 'https://gateway.thegraph.com/api/deployments/id/QmcLwLMw3UzCSbNbjegrpNu6PB3kAd67xquuyaVWvc5Q7Q',
117
117
  oldSubgraphUrl: '',
118
118
  oldFactoryAddress: '',
119
119
  },
@@ -154,6 +154,4 @@ export const Role = {
154
154
  RecordingOracle: 'recording_oracle',
155
155
  };
156
156
 
157
- export const SUBGRAPH_API_KEY_PLACEHOLDER = '[SUBGRAPH_API_KEY]';
158
-
159
157
  export const ESCROW_BULK_PAYOUT_MAX_ITEMS = 99;