@human-protocol/sdk 6.0.0 → 7.0.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 (129) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/base.d.ts +4 -2
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +14 -0
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +27 -16
  8. package/dist/encryption/encryption.d.ts +84 -0
  9. package/dist/encryption/encryption.d.ts.map +1 -0
  10. package/dist/{encryption.js → encryption/encryption.js} +3 -161
  11. package/dist/encryption/encryption_utils.d.ts +101 -0
  12. package/dist/encryption/encryption_utils.d.ts.map +1 -0
  13. package/dist/encryption/encryption_utils.js +191 -0
  14. package/dist/encryption/index.d.ts +4 -0
  15. package/dist/encryption/index.d.ts.map +1 -0
  16. package/dist/encryption/index.js +7 -0
  17. package/dist/encryption/types.d.ts +9 -0
  18. package/dist/encryption/types.d.ts.map +1 -0
  19. package/dist/encryption/types.js +9 -0
  20. package/dist/error.d.ts +6 -10
  21. package/dist/error.d.ts.map +1 -1
  22. package/dist/error.js +12 -14
  23. package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +16 -196
  24. package/dist/escrow/escrow_client.d.ts.map +1 -0
  25. package/dist/{escrow.js → escrow/escrow_client.js} +50 -430
  26. package/dist/escrow/escrow_utils.d.ts +172 -0
  27. package/dist/escrow/escrow_utils.d.ts.map +1 -0
  28. package/dist/escrow/escrow_utils.js +388 -0
  29. package/dist/escrow/index.d.ts +3 -0
  30. package/dist/escrow/index.d.ts.map +1 -0
  31. package/dist/escrow/index.js +7 -0
  32. package/dist/graphql/queries/statistics.d.ts +1 -0
  33. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  34. package/dist/graphql/queries/statistics.js +36 -2
  35. package/dist/graphql/types.d.ts +3 -1
  36. package/dist/graphql/types.d.ts.map +1 -1
  37. package/dist/index.d.ts +10 -10
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +23 -22
  40. package/dist/interfaces.d.ts +2 -7
  41. package/dist/interfaces.d.ts.map +1 -1
  42. package/dist/kvstore/index.d.ts +3 -0
  43. package/dist/kvstore/index.d.ts.map +1 -0
  44. package/dist/kvstore/index.js +7 -0
  45. package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +7 -112
  46. package/dist/kvstore/kvstore_client.d.ts.map +1 -0
  47. package/dist/{kvstore.js → kvstore/kvstore_client.js} +25 -187
  48. package/dist/kvstore/kvstore_utils.d.ts +105 -0
  49. package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
  50. package/dist/kvstore/kvstore_utils.js +184 -0
  51. package/dist/operator/index.d.ts +2 -0
  52. package/dist/operator/index.d.ts.map +1 -0
  53. package/dist/operator/index.js +5 -0
  54. package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
  55. package/dist/operator/operator_utils.d.ts.map +1 -0
  56. package/dist/{operator.js → operator/operator_utils.js} +6 -6
  57. package/dist/staking/index.d.ts +3 -0
  58. package/dist/staking/index.d.ts.map +1 -0
  59. package/dist/staking/index.js +7 -0
  60. package/dist/{staking.d.ts → staking/staking_client.d.ts} +10 -71
  61. package/dist/staking/staking_client.d.ts.map +1 -0
  62. package/dist/{staking.js → staking/staking_client.js} +11 -141
  63. package/dist/staking/staking_utils.d.ts +63 -0
  64. package/dist/staking/staking_utils.d.ts.map +1 -0
  65. package/dist/staking/staking_utils.js +137 -0
  66. package/dist/statistics/index.d.ts +2 -0
  67. package/dist/statistics/index.d.ts.map +1 -0
  68. package/dist/statistics/index.js +5 -0
  69. package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
  70. package/dist/statistics/statistics_utils.d.ts.map +1 -0
  71. package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
  72. package/dist/transaction/index.d.ts +2 -0
  73. package/dist/transaction/index.d.ts.map +1 -0
  74. package/dist/transaction/index.js +5 -0
  75. package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +5 -5
  76. package/dist/transaction/transaction_utils.d.ts.map +1 -0
  77. package/dist/{transaction.js → transaction/transaction_utils.js} +9 -9
  78. package/dist/types.d.ts +22 -1
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/utils.d.ts +16 -1
  81. package/dist/utils.d.ts.map +1 -1
  82. package/dist/utils.js +72 -6
  83. package/dist/worker/index.d.ts +2 -0
  84. package/dist/worker/index.d.ts.map +1 -0
  85. package/dist/worker/index.js +5 -0
  86. package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -3
  87. package/dist/worker/worker_utils.d.ts.map +1 -0
  88. package/dist/{worker.js → worker/worker_utils.js} +5 -5
  89. package/package.json +5 -5
  90. package/src/base.ts +38 -2
  91. package/src/constants.ts +38 -16
  92. package/src/{encryption.ts → encryption/encryption.ts} +1 -193
  93. package/src/encryption/encryption_utils.ts +179 -0
  94. package/src/encryption/index.ts +3 -0
  95. package/src/encryption/types.ts +15 -0
  96. package/src/error.ts +11 -17
  97. package/src/{escrow.ts → escrow/escrow_client.ts} +151 -659
  98. package/src/escrow/escrow_utils.ts +510 -0
  99. package/src/escrow/index.ts +2 -0
  100. package/src/graphql/queries/statistics.ts +37 -1
  101. package/src/graphql/types.ts +4 -1
  102. package/src/index.ts +11 -25
  103. package/src/interfaces.ts +2 -7
  104. package/src/kvstore/index.ts +2 -0
  105. package/src/kvstore/kvstore_client.ts +291 -0
  106. package/src/kvstore/kvstore_utils.ts +244 -0
  107. package/src/operator/index.ts +1 -0
  108. package/src/{operator.ts → operator/operator_utils.ts} +8 -8
  109. package/src/staking/index.ts +2 -0
  110. package/src/{staking.ts → staking/staking_client.ts} +49 -199
  111. package/src/staking/staking_utils.ts +170 -0
  112. package/src/statistics/index.ts +1 -0
  113. package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
  114. package/src/transaction/index.ts +1 -0
  115. package/src/{transaction.ts → transaction/transaction_utils.ts} +11 -11
  116. package/src/types.ts +24 -1
  117. package/src/utils.ts +82 -9
  118. package/src/worker/index.ts +1 -0
  119. package/src/{worker.ts → worker/worker_utils.ts} +7 -7
  120. package/dist/encryption.d.ts +0 -189
  121. package/dist/encryption.d.ts.map +0 -1
  122. package/dist/escrow.d.ts.map +0 -1
  123. package/dist/kvstore.d.ts.map +0 -1
  124. package/dist/operator.d.ts.map +0 -1
  125. package/dist/staking.d.ts.map +0 -1
  126. package/dist/statistics.d.ts.map +0 -1
  127. package/dist/transaction.d.ts.map +0 -1
  128. package/dist/worker.d.ts.map +0 -1
  129. package/src/kvstore.ts +0 -497
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escrow_client.d.ts","sourceRoot":"","sources":["../../src/escrow/escrow_client.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,aAAa,EAKd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAY,SAAS,EAAkB,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA6B3C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IACzC,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;;OAMG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAS5D;;;;;;;OAOG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAiBxE;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;;;;;;;;;;;;;;OAiBG;IAEU,YAAY,CACvB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,S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xE;;;;;;;;;;;;;OAaG;IACG,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBtE;;;;;;;;;;;;;OAaG;IACG,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBhE"}
@@ -9,18 +9,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.EscrowUtils = exports.EscrowClient = void 0;
12
+ exports.EscrowClient = void 0;
13
13
  /* eslint-disable @typescript-eslint/no-explicit-any */
