@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/src/escrow.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import {
|
|
3
|
+
ERC20,
|
|
4
|
+
ERC20__factory,
|
|
3
5
|
Escrow,
|
|
4
6
|
EscrowFactory,
|
|
5
7
|
EscrowFactory__factory,
|
|
@@ -7,10 +9,10 @@ import {
|
|
|
7
9
|
HMToken,
|
|
8
10
|
HMToken__factory,
|
|
9
11
|
} from '@human-protocol/core/typechain-types';
|
|
10
|
-
import { ContractRunner, EventLog, Overrides, ethers } from 'ethers';
|
|
12
|
+
import { ContractRunner, EventLog, Overrides, Signer, ethers } from 'ethers';
|
|
11
13
|
import gqlFetch from 'graphql-request';
|
|
12
14
|
import { BaseEthersClient } from './base';
|
|
13
|
-
import {
|
|
15
|
+
import { ESCROW_BULK_PAYOUT_MAX_ITEMS, NETWORKS } from './constants';
|
|
14
16
|
import { requiresSigner } from './decorators';
|
|
15
17
|
import { ChainId, OrderDirection } from './enums';
|
|
16
18
|
import {
|
|
@@ -31,6 +33,7 @@ import {
|
|
|
31
33
|
ErrorProviderDoesNotExist,
|
|
32
34
|
ErrorRecipientAndAmountsMustBeSameLength,
|
|
33
35
|
ErrorRecipientCannotBeEmptyArray,
|
|
36
|
+
ErrorTooManyRecipients,
|
|
34
37
|
ErrorTotalFeeMustBeLessThanHundred,
|
|
35
38
|
ErrorTransferEventNotFoundInTransactionLogs,
|
|
36
39
|
ErrorUnsupportedChainID,
|
|
@@ -45,25 +48,31 @@ import {
|
|
|
45
48
|
StatusEvent,
|
|
46
49
|
} from './graphql';
|
|
47
50
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
48
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
EscrowCancel,
|
|
53
|
+
EscrowStatus,
|
|
54
|
+
EscrowWithdraw,
|
|
55
|
+
NetworkData,
|
|
56
|
+
TransactionLikeWithNonce,
|
|
57
|
+
} from './types';
|
|
49
58
|
import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
50
59
|
|
|
51
60
|
/**
|
|
52
61
|
* ## Introduction
|
|
53
62
|
*
|
|
54
|
-
* This client enables
|
|
63
|
+
* This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
|
|
55
64
|
*
|
|
56
65
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
57
66
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
58
67
|
*
|
|
59
68
|
* ```ts
|
|
60
|
-
* static async build(runner: ContractRunner)
|
|
69
|
+
* static async build(runner: ContractRunner): Promise<EscrowClient>;
|
|
61
70
|
* ```
|
|
62
71
|
*
|
|
63
72
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
64
73
|
*
|
|
65
|
-
* - **Signer**: when the user wants to use this model
|
|
66
|
-
* - **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.
|
|
67
76
|
*
|
|
68
77
|
* ## Installation
|
|
69
78
|
*
|
|
@@ -81,21 +90,21 @@ import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
|
81
90
|
*
|
|
82
91
|
* ### Signer
|
|
83
92
|
*
|
|
84
|
-
* **Using private key(backend)**
|
|
93
|
+
* **Using private key (backend)**
|
|
85
94
|
*
|
|
86
95
|
* ```ts
|
|
87
96
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
88
97
|
* import { Wallet, providers } from 'ethers';
|
|
89
98
|
*
|
|
90
99
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
91
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
100
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
92
101
|
*
|
|
93
102
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
94
103
|
* const signer = new Wallet(privateKey, provider);
|
|
95
104
|
* const escrowClient = await EscrowClient.build(signer);
|
|
96
105
|
* ```
|
|
97
106
|
*
|
|
98
|
-
* **Using Wagmi(frontend)**
|
|
107
|
+
* **Using Wagmi (frontend)**
|
|
99
108
|
*
|
|
100
109
|
* ```ts
|
|
101
110
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -124,7 +133,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
124
133
|
* **EscrowClient constructor**
|
|
125
134
|
*
|
|
126
135
|
* @param {ContractRunner} runner The Runner object to interact with the Ethereum network
|
|
127
|
-
* @param {NetworkData}
|
|
136
|
+
* @param {NetworkData} networkData The network information required to connect to the Escrow contract
|
|
128
137
|
*/
|
|
129
138
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
130
139
|
super(runner, networkData);
|
|
@@ -144,7 +153,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
144
153
|
* @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
|
|
145
154
|
* @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
|
|
146
155
|
*/
|
|
147
|
-
public static async build(runner: ContractRunner) {
|
|
156
|
+
public static async build(runner: ContractRunner): Promise<EscrowClient> {
|
|
148
157
|
if (!runner.provider) {
|
|
149
158
|
throw ErrorProviderDoesNotExist;
|
|
150
159
|
}
|
|
@@ -177,11 +186,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
177
186
|
/**
|
|
178
187
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
179
188
|
*
|
|
180
|
-
* @param {string} tokenAddress Token address to use for
|
|
189
|
+
* @param {string} tokenAddress Token address to use for payouts.
|
|
181
190
|
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
182
191
|
* @param {string} jobRequesterId Job Requester Id
|
|
183
192
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
184
|
-
* @returns {Promise<string>}
|
|
193
|
+
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
185
194
|
*
|
|
186
195
|
*
|
|
187
196
|
* **Code example**
|
|
@@ -193,7 +202,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
193
202
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
194
203
|
*
|
|
195
204
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
196
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
205
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
197
206
|
*
|
|
198
207
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
199
208
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -266,7 +275,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
266
275
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
267
276
|
*
|
|
268
277
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
269
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
278
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
270
279
|
*
|
|
271
280
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
272
281
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -277,10 +286,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
277
286
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
278
287
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
279
288
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
280
|
-
* recordingOracleFee:
|
|
281
|
-
* reputationOracleFee:
|
|
282
|
-
* exchangeOracleFee:
|
|
283
|
-
* manifestUrl: '
|
|
289
|
+
* recordingOracleFee: BigInt('10'),
|
|
290
|
+
* reputationOracleFee: BigInt('10'),
|
|
291
|
+
* exchangeOracleFee: BigInt('10'),
|
|
292
|
+
* manifestUrl: 'http://localhost/manifest.json',
|
|
284
293
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
285
294
|
* };
|
|
286
295
|
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
@@ -370,69 +379,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
370
379
|
}
|
|
371
380
|
}
|
|
372
381
|
|
|
373
|
-
/**
|
|
374
|
-
* This function creates and sets up an escrow.
|
|
375
|
-
*
|
|
376
|
-
* @param {string} tokenAddress Token address to use for pay outs.
|
|
377
|
-
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
378
|
-
* @param {string} jobRequesterId Job Requester Id
|
|
379
|
-
* @param {IEscrowConfig} escrowConfig Configuration object with escrow settings.
|
|
380
|
-
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* **Code example**
|
|
384
|
-
*
|
|
385
|
-
* ```ts
|
|
386
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
387
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
388
|
-
*
|
|
389
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
390
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
391
|
-
*
|
|
392
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
393
|
-
* const signer = new Wallet(privateKey, provider);
|
|
394
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
395
|
-
*
|
|
396
|
-
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
397
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
398
|
-
* const jobRequesterId = "job-requester-id";
|
|
399
|
-
*
|
|
400
|
-
* const escrowConfig = {
|
|
401
|
-
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
402
|
-
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
403
|
-
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
404
|
-
* recordingOracleFee: bigint.from('10'),
|
|
405
|
-
* reputationOracleFee: bigint.from('10'),
|
|
406
|
-
* exchangeOracleFee: bigint.from('10'),
|
|
407
|
-
* manifestUrl: 'htttp://localhost/manifest.json',
|
|
408
|
-
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
409
|
-
* };
|
|
410
|
-
*
|
|
411
|
-
* const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig);
|
|
412
|
-
* ```
|
|
413
|
-
*/
|
|
414
|
-
@requiresSigner
|
|
415
|
-
async createAndSetupEscrow(
|
|
416
|
-
tokenAddress: string,
|
|
417
|
-
trustedHandlers: string[],
|
|
418
|
-
jobRequesterId: string,
|
|
419
|
-
escrowConfig: IEscrowConfig
|
|
420
|
-
): Promise<string> {
|
|
421
|
-
try {
|
|
422
|
-
const escrowAddress = await this.createEscrow(
|
|
423
|
-
tokenAddress,
|
|
424
|
-
trustedHandlers,
|
|
425
|
-
jobRequesterId
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
await this.setup(escrowAddress, escrowConfig);
|
|
429
|
-
|
|
430
|
-
return escrowAddress;
|
|
431
|
-
} catch (e) {
|
|
432
|
-
return throwError(e);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
382
|
/**
|
|
437
383
|
* This function adds funds of the chosen token to the escrow.
|
|
438
384
|
*
|
|
@@ -449,7 +395,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
449
395
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
450
396
|
*
|
|
451
397
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
452
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
398
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
453
399
|
*
|
|
454
400
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
455
401
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -497,10 +443,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
497
443
|
}
|
|
498
444
|
|
|
499
445
|
/**
|
|
500
|
-
* This function stores the results
|
|
446
|
+
* This function stores the results URL and hash.
|
|
501
447
|
*
|
|
502
448
|
* @param {string} escrowAddress Address of the escrow.
|
|
503
|
-
* @param {string} url Results file
|
|
449
|
+
* @param {string} url Results file URL.
|
|
504
450
|
* @param {string} hash Results file hash.
|
|
505
451
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
506
452
|
* @returns Returns void if successful. Throws error if any.
|
|
@@ -515,13 +461,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
515
461
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
516
462
|
*
|
|
517
463
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
518
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
464
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
519
465
|
*
|
|
520
466
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
521
467
|
* const signer = new Wallet(privateKey, provider);
|
|
522
468
|
* const escrowClient = await EscrowClient.build(signer);
|
|
523
469
|
*
|
|
524
|
-
* await
|
|
470
|
+
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
525
471
|
* ```
|
|
526
472
|
*/
|
|
527
473
|
@requiresSigner
|
|
@@ -579,7 +525,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
579
525
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
580
526
|
*
|
|
581
527
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
582
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
528
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
583
529
|
*
|
|
584
530
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
585
531
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -617,8 +563,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
617
563
|
* @param {string} escrowAddress Escrow address to payout.
|
|
618
564
|
* @param {string[]} recipients Array of recipient addresses.
|
|
619
565
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
620
|
-
* @param {string} finalResultsUrl Final results file
|
|
566
|
+
* @param {string} finalResultsUrl Final results file URL.
|
|
621
567
|
* @param {string} finalResultsHash Final results file hash.
|
|
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).
|
|
622
570
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
623
571
|
* @returns Returns void if successful. Throws error if any.
|
|
624
572
|
*
|
|
@@ -632,7 +580,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
632
580
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
633
581
|
*
|
|
634
582
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
635
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
583
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
636
584
|
*
|
|
637
585
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
638
586
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -641,9 +589,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
641
589
|
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
642
590
|
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
643
591
|
* const resultsUrl = 'http://localhost/results.json';
|
|
644
|
-
* const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
592
|
+
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
593
|
+
* const txId = 1;
|
|
645
594
|
*
|
|
646
|
-
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash);
|
|
595
|
+
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash, txId);
|
|
647
596
|
* ```
|
|
648
597
|
*/
|
|
649
598
|
@requiresSigner
|
|
@@ -653,70 +602,48 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
653
602
|
amounts: bigint[],
|
|
654
603
|
finalResultsUrl: string,
|
|
655
604
|
finalResultsHash: string,
|
|
605
|
+
txId: number,
|
|
606
|
+
forceComplete = false,
|
|
656
607
|
txOptions: Overrides = {}
|
|
657
608
|
): Promise<void> {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
if (amounts.length === 0) {
|
|
667
|
-
throw ErrorAmountsCannotBeEmptyArray;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if (recipients.length !== amounts.length) {
|
|
671
|
-
throw ErrorRecipientAndAmountsMustBeSameLength;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
recipients.forEach((recipient) => {
|
|
675
|
-
if (!ethers.isAddress(recipient)) {
|
|
676
|
-
throw new InvalidEthereumAddressError(recipient);
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
if (!finalResultsUrl) {
|
|
681
|
-
throw ErrorUrlIsEmptyString;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
if (!isValidUrl(finalResultsUrl)) {
|
|
685
|
-
throw ErrorInvalidUrl;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
if (!finalResultsHash) {
|
|
689
|
-
throw ErrorHashIsEmptyString;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const balance = await this.getBalance(escrowAddress);
|
|
693
|
-
|
|
694
|
-
let totalAmount = 0n;
|
|
695
|
-
amounts.forEach((amount) => {
|
|
696
|
-
totalAmount = totalAmount + amount;
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
if (balance < totalAmount) {
|
|
700
|
-
throw ErrorEscrowDoesNotHaveEnoughBalance;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
704
|
-
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
705
|
-
}
|
|
609
|
+
await this.ensureCorrectBulkPayoutInput(
|
|
610
|
+
escrowAddress,
|
|
611
|
+
recipients,
|
|
612
|
+
amounts,
|
|
613
|
+
finalResultsUrl,
|
|
614
|
+
finalResultsHash
|
|
615
|
+
);
|
|
706
616
|
|
|
707
617
|
try {
|
|
708
618
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
619
|
+
if (forceComplete) {
|
|
620
|
+
await (
|
|
621
|
+
await escrowContract[
|
|
622
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
623
|
+
](
|
|
624
|
+
recipients,
|
|
625
|
+
amounts,
|
|
626
|
+
finalResultsUrl,
|
|
627
|
+
finalResultsHash,
|
|
628
|
+
txId,
|
|
629
|
+
forceComplete,
|
|
630
|
+
txOptions
|
|
631
|
+
)
|
|
632
|
+
).wait();
|
|
633
|
+
} else {
|
|
634
|
+
await (
|
|
635
|
+
await escrowContract[
|
|
636
|
+
'bulkPayOut(address[],uint256[],string,string,uint256)'
|
|
637
|
+
](
|
|
638
|
+
recipients,
|
|
639
|
+
amounts,
|
|
640
|
+
finalResultsUrl,
|
|
641
|
+
finalResultsHash,
|
|
642
|
+
txId,
|
|
643
|
+
txOptions
|
|
644
|
+
)
|
|
645
|
+
).wait();
|
|
646
|
+
}
|
|
720
647
|
return;
|
|
721
648
|
} catch (e) {
|
|
722
649
|
return throwError(e);
|
|
@@ -740,7 +667,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
740
667
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
741
668
|
*
|
|
742
669
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
743
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
670
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
744
671
|
*
|
|
745
672
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
746
673
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -808,9 +735,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
808
735
|
}
|
|
809
736
|
|
|
810
737
|
/**
|
|
811
|
-
* This function
|
|
738
|
+
* This function adds an array of addresses to the trusted handlers list.
|
|
812
739
|
*
|
|
813
740
|
* @param {string} escrowAddress Address of the escrow.
|
|
741
|
+
* @param {string[]} trustedHandlers Array of addresses of trusted handlers to add.
|
|
814
742
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
815
743
|
* @returns Returns void if successful. Throws error if any.
|
|
816
744
|
*
|
|
@@ -824,21 +752,36 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
824
752
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
825
753
|
*
|
|
826
754
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
827
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
755
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
828
756
|
*
|
|
829
757
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
830
758
|
* const signer = new Wallet(privateKey, provider);
|
|
831
759
|
* const escrowClient = await EscrowClient.build(signer);
|
|
832
760
|
*
|
|
833
|
-
*
|
|
761
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
762
|
+
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
834
763
|
* ```
|
|
835
764
|
*/
|
|
836
765
|
@requiresSigner
|
|
837
|
-
async
|
|
766
|
+
async addTrustedHandlers(
|
|
767
|
+
escrowAddress: string,
|
|
768
|
+
trustedHandlers: string[],
|
|
769
|
+
txOptions: Overrides = {}
|
|
770
|
+
): Promise<void> {
|
|
838
771
|
if (!ethers.isAddress(escrowAddress)) {
|
|
839
772
|
throw ErrorInvalidEscrowAddressProvided;
|
|
840
773
|
}
|
|
841
774
|
|
|
775
|
+
if (trustedHandlers.length === 0) {
|
|
776
|
+
throw ErrorListOfHandlersCannotBeEmpty;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
trustedHandlers.forEach((trustedHandler) => {
|
|
780
|
+
if (!ethers.isAddress(trustedHandler)) {
|
|
781
|
+
throw new InvalidEthereumAddressError(trustedHandler);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
|
|
842
785
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
843
786
|
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
844
787
|
}
|
|
@@ -846,7 +789,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
846
789
|
try {
|
|
847
790
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
848
791
|
|
|
849
|
-
await (
|
|
792
|
+
await (
|
|
793
|
+
await escrowContract.addTrustedHandlers(trustedHandlers, txOptions)
|
|
794
|
+
).wait();
|
|
850
795
|
return;
|
|
851
796
|
} catch (e) {
|
|
852
797
|
return throwError(e);
|
|
@@ -854,53 +799,49 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
854
799
|
}
|
|
855
800
|
|
|
856
801
|
/**
|
|
857
|
-
* This function
|
|
802
|
+
* This function withdraws additional tokens in the escrow to the canceler.
|
|
858
803
|
*
|
|
859
|
-
* @param {string} escrowAddress Address of the escrow.
|
|
860
|
-
* @param {string
|
|
804
|
+
* @param {string} escrowAddress Address of the escrow to withdraw.
|
|
805
|
+
* @param {string} tokenAddress Address of the token to withdraw.
|
|
861
806
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
862
|
-
* @returns Returns
|
|
807
|
+
* @returns {EscrowWithdraw} Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.
|
|
863
808
|
*
|
|
864
809
|
*
|
|
865
810
|
* **Code example**
|
|
866
811
|
*
|
|
867
|
-
* > Only Job Launcher or trusted handler can call it.
|
|
812
|
+
* > Only Job Launcher or a trusted handler can call it.
|
|
868
813
|
*
|
|
869
814
|
* ```ts
|
|
870
|
-
* import { Wallet, providers } from 'ethers';
|
|
815
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
871
816
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
872
817
|
*
|
|
873
818
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
874
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
819
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
875
820
|
*
|
|
876
821
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
877
822
|
* const signer = new Wallet(privateKey, provider);
|
|
878
823
|
* const escrowClient = await EscrowClient.build(signer);
|
|
879
824
|
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
825
|
+
* await escrowClient.withdraw(
|
|
826
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
827
|
+
* '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
|
|
828
|
+
* );
|
|
882
829
|
* ```
|
|
883
830
|
*/
|
|
884
831
|
@requiresSigner
|
|
885
|
-
async
|
|
832
|
+
async withdraw(
|
|
886
833
|
escrowAddress: string,
|
|
887
|
-
|
|
834
|
+
tokenAddress: string,
|
|
888
835
|
txOptions: Overrides = {}
|
|
889
|
-
): Promise<
|
|
836
|
+
): Promise<EscrowWithdraw> {
|
|
890
837
|
if (!ethers.isAddress(escrowAddress)) {
|
|
891
838
|
throw ErrorInvalidEscrowAddressProvided;
|
|
892
839
|
}
|
|
893
840
|
|
|
894
|
-
if (
|
|
895
|
-
throw
|
|
841
|
+
if (!ethers.isAddress(tokenAddress)) {
|
|
842
|
+
throw ErrorInvalidTokenAddress;
|
|
896
843
|
}
|
|
897
844
|
|
|
898
|
-
trustedHandlers.forEach((trustedHandler) => {
|
|
899
|
-
if (!ethers.isAddress(trustedHandler)) {
|
|
900
|
-
throw new InvalidEthereumAddressError(trustedHandler);
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
|
|
904
845
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
905
846
|
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
906
847
|
}
|
|
@@ -908,20 +849,219 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
908
849
|
try {
|
|
909
850
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
910
851
|
|
|
911
|
-
await (
|
|
912
|
-
await escrowContract.
|
|
852
|
+
const transactionReceipt = await (
|
|
853
|
+
await escrowContract.withdraw(tokenAddress, txOptions)
|
|
913
854
|
).wait();
|
|
914
|
-
|
|
855
|
+
|
|
856
|
+
let amountTransferred: bigint | undefined = undefined;
|
|
857
|
+
|
|
858
|
+
const tokenContract: ERC20 = ERC20__factory.connect(
|
|
859
|
+
tokenAddress,
|
|
860
|
+
this.runner
|
|
861
|
+
);
|
|
862
|
+
if (transactionReceipt)
|
|
863
|
+
for (const log of transactionReceipt.logs) {
|
|
864
|
+
if (log.address === tokenAddress) {
|
|
865
|
+
const parsedLog = tokenContract.interface.parseLog({
|
|
866
|
+
topics: log.topics as string[],
|
|
867
|
+
data: log.data,
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
const from = parsedLog?.args[0];
|
|
871
|
+
if (parsedLog?.name === 'Transfer' && from === escrowAddress) {
|
|
872
|
+
amountTransferred = parsedLog?.args[2];
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
if (amountTransferred === undefined) {
|
|
879
|
+
throw ErrorTransferEventNotFoundInTransactionLogs;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const escrowWithdrawData: EscrowWithdraw = {
|
|
883
|
+
txHash: transactionReceipt?.hash || '',
|
|
884
|
+
tokenAddress,
|
|
885
|
+
amountWithdrawn: amountTransferred,
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
return escrowWithdrawData;
|
|
915
889
|
} catch (e) {
|
|
916
890
|
return throwError(e);
|
|
917
891
|
}
|
|
918
892
|
}
|
|
919
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
|
+
|
|
920
1060
|
/**
|
|
921
1061
|
* This function returns the balance for a specified escrow address.
|
|
922
1062
|
*
|
|
923
1063
|
* @param {string} escrowAddress Address of the escrow.
|
|
924
|
-
* @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.
|
|
925
1065
|
*
|
|
926
1066
|
* **Code example**
|
|
927
1067
|
*
|
|
@@ -932,7 +1072,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
932
1072
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
933
1073
|
*
|
|
934
1074
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
935
|
-
* const escrowClient = await EscrowClient.build(
|
|
1075
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
936
1076
|
*
|
|
937
1077
|
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
938
1078
|
* ```
|
|
@@ -949,7 +1089,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
949
1089
|
try {
|
|
950
1090
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
951
1091
|
|
|
952
|
-
|
|
1092
|
+
try {
|
|
1093
|
+
return await escrowContract.remainingFunds();
|
|
1094
|
+
} catch {
|
|
1095
|
+
// Use getBalance() method below if remainingFunds() is not available
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
return await escrowContract.getBalance();
|
|
953
1099
|
} catch (e) {
|
|
954
1100
|
return throwError(e);
|
|
955
1101
|
}
|
|
@@ -959,7 +1105,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
959
1105
|
* This function returns the manifest file hash.
|
|
960
1106
|
*
|
|
961
1107
|
* @param {string} escrowAddress Address of the escrow.
|
|
962
|
-
* @returns {string} Hash of the manifest file content.
|
|
1108
|
+
* @returns {Promise<string>} Hash of the manifest file content.
|
|
963
1109
|
*
|
|
964
1110
|
* **Code example**
|
|
965
1111
|
*
|
|
@@ -970,7 +1116,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
970
1116
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
971
1117
|
*
|
|
972
1118
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
973
|
-
* const escrowClient = await EscrowClient.build(
|
|
1119
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
974
1120
|
*
|
|
975
1121
|
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
976
1122
|
* ```
|
|
@@ -997,7 +1143,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
997
1143
|
* This function returns the manifest file URL.
|
|
998
1144
|
*
|
|
999
1145
|
* @param {string} escrowAddress Address of the escrow.
|
|
1000
|
-
* @returns {string} Url of the manifest.
|
|
1146
|
+
* @returns {Promise<string>} Url of the manifest.
|
|
1001
1147
|
*
|
|
1002
1148
|
* **Code example**
|
|
1003
1149
|
*
|
|
@@ -1008,7 +1154,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1008
1154
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1009
1155
|
*
|
|
1010
1156
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1011
|
-
* const escrowClient = await EscrowClient.build(
|
|
1157
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1012
1158
|
*
|
|
1013
1159
|
* const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1014
1160
|
* ```
|
|
@@ -1035,7 +1181,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1035
1181
|
* This function returns the results file URL.
|
|
1036
1182
|
*
|
|
1037
1183
|
* @param {string} escrowAddress Address of the escrow.
|
|
1038
|
-
* @returns {string} Results file url.
|
|
1184
|
+
* @returns {Promise<string>} Results file url.
|
|
1039
1185
|
*
|
|
1040
1186
|
* **Code example**
|
|
1041
1187
|
*
|
|
@@ -1046,7 +1192,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1046
1192
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1047
1193
|
*
|
|
1048
1194
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1049
|
-
* const escrowClient = await EscrowClient.build(
|
|
1195
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1050
1196
|
*
|
|
1051
1197
|
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1052
1198
|
* ```
|
|
@@ -1073,7 +1219,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1073
1219
|
* This function returns the intermediate results file URL.
|
|
1074
1220
|
*
|
|
1075
1221
|
* @param {string} escrowAddress Address of the escrow.
|
|
1076
|
-
* @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.
|
|
1077
1223
|
*
|
|
1078
1224
|
* **Code example**
|
|
1079
1225
|
*
|
|
@@ -1084,9 +1230,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1084
1230
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1085
1231
|
*
|
|
1086
1232
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1087
|
-
* const escrowClient = await EscrowClient.build(
|
|
1233
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1088
1234
|
*
|
|
1089
|
-
* const
|
|
1235
|
+
* const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1090
1236
|
* ```
|
|
1091
1237
|
*/
|
|
1092
1238
|
async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
|
|
@@ -1102,7 +1248,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1102
1248
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1103
1249
|
|
|
1104
1250
|
return escrowContract.intermediateResultsUrl();
|
|
1105
|
-
} catch (e
|
|
1251
|
+
} catch (e) {
|
|
1106
1252
|
return throwError(e);
|
|
1107
1253
|
}
|
|
1108
1254
|
}
|
|
@@ -1111,7 +1257,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1111
1257
|
* This function returns the token address used for funding the escrow.
|
|
1112
1258
|
*
|
|
1113
1259
|
* @param {string} escrowAddress Address of the escrow.
|
|
1114
|
-
* @returns {string} Address of the token used to fund the escrow.
|
|
1260
|
+
* @returns {Promise<string>} Address of the token used to fund the escrow.
|
|
1115
1261
|
*
|
|
1116
1262
|
* **Code example**
|
|
1117
1263
|
*
|
|
@@ -1122,7 +1268,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1122
1268
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1123
1269
|
*
|
|
1124
1270
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1125
|
-
* const escrowClient = await EscrowClient.build(
|
|
1271
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1126
1272
|
*
|
|
1127
1273
|
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1128
1274
|
* ```
|
|
@@ -1149,7 +1295,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1149
1295
|
* This function returns the current status of the escrow.
|
|
1150
1296
|
*
|
|
1151
1297
|
* @param {string} escrowAddress Address of the escrow.
|
|
1152
|
-
* @returns {EscrowStatus} Current status of the escrow.
|
|
1298
|
+
* @returns {Promise<EscrowStatus>} Current status of the escrow.
|
|
1153
1299
|
*
|
|
1154
1300
|
* **Code example**
|
|
1155
1301
|
*
|
|
@@ -1160,7 +1306,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1160
1306
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1161
1307
|
*
|
|
1162
1308
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1163
|
-
* const escrowClient = await EscrowClient.build(
|
|
1309
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1164
1310
|
*
|
|
1165
1311
|
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1166
1312
|
* ```
|
|
@@ -1187,7 +1333,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1187
1333
|
* This function returns the recording oracle address for a given escrow.
|
|
1188
1334
|
*
|
|
1189
1335
|
* @param {string} escrowAddress Address of the escrow.
|
|
1190
|
-
* @returns {string} Address of the Recording Oracle.
|
|
1336
|
+
* @returns {Promise<string>} Address of the Recording Oracle.
|
|
1191
1337
|
*
|
|
1192
1338
|
* **Code example**
|
|
1193
1339
|
*
|
|
@@ -1198,7 +1344,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1198
1344
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1199
1345
|
*
|
|
1200
1346
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1201
|
-
* const escrowClient = await EscrowClient.build(
|
|
1347
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1202
1348
|
*
|
|
1203
1349
|
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1204
1350
|
* ```
|
|
@@ -1216,7 +1362,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1216
1362
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1217
1363
|
|
|
1218
1364
|
return escrowContract.recordingOracle();
|
|
1219
|
-
} catch (e
|
|
1365
|
+
} catch (e) {
|
|
1220
1366
|
return throwError(e);
|
|
1221
1367
|
}
|
|
1222
1368
|
}
|
|
@@ -1225,7 +1371,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1225
1371
|
* This function returns the job launcher address for a given escrow.
|
|
1226
1372
|
*
|
|
1227
1373
|
* @param {string} escrowAddress Address of the escrow.
|
|
1228
|
-
* @returns {string} Address of the Job Launcher.
|
|
1374
|
+
* @returns {Promise<string>} Address of the Job Launcher.
|
|
1229
1375
|
*
|
|
1230
1376
|
* **Code example**
|
|
1231
1377
|
*
|
|
@@ -1236,7 +1382,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1236
1382
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1237
1383
|
*
|
|
1238
1384
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1239
|
-
* const escrowClient = await EscrowClient.build(
|
|
1385
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1240
1386
|
*
|
|
1241
1387
|
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1242
1388
|
* ```
|
|
@@ -1254,7 +1400,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1254
1400
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1255
1401
|
|
|
1256
1402
|
return escrowContract.launcher();
|
|
1257
|
-
} catch (e
|
|
1403
|
+
} catch (e) {
|
|
1258
1404
|
return throwError(e);
|
|
1259
1405
|
}
|
|
1260
1406
|
}
|
|
@@ -1263,7 +1409,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1263
1409
|
* This function returns the reputation oracle address for a given escrow.
|
|
1264
1410
|
*
|
|
1265
1411
|
* @param {string} escrowAddress Address of the escrow.
|
|
1266
|
-
* @returns {
|
|
1412
|
+
* @returns {Promise<string>} Address of the Reputation Oracle.
|
|
1267
1413
|
*
|
|
1268
1414
|
* **Code example**
|
|
1269
1415
|
*
|
|
@@ -1274,7 +1420,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1274
1420
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1275
1421
|
*
|
|
1276
1422
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1277
|
-
* const escrowClient = await EscrowClient.build(
|
|
1423
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1278
1424
|
*
|
|
1279
1425
|
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1280
1426
|
* ```
|
|
@@ -1292,7 +1438,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1292
1438
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1293
1439
|
|
|
1294
1440
|
return escrowContract.reputationOracle();
|
|
1295
|
-
} catch (e
|
|
1441
|
+
} catch (e) {
|
|
1296
1442
|
return throwError(e);
|
|
1297
1443
|
}
|
|
1298
1444
|
}
|
|
@@ -1301,7 +1447,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1301
1447
|
* This function returns the exchange oracle address for a given escrow.
|
|
1302
1448
|
*
|
|
1303
1449
|
* @param {string} escrowAddress Address of the escrow.
|
|
1304
|
-
* @returns {
|
|
1450
|
+
* @returns {Promise<string>} Address of the Exchange Oracle.
|
|
1305
1451
|
*
|
|
1306
1452
|
* **Code example**
|
|
1307
1453
|
*
|
|
@@ -1312,7 +1458,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1312
1458
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1313
1459
|
*
|
|
1314
1460
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1315
|
-
* const escrowClient = await EscrowClient.build(
|
|
1461
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1316
1462
|
*
|
|
1317
1463
|
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1318
1464
|
* ```
|
|
@@ -1330,7 +1476,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1330
1476
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1331
1477
|
|
|
1332
1478
|
return escrowContract.exchangeOracle();
|
|
1333
|
-
} catch (e
|
|
1479
|
+
} catch (e) {
|
|
1334
1480
|
return throwError(e);
|
|
1335
1481
|
}
|
|
1336
1482
|
}
|
|
@@ -1339,7 +1485,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1339
1485
|
* This function returns the escrow factory address for a given escrow.
|
|
1340
1486
|
*
|
|
1341
1487
|
* @param {string} escrowAddress Address of the escrow.
|
|
1342
|
-
* @returns {
|
|
1488
|
+
* @returns {Promise<string>} Address of the escrow factory.
|
|
1343
1489
|
*
|
|
1344
1490
|
* **Code example**
|
|
1345
1491
|
*
|
|
@@ -1350,7 +1496,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1350
1496
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1351
1497
|
*
|
|
1352
1498
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1353
|
-
* const escrowClient = await EscrowClient.build(
|
|
1499
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
1354
1500
|
*
|
|
1355
1501
|
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1356
1502
|
* ```
|
|
@@ -1368,12 +1514,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1368
1514
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1369
1515
|
|
|
1370
1516
|
return escrowContract.escrowFactory();
|
|
1371
|
-
} catch (e
|
|
1517
|
+
} catch (e) {
|
|
1372
1518
|
return throwError(e);
|
|
1373
1519
|
}
|
|
1374
1520
|
}
|
|
1375
1521
|
}
|
|
1376
|
-
|
|
1377
1522
|
/**
|
|
1378
1523
|
* ## Introduction
|
|
1379
1524
|
*
|
|
@@ -1401,7 +1546,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1401
1546
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1402
1547
|
*
|
|
1403
1548
|
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1404
|
-
*
|
|
1549
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
1405
1550
|
* });
|
|
1406
1551
|
* ```
|
|
1407
1552
|
*/
|
|
@@ -1446,7 +1591,6 @@ export class EscrowUtils {
|
|
|
1446
1591
|
* AVALANCHE_TESTNET = 43113,
|
|
1447
1592
|
* CELO = 42220,
|
|
1448
1593
|
* CELO_ALFAJORES = 44787,
|
|
1449
|
-
* = 1273227453,
|
|
1450
1594
|
* LOCALHOST = 1338,
|
|
1451
1595
|
* }
|
|
1452
1596
|
* ```
|