@human-protocol/sdk 6.0.0 → 6.1.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 +13 -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 +7 -8
- package/dist/escrow.d.ts +13 -13
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +17 -21
- package/dist/interfaces.d.ts +2 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +5 -5
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +3 -3
- package/dist/staking.d.ts +7 -7
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +5 -5
- package/dist/transaction.d.ts +2 -2
- package/dist/transaction.js +4 -4
- package/dist/types.d.ts +14 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -2
- package/package.json +2 -2
- package/src/base.ts +38 -2
- package/src/constants.ts +6 -8
- package/src/escrow.ts +123 -111
- package/src/interfaces.ts +2 -2
- package/src/kvstore.ts +22 -14
- package/src/staking.ts +42 -26
- package/src/transaction.ts +4 -4
- package/src/types.ts +16 -1
- package/src/utils.ts +2 -6
package/src/escrow.ts
CHANGED
|
@@ -66,7 +66,12 @@ import {
|
|
|
66
66
|
IEscrowWithdraw,
|
|
67
67
|
SubgraphOptions,
|
|
68
68
|
} from './interfaces';
|
|
69
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
EscrowStatus,
|
|
71
|
+
NetworkData,
|
|
72
|
+
TransactionLikeWithNonce,
|
|
73
|
+
TransactionOverrides,
|
|
74
|
+
} from './types';
|
|
70
75
|
import {
|
|
71
76
|
getSubgraphUrl,
|
|
72
77
|
getUnixTimestamp,
|
|
@@ -205,20 +210,22 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
205
210
|
public async createEscrow(
|
|
206
211
|
tokenAddress: string,
|
|
207
212
|
jobRequesterId: string,
|
|
208
|
-
txOptions:
|
|
213
|
+
txOptions: TransactionOverrides = {}
|
|
209
214
|
): Promise<string> {
|
|
210
215
|
if (!ethers.isAddress(tokenAddress)) {
|
|
211
216
|
throw ErrorInvalidTokenAddress;
|
|
212
217
|
}
|
|
213
218
|
|
|
214
219
|
try {
|
|
215
|
-
const result = await (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
const result = await this.sendTxAndWait(
|
|
221
|
+
(overrides) =>
|
|
222
|
+
this.escrowFactoryContract.createEscrow(
|
|
223
|
+
tokenAddress,
|
|
224
|
+
jobRequesterId,
|
|
225
|
+
overrides
|
|
226
|
+
),
|
|
227
|
+
txOptions
|
|
228
|
+
);
|
|
222
229
|
|
|
223
230
|
const event = (
|
|
224
231
|
result?.logs?.find(({ topics }) =>
|
|
@@ -340,7 +347,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
340
347
|
amount: bigint,
|
|
341
348
|
jobRequesterId: string,
|
|
342
349
|
escrowConfig: IEscrowConfig,
|
|
343
|
-
txOptions:
|
|
350
|
+
txOptions: TransactionOverrides = {}
|
|
344
351
|
): Promise<string> {
|
|
345
352
|
if (!ethers.isAddress(tokenAddress)) {
|
|
346
353
|
throw ErrorInvalidTokenAddress;
|
|
@@ -360,22 +367,24 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
360
367
|
} = escrowConfig;
|
|
361
368
|
|
|
362
369
|
try {
|
|
363
|
-
const result = await (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
370
|
+
const result = await this.sendTxAndWait(
|
|
371
|
+
(overrides) =>
|
|
372
|
+
this.escrowFactoryContract.createFundAndSetupEscrow(
|
|
373
|
+
tokenAddress,
|
|
374
|
+
amount,
|
|
375
|
+
jobRequesterId,
|
|
376
|
+
reputationOracle,
|
|
377
|
+
recordingOracle,
|
|
378
|
+
exchangeOracle,
|
|
379
|
+
reputationOracleFee,
|
|
380
|
+
recordingOracleFee,
|
|
381
|
+
exchangeOracleFee,
|
|
382
|
+
manifest,
|
|
383
|
+
manifestHash,
|
|
384
|
+
overrides
|
|
385
|
+
),
|
|
386
|
+
txOptions
|
|
387
|
+
);
|
|
379
388
|
|
|
380
389
|
const event = (
|
|
381
390
|
result?.logs?.find(({ topics }) =>
|
|
@@ -433,7 +442,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
433
442
|
async setup(
|
|
434
443
|
escrowAddress: string,
|
|
435
444
|
escrowConfig: IEscrowConfig,
|
|
436
|
-
txOptions:
|
|
445
|
+
txOptions: TransactionOverrides = {}
|
|
437
446
|
): Promise<void> {
|
|
438
447
|
const {
|
|
439
448
|
recordingOracle,
|
|
@@ -459,19 +468,21 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
459
468
|
try {
|
|
460
469
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
461
470
|
|
|
462
|
-
await (
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
471
|
+
await this.sendTxAndWait(
|
|
472
|
+
(overrides) =>
|
|
473
|
+
escrowContract.setup(
|
|
474
|
+
reputationOracle,
|
|
475
|
+
recordingOracle,
|
|
476
|
+
exchangeOracle,
|
|
477
|
+
reputationOracleFee,
|
|
478
|
+
recordingOracleFee,
|
|
479
|
+
exchangeOracleFee,
|
|
480
|
+
manifest,
|
|
481
|
+
manifestHash,
|
|
482
|
+
overrides
|
|
483
|
+
),
|
|
484
|
+
txOptions
|
|
485
|
+
);
|
|
475
486
|
|
|
476
487
|
return;
|
|
477
488
|
} catch (e) {
|
|
@@ -502,7 +513,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
502
513
|
async fund(
|
|
503
514
|
escrowAddress: string,
|
|
504
515
|
amount: bigint,
|
|
505
|
-
txOptions:
|
|
516
|
+
txOptions: TransactionOverrides = {}
|
|
506
517
|
): Promise<void> {
|
|
507
518
|
if (!ethers.isAddress(escrowAddress)) {
|
|
508
519
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -525,9 +536,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
525
536
|
tokenAddress,
|
|
526
537
|
this.runner
|
|
527
538
|
);
|
|
528
|
-
await (
|
|
529
|
-
|
|
530
|
-
|
|
539
|
+
await this.sendTxAndWait(
|
|
540
|
+
(overrides) => tokenContract.transfer(escrowAddress, amount, overrides),
|
|
541
|
+
txOptions
|
|
542
|
+
);
|
|
531
543
|
|
|
532
544
|
return;
|
|
533
545
|
} catch (e) {
|
|
@@ -564,7 +576,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
564
576
|
escrowAddress: string,
|
|
565
577
|
url: string,
|
|
566
578
|
hash: string,
|
|
567
|
-
txOptions?:
|
|
579
|
+
txOptions?: TransactionOverrides
|
|
568
580
|
): Promise<void>;
|
|
569
581
|
|
|
570
582
|
/**
|
|
@@ -604,7 +616,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
604
616
|
url: string,
|
|
605
617
|
hash: string,
|
|
606
618
|
fundsToReserve: bigint,
|
|
607
|
-
txOptions?:
|
|
619
|
+
txOptions?: TransactionOverrides
|
|
608
620
|
): Promise<void>;
|
|
609
621
|
|
|
610
622
|
@requiresSigner
|
|
@@ -612,14 +624,16 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
612
624
|
escrowAddress: string,
|
|
613
625
|
url: string,
|
|
614
626
|
hash: string,
|
|
615
|
-
a?: bigint |
|
|
616
|
-
b?:
|
|
627
|
+
a?: bigint | TransactionOverrides,
|
|
628
|
+
b?: TransactionOverrides
|
|
617
629
|
): Promise<void> {
|
|
618
630
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
619
631
|
|
|
620
632
|
const hasFundsToReserveParam = typeof a === 'bigint';
|
|
621
633
|
const fundsToReserve = hasFundsToReserveParam ? (a as bigint) : null;
|
|
622
|
-
const txOptions = (hasFundsToReserveParam ? b : a)
|
|
634
|
+
const txOptions = (hasFundsToReserveParam ? b : a) as
|
|
635
|
+
| TransactionOverrides
|
|
636
|
+
| undefined;
|
|
623
637
|
// When fundsToReserve is provided and is 0, allow empty URL.
|
|
624
638
|
// In this situation not solutions might have been provided so the escrow can be straight cancelled.
|
|
625
639
|
const allowEmptyUrl = hasFundsToReserveParam && fundsToReserve === 0n;
|
|
@@ -640,24 +654,17 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
640
654
|
}
|
|
641
655
|
|
|
642
656
|
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
|
-
}
|
|
657
|
+
const txFactory = (overrides: Overrides) =>
|
|
658
|
+
fundsToReserve !== null
|
|
659
|
+
? escrowContract['storeResults(string,string,uint256)'](
|
|
660
|
+
url,
|
|
661
|
+
hash,
|
|
662
|
+
fundsToReserve,
|
|
663
|
+
overrides
|
|
664
|
+
)
|
|
665
|
+
: escrowContract['storeResults(string,string)'](url, hash, overrides);
|
|
666
|
+
|
|
667
|
+
await this.sendTxAndWait(txFactory, txOptions);
|
|
661
668
|
} catch (e) {
|
|
662
669
|
if (!hasFundsToReserveParam && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
663
670
|
throw ErrorStoreResultsVersion;
|
|
@@ -685,7 +692,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
685
692
|
@requiresSigner
|
|
686
693
|
async complete(
|
|
687
694
|
escrowAddress: string,
|
|
688
|
-
txOptions:
|
|
695
|
+
txOptions: TransactionOverrides = {}
|
|
689
696
|
): Promise<void> {
|
|
690
697
|
if (!ethers.isAddress(escrowAddress)) {
|
|
691
698
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -697,8 +704,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
697
704
|
|
|
698
705
|
try {
|
|
699
706
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
700
|
-
|
|
701
|
-
|
|
707
|
+
await this.sendTxAndWait(
|
|
708
|
+
(overrides) => escrowContract.complete(overrides),
|
|
709
|
+
txOptions
|
|
710
|
+
);
|
|
702
711
|
return;
|
|
703
712
|
} catch (e) {
|
|
704
713
|
return throwError(e);
|
|
@@ -759,7 +768,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
759
768
|
finalResultsHash: string,
|
|
760
769
|
txId: number,
|
|
761
770
|
forceComplete: boolean,
|
|
762
|
-
txOptions:
|
|
771
|
+
txOptions: TransactionOverrides
|
|
763
772
|
): Promise<void>;
|
|
764
773
|
|
|
765
774
|
/**
|
|
@@ -817,7 +826,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
817
826
|
finalResultsHash: string,
|
|
818
827
|
payoutId: string,
|
|
819
828
|
forceComplete: boolean,
|
|
820
|
-
txOptions:
|
|
829
|
+
txOptions: TransactionOverrides
|
|
821
830
|
): Promise<void>;
|
|
822
831
|
|
|
823
832
|
@requiresSigner
|
|
@@ -829,7 +838,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
829
838
|
finalResultsHash: string,
|
|
830
839
|
id: number | string,
|
|
831
840
|
forceComplete: boolean,
|
|
832
|
-
txOptions:
|
|
841
|
+
txOptions: TransactionOverrides = {}
|
|
833
842
|
): Promise<void> {
|
|
834
843
|
await this.ensureCorrectBulkPayoutInput(
|
|
835
844
|
escrowAddress,
|
|
@@ -843,35 +852,32 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
843
852
|
const idIsString = typeof id === 'string';
|
|
844
853
|
|
|
845
854
|
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
|
-
}
|
|
855
|
+
const txFactory = (overrides: Overrides) =>
|
|
856
|
+
idIsString
|
|
857
|
+
? escrowContract[
|
|
858
|
+
'bulkPayOut(address[],uint256[],string,string,string,bool)'
|
|
859
|
+
](
|
|
860
|
+
recipients,
|
|
861
|
+
amounts,
|
|
862
|
+
finalResultsUrl,
|
|
863
|
+
finalResultsHash,
|
|
864
|
+
id,
|
|
865
|
+
forceComplete,
|
|
866
|
+
overrides
|
|
867
|
+
)
|
|
868
|
+
: escrowContract[
|
|
869
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
870
|
+
](
|
|
871
|
+
recipients,
|
|
872
|
+
amounts,
|
|
873
|
+
finalResultsUrl,
|
|
874
|
+
finalResultsHash,
|
|
875
|
+
id,
|
|
876
|
+
forceComplete,
|
|
877
|
+
overrides
|
|
878
|
+
);
|
|
879
|
+
|
|
880
|
+
await this.sendTxAndWait(txFactory, txOptions);
|
|
875
881
|
} catch (e) {
|
|
876
882
|
if (!idIsString && e.reason === 'DEPRECATED_SIGNATURE') {
|
|
877
883
|
throw ErrorBulkPayOutVersion;
|
|
@@ -900,7 +906,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
900
906
|
@requiresSigner
|
|
901
907
|
async cancel(
|
|
902
908
|
escrowAddress: string,
|
|
903
|
-
txOptions:
|
|
909
|
+
txOptions: TransactionOverrides = {}
|
|
904
910
|
): Promise<void> {
|
|
905
911
|
if (!ethers.isAddress(escrowAddress)) {
|
|
906
912
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -912,7 +918,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
912
918
|
|
|
913
919
|
try {
|
|
914
920
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
915
|
-
await
|
|
921
|
+
await this.sendTxAndWait(
|
|
922
|
+
(overrides) => escrowContract.cancel(overrides),
|
|
923
|
+
txOptions
|
|
924
|
+
);
|
|
916
925
|
} catch (e) {
|
|
917
926
|
return throwError(e);
|
|
918
927
|
}
|
|
@@ -936,7 +945,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
936
945
|
@requiresSigner
|
|
937
946
|
async requestCancellation(
|
|
938
947
|
escrowAddress: string,
|
|
939
|
-
txOptions:
|
|
948
|
+
txOptions: TransactionOverrides = {}
|
|
940
949
|
): Promise<void> {
|
|
941
950
|
if (!ethers.isAddress(escrowAddress)) {
|
|
942
951
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -948,7 +957,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
948
957
|
|
|
949
958
|
try {
|
|
950
959
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
951
|
-
await
|
|
960
|
+
await this.sendTxAndWait(
|
|
961
|
+
(overrides) => escrowContract.requestCancellation(overrides),
|
|
962
|
+
txOptions
|
|
963
|
+
);
|
|
952
964
|
} catch (e) {
|
|
953
965
|
return throwError(e);
|
|
954
966
|
}
|
|
@@ -981,7 +993,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
981
993
|
async withdraw(
|
|
982
994
|
escrowAddress: string,
|
|
983
995
|
tokenAddress: string,
|
|
984
|
-
txOptions:
|
|
996
|
+
txOptions: TransactionOverrides = {}
|
|
985
997
|
): Promise<IEscrowWithdraw> {
|
|
986
998
|
if (!ethers.isAddress(escrowAddress)) {
|
|
987
999
|
throw ErrorInvalidEscrowAddressProvided;
|
|
@@ -997,10 +1009,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
997
1009
|
|
|
998
1010
|
try {
|
|
999
1011
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
)
|
|
1012
|
+
const transactionReceipt = await this.sendTxAndWait(
|
|
1013
|
+
(overrides) => escrowContract.withdraw(tokenAddress, overrides),
|
|
1014
|
+
txOptions
|
|
1015
|
+
);
|
|
1004
1016
|
|
|
1005
1017
|
let amountTransferred: bigint | undefined = undefined;
|
|
1006
1018
|
|
package/src/interfaces.ts
CHANGED
|
@@ -149,8 +149,8 @@ export interface ITransaction {
|
|
|
149
149
|
|
|
150
150
|
export interface ITransactionsFilter extends IPagination {
|
|
151
151
|
chainId: ChainId;
|
|
152
|
-
startBlock?: number;
|
|
153
|
-
endBlock?: number;
|
|
152
|
+
startBlock?: number | bigint;
|
|
153
|
+
endBlock?: number | bigint;
|
|
154
154
|
startDate?: Date;
|
|
155
155
|
endDate?: Date;
|
|
156
156
|
fromAddress?: string;
|
package/src/kvstore.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
KVStore,
|
|
3
3
|
KVStore__factory,
|
|
4
4
|
} from '@human-protocol/core/typechain-types';
|
|
5
|
-
import { ContractRunner,
|
|
5
|
+
import { ContractRunner, ethers } from 'ethers';
|
|
6
6
|
import { BaseEthersClient } from './base';
|
|
7
7
|
import { KVStoreKeys, NETWORKS } from './constants';
|
|
8
8
|
import { requiresSigner } from './decorators';
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
ErrorUnsupportedChainID,
|
|
18
18
|
InvalidKeyError,
|
|
19
19
|
} from './error';
|
|
20
|
-
import { NetworkData } from './types';
|
|
20
|
+
import { NetworkData, TransactionOverrides } from './types';
|
|
21
21
|
import { getSubgraphUrl, customGqlFetch, isValidUrl } from './utils';
|
|
22
22
|
import {
|
|
23
23
|
GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY,
|
|
@@ -156,11 +156,14 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
156
156
|
public async set(
|
|
157
157
|
key: string,
|
|
158
158
|
value: string,
|
|
159
|
-
txOptions:
|
|
159
|
+
txOptions: TransactionOverrides = {}
|
|
160
160
|
): Promise<void> {
|
|
161
161
|
if (key === '') throw ErrorKVStoreEmptyKey;
|
|
162
162
|
try {
|
|
163
|
-
await
|
|
163
|
+
await this.sendTxAndWait(
|
|
164
|
+
(overrides) => this.contract.set(key, value, overrides),
|
|
165
|
+
txOptions
|
|
166
|
+
);
|
|
164
167
|
} catch (e) {
|
|
165
168
|
if (e instanceof Error) throw Error(`Failed to set value: ${e.message}`);
|
|
166
169
|
}
|
|
@@ -188,13 +191,16 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
188
191
|
public async setBulk(
|
|
189
192
|
keys: string[],
|
|
190
193
|
values: string[],
|
|
191
|
-
txOptions:
|
|
194
|
+
txOptions: TransactionOverrides = {}
|
|
192
195
|
): Promise<void> {
|
|
193
196
|
if (keys.length !== values.length) throw ErrorKVStoreArrayLength;
|
|
194
197
|
if (keys.includes('')) throw ErrorKVStoreEmptyKey;
|
|
195
198
|
|
|
196
199
|
try {
|
|
197
|
-
await
|
|
200
|
+
await this.sendTxAndWait(
|
|
201
|
+
(overrides) => this.contract.setBulk(keys, values, overrides),
|
|
202
|
+
txOptions
|
|
203
|
+
);
|
|
198
204
|
} catch (e) {
|
|
199
205
|
if (e instanceof Error)
|
|
200
206
|
throw Error(`Failed to set bulk values: ${e.message}`);
|
|
@@ -221,7 +227,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
221
227
|
public async setFileUrlAndHash(
|
|
222
228
|
url: string,
|
|
223
229
|
urlKey = 'url',
|
|
224
|
-
txOptions:
|
|
230
|
+
txOptions: TransactionOverrides = {}
|
|
225
231
|
): Promise<void> {
|
|
226
232
|
if (!isValidUrl(url)) {
|
|
227
233
|
throw ErrorInvalidUrl;
|
|
@@ -233,13 +239,15 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
233
239
|
const hashKey = urlKey + '_hash';
|
|
234
240
|
|
|
235
241
|
try {
|
|
236
|
-
await (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
await this.sendTxAndWait(
|
|
243
|
+
(overrides) =>
|
|
244
|
+
this.contract.setBulk(
|
|
245
|
+
[urlKey, hashKey],
|
|
246
|
+
[url, contentHash],
|
|
247
|
+
overrides
|
|
248
|
+
),
|
|
249
|
+
txOptions
|
|
250
|
+
);
|
|
243
251
|
} catch (e) {
|
|
244
252
|
if (e instanceof Error)
|
|
245
253
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
package/src/staking.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
Staking,
|
|
7
7
|
Staking__factory,
|
|
8
8
|
} from '@human-protocol/core/typechain-types';
|
|
9
|
-
import { ContractRunner,
|
|
9
|
+
import { ContractRunner, ethers } from 'ethers';
|
|
10
10
|
import { BaseEthersClient } from './base';
|
|
11
11
|
import { NETWORKS } from './constants';
|
|
12
12
|
import { requiresSigner } from './decorators';
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
SubgraphOptions,
|
|
30
30
|
} from './interfaces';
|
|
31
31
|
import { StakerData } from './graphql';
|
|
32
|
-
import { NetworkData } from './types';
|
|
32
|
+
import { NetworkData, TransactionOverrides } from './types';
|
|
33
33
|
import { getSubgraphUrl, customGqlFetch, throwError } from './utils';
|
|
34
34
|
import {
|
|
35
35
|
GET_STAKER_BY_ADDRESS_QUERY,
|
|
@@ -194,7 +194,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
194
194
|
@requiresSigner
|
|
195
195
|
public async approveStake(
|
|
196
196
|
amount: bigint,
|
|
197
|
-
txOptions:
|
|
197
|
+
txOptions: TransactionOverrides = {}
|
|
198
198
|
): Promise<void> {
|
|
199
199
|
if (typeof amount !== 'bigint') {
|
|
200
200
|
throw ErrorInvalidStakingValueType;
|
|
@@ -205,13 +205,15 @@ export class StakingClient extends BaseEthersClient {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
try {
|
|
208
|
-
await (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
await this.sendTxAndWait(
|
|
209
|
+
async (overrides) =>
|
|
210
|
+
this.tokenContract.approve(
|
|
211
|
+
await this.stakingContract.getAddress(),
|
|
212
|
+
amount,
|
|
213
|
+
overrides
|
|
214
|
+
),
|
|
215
|
+
txOptions
|
|
216
|
+
);
|
|
215
217
|
return;
|
|
216
218
|
} catch (e) {
|
|
217
219
|
return throwError(e);
|
|
@@ -240,7 +242,10 @@ export class StakingClient extends BaseEthersClient {
|
|
|
240
242
|
* ```
|
|
241
243
|
*/
|
|
242
244
|
@requiresSigner
|
|
243
|
-
public async stake(
|
|
245
|
+
public async stake(
|
|
246
|
+
amount: bigint,
|
|
247
|
+
txOptions: TransactionOverrides = {}
|
|
248
|
+
): Promise<void> {
|
|
244
249
|
if (typeof amount !== 'bigint') {
|
|
245
250
|
throw ErrorInvalidStakingValueType;
|
|
246
251
|
}
|
|
@@ -250,7 +255,10 @@ export class StakingClient extends BaseEthersClient {
|
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
try {
|
|
253
|
-
await
|
|
258
|
+
await this.sendTxAndWait(
|
|
259
|
+
(overrides) => this.stakingContract.stake(amount, overrides),
|
|
260
|
+
txOptions
|
|
261
|
+
);
|
|
254
262
|
return;
|
|
255
263
|
} catch (e) {
|
|
256
264
|
return throwError(e);
|
|
@@ -280,7 +288,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
280
288
|
@requiresSigner
|
|
281
289
|
public async unstake(
|
|
282
290
|
amount: bigint,
|
|
283
|
-
txOptions:
|
|
291
|
+
txOptions: TransactionOverrides = {}
|
|
284
292
|
): Promise<void> {
|
|
285
293
|
if (typeof amount !== 'bigint') {
|
|
286
294
|
throw ErrorInvalidStakingValueType;
|
|
@@ -291,7 +299,10 @@ export class StakingClient extends BaseEthersClient {
|
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
try {
|
|
294
|
-
await
|
|
302
|
+
await this.sendTxAndWait(
|
|
303
|
+
(overrides) => this.stakingContract.unstake(amount, overrides),
|
|
304
|
+
txOptions
|
|
305
|
+
);
|
|
295
306
|
return;
|
|
296
307
|
} catch (e) {
|
|
297
308
|
return throwError(e);
|
|
@@ -312,9 +323,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
312
323
|
* ```
|
|
313
324
|
*/
|
|
314
325
|
@requiresSigner
|
|
315
|
-
public async withdraw(txOptions:
|
|
326
|
+
public async withdraw(txOptions: TransactionOverrides = {}): Promise<void> {
|
|
316
327
|
try {
|
|
317
|
-
await
|
|
328
|
+
await this.sendTxAndWait(
|
|
329
|
+
(overrides) => this.stakingContract.withdraw(overrides),
|
|
330
|
+
txOptions
|
|
331
|
+
);
|
|
318
332
|
return;
|
|
319
333
|
} catch (e) {
|
|
320
334
|
return throwError(e);
|
|
@@ -356,7 +370,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
356
370
|
staker: string,
|
|
357
371
|
escrowAddress: string,
|
|
358
372
|
amount: bigint,
|
|
359
|
-
txOptions:
|
|
373
|
+
txOptions: TransactionOverrides = {}
|
|
360
374
|
): Promise<void> {
|
|
361
375
|
if (typeof amount !== 'bigint') {
|
|
362
376
|
throw ErrorInvalidStakingValueType;
|
|
@@ -377,15 +391,17 @@ export class StakingClient extends BaseEthersClient {
|
|
|
377
391
|
await this.checkValidEscrow(escrowAddress);
|
|
378
392
|
|
|
379
393
|
try {
|
|
380
|
-
await (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
394
|
+
await this.sendTxAndWait(
|
|
395
|
+
(overrides) =>
|
|
396
|
+
this.stakingContract.slash(
|
|
397
|
+
slasher,
|
|
398
|
+
staker,
|
|
399
|
+
escrowAddress,
|
|
400
|
+
amount,
|
|
401
|
+
overrides
|
|
402
|
+
),
|
|
403
|
+
txOptions
|
|
404
|
+
);
|
|
389
405
|
|
|
390
406
|
return;
|
|
391
407
|
} catch (e) {
|
package/src/transaction.ts
CHANGED
|
@@ -129,8 +129,8 @@ export class TransactionUtils {
|
|
|
129
129
|
* token?: string; // (Optional) The token address to filter transactions.
|
|
130
130
|
* startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
|
|
131
131
|
* endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
|
|
132
|
-
* startBlock?: number; // (Optional) The start block
|
|
133
|
-
* endBlock?: number; // (Optional) The end block
|
|
132
|
+
* startBlock?: bigint | number; // (Optional) The start block to filter transactions (inclusive).
|
|
133
|
+
* endBlock?: bigint | number; // (Optional) The end block to filter transactions (inclusive).
|
|
134
134
|
* first?: number; // (Optional) Number of transactions per page. Default is 10.
|
|
135
135
|
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
136
136
|
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
|
|
@@ -220,8 +220,8 @@ export class TransactionUtils {
|
|
|
220
220
|
? getUnixTimestamp(filter?.startDate)
|
|
221
221
|
: undefined,
|
|
222
222
|
endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
|
|
223
|
-
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
224
|
-
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
223
|
+
startBlock: filter.startBlock ? Number(filter.startBlock) : undefined,
|
|
224
|
+
endBlock: filter.endBlock ? Number(filter.endBlock) : undefined,
|
|
225
225
|
method: filter.method ? filter.method : undefined,
|
|
226
226
|
escrow: filter.escrow ? filter.escrow : undefined,
|
|
227
227
|
token: filter.token ? filter.token : undefined,
|