14
14
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
15
15
  const ethers_1 = require("ethers");
16
- const base_1 = require("./base");
17
- const constants_1 = require("./constants");
18
- const decorators_1 = require("./decorators");
19
- const enums_1 = require("./enums");
20
- const error_1 = require("./error");
21
- const graphql_1 = require("./graphql");
22
- const types_1 = require("./types");
23
- const utils_1 = require("./utils");
16
+ const base_1 = require("../base");
17
+ const constants_1 = require("../constants");
18
+ const decorators_1 = require("../decorators");
19
+ const error_1 = require("../error");
20
+ const utils_1 = require("../utils");
24
21
  /**
25
22
  * Client to perform actions on Escrow contracts and obtain information from the contracts.
26
23
  *
@@ -139,7 +136,7 @@ class EscrowClient extends base_1.BaseEthersClient {
139
136
  throw error_1.ErrorInvalidTokenAddress;
140
137
  }
141
138
  try {
142
- const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress, jobRequesterId, txOptions)).wait();
139
+ const result = await this.sendTxAndWait((overrides) => this.escrowFactoryContract.createEscrow(tokenAddress, jobRequesterId, overrides), txOptions);
143
140
  const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
144
141
  if (!event) {
145
142
  throw error_1.ErrorLaunchedEventIsNotEmitted;
@@ -151,7 +148,7 @@ class EscrowClient extends base_1.BaseEthersClient {
151
148
  }
152
149
  }
153
150
  verifySetupParameters(escrowConfig) {
154
- const { recordingOracle, reputationOracle, exchangeOracle, recordingOracleFee, reputationOracleFee, exchangeOracleFee, manifest, manifestHash, } = escrowConfig;
151
+ const { recordingOracle, reputationOracle, exchangeOracle, manifest, manifestHash, } = escrowConfig;
155
152
  if (!ethers_1.ethers.isAddress(recordingOracle)) {
156
153
  throw error_1.ErrorInvalidRecordingOracleAddressProvided;
157
154
  }
@@ -161,14 +158,6 @@ class EscrowClient extends base_1.BaseEthersClient {
161
158
  if (!ethers_1.ethers.isAddress(exchangeOracle)) {
162
159
  throw error_1.ErrorInvalidExchangeOracleAddressProvided;
163
160
  }
164
- if (recordingOracleFee <= 0 ||
165
- reputationOracleFee <= 0 ||
166
- exchangeOracleFee <= 0) {
167
- throw error_1.ErrorAmountMustBeGreaterThanZero;
168
- }
169
- if (recordingOracleFee + reputationOracleFee + exchangeOracleFee > 100) {
170
- throw error_1.ErrorTotalFeeMustBeLessThanHundred;
171
- }
172
161
  const isManifestValid = (0, utils_1.isValidUrl)(manifest) || (0, utils_1.isValidJson)(manifest);
173
162
  if (!isManifestValid) {
174
163
  throw error_1.ErrorInvalidManifest;
@@ -191,8 +180,6 @@ class EscrowClient extends base_1.BaseEthersClient {
191
180
  * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
192
181
  * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
193
182
  * @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
183
  * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
197
184
  * @throws ErrorHashIsEmptyString If the manifest hash is empty
198
185
  * @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
@@ -213,9 +200,6 @@ class EscrowClient extends base_1.BaseEthersClient {
213
200
  * recordingOracle: '0xRecordingOracleAddress',
214
201
  * reputationOracle: '0xReputationOracleAddress',
215
202
  * exchangeOracle: '0xExchangeOracleAddress',
216
- * recordingOracleFee: 5n,
217
- * reputationOracleFee: 5n,
218
- * exchangeOracleFee: 5n,
219
203
  * manifest: 'https://example.com/manifest.json',
220
204
  * manifestHash: 'manifestHash-123',
221
205
  * };
@@ -234,9 +218,9 @@ class EscrowClient extends base_1.BaseEthersClient {
234
218
  throw error_1.ErrorInvalidTokenAddress;
235
219
  }
236
220
  this.verifySetupParameters(escrowConfig);
237
- const { recordingOracle, reputationOracle, exchangeOracle, recordingOracleFee, reputationOracleFee, exchangeOracleFee, manifest, manifestHash, } = escrowConfig;
221
+ const { recordingOracle, reputationOracle, exchangeOracle, manifest, manifestHash, } = escrowConfig;
238
222
  try {
239
- const result = await (await this.escrowFactoryContract.createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, txOptions)).wait();
223
+ const result = await this.sendTxAndWait((overrides) => this.escrowFactoryContract.createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, reputationOracle, recordingOracle, exchangeOracle, manifest, manifestHash, overrides), txOptions);
240
224
  const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
241
225
  if (!event) {
242
226
  throw error_1.ErrorLaunchedEventIsNotEmitted;
@@ -259,8 +243,6 @@ class EscrowClient extends base_1.BaseEthersClient {
259
243
  * @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
260
244
  * @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
261
245
  * @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
246
  * @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
265
247
  * @throws ErrorHashIsEmptyString If the manifest hash is empty
266
248
  * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
@@ -274,9 +256,6 @@ class EscrowClient extends base_1.BaseEthersClient {
274
256
  * recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
275
257
  * reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
276
258
  * exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
277
- * recordingOracleFee: 10n,
278
- * reputationOracleFee: 10n,
279
- * exchangeOracleFee: 10n,
280
259
  * manifest: 'http://localhost/manifest.json',
281
260
  * manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
282
261
  * };
@@ -284,7 +263,7 @@ class EscrowClient extends base_1.BaseEthersClient {
284
263
  * ```
285
264
  */
