@human-protocol/sdk 3.0.6 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -24
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +23 -64
- package/dist/encryption.d.ts +6 -4
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +52 -16
- package/dist/escrow.d.ts +20 -57
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +74 -88
- package/dist/graphql/queries/operator.js +2 -2
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +0 -2
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +23 -10
- package/dist/graphql/types.d.ts +0 -2
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/interfaces.d.ts +19 -10
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +1 -1
- package/dist/kvstore.js +1 -1
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +13 -0
- package/dist/staking.d.ts +3 -112
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +2 -170
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +3 -1
- package/dist/storage.js +17 -7
- package/dist/types.d.ts +17 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/constants.ts +23 -64
- package/src/encryption.ts +47 -15
- package/src/escrow.ts +119 -103
- package/src/graphql/queries/operator.ts +2 -2
- package/src/graphql/queries/statistics.ts +0 -2
- package/src/graphql/queries/transaction.ts +23 -13
- package/src/graphql/types.ts +0 -2
- package/src/interfaces.ts +19 -11
- package/src/kvstore.ts +1 -1
- package/src/operator.ts +21 -0
- package/src/staking.ts +2 -185
- package/src/statistics.ts +3 -1
- package/src/types.ts +18 -4
package/src/escrow.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import {
|
|
3
|
+
ERC20,
|
|
4
|
+
ERC20__factory,
|
|
3
5
|
Escrow,
|
|
4
6
|
EscrowFactory,
|
|
5
7
|
EscrowFactory__factory,
|
|
@@ -45,7 +47,12 @@ import {
|
|
|
45
47
|
StatusEvent,
|
|
46
48
|
} from './graphql';
|
|
47
49
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
48
|
-
import {
|
|
50
|
+
import {
|
|
51
|
+
EscrowCancel,
|
|
52
|
+
EscrowStatus,
|
|
53
|
+
EscrowWithdraw,
|
|
54
|
+
NetworkData,
|
|
55
|
+
} from './types';
|
|
49
56
|
import { getSubgraphUrl, isValidUrl, throwError } from './utils';
|
|
50
57
|
|
|
51
58
|
/**
|
|
@@ -124,7 +131,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
124
131
|
* **EscrowClient constructor**
|
|
125
132
|
*
|
|
126
133
|
* @param {ContractRunner} runner The Runner object to interact with the Ethereum network
|
|
127
|
-
* @param {NetworkData}
|
|
134
|
+
* @param {NetworkData} networkData The network information required to connect to the Escrow contract
|
|
128
135
|
*/
|
|
129
136
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
130
137
|
super(runner, networkData);
|
|
@@ -370,69 +377,6 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
370
377
|
}
|
|
371
378
|
}
|
|
372
379
|
|
|
373
|
-
/**
|
|
374
|
-
* This function creates and sets up an escrow.
|
|
375
|
-
*
|
|
376
|
-
* @param {string} tokenAddress Token address to use for pay outs.
|
|
377
|
-
* @param {string[]} trustedHandlers Array of addresses that can perform actions on the contract.
|
|
378
|
-
* @param {string} jobRequesterId Job Requester Id
|
|
379
|
-
* @param {IEscrowConfig} escrowConfig Configuration object with escrow settings.
|
|
380
|
-
* @returns {Promise<string>} Returns the address of the escrow created.
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* **Code example**
|
|
384
|
-
*
|
|
385
|
-
* ```ts
|
|
386
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
387
|
-
* import { EscrowClient } from '@human-protocol/sdk';
|
|
388
|
-
*
|
|
389
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
390
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
391
|
-
*
|
|
392
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
393
|
-
* const signer = new Wallet(privateKey, provider);
|
|
394
|
-
* const escrowClient = await EscrowClient.build(signer);
|
|
395
|
-
*
|
|
396
|
-
* const tokenAddress = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4';
|
|
397
|
-
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'];
|
|
398
|
-
* const jobRequesterId = "job-requester-id";
|
|
399
|
-
*
|
|
400
|
-
* const escrowConfig = {
|
|
401
|
-
* recordingOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
402
|
-
* reputationOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
403
|
-
* exchangeOracle: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
404
|
-
* recordingOracleFee: bigint.from('10'),
|
|
405
|
-
* reputationOracleFee: bigint.from('10'),
|
|
406
|
-
* exchangeOracleFee: bigint.from('10'),
|
|
407
|
-
* manifestUrl: 'htttp://localhost/manifest.json',
|
|
408
|
-
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
409
|
-
* };
|
|
410
|
-
*
|
|
411
|
-
* const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig);
|
|
412
|
-
* ```
|
|
413
|
-
*/
|
|
414
|
-
@requiresSigner
|
|
415
|
-
async createAndSetupEscrow(
|
|
416
|
-
tokenAddress: string,
|
|
417
|
-
trustedHandlers: string[],
|
|
418
|
-
jobRequesterId: string,
|
|
419
|
-
escrowConfig: IEscrowConfig
|
|
420
|
-
): Promise<string> {
|
|
421
|
-
try {
|
|
422
|
-
const escrowAddress = await this.createEscrow(
|
|
423
|
-
tokenAddress,
|
|
424
|
-
trustedHandlers,
|
|
425
|
-
jobRequesterId
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
await this.setup(escrowAddress, escrowConfig);
|
|
429
|
-
|
|
430
|
-
return escrowAddress;
|
|
431
|
-
} catch (e) {
|
|
432
|
-
return throwError(e);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
380
|
/**
|
|
437
381
|
* This function adds funds of the chosen token to the escrow.
|
|
438
382
|
*
|
|
@@ -619,6 +563,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
619
563
|
* @param {bigint[]} amounts Array of amounts the recipients will receive.
|
|
620
564
|
* @param {string} finalResultsUrl Final results file url.
|
|
621
565
|
* @param {string} finalResultsHash Final results file hash.
|
|
566
|
+
* @param {string} forceComplete Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).
|
|
622
567
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
623
568
|
* @returns Returns void if successful. Throws error if any.
|
|
624
569
|
*
|
|
@@ -653,6 +598,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
653
598
|
amounts: bigint[],
|
|
654
599
|
finalResultsUrl: string,
|
|
655
600
|
finalResultsHash: string,
|
|
601
|
+
forceComplete = false,
|
|
656
602
|
txOptions: Overrides = {}
|
|
657
603
|
): Promise<void> {
|
|
658
604
|
if (!ethers.isAddress(escrowAddress)) {
|
|
@@ -706,17 +652,34 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
706
652
|
|
|
707
653
|
try {
|
|
708
654
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
655
|
+
if (forceComplete) {
|
|
656
|
+
await (
|
|
657
|
+
await escrowContract[
|
|
658
|
+
'bulkPayOut(address[],uint256[],string,string,uint256,bool)'
|
|
659
|
+
](
|
|
660
|
+
recipients,
|
|
661
|
+
amounts,
|
|
662
|
+
finalResultsUrl,
|
|
663
|
+
finalResultsHash,
|
|
664
|
+
DEFAULT_TX_ID,
|
|
665
|
+
forceComplete,
|
|
666
|
+
txOptions
|
|
667
|
+
)
|
|
668
|
+
).wait();
|
|
669
|
+
} else {
|
|
670
|
+
await (
|
|
671
|
+
await escrowContract[
|
|
672
|
+
'bulkPayOut(address[],uint256[],string,string,uint256)'
|
|
673
|
+
](
|
|
674
|
+
recipients,
|
|
675
|
+
amounts,
|
|
676
|
+
finalResultsUrl,
|
|
677
|
+
finalResultsHash,
|
|
678
|
+
DEFAULT_TX_ID,
|
|
679
|
+
txOptions
|
|
680
|
+
)
|
|
681
|
+
).wait();
|
|
682
|
+
}
|
|
720
683
|
return;
|
|
721
684
|
} catch (e) {
|
|
722
685
|
return throwError(e);
|
|
@@ -808,9 +771,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
808
771
|
}
|
|
809
772
|
|
|
810
773
|
/**
|
|
811
|
-
* This function
|
|
774
|
+
* This function adds an array of addresses to the trusted handlers list.
|
|
812
775
|
*
|
|
813
776
|
* @param {string} escrowAddress Address of the escrow.
|
|
777
|
+
* @param {string[]} trustedHandlers Array of addresses of trusted handlers to add.
|
|
814
778
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
815
779
|
* @returns Returns void if successful. Throws error if any.
|
|
816
780
|
*
|
|
@@ -830,15 +794,30 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
830
794
|
* const signer = new Wallet(privateKey, provider);
|
|
831
795
|
* const escrowClient = await EscrowClient.build(signer);
|
|
832
796
|
*
|
|
833
|
-
*
|
|
797
|
+
* const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']
|
|
798
|
+
* await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);
|
|
834
799
|
* ```
|
|
835
800
|
*/
|
|
836
801
|
@requiresSigner
|
|
837
|
-
async
|
|
802
|
+
async addTrustedHandlers(
|
|
803
|
+
escrowAddress: string,
|
|
804
|
+
trustedHandlers: string[],
|
|
805
|
+
txOptions: Overrides = {}
|
|
806
|
+
): Promise<void> {
|
|
838
807
|
if (!ethers.isAddress(escrowAddress)) {
|
|
839
808
|
throw ErrorInvalidEscrowAddressProvided;
|
|
840
809
|
}
|
|
841
810
|
|
|
811
|
+
if (trustedHandlers.length === 0) {
|
|
812
|
+
throw ErrorListOfHandlersCannotBeEmpty;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
trustedHandlers.forEach((trustedHandler) => {
|
|
816
|
+
if (!ethers.isAddress(trustedHandler)) {
|
|
817
|
+
throw new InvalidEthereumAddressError(trustedHandler);
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
|
|
842
821
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
843
822
|
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
844
823
|
}
|
|
@@ -846,7 +825,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
846
825
|
try {
|
|
847
826
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
848
827
|
|
|
849
|
-
await (
|
|
828
|
+
await (
|
|
829
|
+
await escrowContract.addTrustedHandlers(trustedHandlers, txOptions)
|
|
830
|
+
).wait();
|
|
850
831
|
return;
|
|
851
832
|
} catch (e) {
|
|
852
833
|
return throwError(e);
|
|
@@ -854,20 +835,20 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
854
835
|
}
|
|
855
836
|
|
|
856
837
|
/**
|
|
857
|
-
* This function
|
|
838
|
+
* This function withdraws additional tokens in the escrow to the canceler.
|
|
858
839
|
*
|
|
859
|
-
* @param {string} escrowAddress Address of the escrow.
|
|
860
|
-
* @param {string
|
|
840
|
+
* @param {string} escrowAddress Address of the escrow to withdraw.
|
|
841
|
+
* @param {string} tokenAddress Address of the token to withdraw.
|
|
861
842
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
862
|
-
* @returns Returns
|
|
843
|
+
* @returns {EscrowWithdraw} Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.
|
|
863
844
|
*
|
|
864
845
|
*
|
|
865
846
|
* **Code example**
|
|
866
847
|
*
|
|
867
|
-
* > Only Job Launcher or trusted handler can call it.
|
|
848
|
+
* > Only Job Launcher or a trusted handler can call it.
|
|
868
849
|
*
|
|
869
850
|
* ```ts
|
|
870
|
-
* import { Wallet, providers } from 'ethers';
|
|
851
|
+
* import { ethers, Wallet, providers } from 'ethers';
|
|
871
852
|
* import { EscrowClient } from '@human-protocol/sdk';
|
|
872
853
|
*
|
|
873
854
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
@@ -877,30 +858,26 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
877
858
|
* const signer = new Wallet(privateKey, provider);
|
|
878
859
|
* const escrowClient = await EscrowClient.build(signer);
|
|
879
860
|
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
861
|
+
* await escrowClient.withdraw(
|
|
862
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
863
|
+
* '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
|
|
864
|
+
* );
|
|
882
865
|
* ```
|
|
883
866
|
*/
|
|
884
867
|
@requiresSigner
|
|
885
|
-
async
|
|
868
|
+
async withdraw(
|
|
886
869
|
escrowAddress: string,
|
|
887
|
-
|
|
870
|
+
tokenAddress: string,
|
|
888
871
|
txOptions: Overrides = {}
|
|
889
|
-
): Promise<
|
|
872
|
+
): Promise<EscrowWithdraw> {
|
|
890
873
|
if (!ethers.isAddress(escrowAddress)) {
|
|
891
874
|
throw ErrorInvalidEscrowAddressProvided;
|
|
892
875
|
}
|
|
893
876
|
|
|
894
|
-
if (
|
|
895
|
-
throw
|
|
877
|
+
if (!ethers.isAddress(tokenAddress)) {
|
|
878
|
+
throw ErrorInvalidTokenAddress;
|
|
896
879
|
}
|
|
897
880
|
|
|
898
|
-
trustedHandlers.forEach((trustedHandler) => {
|
|
899
|
-
if (!ethers.isAddress(trustedHandler)) {
|
|
900
|
-
throw new InvalidEthereumAddressError(trustedHandler);
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
|
|
904
881
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
905
882
|
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
906
883
|
}
|
|
@@ -908,10 +885,43 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
908
885
|
try {
|
|
909
886
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
910
887
|
|
|
911
|
-
await (
|
|
912
|
-
await escrowContract.
|
|
888
|
+
const transactionReceipt = await (
|
|
889
|
+
await escrowContract.withdraw(tokenAddress, txOptions)
|
|
913
890
|
).wait();
|
|
914
|
-
|
|
891
|
+
|
|
892
|
+
let amountTransferred: bigint | undefined = undefined;
|
|
893
|
+
|
|
894
|
+
const tokenContract: ERC20 = ERC20__factory.connect(
|
|
895
|
+
tokenAddress,
|
|
896
|
+
this.runner
|
|
897
|
+
);
|
|
898
|
+
if (transactionReceipt)
|
|
899
|
+
for (const log of transactionReceipt.logs) {
|
|
900
|
+
if (log.address === tokenAddress) {
|
|
901
|
+
const parsedLog = tokenContract.interface.parseLog({
|
|
902
|
+
topics: log.topics as string[],
|
|
903
|
+
data: log.data,
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
const from = parsedLog?.args[0];
|
|
907
|
+
if (parsedLog?.name === 'Transfer' && from === escrowAddress) {
|
|
908
|
+
amountTransferred = parsedLog?.args[2];
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
if (amountTransferred === undefined) {
|
|
915
|
+
throw ErrorTransferEventNotFoundInTransactionLogs;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const escrowWithdrawData: EscrowWithdraw = {
|
|
919
|
+
txHash: transactionReceipt?.hash || '',
|
|
920
|
+
tokenAddress,
|
|
921
|
+
amountWithdrawn: amountTransferred,
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
return escrowWithdrawData;
|
|
915
925
|
} catch (e) {
|
|
916
926
|
return throwError(e);
|
|
917
927
|
}
|
|
@@ -949,7 +959,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
949
959
|
try {
|
|
950
960
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
951
961
|
|
|
952
|
-
|
|
962
|
+
try {
|
|
963
|
+
return await escrowContract.remainingFunds();
|
|
964
|
+
} catch {
|
|
965
|
+
// Use getBalance() method below if remainingFunds() is not available
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
return await escrowContract.getBalance();
|
|
953
969
|
} catch (e) {
|
|
954
970
|
return throwError(e);
|
|
955
971
|
}
|
|
@@ -6,22 +6,22 @@ const LEADER_FRAGMENT = gql`
|
|
|
6
6
|
id
|
|
7
7
|
address
|
|
8
8
|
amountStaked
|
|
9
|
-
amountAllocated
|
|
10
9
|
amountLocked
|
|
11
10
|
lockedUntilTimestamp
|
|
12
11
|
amountWithdrawn
|
|
13
12
|
amountSlashed
|
|
14
|
-
reputation
|
|
15
13
|
reward
|
|
16
14
|
amountJobsProcessed
|
|
17
15
|
role
|
|
18
16
|
fee
|
|
19
17
|
publicKey
|
|
20
18
|
webhookUrl
|
|
19
|
+
website
|
|
21
20
|
url
|
|
22
21
|
jobTypes
|
|
23
22
|
registrationNeeded
|
|
24
23
|
registrationInstructions
|
|
24
|
+
reputationNetworks
|
|
25
25
|
}
|
|
26
26
|
`;
|
|
27
27
|
|
|
@@ -15,7 +15,6 @@ const HMTOKEN_STATISTICS_FRAGMENT = gql`
|
|
|
15
15
|
const ESCROW_STATISTICS_FRAGMENT = gql`
|
|
16
16
|
fragment EscrowStatisticsFields on EscrowStatistics {
|
|
17
17
|
fundEventCount
|
|
18
|
-
setupEventCount
|
|
19
18
|
storeResultsEventCount
|
|
20
19
|
bulkPayoutEventCount
|
|
21
20
|
pendingStatusEventCount
|
|
@@ -32,7 +31,6 @@ const EVENT_DAY_DATA_FRAGMENT = gql`
|
|
|
32
31
|
fragment EventDayDataFields on EventDayData {
|
|
33
32
|
timestamp
|
|
34
33
|
dailyFundEventCount
|
|
35
|
-
dailySetupEventCount
|
|
36
34
|
dailyStoreResultsEventCount
|
|
37
35
|
dailyBulkPayoutEventCount
|
|
38
36
|
dailyPendingStatusEventCount
|
|
@@ -10,35 +10,45 @@ const TRANSACTION_FRAGMENT = gql`
|
|
|
10
10
|
timestamp
|
|
11
11
|
value
|
|
12
12
|
method
|
|
13
|
+
receiver
|
|
14
|
+
escrow
|
|
15
|
+
token
|
|
16
|
+
internalTransactions {
|
|
17
|
+
from
|
|
18
|
+
id
|
|
19
|
+
to
|
|
20
|
+
value
|
|
21
|
+
receiver
|
|
22
|
+
escrow
|
|
23
|
+
token
|
|
24
|
+
method
|
|
25
|
+
}
|
|
13
26
|
}
|
|
14
27
|
`;
|
|
15
28
|
|
|
16
29
|
export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
17
30
|
const { startDate, endDate, startBlock, endBlock, fromAddress, toAddress } =
|
|
18
31
|
filter;
|
|
19
|
-
|
|
20
32
|
const addressCondition =
|
|
21
33
|
fromAddress === toAddress
|
|
22
34
|
? `
|
|
23
35
|
${fromAddress ? `{ from: $fromAddress }` : ''}
|
|
24
|
-
${toAddress ? `{ to: $toAddress }` : ''}
|
|
36
|
+
${toAddress ? `{ or: [{ or: [{ to: $toAddress }, { receiver: $toAddress }] }, {internalTransactions_: { or: [{ to: $toAddress }, { receiver: $toAddress }] } }] }` : ''}
|
|
25
37
|
`
|
|
26
38
|
: `
|
|
27
|
-
${fromAddress ? `from: $fromAddress` : ''}
|
|
28
|
-
${toAddress ? `to: $toAddress` : ''}
|
|
39
|
+
${fromAddress ? `{ from: $fromAddress }` : ''}
|
|
40
|
+
${toAddress ? `{ or: [{ or: [{ to: $toAddress }, { receiver: $toAddress }] }, { internalTransactions_: { or: [{ to: $toAddress }, { receiver: $toAddress }] } }] }` : ''}
|
|
29
41
|
`;
|
|
30
42
|
|
|
31
43
|
const WHERE_CLAUSE = `
|
|
32
44
|
where: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
${
|
|
39
|
-
|
|
40
|
-
${startBlock ? `block_gte: $startBlock,` : ''}
|
|
41
|
-
${endBlock ? `block_lte: $endBlock,` : ''}
|
|
45
|
+
and: [
|
|
46
|
+
${fromAddress && fromAddress === toAddress ? `{or: [ ${addressCondition} ]},` : `${addressCondition}`}
|
|
47
|
+
${startDate ? `{timestamp_gte: $startDate},` : ''}
|
|
48
|
+
${endDate ? `{timestamp_lte: $endDate},` : ''}
|
|
49
|
+
${startBlock ? `{block_gte: $startBlock},` : ''}
|
|
50
|
+
${endBlock ? `{block_lte: $endBlock},` : ''}
|
|
51
|
+
]
|
|
42
52
|
}
|
|
43
53
|
`;
|
|
44
54
|
|
package/src/graphql/types.ts
CHANGED
|
@@ -41,7 +41,6 @@ export type HMTStatisticsData = {
|
|
|
41
41
|
|
|
42
42
|
export type EscrowStatisticsData = {
|
|
43
43
|
fundEventCount: string;
|
|
44
|
-
setupEventCount: string;
|
|
45
44
|
storeResultsEventCount: string;
|
|
46
45
|
bulkPayoutEventCount: string;
|
|
47
46
|
pendingStatusEventCount: string;
|
|
@@ -56,7 +55,6 @@ export type EscrowStatisticsData = {
|
|
|
56
55
|
export type EventDayData = {
|
|
57
56
|
timestamp: string;
|
|
58
57
|
dailyFundEventCount: string;
|
|
59
|
-
dailySetupEventCount: string;
|
|
60
58
|
dailyStoreResultsEventCount: string;
|
|
61
59
|
dailyBulkPayoutEventCount: string;
|
|
62
60
|
dailyPendingStatusEventCount: string;
|
package/src/interfaces.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { EscrowStatus } from './types';
|
|
2
2
|
import { ChainId, OrderDirection } from './enums';
|
|
3
3
|
|
|
4
|
-
export interface IAllocation {
|
|
5
|
-
escrowAddress: string;
|
|
6
|
-
staker: string;
|
|
7
|
-
tokens: bigint;
|
|
8
|
-
createdAt: bigint;
|
|
9
|
-
closedAt: bigint;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
4
|
export interface IReward {
|
|
13
5
|
escrowAddress: string;
|
|
14
6
|
amount: bigint;
|
|
@@ -19,26 +11,28 @@ export interface ILeader {
|
|
|
19
11
|
chainId: ChainId;
|
|
20
12
|
address: string;
|
|
21
13
|
amountStaked: bigint;
|
|
22
|
-
amountAllocated: bigint;
|
|
23
14
|
amountLocked: bigint;
|
|
24
15
|
lockedUntilTimestamp: bigint;
|
|
25
16
|
amountWithdrawn: bigint;
|
|
26
17
|
amountSlashed: bigint;
|
|
27
|
-
reputation: bigint;
|
|
28
18
|
reward: bigint;
|
|
29
19
|
amountJobsProcessed: bigint;
|
|
30
20
|
role?: string;
|
|
31
21
|
fee?: bigint;
|
|
32
22
|
publicKey?: string;
|
|
33
23
|
webhookUrl?: string;
|
|
24
|
+
website?: string;
|
|
34
25
|
url?: string;
|
|
35
26
|
jobTypes?: string[];
|
|
36
27
|
registrationNeeded?: boolean;
|
|
37
28
|
registrationInstructions?: string;
|
|
29
|
+
reputationNetworks?: string[];
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
export interface ILeaderSubgraph
|
|
32
|
+
export interface ILeaderSubgraph
|
|
33
|
+
extends Omit<ILeader, 'jobTypes' | 'reputationNetworks' | 'chainId'> {
|
|
41
34
|
jobTypes?: string;
|
|
35
|
+
reputationNetworks?: { address: string }[];
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
export interface ILeadersFilter {
|
|
@@ -121,6 +115,16 @@ export interface IKVStore {
|
|
|
121
115
|
value: string;
|
|
122
116
|
}
|
|
123
117
|
|
|
118
|
+
export interface InternalTransaction {
|
|
119
|
+
from: string;
|
|
120
|
+
to: string;
|
|
121
|
+
value: string;
|
|
122
|
+
method: string;
|
|
123
|
+
receiver?: string;
|
|
124
|
+
escrow?: string;
|
|
125
|
+
token?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
export interface ITransaction {
|
|
125
129
|
block: bigint;
|
|
126
130
|
txHash: string;
|
|
@@ -129,6 +133,10 @@ export interface ITransaction {
|
|
|
129
133
|
timestamp: bigint;
|
|
130
134
|
value: string;
|
|
131
135
|
method: string;
|
|
136
|
+
receiver?: string;
|
|
137
|
+
escrow?: string;
|
|
138
|
+
token?: string;
|
|
139
|
+
internalTransactions: InternalTransaction[];
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
export interface ITransactionsFilter extends IPagination {
|
package/src/kvstore.ts
CHANGED
|
@@ -103,7 +103,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
103
103
|
* **KVStoreClient constructor**
|
|
104
104
|
*
|
|
105
105
|
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
106
|
-
* @param {NetworkData}
|
|
106
|
+
* @param {NetworkData} networkData - The network information required to connect to the KVStore contract
|
|
107
107
|
*/
|
|
108
108
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
109
109
|
super(runner, networkData);
|
package/src/operator.ts
CHANGED
|
@@ -65,6 +65,7 @@ export class OperatorUtils {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
let jobTypes: string[] = [];
|
|
68
|
+
let reputationNetworks: string[] = [];
|
|
68
69
|
|
|
69
70
|
if (typeof leader.jobTypes === 'string') {
|
|
70
71
|
jobTypes = leader.jobTypes.split(',');
|
|
@@ -72,9 +73,17 @@ export class OperatorUtils {
|
|
|
72
73
|
jobTypes = leader.jobTypes;
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
if (leader.reputationNetworks && Array.isArray(leader.reputationNetworks)) {
|
|
77
|
+
reputationNetworks = leader.reputationNetworks.map(
|
|
78
|
+
(network) => network.address
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
return {
|
|
76
83
|
...leader,
|
|
77
84
|
jobTypes,
|
|
85
|
+
reputationNetworks,
|
|
86
|
+
chainId,
|
|
78
87
|
};
|
|
79
88
|
}
|
|
80
89
|
|
|
@@ -118,6 +127,7 @@ export class OperatorUtils {
|
|
|
118
127
|
leaders_data = leaders_data.concat(
|
|
119
128
|
leaders.map((leader) => {
|
|
120
129
|
let jobTypes: string[] = [];
|
|
130
|
+
let reputationNetworks: string[] = [];
|
|
121
131
|
|
|
122
132
|
if (typeof leader.jobTypes === 'string') {
|
|
123
133
|
jobTypes = leader.jobTypes.split(',');
|
|
@@ -125,9 +135,20 @@ export class OperatorUtils {
|
|
|
125
135
|
jobTypes = leader.jobTypes;
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
if (
|
|
139
|
+
leader.reputationNetworks &&
|
|
140
|
+
Array.isArray(leader.reputationNetworks)
|
|
141
|
+
) {
|
|
142
|
+
reputationNetworks = leader.reputationNetworks.map(
|
|
143
|
+
(network) => network.address
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
128
147
|
return {
|
|
129
148
|
...leader,
|
|
130
149
|
jobTypes,
|
|
150
|
+
reputationNetworks,
|
|
151
|
+
chainId: filter.chainId,
|
|
131
152
|
};
|
|
132
153
|
})
|
|
133
154
|
);
|