@human-protocol/sdk 3.0.8 → 4.0.1
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 +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +11 -151
- 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/enums.d.ts +5 -12
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +6 -12
- 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 +104 -88
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +192 -131
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +15 -5
- package/dist/interfaces.d.ts +12 -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 +18 -37
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +13 -18
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +3 -5
- 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 +7 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -2
- package/package.json +1 -1
- package/src/constants.ts +11 -174
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/enums.ts +5 -11
- package/src/error.ts +39 -37
- package/src/escrow.ts +257 -151
- package/src/graphql/queries/operator.ts +15 -5
- package/src/interfaces.ts +13 -2
- package/src/kvstore.ts +16 -16
- package/src/operator.ts +26 -12
- package/src/staking.ts +71 -22
- package/src/statistics.ts +19 -38
- package/src/storage.ts +13 -18
- package/src/transaction.ts +5 -7
- package/src/types.ts +6 -2
- package/src/utils.ts +10 -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,31 @@ import {
|
|
|
52
53
|
EscrowStatus,
|
|
53
54
|
EscrowWithdraw,
|
|
54
55
|
NetworkData,
|
|
56
|
+
TransactionLikeWithNonce,
|
|
55
57
|
} from './types';
|
|
56
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
getSubgraphUrl,
|
|
60
|
+
getUnixTimestamp,
|
|
61
|
+
isValidUrl,
|
|
62
|
+
throwError,
|
|
63
|
+
} from './utils';
|
|
57
64
|
|
|
58
65
|
/**
|
|
59
66
|
* ## Introduction
|
|
60
67
|
*
|
|
61
|
-
* This client enables
|
|
68
|
+
* This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
|
|
62
69
|
*
|
|
63
70
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
64
71
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
65
72
|
*
|
|
66
73
|
* ```ts
|
|
67
|
-
* static async build(runner: ContractRunner)
|
|
74
|
+
* static async build(runner: ContractRunner): Promise<EscrowClient>;
|
|
68
75
|
* ```
|
|
69
76
|
*
|
|
70
77
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
71
78
|
*
|
|
72
|
-
* - **Signer**: when the user wants to use this model
|
|
73
|
-
* - **Provider**: when the user wants to use this model
|
|
79
|
+
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
80
|
+
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
74
81
|
*
|
|
75
82
|
* ## Installation
|
|
76
83
|
*
|
|
@@ -88,21 +95,21 @@ import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
|
88
95
|
*
|
|
89
96
|
* ### Signer
|
|
90
97
|
*
|
|
91
|
-
* **Using private key(backend)**
|
|
98
|
+
* **Using private key (backend)**
|
|
92
99
|
*
|
|
93
100
|
* ```ts
|
|
94
101
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
95
102
|
* import { Wallet, providers } from 'ethers';
|
|
96
103
|
*
|
|
97
104
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
98
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
105
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
99
106
|
*
|
|
100
107
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
101
108
|
* const signer = new Wallet(privateKey, provider);
|
|
102
109
|
* const escrowClient = await EscrowClient.build(signer);
|
|
103
110
|
* ```
|
|
104
111
|
*
|
|
105
|
-
* **Using Wagmi(frontend)**
|
|
112
|
+
* **Using Wagmi (frontend)**
|
|
106
113
|
*
|
|
107
114
|
* ```ts
|
|
108
115
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -151,7 +158,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
151
158
|
* @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
|
|
152
159
|
* @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
|
|
153
160
|
*/
|
|
154
|
-
public static async build(runner: ContractRunner) {
|
|
161
|
+
public static async build(runner: ContractRunner): Promise<EscrowClient> {
|
|
155
162
|
if (!runner.provider) {
|
|
156
163
|
throw ErrorProviderDoesNotExist;
|
|
157
164
|
}
|
|
@@ -184,11 +191,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
184
191
|
/**
|
|
185
192
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
186
193
|
*
|
|
187
|
-
* @param {string} tokenAddress Token address to use for
|
|
194
|
+
* @param {string} tokenAddress Token address to use for payouts.
|
|
188
195
|
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
189
196
|
* @param {string} jobRequesterId Job Requester Id
|
|
190
197
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
191
|
-
* @returns {Promise<string>}
|
|
198
|
+
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
192
199
|
*
|
|
193
200
|
*
|
|
194
201
|
* **Code example**
|
|
@@ -200,7 +207,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
200
207
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
201
208
|
*
|
|
202
209
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
203
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
210
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
204
211
|
*
|
|
205
212
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
206
213
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -273,7 +280,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
273
280
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
274
281
|
*
|
|
275
282
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
276
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
283
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
277
284
|
*
|
|
278
285
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
279
286
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -284,10 +291,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
284
291
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
285
292
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
286
293
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
287
|
-
* recordingOracleFee:
|
|
288
|
-
* reputationOracleFee:
|
|
289
|
-
* exchangeOracleFee:
|
|
290
|
-
* manifestUrl: '
|
|
294
|
+
* recordingOracleFee: BigInt('10'),
|
|
295
|
+
* reputationOracleFee: BigInt('10'),
|
|
296
|
+
* exchangeOracleFee: BigInt('10'),
|
|
297
|
+
* manifestUrl: 'http://localhost/manifest.json',
|
|
291
298
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
292
299
|
* };
|
|
293
300
|
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
@@ -393,7 +400,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
393
400
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
394
401
|
*
|
|
395
402
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
396
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
403
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
397
404
|
*
|
|
398
405
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
399
406
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -441,10 +448,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
441
448
|
}
|
|
442
449
|
|
|
443
450
|
/**
|
|
444
|
-
* This function stores the results
|
|
451
|
+
* This function stores the results URL and hash.
|
|
445
452
|
*
|
|
446
453
|
* @param {string} escrowAddress Address of the escrow.
|
|
447
|
-
* @param {string} url Results file
|
|
454
|
+
* @param {string} url Results file URL.
|
|
448
455
|
* @param {string} hash Results file hash.
|
|
449
456
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
450
457
|
* @returns Returns void if successful. Throws error if any.
|
|
@@ -459,13 +466,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
459
466
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
460
467
|
*
|
|
461
468
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
462
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
469
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
463
470
|
*
|
|
464
471
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
465
472
|
* const signer = new Wallet(privateKey, provider);
|
|
466
473
|
* const escrowClient = await EscrowClient.build(signer);
|
|
467
474
|
*
|
|
468
|
-
* await
|
|
475
|
+
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
469
476
|
* ```
|
|
470
477
|
*/
|
|
471
478
|
@requiresSigner
|
|
@@ -523,7 +530,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
523
530
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
524
531
|
*
|
|
525
532
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
526
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
533
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
527
534
|
*
|
|
528
535
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
529
536
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -561,9 +568,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
561
568
|
* @param {string} escrowAddress Escrow address to payout.
|
|
562
569
|
* @param {string[]} recipients Array of recipient addresses.
|
|
563
570
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
564
|
-
* @param {string} finalResultsUrl Final results file
|
|
571
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
565
572
|
* @param {string} finalResultsHash Final results file hash.
|
|
566
|
-
* @param {
|
|
573
|
+
* @param {number} txId Transaction ID.
|
|
574
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
567
575
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
568
576
|
* @returns Returns void if successful. Throws error if any.
|
|
569
577
|
*
|
|
@@ -577,7 +585,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
577
585
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
578
586
|
*
|
|
579
587
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
580
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
588
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
581
589
|
*
|
|
582
590
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
583
591
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -586,9 +594,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
586
594
|
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
587
595
|
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
588
596
|
* const resultsUrl = 'http://localhost/results.json';
|
|
589
|
-
* const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
597
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
598
|
+
* const txId = 1;
|
|
590
599
|
*
|
|
591
|
-
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash);
|
|
600
|
+
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
592
601
|
* ```
|
|
593
602
|
*/
|
|
594
603
|
@requiresSigner
|
|
@@ -598,57 +607,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
598
607
|
amounts: bigint[],
|
|
599
608
|
finalResultsUrl: string,
|
|
600
609
|
finalResultsHash: string,
|
|
610
|
+
txId: number,
|
|
601
611
|
forceComplete = false,
|
|
602
612
|
txOptions: Overrides = {}
|
|
603
613
|
): 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
|
-
}
|
|
614
|
+
await this.ensureCorrectBulkPayoutInput(
|
|
615
|
+
escrowAddress,
|
|
616
|
+
recipients,
|
|
617
|
+
amounts,
|
|
618
|
+
finalResultsUrl,
|
|
619
|
+
finalResultsHash
|
|
620
|
+
);
|
|
652
621
|
|
|
653
622
|
try {
|
|
654
623
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
@@ -661,7 +630,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
661
630
|
amounts,
|
|
662
631
|
finalResultsUrl,
|
|
663
632
|
finalResultsHash,
|
|
664
|
-
|
|
633
|
+
txId,
|
|
665
634
|
forceComplete,
|
|
666
635
|
txOptions
|
|
667
636
|
)
|
|
@@ -675,7 +644,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
675
644
|
amounts,
|
|
676
645
|
finalResultsUrl,
|
|
677
646
|
finalResultsHash,
|
|
678
|
-
|
|
647
|
+
txId,
|
|
679
648
|
txOptions
|
|
680
649
|
)
|
|
681
650
|
).wait();
|
|
@@ -703,7 +672,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
703
672
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
704
673
|
*
|
|
705
674
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
706
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
675
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
707
676
|
*
|
|
708
677
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
709
678
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -788,13 +757,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
788
757
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
789
758
|
*
|
|
790
759
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
791
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
760
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
792
761
|
*
|
|
793
762
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
794
763
|
* const signer = new Wallet(privateKey, provider);
|
|
795
764
|
* const escrowClient = await EscrowClient.build(signer);
|
|
796
765
|
*
|
|
797
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']
|
|
766
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
798
767
|
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
799
768
|
* ```
|
|
800
769
|
*/
|
|
@@ -852,7 +821,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
852
821
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
853
822
|
*
|
|
854
823
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
855
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
824
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
856
825
|
*
|
|
857
826
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
858
827
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -927,11 +896,177 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
927
896
|
}
|
|
928
897
|
}
|
|
929
898
|
|
|
899
|
+
/**
|
|
900
|
+
* Creates a prepared transaction for bulk payout without immediately sending it.
|
|
901
|
+
* @param {string} escrowAddress Escrow address to payout.
|
|
902
|
+
* @param {string[]} recipients Array of recipient addresses.
|
|
903
|
+
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
904
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
905
|
+
* @param {string} finalResultsHash Final results file hash.
|
|
906
|
+
* @param {number} txId Transaction ID.
|
|
907
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
908
|
+
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
909
|
+
* @returns Returns object with raw transaction and signed transaction hash
|
|
910
|
+
*
|
|
911
|
+
* **Code example**
|
|
912
|
+
*
|
|
913
|
+
* > Only Reputation Oracle or a trusted handler can call it.
|
|
914
|
+
*
|
|
915
|
+
* ```ts
|
|
916
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
917
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
918
|
+
*
|
|
919
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
920
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
921
|
+
*
|
|
922
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
923
|
+
* const signer = new Wallet(privateKey, provider);
|
|
924
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
925
|
+
*
|
|
926
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
927
|
+
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
928
|
+
* const resultsUrl = 'http://localhost/results.json';
|
|
929
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
930
|
+
* const txId = 1;
|
|
931
|
+
*
|
|
932
|
+
* const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
933
|
+
* console.log('Raw transaction:', rawTransaction);
|
|
934
|
+
*
|
|
935
|
+
* const signedTransaction = await signer.signTransaction(rawTransaction);
|
|
936
|
+
* console.log('Tx hash:', ethers.keccak256(signedTransaction));
|
|
937
|
+
* (await signer.sendTransaction(rawTransaction)).wait();
|
|
938
|
+
*/
|
|
939
|
+
@requiresSigner
|
|
940
|
+
async createBulkPayoutTransaction(
|
|
941
|
+
escrowAddress: string,
|
|
942
|
+
recipients: string[],
|
|
943
|
+
amounts: bigint[],
|
|
944
|
+
finalResultsUrl: string,
|
|
945
|
+
finalResultsHash: string,
|
|
946
|
+
txId: number,
|
|
947
|
+
forceComplete = false,
|
|
948
|
+
txOptions: Overrides = {}
|
|
949
|
+
): Promise<TransactionLikeWithNonce> {
|
|
950
|
+
await this.ensureCorrectBulkPayoutInput(
|
|
951
|
+
escrowAddress,
|
|
952
|
+
recipients,
|
|
953
|
+
amounts,
|
|
954
|
+
finalResultsUrl,
|
|
955
|
+
finalResultsHash
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
const signer = this.runner as Signer;
|
|
959
|
+
try {
|
|
960
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
961
|
+
|
|
962
|
+
const populatedTransaction = await escrowContract[
|
|
963
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
964
|
+
].populateTransaction(
|
|
965
|
+
recipients,
|
|
966
|
+
amounts,
|
|
967
|
+
finalResultsUrl,
|
|
968
|
+
finalResultsHash,
|
|
969
|
+
txId,
|
|
970
|
+
forceComplete,
|
|
971
|
+
txOptions
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Safety-belt: explicitly set the passed nonce
|
|
976
|
+
* because 'populateTransaction' return value
|
|
977
|
+
* doesn't mention it even in library docs,
|
|
978
|
+
* even though it includes if from txOptions.
|
|
979
|
+
*/
|
|
980
|
+
if (typeof txOptions.nonce === 'number') {
|
|
981
|
+
populatedTransaction.nonce = txOptions.nonce;
|
|
982
|
+
} else {
|
|
983
|
+
populatedTransaction.nonce = await signer.getNonce();
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* It's needed to get all necessary info for tx object
|
|
987
|
+
* before signing it, e.g.:
|
|
988
|
+
* - type
|
|
989
|
+
* - chainId
|
|
990
|
+
* - fees params
|
|
991
|
+
* - etc.
|
|
992
|
+
*
|
|
993
|
+
* All information is needed in order to get proper hash value
|
|
994
|
+
*/
|
|
995
|
+
const preparedTransaction =
|
|
996
|
+
await signer.populateTransaction(populatedTransaction);
|
|
997
|
+
|
|
998
|
+
return preparedTransaction as TransactionLikeWithNonce;
|
|
999
|
+
} catch (e) {
|
|
1000
|
+
return throwError(e);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
private async ensureCorrectBulkPayoutInput(
|
|
1005
|
+
escrowAddress: string,
|
|
1006
|
+
recipients: string[],
|
|
1007
|
+
amounts: bigint[],
|
|
1008
|
+
finalResultsUrl: string,
|
|
1009
|
+
finalResultsHash: string
|
|
1010
|
+
): Promise<void> {
|
|
1011
|
+
if (!ethers.isAddress(escrowAddress)) {
|
|
1012
|
+
throw ErrorInvalidEscrowAddressProvided;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
if (recipients.length === 0) {
|
|
1016
|
+
throw ErrorRecipientCannotBeEmptyArray;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
if (recipients.length > ESCROW_BULK_PAYOUT_MAX_ITEMS) {
|
|
1020
|
+
throw ErrorTooManyRecipients;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
if (amounts.length === 0) {
|
|
1024
|
+
throw ErrorAmountsCannotBeEmptyArray;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (recipients.length !== amounts.length) {
|
|
1028
|
+
throw ErrorRecipientAndAmountsMustBeSameLength;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
recipients.forEach((recipient) => {
|
|
1032
|
+
if (!ethers.isAddress(recipient)) {
|
|
1033
|
+
throw new InvalidEthereumAddressError(recipient);
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
if (!finalResultsUrl) {
|
|
1038
|
+
throw ErrorUrlIsEmptyString;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (!isValidUrl(finalResultsUrl)) {
|
|
1042
|
+
throw ErrorInvalidUrl;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
if (!finalResultsHash) {
|
|
1046
|
+
throw ErrorHashIsEmptyString;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
const balance = await this.getBalance(escrowAddress);
|
|
1050
|
+
|
|
1051
|
+
let totalAmount = 0n;
|
|
1052
|
+
amounts.forEach((amount) => {
|
|
1053
|
+
totalAmount = totalAmount + amount;
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
if (balance < totalAmount) {
|
|
1057
|
+
throw ErrorEscrowDoesNotHaveEnoughBalance;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
1061
|
+
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
930
1065
|
/**
|
|
931
1066
|
* This function returns the balance for a specified escrow address.
|
|
932
1067
|
*
|
|
933
1068
|
* @param {string} escrowAddress Address of the escrow.
|
|
934
|
-
* @returns {bigint} Balance of the escrow in the token used to fund it.
|
|
1069
|
+
* @returns {Promise<bigint>} Balance of the escrow in the token used to fund it.
|
|
935
1070
|
*
|
|
936
1071
|
* **Code example**
|
|
937
1072
|
*
|
|
@@ -942,7 +1077,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
942
1077
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
943
1078
|
*
|
|
944
1079
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
945
|
-
* const escrowClient = await EscrowClient.build(
|
|
1080
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
946
1081
|
*
|
|
947
1082
|
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
948
1083
|
* ```
|
|
@@ -975,7 +1110,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
975
1110
|
* This function returns the manifest file hash.
|
|
976
1111
|
*
|
|
977
1112
|
* @param {string} escrowAddress Address of the escrow.
|
|
978
|
-
* @returns {string} Hash of the manifest file content.
|
|
1113
|
+
* @returns {Promise<string>} Hash of the manifest file content.
|
|
979
1114
|
*
|
|
980
1115
|
* **Code example**
|
|
981
1116
|
*
|
|
@@ -986,7 +1121,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
986
1121
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
987
1122
|
*
|
|
988
1123
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
989
|
-
* const escrowClient = await EscrowClient.build(
|
|
1124
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
990
1125
|
*
|
|
991
1126
|
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
992
1127
|
* ```
|
|
@@ -1013,7 +1148,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1013
1148
|
* This function returns the manifest file URL.
|
|
1014
1149
|
*
|
|
1015
1150
|
* @param {string} escrowAddress Address of the escrow.
|
|
1016
|
-
* @returns {string} Url of the manifest.
|
|
1151
|
+
* @returns {Promise<string>} Url of the manifest.
|
|
1017
1152
|
*
|
|
1018
1153
|
* **Code example**
|
|
1019
1154
|
*
|
|
@@ -1024,7 +1159,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1024
1159
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1025
1160
|
*
|
|
1026
1161
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1027
|
-
* const escrowClient = await EscrowClient.build(
|
|
1162
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1028
1163
|
*
|
|
1029
1164
|
* const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1030
1165
|
* ```
|
|
@@ -1051,7 +1186,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1051
1186
|
* This function returns the results file URL.
|
|
1052
1187
|
*
|
|
1053
1188
|
* @param {string} escrowAddress Address of the escrow.
|
|
1054
|
-
* @returns {string} Results file url.
|
|
1189
|
+
* @returns {Promise<string>} Results file url.
|
|
1055
1190
|
*
|
|
1056
1191
|
* **Code example**
|
|
1057
1192
|
*
|
|
@@ -1062,7 +1197,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1062
1197
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1063
1198
|
*
|
|
1064
1199
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1065
|
-
* const escrowClient = await EscrowClient.build(
|
|
1200
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1066
1201
|
*
|
|
1067
1202
|
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1068
1203
|
* ```
|
|
@@ -1089,7 +1224,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1089
1224
|
* This function returns the intermediate results file URL.
|
|
1090
1225
|
*
|
|
1091
1226
|
* @param {string} escrowAddress Address of the escrow.
|
|
1092
|
-
* @returns {string} Url of the file that store results from Recording Oracle.
|
|
1227
|
+
* @returns {Promise<string>} Url of the file that store results from Recording Oracle.
|
|
1093
1228
|
*
|
|
1094
1229
|
* **Code example**
|
|
1095
1230
|
*
|
|
@@ -1100,9 +1235,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1100
1235
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1101
1236
|
*
|
|
1102
1237
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1103
|
-
* const escrowClient = await EscrowClient.build(
|
|
1238
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1104
1239
|
*
|
|
1105
|
-
* const
|
|
1240
|
+
* const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1106
1241
|
* ```
|
|
1107
1242
|
*/
|
|
1108
1243
|
async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
|
|
@@ -1118,7 +1253,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1118
1253
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1119
1254
|
|
|
1120
1255
|
return escrowContract.intermediateResultsUrl();
|
|
1121
|
-
} catch (e
|
|
1256
|
+
} catch (e) {
|
|
1122
1257
|
return throwError(e);
|
|
1123
1258
|
}
|
|
1124
1259
|
}
|
|
@@ -1127,7 +1262,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1127
1262
|
* This function returns the token address used for funding the escrow.
|
|
1128
1263
|
*
|
|
1129
1264
|
* @param {string} escrowAddress Address of the escrow.
|
|
1130
|
-
* @returns {string} Address of the token used to fund the escrow.
|
|
1265
|
+
* @returns {Promise<string>} Address of the token used to fund the escrow.
|
|
1131
1266
|
*
|
|
1132
1267
|
* **Code example**
|
|
1133
1268
|
*
|
|
@@ -1138,7 +1273,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1138
1273
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1139
1274
|
*
|
|
1140
1275
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1141
|
-
* const escrowClient = await EscrowClient.build(
|
|
1276
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1142
1277
|
*
|
|
1143
1278
|
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1144
1279
|
* ```
|
|
@@ -1165,7 +1300,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1165
1300
|
* This function returns the current status of the escrow.
|
|
1166
1301
|
*
|
|
1167
1302
|
* @param {string} escrowAddress Address of the escrow.
|
|
1168
|
-
* @returns {EscrowStatus} Current status of the escrow.
|
|
1303
|
+
* @returns {Promise<EscrowStatus>} Current status of the escrow.
|
|
1169
1304
|
*
|
|
1170
1305
|
* **Code example**
|
|
1171
1306
|
*
|
|
@@ -1176,7 +1311,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1176
1311
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1177
1312
|
*
|
|
1178
1313
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1179
|
-
* const escrowClient = await EscrowClient.build(
|
|
1314
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1180
1315
|
*
|
|
1181
1316
|
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1182
1317
|
* ```
|
|
@@ -1203,7 +1338,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1203
1338
|
* This function returns the recording oracle address for a given escrow.
|
|
1204
1339
|
*
|
|
1205
1340
|
* @param {string} escrowAddress Address of the escrow.
|
|
1206
|
-
* @returns {string} Address of the Recording Oracle.
|
|
1341
|
+
* @returns {Promise<string>} Address of the Recording Oracle.
|
|
1207
1342
|
*
|
|
1208
1343
|
* **Code example**
|
|
1209
1344
|
*
|
|
@@ -1214,7 +1349,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1214
1349
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1215
1350
|
*
|
|
1216
1351
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1217
|
-
* const escrowClient = await EscrowClient.build(
|
|
1352
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1218
1353
|
*
|
|
1219
1354
|
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1220
1355
|
* ```
|
|
@@ -1232,7 +1367,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1232
1367
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1233
1368
|
|
|
1234
1369
|
return escrowContract.recordingOracle();
|
|
1235
|
-
} catch (e
|
|
1370
|
+
} catch (e) {
|
|
1236
1371
|
return throwError(e);
|
|
1237
1372
|
}
|
|
1238
1373
|
}
|
|
@@ -1241,7 +1376,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1241
1376
|
* This function returns the job launcher address for a given escrow.
|
|
1242
1377
|
*
|
|
1243
1378
|
* @param {string} escrowAddress Address of the escrow.
|
|
1244
|
-
* @returns {string} Address of the Job Launcher.
|
|
1379
|
+
* @returns {Promise<string>} Address of the Job Launcher.
|
|
1245
1380
|
*
|
|
1246
1381
|
* **Code example**
|
|
1247
1382
|
*
|
|
@@ -1252,7 +1387,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1252
1387
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1253
1388
|
*
|
|
1254
1389
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1255
|
-
* const escrowClient = await EscrowClient.build(
|
|
1390
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1256
1391
|
*
|
|
1257
1392
|
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1258
1393
|
* ```
|
|
@@ -1270,7 +1405,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1270
1405
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1271
1406
|
|
|
1272
1407
|
return escrowContract.launcher();
|
|
1273
|
-
} catch (e
|
|
1408
|
+
} catch (e) {
|
|
1274
1409
|
return throwError(e);
|
|
1275
1410
|
}
|
|
1276
1411
|
}
|
|
@@ -1279,7 +1414,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1279
1414
|
* This function returns the reputation oracle address for a given escrow.
|
|
1280
1415
|
*
|
|
1281
1416
|
* @param {string} escrowAddress Address of the escrow.
|
|
1282
|
-
* @returns {
|
|
1417
|
+
* @returns {Promise<string>} Address of the Reputation Oracle.
|
|
1283
1418
|
*
|
|
1284
1419
|
* **Code example**
|
|
1285
1420
|
*
|
|
@@ -1290,7 +1425,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1290
1425
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1291
1426
|
*
|
|
1292
1427
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1293
|
-
* const escrowClient = await EscrowClient.build(
|
|
1428
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1294
1429
|
*
|
|
1295
1430
|
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1296
1431
|
* ```
|
|
@@ -1308,7 +1443,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1308
1443
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1309
1444
|
|
|
1310
1445
|
return escrowContract.reputationOracle();
|
|
1311
|
-
} catch (e
|
|
1446
|
+
} catch (e) {
|
|
1312
1447
|
return throwError(e);
|
|
1313
1448
|
}
|
|
1314
1449
|
}
|
|
@@ -1317,7 +1452,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1317
1452
|
* This function returns the exchange oracle address for a given escrow.
|
|
1318
1453
|
*
|
|
1319
1454
|
* @param {string} escrowAddress Address of the escrow.
|
|
1320
|
-
* @returns {
|
|
1455
|
+
* @returns {Promise<string>} Address of the Exchange Oracle.
|
|
1321
1456
|
*
|
|
1322
1457
|
* **Code example**
|
|
1323
1458
|
*
|
|
@@ -1328,7 +1463,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1328
1463
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1329
1464
|
*
|
|
1330
1465
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1331
|
-
* const escrowClient = await EscrowClient.build(
|
|
1466
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1332
1467
|
*
|
|
1333
1468
|
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1334
1469
|
* ```
|
|
@@ -1346,7 +1481,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1346
1481
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1347
1482
|
|
|
1348
1483
|
return escrowContract.exchangeOracle();
|
|
1349
|
-
} catch (e
|
|
1484
|
+
} catch (e) {
|
|
1350
1485
|
return throwError(e);
|
|
1351
1486
|
}
|
|
1352
1487
|
}
|
|
@@ -1355,7 +1490,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1355
1490
|
* This function returns the escrow factory address for a given escrow.
|
|
1356
1491
|
*
|
|
1357
1492
|
* @param {string} escrowAddress Address of the escrow.
|
|
1358
|
-
* @returns {
|
|
1493
|
+
* @returns {Promise<string>} Address of the escrow factory.
|
|
1359
1494
|
*
|
|
1360
1495
|
* **Code example**
|
|
1361
1496
|
*
|
|
@@ -1366,7 +1501,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1366
1501
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1367
1502
|
*
|
|
1368
1503
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1369
|
-
* const escrowClient = await EscrowClient.build(
|
|
1504
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1370
1505
|
*
|
|
1371
1506
|
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1372
1507
|
* ```
|
|
@@ -1384,12 +1519,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1384
1519
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1385
1520
|
|
|
1386
1521
|
return escrowContract.escrowFactory();
|
|
1387
|
-
} catch (e
|
|
1522
|
+
} catch (e) {
|
|
1388
1523
|
return throwError(e);
|
|
1389
1524
|
}
|
|
1390
1525
|
}
|
|
1391
1526
|
}
|
|
1392
|
-
|
|
1393
1527
|
/**
|
|
1394
1528
|
* ## Introduction
|
|
1395
1529
|
*
|
|
@@ -1417,7 +1551,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1417
1551
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1418
1552
|
*
|
|
1419
1553
|
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1420
|
-
*
|
|
1554
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
1421
1555
|
* });
|
|
1422
1556
|
* ```
|
|
1423
1557
|
*/
|
|
@@ -1449,20 +1583,11 @@ export class EscrowUtils {
|
|
|
1449
1583
|
* enum ChainId {
|
|
1450
1584
|
* ALL = -1,
|
|
1451
1585
|
* MAINNET = 1,
|
|
1452
|
-
*
|
|
1453
|
-
* GOERLI = 5,
|
|
1586
|
+
* SEPOLIA = 11155111,
|
|
1454
1587
|
* BSC_MAINNET = 56,
|
|
1455
1588
|
* BSC_TESTNET = 97,
|
|
1456
1589
|
* POLYGON = 137,
|
|
1457
|
-
* POLYGON_MUMBAI = 80001,
|
|
1458
1590
|
* POLYGON_AMOY=80002,
|
|
1459
|
-
* MOONBEAM = 1284,
|
|
1460
|
-
* MOONBASE_ALPHA = 1287,
|
|
1461
|
-
* AVALANCHE = 43114,
|
|
1462
|
-
* AVALANCHE_TESTNET = 43113,
|
|
1463
|
-
* CELO = 42220,
|
|
1464
|
-
* CELO_ALFAJORES = 44787,
|
|
1465
|
-
* = 1273227453,
|
|
1466
1591
|
* LOCALHOST = 1338,
|
|
1467
1592
|
* }
|
|
1468
1593
|
* ```
|
|
@@ -1572,8 +1697,8 @@ export class EscrowUtils {
|
|
|
1572
1697
|
([, value]) => value === filter.status
|
|
1573
1698
|
)?.[0]
|
|
1574
1699
|
: undefined,
|
|
1575
|
-
from: filter.from ?
|
|
1576
|
-
to: filter.to ?
|
|
1700
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
1701
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
1577
1702
|
orderDirection: orderDirection,
|
|
1578
1703
|
first: first,
|
|
1579
1704
|
skip: skip,
|
|
@@ -1599,19 +1724,11 @@ export class EscrowUtils {
|
|
|
1599
1724
|
* enum ChainId {
|
|
1600
1725
|
* ALL = -1,
|
|
1601
1726
|
* MAINNET = 1,
|
|
1602
|
-
*
|
|
1603
|
-
* GOERLI = 5,
|
|
1727
|
+
* SEPOLIA = 11155111,
|
|
1604
1728
|
* BSC_MAINNET = 56,
|
|
1605
1729
|
* BSC_TESTNET = 97,
|
|
1606
1730
|
* POLYGON = 137,
|
|
1607
|
-
* POLYGON_MUMBAI = 80001,
|
|
1608
1731
|
* POLYGON_AMOY = 80002,
|
|
1609
|
-
* MOONBEAM = 1284,
|
|
1610
|
-
* MOONBASE_ALPHA = 1287,
|
|
1611
|
-
* AVALANCHE = 43114,
|
|
1612
|
-
* AVALANCHE_TESTNET = 43113,
|
|
1613
|
-
* CELO = 42220,
|
|
1614
|
-
* CELO_ALFAJORES = 44787,
|
|
1615
1732
|
* LOCALHOST = 1338,
|
|
1616
1733
|
* }
|
|
1617
1734
|
* ```
|
|
@@ -1687,23 +1804,12 @@ export class EscrowUtils {
|
|
|
1687
1804
|
* enum ChainId {
|
|
1688
1805
|
* ALL = -1,
|
|
1689
1806
|
* MAINNET = 1,
|
|
1690
|
-
* RINKEBY = 4,
|
|
1691
|
-
* GOERLI = 5,
|
|
1692
1807
|
* SEPOLIA = 11155111,
|
|
1693
1808
|
* BSC_MAINNET = 56,
|
|
1694
1809
|
* BSC_TESTNET = 97,
|
|
1695
1810
|
* POLYGON = 137,
|
|
1696
|
-
* POLYGON_MUMBAI = 80001,
|
|
1697
1811
|
* POLYGON_AMOY = 80002,
|
|
1698
|
-
* MOONBEAM = 1284,
|
|
1699
|
-
* MOONBASE_ALPHA = 1287,
|
|
1700
|
-
* AVALANCHE = 43114,
|
|
1701
|
-
* AVALANCHE_TESTNET = 43113,
|
|
1702
|
-
* CELO = 42220,
|
|
1703
|
-
* CELO_ALFAJORES = 44787,
|
|
1704
1812
|
* LOCALHOST = 1338,
|
|
1705
|
-
* XLAYER_TESTNET = 195,
|
|
1706
|
-
* XLAYER = 196,
|
|
1707
1813
|
* }
|
|
1708
1814
|
* ```
|
|
1709
1815
|
*
|
|
@@ -1793,8 +1899,8 @@ export class EscrowUtils {
|
|
|
1793
1899
|
GET_STATUS_UPDATES_QUERY(from, to, launcher),
|
|
1794
1900
|
{
|
|
1795
1901
|
status: statusNames,
|
|
1796
|
-
from: from ?
|
|
1797
|
-
to: to ?
|
|
1902
|
+
from: from ? getUnixTimestamp(from) : undefined,
|
|
1903
|
+
to: to ? getUnixTimestamp(to) : undefined,
|
|
1798
1904
|
launcher: launcher || undefined,
|
|
1799
1905
|
orderDirection: orderDirection,
|
|
1800
1906
|
first: first,
|