@human-protocol/sdk 1.1.13 → 1.1.15
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/encryption.d.ts +245 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +245 -29
- package/dist/escrow.d.ts +731 -117
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +734 -120
- package/dist/kvstore.d.ts +138 -15
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +138 -15
- package/dist/staking.d.ts +324 -54
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +324 -54
- package/dist/statistics.d.ts +266 -16
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +266 -16
- package/dist/storage.d.ts +155 -16
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +155 -16
- package/package.json +17 -1
- package/src/encryption.ts +246 -29
- package/src/escrow.ts +734 -120
- package/src/kvstore.ts +138 -15
- package/src/staking.ts +324 -54
- package/src/statistics.ts +266 -16
- package/src/storage.ts +156 -17
package/src/escrow.ts
CHANGED
|
@@ -47,6 +47,75 @@ import {
|
|
|
47
47
|
GET_ESCROW_BY_ADDRESS_QUERY,
|
|
48
48
|
} from './graphql';
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* ## Introduction
|
|
52
|
+
*
|
|
53
|
+
* This client enables to perform actions on Escrow contracts and obtain information from both the contracts and subgraph.
|
|
54
|
+
*
|
|
55
|
+
* Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
|
|
56
|
+
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* static async build(signerOrProvider: Signer | Provider);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
63
|
+
*
|
|
64
|
+
* - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
|
|
65
|
+
* - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
|
|
66
|
+
*
|
|
67
|
+
* ## Installation
|
|
68
|
+
*
|
|
69
|
+
* ### npm
|
|
70
|
+
* ```bash
|
|
71
|
+
* npm install @human-protocol/sdk
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* ### yarn
|
|
75
|
+
* ```bash
|
|
76
|
+
* yarn install @human-protocol/sdk
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* ## Code example
|
|
80
|
+
*
|
|
81
|
+
* ### Signer
|
|
82
|
+
*
|
|
83
|
+
* **Using private key(backend)**
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
87
|
+
* import { Wallet, providers } from 'ethers';
|
|
88
|
+
*
|
|
89
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
90
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
91
|
+
*
|
|
92
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
93
|
+
* const signer = new Wallet(privateKey, provider);
|
|
94
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* **Using Wagmi(frontend)**
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { useSigner, useChainId } from 'wagmi';
|
|
101
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
102
|
+
*
|
|
103
|
+
* const { data: signer } = useSigner();
|
|
104
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* ### Provider
|
|
108
|
+
*
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
111
|
+
* import { providers } from 'ethers';
|
|
112
|
+
*
|
|
113
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
114
|
+
*
|
|
115
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
116
|
+
* const escrowClient = await EscrowClient.build(provider);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
50
119
|
export class EscrowClient {
|
|
51
120
|
private escrowFactoryContract: EscrowFactory;
|
|
52
121
|
private escrowContract?: Escrow;
|
|
@@ -56,8 +125,8 @@ export class EscrowClient {
|
|
|
56
125
|
/**
|
|
57
126
|
* **EscrowClient constructor**
|
|
58
127
|
*
|
|
59
|
-
* @param {Signer | Provider} signerOrProvider
|
|
60
|
-
* @param {NetworkData} network
|
|
128
|
+
* @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
|
|
129
|
+
* @param {NetworkData} network The network information required to connect to the Escrow contract
|
|
61
130
|
*/
|
|
62
131
|
constructor(signerOrProvider: Signer | Provider, network: NetworkData) {
|
|
63
132
|
this.escrowFactoryContract = EscrowFactory__factory.connect(
|
|
@@ -71,10 +140,10 @@ export class EscrowClient {
|
|
|
71
140
|
/**
|
|
72
141
|
* Creates an instance of EscrowClient from a Signer or Provider.
|
|
73
142
|
*
|
|
74
|
-
* @param {Signer | Provider} signerOrProvider
|
|
75
|
-
* @returns {Promise<EscrowClient>}
|
|
76
|
-
* @throws {ErrorProviderDoesNotExist}
|
|
77
|
-
* @throws {ErrorUnsupportedChainID}
|
|
143
|
+
* @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
|
|
144
|
+
* @returns {Promise<EscrowClient>} An instance of EscrowClient
|
|
145
|
+
* @throws {ErrorProviderDoesNotExist} Thrown if the provider does not exist for the provided Signer
|
|
146
|
+
* @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
|
|
78
147
|
*/
|
|
79
148
|
public static async build(signerOrProvider: Signer | Provider) {
|
|
80
149
|
let network: Network;
|
|
@@ -99,12 +168,34 @@ export class EscrowClient {
|
|
|
99
168
|
}
|
|
100
169
|
|
|
101
170
|
/**
|
|
102
|
-
*
|
|
171
|
+
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
103
172
|
*
|
|
104
|
-
* @param {string} tokenAddress
|
|
105
|
-
* @param {string[]} trustedHandlers
|
|
106
|
-
* @
|
|
107
|
-
* @
|
|
173
|
+
* @param {string} tokenAddress Token address to use for pay outs.
|
|
174
|
+
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
175
|
+
* @param {string} jobRequesterId Job Requester Id
|
|
176
|
+
* @returns {Promise<string>} Return the address of the escrow created.
|
|
177
|
+
*
|
|
178
|
+
*
|
|
179
|
+
* **Code example**
|
|
180
|
+
*
|
|
181
|
+
* > Need to have available stake.
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { Wallet, providers } from 'ethers';
|
|
185
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
186
|
+
*
|
|
187
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
188
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
189
|
+
*
|
|
190
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
191
|
+
* const signer = new Wallet(privateKey, provider);
|
|
192
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
193
|
+
*
|
|
194
|
+
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
195
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
196
|
+
* const jobRequesterId = "job-requester-id";
|
|
197
|
+
* const escrowAddress = await escrowClient.createEscrow(tokenAddress, trustedHandlers, jobRequesterId);
|
|
198
|
+
* ```
|
|
108
199
|
*/
|
|
109
200
|
@requiresSigner
|
|
110
201
|
public async createEscrow(
|
|
@@ -146,12 +237,41 @@ export class EscrowClient {
|
|
|
146
237
|
}
|
|
147
238
|
|
|
148
239
|
/**
|
|
149
|
-
*
|
|
240
|
+
* This function sets up the parameters of the escrow.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} escrowAddress Address of the escrow to set up.
|
|
243
|
+
* @param {IEscrowConfig} escrowConfig Escrow configuration parameters.
|
|
244
|
+
* @returns Returns void if successful. Throws error if any.
|
|
245
|
+
*
|
|
246
|
+
*
|
|
247
|
+
* **Code example**
|
|
150
248
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
249
|
+
* > Only Job Launcher or a trusted handler can call it.
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { Wallet, providers } from 'ethers';
|
|
253
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
254
|
+
*
|
|
255
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
256
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
257
|
+
*
|
|
258
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
259
|
+
* const signer = new Wallet(privateKey, provider);
|
|
260
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
261
|
+
*
|
|
262
|
+
* const escrowAddress = '0x62dD51230A30401C455c8398d06F85e4EaB6309f';
|
|
263
|
+
* const escrowConfig = {
|
|
264
|
+
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
265
|
+
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
266
|
+
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
267
|
+
* recordingOracleFee: BigNumber.from('10'),
|
|
268
|
+
* reputationOracleFee: BigNumber.from('10'),
|
|
269
|
+
* exchangeOracleFee: BigNumber.from('10'),
|
|
270
|
+
* manifestUrl: 'htttp://localhost/manifest.json',
|
|
271
|
+
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
272
|
+
* };
|
|
273
|
+
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
274
|
+
* ```
|
|
155
275
|
*/
|
|
156
276
|
@requiresSigner
|
|
157
277
|
async setup(
|
|
@@ -238,14 +358,45 @@ export class EscrowClient {
|
|
|
238
358
|
}
|
|
239
359
|
|
|
240
360
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* @param {string}
|
|
245
|
-
* @param {string
|
|
246
|
-
* @param {IEscrowConfig} escrowConfig
|
|
247
|
-
* @returns {Promise<string>}
|
|
248
|
-
*
|
|
361
|
+
* This function creates and sets up an escrow.
|
|
362
|
+
*
|
|
363
|
+
* @param {string} tokenAddress Token address to use for pay outs.
|
|
364
|
+
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
365
|
+
* @param {string} jobRequesterId Job Requester Id
|
|
366
|
+
* @param {IEscrowConfig} escrowConfig Configuration object with escrow settings.
|
|
367
|
+
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
368
|
+
*
|
|
369
|
+
*
|
|
370
|
+
* **Code example**
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
374
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
375
|
+
*
|
|
376
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
377
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
378
|
+
*
|
|
379
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
380
|
+
* const signer = new Wallet(privateKey, provider);
|
|
381
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
382
|
+
*
|
|
383
|
+
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
384
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
385
|
+
* const jobRequesterId = "job-requester-id";
|
|
386
|
+
*
|
|
387
|
+
* const escrowConfig = {
|
|
388
|
+
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
389
|
+
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
390
|
+
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
391
|
+
* recordingOracleFee: BigNumber.from('10'),
|
|
392
|
+
* reputationOracleFee: BigNumber.from('10'),
|
|
393
|
+
* exchangeOracleFee: BigNumber.from('10'),
|
|
394
|
+
* manifestUrl: 'htttp://localhost/manifest.json',
|
|
395
|
+
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
396
|
+
* };
|
|
397
|
+
*
|
|
398
|
+
* const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig);
|
|
399
|
+
* ```
|
|
249
400
|
*/
|
|
250
401
|
@requiresSigner
|
|
251
402
|
async createAndSetupEscrow(
|
|
@@ -270,12 +421,29 @@ export class EscrowClient {
|
|
|
270
421
|
}
|
|
271
422
|
|
|
272
423
|
/**
|
|
273
|
-
*
|
|
424
|
+
* This function adds funds of the chosen token to the escrow.
|
|
425
|
+
*
|
|
426
|
+
* @param {string} escrowAddress Address of the escrow to fund.
|
|
427
|
+
* @param {BigNumber} amount Amount to be added as funds.
|
|
428
|
+
* @returns Returns void if successful. Throws error if any.
|
|
429
|
+
*
|
|
430
|
+
*
|
|
431
|
+
* **Code example**
|
|
432
|
+
*
|
|
433
|
+
* ```ts
|
|
434
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
435
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
436
|
+
*
|
|
437
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
438
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
439
|
+
*
|
|
440
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
441
|
+
* const signer = new Wallet(privateKey, provider);
|
|
442
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
274
443
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @throws {Error} - An error object if an error occurred.
|
|
444
|
+
* const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
445
|
+
* await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
|
|
446
|
+
* ```
|
|
279
447
|
*/
|
|
280
448
|
@requiresSigner
|
|
281
449
|
async fund(escrowAddress: string, amount: BigNumber): Promise<void> {
|
|
@@ -313,14 +481,31 @@ export class EscrowClient {
|
|
|
313
481
|
}
|
|
314
482
|
|
|
315
483
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* @param {string} escrowAddress
|
|
319
|
-
* @param {string}
|
|
320
|
-
* @param {string}
|
|
321
|
-
* @
|
|
322
|
-
*
|
|
323
|
-
*
|
|
484
|
+
* This function stores the results url and hash.
|
|
485
|
+
*
|
|
486
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
487
|
+
* @param {string} url Results file url.
|
|
488
|
+
* @param {string} hash Results file hash.
|
|
489
|
+
* @returns Returns void if successful. Throws error if any.
|
|
490
|
+
*
|
|
491
|
+
*
|
|
492
|
+
* **Code example**
|
|
493
|
+
*
|
|
494
|
+
* > Only Recording Oracle or a trusted handler can call it.
|
|
495
|
+
*
|
|
496
|
+
* ```ts
|
|
497
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
498
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
499
|
+
*
|
|
500
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
501
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
502
|
+
*
|
|
503
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
504
|
+
* const signer = new Wallet(privateKey, provider);
|
|
505
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
506
|
+
*
|
|
507
|
+
* await storeResults.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079');
|
|
508
|
+
* ```
|
|
324
509
|
*/
|
|
325
510
|
@requiresSigner
|
|
326
511
|
async storeResults(
|
|
@@ -362,11 +547,29 @@ export class EscrowClient {
|
|
|
362
547
|
}
|
|
363
548
|
|
|
364
549
|
/**
|
|
365
|
-
*
|
|
550
|
+
* This function sets the status of an escrow to completed.
|
|
551
|
+
*
|
|
552
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
553
|
+
* @returns Returns void if successful. Throws error if any.
|
|
366
554
|
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
555
|
+
*
|
|
556
|
+
* **Code example**
|
|
557
|
+
*
|
|
558
|
+
* > Only Recording Oracle or a trusted handler can call it.
|
|
559
|
+
*
|
|
560
|
+
* ```ts
|
|
561
|
+
* import { Wallet, providers } from 'ethers';
|
|
562
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
563
|
+
*
|
|
564
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
565
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
566
|
+
*
|
|
567
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
568
|
+
* const signer = new Wallet(privateKey, provider);
|
|
569
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
570
|
+
*
|
|
571
|
+
* await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
572
|
+
* ```
|
|
370
573
|
*/
|
|
371
574
|
@requiresSigner
|
|
372
575
|
async complete(escrowAddress: string): Promise<void> {
|
|
@@ -391,15 +594,38 @@ export class EscrowClient {
|
|
|
391
594
|
}
|
|
392
595
|
|
|
393
596
|
/**
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* @param {string} escrowAddress
|
|
397
|
-
* @param {string[]} recipients
|
|
398
|
-
* @param {BigNumber[]} amounts
|
|
399
|
-
* @param {string} finalResultsUrl
|
|
400
|
-
* @param {string} finalResultsHash
|
|
401
|
-
* @returns
|
|
402
|
-
*
|
|
597
|
+
* This function pays out the amounts specified to the workers and sets the URL of the final results file.
|
|
598
|
+
*
|
|
599
|
+
* @param {string} escrowAddress Escrow address to payout.
|
|
600
|
+
* @param {string[]} recipients Array of recipient addresses.
|
|
601
|
+
* @param {BigNumber[]} amounts Array of amounts the recipients will receive.
|
|
602
|
+
* @param {string} finalResultsUrl Final results file url.
|
|
603
|
+
* @param {string} finalResultsHash Final results file hash.
|
|
604
|
+
* @returns Returns void if successful. Throws error if any.
|
|
605
|
+
*
|
|
606
|
+
*
|
|
607
|
+
* **Code example**
|
|
608
|
+
*
|
|
609
|
+
* > Only Reputation Oracle or a trusted handler can call it.
|
|
610
|
+
*
|
|
611
|
+
* ```ts
|
|
612
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
613
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
614
|
+
*
|
|
615
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
616
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
617
|
+
*
|
|
618
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
619
|
+
* const signer = new Wallet(privateKey, provider);
|
|
620
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
621
|
+
*
|
|
622
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
623
|
+
* const amounts = [ethers.utils.parseUnits(5, 'ether'), ethers.utils.parseUnits(10, 'ether')];
|
|
624
|
+
* const resultsUrl = 'http://localhost/results.json';
|
|
625
|
+
* const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
626
|
+
*
|
|
627
|
+
* await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash);
|
|
628
|
+
* ```
|
|
403
629
|
*/
|
|
404
630
|
@requiresSigner
|
|
405
631
|
async bulkPayOut(
|
|
@@ -478,11 +704,29 @@ export class EscrowClient {
|
|
|
478
704
|
}
|
|
479
705
|
|
|
480
706
|
/**
|
|
481
|
-
*
|
|
707
|
+
* This function cancels the specified escrow and sends the balance to the canceler.
|
|
708
|
+
*
|
|
709
|
+
* @param {string} escrowAddress Address of the escrow to cancel.
|
|
710
|
+
* @returns {EscrowCancel} Returns the escrow cancellation data including transaction hash and refunded amount. Throws error if any.
|
|
711
|
+
*
|
|
712
|
+
*
|
|
713
|
+
* **Code example**
|
|
714
|
+
*
|
|
715
|
+
* > Only Job Launcher or a trusted handler can call it.
|
|
482
716
|
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
717
|
+
* ```ts
|
|
718
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
719
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
720
|
+
*
|
|
721
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
722
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
723
|
+
*
|
|
724
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
725
|
+
* const signer = new Wallet(privateKey, provider);
|
|
726
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
727
|
+
*
|
|
728
|
+
* await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
729
|
+
* ```
|
|
486
730
|
*/
|
|
487
731
|
@requiresSigner
|
|
488
732
|
async cancel(escrowAddress: string): Promise<EscrowCancel> {
|
|
@@ -538,11 +782,29 @@ export class EscrowClient {
|
|
|
538
782
|
}
|
|
539
783
|
|
|
540
784
|
/**
|
|
541
|
-
*
|
|
785
|
+
* This function cancels the specified escrow, sends the balance to the canceler and selfdestructs the escrow contract.
|
|
786
|
+
*
|
|
787
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
788
|
+
* @returns Returns void if successful. Throws error if any.
|
|
789
|
+
*
|
|
790
|
+
*
|
|
791
|
+
* **Code example**
|
|
792
|
+
*
|
|
793
|
+
* > Only Job Launcher or trusted handler can call it.
|
|
794
|
+
*
|
|
795
|
+
* ```ts
|
|
796
|
+
* import { Wallet, providers } from 'ethers';
|
|
797
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
798
|
+
*
|
|
799
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
800
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
801
|
+
*
|
|
802
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
803
|
+
* const signer = new Wallet(privateKey, provider);
|
|
804
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
542
805
|
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
* @throws {Error} - An error object if an error occurred.
|
|
806
|
+
* await escrowClient.abort('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
807
|
+
* ```
|
|
546
808
|
*/
|
|
547
809
|
@requiresSigner
|
|
548
810
|
async abort(escrowAddress: string): Promise<void> {
|
|
@@ -567,12 +829,31 @@ export class EscrowClient {
|
|
|
567
829
|
}
|
|
568
830
|
|
|
569
831
|
/**
|
|
570
|
-
*
|
|
832
|
+
* This function sets the status of an escrow to completed.
|
|
571
833
|
*
|
|
572
|
-
* @param {string} escrowAddress
|
|
573
|
-
* @param {string[]} trustedHandlers
|
|
574
|
-
* @returns
|
|
575
|
-
*
|
|
834
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
835
|
+
* @param {string[]} trustedHandlers Array of addresses of trusted handlers to add.
|
|
836
|
+
* @returns Returns void if successful. Throws error if any.
|
|
837
|
+
*
|
|
838
|
+
*
|
|
839
|
+
* **Code example**
|
|
840
|
+
*
|
|
841
|
+
* > Only Job Launcher or trusted handler can call it.
|
|
842
|
+
*
|
|
843
|
+
* ```ts
|
|
844
|
+
* import { Wallet, providers } from 'ethers';
|
|
845
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
846
|
+
*
|
|
847
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
848
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
849
|
+
*
|
|
850
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
851
|
+
* const signer = new Wallet(privateKey, provider);
|
|
852
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
853
|
+
*
|
|
854
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']
|
|
855
|
+
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
856
|
+
* ```
|
|
576
857
|
*/
|
|
577
858
|
@requiresSigner
|
|
578
859
|
async addTrustedHandlers(
|
|
@@ -610,11 +891,24 @@ export class EscrowClient {
|
|
|
610
891
|
}
|
|
611
892
|
|
|
612
893
|
/**
|
|
613
|
-
*
|
|
894
|
+
* This function returns the balance for a specified escrow address.
|
|
895
|
+
*
|
|
896
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
897
|
+
* @returns {BigNumber} Balance of the escrow in the token used to fund it.
|
|
898
|
+
*
|
|
899
|
+
* **Code example**
|
|
614
900
|
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
901
|
+
* ```ts
|
|
902
|
+
* import { providers } from 'ethers';
|
|
903
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
904
|
+
*
|
|
905
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
906
|
+
*
|
|
907
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
908
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
909
|
+
*
|
|
910
|
+
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
911
|
+
* ```
|
|
618
912
|
*/
|
|
619
913
|
async getBalance(escrowAddress: string): Promise<BigNumber> {
|
|
620
914
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -637,11 +931,24 @@ export class EscrowClient {
|
|
|
637
931
|
}
|
|
638
932
|
|
|
639
933
|
/**
|
|
640
|
-
*
|
|
934
|
+
* This function returns the manifest file hash.
|
|
935
|
+
*
|
|
936
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
937
|
+
* @returns {string} Hash of the manifest file content.
|
|
938
|
+
*
|
|
939
|
+
* **Code example**
|
|
641
940
|
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
941
|
+
* ```ts
|
|
942
|
+
* import { providers } from 'ethers';
|
|
943
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
944
|
+
*
|
|
945
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
946
|
+
*
|
|
947
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
948
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
949
|
+
*
|
|
950
|
+
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
951
|
+
* ```
|
|
645
952
|
*/
|
|
646
953
|
async getManifestHash(escrowAddress: string): Promise<string> {
|
|
647
954
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -664,11 +971,24 @@ export class EscrowClient {
|
|
|
664
971
|
}
|
|
665
972
|
|
|
666
973
|
/**
|
|
667
|
-
*
|
|
974
|
+
* This function returns the manifest file URL.
|
|
975
|
+
*
|
|
976
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
977
|
+
* @returns {string} Url of the manifest.
|
|
978
|
+
*
|
|
979
|
+
* **Code example**
|
|
668
980
|
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
981
|
+
* ```ts
|
|
982
|
+
* import { providers } from 'ethers';
|
|
983
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
984
|
+
*
|
|
985
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
986
|
+
*
|
|
987
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
988
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
989
|
+
*
|
|
990
|
+
* const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
991
|
+
* ```
|
|
672
992
|
*/
|
|
673
993
|
async getManifestUrl(escrowAddress: string): Promise<string> {
|
|
674
994
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -691,11 +1011,24 @@ export class EscrowClient {
|
|
|
691
1011
|
}
|
|
692
1012
|
|
|
693
1013
|
/**
|
|
694
|
-
*
|
|
1014
|
+
* This function returns the results file URL.
|
|
1015
|
+
*
|
|
1016
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1017
|
+
* @returns {string} Results file url.
|
|
1018
|
+
*
|
|
1019
|
+
* **Code example**
|
|
695
1020
|
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* import { providers } from 'ethers';
|
|
1023
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1024
|
+
*
|
|
1025
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1026
|
+
*
|
|
1027
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1028
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1029
|
+
*
|
|
1030
|
+
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1031
|
+
* ```
|
|
699
1032
|
*/
|
|
700
1033
|
async getResultsUrl(escrowAddress: string): Promise<string> {
|
|
701
1034
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -718,11 +1051,24 @@ export class EscrowClient {
|
|
|
718
1051
|
}
|
|
719
1052
|
|
|
720
1053
|
/**
|
|
721
|
-
*
|
|
1054
|
+
* This function returns the intermediate results file URL.
|
|
1055
|
+
*
|
|
1056
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1057
|
+
* @returns {string} Url of the file that store results from Recording Oracle.
|
|
722
1058
|
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
1059
|
+
* **Code example**
|
|
1060
|
+
*
|
|
1061
|
+
* ```ts
|
|
1062
|
+
* import { providers } from 'ethers';
|
|
1063
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1064
|
+
*
|
|
1065
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1066
|
+
*
|
|
1067
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1068
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1069
|
+
*
|
|
1070
|
+
* const intemediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1071
|
+
* ```
|
|
726
1072
|
*/
|
|
727
1073
|
async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
|
|
728
1074
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -745,11 +1091,24 @@ export class EscrowClient {
|
|
|
745
1091
|
}
|
|
746
1092
|
|
|
747
1093
|
/**
|
|
748
|
-
*
|
|
1094
|
+
* This function returns the token address used for funding the escrow.
|
|
1095
|
+
*
|
|
1096
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1097
|
+
* @returns {string} Address of the token used to fund the escrow.
|
|
749
1098
|
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
1099
|
+
* **Code example**
|
|
1100
|
+
*
|
|
1101
|
+
* ```ts
|
|
1102
|
+
* import { providers } from 'ethers';
|
|
1103
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1104
|
+
*
|
|
1105
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1106
|
+
*
|
|
1107
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1108
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1109
|
+
*
|
|
1110
|
+
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1111
|
+
* ```
|
|
753
1112
|
*/
|
|
754
1113
|
async getTokenAddress(escrowAddress: string): Promise<string> {
|
|
755
1114
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -772,11 +1131,24 @@ export class EscrowClient {
|
|
|
772
1131
|
}
|
|
773
1132
|
|
|
774
1133
|
/**
|
|
775
|
-
*
|
|
1134
|
+
* This function returns the current status of the escrow.
|
|
1135
|
+
*
|
|
1136
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1137
|
+
* @returns {EscrowStatus} Current status of the escrow.
|
|
776
1138
|
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
1139
|
+
* **Code example**
|
|
1140
|
+
*
|
|
1141
|
+
* ```ts
|
|
1142
|
+
* import { providers } from 'ethers';
|
|
1143
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1144
|
+
*
|
|
1145
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1146
|
+
*
|
|
1147
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1148
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1149
|
+
*
|
|
1150
|
+
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1151
|
+
* ```
|
|
780
1152
|
*/
|
|
781
1153
|
async getStatus(escrowAddress: string): Promise<EscrowStatus> {
|
|
782
1154
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -799,11 +1171,24 @@ export class EscrowClient {
|
|
|
799
1171
|
}
|
|
800
1172
|
|
|
801
1173
|
/**
|
|
802
|
-
*
|
|
1174
|
+
* This function returns the recording oracle address for a given escrow.
|
|
1175
|
+
*
|
|
1176
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1177
|
+
* @returns {string} Address of the Recording Oracle.
|
|
1178
|
+
*
|
|
1179
|
+
* **Code example**
|
|
1180
|
+
*
|
|
1181
|
+
* ```ts
|
|
1182
|
+
* import { providers } from 'ethers';
|
|
1183
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1184
|
+
*
|
|
1185
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1186
|
+
*
|
|
1187
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1188
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
803
1189
|
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
* @throws {Error} - An error object if an error occurred.
|
|
1190
|
+
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1191
|
+
* ```
|
|
807
1192
|
*/
|
|
808
1193
|
async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
|
|
809
1194
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -826,11 +1211,24 @@ export class EscrowClient {
|
|
|
826
1211
|
}
|
|
827
1212
|
|
|
828
1213
|
/**
|
|
829
|
-
*
|
|
1214
|
+
* This function returns the job launcher address for a given escrow.
|
|
830
1215
|
*
|
|
831
|
-
* @param {string} escrowAddress
|
|
832
|
-
* @returns {
|
|
833
|
-
*
|
|
1216
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1217
|
+
* @returns {string} Address of the Job Launcher.
|
|
1218
|
+
*
|
|
1219
|
+
* **Code example**
|
|
1220
|
+
*
|
|
1221
|
+
* ```ts
|
|
1222
|
+
* import { providers } from 'ethers';
|
|
1223
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1224
|
+
*
|
|
1225
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1226
|
+
*
|
|
1227
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1228
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1229
|
+
*
|
|
1230
|
+
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1231
|
+
* ```
|
|
834
1232
|
*/
|
|
835
1233
|
async getJobLauncherAddress(escrowAddress: string): Promise<string> {
|
|
836
1234
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -853,11 +1251,24 @@ export class EscrowClient {
|
|
|
853
1251
|
}
|
|
854
1252
|
|
|
855
1253
|
/**
|
|
856
|
-
*
|
|
1254
|
+
* This function returns the reputation oracle address for a given escrow.
|
|
1255
|
+
*
|
|
1256
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1257
|
+
* @returns {EscrowStatus} Address of the Reputation Oracle.
|
|
1258
|
+
*
|
|
1259
|
+
* **Code example**
|
|
1260
|
+
*
|
|
1261
|
+
* ```ts
|
|
1262
|
+
* import { providers } from 'ethers';
|
|
1263
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1264
|
+
*
|
|
1265
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1266
|
+
*
|
|
1267
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1268
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
857
1269
|
*
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
* @throws {Error} - An error object if an error occurred.
|
|
1270
|
+
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1271
|
+
* ```
|
|
861
1272
|
*/
|
|
862
1273
|
async getReputationOracleAddress(escrowAddress: string): Promise<string> {
|
|
863
1274
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -880,11 +1291,24 @@ export class EscrowClient {
|
|
|
880
1291
|
}
|
|
881
1292
|
|
|
882
1293
|
/**
|
|
883
|
-
*
|
|
1294
|
+
* This function returns the exchange oracle address for a given escrow.
|
|
884
1295
|
*
|
|
885
|
-
* @param {string} escrowAddress
|
|
886
|
-
* @returns {
|
|
887
|
-
*
|
|
1296
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1297
|
+
* @returns {EscrowStatus} Address of the Exchange Oracle.
|
|
1298
|
+
*
|
|
1299
|
+
* **Code example**
|
|
1300
|
+
*
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* import { providers } from 'ethers';
|
|
1303
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1304
|
+
*
|
|
1305
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1306
|
+
*
|
|
1307
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1308
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1309
|
+
*
|
|
1310
|
+
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1311
|
+
* ```
|
|
888
1312
|
*/
|
|
889
1313
|
async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
|
|
890
1314
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -907,11 +1331,24 @@ export class EscrowClient {
|
|
|
907
1331
|
}
|
|
908
1332
|
|
|
909
1333
|
/**
|
|
910
|
-
*
|
|
1334
|
+
* This function returns the escrow factory address for a given escrow.
|
|
1335
|
+
*
|
|
1336
|
+
* @param {string} escrowAddress Address of the escrow.
|
|
1337
|
+
* @returns {EscrowStatus} Address of the escrow factory.
|
|
1338
|
+
*
|
|
1339
|
+
* **Code example**
|
|
1340
|
+
*
|
|
1341
|
+
* ```ts
|
|
1342
|
+
* import { providers } from 'ethers';
|
|
1343
|
+
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1344
|
+
*
|
|
1345
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
911
1346
|
*
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
1347
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1348
|
+
* const escrowClient = await EscrowClient.build(signer);
|
|
1349
|
+
*
|
|
1350
|
+
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1351
|
+
* ```
|
|
915
1352
|
*/
|
|
916
1353
|
async getFactoryAddress(escrowAddress: string): Promise<string> {
|
|
917
1354
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
@@ -934,13 +1371,132 @@ export class EscrowClient {
|
|
|
934
1371
|
}
|
|
935
1372
|
}
|
|
936
1373
|
|
|
1374
|
+
/**
|
|
1375
|
+
* ## Introduction
|
|
1376
|
+
*
|
|
1377
|
+
* Utility class for escrow-related operations.
|
|
1378
|
+
*
|
|
1379
|
+
* ## Installation
|
|
1380
|
+
*
|
|
1381
|
+
* ### npm
|
|
1382
|
+
* ```bash
|
|
1383
|
+
* npm install @human-protocol/sdk
|
|
1384
|
+
* ```
|
|
1385
|
+
*
|
|
1386
|
+
* ### yarn
|
|
1387
|
+
* ```bash
|
|
1388
|
+
* yarn install @human-protocol/sdk
|
|
1389
|
+
* ```
|
|
1390
|
+
*
|
|
1391
|
+
* ## Code example
|
|
1392
|
+
*
|
|
1393
|
+
* ### Signer
|
|
1394
|
+
*
|
|
1395
|
+
* **Using private key(backend)**
|
|
1396
|
+
*
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1399
|
+
*
|
|
1400
|
+
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1401
|
+
* networks: [ChainId.POLYGON_MUMBAI]
|
|
1402
|
+
* });
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
937
1405
|
export class EscrowUtils {
|
|
938
1406
|
/**
|
|
939
|
-
*
|
|
1407
|
+
* This function returns an array of escrows based on the specified filter parameters.
|
|
1408
|
+
*
|
|
1409
|
+
*
|
|
1410
|
+
* **Input parameters**
|
|
1411
|
+
*
|
|
1412
|
+
* ```ts
|
|
1413
|
+
* interface IEscrowsFilter {
|
|
1414
|
+
* networks: ChainId[];
|
|
1415
|
+
* launcher?: string;
|
|
1416
|
+
* reputationOracle?: string;
|
|
1417
|
+
* recordingOracle?: string;
|
|
1418
|
+
* exchangeOracle?: string;
|
|
1419
|
+
* jobRequesterId?: string;
|
|
1420
|
+
* status?: EscrowStatus;
|
|
1421
|
+
* from?: Date;
|
|
1422
|
+
* to?: Date;
|
|
1423
|
+
* }
|
|
1424
|
+
* ```
|
|
1425
|
+
*
|
|
1426
|
+
* ```ts
|
|
1427
|
+
* enum ChainId {
|
|
1428
|
+
* ALL = -1,
|
|
1429
|
+
* MAINNET = 1,
|
|
1430
|
+
* RINKEBY = 4,
|
|
1431
|
+
* GOERLI = 5,
|
|
1432
|
+
* BSC_MAINNET = 56,
|
|
1433
|
+
* BSC_TESTNET = 97,
|
|
1434
|
+
* POLYGON = 137,
|
|
1435
|
+
* POLYGON_MUMBAI = 80001,
|
|
1436
|
+
* MOONBEAM = 1284,
|
|
1437
|
+
* MOONBASE_ALPHA = 1287,
|
|
1438
|
+
* AVALANCHE = 43114,
|
|
1439
|
+
* AVALANCHE_TESTNET = 43113,
|
|
1440
|
+
* SKALE = 1273227453,
|
|
1441
|
+
* LOCALHOST = 1338,
|
|
1442
|
+
* }
|
|
1443
|
+
* ```
|
|
1444
|
+
*
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* enum EscrowStatus {
|
|
1447
|
+
* Launched,
|
|
1448
|
+
* Pending,
|
|
1449
|
+
* Partial,
|
|
1450
|
+
* Paid,
|
|
1451
|
+
* Complete,
|
|
1452
|
+
* Cancelled,
|
|
1453
|
+
* }
|
|
1454
|
+
* ```
|
|
1455
|
+
*
|
|
1456
|
+
* ```ts
|
|
1457
|
+
* type EscrowData = {
|
|
1458
|
+
* id: string;
|
|
1459
|
+
* address: string;
|
|
1460
|
+
* amountPaid: string;
|
|
1461
|
+
* balance: string;
|
|
1462
|
+
* count: string;
|
|
1463
|
+
* jobRequesterId: string;
|
|
1464
|
+
* factoryAddress: string;
|
|
1465
|
+
* finalResultsUrl?: string;
|
|
1466
|
+
* intermediateResultsUrl?: string;
|
|
1467
|
+
* launcher: string;
|
|
1468
|
+
* manifestHash?: string;
|
|
1469
|
+
* manifestUrl?: string;
|
|
1470
|
+
* recordingOracle?: string;
|
|
1471
|
+
* recordingOracleFee?: string;
|
|
1472
|
+
* reputationOracle?: string;
|
|
1473
|
+
* reputationOracleFee?: string;
|
|
1474
|
+
* exchangeOracle?: string;
|
|
1475
|
+
* exchangeOracleFee?: string;
|
|
1476
|
+
* status: EscrowStatus;
|
|
1477
|
+
* token: string;
|
|
1478
|
+
* totalFundedAmount: string;
|
|
1479
|
+
* createdAt: string;
|
|
1480
|
+
* };
|
|
1481
|
+
* ```
|
|
1482
|
+
*
|
|
1483
|
+
*
|
|
1484
|
+
* @param {IEscrowsFilter} filter Filter parameters.
|
|
1485
|
+
* @returns {EscrowData[]} List of escrows that match the filter.
|
|
1486
|
+
*
|
|
1487
|
+
* **Code example**
|
|
940
1488
|
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
1489
|
+
* ```ts
|
|
1490
|
+
* import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
|
|
1491
|
+
*
|
|
1492
|
+
* const filters: IEscrowsFilter = {
|
|
1493
|
+
* status: EscrowStatus.Pending,
|
|
1494
|
+
* from: new Date(2023, 4, 8),
|
|
1495
|
+
* to: new Date(2023, 5, 8),
|
|
1496
|
+
* networks: [ChainId.POLYGON_MUMBAI]
|
|
1497
|
+
* };
|
|
1498
|
+
* const escrowDatas = await EscrowUtils.getEscrows(filters);
|
|
1499
|
+
* ```
|
|
944
1500
|
*/
|
|
945
1501
|
public static async getEscrows(
|
|
946
1502
|
filter: IEscrowsFilter
|
|
@@ -1007,12 +1563,70 @@ export class EscrowUtils {
|
|
|
1007
1563
|
}
|
|
1008
1564
|
|
|
1009
1565
|
/**
|
|
1010
|
-
*
|
|
1566
|
+
* This function returns the escrow data for a given address.
|
|
1567
|
+
*
|
|
1568
|
+
* > This uses Subgraph
|
|
1569
|
+
*
|
|
1570
|
+
* **Input parameters**
|
|
1571
|
+
*
|
|
1572
|
+
* ```ts
|
|
1573
|
+
* enum ChainId {
|
|
1574
|
+
* ALL = -1,
|
|
1575
|
+
* MAINNET = 1,
|
|
1576
|
+
* RINKEBY = 4,
|
|
1577
|
+
* GOERLI = 5,
|
|
1578
|
+
* BSC_MAINNET = 56,
|
|
1579
|
+
* BSC_TESTNET = 97,
|
|
1580
|
+
* POLYGON = 137,
|
|
1581
|
+
* POLYGON_MUMBAI = 80001,
|
|
1582
|
+
* MOONBEAM = 1284,
|
|
1583
|
+
* MOONBASE_ALPHA = 1287,
|
|
1584
|
+
* AVALANCHE = 43114,
|
|
1585
|
+
* AVALANCHE_TESTNET = 43113,
|
|
1586
|
+
* SKALE = 1273227453,
|
|
1587
|
+
* LOCALHOST = 1338,
|
|
1588
|
+
* }
|
|
1589
|
+
* ```
|
|
1590
|
+
*
|
|
1591
|
+
* ```ts
|
|
1592
|
+
* type EscrowData = {
|
|
1593
|
+
* id: string;
|
|
1594
|
+
* address: string;
|
|
1595
|
+
* amountPaid: string;
|
|
1596
|
+
* balance: string;
|
|
1597
|
+
* count: string;
|
|
1598
|
+
* jobRequesterId: string;
|
|
1599
|
+
* factoryAddress: string;
|
|
1600
|
+
* finalResultsUrl?: string;
|
|
1601
|
+
* intermediateResultsUrl?: string;
|
|
1602
|
+
* launcher: string;
|
|
1603
|
+
* manifestHash?: string;
|
|
1604
|
+
* manifestUrl?: string;
|
|
1605
|
+
* recordingOracle?: string;
|
|
1606
|
+
* recordingOracleFee?: string;
|
|
1607
|
+
* reputationOracle?: string;
|
|
1608
|
+
* reputationOracleFee?: string;
|
|
1609
|
+
* exchangeOracle?: string;
|
|
1610
|
+
* exchangeOracleFee?: string;
|
|
1611
|
+
* status: EscrowStatus;
|
|
1612
|
+
* token: string;
|
|
1613
|
+
* totalFundedAmount: string;
|
|
1614
|
+
* createdAt: string;
|
|
1615
|
+
* };
|
|
1616
|
+
* ```
|
|
1617
|
+
*
|
|
1618
|
+
*
|
|
1619
|
+
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
1620
|
+
* @param {string} escrowAddress Address of the escrow
|
|
1621
|
+
* @returns {EscrowData} Escrow data
|
|
1622
|
+
*
|
|
1623
|
+
* **Code example**
|
|
1624
|
+
*
|
|
1625
|
+
* ```ts
|
|
1626
|
+
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1011
1627
|
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1014
|
-
* @returns {Promise<EscrowData>}
|
|
1015
|
-
* @throws {Error} - An error object if an error occurred.
|
|
1628
|
+
* const escrowData = new EscrowUtils.getEscrow(ChainId.POLYGON_MUMBAI, "0x1234567890123456789012345678901234567890");
|
|
1629
|
+
* ```
|
|
1016
1630
|
*/
|
|
1017
1631
|
public static async getEscrow(
|
|
1018
1632
|
chainId: ChainId,
|