@human-protocol/sdk 4.2.0 → 5.0.0-beta.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/constants.js +4 -4
- package/dist/error.d.ts +16 -4
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +18 -6
- package/dist/escrow.d.ts +238 -28
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +255 -152
- package/dist/graphql/queries/escrow.d.ts +3 -1
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +49 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +11 -9
- package/dist/graphql/queries/staking.d.ts +4 -0
- package/dist/graphql/queries/staking.d.ts.map +1 -0
- package/dist/graphql/queries/staking.js +71 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/interfaces.d.ts +56 -16
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +53 -58
- package/dist/staking.d.ts +21 -1
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +84 -1
- package/dist/types.d.ts +39 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/package.json +2 -2
- package/src/constants.ts +4 -4
- package/src/error.ts +25 -7
- package/src/escrow.ts +416 -113
- package/src/graphql/queries/escrow.ts +52 -1
- package/src/graphql/queries/operator.ts +11 -9
- package/src/graphql/queries/staking.ts +80 -0
- package/src/index.ts +2 -1
- package/src/interfaces.ts +63 -18
- package/src/operator.ts +62 -76
- package/src/staking.ts +106 -3
- package/src/types.ts +40 -15
package/dist/escrow.js
CHANGED
|
@@ -143,7 +143,6 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
143
143
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
144
144
|
*
|
|
145
145
|
* @param {string} tokenAddress Token address to use for payouts.
|
|
146
|
-
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
147
146
|
* @param {string} jobRequesterId Job Requester Id
|
|
148
147
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
149
148
|
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
@@ -165,22 +164,16 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
165
164
|
* const escrowClient = await EscrowClient.build(signer);
|
|
166
165
|
*
|
|
167
166
|
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
168
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
169
167
|
* const jobRequesterId = "job-requester-id";
|
|
170
|
-
* const escrowAddress = await escrowClient.createEscrow(tokenAddress,
|
|
168
|
+
* const escrowAddress = await escrowClient.createEscrow(tokenAddress, jobRequesterId);
|
|
171
169
|
* ```
|
|
172
170
|
*/
|
|
173
|
-
async createEscrow(tokenAddress,
|
|
171
|
+
async createEscrow(tokenAddress, jobRequesterId, txOptions = {}) {
|
|
174
172
|
if (!ethers_1.ethers.isAddress(tokenAddress)) {
|
|
175
173
|
throw error_1.ErrorInvalidTokenAddress;
|
|
176
174
|
}
|
|
177
|
-
trustedHandlers.forEach((trustedHandler) => {
|
|
178
|
-
if (!ethers_1.ethers.isAddress(trustedHandler)) {
|
|
179
|
-
throw new error_1.InvalidEthereumAddressError(trustedHandler);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
175
|
try {
|
|
183
|
-
const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress,
|
|
176
|
+
const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress, jobRequesterId, txOptions)).wait();
|
|
184
177
|
const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
|
|
185
178
|
if (!event) {
|
|
186
179
|
throw error_1.ErrorLaunchedEventIsNotEmitted;
|
|
@@ -202,7 +195,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
202
195
|
*
|
|
203
196
|
* **Code example**
|
|
204
197
|
*
|
|
205
|
-
* > Only Job Launcher or
|
|
198
|
+
* > Only Job Launcher or admin can call it.
|
|
206
199
|
*
|
|
207
200
|
* ```ts
|
|
208
201
|
* import { Wallet, providers } from 'ethers';
|
|
@@ -317,56 +310,40 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
317
310
|
return (0, utils_1.throwError)(e);
|
|
318
311
|
}
|
|
319
312
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* **Code example**
|
|
331
|
-
*
|
|
332
|
-
* > Only Recording Oracle or a trusted handler can call it.
|
|
333
|
-
*
|
|
334
|
-
* ```ts
|
|
335
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
336
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
337
|
-
*
|
|
338
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
339
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
340
|
-
*
|
|
341
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
342
|
-
* const signer = new Wallet(privateKey, provider);
|
|
343
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
344
|
-
*
|
|
345
|
-
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
async storeResults(escrowAddress, url, hash, txOptions = {}) {
|
|
313
|
+
async storeResults(escrowAddress, url, hash, a, b) {
|
|
314
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
315
|
+
const hasFundsToReserveParam = typeof a === 'bigint';
|
|
316
|
+
const fundsToReserve = hasFundsToReserveParam ? a : undefined;
|
|
317
|
+
const txOptions = (hasFundsToReserveParam ? b : a) || {};
|
|
318
|
+
// When fundsToReserve is provided and is 0, allow empty URL.
|
|
319
|
+
// In this situation not solutions might have been provided so the escrow can be straight cancelled.
|
|
320
|
+
const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
|
|
349
321
|
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
350
322
|
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
351
323
|
}
|
|
352
|
-
if (!url) {
|
|
353
|
-
throw error_1.ErrorInvalidUrl;
|
|
354
|
-
}
|
|
355
|
-
if (!(0, utils_1.isValidUrl)(url)) {
|
|
324
|
+
if (!allowEmptyUrl && !(0, utils_1.isValidUrl)(url)) {
|
|
356
325
|
throw error_1.ErrorInvalidUrl;
|
|
357
326
|
}
|
|
358
|
-
if (!hash) {
|
|
327
|
+
if (!hash && !allowEmptyUrl) {
|
|
359
328
|
throw error_1.ErrorHashIsEmptyString;
|
|
360
329
|
}
|
|
361
330
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
362
331
|
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
363
332
|
}
|
|
364
333
|
try {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
334
|
+
if (fundsToReserve !== undefined) {
|
|
335
|
+
await (await escrowContract['storeResults(string,string,uint256)'](url, hash, fundsToReserve, txOptions)).wait();
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
await (await escrowContract['storeResults(string,string)'](url, hash, txOptions)).wait();
|
|
339
|
+
}
|
|
368
340
|
}
|
|
369
341
|
catch (e) {
|
|
342
|
+
if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
343
|
+
throw error_1.ErrorStoreResultsVersion;
|
|
344
|
+
}
|
|
345
|
+
// eslint-disable-next-line no-console
|
|
346
|
+
console.warn(error_1.WarnVersionMismatch);
|
|
370
347
|
return (0, utils_1.throwError)(e);
|
|
371
348
|
}
|
|
372
349
|
}
|
|
@@ -380,7 +357,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
380
357
|
*
|
|
381
358
|
* **Code example**
|
|
382
359
|
*
|
|
383
|
-
* > Only Recording Oracle or
|
|
360
|
+
* > Only Recording Oracle or admin can call it.
|
|
384
361
|
*
|
|
385
362
|
* ```ts
|
|
386
363
|
* import { Wallet, providers } from 'ethers';
|
|
@@ -412,57 +389,24 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
412
389
|
return (0, utils_1.throwError)(e);
|
|
413
390
|
}
|
|
414
391
|
}
|
|
415
|
-
|
|
416
|
-
* This function pays out the amounts specified to the workers and sets the URL of the final results file.
|
|
417
|
-
*
|
|
418
|
-
* @param {string} escrowAddress Escrow address to payout.
|
|
419
|
-
* @param {string[]} recipients Array of recipient addresses.
|
|
420
|
-
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
421
|
-
* @param {string} finalResultsUrl Final results file URL.
|
|
422
|
-
* @param {string} finalResultsHash Final results file hash.
|
|
423
|
-
* @param {number} txId Transaction ID.
|
|
424
|
-
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
425
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
426
|
-
* @returns Returns void if successful. Throws error if any.
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* **Code example**
|
|
430
|
-
*
|
|
431
|
-
* > Only Reputation Oracle or a trusted handler can call it.
|
|
432
|
-
*
|
|
433
|
-
* ```ts
|
|
434
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
435
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
436
|
-
*
|
|
437
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
438
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
439
|
-
*
|
|
440
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
441
|
-
* const signer = new Wallet(privateKey, provider);
|
|
442
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
443
|
-
*
|
|
444
|
-
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
445
|
-
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
446
|
-
* const resultsUrl = 'http://localhost/results.json';
|
|
447
|
-
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
448
|
-
* const txId = 1;
|
|
449
|
-
*
|
|
450
|
-
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
451
|
-
* ```
|
|
452
|
-
*/
|
|
453
|
-
async bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete = false, txOptions = {}) {
|
|
392
|
+
async bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions = {}) {
|
|
454
393
|
await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
394
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
395
|
+
const idIsString = typeof id === 'string';
|
|
455
396
|
try {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, txOptions)).wait();
|
|
397
|
+
if (idIsString) {
|
|
398
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
|
|
459
399
|
}
|
|
460
400
|
else {
|
|
461
|
-
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256)'](recipients, amounts, finalResultsUrl, finalResultsHash,
|
|
401
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, id, forceComplete, txOptions)).wait();
|
|
462
402
|
}
|
|
463
|
-
return;
|
|
464
403
|
}
|
|
465
404
|
catch (e) {
|
|
405
|
+
if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
406
|
+
throw error_1.ErrorBulkPayOutVersion;
|
|
407
|
+
}
|
|
408
|
+
// eslint-disable-next-line no-console
|
|
409
|
+
console.warn(error_1.WarnVersionMismatch);
|
|
466
410
|
return (0, utils_1.throwError)(e);
|
|
467
411
|
}
|
|
468
412
|
}
|
|
@@ -471,12 +415,11 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
471
415
|
*
|
|
472
416
|
* @param {string} escrowAddress Address of the escrow to cancel.
|
|
473
417
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
474
|
-
* @returns {EscrowCancel} Returns the escrow cancellation data including transaction hash and refunded amount. Throws error if any.
|
|
475
418
|
*
|
|
476
419
|
*
|
|
477
420
|
* **Code example**
|
|
478
421
|
*
|
|
479
|
-
* > Only Job Launcher or
|
|
422
|
+
* > Only Job Launcher or admin can call it.
|
|
480
423
|
*
|
|
481
424
|
* ```ts
|
|
482
425
|
* import { ethers, Wallet, providers } from 'ethers';
|
|
@@ -501,49 +444,22 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
501
444
|
}
|
|
502
445
|
try {
|
|
503
446
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
504
|
-
|
|
505
|
-
let amountTransferred = undefined;
|
|
506
|
-
const tokenAddress = await escrowContract.token();
|
|
507
|
-
const tokenContract = typechain_types_1.HMToken__factory.connect(tokenAddress, this.runner);
|
|
508
|
-
if (transactionReceipt)
|
|
509
|
-
for (const log of transactionReceipt.logs) {
|
|
510
|
-
if (log.address === tokenAddress) {
|
|
511
|
-
const parsedLog = tokenContract.interface.parseLog({
|
|
512
|
-
topics: log.topics,
|
|
513
|
-
data: log.data,
|
|
514
|
-
});
|
|
515
|
-
const from = parsedLog?.args[0];
|
|
516
|
-
if (parsedLog?.name === 'Transfer' && from === escrowAddress) {
|
|
517
|
-
amountTransferred = parsedLog?.args[2];
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
if (amountTransferred === undefined) {
|
|
523
|
-
throw error_1.ErrorTransferEventNotFoundInTransactionLogs;
|
|
524
|
-
}
|
|
525
|
-
const escrowCancelData = {
|
|
526
|
-
txHash: transactionReceipt?.hash || '',
|
|
527
|
-
amountRefunded: amountTransferred,
|
|
528
|
-
};
|
|
529
|
-
return escrowCancelData;
|
|
447
|
+
await (await escrowContract.cancel(txOptions)).wait();
|
|
530
448
|
}
|
|
531
449
|
catch (e) {
|
|
532
450
|
return (0, utils_1.throwError)(e);
|
|
533
451
|
}
|
|
534
452
|
}
|
|
535
453
|
/**
|
|
536
|
-
* This function
|
|
454
|
+
* This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
|
|
537
455
|
*
|
|
538
|
-
* @param {string} escrowAddress Address of the escrow.
|
|
539
|
-
* @param {string[]} trustedHandlers Array of addresses of trusted handlers to add.
|
|
456
|
+
* @param {string} escrowAddress Address of the escrow to request cancellation.
|
|
540
457
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
541
458
|
* @returns Returns void if successful. Throws error if any.
|
|
542
459
|
*
|
|
543
|
-
*
|
|
544
460
|
* **Code example**
|
|
545
461
|
*
|
|
546
|
-
* > Only Job Launcher or
|
|
462
|
+
* > Only Job Launcher or admin can call it.
|
|
547
463
|
*
|
|
548
464
|
* ```ts
|
|
549
465
|
* import { Wallet, providers } from 'ethers';
|
|
@@ -556,29 +472,19 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
556
472
|
* const signer = new Wallet(privateKey, provider);
|
|
557
473
|
* const escrowClient = await EscrowClient.build(signer);
|
|
558
474
|
*
|
|
559
|
-
*
|
|
560
|
-
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
475
|
+
* await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
561
476
|
* ```
|
|
562
477
|
*/
|
|
563
|
-
async
|
|
478
|
+
async requestCancellation(escrowAddress, txOptions = {}) {
|
|
564
479
|
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
565
480
|
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
566
481
|
}
|
|
567
|
-
if (trustedHandlers.length === 0) {
|
|
568
|
-
throw error_1.ErrorListOfHandlersCannotBeEmpty;
|
|
569
|
-
}
|
|
570
|
-
trustedHandlers.forEach((trustedHandler) => {
|
|
571
|
-
if (!ethers_1.ethers.isAddress(trustedHandler)) {
|
|
572
|
-
throw new error_1.InvalidEthereumAddressError(trustedHandler);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
482
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
576
483
|
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
577
484
|
}
|
|
578
485
|
try {
|
|
579
486
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
580
|
-
await (await escrowContract.
|
|
581
|
-
return;
|
|
487
|
+
await (await escrowContract.requestCancellation(txOptions)).wait();
|
|
582
488
|
}
|
|
583
489
|
catch (e) {
|
|
584
490
|
return (0, utils_1.throwError)(e);
|
|
@@ -595,7 +501,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
595
501
|
*
|
|
596
502
|
* **Code example**
|
|
597
503
|
*
|
|
598
|
-
* > Only Job Launcher or
|
|
504
|
+
* > Only Job Launcher or admin can call it.
|
|
599
505
|
*
|
|
600
506
|
* ```ts
|
|
601
507
|
* import { ethers, Wallet, providers } from 'ethers';
|
|
@@ -649,7 +555,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
649
555
|
const escrowWithdrawData = {
|
|
650
556
|
txHash: transactionReceipt?.hash || '',
|
|
651
557
|
tokenAddress,
|
|
652
|
-
|
|
558
|
+
withdrawnAmount: amountTransferred,
|
|
653
559
|
};
|
|
654
560
|
return escrowWithdrawData;
|
|
655
561
|
}
|
|
@@ -664,14 +570,14 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
664
570
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
665
571
|
* @param {string} finalResultsUrl Final results file URL.
|
|
666
572
|
* @param {string} finalResultsHash Final results file hash.
|
|
667
|
-
* @param {
|
|
573
|
+
* @param {string} payoutId Payout ID to identify the payout.
|
|
668
574
|
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
669
575
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
670
576
|
* @returns Returns object with raw transaction and signed transaction hash
|
|
671
577
|
*
|
|
672
578
|
* **Code example**
|
|
673
579
|
*
|
|
674
|
-
* > Only Reputation Oracle or
|
|
580
|
+
* > Only Reputation Oracle or admin can call it.
|
|
675
581
|
*
|
|
676
582
|
* ```ts
|
|
677
583
|
* import { ethers, Wallet, providers } from 'ethers';
|
|
@@ -688,7 +594,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
688
594
|
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
689
595
|
* const resultsUrl = 'http://localhost/results.json';
|
|
690
596
|
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
691
|
-
* const
|
|
597
|
+
* const payoutId = '372f6916-fe34-4711-b6e3-274f682047de';
|
|
692
598
|
*
|
|
693
599
|
* const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
694
600
|
* console.log('Raw transaction:', rawTransaction);
|
|
@@ -697,12 +603,12 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
697
603
|
* console.log('Tx hash:', ethers.keccak256(signedTransaction));
|
|
698
604
|
* (await signer.sendTransaction(rawTransaction)).wait();
|
|
699
605
|
*/
|
|
700
|
-
async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash,
|
|
606
|
+
async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete = false, txOptions = {}) {
|
|
701
607
|
await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
702
608
|
const signer = this.runner;
|
|
703
609
|
try {
|
|
704
610
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
705
|
-
const populatedTransaction = await escrowContract['bulkPayOut(address[],uint256[],string,string,
|
|
611
|
+
const populatedTransaction = await escrowContract['bulkPayOut(address[],uint256[],string,string,string,bool)'].populateTransaction(recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete, txOptions);
|
|
706
612
|
/**
|
|
707
613
|
* Safety-belt: explicitly set the passed nonce
|
|
708
614
|
* because 'populateTransaction' return value
|
|
@@ -815,6 +721,41 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
815
721
|
return (0, utils_1.throwError)(e);
|
|
816
722
|
}
|
|
817
723
|
}
|
|
724
|
+
/**
|
|
725
|
+
* This function returns the reserved funds for a specified escrow address.
|
|
726
|
+
*
|
|
727
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
728
|
+
* @returns {Promise<bigint>} Reserved funds of the escrow in the token used to fund it.
|
|
729
|
+
*
|
|
730
|
+
* **Code example**
|
|
731
|
+
*
|
|
732
|
+
* ```ts
|
|
733
|
+
* import { providers } from 'ethers';
|
|
734
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
735
|
+
*
|
|
736
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
737
|
+
*
|
|
738
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
739
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
740
|
+
*
|
|
741
|
+
* const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
async getReservedFunds(escrowAddress) {
|
|
745
|
+
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
746
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
747
|
+
}
|
|
748
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
749
|
+
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
750
|
+
}
|
|
751
|
+
try {
|
|
752
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
753
|
+
return await escrowContract.reservedFunds();
|
|
754
|
+
}
|
|
755
|
+
catch (e) {
|
|
756
|
+
return (0, utils_1.throwError)(e);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
818
759
|
/**
|
|
819
760
|
* This function returns the manifest file hash.
|
|
820
761
|
*
|
|
@@ -955,6 +896,41 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
955
896
|
return (0, utils_1.throwError)(e);
|
|
956
897
|
}
|
|
957
898
|
}
|
|
899
|
+
/**
|
|
900
|
+
* This function returns the intermediate results hash.
|
|
901
|
+
*
|
|
902
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
903
|
+
* @returns {Promise<string>} Hash of the intermediate results file content.
|
|
904
|
+
*
|
|
905
|
+
* **Code example**
|
|
906
|
+
*
|
|
907
|
+
* ```ts
|
|
908
|
+
* import { providers } from 'ethers';
|
|
909
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
910
|
+
*
|
|
911
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
912
|
+
*
|
|
913
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
914
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
915
|
+
*
|
|
916
|
+
* const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
917
|
+
* ```
|
|
918
|
+
*/
|
|
919
|
+
async getIntermediateResultsHash(escrowAddress) {
|
|
920
|
+
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
921
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
922
|
+
}
|
|
923
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
924
|
+
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
925
|
+
}
|
|
926
|
+
try {
|
|
927
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
928
|
+
return escrowContract.intermediateResultsHash();
|
|
929
|
+
}
|
|
930
|
+
catch (e) {
|
|
931
|
+
return (0, utils_1.throwError)(e);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
958
934
|
/**
|
|
959
935
|
* This function returns the token address used for funding the escrow.
|
|
960
936
|
*
|
|
@@ -1205,7 +1181,7 @@ exports.EscrowClient = EscrowClient;
|
|
|
1205
1181
|
__decorate([
|
|
1206
1182
|
decorators_1.requiresSigner,
|
|
1207
1183
|
__metadata("design:type", Function),
|
|
1208
|
-
__metadata("design:paramtypes", [String,
|
|
1184
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
1209
1185
|
__metadata("design:returntype", Promise)
|
|
1210
1186
|
], EscrowClient.prototype, "createEscrow", null);
|
|
1211
1187
|
__decorate([
|
|
@@ -1223,7 +1199,7 @@ __decorate([
|
|
|
1223
1199
|
__decorate([
|
|
1224
1200
|
decorators_1.requiresSigner,
|
|
1225
1201
|
__metadata("design:type", Function),
|
|
1226
|
-
__metadata("design:paramtypes", [String, String, String, Object]),
|
|
1202
|
+
__metadata("design:paramtypes", [String, String, String, Object, Object]),
|
|
1227
1203
|
__metadata("design:returntype", Promise)
|
|
1228
1204
|
], EscrowClient.prototype, "storeResults", null);
|
|
1229
1205
|
__decorate([
|
|
@@ -1235,7 +1211,7 @@ __decorate([
|
|
|
1235
1211
|
__decorate([
|
|
1236
1212
|
decorators_1.requiresSigner,
|
|
1237
1213
|
__metadata("design:type", Function),
|
|
1238
|
-
__metadata("design:paramtypes", [String, Array, Array, String, String,
|
|
1214
|
+
__metadata("design:paramtypes", [String, Array, Array, String, String, Object, Boolean, Object]),
|
|
1239
1215
|
__metadata("design:returntype", Promise)
|
|
1240
1216
|
], EscrowClient.prototype, "bulkPayOut", null);
|
|
1241
1217
|
__decorate([
|
|
@@ -1247,9 +1223,9 @@ __decorate([
|
|
|
1247
1223
|
__decorate([
|
|
1248
1224
|
decorators_1.requiresSigner,
|
|
1249
1225
|
__metadata("design:type", Function),
|
|
1250
|
-
__metadata("design:paramtypes", [String,
|
|
1226
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
1251
1227
|
__metadata("design:returntype", Promise)
|
|
1252
|
-
], EscrowClient.prototype, "
|
|
1228
|
+
], EscrowClient.prototype, "requestCancellation", null);
|
|
1253
1229
|
__decorate([
|
|
1254
1230
|
decorators_1.requiresSigner,
|
|
1255
1231
|
__metadata("design:type", Function),
|
|
@@ -1259,7 +1235,7 @@ __decorate([
|
|
|
1259
1235
|
__decorate([
|
|
1260
1236
|
decorators_1.requiresSigner,
|
|
1261
1237
|
__metadata("design:type", Function),
|
|
1262
|
-
__metadata("design:paramtypes", [String, Array, Array, String, String,
|
|
1238
|
+
__metadata("design:paramtypes", [String, Array, Array, String, String, String, Object, Object]),
|
|
1263
1239
|
__metadata("design:returntype", Promise)
|
|
1264
1240
|
], EscrowClient.prototype, "createBulkPayoutTransaction", null);
|
|
1265
1241
|
/**
|
|
@@ -1647,5 +1623,132 @@ class EscrowUtils {
|
|
|
1647
1623
|
});
|
|
1648
1624
|
return payouts || [];
|
|
1649
1625
|
}
|
|
1626
|
+
/**
|
|
1627
|
+
* This function returns the cancellation refunds for a given set of networks.
|
|
1628
|
+
*
|
|
1629
|
+
* > This uses Subgraph
|
|
1630
|
+
*
|
|
1631
|
+
* **Input parameters**
|
|
1632
|
+
*
|
|
1633
|
+
* ```ts
|
|
1634
|
+
* enum ChainId {
|
|
1635
|
+
* ALL = -1,
|
|
1636
|
+
* MAINNET = 1,
|
|
1637
|
+
* SEPOLIA = 11155111,
|
|
1638
|
+
* BSC_MAINNET = 56,
|
|
1639
|
+
* BSC_TESTNET = 97,
|
|
1640
|
+
* POLYGON = 137,
|
|
1641
|
+
* POLYGON_AMOY = 80002,
|
|
1642
|
+
* LOCALHOST = 1338,
|
|
1643
|
+
* }
|
|
1644
|
+
* ```
|
|
1645
|
+
*
|
|
1646
|
+
* ```ts
|
|
1647
|
+
* type CancellationRefund = {
|
|
1648
|
+
* id: string;
|
|
1649
|
+
* escrowAddress: string;
|
|
1650
|
+
* receiver: string;
|
|
1651
|
+
* amount: bigint;
|
|
1652
|
+
* block: number;
|
|
1653
|
+
* timestamp: number;
|
|
1654
|
+
* txHash: string;
|
|
1655
|
+
* };
|
|
1656
|
+
* ```
|
|
1657
|
+
*
|
|
1658
|
+
*
|
|
1659
|
+
* @param {Object} filter Filter parameters.
|
|
1660
|
+
* @returns {Promise<CancellationRefund[]>} List of cancellation refunds matching the filters.
|
|
1661
|
+
*
|
|
1662
|
+
* **Code example**
|
|
1663
|
+
*
|
|
1664
|
+
* ```ts
|
|
1665
|
+
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1666
|
+
*
|
|
1667
|
+
* const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
|
|
1668
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
1669
|
+
* escrowAddress: '0x1234567890123456789012345678901234567890',
|
|
1670
|
+
* });
|
|
1671
|
+
* console.log(cancellationRefunds);
|
|
1672
|
+
* ```
|
|
1673
|
+
*/
|
|
1674
|
+
static async getCancellationRefunds(filter) {
|
|
1675
|
+
const networkData = constants_1.NETWORKS[filter.chainId];
|
|
1676
|
+
if (!networkData)
|
|
1677
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
1678
|
+
if (filter.escrowAddress && !ethers_1.ethers.isAddress(filter.escrowAddress)) {
|
|
1679
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
1680
|
+
}
|
|
1681
|
+
if (filter.receiver && !ethers_1.ethers.isAddress(filter.receiver)) {
|
|
1682
|
+
throw error_1.ErrorInvalidAddress;
|
|
1683
|
+
}
|
|
1684
|
+
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
1685
|
+
const skip = filter.skip || 0;
|
|
1686
|
+
const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
|
|
1687
|
+
const { cancellationRefundEvents } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_CANCELLATION_REFUNDS_QUERY)(filter), {
|
|
1688
|
+
escrowAddress: filter.escrowAddress?.toLowerCase(),
|
|
1689
|
+
receiver: filter.receiver?.toLowerCase(),
|
|
1690
|
+
from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
|
|
1691
|
+
to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
|
|
1692
|
+
first,
|
|
1693
|
+
skip,
|
|
1694
|
+
orderDirection,
|
|
1695
|
+
});
|
|
1696
|
+
return cancellationRefundEvents || [];
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* This function returns the cancellation refund for a given escrow address.
|
|
1700
|
+
*
|
|
1701
|
+
* > This uses Subgraph
|
|
1702
|
+
*
|
|
1703
|
+
* **Input parameters**
|
|
1704
|
+
*
|
|
1705
|
+
* ```ts
|
|
1706
|
+
* enum ChainId {
|
|
1707
|
+
* ALL = -1,
|
|
1708
|
+
* MAINNET = 1,
|
|
1709
|
+
* SEPOLIA = 11155111,
|
|
1710
|
+
* BSC_MAINNET = 56,
|
|
1711
|
+
* BSC_TESTNET = 97,
|
|
1712
|
+
* POLYGON = 137,
|
|
1713
|
+
* POLYGON_AMOY = 80002,
|
|
1714
|
+
* LOCALHOST = 1338,
|
|
1715
|
+
* }
|
|
1716
|
+
* ```
|
|
1717
|
+
*
|
|
1718
|
+
* ```ts
|
|
1719
|
+
* type CancellationRefund = {
|
|
1720
|
+
* id: string;
|
|
1721
|
+
* escrowAddress: string;
|
|
1722
|
+
* receiver: string;
|
|
1723
|
+
* amount: bigint;
|
|
1724
|
+
* block: number;
|
|
1725
|
+
* timestamp: number;
|
|
1726
|
+
* txHash: string;
|
|
1727
|
+
* };
|
|
1728
|
+
* ```
|
|
1729
|
+
*
|
|
1730
|
+
*
|
|
1731
|
+
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
1732
|
+
* @param {string} escrowAddress Address of the escrow
|
|
1733
|
+
* @returns {Promise<CancellationRefund>} Cancellation refund data
|
|
1734
|
+
*
|
|
1735
|
+
* **Code example**
|
|
1736
|
+
*
|
|
1737
|
+
* ```ts
|
|
1738
|
+
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1739
|
+
*
|
|
1740
|
+
* const cancellationRefund = await EscrowUtils.getCancellationRefund(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
1741
|
+
* ```
|
|
1742
|
+
*/
|
|
1743
|
+
static async getCancellationRefund(chainId, escrowAddress) {
|
|
1744
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
1745
|
+
if (!networkData)
|
|
1746
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
1747
|
+
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
1748
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
1749
|
+
}
|
|
1750
|
+
const { cancellationRefundEvents } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY)(), { escrowAddress: escrowAddress.toLowerCase() });
|
|
1751
|
+
return cancellationRefundEvents?.[0] || null;
|
|
1752
|
+
}
|
|
1650
1753
|
}
|
|
1651
1754
|
exports.EscrowUtils = EscrowUtils;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { IEscrowsFilter } from '../../interfaces';
|
|
1
|
+
import { ICancellationRefundFilter, IEscrowsFilter } from '../../interfaces';
|
|
2
2
|
export declare const GET_ESCROW_BY_ADDRESS_QUERY: () => import("graphql").DocumentNode;
|
|
3
3
|
export declare const GET_ESCROWS_QUERY: (filter: IEscrowsFilter) => import("graphql").DocumentNode;
|
|
4
4
|
export declare const GET_STATUS_UPDATES_QUERY: (from?: Date, to?: Date, launcher?: string) => import("graphql").DocumentNode;
|
|
5
|
+
export declare const GET_CANCELLATION_REFUNDS_QUERY: (filter: ICancellationRefundFilter) => import("graphql").DocumentNode;
|
|
6
|
+
export declare const GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY: () => import("graphql").DocumentNode;
|
|
5
7
|
//# sourceMappingURL=escrow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/escrow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/escrow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAsC7E,eAAO,MAAM,2BAA2B,sCAOvC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,cAAc,mCAmDvD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,OAAO,IAAI,EACX,KAAK,IAAI,EACT,WAAW,MAAM,mCAiClB,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,QAAQ,yBAAyB,mCA2BlC,CAAC;AAEF,eAAO,MAAM,wCAAwC,sCAOpD,CAAC"}
|