@human-protocol/sdk 5.1.0 → 6.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/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +4 -5
- package/dist/constants.js +6 -6
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +67 -203
- package/dist/error.d.ts +4 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +6 -26
- package/dist/escrow.d.ts +427 -780
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +314 -684
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/interfaces.d.ts +5 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +119 -181
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +119 -182
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +135 -134
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +135 -135
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +36 -15
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -16
- package/dist/types.d.ts +0 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -17
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +57 -28
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +13 -28
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +70 -204
- package/src/error.ts +7 -36
- package/src/escrow.ts +426 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/interfaces.ts +5 -0
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +136 -135
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -16
- package/src/types.ts +0 -57
- package/src/utils.ts +62 -31
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- package/src/storage.ts +0 -313
package/src/escrow.ts
CHANGED
|
@@ -77,82 +77,64 @@ import {
|
|
|
77
77
|
} from './utils';
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.
|
|
80
|
+
* Client to perform actions on Escrow contracts and obtain information from the contracts.
|
|
83
81
|
*
|
|
84
82
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
85
|
-
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
86
|
-
*
|
|
87
|
-
* ```ts
|
|
88
|
-
* static async build(runner: ContractRunner): Promise<EscrowClient>;
|
|
89
|
-
* ```
|
|
83
|
+
* To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/EscrowClient/#build) method.
|
|
90
84
|
*
|
|
91
85
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
92
86
|
*
|
|
93
87
|
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
94
88
|
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
95
89
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* ### npm
|
|
99
|
-
* ```bash
|
|
100
|
-
* npm install @human-protocol/sdk
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* ### yarn
|
|
104
|
-
* ```bash
|
|
105
|
-
* yarn install @human-protocol/sdk
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* ## Code example
|
|
90
|
+
* @example
|
|
109
91
|
*
|
|
110
|
-
* ### Signer
|
|
92
|
+
* ###Using Signer
|
|
111
93
|
*
|
|
112
|
-
*
|
|
94
|
+
* ####Using private key (backend)
|
|
113
95
|
*
|
|
114
96
|
* ```ts
|
|
115
97
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
116
|
-
* import { Wallet,
|
|
98
|
+
* import { Wallet, JsonRpcProvider } from 'ethers';
|
|
117
99
|
*
|
|
118
100
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
119
101
|
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
120
102
|
*
|
|
121
|
-
* const provider = new
|
|
103
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
122
104
|
* const signer = new Wallet(privateKey, provider);
|
|
123
105
|
* const escrowClient = await EscrowClient.build(signer);
|
|
124
106
|
* ```
|
|
125
107
|
*
|
|
126
|
-
*
|
|
108
|
+
* ####Using Wagmi (frontend)
|
|
127
109
|
*
|
|
128
110
|
* ```ts
|
|
129
|
-
* import { useSigner
|
|
111
|
+
* import { useSigner } from 'wagmi';
|
|
130
112
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
131
113
|
*
|
|
132
114
|
* const { data: signer } = useSigner();
|
|
133
115
|
* const escrowClient = await EscrowClient.build(signer);
|
|
134
116
|
* ```
|
|
135
117
|
*
|
|
136
|
-
* ### Provider
|
|
118
|
+
* ###Using Provider
|
|
137
119
|
*
|
|
138
120
|
* ```ts
|
|
139
121
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
140
|
-
* import {
|
|
122
|
+
* import { JsonRpcProvider } from 'ethers';
|
|
141
123
|
*
|
|
142
124
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
143
|
-
*
|
|
144
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
125
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
145
126
|
* const escrowClient = await EscrowClient.build(provider);
|
|
146
127
|
* ```
|
|
147
128
|
*/
|
|
148
129
|
export class EscrowClient extends BaseEthersClient {
|
|
149
|
-
|
|
130
|
+
public escrowFactoryContract: EscrowFactory;
|
|
150
131
|
|
|
151
132
|
/**
|
|
152
133
|
* **EscrowClient constructor**
|
|
153
134
|
*
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
135
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
136
|
+
* @param networkData - The network information required to connect to the Escrow contract
|
|
137
|
+
* @returns An instance of EscrowClient
|
|
156
138
|
*/
|
|
157
139
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
158
140
|
super(runner, networkData);
|
|
@@ -166,11 +148,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
166
148
|
/**
|
|
167
149
|
* Creates an instance of EscrowClient from a Runner.
|
|
168
150
|
*
|
|
169
|
-
* @param
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
172
|
-
* @throws
|
|
173
|
-
* @throws {ErrorUnsupportedChainID} Thrown if the network's chainId is not supported
|
|
151
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
152
|
+
* @returns An instance of EscrowClient
|
|
153
|
+
* @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
|
|
154
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
174
155
|
*/
|
|
175
156
|
public static async build(runner: ContractRunner): Promise<EscrowClient> {
|
|
176
157
|
if (!runner.provider) {
|
|
@@ -204,28 +185,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
204
185
|
|
|
205
186
|
/**
|
|
206
187
|
* This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
188
|
+
* @remarks Need to have available stake.
|
|
189
|
+
* @param tokenAddress - The address of the token to use for escrow funding.
|
|
190
|
+
* @param jobRequesterId - Identifier for the job requester.
|
|
191
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
192
|
+
* @returns Returns the address of the escrow created.
|
|
193
|
+
* @throws ErrorInvalidTokenAddress If the token address is invalid
|
|
194
|
+
* @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
|
|
207
195
|
*
|
|
208
|
-
* @
|
|
209
|
-
* @param {string} jobRequesterId - Identifier for the job requester.
|
|
210
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
211
|
-
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* **Code example**
|
|
215
|
-
*
|
|
216
|
-
* > Need to have available stake.
|
|
196
|
+
* @example
|
|
217
197
|
*
|
|
218
198
|
* ```ts
|
|
219
|
-
* import { Wallet, providers } from 'ethers';
|
|
220
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
221
|
-
*
|
|
222
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
223
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
224
|
-
*
|
|
225
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
226
|
-
* const signer = new Wallet(privateKey, provider);
|
|
227
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
228
|
-
*
|
|
229
199
|
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
230
200
|
* const jobRequesterId = "job-requester-id";
|
|
231
201
|
* const escrowAddress = await escrowClient.createEscrow(tokenAddress, jobRequesterId);
|
|
@@ -265,6 +235,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
265
235
|
return throwError(e);
|
|
266
236
|
}
|
|
267
237
|
}
|
|
238
|
+
|
|
268
239
|
private verifySetupParameters(escrowConfig: IEscrowConfig) {
|
|
269
240
|
const {
|
|
270
241
|
recordingOracle,
|
|
@@ -314,50 +285,45 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
314
285
|
/**
|
|
315
286
|
* Creates, funds, and sets up a new escrow contract in a single transaction.
|
|
316
287
|
*
|
|
317
|
-
* @
|
|
318
|
-
* @param
|
|
319
|
-
* @param
|
|
320
|
-
* @param
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* @
|
|
330
|
-
*
|
|
331
|
-
* @
|
|
288
|
+
* @remarks Need to have available stake and approve allowance in the token contract before calling this method.
|
|
289
|
+
* @param tokenAddress - The ERC-20 token address used to fund the escrow.
|
|
290
|
+
* @param amount - The token amount to fund the escrow with.
|
|
291
|
+
* @param jobRequesterId - An off-chain identifier for the job requester.
|
|
292
|
+
* @param escrowConfig - Configuration parameters for escrow setup.
|
|
293
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
294
|
+
* @returns Returns the address of the escrow created.
|
|
295
|
+
* @throws ErrorInvalidTokenAddress If the token address is invalid
|
|
296
|
+
* @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
|
|
297
|
+
* @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
|
|
298
|
+
* @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
|
|
299
|
+
* @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
|
|
300
|
+
* @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
|
|
301
|
+
* @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
|
|
302
|
+
* @throws ErrorHashIsEmptyString If the manifest hash is empty
|
|
303
|
+
* @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
|
|
332
304
|
*
|
|
333
305
|
* @example
|
|
334
|
-
*
|
|
335
|
-
* import {
|
|
336
|
-
*
|
|
337
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
338
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
339
|
-
* const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
340
|
-
* const signer = new Wallet(privateKey, provider);
|
|
341
|
-
*
|
|
342
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { ethers } from 'ethers';
|
|
308
|
+
* import { ERC20__factory } from '@human-protocol/sdk';
|
|
343
309
|
*
|
|
344
|
-
* const tokenAddress = '
|
|
310
|
+
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
345
311
|
* const amount = ethers.parseUnits('1000', 18);
|
|
346
312
|
* const jobRequesterId = 'requester-123';
|
|
347
313
|
*
|
|
348
|
-
* const token =
|
|
314
|
+
* const token = ERC20__factory.connect(tokenAddress, signer);
|
|
349
315
|
* await token.approve(escrowClient.escrowFactoryContract.target, amount);
|
|
350
316
|
*
|
|
351
317
|
* const escrowConfig = {
|
|
352
|
-
* recordingOracle: '
|
|
353
|
-
* reputationOracle: '
|
|
354
|
-
* exchangeOracle: '
|
|
318
|
+
* recordingOracle: '0xRecordingOracleAddress',
|
|
319
|
+
* reputationOracle: '0xReputationOracleAddress',
|
|
320
|
+
* exchangeOracle: '0xExchangeOracleAddress',
|
|
355
321
|
* recordingOracleFee: 5n,
|
|
356
322
|
* reputationOracleFee: 5n,
|
|
357
323
|
* exchangeOracleFee: 5n,
|
|
358
324
|
* manifest: 'https://example.com/manifest.json',
|
|
359
325
|
* manifestHash: 'manifestHash-123',
|
|
360
|
-
* }
|
|
326
|
+
* };
|
|
361
327
|
*
|
|
362
328
|
* const escrowAddress = await escrowClient.createFundAndSetupEscrow(
|
|
363
329
|
* tokenAddress,
|
|
@@ -365,8 +331,8 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
365
331
|
* jobRequesterId,
|
|
366
332
|
* escrowConfig
|
|
367
333
|
* );
|
|
368
|
-
*
|
|
369
334
|
* console.log('Escrow created at:', escrowAddress);
|
|
335
|
+
* ```
|
|
370
336
|
*/
|
|
371
337
|
@requiresSigner
|
|
372
338
|
public async createFundAndSetupEscrow(
|
|
@@ -430,35 +396,33 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
430
396
|
/**
|
|
431
397
|
* This function sets up the parameters of the escrow.
|
|
432
398
|
*
|
|
433
|
-
* @
|
|
434
|
-
*
|
|
435
|
-
* @param
|
|
436
|
-
* @
|
|
437
|
-
*
|
|
399
|
+
* @remarks Only Job Launcher or admin can call it.
|
|
400
|
+
*
|
|
401
|
+
* @param escrowAddress - Address of the escrow to set up.
|
|
402
|
+
* @param escrowConfig - Escrow configuration parameters.
|
|
403
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
404
|
+
* @returns -
|
|
405
|
+
* @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
|
|
406
|
+
* @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
|
|
407
|
+
* @throws ErrorInvalidExchangeOracleAddressProvided If the exchange oracle address is invalid
|
|
408
|
+
* @throws ErrorAmountMustBeGreaterThanZero If any oracle fee is less than or equal to zero
|
|
409
|
+
* @throws ErrorTotalFeeMustBeLessThanHundred If the total oracle fees exceed 100
|
|
410
|
+
* @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
|
|
411
|
+
* @throws ErrorHashIsEmptyString If the manifest hash is empty
|
|
412
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
413
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
438
414
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
* > Only Job Launcher or admin can call it.
|
|
415
|
+
* @example
|
|
442
416
|
*
|
|
443
417
|
* ```ts
|
|
444
|
-
* import { Wallet, providers } from 'ethers';
|
|
445
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
446
|
-
*
|
|
447
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
448
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
449
|
-
*
|
|
450
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
451
|
-
* const signer = new Wallet(privateKey, provider);
|
|
452
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
453
|
-
*
|
|
454
418
|
* const escrowAddress = '0x62dD51230A30401C455c8398d06F85e4EaB6309f';
|
|
455
419
|
* const escrowConfig = {
|
|
456
420
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
457
421
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
458
422
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
459
|
-
* recordingOracleFee:
|
|
460
|
-
* reputationOracleFee:
|
|
461
|
-
* exchangeOracleFee:
|
|
423
|
+
* recordingOracleFee: 10n,
|
|
424
|
+
* reputationOracleFee: 10n,
|
|
425
|
+
* exchangeOracleFee: 10n,
|
|
462
426
|
* manifest: 'http://localhost/manifest.json',
|
|
463
427
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
464
428
|
* };
|
|
@@ -518,26 +482,19 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
518
482
|
/**
|
|
519
483
|
* This function adds funds of the chosen token to the escrow.
|
|
520
484
|
*
|
|
521
|
-
* @param
|
|
522
|
-
* @param
|
|
523
|
-
* @param
|
|
524
|
-
* @returns
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
485
|
+
* @param escrowAddress - Address of the escrow to fund.
|
|
486
|
+
* @param amount - Amount to be added as funds.
|
|
487
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
488
|
+
* @returns -
|
|
489
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
490
|
+
* @throws ErrorAmountMustBeGreaterThanZero If the amount is less than or equal to zero
|
|
491
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
528
492
|
*
|
|
493
|
+
* @example
|
|
529
494
|
* ```ts
|
|
530
|
-
* import { ethers
|
|
531
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
532
|
-
*
|
|
533
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
534
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
495
|
+
* import { ethers } from 'ethers';
|
|
535
496
|
*
|
|
536
|
-
* const
|
|
537
|
-
* const signer = new Wallet(privateKey, provider);
|
|
538
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
539
|
-
*
|
|
540
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
497
|
+
* const amount = ethers.parseUnits('5', 'ether');
|
|
541
498
|
* await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
|
|
542
499
|
* ```
|
|
543
500
|
*/
|
|
@@ -579,75 +536,74 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
579
536
|
}
|
|
580
537
|
|
|
581
538
|
/**
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* @param {string} escrowAddress Address of the escrow.
|
|
585
|
-
* @param {string} url Results file URL.
|
|
586
|
-
* @param {string} hash Results file hash.
|
|
587
|
-
* @param {bigint} fundsToReserve Funds to reserve for payouts
|
|
588
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
589
|
-
* @returns Returns void if successful. Throws error if any.
|
|
539
|
+
* Stores the result URL and result hash for an escrow.
|
|
590
540
|
*
|
|
541
|
+
* @remarks Only Recording Oracle or admin can call it.
|
|
591
542
|
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
543
|
+
* @param escrowAddress - The escrow address.
|
|
544
|
+
* @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
|
|
545
|
+
* @param hash - The hash of the results payload.
|
|
546
|
+
* @param txOptions - Optional transaction overrides.
|
|
547
|
+
* @returns -
|
|
548
|
+
* @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
|
|
549
|
+
* @throws ErrorInvalidUrl If the URL format is invalid.
|
|
550
|
+
* @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
|
|
551
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
|
|
552
|
+
* @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
|
|
595
553
|
*
|
|
554
|
+
* @example
|
|
596
555
|
* ```ts
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
604
|
-
* const signer = new Wallet(privateKey, provider);
|
|
605
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
606
|
-
*
|
|
607
|
-
* await escrowClient.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079', ethers.parseEther('10'));
|
|
556
|
+
* await escrowClient.storeResults(
|
|
557
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
558
|
+
* 'https://example.com/results.json',
|
|
559
|
+
* '0xHASH123'
|
|
560
|
+
* );
|
|
608
561
|
* ```
|
|
609
562
|
*/
|
|
610
|
-
|
|
611
563
|
async storeResults(
|
|
612
564
|
escrowAddress: string,
|
|
613
565
|
url: string,
|
|
614
566
|
hash: string,
|
|
615
|
-
fundsToReserve: bigint,
|
|
616
567
|
txOptions?: Overrides
|
|
617
568
|
): Promise<void>;
|
|
618
569
|
|
|
619
570
|
/**
|
|
620
|
-
*
|
|
571
|
+
* Stores the result URL and result hash for an escrow.
|
|
621
572
|
*
|
|
622
|
-
* @
|
|
623
|
-
* @param {string} url Results file URL.
|
|
624
|
-
* @param {string} hash Results file hash.
|
|
625
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
626
|
-
* @returns Returns void if successful. Throws error if any.
|
|
573
|
+
* @remarks Only Recording Oracle or admin can call it.
|
|
627
574
|
*
|
|
575
|
+
* If `fundsToReserve` is provided, the escrow reserves the specified funds.
|
|
576
|
+
* When `fundsToReserve` is `0n`, an empty URL is allowed (for cases where no solutions were provided).
|
|
628
577
|
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
578
|
+
* @param escrowAddress - The escrow address.
|
|
579
|
+
* @param url - The URL containing the final results. May be empty only when `fundsToReserve` is `0n`.
|
|
580
|
+
* @param hash - The hash of the results payload.
|
|
581
|
+
* @param fundsToReserve - Optional amount of funds to reserve (when using second overload).
|
|
582
|
+
* @param txOptions - Optional transaction overrides.
|
|
583
|
+
* @returns -
|
|
584
|
+
* @throws ErrorInvalidEscrowAddressProvided If the provided escrow address is invalid.
|
|
585
|
+
* @throws ErrorInvalidUrl If the URL format is invalid.
|
|
586
|
+
* @throws ErrorHashIsEmptyString If the hash is empty and empty values are not allowed.
|
|
587
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow does not exist in the factory.
|
|
588
|
+
* @throws ErrorStoreResultsVersion If the contract supports only the deprecated signature.
|
|
632
589
|
*
|
|
590
|
+
* @example
|
|
633
591
|
* ```ts
|
|
634
|
-
* import { ethers
|
|
635
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
636
|
-
*
|
|
637
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
638
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
639
|
-
*
|
|
640
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
641
|
-
* const signer = new Wallet(privateKey, provider);
|
|
642
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
592
|
+
* import { ethers } from 'ethers';
|
|
643
593
|
*
|
|
644
|
-
* await escrowClient.storeResults(
|
|
594
|
+
* await escrowClient.storeResults(
|
|
595
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
596
|
+
* 'https://example.com/results.json',
|
|
597
|
+
* '0xHASH123',
|
|
598
|
+
* ethers.parseEther('5')
|
|
599
|
+
* );
|
|
645
600
|
* ```
|
|
646
601
|
*/
|
|
647
602
|
async storeResults(
|
|
648
603
|
escrowAddress: string,
|
|
649
604
|
url: string,
|
|
650
605
|
hash: string,
|
|
606
|
+
fundsToReserve: bigint,
|
|
651
607
|
txOptions?: Overrides
|
|
652
608
|
): Promise<void>;
|
|
653
609
|
|
|
@@ -714,27 +670,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
714
670
|
|
|
715
671
|
/**
|
|
716
672
|
* This function sets the status of an escrow to completed.
|
|
673
|
+
* @remarks Only Recording Oracle or admin can call it.
|
|
674
|
+
* @param escrowAddress - Address of the escrow.
|
|
675
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
676
|
+
* @returns -
|
|
677
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid.
|
|
678
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory.
|
|
717
679
|
*
|
|
718
|
-
* @
|
|
719
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
720
|
-
* @returns Returns void if successful. Throws error if any.
|
|
721
|
-
*
|
|
722
|
-
*
|
|
723
|
-
* **Code example**
|
|
724
|
-
*
|
|
725
|
-
* > Only Recording Oracle or admin can call it.
|
|
726
|
-
*
|
|
680
|
+
* @example
|
|
727
681
|
* ```ts
|
|
728
|
-
* import { Wallet, providers } from 'ethers';
|
|
729
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
730
|
-
*
|
|
731
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
732
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
733
|
-
*
|
|
734
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
735
|
-
* const signer = new Wallet(privateKey, provider);
|
|
736
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
737
|
-
*
|
|
738
682
|
* await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
739
683
|
* ```
|
|
740
684
|
*/
|
|
@@ -763,40 +707,48 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
763
707
|
|
|
764
708
|
/**
|
|
765
709
|
* This function pays out the amounts specified to the workers and sets the URL of the final results file.
|
|
710
|
+
* @remarks Only Reputation Oracle or admin can call it.
|
|
711
|
+
*
|
|
712
|
+
* @param escrowAddress - Escrow address to payout.
|
|
713
|
+
* @param recipients - Array of recipient addresses.
|
|
714
|
+
* @param amounts - Array of amounts the recipients will receive.
|
|
715
|
+
* @param finalResultsUrl - Final results file URL.
|
|
716
|
+
* @param finalResultsHash - Final results file hash.
|
|
717
|
+
* @param txId - Transaction ID.
|
|
718
|
+
* @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
719
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
720
|
+
* @returns -
|
|
721
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
722
|
+
* @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
|
|
723
|
+
* @throws ErrorTooManyRecipients If there are too many recipients
|
|
724
|
+
* @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
|
|
725
|
+
* @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
|
|
726
|
+
* @throws InvalidEthereumAddressError If any recipient address is invalid
|
|
727
|
+
* @throws ErrorInvalidUrl If the final results URL is invalid
|
|
728
|
+
* @throws ErrorHashIsEmptyString If the final results hash is empty
|
|
729
|
+
* @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
|
|
730
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
731
|
+
* @throws ErrorBulkPayOutVersion If using deprecated signature
|
|
766
732
|
*
|
|
767
|
-
* @
|
|
768
|
-
* @param {string[]} recipients Array of recipient addresses.
|
|
769
|
-
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
770
|
-
* @param {string} finalResultsUrl Final results file URL.
|
|
771
|
-
* @param {string} finalResultsHash Final results file hash.
|
|
772
|
-
* @param {number} txId Transaction ID.
|
|
773
|
-
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
774
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
775
|
-
* @returns Returns void if successful. Throws error if any.
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
* **Code example**
|
|
779
|
-
*
|
|
780
|
-
* > Only Reputation Oracle or admin can call it.
|
|
781
|
-
*
|
|
733
|
+
* @example
|
|
782
734
|
* ```ts
|
|
783
|
-
* import { ethers
|
|
784
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
785
|
-
*
|
|
786
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
787
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
735
|
+
* import { ethers } from 'ethers';
|
|
788
736
|
*
|
|
789
|
-
* const
|
|
790
|
-
* const
|
|
791
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
792
|
-
*
|
|
793
|
-
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
794
|
-
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
737
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
|
|
738
|
+
* const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
|
|
795
739
|
* const resultsUrl = 'http://localhost/results.json';
|
|
796
740
|
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
797
741
|
* const txId = 1;
|
|
798
742
|
*
|
|
799
|
-
* await escrowClient.bulkPayOut(
|
|
743
|
+
* await escrowClient.bulkPayOut(
|
|
744
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
745
|
+
* recipients,
|
|
746
|
+
* amounts,
|
|
747
|
+
* resultsUrl,
|
|
748
|
+
* resultsHash,
|
|
749
|
+
* txId,
|
|
750
|
+
* true
|
|
751
|
+
* );
|
|
800
752
|
* ```
|
|
801
753
|
*/
|
|
802
754
|
async bulkPayOut(
|
|
@@ -812,41 +764,49 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
812
764
|
|
|
813
765
|
/**
|
|
814
766
|
* This function pays out the amounts specified to the workers and sets the URL of the final results file.
|
|
767
|
+
* @remarks Only Reputation Oracle or admin can call it.
|
|
768
|
+
* @param escrowAddress - Escrow address to payout.
|
|
769
|
+
* @param recipients - Array of recipient addresses.
|
|
770
|
+
* @param amounts - Array of amounts the recipients will receive.
|
|
771
|
+
* @param finalResultsUrl - Final results file URL.
|
|
772
|
+
* @param finalResultsHash - Final results file hash.
|
|
773
|
+
* @param payoutId - Payout ID.
|
|
774
|
+
* @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
775
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
776
|
+
* @returns -
|
|
777
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
778
|
+
* @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
|
|
779
|
+
* @throws ErrorTooManyRecipients If there are too many recipients
|
|
780
|
+
* @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
|
|
781
|
+
* @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
|
|
782
|
+
* @throws InvalidEthereumAddressError If any recipient address is invalid
|
|
783
|
+
* @throws ErrorInvalidUrl If the final results URL is invalid
|
|
784
|
+
* @throws ErrorHashIsEmptyString If the final results hash is empty
|
|
785
|
+
* @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
|
|
786
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
787
|
+
* @throws ErrorBulkPayOutVersion If using deprecated signature
|
|
815
788
|
*
|
|
816
|
-
* @
|
|
817
|
-
* @param {string[]} recipients Array of recipient addresses.
|
|
818
|
-
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
819
|
-
* @param {string} finalResultsUrl Final results file URL.
|
|
820
|
-
* @param {string} finalResultsHash Final results file hash.
|
|
821
|
-
* @param {string} payoutId Payout ID.
|
|
822
|
-
* @param {boolean} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
823
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
824
|
-
* @returns Returns void if successful. Throws error if any.
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
* **Code example**
|
|
828
|
-
*
|
|
829
|
-
* > Only Reputation Oracle or admin can call it.
|
|
789
|
+
* @example
|
|
830
790
|
*
|
|
831
791
|
* ```ts
|
|
832
|
-
* import { ethers
|
|
833
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
792
|
+
* import { ethers } from 'ethers';
|
|
834
793
|
* import { v4 as uuidV4 } from 'uuid';
|
|
835
794
|
*
|
|
836
|
-
* const
|
|
837
|
-
* const
|
|
838
|
-
*
|
|
839
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
840
|
-
* const signer = new Wallet(privateKey, provider);
|
|
841
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
842
|
-
*
|
|
843
|
-
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
844
|
-
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
795
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
|
|
796
|
+
* const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
|
|
845
797
|
* const resultsUrl = 'http://localhost/results.json';
|
|
846
798
|
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
847
799
|
* const payoutId = uuidV4();
|
|
848
800
|
*
|
|
849
|
-
* await escrowClient.bulkPayOut(
|
|
801
|
+
* await escrowClient.bulkPayOut(
|
|
802
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
803
|
+
* recipients,
|
|
804
|
+
* amounts,
|
|
805
|
+
* resultsUrl,
|
|
806
|
+
* resultsHash,
|
|
807
|
+
* payoutId,
|
|
808
|
+
* true
|
|
809
|
+
* );
|
|
850
810
|
* ```
|
|
851
811
|
*/
|
|
852
812
|
async bulkPayOut(
|
|
@@ -924,26 +884,16 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
924
884
|
|
|
925
885
|
/**
|
|
926
886
|
* This function cancels the specified escrow and sends the balance to the canceler.
|
|
887
|
+
* @remarks Only Job Launcher or admin can call it.
|
|
888
|
+
* @param escrowAddress - Address of the escrow to cancel.
|
|
889
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
890
|
+
* @returns -
|
|
891
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
892
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
927
893
|
*
|
|
928
|
-
* @
|
|
929
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
* **Code example**
|
|
933
|
-
*
|
|
934
|
-
* > Only Job Launcher or admin can call it.
|
|
894
|
+
* @example
|
|
935
895
|
*
|
|
936
896
|
* ```ts
|
|
937
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
938
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
939
|
-
*
|
|
940
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
941
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
942
|
-
*
|
|
943
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
944
|
-
* const signer = new Wallet(privateKey, provider);
|
|
945
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
946
|
-
*
|
|
947
897
|
* await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
948
898
|
* ```
|
|
949
899
|
*/
|
|
@@ -970,26 +920,16 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
970
920
|
|
|
971
921
|
/**
|
|
972
922
|
* This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).
|
|
923
|
+
* @remarks Only Job Launcher or admin can call it.
|
|
924
|
+
* @param escrowAddress - Address of the escrow to request cancellation.
|
|
925
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
926
|
+
* @returns -
|
|
927
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
928
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
973
929
|
*
|
|
974
|
-
* @
|
|
975
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
976
|
-
* @returns Returns void if successful. Throws error if any.
|
|
977
|
-
*
|
|
978
|
-
* **Code example**
|
|
979
|
-
*
|
|
980
|
-
* > Only Job Launcher or admin can call it.
|
|
930
|
+
* @example
|
|
981
931
|
*
|
|
982
932
|
* ```ts
|
|
983
|
-
* import { Wallet, providers } from 'ethers';
|
|
984
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
985
|
-
*
|
|
986
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
987
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
988
|
-
*
|
|
989
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
990
|
-
* const signer = new Wallet(privateKey, provider);
|
|
991
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
992
|
-
*
|
|
993
933
|
* await escrowClient.requestCancellation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
994
934
|
* ```
|
|
995
935
|
*/
|
|
@@ -1016,32 +956,25 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1016
956
|
|
|
1017
957
|
/**
|
|
1018
958
|
* This function withdraws additional tokens in the escrow to the canceler.
|
|
959
|
+
* @remarks Only Job Launcher or admin can call it.
|
|
1019
960
|
*
|
|
1020
|
-
* @param
|
|
1021
|
-
* @param
|
|
1022
|
-
* @param
|
|
1023
|
-
* @returns
|
|
1024
|
-
*
|
|
961
|
+
* @param escrowAddress - Address of the escrow to withdraw.
|
|
962
|
+
* @param tokenAddress - Address of the token to withdraw.
|
|
963
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
964
|
+
* @returns Returns the escrow withdrawal data including transaction hash and withdrawal amount.
|
|
965
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
966
|
+
* @throws ErrorInvalidTokenAddress If the token address is invalid
|
|
967
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
968
|
+
* @throws ErrorTransferEventNotFoundInTransactionLogs If the Transfer event is not found in transaction logs
|
|
1025
969
|
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
* > Only Job Launcher or admin can call it.
|
|
970
|
+
* @example
|
|
1029
971
|
*
|
|
1030
972
|
* ```ts
|
|
1031
|
-
*
|
|
1032
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1033
|
-
*
|
|
1034
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1035
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
1036
|
-
*
|
|
1037
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1038
|
-
* const signer = new Wallet(privateKey, provider);
|
|
1039
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
1040
|
-
*
|
|
1041
|
-
* await escrowClient.withdraw(
|
|
973
|
+
* const withdrawData = await escrowClient.withdraw(
|
|
1042
974
|
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
1043
975
|
* '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
|
|
1044
976
|
* );
|
|
977
|
+
* console.log('Withdrawn amount:', withdrawData.withdrawnAmount);
|
|
1045
978
|
* ```
|
|
1046
979
|
*/
|
|
1047
980
|
@requiresSigner
|
|
@@ -1107,43 +1040,54 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1107
1040
|
|
|
1108
1041
|
/**
|
|
1109
1042
|
* Creates a prepared transaction for bulk payout without immediately sending it.
|
|
1110
|
-
* @
|
|
1111
|
-
*
|
|
1112
|
-
* @param
|
|
1113
|
-
* @param
|
|
1114
|
-
* @param
|
|
1115
|
-
* @param
|
|
1116
|
-
* @param
|
|
1117
|
-
* @param
|
|
1118
|
-
* @
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1043
|
+
* @remarks Only Reputation Oracle or admin can call it.
|
|
1044
|
+
*
|
|
1045
|
+
* @param escrowAddress - Escrow address to payout.
|
|
1046
|
+
* @param recipients - Array of recipient addresses.
|
|
1047
|
+
* @param amounts - Array of amounts the recipients will receive.
|
|
1048
|
+
* @param finalResultsUrl - Final results file URL.
|
|
1049
|
+
* @param finalResultsHash - Final results file hash.
|
|
1050
|
+
* @param payoutId - Payout ID to identify the payout.
|
|
1051
|
+
* @param forceComplete - Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
1052
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
1053
|
+
* @returns Returns object with raw transaction and nonce
|
|
1054
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1055
|
+
* @throws ErrorRecipientCannotBeEmptyArray If the recipients array is empty
|
|
1056
|
+
* @throws ErrorTooManyRecipients If there are too many recipients
|
|
1057
|
+
* @throws ErrorAmountsCannotBeEmptyArray If the amounts array is empty
|
|
1058
|
+
* @throws ErrorRecipientAndAmountsMustBeSameLength If recipients and amounts arrays have different lengths
|
|
1059
|
+
* @throws InvalidEthereumAddressError If any recipient address is invalid
|
|
1060
|
+
* @throws ErrorInvalidUrl If the final results URL is invalid
|
|
1061
|
+
* @throws ErrorHashIsEmptyString If the final results hash is empty
|
|
1062
|
+
* @throws ErrorEscrowDoesNotHaveEnoughBalance If the escrow doesn't have enough balance
|
|
1063
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1121
1064
|
*
|
|
1122
|
-
*
|
|
1065
|
+
* @example
|
|
1123
1066
|
*
|
|
1124
1067
|
* ```ts
|
|
1125
|
-
* import { ethers
|
|
1126
|
-
* import {
|
|
1127
|
-
*
|
|
1128
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1129
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
1130
|
-
*
|
|
1131
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1132
|
-
* const signer = new Wallet(privateKey, provider);
|
|
1133
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
1068
|
+
* import { ethers } from 'ethers';
|
|
1069
|
+
* import { v4 as uuidV4 } from 'uuid';
|
|
1134
1070
|
*
|
|
1135
|
-
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '
|
|
1136
|
-
* const amounts = [ethers.parseUnits(5, 'ether'), ethers.parseUnits(10, 'ether')];
|
|
1071
|
+
* const recipients = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'];
|
|
1072
|
+
* const amounts = [ethers.parseUnits('5', 'ether'), ethers.parseUnits('10', 'ether')];
|
|
1137
1073
|
* const resultsUrl = 'http://localhost/results.json';
|
|
1138
1074
|
* const resultsHash = 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079';
|
|
1139
|
-
* const payoutId =
|
|
1075
|
+
* const payoutId = uuidV4();
|
|
1140
1076
|
*
|
|
1141
|
-
* const rawTransaction = await escrowClient.createBulkPayoutTransaction(
|
|
1077
|
+
* const rawTransaction = await escrowClient.createBulkPayoutTransaction(
|
|
1078
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
1079
|
+
* recipients,
|
|
1080
|
+
* amounts,
|
|
1081
|
+
* resultsUrl,
|
|
1082
|
+
* resultsHash,
|
|
1083
|
+
* payoutId
|
|
1084
|
+
* );
|
|
1142
1085
|
* console.log('Raw transaction:', rawTransaction);
|
|
1143
1086
|
*
|
|
1144
1087
|
* const signedTransaction = await signer.signTransaction(rawTransaction);
|
|
1145
1088
|
* console.log('Tx hash:', ethers.keccak256(signedTransaction));
|
|
1146
|
-
*
|
|
1089
|
+
* await signer.sendTransaction(rawTransaction);
|
|
1090
|
+
* ```
|
|
1147
1091
|
*/
|
|
1148
1092
|
@requiresSigner
|
|
1149
1093
|
async createBulkPayoutTransaction(
|
|
@@ -1274,21 +1218,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1274
1218
|
/**
|
|
1275
1219
|
* This function returns the balance for a specified escrow address.
|
|
1276
1220
|
*
|
|
1277
|
-
* @param
|
|
1278
|
-
* @returns
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1221
|
+
* @param escrowAddress - Address of the escrow.
|
|
1222
|
+
* @returns Balance of the escrow in the token used to fund it.
|
|
1223
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1224
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1281
1225
|
*
|
|
1226
|
+
* @example
|
|
1282
1227
|
* ```ts
|
|
1283
|
-
* import { providers } from 'ethers';
|
|
1284
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1285
|
-
*
|
|
1286
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1287
|
-
*
|
|
1288
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1289
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1290
|
-
*
|
|
1291
1228
|
* const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1229
|
+
* console.log('Balance:', balance);
|
|
1292
1230
|
* ```
|
|
1293
1231
|
*/
|
|
1294
1232
|
async getBalance(escrowAddress: string): Promise<bigint> {
|
|
@@ -1318,21 +1256,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1318
1256
|
/**
|
|
1319
1257
|
* This function returns the reserved funds for a specified escrow address.
|
|
1320
1258
|
*
|
|
1321
|
-
* @param
|
|
1322
|
-
* @returns
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1259
|
+
* @param escrowAddress - Address of the escrow.
|
|
1260
|
+
* @returns Reserved funds of the escrow in the token used to fund it.
|
|
1261
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1262
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1325
1263
|
*
|
|
1264
|
+
* @example
|
|
1326
1265
|
* ```ts
|
|
1327
|
-
* import { providers } from 'ethers';
|
|
1328
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1329
|
-
*
|
|
1330
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1331
|
-
*
|
|
1332
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1333
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1334
|
-
*
|
|
1335
1266
|
* const reservedFunds = await escrowClient.getReservedFunds('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1267
|
+
* console.log('Reserved funds:', reservedFunds);
|
|
1336
1268
|
* ```
|
|
1337
1269
|
*/
|
|
1338
1270
|
async getReservedFunds(escrowAddress: string): Promise<bigint> {
|
|
@@ -1355,21 +1287,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1355
1287
|
/**
|
|
1356
1288
|
* This function returns the manifest file hash.
|
|
1357
1289
|
*
|
|
1358
|
-
* @param
|
|
1359
|
-
* @returns
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1290
|
+
* @param escrowAddress - Address of the escrow.
|
|
1291
|
+
* @returns Hash of the manifest file content.
|
|
1292
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1293
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1362
1294
|
*
|
|
1295
|
+
* @example
|
|
1363
1296
|
* ```ts
|
|
1364
|
-
* import { providers } from 'ethers';
|
|
1365
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1366
|
-
*
|
|
1367
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1368
|
-
*
|
|
1369
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1370
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1371
|
-
*
|
|
1372
1297
|
* const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1298
|
+
* console.log('Manifest hash:', manifestHash);
|
|
1373
1299
|
* ```
|
|
1374
1300
|
*/
|
|
1375
1301
|
async getManifestHash(escrowAddress: string): Promise<string> {
|
|
@@ -1393,21 +1319,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1393
1319
|
/**
|
|
1394
1320
|
* This function returns the manifest. Could be a URL or a JSON string.
|
|
1395
1321
|
*
|
|
1396
|
-
* @param
|
|
1397
|
-
* @returns
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1322
|
+
* @param escrowAddress - Address of the escrow.
|
|
1323
|
+
* @returns Manifest URL or JSON string.
|
|
1324
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1325
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1400
1326
|
*
|
|
1327
|
+
* @example
|
|
1401
1328
|
* ```ts
|
|
1402
|
-
* import { providers } from 'ethers';
|
|
1403
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1404
|
-
*
|
|
1405
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1406
|
-
*
|
|
1407
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1408
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1409
|
-
*
|
|
1410
1329
|
* const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1330
|
+
* console.log('Manifest:', manifest);
|
|
1411
1331
|
* ```
|
|
1412
1332
|
*/
|
|
1413
1333
|
async getManifest(escrowAddress: string): Promise<string> {
|
|
@@ -1431,21 +1351,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1431
1351
|
/**
|
|
1432
1352
|
* This function returns the results file URL.
|
|
1433
1353
|
*
|
|
1434
|
-
* @param
|
|
1435
|
-
* @returns
|
|
1436
|
-
*
|
|
1437
|
-
*
|
|
1354
|
+
* @param escrowAddress - Address of the escrow.
|
|
1355
|
+
* @returns Results file URL.
|
|
1356
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1357
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1438
1358
|
*
|
|
1359
|
+
* @example
|
|
1439
1360
|
* ```ts
|
|
1440
|
-
* import { providers } from 'ethers';
|
|
1441
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1442
|
-
*
|
|
1443
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1444
|
-
*
|
|
1445
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1446
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1447
|
-
*
|
|
1448
1361
|
* const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1362
|
+
* console.log('Results URL:', resultsUrl);
|
|
1449
1363
|
* ```
|
|
1450
1364
|
*/
|
|
1451
1365
|
async getResultsUrl(escrowAddress: string): Promise<string> {
|
|
@@ -1469,21 +1383,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1469
1383
|
/**
|
|
1470
1384
|
* This function returns the intermediate results file URL.
|
|
1471
1385
|
*
|
|
1472
|
-
* @param
|
|
1473
|
-
* @returns
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1386
|
+
* @param escrowAddress - Address of the escrow.
|
|
1387
|
+
* @returns URL of the file that stores results from Recording Oracle.
|
|
1388
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1389
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1476
1390
|
*
|
|
1391
|
+
* @example
|
|
1477
1392
|
* ```ts
|
|
1478
|
-
* import { providers } from 'ethers';
|
|
1479
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1480
|
-
*
|
|
1481
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1482
|
-
*
|
|
1483
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1484
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1485
|
-
*
|
|
1486
1393
|
* const intermediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1394
|
+
* console.log('Intermediate results URL:', intermediateResultsUrl);
|
|
1487
1395
|
* ```
|
|
1488
1396
|
*/
|
|
1489
1397
|
async getIntermediateResultsUrl(escrowAddress: string): Promise<string> {
|
|
@@ -1507,21 +1415,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1507
1415
|
/**
|
|
1508
1416
|
* This function returns the intermediate results hash.
|
|
1509
1417
|
*
|
|
1510
|
-
* @param
|
|
1511
|
-
* @returns
|
|
1512
|
-
*
|
|
1513
|
-
*
|
|
1418
|
+
* @param escrowAddress - Address of the escrow.
|
|
1419
|
+
* @returns Hash of the intermediate results file content.
|
|
1420
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1421
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1514
1422
|
*
|
|
1423
|
+
* @example
|
|
1515
1424
|
* ```ts
|
|
1516
|
-
* import { providers } from 'ethers';
|
|
1517
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1518
|
-
*
|
|
1519
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1520
|
-
*
|
|
1521
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1522
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1523
|
-
*
|
|
1524
1425
|
* const intermediateResultsHash = await escrowClient.getIntermediateResultsHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1426
|
+
* console.log('Intermediate results hash:', intermediateResultsHash);
|
|
1525
1427
|
* ```
|
|
1526
1428
|
*/
|
|
1527
1429
|
async getIntermediateResultsHash(escrowAddress: string): Promise<string> {
|
|
@@ -1545,21 +1447,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1545
1447
|
/**
|
|
1546
1448
|
* This function returns the token address used for funding the escrow.
|
|
1547
1449
|
*
|
|
1548
|
-
* @param
|
|
1549
|
-
* @returns
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1450
|
+
* @param escrowAddress - Address of the escrow.
|
|
1451
|
+
* @returns Address of the token used to fund the escrow.
|
|
1452
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1453
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1552
1454
|
*
|
|
1455
|
+
* @example
|
|
1553
1456
|
* ```ts
|
|
1554
|
-
* import { providers } from 'ethers';
|
|
1555
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1556
|
-
*
|
|
1557
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1558
|
-
*
|
|
1559
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1560
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1561
|
-
*
|
|
1562
1457
|
* const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1458
|
+
* console.log('Token address:', tokenAddress);
|
|
1563
1459
|
* ```
|
|
1564
1460
|
*/
|
|
1565
1461
|
async getTokenAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1583,21 +1479,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1583
1479
|
/**
|
|
1584
1480
|
* This function returns the current status of the escrow.
|
|
1585
1481
|
*
|
|
1586
|
-
* @param
|
|
1587
|
-
* @returns
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1482
|
+
* @param escrowAddress - Address of the escrow.
|
|
1483
|
+
* @returns Current status of the escrow.
|
|
1484
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1485
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1590
1486
|
*
|
|
1487
|
+
* @example
|
|
1591
1488
|
* ```ts
|
|
1592
|
-
* import {
|
|
1593
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1594
|
-
*
|
|
1595
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1596
|
-
*
|
|
1597
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1598
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1489
|
+
* import { EscrowStatus } from '@human-protocol/sdk';
|
|
1599
1490
|
*
|
|
1600
1491
|
* const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1492
|
+
* console.log('Status:', EscrowStatus[status]);
|
|
1601
1493
|
* ```
|
|
1602
1494
|
*/
|
|
1603
1495
|
async getStatus(escrowAddress: string): Promise<EscrowStatus> {
|
|
@@ -1621,21 +1513,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1621
1513
|
/**
|
|
1622
1514
|
* This function returns the recording oracle address for a given escrow.
|
|
1623
1515
|
*
|
|
1624
|
-
* @param
|
|
1625
|
-
* @returns
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1516
|
+
* @param escrowAddress - Address of the escrow.
|
|
1517
|
+
* @returns Address of the Recording Oracle.
|
|
1518
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1519
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1628
1520
|
*
|
|
1521
|
+
* @example
|
|
1629
1522
|
* ```ts
|
|
1630
|
-
* import { providers } from 'ethers';
|
|
1631
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1632
|
-
*
|
|
1633
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1634
|
-
*
|
|
1635
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1636
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1637
|
-
*
|
|
1638
1523
|
* const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1524
|
+
* console.log('Recording Oracle address:', oracleAddress);
|
|
1639
1525
|
* ```
|
|
1640
1526
|
*/
|
|
1641
1527
|
async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1659,21 +1545,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1659
1545
|
/**
|
|
1660
1546
|
* This function returns the job launcher address for a given escrow.
|
|
1661
1547
|
*
|
|
1662
|
-
* @param
|
|
1663
|
-
* @returns
|
|
1664
|
-
*
|
|
1665
|
-
*
|
|
1548
|
+
* @param escrowAddress - Address of the escrow.
|
|
1549
|
+
* @returns Address of the Job Launcher.
|
|
1550
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1551
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1666
1552
|
*
|
|
1553
|
+
* @example
|
|
1667
1554
|
* ```ts
|
|
1668
|
-
* import { providers } from 'ethers';
|
|
1669
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1670
|
-
*
|
|
1671
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1672
|
-
*
|
|
1673
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1674
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1675
|
-
*
|
|
1676
1555
|
* const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1556
|
+
* console.log('Job Launcher address:', jobLauncherAddress);
|
|
1677
1557
|
* ```
|
|
1678
1558
|
*/
|
|
1679
1559
|
async getJobLauncherAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1697,21 +1577,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1697
1577
|
/**
|
|
1698
1578
|
* This function returns the reputation oracle address for a given escrow.
|
|
1699
1579
|
*
|
|
1700
|
-
* @param
|
|
1701
|
-
* @returns
|
|
1702
|
-
*
|
|
1703
|
-
*
|
|
1580
|
+
* @param escrowAddress - Address of the escrow.
|
|
1581
|
+
* @returns Address of the Reputation Oracle.
|
|
1582
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1583
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1704
1584
|
*
|
|
1585
|
+
* @example
|
|
1705
1586
|
* ```ts
|
|
1706
|
-
* import { providers } from 'ethers';
|
|
1707
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1708
|
-
*
|
|
1709
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1710
|
-
*
|
|
1711
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1712
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1713
|
-
*
|
|
1714
1587
|
* const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1588
|
+
* console.log('Reputation Oracle address:', oracleAddress);
|
|
1715
1589
|
* ```
|
|
1716
1590
|
*/
|
|
1717
1591
|
async getReputationOracleAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1735,21 +1609,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1735
1609
|
/**
|
|
1736
1610
|
* This function returns the exchange oracle address for a given escrow.
|
|
1737
1611
|
*
|
|
1738
|
-
* @param
|
|
1739
|
-
* @returns
|
|
1740
|
-
*
|
|
1741
|
-
*
|
|
1612
|
+
* @param escrowAddress - Address of the escrow.
|
|
1613
|
+
* @returns Address of the Exchange Oracle.
|
|
1614
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1615
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1742
1616
|
*
|
|
1617
|
+
* @example
|
|
1743
1618
|
* ```ts
|
|
1744
|
-
* import { providers } from 'ethers';
|
|
1745
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1746
|
-
*
|
|
1747
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1748
|
-
*
|
|
1749
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1750
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1751
|
-
*
|
|
1752
1619
|
* const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1620
|
+
* console.log('Exchange Oracle address:', oracleAddress);
|
|
1753
1621
|
* ```
|
|
1754
1622
|
*/
|
|
1755
1623
|
async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1773,21 +1641,15 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1773
1641
|
/**
|
|
1774
1642
|
* This function returns the escrow factory address for a given escrow.
|
|
1775
1643
|
*
|
|
1776
|
-
* @param
|
|
1777
|
-
* @returns
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1644
|
+
* @param escrowAddress - Address of the escrow.
|
|
1645
|
+
* @returns Address of the escrow factory.
|
|
1646
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1647
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
1780
1648
|
*
|
|
1649
|
+
* @example
|
|
1781
1650
|
* ```ts
|
|
1782
|
-
* import { providers } from 'ethers';
|
|
1783
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
1784
|
-
*
|
|
1785
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
1786
|
-
*
|
|
1787
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1788
|
-
* const escrowClient = await EscrowClient.build(provider);
|
|
1789
|
-
*
|
|
1790
1651
|
* const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1652
|
+
* console.log('Factory address:', factoryAddress);
|
|
1791
1653
|
* ```
|
|
1792
1654
|
*/
|
|
1793
1655
|
async getFactoryAddress(escrowAddress: string): Promise<string> {
|
|
@@ -1809,138 +1671,40 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1809
1671
|
}
|
|
1810
1672
|
}
|
|
1811
1673
|
/**
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
* Utility class for escrow-related operations.
|
|
1815
|
-
*
|
|
1816
|
-
* ## Installation
|
|
1817
|
-
*
|
|
1818
|
-
* ### npm
|
|
1819
|
-
* ```bash
|
|
1820
|
-
* npm install @human-protocol/sdk
|
|
1821
|
-
* ```
|
|
1822
|
-
*
|
|
1823
|
-
* ### yarn
|
|
1824
|
-
* ```bash
|
|
1825
|
-
* yarn install @human-protocol/sdk
|
|
1826
|
-
* ```
|
|
1827
|
-
*
|
|
1828
|
-
* ## Code example
|
|
1829
|
-
*
|
|
1830
|
-
* ### Signer
|
|
1831
|
-
*
|
|
1832
|
-
* **Using private key(backend)**
|
|
1674
|
+
* Utility helpers for escrow-related queries.
|
|
1833
1675
|
*
|
|
1676
|
+
* @example
|
|
1834
1677
|
* ```ts
|
|
1835
1678
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1836
1679
|
*
|
|
1837
|
-
* const
|
|
1680
|
+
* const escrows = await EscrowUtils.getEscrows({
|
|
1838
1681
|
* chainId: ChainId.POLYGON_AMOY
|
|
1839
1682
|
* });
|
|
1683
|
+
* console.log('Escrows:', escrows);
|
|
1840
1684
|
* ```
|
|
1841
1685
|
*/
|
|
1842
1686
|
export class EscrowUtils {
|
|
1843
1687
|
/**
|
|
1844
1688
|
* This function returns an array of escrows based on the specified filter parameters.
|
|
1845
1689
|
*
|
|
1690
|
+
* @param filter - Filter parameters.
|
|
1691
|
+
* @param options - Optional configuration for subgraph requests.
|
|
1692
|
+
* @returns List of escrows that match the filter.
|
|
1693
|
+
* @throws ErrorInvalidAddress If any filter address is invalid
|
|
1694
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
1846
1695
|
*
|
|
1847
|
-
*
|
|
1848
|
-
*
|
|
1849
|
-
* ```ts
|
|
1850
|
-
* interface IEscrowsFilter {
|
|
1851
|
-
* chainId: ChainId;
|
|
1852
|
-
* launcher?: string;
|
|
1853
|
-
* reputationOracle?: string;
|
|
1854
|
-
* recordingOracle?: string;
|
|
1855
|
-
* exchangeOracle?: string;
|
|
1856
|
-
* jobRequesterId?: string;
|
|
1857
|
-
* status?: EscrowStatus;
|
|
1858
|
-
* from?: Date;
|
|
1859
|
-
* to?: Date;
|
|
1860
|
-
* first?: number;
|
|
1861
|
-
* skip?: number;
|
|
1862
|
-
* orderDirection?: OrderDirection;
|
|
1863
|
-
* }
|
|
1864
|
-
* ```
|
|
1865
|
-
*
|
|
1866
|
-
* ```ts
|
|
1867
|
-
* enum ChainId {
|
|
1868
|
-
* ALL = -1,
|
|
1869
|
-
* MAINNET = 1,
|
|
1870
|
-
* SEPOLIA = 11155111,
|
|
1871
|
-
* BSC_MAINNET = 56,
|
|
1872
|
-
* BSC_TESTNET = 97,
|
|
1873
|
-
* POLYGON = 137,
|
|
1874
|
-
* POLYGON_AMOY=80002,
|
|
1875
|
-
* LOCALHOST = 1338,
|
|
1876
|
-
* }
|
|
1877
|
-
* ```
|
|
1878
|
-
*
|
|
1879
|
-
* ```ts
|
|
1880
|
-
* enum OrderDirection {
|
|
1881
|
-
* ASC = 'asc',
|
|
1882
|
-
* DESC = 'desc',
|
|
1883
|
-
* }
|
|
1884
|
-
* ```
|
|
1885
|
-
*
|
|
1886
|
-
* ```ts
|
|
1887
|
-
* enum EscrowStatus {
|
|
1888
|
-
* Launched,
|
|
1889
|
-
* Pending,
|
|
1890
|
-
* Partial,
|
|
1891
|
-
* Paid,
|
|
1892
|
-
* Complete,
|
|
1893
|
-
* Cancelled,
|
|
1894
|
-
* }
|
|
1895
|
-
* ```
|
|
1896
|
-
*
|
|
1897
|
-
* ```ts
|
|
1898
|
-
* interface IEscrow {
|
|
1899
|
-
* id: string;
|
|
1900
|
-
* address: string;
|
|
1901
|
-
* amountPaid: bigint;
|
|
1902
|
-
* balance: bigint;
|
|
1903
|
-
* count: bigint;
|
|
1904
|
-
* factoryAddress: string;
|
|
1905
|
-
* finalResultsUrl: string | null;
|
|
1906
|
-
* finalResultsHash: string | null;
|
|
1907
|
-
* intermediateResultsUrl: string | null;
|
|
1908
|
-
* intermediateResultsHash: string | null;
|
|
1909
|
-
* launcher: string;
|
|
1910
|
-
* jobRequesterId: string | null;
|
|
1911
|
-
* manifestHash: string | null;
|
|
1912
|
-
* manifest: string | null;
|
|
1913
|
-
* recordingOracle: string | null;
|
|
1914
|
-
* reputationOracle: string | null;
|
|
1915
|
-
* exchangeOracle: string | null;
|
|
1916
|
-
* recordingOracleFee: number | null;
|
|
1917
|
-
* reputationOracleFee: number | null;
|
|
1918
|
-
* exchangeOracleFee: number | null;
|
|
1919
|
-
* status: string;
|
|
1920
|
-
* token: string;
|
|
1921
|
-
* totalFundedAmount: bigint;
|
|
1922
|
-
* createdAt: number;
|
|
1923
|
-
* chainId: number;
|
|
1924
|
-
* };
|
|
1925
|
-
* ```
|
|
1926
|
-
*
|
|
1927
|
-
*
|
|
1928
|
-
* @param {IEscrowsFilter} filter Filter parameters.
|
|
1929
|
-
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
1930
|
-
* @returns {IEscrow[]} List of escrows that match the filter.
|
|
1931
|
-
*
|
|
1932
|
-
* **Code example**
|
|
1933
|
-
*
|
|
1696
|
+
* @example
|
|
1934
1697
|
* ```ts
|
|
1935
|
-
* import { ChainId,
|
|
1698
|
+
* import { ChainId, EscrowStatus } from '@human-protocol/sdk';
|
|
1936
1699
|
*
|
|
1937
|
-
* const filters
|
|
1700
|
+
* const filters = {
|
|
1938
1701
|
* status: EscrowStatus.Pending,
|
|
1939
1702
|
* from: new Date(2023, 4, 8),
|
|
1940
1703
|
* to: new Date(2023, 5, 8),
|
|
1941
1704
|
* chainId: ChainId.POLYGON_AMOY
|
|
1942
1705
|
* };
|
|
1943
1706
|
* const escrows = await EscrowUtils.getEscrows(filters);
|
|
1707
|
+
* console.log('Found escrows:', escrows.length);
|
|
1944
1708
|
* ```
|
|
1945
1709
|
*/
|
|
1946
1710
|
public static async getEscrows(
|
|
@@ -2005,63 +1769,24 @@ export class EscrowUtils {
|
|
|
2005
1769
|
*
|
|
2006
1770
|
* > This uses Subgraph
|
|
2007
1771
|
*
|
|
2008
|
-
*
|
|
2009
|
-
*
|
|
2010
|
-
*
|
|
2011
|
-
*
|
|
2012
|
-
*
|
|
2013
|
-
*
|
|
2014
|
-
* SEPOLIA = 11155111,
|
|
2015
|
-
* BSC_MAINNET = 56,
|
|
2016
|
-
* BSC_TESTNET = 97,
|
|
2017
|
-
* POLYGON = 137,
|
|
2018
|
-
* POLYGON_AMOY = 80002,
|
|
2019
|
-
* LOCALHOST = 1338,
|
|
2020
|
-
* }
|
|
2021
|
-
* ```
|
|
2022
|
-
*
|
|
2023
|
-
* ```ts
|
|
2024
|
-
* interface IEscrow {
|
|
2025
|
-
* id: string;
|
|
2026
|
-
* address: string;
|
|
2027
|
-
* amountPaid: bigint;
|
|
2028
|
-
* balance: bigint;
|
|
2029
|
-
* count: bigint;
|
|
2030
|
-
* factoryAddress: string;
|
|
2031
|
-
* finalResultsUrl: string | null;
|
|
2032
|
-
* finalResultsHash: string | null;
|
|
2033
|
-
* intermediateResultsUrl: string | null;
|
|
2034
|
-
* intermediateResultsHash: string | null;
|
|
2035
|
-
* launcher: string;
|
|
2036
|
-
* jobRequesterId: string | null;
|
|
2037
|
-
* manifestHash: string | null;
|
|
2038
|
-
* manifest: string | null;
|
|
2039
|
-
* recordingOracle: string | null;
|
|
2040
|
-
* reputationOracle: string | null;
|
|
2041
|
-
* exchangeOracle: string | null;
|
|
2042
|
-
* recordingOracleFee: number | null;
|
|
2043
|
-
* reputationOracleFee: number | null;
|
|
2044
|
-
* exchangeOracleFee: number | null;
|
|
2045
|
-
* status: string;
|
|
2046
|
-
* token: string;
|
|
2047
|
-
* totalFundedAmount: bigint;
|
|
2048
|
-
* createdAt: number;
|
|
2049
|
-
* chainId: number;
|
|
2050
|
-
* };
|
|
2051
|
-
* ```
|
|
2052
|
-
*
|
|
2053
|
-
*
|
|
2054
|
-
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
2055
|
-
* @param {string} escrowAddress Address of the escrow
|
|
2056
|
-
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
2057
|
-
* @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
|
|
2058
|
-
*
|
|
2059
|
-
* **Code example**
|
|
1772
|
+
* @param chainId - Network in which the escrow has been deployed
|
|
1773
|
+
* @param escrowAddress - Address of the escrow
|
|
1774
|
+
* @param options - Optional configuration for subgraph requests.
|
|
1775
|
+
* @returns Escrow data or null if not found.
|
|
1776
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
1777
|
+
* @throws ErrorInvalidAddress If the escrow address is invalid
|
|
2060
1778
|
*
|
|
1779
|
+
* @example
|
|
2061
1780
|
* ```ts
|
|
2062
|
-
* import { ChainId
|
|
1781
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
2063
1782
|
*
|
|
2064
|
-
* const escrow =
|
|
1783
|
+
* const escrow = await EscrowUtils.getEscrow(
|
|
1784
|
+
* ChainId.POLYGON_AMOY,
|
|
1785
|
+
* "0x1234567890123456789012345678901234567890"
|
|
1786
|
+
* );
|
|
1787
|
+
* if (escrow) {
|
|
1788
|
+
* console.log('Escrow status:', escrow.status);
|
|
1789
|
+
* }
|
|
2065
1790
|
* ```
|
|
2066
1791
|
*/
|
|
2067
1792
|
public static async getEscrow(
|
|
@@ -2095,56 +1820,25 @@ export class EscrowUtils {
|
|
|
2095
1820
|
*
|
|
2096
1821
|
* > This uses Subgraph
|
|
2097
1822
|
*
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
* MAINNET = 1,
|
|
2104
|
-
* SEPOLIA = 11155111,
|
|
2105
|
-
* BSC_MAINNET = 56,
|
|
2106
|
-
* BSC_TESTNET = 97,
|
|
2107
|
-
* POLYGON = 137,
|
|
2108
|
-
* POLYGON_AMOY = 80002,
|
|
2109
|
-
* LOCALHOST = 1338,
|
|
2110
|
-
* }
|
|
2111
|
-
* ```
|
|
2112
|
-
*
|
|
2113
|
-
* ```ts
|
|
2114
|
-
* enum OrderDirection {
|
|
2115
|
-
* ASC = 'asc',
|
|
2116
|
-
* DESC = 'desc',
|
|
2117
|
-
* }
|
|
2118
|
-
* ```
|
|
1823
|
+
* @param filter - Filter parameters.
|
|
1824
|
+
* @param options - Optional configuration for subgraph requests.
|
|
1825
|
+
* @returns Array of status events with their corresponding statuses.
|
|
1826
|
+
* @throws ErrorInvalidAddress If the launcher address is invalid
|
|
1827
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
2119
1828
|
*
|
|
1829
|
+
* @example
|
|
2120
1830
|
* ```ts
|
|
2121
|
-
*
|
|
2122
|
-
* escrowAddress: string;
|
|
2123
|
-
* timestamp: string;
|
|
2124
|
-
* status: string;
|
|
2125
|
-
* };
|
|
2126
|
-
* ```
|
|
2127
|
-
*
|
|
2128
|
-
* @param {IStatusEventFilter} filter Filter parameters.
|
|
2129
|
-
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
2130
|
-
* @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
|
|
1831
|
+
* import { ChainId, EscrowStatus } from '@human-protocol/sdk';
|
|
2131
1832
|
*
|
|
2132
|
-
*
|
|
2133
|
-
*
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
*
|
|
2141
|
-
* chainId: ChainId.POLYGON,
|
|
2142
|
-
* statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
|
|
2143
|
-
* from: fromDate,
|
|
2144
|
-
* to: toDate
|
|
2145
|
-
* });
|
|
2146
|
-
* console.log(statusEvents);
|
|
2147
|
-
* })();
|
|
1833
|
+
* const fromDate = new Date('2023-01-01');
|
|
1834
|
+
* const toDate = new Date('2023-12-31');
|
|
1835
|
+
* const statusEvents = await EscrowUtils.getStatusEvents({
|
|
1836
|
+
* chainId: ChainId.POLYGON,
|
|
1837
|
+
* statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
|
|
1838
|
+
* from: fromDate,
|
|
1839
|
+
* to: toDate
|
|
1840
|
+
* });
|
|
1841
|
+
* console.log('Status events:', statusEvents.length);
|
|
2148
1842
|
* ```
|
|
2149
1843
|
*/
|
|
2150
1844
|
public static async getStatusEvents(
|
|
@@ -2217,17 +1911,15 @@ export class EscrowUtils {
|
|
|
2217
1911
|
*
|
|
2218
1912
|
* > This uses Subgraph
|
|
2219
1913
|
*
|
|
2220
|
-
*
|
|
2221
|
-
*
|
|
2222
|
-
*
|
|
2223
|
-
* @
|
|
2224
|
-
* @
|
|
2225
|
-
* @returns {Promise<IPayout[]>} List of payouts matching the filters.
|
|
2226
|
-
*
|
|
2227
|
-
* **Code example**
|
|
1914
|
+
* @param filter - Filter parameters.
|
|
1915
|
+
* @param options - Optional configuration for subgraph requests.
|
|
1916
|
+
* @returns List of payouts matching the filters.
|
|
1917
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
1918
|
+
* @throws ErrorInvalidAddress If any filter address is invalid
|
|
2228
1919
|
*
|
|
1920
|
+
* @example
|
|
2229
1921
|
* ```ts
|
|
2230
|
-
* import { ChainId
|
|
1922
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
2231
1923
|
*
|
|
2232
1924
|
* const payouts = await EscrowUtils.getPayouts({
|
|
2233
1925
|
* chainId: ChainId.POLYGON,
|
|
@@ -2236,7 +1928,7 @@ export class EscrowUtils {
|
|
|
2236
1928
|
* from: new Date('2023-01-01'),
|
|
2237
1929
|
* to: new Date('2023-12-31')
|
|
2238
1930
|
* });
|
|
2239
|
-
* console.log(payouts);
|
|
1931
|
+
* console.log('Payouts:', payouts.length);
|
|
2240
1932
|
* ```
|
|
2241
1933
|
*/
|
|
2242
1934
|
public static async getPayouts(
|
|
@@ -2291,48 +1983,22 @@ export class EscrowUtils {
|
|
|
2291
1983
|
*
|
|
2292
1984
|
* > This uses Subgraph
|
|
2293
1985
|
*
|
|
2294
|
-
*
|
|
2295
|
-
*
|
|
2296
|
-
*
|
|
2297
|
-
*
|
|
2298
|
-
*
|
|
2299
|
-
*
|
|
2300
|
-
* SEPOLIA = 11155111,
|
|
2301
|
-
* BSC_MAINNET = 56,
|
|
2302
|
-
* BSC_TESTNET = 97,
|
|
2303
|
-
* POLYGON = 137,
|
|
2304
|
-
* POLYGON_AMOY = 80002,
|
|
2305
|
-
* LOCALHOST = 1338,
|
|
2306
|
-
* }
|
|
2307
|
-
* ```
|
|
2308
|
-
*
|
|
2309
|
-
* ```ts
|
|
2310
|
-
* interface ICancellationRefund {
|
|
2311
|
-
* id: string;
|
|
2312
|
-
* escrowAddress: string;
|
|
2313
|
-
* receiver: string;
|
|
2314
|
-
* amount: bigint;
|
|
2315
|
-
* block: number;
|
|
2316
|
-
* timestamp: number;
|
|
2317
|
-
* txHash: string;
|
|
2318
|
-
* };
|
|
2319
|
-
* ```
|
|
2320
|
-
*
|
|
2321
|
-
*
|
|
2322
|
-
* @param {Object} filter Filter parameters.
|
|
2323
|
-
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
2324
|
-
* @returns {Promise<ICancellationRefund[]>} List of cancellation refunds matching the filters.
|
|
2325
|
-
*
|
|
2326
|
-
* **Code example**
|
|
1986
|
+
* @param filter - Filter parameters.
|
|
1987
|
+
* @param options - Optional configuration for subgraph requests.
|
|
1988
|
+
* @returns List of cancellation refunds matching the filters.
|
|
1989
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
1990
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
1991
|
+
* @throws ErrorInvalidAddress If the receiver address is invalid
|
|
2327
1992
|
*
|
|
1993
|
+
* @example
|
|
2328
1994
|
* ```ts
|
|
2329
|
-
* import { ChainId
|
|
1995
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
2330
1996
|
*
|
|
2331
1997
|
* const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
|
|
2332
1998
|
* chainId: ChainId.POLYGON_AMOY,
|
|
2333
1999
|
* escrowAddress: '0x1234567890123456789012345678901234567890',
|
|
2334
2000
|
* });
|
|
2335
|
-
* console.log(cancellationRefunds);
|
|
2001
|
+
* console.log('Cancellation refunds:', cancellationRefunds.length);
|
|
2336
2002
|
* ```
|
|
2337
2003
|
*/
|
|
2338
2004
|
public static async getCancellationRefunds(
|
|
@@ -2390,45 +2056,25 @@ export class EscrowUtils {
|
|
|
2390
2056
|
*
|
|
2391
2057
|
* > This uses Subgraph
|
|
2392
2058
|
*
|
|
2393
|
-
*
|
|
2394
|
-
*
|
|
2395
|
-
*
|
|
2396
|
-
*
|
|
2397
|
-
*
|
|
2398
|
-
*
|
|
2399
|
-
* SEPOLIA = 11155111,
|
|
2400
|
-
* BSC_MAINNET = 56,
|
|
2401
|
-
* BSC_TESTNET = 97,
|
|
2402
|
-
* POLYGON = 137,
|
|
2403
|
-
* POLYGON_AMOY = 80002,
|
|
2404
|
-
* LOCALHOST = 1338,
|
|
2405
|
-
* }
|
|
2406
|
-
* ```
|
|
2059
|
+
* @param chainId - Network in which the escrow has been deployed
|
|
2060
|
+
* @param escrowAddress - Address of the escrow
|
|
2061
|
+
* @param options - Optional configuration for subgraph requests.
|
|
2062
|
+
* @returns Cancellation refund data or null if not found.
|
|
2063
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
2064
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
2407
2065
|
*
|
|
2066
|
+
* @example
|
|
2408
2067
|
* ```ts
|
|
2409
|
-
*
|
|
2410
|
-
* id: string;
|
|
2411
|
-
* escrowAddress: string;
|
|
2412
|
-
* receiver: string;
|
|
2413
|
-
* amount: bigint;
|
|
2414
|
-
* block: number;
|
|
2415
|
-
* timestamp: number;
|
|
2416
|
-
* txHash: string;
|
|
2417
|
-
* };
|
|
2418
|
-
* ```
|
|
2419
|
-
*
|
|
2420
|
-
*
|
|
2421
|
-
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
2422
|
-
* @param {string} escrowAddress Address of the escrow
|
|
2423
|
-
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
2424
|
-
* @returns {Promise<ICancellationRefund>} Cancellation refund data
|
|
2068
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
2425
2069
|
*
|
|
2426
|
-
* **Code example**
|
|
2427
2070
|
*
|
|
2428
|
-
*
|
|
2429
|
-
*
|
|
2430
|
-
*
|
|
2431
|
-
*
|
|
2071
|
+
* const cancellationRefund = await EscrowUtils.getCancellationRefund(
|
|
2072
|
+
* ChainId.POLYGON_AMOY,
|
|
2073
|
+
* "0x1234567890123456789012345678901234567890"
|
|
2074
|
+
* );
|
|
2075
|
+
* if (cancellationRefund) {
|
|
2076
|
+
* console.log('Refund amount:', cancellationRefund.amount);
|
|
2077
|
+
* }
|
|
2432
2078
|
* ```
|
|
2433
2079
|
*/
|
|
2434
2080
|
public static async getCancellationRefund(
|