@human-protocol/sdk 6.0.0 → 7.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/CHANGELOG.md +34 -0
- package/dist/base.d.ts +4 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +14 -0
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +27 -16
- package/dist/encryption/encryption.d.ts +84 -0
- package/dist/encryption/encryption.d.ts.map +1 -0
- package/dist/{encryption.js → encryption/encryption.js} +3 -161
- package/dist/encryption/encryption_utils.d.ts +101 -0
- package/dist/encryption/encryption_utils.d.ts.map +1 -0
- package/dist/encryption/encryption_utils.js +191 -0
- package/dist/encryption/index.d.ts +4 -0
- package/dist/encryption/index.d.ts.map +1 -0
- package/dist/encryption/index.js +7 -0
- package/dist/encryption/types.d.ts +9 -0
- package/dist/encryption/types.d.ts.map +1 -0
- package/dist/encryption/types.js +9 -0
- package/dist/error.d.ts +6 -10
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -14
- package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +16 -196
- package/dist/escrow/escrow_client.d.ts.map +1 -0
- package/dist/{escrow.js → escrow/escrow_client.js} +50 -430
- package/dist/escrow/escrow_utils.d.ts +172 -0
- package/dist/escrow/escrow_utils.d.ts.map +1 -0
- package/dist/escrow/escrow_utils.js +388 -0
- package/dist/escrow/index.d.ts +3 -0
- package/dist/escrow/index.d.ts.map +1 -0
- package/dist/escrow/index.js +7 -0
- package/dist/graphql/queries/statistics.d.ts +1 -0
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +36 -2
- package/dist/graphql/types.d.ts +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -22
- package/dist/interfaces.d.ts +2 -7
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore/index.d.ts +3 -0
- package/dist/kvstore/index.d.ts.map +1 -0
- package/dist/kvstore/index.js +7 -0
- package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +7 -112
- package/dist/kvstore/kvstore_client.d.ts.map +1 -0
- package/dist/{kvstore.js → kvstore/kvstore_client.js} +25 -187
- package/dist/kvstore/kvstore_utils.d.ts +105 -0
- package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
- package/dist/kvstore/kvstore_utils.js +184 -0
- package/dist/operator/index.d.ts +2 -0
- package/dist/operator/index.d.ts.map +1 -0
- package/dist/operator/index.js +5 -0
- package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
- package/dist/operator/operator_utils.d.ts.map +1 -0
- package/dist/{operator.js → operator/operator_utils.js} +6 -6
- package/dist/staking/index.d.ts +3 -0
- package/dist/staking/index.d.ts.map +1 -0
- package/dist/staking/index.js +7 -0
- package/dist/{staking.d.ts → staking/staking_client.d.ts} +10 -71
- package/dist/staking/staking_client.d.ts.map +1 -0
- package/dist/{staking.js → staking/staking_client.js} +11 -141
- package/dist/staking/staking_utils.d.ts +63 -0
- package/dist/staking/staking_utils.d.ts.map +1 -0
- package/dist/staking/staking_utils.js +137 -0
- package/dist/statistics/index.d.ts +2 -0
- package/dist/statistics/index.d.ts.map +1 -0
- package/dist/statistics/index.js +5 -0
- package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
- package/dist/statistics/statistics_utils.d.ts.map +1 -0
- package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +5 -0
- package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +5 -5
- package/dist/transaction/transaction_utils.d.ts.map +1 -0
- package/dist/{transaction.js → transaction/transaction_utils.js} +9 -9
- package/dist/types.d.ts +22 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +16 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +72 -6
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +5 -0
- package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -3
- package/dist/worker/worker_utils.d.ts.map +1 -0
- package/dist/{worker.js → worker/worker_utils.js} +5 -5
- package/package.json +5 -5
- package/src/base.ts +38 -2
- package/src/constants.ts +38 -16
- package/src/{encryption.ts → encryption/encryption.ts} +1 -193
- package/src/encryption/encryption_utils.ts +179 -0
- package/src/encryption/index.ts +3 -0
- package/src/encryption/types.ts +15 -0
- package/src/error.ts +11 -17
- package/src/{escrow.ts → escrow/escrow_client.ts} +151 -659
- package/src/escrow/escrow_utils.ts +510 -0
- package/src/escrow/index.ts +2 -0
- package/src/graphql/queries/statistics.ts +37 -1
- package/src/graphql/types.ts +4 -1
- package/src/index.ts +11 -25
- package/src/interfaces.ts +2 -7
- package/src/kvstore/index.ts +2 -0
- package/src/kvstore/kvstore_client.ts +291 -0
- package/src/kvstore/kvstore_utils.ts +244 -0
- package/src/operator/index.ts +1 -0
- package/src/{operator.ts → operator/operator_utils.ts} +8 -8
- package/src/staking/index.ts +2 -0
- package/src/{staking.ts → staking/staking_client.ts} +49 -199
- package/src/staking/staking_utils.ts +170 -0
- package/src/statistics/index.ts +1 -0
- package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
- package/src/transaction/index.ts +1 -0
- package/src/{transaction.ts → transaction/transaction_utils.ts} +11 -11
- package/src/types.ts +24 -1
- package/src/utils.ts +82 -9
- package/src/worker/index.ts +1 -0
- package/src/{worker.ts → worker/worker_utils.ts} +7 -7
- package/dist/encryption.d.ts +0 -189
- package/dist/encryption.d.ts.map +0 -1
- package/dist/escrow.d.ts.map +0 -1
- package/dist/kvstore.d.ts.map +0 -1
- package/dist/operator.d.ts.map +0 -1
- package/dist/staking.d.ts.map +0 -1
- package/dist/statistics.d.ts.map +0 -1
- package/dist/transaction.d.ts.map +0 -1
- package/dist/worker.d.ts.map +0 -1
- package/src/kvstore.ts +0 -497
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
HMToken__factory,
|
|
11
11
|
} from '@human-protocol/core/typechain-types';
|
|
12
12
|
import { ContractRunner, EventLog, Overrides, Signer, ethers } from 'ethers';
|
|
13
|
-
import { BaseEthersClient } from '
|
|
14
|
-
import { ESCROW_BULK_PAYOUT_MAX_ITEMS, NETWORKS } from '
|
|
15
|
-
import { requiresSigner } from '
|
|
16
|
-
import { ChainId
|
|
13
|
+
import { BaseEthersClient } from '../base';
|
|
14
|
+
import { ESCROW_BULK_PAYOUT_MAX_ITEMS, NETWORKS } from '../constants';
|
|
15
|
+
import { requiresSigner } from '../decorators';
|
|
16
|
+
import { ChainId } from '../enums';
|
|
17
17
|
import {
|
|
18
18
|
ErrorAmountMustBeGreaterThanZero,
|
|
19
19
|
ErrorAmountsCannotBeEmptyArray,
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
ErrorEscrowAddressIsNotProvidedByFactory,
|
|
22
22
|
ErrorEscrowDoesNotHaveEnoughBalance,
|
|
23
23
|
ErrorHashIsEmptyString,
|
|
24
|
-
ErrorInvalidAddress,
|
|
25
24
|
ErrorInvalidEscrowAddressProvided,
|
|
26
25
|
ErrorInvalidExchangeOracleAddressProvided,
|
|
27
26
|
ErrorInvalidManifest,
|
|
@@ -35,46 +34,19 @@ import {
|
|
|
35
34
|
ErrorRecipientCannotBeEmptyArray,
|
|
36
35
|
ErrorStoreResultsVersion,
|
|
37
36
|
ErrorTooManyRecipients,
|
|
38
|
-
ErrorTotalFeeMustBeLessThanHundred,
|
|
39
37
|
ErrorTransferEventNotFoundInTransactionLogs,
|
|
40
38
|
ErrorUnsupportedChainID,
|
|
41
39
|
InvalidEthereumAddressError,
|
|
42
40
|
WarnVersionMismatch,
|
|
43
|
-
} from '
|
|
41
|
+
} from '../error';
|
|
42
|
+
import { IEscrowConfig, IEscrowWithdraw } from '../interfaces';
|
|
44
43
|
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
GET_PAYOUTS_QUERY,
|
|
52
|
-
GET_STATUS_UPDATES_QUERY,
|
|
53
|
-
PayoutData,
|
|
54
|
-
StatusEvent,
|
|
55
|
-
} from './graphql';
|
|
56
|
-
import {
|
|
57
|
-
IEscrow,
|
|
58
|
-
IEscrowConfig,
|
|
59
|
-
IEscrowsFilter,
|
|
60
|
-
IPayoutFilter,
|
|
61
|
-
IStatusEventFilter,
|
|
62
|
-
IStatusEvent,
|
|
63
|
-
ICancellationRefund,
|
|
64
|
-
ICancellationRefundFilter,
|
|
65
|
-
IPayout,
|
|
66
|
-
IEscrowWithdraw,
|
|
67
|
-
SubgraphOptions,
|
|
68
|
-
} from './interfaces';
|
|
69
|
-
import { EscrowStatus, NetworkData, TransactionLikeWithNonce } from './types';
|
|
70
|
-
import {
|
|
71
|
-
getSubgraphUrl,
|
|
72
|
-
getUnixTimestamp,
|
|
73
|
-
customGqlFetch,
|
|
74
|
-
isValidJson,
|
|
75
|
-
isValidUrl,
|
|
76
|
-
throwError,
|
|
77
|
-
} from './utils';
|
|
44
|
+
EscrowStatus,
|
|
45
|
+
NetworkData,
|
|
46
|
+
TransactionLikeWithNonce,
|
|
47
|
+
TransactionOverrides,
|
|
48
|
+
} from '../types';
|
|
49
|
+
import { getErrorMessage, isValidJson, isValidUrl, throwError } from '../utils';
|
|
78
50
|
|
|
79
51
|
/**
|
|
80
52
|
* Client to perform actions on Escrow contracts and obtain information from the contracts.
|
|
@@ -205,20 +177,22 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
205
177
|
public async createEscrow(
|
|
206
178
|
tokenAddress: string,
|
|
207
179
|
jobRequesterId: string,
|
|
208
|
-
txOptions:
|
|
180
|
+
txOptions: TransactionOverrides = {}
|
|
209
181
|
): Promise<string> {
|
|
210
182
|
if (!ethers.isAddress(tokenAddress)) {
|
|
211
183
|
throw ErrorInvalidTokenAddress;
|
|
212
184
|
}
|
|
213
185
|
|
|
214
186
|
try {
|
|
215
|
-
const result = await (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
187
|
+
const result = await this.sendTxAndWait(
|
|
188
|
+
(overrides) =>
|
|
189
|
+
this.escrowFactoryContract.createEscrow(
|
|
190
|
+
tokenAddress,
|
|
191
|
+
jobRequesterId,
|
|
192
|
+
overrides
|
|
193
|
+
),
|
|
194
|
+
txOptions
|
|
195
|
+
);
|
|
222
196
|
|
|
223
197
|
const event = (
|
|
224
198
|
result?.logs?.find(({ topics }) =>
|
|
@@ -241,9 +215,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
241
215
|
recordingOracle,
|
|
242
216
|
reputationOracle,
|
|
243
217
|
exchangeOracle,
|
|
244
|
-
recordingOracleFee,
|
|
245
|
-
reputationOracleFee,
|
|
246
|
-
exchangeOracleFee,
|
|
247
218
|
manifest,
|
|
248
219
|
manifestHash,
|
|
249
220
|
} = escrowConfig;
|
|
@@ -260,18 +231,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
260
231
|
throw ErrorInvalidExchangeOracleAddressProvided;
|
|
261
232
|
}
|
|
262
233
|
|
|
263
|
-
if (
|
|
264
|
-
recordingOracleFee <= 0 ||
|
|
265
|
-
reputationOracleFee <= 0 ||
|
|
266
|
-
exchangeOracleFee <= 0
|
|
267
|
-
) {
|
|
268
|
-
throw ErrorAmountMustBeGreaterThanZero;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (recordingOracleFee + reputationOracleFee + exchangeOracleFee > 100) {
|
|
272
|
-
throw ErrorTotalFeeMustBeLessThanHundred;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
234
|
const isManifestValid = isValidUrl(manifest) || isValidJson(manifest);
|
|
276
235
|
if (!isManifestValid) {
|
|
277
236
|
throw ErrorInvalidManifest;
|
|
@@ -296,8 +255,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
296
255
|
* @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
|
|
297
256
|
* @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
|
|
298
257
|
* @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
258
|
* @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
|
|
302
259
|
* @throws ErrorHashIsEmptyString If the manifest hash is empty
|
|
303
260
|
* @throws ErrorLaunchedEventIsNotEmitted If the LaunchedV2 event is not emitted
|
|
@@ -318,9 +275,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
318
275
|
* recordingOracle: '0xRecordingOracleAddress',
|
|
319
276
|
* reputationOracle: '0xReputationOracleAddress',
|
|
320
277
|
* exchangeOracle: '0xExchangeOracleAddress',
|
|
321
|
-
* recordingOracleFee: 5n,
|
|
322
|
-
* reputationOracleFee: 5n,
|
|
323
|
-
* exchangeOracleFee: 5n,
|
|
324
278
|
* manifest: 'https://example.com/manifest.json',
|
|
325
279
|
* manifestHash: 'manifestHash-123',
|
|
326
280
|
* };
|
|
@@ -340,7 +294,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
340
294
|
amount: bigint,
|
|
341
295
|
jobRequesterId: string,
|
|
342
296
|
escrowConfig: IEscrowConfig,
|
|
343
|
-
txOptions:
|
|
297
|
+
txOptions: TransactionOverrides = {}
|
|
344
298
|
): Promise<string> {
|
|
345
299
|
if (!ethers.isAddress(tokenAddress)) {
|
|
346
300
|
throw ErrorInvalidTokenAddress;
|
|
@@ -352,30 +306,26 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
352
306
|
recordingOracle,
|
|
353
307
|
reputationOracle,
|
|
354
308
|
exchangeOracle,
|
|
355
|
-
recordingOracleFee,
|
|
356
|
-
reputationOracleFee,
|
|
357
|
-
exchangeOracleFee,
|
|
358
309
|
manifest,
|
|
359
310
|
manifestHash,
|
|
360
311
|
} = escrowConfig;
|
|
361
312
|
|
|
362
313
|
try {
|
|
363
|
-
const result = await (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
).wait();
|
|
314
|
+
const result = await this.sendTxAndWait(
|
|
315
|
+
(overrides) =>
|
|
316
|
+
this.escrowFactoryContract.createFundAndSetupEscrow(
|
|
317
|
+
tokenAddress,
|
|
318
|
+
amount,
|
|
319
|
+
jobRequesterId,
|
|
320
|
+
reputationOracle,
|
|
321
|
+
recordingOracle,
|
|
322
|
+
exchangeOracle,
|
|
323
|
+
manifest,
|
|
324
|
+
manifestHash,
|
|
325
|
+
overrides
|
|
326
|
+
),
|
|
327
|
+
txOptions
|
|
328
|
+
);
|
|
379
329
|
|
|
380
330
|
const event = (
|
|
381
331
|
result?.logs?.find(({ topics }) =>
|
|
@@ -405,8 +355,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
405
355
|
* @throws ErrorInvalidRecordingOracleAddressProvided If the recording oracle address is invalid
|
|
406
356
|
* @throws ErrorInvalidReputationOracleAddressProvided If the reputation oracle address is invalid
|
|
407
357
|
* @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
358
|
* @throws ErrorInvalidManifest If the manifest is not a valid URL or JSON string
|
|
411
359
|
* @throws ErrorHashIsEmptyString If the manifest hash is empty
|
|
412
360
|
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
@@ -420,9 +368,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
420
368
|
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
421
369
|
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
422
370
|
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
423
|
-
* recordingOracleFee: 10n,
|
|
424
|
-
* reputationOracleFee: 10n,
|
|
425
|
-
* exchangeOracleFee: 10n,
|
|
426
371
|
* manifest: 'http://localhost/manifest.json',
|
|
427
372
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
428
373
|
* };
|
|
@@ -433,15 +378,12 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
433
378
|
async setup(
|
|
434
379
|
escrowAddress: string,
|
|
435
380
|
escrowConfig: IEscrowConfig,
|
|
436
|
-
txOptions:
|
|
381
|
+
txOptions: TransactionOverrides = {}
|
|
437
382
|
): Promise<void> {
|
|
438
383
|
const {
|
|
439
384
|
recordingOracle,
|
|
440
385
|
reputationOracle,
|
|
441
386
|
exchangeOracle,
|
|
442
|
-
recordingOracleFee,
|
|
443
|
-
reputationOracleFee,
|
|
444
|
-
exchangeOracleFee,
|
|
445
387
|
manifest,
|
|
446
388
|
manifestHash,
|
|
447
389
|
} = escrowConfig;
|
|
@@ -459,19 +401,18 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
459
401
|
try {
|
|
460
402
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
461
403
|
|
|
462
|
-
await (
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
).wait();
|
|
404
|
+
await this.sendTxAndWait(
|
|
405
|
+
(overrides) =>
|
|
406
|
+
escrowContract.setup(
|
|
407
|
+
reputationOracle,
|
|
408
|
+
recordingOracle,
|
|
409
|
+
exchangeOracle,
|
|
410
|
+
manifest,
|
|
411
|
+
manifestHash,
|
|
412
|
+
overrides
|
|
413
|
+
),
|
|
414
|
+
txOptions
|
|
415
|
+
);
|
|
475
416
|
|
|
476
417
|
return;
|
|
477
418
|
} catch (e) {
|
|
@@ -502,7 +443,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
502
443
|
async fund(
|
|
503
444
|
escrowAddress: string,
|
|
504
445
|
amount: bigint,
|
|
505
|
-
txOptions:
|
|
446
|
+
txOptions: TransactionOverrides = {}
|
|
506
447
|
): Promise<void> {
|
|
507
448
|
if (!ethers.isAddress(escrowAddress)) {
|
|
508
449
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -525,9 +466,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
525
466
|
tokenAddress,
|
|
526
467
|
this.runner
|
|
527
468
|
);
|
|
528
|
-
await (
|
|
529
|
-
|
|
530
|
-
|
|
469
|
+
await this.sendTxAndWait(
|
|
470
|
+
(overrides) => tokenContract.transfer(escrowAddress, amount, overrides),
|
|
471
|
+
txOptions
|
|
472
|
+
);
|
|
531
473
|
|
|
532
474
|
return;
|
|
533
475
|
} catch (e) {
|
|
@@ -564,7 +506,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
564
506
|
escrowAddress: string,
|
|
565
507
|
url: string,
|
|
566
508
|
hash: string,
|
|
567
|
-
txOptions?:
|
|
509
|
+
txOptions?: TransactionOverrides
|
|
568
510
|
): Promise<void>;
|
|
569
511
|
|
|
570
512
|
/**
|
|
@@ -604,7 +546,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
604
546
|
url: string,
|
|
605
547
|
hash: string,
|
|
606
548
|
fundsToReserve: bigint,
|
|
607
|
-
txOptions?:
|
|
549
|
+
txOptions?: TransactionOverrides
|
|
608
550
|
): Promise<void>;
|
|
609
551
|
|
|
610
552
|
@requiresSigner
|
|
@@ -612,14 +554,16 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
612
554
|
escrowAddress: string,
|
|
613
555
|
url: string,
|
|
614
556
|
hash: string,
|
|
615
|
-
a?: bigint |
|
|
616
|
-
b?:
|
|
557
|
+
a?: bigint | TransactionOverrides,
|
|
558
|
+
b?: TransactionOverrides
|
|
617
559
|
): Promise<void> {
|
|
618
560
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
619
561
|
|
|
620
562
|
const hasFundsToReserveParam = typeof a === 'bigint';
|
|
621
563
|
const fundsToReserve = hasFundsToReserveParam ? (a as bigint) : null;
|
|
622
|
-
const txOptions = (hasFundsToReserveParam ? b : a)
|
|
564
|
+
const txOptions = (hasFundsToReserveParam ? b : a) as
|
|
565
|
+
| TransactionOverrides
|
|
566
|
+
| undefined;
|
|
623
567
|
// When fundsToReserve is provided and is 0, allow empty URL.
|
|
624
568
|
// In this situation not solutions might have been provided so the escrow can be straight cancelled.
|
|
625
569
|
const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
|
|
@@ -640,24 +584,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
640
584
|
}
|
|
641
585
|
|
|
642
586
|
try {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
await escrowContract['storeResults(string,string)'](
|
|
655
|
-
url,
|
|
656
|
-
hash,
|
|
657
|
-
txOptions
|
|
658
|
-
)
|
|
659
|
-
).wait();
|
|
660
|
-
}
|
|
587
|
+
const txFactory = (overrides: Overrides) =>
|
|
588
|
+
fundsToReserve !== null
|
|
589
|
+
? escrowContract['storeResults(string,string,uint256)'](
|
|
590
|
+
url,
|
|
591
|
+
hash,
|
|
592
|
+
fundsToReserve,
|
|
593
|
+
overrides
|
|
594
|
+
)
|
|
595
|
+
: escrowContract['storeResults(string,string)'](url, hash, overrides);
|
|
596
|
+
|
|
597
|
+
await this.sendTxAndWait(txFactory, txOptions);
|
|
661
598
|
} catch (e) {
|
|
662
599
|
if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
663
600
|
throw ErrorStoreResultsVersion;
|
|
@@ -685,7 +622,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
685
622
|
@requiresSigner
|
|
686
623
|
async complete(
|
|
687
624
|
escrowAddress: string,
|
|
688
|
-
txOptions:
|
|
625
|
+
txOptions: TransactionOverrides = {}
|
|
689
626
|
): Promise<void> {
|
|
690
627
|
if (!ethers.isAddress(escrowAddress)) {
|
|
691
628
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -697,8 +634,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
697
634
|
|
|
698
635
|
try {
|
|
699
636
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
700
|
-
|
|
701
|
-
|
|
637
|
+
await this.sendTxAndWait(
|
|
638
|
+
(overrides) => escrowContract.complete(overrides),
|
|
639
|
+
txOptions
|
|
640
|
+
);
|
|
702
641
|
return;
|
|
703
642
|
} catch (e) {
|
|
704
643
|
return throwError(e);
|
|
@@ -759,7 +698,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
759
698
|
finalResultsHash: string,
|
|
760
699
|
txId: number,
|
|
761
700
|
forceComplete: boolean,
|
|
762
|
-
txOptions:
|
|
701
|
+
txOptions: TransactionOverrides
|
|
763
702
|
): Promise<void>;
|
|
764
703
|
|
|
765
704
|
/**
|
|
@@ -817,7 +756,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
817
756
|
finalResultsHash: string,
|
|
818
757
|
payoutId: string,
|
|
819
758
|
forceComplete: boolean,
|
|
820
|
-
txOptions:
|
|
759
|
+
txOptions: TransactionOverrides
|
|
821
760
|
): Promise<void>;
|
|
822
761
|
|
|
823
762
|
@requiresSigner
|
|
@@ -829,7 +768,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
829
768
|
finalResultsHash: string,
|
|
830
769
|
id: number | string,
|
|
831
770
|
forceComplete: boolean,
|
|
832
|
-
txOptions:
|
|
771
|
+
txOptions: TransactionOverrides = {}
|
|
833
772
|
): Promise<void> {
|
|
834
773
|
await this.ensureCorrectBulkPayoutInput(
|
|
835
774
|
escrowAddress,
|
|
@@ -843,35 +782,32 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
843
782
|
const idIsString = typeof id === 'string';
|
|
844
783
|
|
|
845
784
|
try {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
)
|
|
873
|
-
).wait();
|
|
874
|
-
}
|
|
785
|
+
const txFactory = (overrides: Overrides) =>
|
|
786
|
+
idIsString
|
|
787
|
+
? escrowContract[
|
|
788
|
+
'bulkPayOut(address[],uint256[],string,string,string,bool)'
|
|
789
|
+
](
|
|
790
|
+
recipients,
|
|
791
|
+
amounts,
|
|
792
|
+
finalResultsUrl,
|
|
793
|
+
finalResultsHash,
|
|
794
|
+
id,
|
|
795
|
+
forceComplete,
|
|
796
|
+
overrides
|
|
797
|
+
)
|
|
798
|
+
: escrowContract[
|
|
799
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
800
|
+
](
|
|
801
|
+
recipients,
|
|
802
|
+
amounts,
|
|
803
|
+
finalResultsUrl,
|
|
804
|
+
finalResultsHash,
|
|
805
|
+
id,
|
|
806
|
+
forceComplete,
|
|
807
|
+
overrides
|
|
808
|
+
);
|
|
809
|
+
|
|
810
|
+
await this.sendTxAndWait(txFactory, txOptions);
|
|
875
811
|
} catch (e) {
|
|
876
812
|
if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
877
813
|
throw ErrorBulkPayOutVersion;
|
|
@@ -900,7 +836,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
900
836
|
@requiresSigner
|
|
901
837
|
async cancel(
|
|
902
838
|
escrowAddress: string,
|
|
903
|
-
txOptions:
|
|
839
|
+
txOptions: TransactionOverrides = {}
|
|
904
840
|
): Promise<void> {
|
|
905
841
|
if (!ethers.isAddress(escrowAddress)) {
|
|
906
842
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -912,7 +848,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
912
848
|
|
|
913
849
|
try {
|
|
914
850
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
915
|
-
await
|
|
851
|
+
await this.sendTxAndWait(
|
|
852
|
+
(overrides) => escrowContract.cancel(overrides),
|
|
853
|
+
txOptions
|
|
854
|
+
);
|
|
916
855
|
} catch (e) {
|
|
917
856
|
return throwError(e);
|
|
918
857
|
}
|
|
@@ -936,7 +875,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
936
875
|
@requiresSigner
|
|
937
876
|
async requestCancellation(
|
|
938
877
|
escrowAddress: string,
|
|
939
|
-
txOptions:
|
|
878
|
+
txOptions: TransactionOverrides = {}
|
|
940
879
|
): Promise<void> {
|
|
941
880
|
if (!ethers.isAddress(escrowAddress)) {
|
|
942
881
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -948,7 +887,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
948
887
|
|
|
949
888
|
try {
|
|
950
889
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
951
|
-
await
|
|
890
|
+
await this.sendTxAndWait(
|
|
891
|
+
(overrides) => escrowContract.requestCancellation(overrides),
|
|
892
|
+
txOptions
|
|
893
|
+
);
|
|
952
894
|
} catch (e) {
|
|
953
895
|
return throwError(e);
|
|
954
896
|
}
|
|
@@ -981,7 +923,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
981
923
|
async withdraw(
|
|
982
924
|
escrowAddress: string,
|
|
983
925
|
tokenAddress: string,
|
|
984
|
-
txOptions:
|
|
926
|
+
txOptions: TransactionOverrides = {}
|
|
985
927
|
): Promise<IEscrowWithdraw> {
|
|
986
928
|
if (!ethers.isAddress(escrowAddress)) {
|
|
987
929
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -997,10 +939,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
997
939
|
|
|
998
940
|
try {
|
|
999
941
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
)
|
|
942
|
+
const transactionReceipt = await this.sendTxAndWait(
|
|
943
|
+
(overrides) => escrowContract.withdraw(tokenAddress, overrides),
|
|
944
|
+
txOptions
|
|
945
|
+
);
|
|
1004
946
|
|
|
1005
947
|
let amountTransferred: bigint | undefined = undefined;
|
|
1006
948
|
|
|
@@ -1342,7 +1284,34 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1342
1284
|
try {
|
|
1343
1285
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1344
1286
|
|
|
1345
|
-
|
|
1287
|
+
try {
|
|
1288
|
+
return await escrowContract.manifest();
|
|
1289
|
+
} catch (manifestError) {
|
|
1290
|
+
// Fallback for legacy escrows exposing `manifestUrl()` instead of `manifest()`.
|
|
1291
|
+
try {
|
|
1292
|
+
const provider = this.runner.provider;
|
|
1293
|
+
if (!provider) {
|
|
1294
|
+
throw ErrorProviderDoesNotExist;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const manifestInterface = new ethers.Interface([
|
|
1298
|
+
'function manifestUrl() view returns (string)',
|
|
1299
|
+
]);
|
|
1300
|
+
const target = escrowContract.target as string;
|
|
1301
|
+
const data = manifestInterface.encodeFunctionData('manifestUrl');
|
|
1302
|
+
const result = await provider.call({ to: target, data });
|
|
1303
|
+
return manifestInterface.decodeFunctionResult(
|
|
1304
|
+
'manifestUrl',
|
|
1305
|
+
result
|
|
1306
|
+
)[0] as string;
|
|
1307
|
+
} catch (fallbackError) {
|
|
1308
|
+
throw new Error(
|
|
1309
|
+
`Failed to fetch manifest using both manifest() and manifestUrl(). ` +
|
|
1310
|
+
`manifest() error: ${getErrorMessage(manifestError)}. ` +
|
|
1311
|
+
`manifestUrl() error: ${getErrorMessage(fallbackError)}.`
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1346
1315
|
} catch (e) {
|
|
1347
1316
|
return throwError(e);
|
|
1348
1317
|
}
|
|
@@ -1670,480 +1639,3 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1670
1639
|
}
|
|
1671
1640
|
}
|
|
1672
1641
|
}
|
|
1673
|
-
/**
|
|
1674
|
-
* Utility helpers for escrow-related queries.
|
|
1675
|
-
*
|
|
1676
|
-
* @example
|
|
1677
|
-
* ```ts
|
|
1678
|
-
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1679
|
-
*
|
|
1680
|
-
* const escrows = await EscrowUtils.getEscrows({
|
|
1681
|
-
* chainId: ChainId.POLYGON_AMOY
|
|
1682
|
-
* });
|
|
1683
|
-
* console.log('Escrows:', escrows);
|
|
1684
|
-
* ```
|
|
1685
|
-
*/
|
|
1686
|
-
export class EscrowUtils {
|
|
1687
|
-
/**
|
|
1688
|
-
* This function returns an array of escrows based on the specified filter parameters.
|
|
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
|
|
1695
|
-
*
|
|
1696
|
-
* @example
|
|
1697
|
-
* ```ts
|
|
1698
|
-
* import { ChainId, EscrowStatus } from '@human-protocol/sdk';
|
|
1699
|
-
*
|
|
1700
|
-
* const filters = {
|
|
1701
|
-
* status: EscrowStatus.Pending,
|
|
1702
|
-
* from: new Date(2023, 4, 8),
|
|
1703
|
-
* to: new Date(2023, 5, 8),
|
|
1704
|
-
* chainId: ChainId.POLYGON_AMOY
|
|
1705
|
-
* };
|
|
1706
|
-
* const escrows = await EscrowUtils.getEscrows(filters);
|
|
1707
|
-
* console.log('Found escrows:', escrows.length);
|
|
1708
|
-
* ```
|
|
1709
|
-
*/
|
|
1710
|
-
public static async getEscrows(
|
|
1711
|
-
filter: IEscrowsFilter,
|
|
1712
|
-
options?: SubgraphOptions
|
|
1713
|
-
): Promise<IEscrow[]> {
|
|
1714
|
-
if (filter.launcher && !ethers.isAddress(filter.launcher)) {
|
|
1715
|
-
throw ErrorInvalidAddress;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
if (filter.recordingOracle && !ethers.isAddress(filter.recordingOracle)) {
|
|
1719
|
-
throw ErrorInvalidAddress;
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
if (filter.reputationOracle && !ethers.isAddress(filter.reputationOracle)) {
|
|
1723
|
-
throw ErrorInvalidAddress;
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
if (filter.exchangeOracle && !ethers.isAddress(filter.exchangeOracle)) {
|
|
1727
|
-
throw ErrorInvalidAddress;
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
const first =
|
|
1731
|
-
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
1732
|
-
const skip = filter.skip || 0;
|
|
1733
|
-
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
1734
|
-
|
|
1735
|
-
const networkData = NETWORKS[filter.chainId];
|
|
1736
|
-
|
|
1737
|
-
if (!networkData) {
|
|
1738
|
-
throw ErrorUnsupportedChainID;
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
let statuses;
|
|
1742
|
-
if (filter.status !== undefined) {
|
|
1743
|
-
statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
1744
|
-
statuses = statuses.map((status) => EscrowStatus[status]);
|
|
1745
|
-
}
|
|
1746
|
-
const { escrows } = await customGqlFetch<{ escrows: EscrowData[] }>(
|
|
1747
|
-
getSubgraphUrl(networkData),
|
|
1748
|
-
GET_ESCROWS_QUERY(filter),
|
|
1749
|
-
{
|
|
1750
|
-
...filter,
|
|
1751
|
-
launcher: filter.launcher?.toLowerCase(),
|
|
1752
|
-
reputationOracle: filter.reputationOracle?.toLowerCase(),
|
|
1753
|
-
recordingOracle: filter.recordingOracle?.toLowerCase(),
|
|
1754
|
-
exchangeOracle: filter.exchangeOracle?.toLowerCase(),
|
|
1755
|
-
status: statuses,
|
|
1756
|
-
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
1757
|
-
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
1758
|
-
orderDirection: orderDirection,
|
|
1759
|
-
first: first,
|
|
1760
|
-
skip: skip,
|
|
1761
|
-
},
|
|
1762
|
-
options
|
|
1763
|
-
);
|
|
1764
|
-
return (escrows || []).map((e) => mapEscrow(e, networkData.chainId));
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
/**
|
|
1768
|
-
* This function returns the escrow data for a given address.
|
|
1769
|
-
*
|
|
1770
|
-
* > This uses Subgraph
|
|
1771
|
-
*
|
|
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
|
|
1778
|
-
*
|
|
1779
|
-
* @example
|
|
1780
|
-
* ```ts
|
|
1781
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
1782
|
-
*
|
|
1783
|
-
* const escrow = await EscrowUtils.getEscrow(
|
|
1784
|
-
* ChainId.POLYGON_AMOY,
|
|
1785
|
-
* "0x1234567890123456789012345678901234567890"
|
|
1786
|
-
* );
|
|
1787
|
-
* if (escrow) {
|
|
1788
|
-
* console.log('Escrow status:', escrow.status);
|
|
1789
|
-
* }
|
|
1790
|
-
* ```
|
|
1791
|
-
*/
|
|
1792
|
-
public static async getEscrow(
|
|
1793
|
-
chainId: ChainId,
|
|
1794
|
-
escrowAddress: string,
|
|
1795
|
-
options?: SubgraphOptions
|
|
1796
|
-
): Promise<IEscrow | null> {
|
|
1797
|
-
const networkData = NETWORKS[chainId];
|
|
1798
|
-
|
|
1799
|
-
if (!networkData) {
|
|
1800
|
-
throw ErrorUnsupportedChainID;
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
if (escrowAddress && !ethers.isAddress(escrowAddress)) {
|
|
1804
|
-
throw ErrorInvalidAddress;
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
const { escrow } = await customGqlFetch<{ escrow: EscrowData | null }>(
|
|
1808
|
-
getSubgraphUrl(networkData),
|
|
1809
|
-
GET_ESCROW_BY_ADDRESS_QUERY(),
|
|
1810
|
-
{ escrowAddress: escrowAddress.toLowerCase() },
|
|
1811
|
-
options
|
|
1812
|
-
);
|
|
1813
|
-
if (!escrow) return null;
|
|
1814
|
-
|
|
1815
|
-
return mapEscrow(escrow, networkData.chainId);
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
/**
|
|
1819
|
-
* This function returns the status events for a given set of networks within an optional date range.
|
|
1820
|
-
*
|
|
1821
|
-
* > This uses Subgraph
|
|
1822
|
-
*
|
|
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
|
|
1828
|
-
*
|
|
1829
|
-
* @example
|
|
1830
|
-
* ```ts
|
|
1831
|
-
* import { ChainId, EscrowStatus } from '@human-protocol/sdk';
|
|
1832
|
-
*
|
|
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);
|
|
1842
|
-
* ```
|
|
1843
|
-
*/
|
|
1844
|
-
public static async getStatusEvents(
|
|
1845
|
-
filter: IStatusEventFilter,
|
|
1846
|
-
options?: SubgraphOptions
|
|
1847
|
-
): Promise<IStatusEvent[]> {
|
|
1848
|
-
const {
|
|
1849
|
-
chainId,
|
|
1850
|
-
statuses,
|
|
1851
|
-
from,
|
|
1852
|
-
to,
|
|
1853
|
-
launcher,
|
|
1854
|
-
first = 10,
|
|
1855
|
-
skip = 0,
|
|
1856
|
-
orderDirection = OrderDirection.DESC,
|
|
1857
|
-
} = filter;
|
|
1858
|
-
|
|
1859
|
-
if (launcher && !ethers.isAddress(launcher)) {
|
|
1860
|
-
throw ErrorInvalidAddress;
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
const networkData = NETWORKS[chainId];
|
|
1864
|
-
if (!networkData) {
|
|
1865
|
-
throw ErrorUnsupportedChainID;
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
// If statuses are not provided, use all statuses except Launched
|
|
1869
|
-
const effectiveStatuses = statuses ?? [
|
|
1870
|
-
EscrowStatus.Launched,
|
|
1871
|
-
EscrowStatus.Pending,
|
|
1872
|
-
EscrowStatus.Partial,
|
|
1873
|
-
EscrowStatus.Paid,
|
|
1874
|
-
EscrowStatus.Complete,
|
|
1875
|
-
EscrowStatus.Cancelled,
|
|
1876
|
-
];
|
|
1877
|
-
|
|
1878
|
-
const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
|
|
1879
|
-
|
|
1880
|
-
const data = await customGqlFetch<{
|
|
1881
|
-
escrowStatusEvents: StatusEvent[];
|
|
1882
|
-
}>(
|
|
1883
|
-
getSubgraphUrl(networkData),
|
|
1884
|
-
GET_STATUS_UPDATES_QUERY(from, to, launcher),
|
|
1885
|
-
{
|
|
1886
|
-
status: statusNames,
|
|
1887
|
-
from: from ? getUnixTimestamp(from) : undefined,
|
|
1888
|
-
to: to ? getUnixTimestamp(to) : undefined,
|
|
1889
|
-
launcher: launcher || undefined,
|
|
1890
|
-
orderDirection,
|
|
1891
|
-
first: Math.min(first, 1000),
|
|
1892
|
-
skip,
|
|
1893
|
-
},
|
|
1894
|
-
options
|
|
1895
|
-
);
|
|
1896
|
-
|
|
1897
|
-
if (!data || !data['escrowStatusEvents']) {
|
|
1898
|
-
return [];
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
return data['escrowStatusEvents'].map((event) => ({
|
|
1902
|
-
timestamp: Number(event.timestamp) * 1000,
|
|
1903
|
-
escrowAddress: event.escrowAddress,
|
|
1904
|
-
status: EscrowStatus[event.status as keyof typeof EscrowStatus],
|
|
1905
|
-
chainId,
|
|
1906
|
-
}));
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* This function returns the payouts for a given set of networks.
|
|
1911
|
-
*
|
|
1912
|
-
* > This uses Subgraph
|
|
1913
|
-
*
|
|
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
|
|
1919
|
-
*
|
|
1920
|
-
* @example
|
|
1921
|
-
* ```ts
|
|
1922
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
1923
|
-
*
|
|
1924
|
-
* const payouts = await EscrowUtils.getPayouts({
|
|
1925
|
-
* chainId: ChainId.POLYGON,
|
|
1926
|
-
* escrowAddress: '0x1234567890123456789012345678901234567890',
|
|
1927
|
-
* recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
|
|
1928
|
-
* from: new Date('2023-01-01'),
|
|
1929
|
-
* to: new Date('2023-12-31')
|
|
1930
|
-
* });
|
|
1931
|
-
* console.log('Payouts:', payouts.length);
|
|
1932
|
-
* ```
|
|
1933
|
-
*/
|
|
1934
|
-
public static async getPayouts(
|
|
1935
|
-
filter: IPayoutFilter,
|
|
1936
|
-
options?: SubgraphOptions
|
|
1937
|
-
): Promise<IPayout[]> {
|
|
1938
|
-
const networkData = NETWORKS[filter.chainId];
|
|
1939
|
-
if (!networkData) {
|
|
1940
|
-
throw ErrorUnsupportedChainID;
|
|
1941
|
-
}
|
|
1942
|
-
if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
|
|
1943
|
-
throw ErrorInvalidAddress;
|
|
1944
|
-
}
|
|
1945
|
-
if (filter.recipient && !ethers.isAddress(filter.recipient)) {
|
|
1946
|
-
throw ErrorInvalidAddress;
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
const first =
|
|
1950
|
-
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
1951
|
-
const skip = filter.skip || 0;
|
|
1952
|
-
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
1953
|
-
|
|
1954
|
-
const { payouts } = await customGqlFetch<{ payouts: PayoutData[] }>(
|
|
1955
|
-
getSubgraphUrl(networkData),
|
|
1956
|
-
GET_PAYOUTS_QUERY(filter),
|
|
1957
|
-
{
|
|
1958
|
-
escrowAddress: filter.escrowAddress?.toLowerCase(),
|
|
1959
|
-
recipient: filter.recipient?.toLowerCase(),
|
|
1960
|
-
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
1961
|
-
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
1962
|
-
first: Math.min(first, 1000),
|
|
1963
|
-
skip,
|
|
1964
|
-
orderDirection,
|
|
1965
|
-
},
|
|
1966
|
-
options
|
|
1967
|
-
);
|
|
1968
|
-
if (!payouts) {
|
|
1969
|
-
return [];
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
return payouts.map((payout) => ({
|
|
1973
|
-
id: payout.id,
|
|
1974
|
-
escrowAddress: payout.escrowAddress,
|
|
1975
|
-
recipient: payout.recipient,
|
|
1976
|
-
amount: BigInt(payout.amount),
|
|
1977
|
-
createdAt: Number(payout.createdAt) * 1000,
|
|
1978
|
-
}));
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
/**
|
|
1982
|
-
* This function returns the cancellation refunds for a given set of networks.
|
|
1983
|
-
*
|
|
1984
|
-
* > This uses Subgraph
|
|
1985
|
-
*
|
|
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
|
|
1992
|
-
*
|
|
1993
|
-
* @example
|
|
1994
|
-
* ```ts
|
|
1995
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
1996
|
-
*
|
|
1997
|
-
* const cancellationRefunds = await EscrowUtils.getCancellationRefunds({
|
|
1998
|
-
* chainId: ChainId.POLYGON_AMOY,
|
|
1999
|
-
* escrowAddress: '0x1234567890123456789012345678901234567890',
|
|
2000
|
-
* });
|
|
2001
|
-
* console.log('Cancellation refunds:', cancellationRefunds.length);
|
|
2002
|
-
* ```
|
|
2003
|
-
*/
|
|
2004
|
-
public static async getCancellationRefunds(
|
|
2005
|
-
filter: ICancellationRefundFilter,
|
|
2006
|
-
options?: SubgraphOptions
|
|
2007
|
-
): Promise<ICancellationRefund[]> {
|
|
2008
|
-
const networkData = NETWORKS[filter.chainId];
|
|
2009
|
-
if (!networkData) throw ErrorUnsupportedChainID;
|
|
2010
|
-
if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
|
|
2011
|
-
throw ErrorInvalidEscrowAddressProvided;
|
|
2012
|
-
}
|
|
2013
|
-
if (filter.receiver && !ethers.isAddress(filter.receiver)) {
|
|
2014
|
-
throw ErrorInvalidAddress;
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
const first =
|
|
2018
|
-
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
2019
|
-
const skip = filter.skip || 0;
|
|
2020
|
-
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
2021
|
-
|
|
2022
|
-
const { cancellationRefundEvents } = await customGqlFetch<{
|
|
2023
|
-
cancellationRefundEvents: CancellationRefundData[];
|
|
2024
|
-
}>(
|
|
2025
|
-
getSubgraphUrl(networkData),
|
|
2026
|
-
GET_CANCELLATION_REFUNDS_QUERY(filter),
|
|
2027
|
-
{
|
|
2028
|
-
escrowAddress: filter.escrowAddress?.toLowerCase(),
|
|
2029
|
-
receiver: filter.receiver?.toLowerCase(),
|
|
2030
|
-
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
2031
|
-
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
2032
|
-
first,
|
|
2033
|
-
skip,
|
|
2034
|
-
orderDirection,
|
|
2035
|
-
},
|
|
2036
|
-
options
|
|
2037
|
-
);
|
|
2038
|
-
|
|
2039
|
-
if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
|
|
2040
|
-
return [];
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
return cancellationRefundEvents.map((event) => ({
|
|
2044
|
-
id: event.id,
|
|
2045
|
-
escrowAddress: event.escrowAddress,
|
|
2046
|
-
receiver: event.receiver,
|
|
2047
|
-
amount: BigInt(event.amount),
|
|
2048
|
-
block: Number(event.block),
|
|
2049
|
-
timestamp: Number(event.timestamp) * 1000,
|
|
2050
|
-
txHash: event.txHash,
|
|
2051
|
-
}));
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
/**
|
|
2055
|
-
* This function returns the cancellation refund for a given escrow address.
|
|
2056
|
-
*
|
|
2057
|
-
* > This uses Subgraph
|
|
2058
|
-
*
|
|
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
|
|
2065
|
-
*
|
|
2066
|
-
* @example
|
|
2067
|
-
* ```ts
|
|
2068
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
2071
|
-
* const cancellationRefund = await EscrowUtils.getCancellationRefund(
|
|
2072
|
-
* ChainId.POLYGON_AMOY,
|
|
2073
|
-
* "0x1234567890123456789012345678901234567890"
|
|
2074
|
-
* );
|
|
2075
|
-
* if (cancellationRefund) {
|
|
2076
|
-
* console.log('Refund amount:', cancellationRefund.amount);
|
|
2077
|
-
* }
|
|
2078
|
-
* ```
|
|
2079
|
-
*/
|
|
2080
|
-
public static async getCancellationRefund(
|
|
2081
|
-
chainId: ChainId,
|
|
2082
|
-
escrowAddress: string,
|
|
2083
|
-
options?: SubgraphOptions
|
|
2084
|
-
): Promise<ICancellationRefund | null> {
|
|
2085
|
-
const networkData = NETWORKS[chainId];
|
|
2086
|
-
if (!networkData) throw ErrorUnsupportedChainID;
|
|
2087
|
-
|
|
2088
|
-
if (!ethers.isAddress(escrowAddress)) {
|
|
2089
|
-
throw ErrorInvalidEscrowAddressProvided;
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
const { cancellationRefundEvents } = await customGqlFetch<{
|
|
2093
|
-
cancellationRefundEvents: CancellationRefundData[];
|
|
2094
|
-
}>(
|
|
2095
|
-
getSubgraphUrl(networkData),
|
|
2096
|
-
GET_CANCELLATION_REFUND_BY_ADDRESS_QUERY(),
|
|
2097
|
-
{ escrowAddress: escrowAddress.toLowerCase() },
|
|
2098
|
-
options
|
|
2099
|
-
);
|
|
2100
|
-
|
|
2101
|
-
if (!cancellationRefundEvents || cancellationRefundEvents.length === 0) {
|
|
2102
|
-
return null;
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
return {
|
|
2106
|
-
id: cancellationRefundEvents[0].id,
|
|
2107
|
-
escrowAddress: cancellationRefundEvents[0].escrowAddress,
|
|
2108
|
-
receiver: cancellationRefundEvents[0].receiver,
|
|
2109
|
-
amount: BigInt(cancellationRefundEvents[0].amount),
|
|
2110
|
-
block: Number(cancellationRefundEvents[0].block),
|
|
2111
|
-
timestamp: Number(cancellationRefundEvents[0].timestamp) * 1000,
|
|
2112
|
-
txHash: cancellationRefundEvents[0].txHash,
|
|
2113
|
-
};
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
function mapEscrow(e: EscrowData, chainId: ChainId | number): IEscrow {
|
|
2118
|
-
return {
|
|
2119
|
-
id: e.id,
|
|
2120
|
-
address: e.address,
|
|
2121
|
-
amountPaid: BigInt(e.amountPaid),
|
|
2122
|
-
balance: BigInt(e.balance),
|
|
2123
|
-
count: Number(e.count),
|
|
2124
|
-
factoryAddress: e.factoryAddress,
|
|
2125
|
-
finalResultsUrl: e.finalResultsUrl,
|
|
2126
|
-
finalResultsHash: e.finalResultsHash,
|
|
2127
|
-
intermediateResultsUrl: e.intermediateResultsUrl,
|
|
2128
|
-
intermediateResultsHash: e.intermediateResultsHash,
|
|
2129
|
-
launcher: e.launcher,
|
|
2130
|
-
jobRequesterId: e.jobRequesterId,
|
|
2131
|
-
manifestHash: e.manifestHash,
|
|
2132
|
-
manifest: e.manifest,
|
|
2133
|
-
recordingOracle: e.recordingOracle,
|
|
2134
|
-
reputationOracle: e.reputationOracle,
|
|
2135
|
-
exchangeOracle: e.exchangeOracle,
|
|
2136
|
-
recordingOracleFee: e.recordingOracleFee
|
|
2137
|
-
? Number(e.recordingOracleFee)
|
|
2138
|
-
: null,
|
|
2139
|
-
reputationOracleFee: e.reputationOracleFee
|
|
2140
|
-
? Number(e.reputationOracleFee)
|
|
2141
|
-
: null,
|
|
2142
|
-
exchangeOracleFee: e.exchangeOracleFee ? Number(e.exchangeOracleFee) : null,
|
|
2143
|
-
status: e.status,
|
|
2144
|
-
token: e.token,
|
|
2145
|
-
totalFundedAmount: BigInt(e.totalFundedAmount),
|
|
2146
|
-
createdAt: Number(e.createdAt) * 1000,
|
|
2147
|
-
chainId: Number(chainId),
|
|
2148
|
-
};
|
|
2149
|
-
}
|