@human-protocol/sdk 3.0.7 → 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 +2 -25
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +25 -66
- 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 +34 -36
- 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 +118 -112
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +254 -180
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +15 -7
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +0 -2
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +23 -10
- package/dist/graphql/types.d.ts +0 -2
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/interfaces.d.ts +29 -12
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +16 -16
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +16 -16
- package/dist/operator.d.ts +11 -10
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +36 -11
- package/dist/staking.d.ts +26 -118
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +46 -173
- package/dist/statistics.d.ts +10 -29
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +13 -30
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +30 -25
- package/dist/transaction.js +1 -1
- package/dist/types.d.ts +23 -6
- 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 +8 -4
- package/src/constants.ts +25 -66
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/error.ts +39 -37
- package/src/escrow.ts +360 -216
- package/src/graphql/queries/operator.ts +15 -7
- package/src/graphql/queries/statistics.ts +0 -2
- package/src/graphql/queries/transaction.ts +23 -13
- package/src/graphql/types.ts +0 -2
- package/src/interfaces.ts +30 -13
- package/src/kvstore.ts +17 -17
- package/src/operator.ts +47 -12
- package/src/staking.ts +53 -187
- package/src/statistics.ts +13 -30
- package/src/storage.ts +13 -18
- package/src/transaction.ts +2 -2
- package/src/types.ts +24 -6
- package/src/utils.ts +0 -1
package/dist/escrow.js
CHANGED
|
@@ -28,19 +28,19 @@ const utils_1 = require("./utils");
|
|
|
28
28
|
/**
|
|
29
29
|
* ## Introduction
|
|
30
30
|
*
|
|
31
|
-
* This client enables
|
|
31
|
+
* This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
|
|
32
32
|
*
|
|
33
33
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
34
34
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
35
35
|
*
|
|
36
36
|
* ```ts
|
|
37
|
-
* static async build(runner: ContractRunner)
|
|
37
|
+
* static async build(runner: ContractRunner): Promise<EscrowClient>;
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
40
40
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
41
41
|
*
|
|
42
|
-
* - **Signer**: when the user wants to use this model
|
|
43
|
-
* - **Provider**: when the user wants to use this model
|
|
42
|
+
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
43
|
+
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
44
44
|
*
|
|
45
45
|
* ## Installation
|
|
46
46
|
*
|
|
@@ -58,21 +58,21 @@ const utils_1 = require("./utils");
|
|
|
58
58
|
*
|
|
59
59
|
* ### Signer
|
|
60
60
|
*
|
|
61
|
-
* **Using private key(backend)**
|
|
61
|
+
* **Using private key (backend)**
|
|
62
62
|
*
|
|
63
63
|
* ```ts
|
|
64
64
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
65
65
|
* import { Wallet, providers } from 'ethers';
|
|
66
66
|
*
|
|
67
67
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
68
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
68
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
69
69
|
*
|
|
70
70
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
71
71
|
* const signer = new Wallet(privateKey, provider);
|
|
72
72
|
* const escrowClient = await EscrowClient.build(signer);
|
|
73
73
|
* ```
|
|
74
74
|
*
|
|
75
|
-
* **Using Wagmi(frontend)**
|
|
75
|
+
* **Using Wagmi (frontend)**
|
|
76
76
|
*
|
|
77
77
|
* ```ts
|
|
78
78
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -99,7 +99,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
99
99
|
* **EscrowClient constructor**
|
|
100
100
|
*
|
|
101
101
|
* @param {ContractRunner} runner The Runner object to interact with the Ethereum network
|
|
102
|
-
* @param {NetworkData}
|
|
102
|
+
* @param {NetworkData} networkData The network information required to connect to the Escrow contract
|
|
103
103
|
*/
|
|
104
104
|
constructor(runner, networkData) {
|
|
105
105
|
super(runner, networkData);
|
|
@@ -142,11 +142,11 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
142
142
|
/**
|
|
143
143
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
144
144
|
*
|
|
145
|
-
* @param {string} tokenAddress Token address to use for
|
|
145
|
+
* @param {string} tokenAddress Token address to use for payouts.
|
|
146
146
|
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
147
147
|
* @param {string} jobRequesterId Job Requester Id
|
|
148
148
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
149
|
-
* @returns {Promise<string>}
|
|
149
|
+
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
150
150
|
*
|
|
151
151
|
*
|
|
152
152
|
* **Code example**
|
|
@@ -158,7 +158,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
158
158
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
159
159
|
*
|
|
160
160
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
161
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
161
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
162
162
|
*
|
|
163
163
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
164
164
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -209,7 +209,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
209
209
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
210
210
|
*
|
|
211
211
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
212
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
212
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
213
213
|
*
|
|
214
214
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
215
215
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -220,10 +220,10 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
220
220
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
221
221
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
222
222
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
223
|
-
* recordingOracleFee:
|
|
224
|
-
* reputationOracleFee:
|
|
225
|
-
* exchangeOracleFee:
|
|
226
|
-
* manifestUrl: '
|
|
223
|
+
* recordingOracleFee: BigInt('10'),
|
|
224
|
+
* reputationOracleFee: BigInt('10'),
|
|
225
|
+
* exchangeOracleFee: BigInt('10'),
|
|
226
|
+
* manifestUrl: 'http://localhost/manifest.json',
|
|
227
227
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
228
228
|
* };
|
|
229
229
|
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
@@ -272,57 +272,6 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
272
272
|
return (0, utils_1.throwError)(e);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
/**
|
|
276
|
-
* This function creates and sets up an escrow.
|
|
277
|
-
*
|
|
278
|
-
* @param {string} tokenAddress Token address to use for pay outs.
|
|
279
|
-
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
280
|
-
* @param {string} jobRequesterId Job Requester Id
|
|
281
|
-
* @param {IEscrowConfig} escrowConfig Configuration object with escrow settings.
|
|
282
|
-
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
* **Code example**
|
|
286
|
-
*
|
|
287
|
-
* ```ts
|
|
288
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
289
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
290
|
-
*
|
|
291
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
292
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
293
|
-
*
|
|
294
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
295
|
-
* const signer = new Wallet(privateKey, provider);
|
|
296
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
297
|
-
*
|
|
298
|
-
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
299
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
300
|
-
* const jobRequesterId = "job-requester-id";
|
|
301
|
-
*
|
|
302
|
-
* const escrowConfig = {
|
|
303
|
-
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
304
|
-
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
305
|
-
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
306
|
-
* recordingOracleFee: bigint.from('10'),
|
|
307
|
-
* reputationOracleFee: bigint.from('10'),
|
|
308
|
-
* exchangeOracleFee: bigint.from('10'),
|
|
309
|
-
* manifestUrl: 'htttp://localhost/manifest.json',
|
|
310
|
-
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
311
|
-
* };
|
|
312
|
-
*
|
|
313
|
-
* const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig);
|
|
314
|
-
* ```
|
|
315
|
-
*/
|
|
316
|
-
async createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig) {
|
|
317
|
-
try {
|
|
318
|
-
const escrowAddress = await this.createEscrow(tokenAddress, trustedHandlers, jobRequesterId);
|
|
319
|
-
await this.setup(escrowAddress, escrowConfig);
|
|
320
|
-
return escrowAddress;
|
|
321
|
-
}
|
|
322
|
-
catch (e) {
|
|
323
|
-
return (0, utils_1.throwError)(e);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
275
|
/**
|
|
327
276
|
* This function adds funds of the chosen token to the escrow.
|
|
328
277
|
*
|
|
@@ -339,7 +288,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
339
288
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
340
289
|
*
|
|
341
290
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
342
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
291
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
343
292
|
*
|
|
344
293
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
345
294
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -371,10 +320,10 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
371
320
|
}
|
|
372
321
|
}
|
|
373
322
|
/**
|
|
374
|
-
* This function stores the results
|
|
323
|
+
* This function stores the results URL and hash.
|
|
375
324
|
*
|
|
376
325
|
* @param {string} escrowAddress Address of the escrow.
|
|
377
|
-
* @param {string} url Results file
|
|
326
|
+
* @param {string} url Results file URL.
|
|
378
327
|
* @param {string} hash Results file hash.
|
|
379
328
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
380
329
|
* @returns Returns void if successful. Throws error if any.
|
|
@@ -389,13 +338,13 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
389
338
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
390
339
|
*
|
|
391
340
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
392
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
341
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
393
342
|
*
|
|
394
343
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
395
344
|
* const signer = new Wallet(privateKey, provider);
|
|
396
345
|
* const escrowClient = await EscrowClient.build(signer);
|
|
397
346
|
*
|
|
398
|
-
* await
|
|
347
|
+
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
399
348
|
* ```
|
|
400
349
|
*/
|
|
401
350
|
async storeResults(escrowAddress, url, hash, txOptions = {}) {
|
|
@@ -440,7 +389,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
440
389
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
441
390
|
*
|
|
442
391
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
443
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
392
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
444
393
|
*
|
|
445
394
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
446
395
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -471,8 +420,10 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
471
420
|
* @param {string} escrowAddress Escrow address to payout.
|
|
472
421
|
* @param {string[]} recipients Array of recipient addresses.
|
|
473
422
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
474
|
-
* @param {string} finalResultsUrl Final results file
|
|
423
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
475
424
|
* @param {string} finalResultsHash Final results file hash.
|
|
425
|
+
* @param {number} txId Transaction ID.
|
|
426
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
476
427
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
477
428
|
* @returns Returns void if successful. Throws error if any.
|
|
478
429
|
*
|
|
@@ -486,7 +437,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
486
437
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
487
438
|
*
|
|
488
439
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
489
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
440
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
490
441
|
*
|
|
491
442
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
492
443
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -495,52 +446,22 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
495
446
|
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
496
447
|
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
497
448
|
* const resultsUrl = 'http://localhost/results.json';
|
|
498
|
-
* const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
449
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
450
|
+
* const txId = 1;
|
|
499
451
|
*
|
|
500
|
-
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash);
|
|
452
|
+
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
501
453
|
* ```
|
|
502
454
|
*/
|
|
503
|
-
async bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txOptions = {}) {
|
|
504
|
-
|
|
505
|
-
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
506
|
-
}
|
|
507
|
-
if (recipients.length === 0) {
|
|
508
|
-
throw error_1.ErrorRecipientCannotBeEmptyArray;
|
|
509
|
-
}
|
|
510
|
-
if (amounts.length === 0) {
|
|
511
|
-
throw error_1.ErrorAmountsCannotBeEmptyArray;
|
|
512
|
-
}
|
|
513
|
-
if (recipients.length !== amounts.length) {
|
|
514
|
-
throw error_1.ErrorRecipientAndAmountsMustBeSameLength;
|
|
515
|
-
}
|
|
516
|
-
recipients.forEach((recipient) => {
|
|
517
|
-
if (!ethers_1.ethers.isAddress(recipient)) {
|
|
518
|
-
throw new error_1.InvalidEthereumAddressError(recipient);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
if (!finalResultsUrl) {
|
|
522
|
-
throw error_1.ErrorUrlIsEmptyString;
|
|
523
|
-
}
|
|
524
|
-
if (!(0, utils_1.isValidUrl)(finalResultsUrl)) {
|
|
525
|
-
throw error_1.ErrorInvalidUrl;
|
|
526
|
-
}
|
|
527
|
-
if (!finalResultsHash) {
|
|
528
|
-
throw error_1.ErrorHashIsEmptyString;
|
|
529
|
-
}
|
|
530
|
-
const balance = await this.getBalance(escrowAddress);
|
|
531
|
-
let totalAmount = 0n;
|
|
532
|
-
amounts.forEach((amount) => {
|
|
533
|
-
totalAmount = totalAmount + amount;
|
|
534
|
-
});
|
|
535
|
-
if (balance < totalAmount) {
|
|
536
|
-
throw error_1.ErrorEscrowDoesNotHaveEnoughBalance;
|
|
537
|
-
}
|
|
538
|
-
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
539
|
-
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
540
|
-
}
|
|
455
|
+
async bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete = false, txOptions = {}) {
|
|
456
|
+
await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
541
457
|
try {
|
|
542
458
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
543
|
-
|
|
459
|
+
if (forceComplete) {
|
|
460
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, txOptions)).wait();
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, txOptions)).wait();
|
|
464
|
+
}
|
|
544
465
|
return;
|
|
545
466
|
}
|
|
546
467
|
catch (e) {
|
|
@@ -564,7 +485,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
564
485
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
565
486
|
*
|
|
566
487
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
567
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
488
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
568
489
|
*
|
|
569
490
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
570
491
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -614,9 +535,10 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
614
535
|
}
|
|
615
536
|
}
|
|
616
537
|
/**
|
|
617
|
-
* This function
|
|
538
|
+
* This function adds an array of addresses to the trusted handlers list.
|
|
618
539
|
*
|
|
619
540
|
* @param {string} escrowAddress Address of the escrow.
|
|
541
|
+
* @param {string[]} trustedHandlers Array of addresses of trusted handlers to add.
|
|
620
542
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
621
543
|
* @returns Returns void if successful. Throws error if any.
|
|
622
544
|
*
|
|
@@ -630,25 +552,34 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
630
552
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
631
553
|
*
|
|
632
554
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
633
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
555
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
634
556
|
*
|
|
635
557
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
636
558
|
* const signer = new Wallet(privateKey, provider);
|
|
637
559
|
* const escrowClient = await EscrowClient.build(signer);
|
|
638
560
|
*
|
|
639
|
-
*
|
|
561
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
562
|
+
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
640
563
|
* ```
|
|
641
564
|
*/
|
|
642
|
-
async
|
|
565
|
+
async addTrustedHandlers(escrowAddress, trustedHandlers, txOptions = {}) {
|
|
643
566
|
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
644
567
|
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
645
568
|
}
|
|
569
|
+
if (trustedHandlers.length === 0) {
|
|
570
|
+
throw error_1.ErrorListOfHandlersCannotBeEmpty;
|
|
571
|
+
}
|
|
572
|
+
trustedHandlers.forEach((trustedHandler) => {
|
|
573
|
+
if (!ethers_1.ethers.isAddress(trustedHandler)) {
|
|
574
|
+
throw new error_1.InvalidEthereumAddressError(trustedHandler);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
646
577
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
647
578
|
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
648
579
|
}
|
|
649
580
|
try {
|
|
650
581
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
651
|
-
await (await escrowContract.
|
|
582
|
+
await (await escrowContract.addTrustedHandlers(trustedHandlers, txOptions)).wait();
|
|
652
583
|
return;
|
|
653
584
|
}
|
|
654
585
|
catch (e) {
|
|
@@ -656,62 +587,200 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
656
587
|
}
|
|
657
588
|
}
|
|
658
589
|
/**
|
|
659
|
-
* This function
|
|
590
|
+
* This function withdraws additional tokens in the escrow to the canceler.
|
|
660
591
|
*
|
|
661
|
-
* @param {string} escrowAddress Address of the escrow.
|
|
662
|
-
* @param {string
|
|
592
|
+
* @param {string} escrowAddress Address of the escrow to withdraw.
|
|
593
|
+
* @param {string} tokenAddress Address of the token to withdraw.
|
|
663
594
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
664
|
-
* @returns Returns
|
|
595
|
+
* @returns {EscrowWithdraw} Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.
|
|
665
596
|
*
|
|
666
597
|
*
|
|
667
598
|
* **Code example**
|
|
668
599
|
*
|
|
669
|
-
* > Only Job Launcher or trusted handler can call it.
|
|
600
|
+
* > Only Job Launcher or a trusted handler can call it.
|
|
670
601
|
*
|
|
671
602
|
* ```ts
|
|
672
|
-
* import { Wallet, providers } from 'ethers';
|
|
603
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
673
604
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
674
605
|
*
|
|
675
606
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
676
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
607
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
677
608
|
*
|
|
678
609
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
679
610
|
* const signer = new Wallet(privateKey, provider);
|
|
680
611
|
* const escrowClient = await EscrowClient.build(signer);
|
|
681
612
|
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
613
|
+
* await escrowClient.withdraw(
|
|
614
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
615
|
+
* '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
|
|
616
|
+
* );
|
|
684
617
|
* ```
|
|
685
618
|
*/
|
|
686
|
-
async
|
|
619
|
+
async withdraw(escrowAddress, tokenAddress, txOptions = {}) {
|
|
687
620
|
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
688
621
|
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
689
622
|
}
|
|
690
|
-
if (
|
|
691
|
-
throw error_1.
|
|
623
|
+
if (!ethers_1.ethers.isAddress(tokenAddress)) {
|
|
624
|
+
throw error_1.ErrorInvalidTokenAddress;
|
|
692
625
|
}
|
|
693
|
-
trustedHandlers.forEach((trustedHandler) => {
|
|
694
|
-
if (!ethers_1.ethers.isAddress(trustedHandler)) {
|
|
695
|
-
throw new error_1.InvalidEthereumAddressError(trustedHandler);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
626
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
699
627
|
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
700
628
|
}
|
|
701
629
|
try {
|
|
702
630
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
703
|
-
await (await escrowContract.
|
|
704
|
-
|
|
631
|
+
const transactionReceipt = await (await escrowContract.withdraw(tokenAddress, txOptions)).wait();
|
|
632
|
+
let amountTransferred = undefined;
|
|
633
|
+
const tokenContract = typechain_types_1.ERC20__factory.connect(tokenAddress, this.runner);
|
|
634
|
+
if (transactionReceipt)
|
|
635
|
+
for (const log of transactionReceipt.logs) {
|
|
636
|
+
if (log.address === tokenAddress) {
|
|
637
|
+
const parsedLog = tokenContract.interface.parseLog({
|
|
638
|
+
topics: log.topics,
|
|
639
|
+
data: log.data,
|
|
640
|
+
});
|
|
641
|
+
const from = parsedLog?.args[0];
|
|
642
|
+
if (parsedLog?.name === 'Transfer' && from === escrowAddress) {
|
|
643
|
+
amountTransferred = parsedLog?.args[2];
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (amountTransferred === undefined) {
|
|
649
|
+
throw error_1.ErrorTransferEventNotFoundInTransactionLogs;
|
|
650
|
+
}
|
|
651
|
+
const escrowWithdrawData = {
|
|
652
|
+
txHash: transactionReceipt?.hash || '',
|
|
653
|
+
tokenAddress,
|
|
654
|
+
amountWithdrawn: amountTransferred,
|
|
655
|
+
};
|
|
656
|
+
return escrowWithdrawData;
|
|
705
657
|
}
|
|
706
658
|
catch (e) {
|
|
707
659
|
return (0, utils_1.throwError)(e);
|
|
708
660
|
}
|
|
709
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* Creates a prepared transaction for bulk payout without immediately sending it.
|
|
664
|
+
* @param {string} escrowAddress Escrow address to payout.
|
|
665
|
+
* @param {string[]} recipients Array of recipient addresses.
|
|
666
|
+
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
667
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
668
|
+
* @param {string} finalResultsHash Final results file hash.
|
|
669
|
+
* @param {number} txId Transaction ID.
|
|
670
|
+
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
671
|
+
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
672
|
+
* @returns Returns object with raw transaction and signed transaction hash
|
|
673
|
+
*
|
|
674
|
+
* **Code example**
|
|
675
|
+
*
|
|
676
|
+
* > Only Reputation Oracle or a trusted handler can call it.
|
|
677
|
+
*
|
|
678
|
+
* ```ts
|
|
679
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
680
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
681
|
+
*
|
|
682
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
683
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
684
|
+
*
|
|
685
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
686
|
+
* const signer = new Wallet(privateKey, provider);
|
|
687
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
688
|
+
*
|
|
689
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
690
|
+
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
691
|
+
* const resultsUrl = 'http://localhost/results.json';
|
|
692
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
693
|
+
* const txId = 1;
|
|
694
|
+
*
|
|
695
|
+
* const rawTransaction = await escrowClient.createBulkPayoutTransaction('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
696
|
+
* console.log('Raw transaction:', rawTransaction);
|
|
697
|
+
*
|
|
698
|
+
* const signedTransaction = await signer.signTransaction(rawTransaction);
|
|
699
|
+
* console.log('Tx hash:', ethers.keccak256(signedTransaction));
|
|
700
|
+
* (await signer.sendTransaction(rawTransaction)).wait();
|
|
701
|
+
*/
|
|
702
|
+
async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete = false, txOptions = {}) {
|
|
703
|
+
await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
704
|
+
const signer = this.runner;
|
|
705
|
+
try {
|
|
706
|
+
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
707
|
+
const populatedTransaction = await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'].populateTransaction(recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, txOptions);
|
|
708
|
+
/**
|
|
709
|
+
* Safety-belt: explicitly set the passed nonce
|
|
710
|
+
* because 'populateTransaction' return value
|
|
711
|
+
* doesn't mention it even in library docs,
|
|
712
|
+
* even though it includes if from txOptions.
|
|
713
|
+
*/
|
|
714
|
+
if (typeof txOptions.nonce === 'number') {
|
|
715
|
+
populatedTransaction.nonce = txOptions.nonce;
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
populatedTransaction.nonce = await signer.getNonce();
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* It's needed to get all necessary info for tx object
|
|
722
|
+
* before signing it, e.g.:
|
|
723
|
+
* - type
|
|
724
|
+
* - chainId
|
|
725
|
+
* - fees params
|
|
726
|
+
* - etc.
|
|
727
|
+
*
|
|
728
|
+
* All information is needed in order to get proper hash value
|
|
729
|
+
*/
|
|
730
|
+
const preparedTransaction = await signer.populateTransaction(populatedTransaction);
|
|
731
|
+
return preparedTransaction;
|
|
732
|
+
}
|
|
733
|
+
catch (e) {
|
|
734
|
+
return (0, utils_1.throwError)(e);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
async ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash) {
|
|
738
|
+
if (!ethers_1.ethers.isAddress(escrowAddress)) {
|
|
739
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
740
|
+
}
|
|
741
|
+
if (recipients.length === 0) {
|
|
742
|
+
throw error_1.ErrorRecipientCannotBeEmptyArray;
|
|
743
|
+
}
|
|
744
|
+
if (recipients.length > constants_1.ESCROW_BULK_PAYOUT_MAX_ITEMS) {
|
|
745
|
+
throw error_1.ErrorTooManyRecipients;
|
|
746
|
+
}
|
|
747
|
+
if (amounts.length === 0) {
|
|
748
|
+
throw error_1.ErrorAmountsCannotBeEmptyArray;
|
|
749
|
+
}
|
|
750
|
+
if (recipients.length !== amounts.length) {
|
|
751
|
+
throw error_1.ErrorRecipientAndAmountsMustBeSameLength;
|
|
752
|
+
}
|
|
753
|
+
recipients.forEach((recipient) => {
|
|
754
|
+
if (!ethers_1.ethers.isAddress(recipient)) {
|
|
755
|
+
throw new error_1.InvalidEthereumAddressError(recipient);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
if (!finalResultsUrl) {
|
|
759
|
+
throw error_1.ErrorUrlIsEmptyString;
|
|
760
|
+
}
|
|
761
|
+
if (!(0, utils_1.isValidUrl)(finalResultsUrl)) {
|
|
762
|
+
throw error_1.ErrorInvalidUrl;
|
|
763
|
+
}
|
|
764
|
+
if (!finalResultsHash) {
|
|
765
|
+
throw error_1.ErrorHashIsEmptyString;
|
|
766
|
+
}
|
|
767
|
+
const balance = await this.getBalance(escrowAddress);
|
|
768
|
+
let totalAmount = 0n;
|
|
769
|
+
amounts.forEach((amount) => {
|
|
770
|
+
totalAmount = totalAmount + amount;
|
|
771
|
+
});
|
|
772
|
+
if (balance < totalAmount) {
|
|
773
|
+
throw error_1.ErrorEscrowDoesNotHaveEnoughBalance;
|
|
774
|
+
}
|
|
775
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
776
|
+
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
710
779
|
/**
|
|
711
780
|
* This function returns the balance for a specified escrow address.
|
|
712
781
|
*
|
|
713
782
|
* @param {string} escrowAddress Address of the escrow.
|
|
714
|
-
* @returns {bigint} Balance of the escrow in the token used to fund it.
|
|
783
|
+
* @returns {Promise<bigint>} Balance of the escrow in the token used to fund it.
|
|
715
784
|
*
|
|
716
785
|
* **Code example**
|
|
717
786
|
*
|
|
@@ -722,7 +791,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
722
791
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
723
792
|
*
|
|
724
793
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
725
|
-
* const escrowClient = await EscrowClient.build(
|
|
794
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
726
795
|
*
|
|
727
796
|
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
728
797
|
* ```
|
|
@@ -736,7 +805,13 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
736
805
|
}
|
|
737
806
|
try {
|
|
738
807
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
739
|
-
|
|
808
|
+
try {
|
|
809
|
+
return await escrowContract.remainingFunds();
|
|
810
|
+
}
|
|
811
|
+
catch {
|
|
812
|
+
// Use getBalance() method below if remainingFunds() is not available
|
|
813
|
+
}
|
|
814
|
+
return await escrowContract.getBalance();
|
|
740
815
|
}
|
|
741
816
|
catch (e) {
|
|
742
817
|
return (0, utils_1.throwError)(e);
|
|
@@ -746,7 +821,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
746
821
|
* This function returns the manifest file hash.
|
|
747
822
|
*
|
|
748
823
|
* @param {string} escrowAddress Address of the escrow.
|
|
749
|
-
* @returns {string} Hash of the manifest file content.
|
|
824
|
+
* @returns {Promise<string>} Hash of the manifest file content.
|
|
750
825
|
*
|
|
751
826
|
* **Code example**
|
|
752
827
|
*
|
|
@@ -757,7 +832,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
757
832
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
758
833
|
*
|
|
759
834
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
760
|
-
* const escrowClient = await EscrowClient.build(
|
|
835
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
761
836
|
*
|
|
762
837
|
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
763
838
|
* ```
|
|
@@ -781,7 +856,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
781
856
|
* This function returns the manifest file URL.
|
|
782
857
|
*
|
|
783
858
|
* @param {string} escrowAddress Address of the escrow.
|
|
784
|
-
* @returns {string} Url of the manifest.
|
|
859
|
+
* @returns {Promise<string>} Url of the manifest.
|
|
785
860
|
*
|
|
786
861
|
* **Code example**
|
|
787
862
|
*
|
|
@@ -792,7 +867,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
792
867
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
793
868
|
*
|
|
794
869
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
795
|
-
* const escrowClient = await EscrowClient.build(
|
|
870
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
796
871
|
*
|
|
797
872
|
* const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
798
873
|
* ```
|
|
@@ -816,7 +891,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
816
891
|
* This function returns the results file URL.
|
|
817
892
|
*
|
|
818
893
|
* @param {string} escrowAddress Address of the escrow.
|
|
819
|
-
* @returns {string} Results file url.
|
|
894
|
+
* @returns {Promise<string>} Results file url.
|
|
820
895
|
*
|
|
821
896
|
* **Code example**
|
|
822
897
|
*
|
|
@@ -827,7 +902,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
827
902
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
828
903
|
*
|
|
829
904
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
830
|
-
* const escrowClient = await EscrowClient.build(
|
|
905
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
831
906
|
*
|
|
832
907
|
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
833
908
|
* ```
|
|
@@ -851,7 +926,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
851
926
|
* This function returns the intermediate results file URL.
|
|
852
927
|
*
|
|
853
928
|
* @param {string} escrowAddress Address of the escrow.
|
|
854
|
-
* @returns {string} Url of the file that store results from Recording Oracle.
|
|
929
|
+
* @returns {Promise<string>} Url of the file that store results from Recording Oracle.
|
|
855
930
|
*
|
|
856
931
|
* **Code example**
|
|
857
932
|
*
|
|
@@ -862,9 +937,9 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
862
937
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
863
938
|
*
|
|
864
939
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
865
|
-
* const escrowClient = await EscrowClient.build(
|
|
940
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
866
941
|
*
|
|
867
|
-
* const
|
|
942
|
+
* const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
868
943
|
* ```
|
|
869
944
|
*/
|
|
870
945
|
async getIntermediateResultsUrl(escrowAddress) {
|
|
@@ -886,7 +961,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
886
961
|
* This function returns the token address used for funding the escrow.
|
|
887
962
|
*
|
|
888
963
|
* @param {string} escrowAddress Address of the escrow.
|
|
889
|
-
* @returns {string} Address of the token used to fund the escrow.
|
|
964
|
+
* @returns {Promise<string>} Address of the token used to fund the escrow.
|
|
890
965
|
*
|
|
891
966
|
* **Code example**
|
|
892
967
|
*
|
|
@@ -897,7 +972,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
897
972
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
898
973
|
*
|
|
899
974
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
900
|
-
* const escrowClient = await EscrowClient.build(
|
|
975
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
901
976
|
*
|
|
902
977
|
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
903
978
|
* ```
|
|
@@ -921,7 +996,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
921
996
|
* This function returns the current status of the escrow.
|
|
922
997
|
*
|
|
923
998
|
* @param {string} escrowAddress Address of the escrow.
|
|
924
|
-
* @returns {EscrowStatus} Current status of the escrow.
|
|
999
|
+
* @returns {Promise<EscrowStatus>} Current status of the escrow.
|
|
925
1000
|
*
|
|
926
1001
|
* **Code example**
|
|
927
1002
|
*
|
|
@@ -932,7 +1007,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
932
1007
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
933
1008
|
*
|
|
934
1009
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
935
|
-
* const escrowClient = await EscrowClient.build(
|
|
1010
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
936
1011
|
*
|
|
937
1012
|
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
938
1013
|
* ```
|
|
@@ -956,7 +1031,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
956
1031
|
* This function returns the recording oracle address for a given escrow.
|
|
957
1032
|
*
|
|
958
1033
|
* @param {string} escrowAddress Address of the escrow.
|
|
959
|
-
* @returns {string} Address of the Recording Oracle.
|
|
1034
|
+
* @returns {Promise<string>} Address of the Recording Oracle.
|
|
960
1035
|
*
|
|
961
1036
|
* **Code example**
|
|
962
1037
|
*
|
|
@@ -967,7 +1042,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
967
1042
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
968
1043
|
*
|
|
969
1044
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
970
|
-
* const escrowClient = await EscrowClient.build(
|
|
1045
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
971
1046
|
*
|
|
972
1047
|
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
973
1048
|
* ```
|
|
@@ -991,7 +1066,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
991
1066
|
* This function returns the job launcher address for a given escrow.
|
|
992
1067
|
*
|
|
993
1068
|
* @param {string} escrowAddress Address of the escrow.
|
|
994
|
-
* @returns {string} Address of the Job Launcher.
|
|
1069
|
+
* @returns {Promise<string>} Address of the Job Launcher.
|
|
995
1070
|
*
|
|
996
1071
|
* **Code example**
|
|
997
1072
|
*
|
|
@@ -1002,7 +1077,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1002
1077
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1003
1078
|
*
|
|
1004
1079
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1005
|
-
* const escrowClient = await EscrowClient.build(
|
|
1080
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1006
1081
|
*
|
|
1007
1082
|
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1008
1083
|
* ```
|
|
@@ -1026,7 +1101,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1026
1101
|
* This function returns the reputation oracle address for a given escrow.
|
|
1027
1102
|
*
|
|
1028
1103
|
* @param {string} escrowAddress Address of the escrow.
|
|
1029
|
-
* @returns {
|
|
1104
|
+
* @returns {Promise<string>} Address of the Reputation Oracle.
|
|
1030
1105
|
*
|
|
1031
1106
|
* **Code example**
|
|
1032
1107
|
*
|
|
@@ -1037,7 +1112,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1037
1112
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1038
1113
|
*
|
|
1039
1114
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1040
|
-
* const escrowClient = await EscrowClient.build(
|
|
1115
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1041
1116
|
*
|
|
1042
1117
|
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1043
1118
|
* ```
|
|
@@ -1061,7 +1136,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1061
1136
|
* This function returns the exchange oracle address for a given escrow.
|
|
1062
1137
|
*
|
|
1063
1138
|
* @param {string} escrowAddress Address of the escrow.
|
|
1064
|
-
* @returns {
|
|
1139
|
+
* @returns {Promise<string>} Address of the Exchange Oracle.
|
|
1065
1140
|
*
|
|
1066
1141
|
* **Code example**
|
|
1067
1142
|
*
|
|
@@ -1072,7 +1147,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1072
1147
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1073
1148
|
*
|
|
1074
1149
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1075
|
-
* const escrowClient = await EscrowClient.build(
|
|
1150
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1076
1151
|
*
|
|
1077
1152
|
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1078
1153
|
* ```
|
|
@@ -1096,7 +1171,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1096
1171
|
* This function returns the escrow factory address for a given escrow.
|
|
1097
1172
|
*
|
|
1098
1173
|
* @param {string} escrowAddress Address of the escrow.
|
|
1099
|
-
* @returns {
|
|
1174
|
+
* @returns {Promise<string>} Address of the escrow factory.
|
|
1100
1175
|
*
|
|
1101
1176
|
* **Code example**
|
|
1102
1177
|
*
|
|
@@ -1107,7 +1182,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
1107
1182
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1108
1183
|
*
|
|
1109
1184
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1110
|
-
* const escrowClient = await EscrowClient.build(
|
|
1185
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1111
1186
|
*
|
|
1112
1187
|
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1113
1188
|
* ```
|
|
@@ -1141,12 +1216,6 @@ __decorate([
|
|
|
1141
1216
|
__metadata("design:paramtypes", [String, Object, Object]),
|
|
1142
1217
|
__metadata("design:returntype", Promise)
|
|
1143
1218
|
], EscrowClient.prototype, "setup", null);
|
|
1144
|
-
__decorate([
|
|
1145
|
-
decorators_1.requiresSigner,
|
|
1146
|
-
__metadata("design:type", Function),
|
|
1147
|
-
__metadata("design:paramtypes", [String, Array, String, Object]),
|
|
1148
|
-
__metadata("design:returntype", Promise)
|
|
1149
|
-
], EscrowClient.prototype, "createAndSetupEscrow", null);
|
|
1150
1219
|
__decorate([
|
|
1151
1220
|
decorators_1.requiresSigner,
|
|
1152
1221
|
__metadata("design:type", Function),
|
|
@@ -1168,7 +1237,7 @@ __decorate([
|
|
|
1168
1237
|
__decorate([
|
|
1169
1238
|
decorators_1.requiresSigner,
|
|
1170
1239
|
__metadata("design:type", Function),
|
|
1171
|
-
__metadata("design:paramtypes", [String, Array, Array, String, String, Object]),
|
|
1240
|
+
__metadata("design:paramtypes", [String, Array, Array, String, String, Number, Object, Object]),
|
|
1172
1241
|
__metadata("design:returntype", Promise)
|
|
1173
1242
|
], EscrowClient.prototype, "bulkPayOut", null);
|
|
1174
1243
|
__decorate([
|
|
@@ -1180,15 +1249,21 @@ __decorate([
|
|
|
1180
1249
|
__decorate([
|
|
1181
1250
|
decorators_1.requiresSigner,
|
|
1182
1251
|
__metadata("design:type", Function),
|
|
1183
|
-
__metadata("design:paramtypes", [String, Object]),
|
|
1252
|
+
__metadata("design:paramtypes", [String, Array, Object]),
|
|
1184
1253
|
__metadata("design:returntype", Promise)
|
|
1185
|
-
], EscrowClient.prototype, "
|
|
1254
|
+
], EscrowClient.prototype, "addTrustedHandlers", null);
|
|
1186
1255
|
__decorate([
|
|
1187
1256
|
decorators_1.requiresSigner,
|
|
1188
1257
|
__metadata("design:type", Function),
|
|
1189
|
-
__metadata("design:paramtypes", [String,
|
|
1258
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
1190
1259
|
__metadata("design:returntype", Promise)
|
|
1191
|
-
], EscrowClient.prototype, "
|
|
1260
|
+
], EscrowClient.prototype, "withdraw", null);
|
|
1261
|
+
__decorate([
|
|
1262
|
+
decorators_1.requiresSigner,
|
|
1263
|
+
__metadata("design:type", Function),
|
|
1264
|
+
__metadata("design:paramtypes", [String, Array, Array, String, String, Number, Object, Object]),
|
|
1265
|
+
__metadata("design:returntype", Promise)
|
|
1266
|
+
], EscrowClient.prototype, "createBulkPayoutTransaction", null);
|
|
1192
1267
|
/**
|
|
1193
1268
|
* ## Introduction
|
|
1194
1269
|
*
|
|
@@ -1216,7 +1291,7 @@ __decorate([
|
|
|
1216
1291
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1217
1292
|
*
|
|
1218
1293
|
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1219
|
-
*
|
|
1294
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
1220
1295
|
* });
|
|
1221
1296
|
* ```
|
|
1222
1297
|
*/
|
|
@@ -1261,7 +1336,6 @@ class EscrowUtils {
|
|
|
1261
1336
|
* AVALANCHE_TESTNET = 43113,
|
|
1262
1337
|
* CELO = 42220,
|
|
1263
1338
|
* CELO_ALFAJORES = 44787,
|
|
1264
|
-
* = 1273227453,
|
|
1265
1339
|
* LOCALHOST = 1338,
|
|
1266
1340
|
* }
|
|
1267
1341
|
* ```
|