@human-protocol/sdk 3.0.8 → 4.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.
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -2
- package/dist/decorators.js +1 -1
- package/dist/encryption.d.ts +21 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +17 -29
- package/dist/error.d.ts +31 -28
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +36 -33
- package/dist/escrow.d.ts +102 -59
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +186 -98
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +13 -5
- package/dist/interfaces.d.ts +10 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +15 -15
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +15 -15
- package/dist/operator.d.ts +11 -10
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +23 -11
- package/dist/staking.d.ts +38 -21
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +62 -21
- package/dist/statistics.d.ts +10 -29
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +10 -29
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +13 -18
- package/dist/transaction.js +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -2
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/error.ts +39 -37
- package/src/escrow.ts +245 -117
- package/src/graphql/queries/operator.ts +13 -5
- package/src/interfaces.ts +11 -2
- package/src/kvstore.ts +16 -16
- package/src/operator.ts +26 -12
- package/src/staking.ts +71 -22
- package/src/statistics.ts +10 -29
- package/src/storage.ts +13 -18
- package/src/transaction.ts +2 -2
- package/src/types.ts +6 -2
- package/src/utils.ts +0 -1
package/src/escrow.ts
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
HMToken,
|
|
10
10
|
HMToken__factory,
|
|
11
11
|
} from '@human-protocol/core/typechain-types';
|
|
12
|
-
import { ContractRunner, EventLog, Overrides, ethers } from 'ethers';
|
|
12
|
+
import { ContractRunner, EventLog, Overrides, Signer, ethers } from 'ethers';
|
|
13
13
|
import gqlFetch from 'graphql-request';
|
|
14
14
|
import { BaseEthersClient } from './base';
|
|
15
|
-
import {
|
|
15
|
+
import { ESCROW_BULK_PAYOUT_MAX_ITEMS, NETWORKS } from './constants';
|
|
16
16
|
import { requiresSigner } from './decorators';
|
|
17
17
|
import { ChainId, OrderDirection } from './enums';
|
|
18
18
|
import {
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
ErrorProviderDoesNotExist,
|
|
34
34
|
ErrorRecipientAndAmountsMustBeSameLength,
|
|
35
35
|
ErrorRecipientCannotBeEmptyArray,
|
|
36
|
+
ErrorTooManyRecipients,
|
|
36
37
|
ErrorTotalFeeMustBeLessThanHundred,
|
|
37
38
|
ErrorTransferEventNotFoundInTransactionLogs,
|
|
38
39
|
ErrorUnsupportedChainID,
|
|
@@ -52,25 +53,26 @@ import {
|
|
|
52
53
|
EscrowStatus,
|
|
53
54
|
EscrowWithdraw,
|
|
54
55
|
NetworkData,
|
|
56
|
+
TransactionLikeWithNonce,
|
|
55
57
|
} from './types';
|
|
56
58
|
import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
61
|
* ## Introduction
|
|
60
62
|
*
|
|
61
|
-
* This client enables
|
|
63
|
+
* This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
|
|
62
64
|
*
|
|
63
65
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
64
66
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
65
67
|
*
|
|
66
68
|
* ```ts
|
|
67
|
-
* static async build(runner: ContractRunner)
|
|
69
|
+
* static async build(runner: ContractRunner): Promise<EscrowClient>;
|
|
68
70
|
* ```
|
|
69
71
|
*
|
|
70
72
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
71
73
|
*
|
|
72
|
-
* - **Signer**: when the user wants to use this model
|
|
73
|
-
* - **Provider**: when the user wants to use this model
|
|
74
|
+
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
75
|
+
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
74
76
|
*
|
|
75
77
|
* ## Installation
|
|
76
78
|
*
|
|
@@ -88,21 +90,21 @@ import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
|
88
90
|
*
|
|
89
91
|
* ### Signer
|
|
90
92
|
*
|
|
91
|
-
* **Using private key(backend)**
|
|
93
|
+
* **Using private key (backend)**
|
|
92
94
|
*
|
|
93
95
|
* ```ts
|
|
94
96
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
95
97
|
* import { Wallet, providers } from 'ethers';
|
|
96
98
|
*
|
|
97
99
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
98
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
100
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
99
101
|
*
|
|
100
102
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
101
103
|
* const signer = new Wallet(privateKey, provider);
|
|
102
104
|
* const escrowClient = await EscrowClient.build(signer);
|
|
103
105
|
* ```
|
|
104
106
|
*
|
|
105
|
-
* **Using Wagmi(frontend)**
|
|
107
|
+
* **Using Wagmi (frontend)**
|
|
106
108
|
*
|
|
107
109
|
* ```ts
|
|
108
110
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -151,7 +153,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
151
153
|
* @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
|
|
152
154
|
* @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
|
|
153
155
|
*/
|
|
154
|
-
public static async build(runner: ContractRunner) {
|
|
156
|
+
public static async build(runner: ContractRunner): Promise<EscrowClient> {
|
|
155
157
|
if (!runner.provider) {
|
|
156
158
|
throw ErrorProviderDoesNotExist;
|
|
157
159
|
}
|
|
@@ -184,11 +186,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
184
186
|
/**
|
|
185
187
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
186
188
|
*
|
|
187
|
-
* @param {string} tokenAddress Token address to use for
|
|
189
|
+
* @param {string} tokenAddress Token address to use for payouts.
|
|
188
190
|
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
189
191
|
* @param {string} jobRequesterId Job Requester Id
|
|
190
192
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
191
|
-
* @returns {Promise<string>}
|
|
193
|
+
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
192
194
|
*
|
|
193
195
|
*
|
|
194
196
|
* **Code example**
|
|
@@ -200,7 +202,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
200
202
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
201
203
|
*
|
|
202
204
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
203
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
205
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
204
206
|
*
|
|
205
207
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
206
208
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -273,7 +275,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
273
275
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
274
276
|
*
|
|
275
277
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
276
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
278
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
277
279
|
*
|
|
278
280
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
279
281
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -284,10 +286,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
284
286
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
285
287
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
286
288
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
287
|
-
* recordingOracleFee:
|
|
288
|
-
* reputationOracleFee:
|
|
289
|
-
* exchangeOracleFee:
|
|
290
|
-
* manifestUrl: '
|
|
289
|
+
* recordingOracleFee: BigInt('10'),
|
|
290
|
+
* reputationOracleFee: BigInt('10'),
|
|
291
|
+
* exchangeOracleFee: BigInt('10'),
|
|
292
|
+
* manifestUrl: 'http://localhost/manifest.json',
|
|
291
293
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
292
294
|
* };
|
|
293
295
|
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
@@ -393,7 +395,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
393
395
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
394
396
|
*
|
|
395
397
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
396
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
398
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
397
399
|
*
|
|
398
400
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
399
401
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -441,10 +443,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
441
443
|
}
|
|
442
444
|
|
|
443
445
|
/**
|
|
444
|
-
* This function stores the results
|
|
446
|
+
* This function stores the results URL and hash.
|
|
445
447
|
*
|
|
446
448
|
* @param {string} escrowAddress Address of the escrow.
|
|
447
|
-
* @param {string} url Results file
|
|
449
|
+
* @param {string} url Results file URL.
|
|
448
450
|
* @param {string} hash Results file hash.
|
|
449
451
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
450
452
|
* @returns Returns void if successful. Throws error if any.
|
|
@@ -459,13 +461,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
459
461
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
460
462
|
*
|
|
461
463
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
462
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
464
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
463
465
|
*
|
|
464
466
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
465
467
|
* const signer = new Wallet(privateKey, provider);
|
|
466
468
|
* const escrowClient = await EscrowClient.build(signer);
|
|
467
469
|
*
|
|
468
|
-
* await
|
|
470
|
+
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
469
471
|
* ```
|
|
470
472
|
*/
|
|
471
473
|
@requiresSigner
|
|
@@ -523,7 +525,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
523
525
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
524
526
|
*
|
|
525
527
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
526
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
528
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
527
529
|
*
|
|
528
530
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
529
531
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -561,9 +563,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
561
563
|
* @param {string} escrowAddress Escrow address to payout.
|
|
562
564
|
* @param {string[]} recipients Array of recipient addresses.
|
|
563
565
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
564
|
-
* @param {string} finalResultsUrl Final results file
|
|
566
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
565
567
|
* @param {string} finalResultsHash Final results file hash.
|
|
566
|
-
* @param {
|
|
568
|
+
* @param {number} txId Transaction ID.
|
|
569
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
567
570
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
568
571
|
* @returns Returns void if successful. Throws error if any.
|
|
569
572
|
*
|
|
@@ -577,7 +580,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
577
580
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
578
581
|
*
|
|
579
582
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
580
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
583
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
581
584
|
*
|
|
582
585
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
583
586
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -586,9 +589,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
586
589
|
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
587
590
|
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
588
591
|
* const resultsUrl = 'http://localhost/results.json';
|
|
589
|
-
* const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
592
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
593
|
+
* const txId = 1;
|
|
590
594
|
*
|
|
591
|
-
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash);
|
|
595
|
+
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
592
596
|
* ```
|
|
593
597
|
*/
|
|
594
598
|
@requiresSigner
|
|
@@ -598,57 +602,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
598
602
|
amounts: bigint[],
|
|
599
603
|
finalResultsUrl: string,
|
|
600
604
|
finalResultsHash: string,
|
|
605
|
+
txId: number,
|
|
601
606
|
forceComplete = false,
|
|
602
607
|
txOptions: Overrides = {}
|
|
603
608
|
): Promise<void> {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
if (amounts.length === 0) {
|
|
613
|
-
throw ErrorAmountsCannotBeEmptyArray;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
if (recipients.length !== amounts.length) {
|
|
617
|
-
throw ErrorRecipientAndAmountsMustBeSameLength;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
recipients.forEach((recipient) => {
|
|
621
|
-
if (!ethers.isAddress(recipient)) {
|
|
622
|
-
throw new InvalidEthereumAddressError(recipient);
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
if (!finalResultsUrl) {
|
|
627
|
-
throw ErrorUrlIsEmptyString;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (!isValidUrl(finalResultsUrl)) {
|
|
631
|
-
throw ErrorInvalidUrl;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (!finalResultsHash) {
|
|
635
|
-
throw ErrorHashIsEmptyString;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const balance = await this.getBalance(escrowAddress);
|
|
639
|
-
|
|
640
|
-
let totalAmount = 0n;
|
|
641
|
-
amounts.forEach((amount) => {
|
|
642
|
-
totalAmount = totalAmount + amount;
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
if (balance < totalAmount) {
|
|
646
|
-
throw ErrorEscrowDoesNotHaveEnoughBalance;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
650
|
-
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
651
|
-
}
|
|
609
|
+
await this.ensureCorrectBulkPayoutInput(
|
|
610
|
+
escrowAddress,
|
|
611
|
+
recipients,
|
|
612
|
+
amounts,
|
|
613
|
+
finalResultsUrl,
|
|
614
|
+
finalResultsHash
|
|
615
|
+
);
|
|
652
616
|
|
|
653
617
|
try {
|
|
654
618
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
@@ -661,7 +625,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
661
625
|
amounts,
|
|
662
626
|
finalResultsUrl,
|
|
663
627
|
finalResultsHash,
|
|
664
|
-
|
|
628
|
+
txId,
|
|
665
629
|
forceComplete,
|
|
666
630
|
txOptions
|
|
667
631
|
)
|
|
@@ -675,7 +639,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
675
639
|
amounts,
|
|
676
640
|
finalResultsUrl,
|
|
677
641
|
finalResultsHash,
|
|
678
|
-
|
|
642
|
+
txId,
|
|
679
643
|
txOptions
|
|
680
644
|
)
|
|
681
645
|
).wait();
|
|
@@ -703,7 +667,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
703
667
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
704
668
|
*
|
|
705
669
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
706
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
670
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
707
671
|
*
|
|
708
672
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
709
673
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -788,13 +752,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
788
752
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
789
753
|
*
|
|
790
754
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
791
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
755
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
792
756
|
*
|
|
793
757
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
794
758
|
* const signer = new Wallet(privateKey, provider);
|
|
795
759
|
* const escrowClient = await EscrowClient.build(signer);
|
|
796
760
|
*
|
|
797
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']
|
|
761
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
798
762
|
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
799
763
|
* ```
|
|
800
764
|
*/
|
|
@@ -852,7 +816,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
852
816
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
853
817
|
*
|
|
854
818
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
855
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
819
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
856
820
|
*
|
|
857
821
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
858
822
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -927,11 +891,177 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
927
891
|
}
|
|
928
892
|
}
|
|
929
893
|
|
|
894
|
+
/**
|
|
895
|
+
* Creates a prepared transaction for bulk payout without immediately sending it.
|
|
896
|
+
* @param {string} escrowAddress Escrow address to payout.
|
|
897
|
+
* @param {string[]} recipients Array of recipient addresses.
|
|
898
|
+
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
899
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
900
|
+
* @param {string} finalResultsHash Final results file hash.
|
|
901
|
+
* @param {number} txId Transaction ID.
|
|
902
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
903
|
+
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
904
|
+
* @returns Returns object with raw transaction and signed transaction hash
|
|
905
|
+
*
|
|
906
|
+
* **Code example**
|
|
907
|
+
*
|
|
908
|
+
* > Only Reputation Oracle or a trusted handler can call it.
|
|
909
|
+
*
|
|
910
|
+
* ```ts
|
|
911
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
912
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
913
|
+
*
|
|
914
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
915
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
916
|
+
*
|
|
917
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
918
|
+
* const signer = new Wallet(privateKey, provider);
|
|
919
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
920
|
+
*
|
|
921
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
922
|
+
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
923
|
+
* const resultsUrl = 'http://localhost/results.json';
|
|
924
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
925
|
+
* const txId = 1;
|
|
926
|
+
*
|
|
927
|
+
* const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
928
|
+
* console.log('Raw transaction:', rawTransaction);
|
|
929
|
+
*
|
|
930
|
+
* const signedTransaction = await signer.signTransaction(rawTransaction);
|
|
931
|
+
* console.log('Tx hash:', ethers.keccak256(signedTransaction));
|
|
932
|
+
* (await signer.sendTransaction(rawTransaction)).wait();
|
|
933
|
+
*/
|
|
934
|
+
@requiresSigner
|
|
935
|
+
async createBulkPayoutTransaction(
|
|
936
|
+
escrowAddress: string,
|
|
937
|
+
recipients: string[],
|
|
938
|
+
amounts: bigint[],
|
|
939
|
+
finalResultsUrl: string,
|
|
940
|
+
finalResultsHash: string,
|
|
941
|
+
txId: number,
|
|
942
|
+
forceComplete = false,
|
|
943
|
+
txOptions: Overrides = {}
|
|
944
|
+
): Promise<TransactionLikeWithNonce> {
|
|
945
|
+
await this.ensureCorrectBulkPayoutInput(
|
|
946
|
+
escrowAddress,
|
|
947
|
+
recipients,
|
|
948
|
+
amounts,
|
|
949
|
+
finalResultsUrl,
|
|
950
|
+
finalResultsHash
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
const signer = this.runner as Signer;
|
|
954
|
+
try {
|
|
955
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
956
|
+
|
|
957
|
+
const populatedTransaction = await escrowContract[
|
|
958
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
959
|
+
].populateTransaction(
|
|
960
|
+
recipients,
|
|
961
|
+
amounts,
|
|
962
|
+
finalResultsUrl,
|
|
963
|
+
finalResultsHash,
|
|
964
|
+
txId,
|
|
965
|
+
forceComplete,
|
|
966
|
+
txOptions
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Safety-belt: explicitly set the passed nonce
|
|
971
|
+
* because 'populateTransaction' return value
|
|
972
|
+
* doesn't mention it even in library docs,
|
|
973
|
+
* even though it includes if from txOptions.
|
|
974
|
+
*/
|
|
975
|
+
if (typeof txOptions.nonce === 'number') {
|
|
976
|
+
populatedTransaction.nonce = txOptions.nonce;
|
|
977
|
+
} else {
|
|
978
|
+
populatedTransaction.nonce = await signer.getNonce();
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* It's needed to get all necessary info for tx object
|
|
982
|
+
* before signing it, e.g.:
|
|
983
|
+
* - type
|
|
984
|
+
* - chainId
|
|
985
|
+
* - fees params
|
|
986
|
+
* - etc.
|
|
987
|
+
*
|
|
988
|
+
* All information is needed in order to get proper hash value
|
|
989
|
+
*/
|
|
990
|
+
const preparedTransaction =
|
|
991
|
+
await signer.populateTransaction(populatedTransaction);
|
|
992
|
+
|
|
993
|
+
return preparedTransaction as TransactionLikeWithNonce;
|
|
994
|
+
} catch (e) {
|
|
995
|
+
return throwError(e);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
private async ensureCorrectBulkPayoutInput(
|
|
1000
|
+
escrowAddress: string,
|
|
1001
|
+
recipients: string[],
|
|
1002
|
+
amounts: bigint[],
|
|
1003
|
+
finalResultsUrl: string,
|
|
1004
|
+
finalResultsHash: string
|
|
1005
|
+
): Promise<void> {
|
|
1006
|
+
if (!ethers.isAddress(escrowAddress)) {
|
|
1007
|
+
throw ErrorInvalidEscrowAddressProvided;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
if (recipients.length === 0) {
|
|
1011
|
+
throw ErrorRecipientCannotBeEmptyArray;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
if (recipients.length > ESCROW_BULK_PAYOUT_MAX_ITEMS) {
|
|
1015
|
+
throw ErrorTooManyRecipients;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
if (amounts.length === 0) {
|
|
1019
|
+
throw ErrorAmountsCannotBeEmptyArray;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (recipients.length !== amounts.length) {
|
|
1023
|
+
throw ErrorRecipientAndAmountsMustBeSameLength;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
recipients.forEach((recipient) => {
|
|
1027
|
+
if (!ethers.isAddress(recipient)) {
|
|
1028
|
+
throw new InvalidEthereumAddressError(recipient);
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
if (!finalResultsUrl) {
|
|
1033
|
+
throw ErrorUrlIsEmptyString;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
if (!isValidUrl(finalResultsUrl)) {
|
|
1037
|
+
throw ErrorInvalidUrl;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
if (!finalResultsHash) {
|
|
1041
|
+
throw ErrorHashIsEmptyString;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
const balance = await this.getBalance(escrowAddress);
|
|
1045
|
+
|
|
1046
|
+
let totalAmount = 0n;
|
|
1047
|
+
amounts.forEach((amount) => {
|
|
1048
|
+
totalAmount = totalAmount + amount;
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
if (balance < totalAmount) {
|
|
1052
|
+
throw ErrorEscrowDoesNotHaveEnoughBalance;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
1056
|
+
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
930
1060
|
/**
|
|
931
1061
|
* This function returns the balance for a specified escrow address.
|
|
932
1062
|
*
|
|
933
1063
|
* @param {string} escrowAddress Address of the escrow.
|
|
934
|
-
* @returns {bigint} Balance of the escrow in the token used to fund it.
|
|
1064
|
+
* @returns {Promise<bigint>} Balance of the escrow in the token used to fund it.
|
|
935
1065
|
*
|
|
936
1066
|
* **Code example**
|
|
937
1067
|
*
|
|
@@ -942,7 +1072,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
942
1072
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
943
1073
|
*
|
|
944
1074
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
945
|
-
* const escrowClient = await EscrowClient.build(
|
|
1075
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
946
1076
|
*
|
|
947
1077
|
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
948
1078
|
* ```
|
|
@@ -975,7 +1105,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
975
1105
|
* This function returns the manifest file hash.
|
|
976
1106
|
*
|
|
977
1107
|
* @param {string} escrowAddress Address of the escrow.
|
|
978
|
-
* @returns {string} Hash of the manifest file content.
|
|
1108
|
+
* @returns {Promise<string>} Hash of the manifest file content.
|
|
979
1109
|
*
|
|
980
1110
|
* **Code example**
|
|
981
1111
|
*
|
|
@@ -986,7 +1116,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
986
1116
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
987
1117
|
*
|
|
988
1118
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
989
|
-
* const escrowClient = await EscrowClient.build(
|
|
1119
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
990
1120
|
*
|
|
991
1121
|
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
992
1122
|
* ```
|
|
@@ -1013,7 +1143,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1013
1143
|
* This function returns the manifest file URL.
|
|
1014
1144
|
*
|
|
1015
1145
|
* @param {string} escrowAddress Address of the escrow.
|
|
1016
|
-
* @returns {string} Url of the manifest.
|
|
1146
|
+
* @returns {Promise<string>} Url of the manifest.
|
|
1017
1147
|
*
|
|
1018
1148
|
* **Code example**
|
|
1019
1149
|
*
|
|
@@ -1024,7 +1154,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1024
1154
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1025
1155
|
*
|
|
1026
1156
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1027
|
-
* const escrowClient = await EscrowClient.build(
|
|
1157
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1028
1158
|
*
|
|
1029
1159
|
* const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1030
1160
|
* ```
|
|
@@ -1051,7 +1181,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1051
1181
|
* This function returns the results file URL.
|
|
1052
1182
|
*
|
|
1053
1183
|
* @param {string} escrowAddress Address of the escrow.
|
|
1054
|
-
* @returns {string} Results file url.
|
|
1184
|
+
* @returns {Promise<string>} Results file url.
|
|
1055
1185
|
*
|
|
1056
1186
|
* **Code example**
|
|
1057
1187
|
*
|
|
@@ -1062,7 +1192,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1062
1192
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1063
1193
|
*
|
|
1064
1194
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1065
|
-
* const escrowClient = await EscrowClient.build(
|
|
1195
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1066
1196
|
*
|
|
1067
1197
|
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1068
1198
|
* ```
|
|
@@ -1089,7 +1219,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1089
1219
|
* This function returns the intermediate results file URL.
|
|
1090
1220
|
*
|
|
1091
1221
|
* @param {string} escrowAddress Address of the escrow.
|
|
1092
|
-
* @returns {string} Url of the file that store results from Recording Oracle.
|
|
1222
|
+
* @returns {Promise<string>} Url of the file that store results from Recording Oracle.
|
|
1093
1223
|
*
|
|
1094
1224
|
* **Code example**
|
|
1095
1225
|
*
|
|
@@ -1100,9 +1230,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1100
1230
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1101
1231
|
*
|
|
1102
1232
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1103
|
-
* const escrowClient = await EscrowClient.build(
|
|
1233
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1104
1234
|
*
|
|
1105
|
-
* const
|
|
1235
|
+
* const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1106
1236
|
* ```
|
|
1107
1237
|
*/
|
|
1108
1238
|
async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
|
|
@@ -1118,7 +1248,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1118
1248
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1119
1249
|
|
|
1120
1250
|
return escrowContract.intermediateResultsUrl();
|
|
1121
|
-
} catch (e
|
|
1251
|
+
} catch (e) {
|
|
1122
1252
|
return throwError(e);
|
|
1123
1253
|
}
|
|
1124
1254
|
}
|
|
@@ -1127,7 +1257,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1127
1257
|
* This function returns the token address used for funding the escrow.
|
|
1128
1258
|
*
|
|
1129
1259
|
* @param {string} escrowAddress Address of the escrow.
|
|
1130
|
-
* @returns {string} Address of the token used to fund the escrow.
|
|
1260
|
+
* @returns {Promise<string>} Address of the token used to fund the escrow.
|
|
1131
1261
|
*
|
|
1132
1262
|
* **Code example**
|
|
1133
1263
|
*
|
|
@@ -1138,7 +1268,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1138
1268
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1139
1269
|
*
|
|
1140
1270
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1141
|
-
* const escrowClient = await EscrowClient.build(
|
|
1271
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1142
1272
|
*
|
|
1143
1273
|
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1144
1274
|
* ```
|
|
@@ -1165,7 +1295,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1165
1295
|
* This function returns the current status of the escrow.
|
|
1166
1296
|
*
|
|
1167
1297
|
* @param {string} escrowAddress Address of the escrow.
|
|
1168
|
-
* @returns {EscrowStatus} Current status of the escrow.
|
|
1298
|
+
* @returns {Promise<EscrowStatus>} Current status of the escrow.
|
|
1169
1299
|
*
|
|
1170
1300
|
* **Code example**
|
|
1171
1301
|
*
|
|
@@ -1176,7 +1306,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1176
1306
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1177
1307
|
*
|
|
1178
1308
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1179
|
-
* const escrowClient = await EscrowClient.build(
|
|
1309
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1180
1310
|
*
|
|
1181
1311
|
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1182
1312
|
* ```
|
|
@@ -1203,7 +1333,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1203
1333
|
* This function returns the recording oracle address for a given escrow.
|
|
1204
1334
|
*
|
|
1205
1335
|
* @param {string} escrowAddress Address of the escrow.
|
|
1206
|
-
* @returns {string} Address of the Recording Oracle.
|
|
1336
|
+
* @returns {Promise<string>} Address of the Recording Oracle.
|
|
1207
1337
|
*
|
|
1208
1338
|
* **Code example**
|
|
1209
1339
|
*
|
|
@@ -1214,7 +1344,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1214
1344
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1215
1345
|
*
|
|
1216
1346
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1217
|
-
* const escrowClient = await EscrowClient.build(
|
|
1347
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1218
1348
|
*
|
|
1219
1349
|
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1220
1350
|
* ```
|
|
@@ -1232,7 +1362,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1232
1362
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1233
1363
|
|
|
1234
1364
|
return escrowContract.recordingOracle();
|
|
1235
|
-
} catch (e
|
|
1365
|
+
} catch (e) {
|
|
1236
1366
|
return throwError(e);
|
|
1237
1367
|
}
|
|
1238
1368
|
}
|
|
@@ -1241,7 +1371,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1241
1371
|
* This function returns the job launcher address for a given escrow.
|
|
1242
1372
|
*
|
|
1243
1373
|
* @param {string} escrowAddress Address of the escrow.
|
|
1244
|
-
* @returns {string} Address of the Job Launcher.
|
|
1374
|
+
* @returns {Promise<string>} Address of the Job Launcher.
|
|
1245
1375
|
*
|
|
1246
1376
|
* **Code example**
|
|
1247
1377
|
*
|
|
@@ -1252,7 +1382,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1252
1382
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1253
1383
|
*
|
|
1254
1384
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1255
|
-
* const escrowClient = await EscrowClient.build(
|
|
1385
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1256
1386
|
*
|
|
1257
1387
|
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1258
1388
|
* ```
|
|
@@ -1270,7 +1400,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1270
1400
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1271
1401
|
|
|
1272
1402
|
return escrowContract.launcher();
|
|
1273
|
-
} catch (e
|
|
1403
|
+
} catch (e) {
|
|
1274
1404
|
return throwError(e);
|
|
1275
1405
|
}
|
|
1276
1406
|
}
|
|
@@ -1279,7 +1409,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1279
1409
|
* This function returns the reputation oracle address for a given escrow.
|
|
1280
1410
|
*
|
|
1281
1411
|
* @param {string} escrowAddress Address of the escrow.
|
|
1282
|
-
* @returns {
|
|
1412
|
+
* @returns {Promise<string>} Address of the Reputation Oracle.
|
|
1283
1413
|
*
|
|
1284
1414
|
* **Code example**
|
|
1285
1415
|
*
|
|
@@ -1290,7 +1420,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1290
1420
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1291
1421
|
*
|
|
1292
1422
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1293
|
-
* const escrowClient = await EscrowClient.build(
|
|
1423
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1294
1424
|
*
|
|
1295
1425
|
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1296
1426
|
* ```
|
|
@@ -1308,7 +1438,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1308
1438
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1309
1439
|
|
|
1310
1440
|
return escrowContract.reputationOracle();
|
|
1311
|
-
} catch (e
|
|
1441
|
+
} catch (e) {
|
|
1312
1442
|
return throwError(e);
|
|
1313
1443
|
}
|
|
1314
1444
|
}
|
|
@@ -1317,7 +1447,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1317
1447
|
* This function returns the exchange oracle address for a given escrow.
|
|
1318
1448
|
*
|
|
1319
1449
|
* @param {string} escrowAddress Address of the escrow.
|
|
1320
|
-
* @returns {
|
|
1450
|
+
* @returns {Promise<string>} Address of the Exchange Oracle.
|
|
1321
1451
|
*
|
|
1322
1452
|
* **Code example**
|
|
1323
1453
|
*
|
|
@@ -1328,7 +1458,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1328
1458
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1329
1459
|
*
|
|
1330
1460
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1331
|
-
* const escrowClient = await EscrowClient.build(
|
|
1461
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1332
1462
|
*
|
|
1333
1463
|
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1334
1464
|
* ```
|
|
@@ -1346,7 +1476,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1346
1476
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1347
1477
|
|
|
1348
1478
|
return escrowContract.exchangeOracle();
|
|
1349
|
-
} catch (e
|
|
1479
|
+
} catch (e) {
|
|
1350
1480
|
return throwError(e);
|
|
1351
1481
|
}
|
|
1352
1482
|
}
|
|
@@ -1355,7 +1485,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1355
1485
|
* This function returns the escrow factory address for a given escrow.
|
|
1356
1486
|
*
|
|
1357
1487
|
* @param {string} escrowAddress Address of the escrow.
|
|
1358
|
-
* @returns {
|
|
1488
|
+
* @returns {Promise<string>} Address of the escrow factory.
|
|
1359
1489
|
*
|
|
1360
1490
|
* **Code example**
|
|
1361
1491
|
*
|
|
@@ -1366,7 +1496,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1366
1496
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1367
1497
|
*
|
|
1368
1498
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1369
|
-
* const escrowClient = await EscrowClient.build(
|
|
1499
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1370
1500
|
*
|
|
1371
1501
|
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1372
1502
|
* ```
|
|
@@ -1384,12 +1514,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1384
1514
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1385
1515
|
|
|
1386
1516
|
return escrowContract.escrowFactory();
|
|
1387
|
-
} catch (e
|
|
1517
|
+
} catch (e) {
|
|
1388
1518
|
return throwError(e);
|
|
1389
1519
|
}
|
|
1390
1520
|
}
|
|
1391
1521
|
}
|
|
1392
|
-
|
|
1393
1522
|
/**
|
|
1394
1523
|
* ## Introduction
|
|
1395
1524
|
*
|
|
@@ -1417,7 +1546,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1417
1546
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1418
1547
|
*
|
|
1419
1548
|
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1420
|
-
*
|
|
1549
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
1421
1550
|
* });
|
|
1422
1551
|
* ```
|
|
1423
1552
|
*/
|
|
@@ -1462,7 +1591,6 @@ export class EscrowUtils {
|
|
|
1462
1591
|
* AVALANCHE_TESTNET = 43113,
|
|
1463
1592
|
* CELO = 42220,
|
|
1464
1593
|
* CELO_ALFAJORES = 44787,
|
|
1465
|
-
* = 1273227453,
|
|
1466
1594
|
* LOCALHOST = 1338,
|
|
1467
1595
|
* }
|
|
1468
1596
|
* ```
|