286
265
  async setup(escrowAddress, escrowConfig, txOptions = {}) {
287
- const { recordingOracle, reputationOracle, exchangeOracle, recordingOracleFee, reputationOracleFee, exchangeOracleFee, manifest, manifestHash, } = escrowConfig;
266
+ const { recordingOracle, reputationOracle, exchangeOracle, manifest, manifestHash, } = escrowConfig;
288
267
  this.verifySetupParameters(escrowConfig);
289
268
  if (!ethers_1.ethers.isAddress(escrowAddress)) {
290
269
  throw error_1.ErrorInvalidEscrowAddressProvided;
@@ -294,7 +273,7 @@ class EscrowClient extends base_1.BaseEthersClient {
294
273
  }
295
274
  try {
296
275
  const escrowContract = this.getEscrowContract(escrowAddress);
297
- await (await escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, txOptions)).wait();
276
+ await this.sendTxAndWait((overrides) => escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, manifest, manifestHash, overrides), txOptions);
298
277
  return;
299
278
  }
300
279
  catch (e) {
@@ -334,7 +313,7 @@ class EscrowClient extends base_1.BaseEthersClient {
334
313
  const escrowContract = this.getEscrowContract(escrowAddress);
335
314
  const tokenAddress = await escrowContract.token();
336
315
  const tokenContract = typechain_types_1.HMToken__factory.connect(tokenAddress, this.runner);
337
- await (await tokenContract.transfer(escrowAddress, amount, txOptions)).wait();
316
+ await this.sendTxAndWait((overrides) => tokenContract.transfer(escrowAddress, amount, overrides), txOptions);
338
317
  return;
339
318
  }
340
319
  catch (e) {
@@ -345,7 +324,7 @@ class EscrowClient extends base_1.BaseEthersClient {
345
324
  const escrowContract = this.getEscrowContract(escrowAddress);
346
325
  const hasFundsToReserveParam = typeof a === 'bigint';
347
326
  const fundsToReserve = hasFundsToReserveParam ? a : null;
348
- const txOptions = (hasFundsToReserveParam ? b : a) || {};
327
+ const txOptions = (hasFundsToReserveParam ? b : a);
349
328
  // When fundsToReserve is provided and is 0, allow empty URL.
350
329
  // In this situation not solutions might have been provided so the escrow can be straight cancelled.
351
330
  const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
@@ -362,12 +341,10 @@ class EscrowClient extends base_1.BaseEthersClient {
362
341
  throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
363
342
  }
364
343
  try {
365
- if (fundsToReserve !== null) {
366
- await (await escrowContract['storeResults(string,string,uint256)'](url, hash, fundsToReserve, txOptions)).wait();
367
- }
368
- else {
369
- await (await escrowContract['storeResults(string,string)'](url, hash, txOptions)).wait();
370
- }
344
+ const txFactory = (overrides) => fundsToReserve !== null
345
+ ? escrowContract['storeResults(string,string,uint256)'](url, hash, fundsToReserve, overrides)
346
+ : escrowContract['storeResults(string,string)'](url, hash, overrides);
347
+ await this.sendTxAndWait(txFactory, txOptions);
371
348
  }
372
349
  catch (e) {
373
350
  if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
@@ -401,7 +378,7 @@ class EscrowClient extends base_1.BaseEthersClient {
401
378
  }
402
379
  try {
403
380
  const escrowContract = this.getEscrowContract(escrowAddress);
404
- await (await escrowContract.complete(txOptions)).wait();
381
+ await this.sendTxAndWait((overrides) => escrowContract.complete(overrides), txOptions);
405
382
  return;
406
383
  }
407
384
  catch (e) {
@@ -413,12 +390,10 @@ class EscrowClient extends base_1.BaseEthersClient {
413
390
  const escrowContract = this.getEscrowContract(escrowAddress);
414
391
  const idIsString = typeof id === 'string';
415
392
  try {
416
- if (idIsString) {
417
- await (await escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
418
- }
419
- else {
420
- await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
421
- }
393
+ const txFactory = (overrides) => idIsString
394
+ ? escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, overrides)
395
+ : escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, overrides);
396
+ await this.sendTxAndWait(txFactory, txOptions);
422
397
  }
423
398
  catch (e) {
424
399
  if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
@@ -453,7 +428,7 @@ class EscrowClient extends base_1.BaseEthersClient {
453
428
  }
454
429
  try {
455
430
  const escrowContract = this.getEscrowContract(escrowAddress);
456
- await (await escrowContract.cancel(txOptions)).wait();
431
+ await this.sendTxAndWait((overrides) => escrowContract.cancel(overrides), txOptions);
457
432
  }
458
433
  catch (e) {
459
434
  return (0, utils_1.throwError)(e);
@@ -483,7 +458,7 @@ class EscrowClient extends base_1.BaseEthersClient {
483
458
  }
484
459
  try {
485
460
  const escrowContract = this.getEscrowContract(escrowAddress);
486
- await (await escrowContract.requestCancellation(txOptions)).wait();
461
+ await this.sendTxAndWait((overrides) => escrowContract.requestCancellation(overrides), txOptions);
487
462
  }
488
463
  catch (e) {
489
464
  return (0, utils_1.throwError)(e);
@@ -524,7 +499,7 @@ class EscrowClient extends base_1.BaseEthersClient {
524
499
  }
525
500
  try {
526
501
  const escrowContract = this.getEscrowContract(escrowAddress);
527
- const transactionReceipt = await (await escrowContract.withdraw(tokenAddress, txOptions)).wait();
502
+ const transactionReceipt = await this.sendTxAndWait((overrides) => escrowContract.withdraw(tokenAddress, overrides), txOptions);
528
503
  let amountTransferred = undefined;
529
504
  const tokenContract = typechain_types_1.ERC20__factory.connect(tokenAddress, this.runner);
530
505
  if (transactionReceipt)
@@ -798,7 +773,30 @@ class EscrowClient extends base_1.BaseEthersClient {
798
773
  }
799
774
  try {
800
775
  const escrowContract = this.getEscrowContract(escrowAddress);
801
- return escrowContract.manifestUrl();
776
+ try {
777
+ return await escrowContract.manifest();
778
+ }
779
+ catch (manifestError) {
780
+ // Fallback for legacy escrows exposing `manifestUrl()` instead of `manifest()`.
781
+ try {
782
+ const provider = this.runner.provider;
783
+ if (!provider) {
784
+ throw error_1.ErrorProviderDoesNotExist;
785
+ }
786
+ const manifestInterface = new ethers_1.ethers.Interface([
787
+ 'function manifestUrl() view returns (string)',
788
+ ]);
789
+ const target = escrowContract.target;
790
+ const data = manifestInterface.encodeFunctionData('manifestUrl');
791
+ const result = await provider.call({ to: target, data });
792
+ return manifestInterface.decodeFunctionResult('manifestUrl', result)[0];
793
+ }
794
+ catch (fallbackError) {
795
+ throw new Error(`Failed to fetch manifest using both manifest() and manifestUrl(). ` +
796
+ `manifest() error: ${(0, utils_1.getErrorMessage)(manifestError)}. ` +
797
+ `manifestUrl() error: ${(0, utils_1.getErrorMessage)(fallbackError)}.`);
798
+ }
799
+ }
802
800
  }
803
801
  catch (e) {
804
802
  return (0, utils_1.throwError)(e);
@@ -1164,381 +1162,3 @@ __decorate([
1164
1162
  __metadata("design:paramtypes", [String, Array, Array, String, String, String, Object, Object]),
1165
1163
  __metadata("design:returntype", Promise)
1166
1164
  ], EscrowClient.prototype, "createBulkPayoutTransaction", null);
1167
- /**
1168
- * Utility helpers for escrow-related queries.
1169
- *
1170
- * @example
1171
- * ```ts
1172
- * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1173
- *
1174
- * const escrows = await EscrowUtils.getEscrows({
1175
- * chainId: ChainId.POLYGON_AMOY
1176
- * });
1177
- * console.log('Escrows:', escrows);
1178
- * ```
1179
- */
1180
- class EscrowUtils {
1181
- /**
1182
- * This function returns an array of escrows based on the specified filter parameters.
1183
- *
1184
- * @param filter - Filter parameters.
1185
- * @param options - Optional configuration for subgraph requests.
1186
- * @returns List of escrows that match the filter.
1187
- * @throws ErrorInvalidAddress If any filter address is invalid
1188
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1189
- *
1190
- * @example
1191
- * ```ts
1192
- * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1193
- *
1194
- * const filters = {
1195
- * status: EscrowStatus.Pending,
1196
- * from: new Date(2023, 4, 8),
1197
- * to: new Date(2023, 5, 8),
1198
- * chainId: ChainId.POLYGON_AMOY
1199
- * };
1200
- * const escrows = await EscrowUtils.getEscrows(filters);
1201
- * console.log('Found escrows:', escrows.length);
1202
- * ```
1203
- */
1204
- static async getEscrows(filter, options) {
1205
- if (filter.launcher && !ethers_1.ethers.isAddress(filter.launcher)) {
1206
- throw error_1.ErrorInvalidAddress;
1207
- }
1208
- if (filter.recordingOracle && !ethers_1.ethers.isAddress(filter.recordingOracle)) {
1209
- throw error_1.ErrorInvalidAddress;
1210
- }
1211
- if (filter.reputationOracle && !ethers_1.ethers.isAddress(filter.reputationOracle)) {
1212
- throw error_1.ErrorInvalidAddress;
1213
- }
1214
- if (filter.exchangeOracle && !ethers_1.ethers.isAddress(filter.exchangeOracle)) {
1215
- throw error_1.ErrorInvalidAddress;
1216
- }
1217
- const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1218
- const skip = filter.skip || 0;
1219
- const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
1220
- const networkData = constants_1.NETWORKS[filter.chainId];
1221
- if (!networkData) {
1222
- throw error_1.ErrorUnsupportedChainID;
1223
- }
1224
- let statuses;
1225
- if (filter.status !== undefined) {
1226
- statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
1227
- statuses = statuses.map((status) => types_1.EscrowStatus[status]);
1228
- }
1229
- const { escrows } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_ESCROWS_QUERY)(filter), {
1230
- ...filter,
1231
- launcher: filter.launcher?.toLowerCase(),
1232
- reputationOracle: filter.reputationOracle?.toLowerCase(),
1233
- recordingOracle: filter.recordingOracle?.toLowerCase(),
1234
- exchangeOracle: filter.exchangeOracle?.toLowerCase(),
1235
- status: statuses,
1236
- from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
1237
- to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
1238
- orderDirection: orderDirection,
1239
- first: first,
1240
- skip: skip,
1241
- }, options);
1242
- return (escrows || []).map((e) => mapEscrow(e, networkData.chainId));
1243
- }
1244
- /**
1245
- * This function returns the escrow data for a given address.
1246
- *
1247
- * > This uses Subgraph
1248
- *
1249
- * @param chainId - Network in which the escrow has been deployed
1250
- * @param escrowAddress - Address of the escrow
1251
- * @param options - Optional configuration for subgraph requests.
1252
- * @returns Escrow data or null if not found.
1253
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1254
- * @throws ErrorInvalidAddress If the escrow address is invalid
1255
- *
1256
- * @example
1257
- * ```ts
1258
- * import { ChainId } from '@human-protocol/sdk';
1259
- *
1260
- * const escrow = await EscrowUtils.getEscrow(
1261
- * ChainId.POLYGON_AMOY,
1262
- * "0x1234567890123456789012345678901234567890"
1263
- * );
1264
- * if (escrow) {
1265
- * console.log('Escrow status:', escrow.status);
1266
- * }
1267
- * ```
1268
- */
1269
- static async getEscrow(chainId, escrowAddress, options) {
1270
- const networkData = constants_1.NETWORKS[chainId];
1271
- if (!networkData) {
1272
- throw error_1.ErrorUnsupportedChainID;
1273
- }
1274
- if (escrowAddress && !ethers_1.ethers.isAddress(escrowAddress)) {
1275
- throw error_1.ErrorInvalidAddress;
1276
- }
1277
- const { escrow } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_ESCROW_BY_ADDRESS_QUERY)(), { escrowAddress: escrowAddress.toLowerCase() }, options);
1278
- if (!escrow)
1279
- return null;
1280
- return mapEscrow(escrow, networkData.chainId);
1281
- }
1282
- /**
1283
- * This function returns the status events for a given set of networks within an optional date range.
1284
- *
1285
- * > This uses Subgraph
1286
- *
1287
- * @param filter - Filter parameters.
1288
- * @param options - Optional configuration for subgraph requests.
1289
- * @returns Array of status events with their corresponding statuses.
1290
- * @throws ErrorInvalidAddress If the launcher address is invalid
1291
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1292
- *
1293
- * @example
1294
- * ```ts
1295
- * import { ChainId, EscrowStatus } from '@human-protocol/sdk';
1296
- *
1297
- * const fromDate = new Date('2023-01-01');
1298
- * const toDate = new Date('2023-12-31');
1299
- * const statusEvents = await EscrowUtils.getStatusEvents({
1300
- * chainId: ChainId.POLYGON,
1301
- * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1302
- * from: fromDate,
1303
- * to: toDate
1304
- * });
1305
- * console.log('Status events:', statusEvents.length);
1306
- * ```
1307
- */
1308
- static async getStatusEvents(filter, options) {
1309
- const { chainId, statuses, from, to, launcher, first = 10, skip = 0, orderDirection = enums_1.OrderDirection.DESC, } = filter;
1310
- if (launcher && !ethers_1.ethers.isAddress(launcher)) {
1311
- throw error_1.ErrorInvalidAddress;
1312
- }
1313
- const networkData = constants_1.NETWORKS[chainId];
1314
- if (!networkData) {
1315
- throw error_1.ErrorUnsupportedChainID;
1316
- }
1317
- // If statuses are not provided, use all statuses except Launched
1318
- const effectiveStatuses = statuses ?? [
1319
- types_1.EscrowStatus.Launched,
1320
- types_1.EscrowStatus.Pending,
1321
- types_1.EscrowStatus.Partial,
1322
- types_1.EscrowStatus.Paid,
1323
- types_1.EscrowStatus.Complete,
1324
- types_1.EscrowStatus.Cancelled,
1325
- ];
1326
- const statusNames = effectiveStatuses.map((status) => types_1.EscrowStatus[status]);
1327
- const data = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_STATUS_UPDATES_QUERY)(from, to, launcher), {
1328
- status: statusNames,
1329
- from: from ? (0, utils_1.getUnixTimestamp)(from) : undefined,
1330
- to: to ? (0, utils_1.getUnixTimestamp)(to) : undefined,
1331
- launcher: launcher || undefined,
1332
- orderDirection,
1333
- first: Math.min(first, 1000),
1334
- skip,
1335
- }, options);
1336
- if (!data || !data['escrowStatusEvents']) {
1337
- return [];
1338
- }
1339
- return data['escrowStatusEvents'].map((event) => ({
1340
- timestamp: Number(event.timestamp) * 1000,
1341
- escrowAddress: event.escrowAddress,
1342
- status: types_1.EscrowStatus[event.status],
1343
- chainId,
1344
- }));
1345
- }
1346
- /**
1347
- * This function returns the payouts for a given set of networks.
1348
- *
1349
- * > This uses Subgraph
1350
- *
1351
- * @param filter - Filter parameters.
1352
- * @param options - Optional configuration for subgraph requests.
1353
- * @returns List of payouts matching the filters.
1354
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1355
- * @throws ErrorInvalidAddress If any filter address is invalid
1356
- *
1357
- * @example
1358
- * ```ts
1359
- * import { ChainId } from '@human-protocol/sdk';
1360
- *
1361
- * const payouts = await EscrowUtils.getPayouts({
1362
- * chainId: ChainId.POLYGON,
1363
- * escrowAddress: '0x1234567890123456789012345678901234567890',
1364
- * recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
1365
- * from: new Date('2023-01-01'),
1366
- * to: new Date('2023-12-31')
1367
- * });
1368
- * console.log('Payouts:', payouts.length);
1369
- * ```
1370
- */
1371
- static async getPayouts(filter, options) {
1372
- const networkData = constants_1.NETWORKS[filter.chainId];
1373
- if (!networkData) {
1374
- throw error_1.ErrorUnsupportedChainID;
1375
- }
1376
- if (filter.escrowAddress && !ethers_1.ethers.isAddress(filter.escrowAddress)) {
1377
- throw error_1.ErrorInvalidAddress;
1378
- }
1379
- if (filter.recipient && !ethers_1.ethers.isAddress(filter.recipient)) {
1380
- throw error_1.ErrorInvalidAddress;
1381
- }
1382
- const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1383
- const skip = filter.skip || 0;
1384
- const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
1385
- const { payouts } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_PAYOUTS_QUERY)(filter), {
1386
- escrowAddress: filter.escrowAddress?.toLowerCase(),
1387
- recipient: filter.recipient?.toLowerCase(),
1388
- from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
1389
- to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
1390
- first: Math.min(first, 1000),
1391
- skip,
1392
- orderDirection,
1393
- }, options);
1394
- if (!payouts) {
1395
- return [];
1396
- }
1397
- return payouts.map((payout) => ({
1398
- id: payout.id,
1399
- escrowAddress: payout.escrowAddress,
1400
- recipient: payout.recipient,
1401
- amount: BigInt(payout.amount),
1402
- createdAt: Number(payout.createdAt) * 1000,
1403
- }));
1404
- }
1405
- /**
1406
- * This function returns the cancellation refunds for a given set of networks.
1407
- *
1408
- * > This uses Subgraph
1409
- *
1410
- * @param filter - Filter parameters.
1411
- * @param options - Optional configuration for subgraph requests.
1412
- * @returns List of cancellation refunds matching the filters.
1413
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1414
- * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1415
- * @throws ErrorInvalidAddress If the receiver address is invalid
1416
- *
1417
- * @example
1418
- * ```ts
1419
- * import { ChainId } from '@human-protocol/sdk';
1420
- *
1421
- * const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
1422
- * chainId: ChainId.POLYGON_AMOY,
1423
- * escrowAddress: '0x1234567890123456789012345678901234567890',
1424
- * });
1425
- * console.log('Cancellation refunds:', cancellationRefunds.length);
1426
- * ```
1427
- */
1428
- static async getCancellationRefunds(filter, options) {
1429
- const networkData = constants_1.NETWORKS[filter.chainId];
1430
- if (!networkData)
1431
- throw error_1.ErrorUnsupportedChainID;
1432
- if (filter.escrowAddress && !ethers_1.ethers.isAddress(filter.escrowAddress)) {
1433
- throw error_1.ErrorInvalidEscrowAddressProvided;
1434
- }
1435
- if (filter.receiver && !ethers_1.ethers.isAddress(filter.receiver)) {
1436
- throw error_1.ErrorInvalidAddress;
1437
- }
1438
- const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1439
- const skip = filter.skip || 0;
1440
- const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
1441
- const { cancellationRefundEvents } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_CANCELLATION_REFUNDS_QUERY)(filter), {
1442
- escrowAddress: filter.escrowAddress?.toLowerCase(),
1443
- receiver: filter.receiver?.toLowerCase(),
1444
- from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
1445
- to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
1446
- first,
1447
- skip,
1448
- orderDirection,
1449
- }, options);
1450
- if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
1451
- return [];
1452
- }
1453
- return cancellationRefundEvents.map((event) => ({
1454
- id: event.id,
1455
- escrowAddress: event.escrowAddress,
1456
- receiver: event.receiver,
1457
- amount: BigInt(event.amount),
1458
- block: Number(event.block),
1459
- timestamp: Number(event.timestamp) * 1000,
1460
- txHash: event.txHash,
1461
- }));
1462
- }
1463
- /**
1464
- * This function returns the cancellation refund for a given escrow address.
1465
- *
1466
- * > This uses Subgraph
1467
- *
1468
- * @param chainId - Network in which the escrow has been deployed
1469
- * @param escrowAddress - Address of the escrow
1470
- * @param options - Optional configuration for subgraph requests.
1471
- * @returns Cancellation refund data or null if not found.
1472
- * @throws ErrorUnsupportedChainID If the chain ID is not supported
1473
- * @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
1474
- *
1475
- * @example
1476
- * ```ts
1477
- * import { ChainId } from '@human-protocol/sdk';
1478
- *
1479
- *
1480
- * const cancellationRefund = await EscrowUtils.getCancellationRefund(
1481
- * ChainId.POLYGON_AMOY,
1482
- * "0x1234567890123456789012345678901234567890"
1483
- * );
1484
- * if (cancellationRefund) {
1485
- * console.log('Refund amount:', cancellationRefund.amount);
1486
- * }
1487
- * ```
1488
- */
1489
- static async getCancellationRefund(chainId, escrowAddress, options) {
1490
- const networkData = constants_1.NETWORKS[chainId];
1491
- if (!networkData)
1492
- throw error_1.ErrorUnsupportedChainID;
1493
- if (!ethers_1.ethers.isAddress(escrowAddress)) {
1494
- throw error_1.ErrorInvalidEscrowAddressProvided;
1495
- }
1496
- const { cancellationRefundEvents } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY)(), { escrowAddress: escrowAddress.toLowerCase() }, options);
1497
- if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
1498
- return null;
1499
- }
1500
- return {
1501
- id: cancellationRefundEvents[0].id,
1502
- escrowAddress: cancellationRefundEvents[0].escrowAddress,
1503
- receiver: cancellationRefundEvents[0].receiver,
1504
- amount: BigInt(cancellationRefundEvents[0].amount),
1505
- block: Number(cancellationRefundEvents[0].block),
1506
- timestamp: Number(cancellationRefundEvents[0].timestamp) * 1000,
1507
- txHash: cancellationRefundEvents[0].txHash,
1508
- };
1509
- }
1510
- }
1511
- exports.EscrowUtils = EscrowUtils;
1512
- function mapEscrow(e, chainId) {
1513
- return {
1514
- id: e.id,
1515
- address: e.address,
1516
- amountPaid: BigInt(e.amountPaid),
1517
- balance: BigInt(e.balance),
1518
- count: Number(e.count),
1519
- factoryAddress: e.factoryAddress,
1520
- finalResultsUrl: e.finalResultsUrl,
1521
- finalResultsHash: e.finalResultsHash,
1522
- intermediateResultsUrl: e.intermediateResultsUrl,
1523
- intermediateResultsHash: e.intermediateResultsHash,
1524
- launcher: e.launcher,
1525
- jobRequesterId: e.jobRequesterId,
1526
- manifestHash: e.manifestHash,
1527
- manifest: e.manifest,
1528
- recordingOracle: e.recordingOracle,
1529
- reputationOracle: e.reputationOracle,
1530
- exchangeOracle: e.exchangeOracle,
1531
- recordingOracleFee: e.recordingOracleFee
1532
- ? Number(e.recordingOracleFee)
1533
- : null,
1534
- reputationOracleFee: e.reputationOracleFee
1535
- ? Number(e.reputationOracleFee)
1536
- : null,
1537
- exchangeOracleFee: e.exchangeOracleFee ? Number(e.exchangeOracleFee) : null,
1538
- status: e.status,
1539
- token: e.token,
1540
- totalFundedAmount: BigInt(e.totalFundedAmount),
1541
- createdAt: Number(e.createdAt) * 1000,
1542
- chainId: Number(chainId),
1543
- };
1544
- }