@human-protocol/sdk 3.0.7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +2 -25
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +25 -66
- package/dist/decorators.js +1 -1
- package/dist/encryption.d.ts +21 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +34 -36
- package/dist/error.d.ts +31 -28
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +36 -33
- package/dist/escrow.d.ts +118 -112
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +254 -180
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +15 -7
- 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 +29 -12
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +16 -16
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +16 -16
- package/dist/operator.d.ts +11 -10
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +36 -11
- package/dist/staking.d.ts +26 -118
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +46 -173
- package/dist/statistics.d.ts +10 -29
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +13 -30
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +30 -25
- package/dist/transaction.js +1 -1
- package/dist/types.d.ts +23 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -1
- package/package.json +8 -4
- package/src/constants.ts +25 -66
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/error.ts +39 -37
- package/src/escrow.ts +360 -216
- package/src/graphql/queries/operator.ts +15 -7
- 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 +30 -13
- package/src/kvstore.ts +17 -17
- package/src/operator.ts +47 -12
- package/src/staking.ts +53 -187
- package/src/statistics.ts +13 -30
- package/src/storage.ts +13 -18
- package/src/transaction.ts +2 -2
- package/src/types.ts +24 -6
- package/src/utils.ts +0 -1
|
@@ -6,42 +6,50 @@ 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
|
|
|
28
28
|
export const GET_LEADERS_QUERY = (filter: ILeadersFilter) => {
|
|
29
|
-
const {
|
|
29
|
+
const { roles, minAmountStaked } = filter;
|
|
30
30
|
|
|
31
31
|
const WHERE_CLAUSE = `
|
|
32
32
|
where: {
|
|
33
|
-
${
|
|
33
|
+
${minAmountStaked ? `amountStaked_gte: $minAmountStaked` : ''}
|
|
34
|
+
${roles ? `role_in: $roles` : ''}
|
|
34
35
|
}
|
|
35
36
|
`;
|
|
36
37
|
|
|
37
38
|
return gql`
|
|
38
39
|
query getLeaders(
|
|
39
|
-
$
|
|
40
|
+
$minAmountStaked: Int,
|
|
41
|
+
$roles: [String!]
|
|
42
|
+
$first: Int
|
|
43
|
+
$skip: Int
|
|
44
|
+
$orderBy: String
|
|
45
|
+
$orderDirection: String
|
|
40
46
|
) {
|
|
41
47
|
leaders(
|
|
42
48
|
${WHERE_CLAUSE}
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
first: $first
|
|
50
|
+
skip: $skip
|
|
51
|
+
orderBy: $orderBy
|
|
52
|
+
orderDirection: $orderDirection
|
|
45
53
|
) {
|
|
46
54
|
...LeaderFields
|
|
47
55
|
}
|
|
@@ -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,31 +11,35 @@ 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
|
-
export interface ILeadersFilter {
|
|
38
|
+
export interface ILeadersFilter extends IPagination {
|
|
45
39
|
chainId: ChainId;
|
|
46
|
-
|
|
40
|
+
roles?: string[];
|
|
41
|
+
minAmountStaked?: number;
|
|
42
|
+
orderBy?: string;
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
export interface IReputationNetwork {
|
|
@@ -121,6 +117,16 @@ export interface IKVStore {
|
|
|
121
117
|
value: string;
|
|
122
118
|
}
|
|
123
119
|
|
|
120
|
+
export interface InternalTransaction {
|
|
121
|
+
from: string;
|
|
122
|
+
to: string;
|
|
123
|
+
value: string;
|
|
124
|
+
method: string;
|
|
125
|
+
receiver?: string;
|
|
126
|
+
escrow?: string;
|
|
127
|
+
token?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
124
130
|
export interface ITransaction {
|
|
125
131
|
block: bigint;
|
|
126
132
|
txHash: string;
|
|
@@ -129,6 +135,10 @@ export interface ITransaction {
|
|
|
129
135
|
timestamp: bigint;
|
|
130
136
|
value: string;
|
|
131
137
|
method: string;
|
|
138
|
+
receiver?: string;
|
|
139
|
+
escrow?: string;
|
|
140
|
+
token?: string;
|
|
141
|
+
internalTransactions: InternalTransaction[];
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
export interface ITransactionsFilter extends IPagination {
|
|
@@ -146,3 +156,10 @@ export interface IPagination {
|
|
|
146
156
|
skip?: number;
|
|
147
157
|
orderDirection?: OrderDirection;
|
|
148
158
|
}
|
|
159
|
+
|
|
160
|
+
export interface StakerInfo {
|
|
161
|
+
stakedAmount: bigint;
|
|
162
|
+
lockedAmount: bigint;
|
|
163
|
+
lockedUntil: bigint;
|
|
164
|
+
withdrawableAmount: bigint;
|
|
165
|
+
}
|
package/src/kvstore.ts
CHANGED
|
@@ -29,19 +29,19 @@ import { IKVStore } from './interfaces';
|
|
|
29
29
|
/**
|
|
30
30
|
* ## Introduction
|
|
31
31
|
*
|
|
32
|
-
* This client enables
|
|
32
|
+
* This client enables performing actions on KVStore contract and obtaining information from both the contracts and subgraph.
|
|
33
33
|
*
|
|
34
34
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
35
35
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
36
36
|
*
|
|
37
37
|
* ```ts
|
|
38
|
-
* static async build(runner: ContractRunner)
|
|
38
|
+
* static async build(runner: ContractRunner): Promise<KVStoreClient>;
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
41
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
42
42
|
*
|
|
43
|
-
* - **Signer**: when the user wants to use this model
|
|
44
|
-
* - **Provider**: when the user wants to use this model
|
|
43
|
+
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
44
|
+
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
45
45
|
*
|
|
46
46
|
* ## Installation
|
|
47
47
|
*
|
|
@@ -59,21 +59,21 @@ import { IKVStore } from './interfaces';
|
|
|
59
59
|
*
|
|
60
60
|
* ### Signer
|
|
61
61
|
*
|
|
62
|
-
* **Using private key(backend)**
|
|
62
|
+
* **Using private key (backend)**
|
|
63
63
|
*
|
|
64
64
|
* ```ts
|
|
65
65
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
66
66
|
* import { Wallet, providers } from 'ethers';
|
|
67
67
|
*
|
|
68
68
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
69
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
69
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
70
70
|
*
|
|
71
71
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
72
72
|
* const signer = new Wallet(privateKey, provider);
|
|
73
73
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
74
74
|
* ```
|
|
75
75
|
*
|
|
76
|
-
* **Using Wagmi(frontend)**
|
|
76
|
+
* **Using Wagmi (frontend)**
|
|
77
77
|
*
|
|
78
78
|
* ```ts
|
|
79
79
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -92,7 +92,7 @@ import { IKVStore } from './interfaces';
|
|
|
92
92
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
93
93
|
*
|
|
94
94
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
95
|
-
* const kvstoreClient = await KVStoreClient.build(
|
|
95
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
|
|
@@ -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);
|
|
@@ -123,7 +123,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
123
123
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
124
124
|
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
125
125
|
*/
|
|
126
|
-
public static async build(runner: ContractRunner) {
|
|
126
|
+
public static async build(runner: ContractRunner): Promise<KVStoreClient> {
|
|
127
127
|
if (!runner.provider) {
|
|
128
128
|
throw ErrorProviderDoesNotExist;
|
|
129
129
|
}
|
|
@@ -158,7 +158,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
158
158
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
159
159
|
*
|
|
160
160
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
161
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
161
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
162
162
|
*
|
|
163
163
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
164
164
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -199,7 +199,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
199
199
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
200
200
|
*
|
|
201
201
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
202
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
202
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
203
203
|
*
|
|
204
204
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
205
205
|
* const signer = new Wallet(privateKey, provider);
|
|
@@ -207,7 +207,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
207
207
|
*
|
|
208
208
|
* const keys = ['role', 'webhook_url'];
|
|
209
209
|
* const values = ['RecordingOracle', 'http://localhost'];
|
|
210
|
-
* await kvstoreClient.
|
|
210
|
+
* await kvstoreClient.setBulk(keys, values);
|
|
211
211
|
* ```
|
|
212
212
|
*/
|
|
213
213
|
@requiresSigner
|
|
@@ -243,14 +243,14 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
243
243
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
244
244
|
*
|
|
245
245
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
246
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
246
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
247
247
|
*
|
|
248
248
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
249
249
|
* const signer = new Wallet(privateKey, provider);
|
|
250
250
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
251
251
|
*
|
|
252
252
|
* await kvstoreClient.setFileUrlAndHash('example.com');
|
|
253
|
-
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
|
|
253
|
+
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url');
|
|
254
254
|
* ```
|
|
255
255
|
*/
|
|
256
256
|
@requiresSigner
|
|
@@ -309,9 +309,9 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
309
309
|
* ```ts
|
|
310
310
|
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
311
311
|
*
|
|
312
|
-
* const KVStoreAddresses =
|
|
312
|
+
* const KVStoreAddresses = await KVStoreUtils.getKVStoreData(
|
|
313
313
|
* ChainId.POLYGON_AMOY,
|
|
314
|
-
* "0x1234567890123456789012345678901234567890"
|
|
314
|
+
* "0x1234567890123456789012345678901234567890"
|
|
315
315
|
* );
|
|
316
316
|
* ```
|
|
317
317
|
*/
|
package/src/operator.ts
CHANGED
|
@@ -22,16 +22,16 @@ import {
|
|
|
22
22
|
ErrorUnsupportedChainID,
|
|
23
23
|
} from './error';
|
|
24
24
|
import { getSubgraphUrl } from './utils';
|
|
25
|
-
import { ChainId } from './enums';
|
|
25
|
+
import { ChainId, OrderDirection } from './enums';
|
|
26
26
|
import { NETWORKS } from './constants';
|
|
27
27
|
|
|
28
28
|
export class OperatorUtils {
|
|
29
29
|
/**
|
|
30
30
|
* This function returns the leader data for the given address.
|
|
31
31
|
*
|
|
32
|
+
* @param {ChainId} chainId Network in which the leader is deployed
|
|
32
33
|
* @param {string} address Leader address.
|
|
33
|
-
* @returns {ILeader} Returns the leader details.
|
|
34
|
-
*
|
|
34
|
+
* @returns {Promise<ILeader>} Returns the leader details.
|
|
35
35
|
*
|
|
36
36
|
* **Code example**
|
|
37
37
|
*
|
|
@@ -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
|
|
|
@@ -82,13 +91,12 @@ export class OperatorUtils {
|
|
|
82
91
|
* This function returns all the leader details of the protocol.
|
|
83
92
|
*
|
|
84
93
|
* @param {ILeadersFilter} filter Filter for the leaders.
|
|
85
|
-
* @returns {ILeader[]} Returns an array with all the leader details.
|
|
86
|
-
*
|
|
94
|
+
* @returns {Promise<ILeader[]>} Returns an array with all the leader details.
|
|
87
95
|
*
|
|
88
96
|
* **Code example**
|
|
89
97
|
*
|
|
90
98
|
* ```ts
|
|
91
|
-
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
99
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
92
100
|
*
|
|
93
101
|
* const filter: ILeadersFilter = {
|
|
94
102
|
* chainId: ChainId.POLYGON
|
|
@@ -99,6 +107,14 @@ export class OperatorUtils {
|
|
|
99
107
|
public static async getLeaders(filter: ILeadersFilter): Promise<ILeader[]> {
|
|
100
108
|
let leaders_data: ILeader[] = [];
|
|
101
109
|
|
|
110
|
+
const first =
|
|
111
|
+
filter.first !== undefined && filter.first > 0
|
|
112
|
+
? Math.min(filter.first, 1000)
|
|
113
|
+
: 10;
|
|
114
|
+
const skip =
|
|
115
|
+
filter.skip !== undefined && filter.skip >= 0 ? filter.skip : 0;
|
|
116
|
+
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
117
|
+
|
|
102
118
|
const networkData = NETWORKS[filter.chainId];
|
|
103
119
|
|
|
104
120
|
if (!networkData) {
|
|
@@ -108,7 +124,12 @@ export class OperatorUtils {
|
|
|
108
124
|
const { leaders } = await gqlFetch<{
|
|
109
125
|
leaders: ILeaderSubgraph[];
|
|
110
126
|
}>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), {
|
|
111
|
-
|
|
127
|
+
minAmountStaked: filter?.minAmountStaked,
|
|
128
|
+
roles: filter?.roles,
|
|
129
|
+
orderBy: filter?.orderBy,
|
|
130
|
+
orderDirection: orderDirection,
|
|
131
|
+
first: first,
|
|
132
|
+
skip: skip,
|
|
112
133
|
});
|
|
113
134
|
|
|
114
135
|
if (!leaders) {
|
|
@@ -118,6 +139,7 @@ export class OperatorUtils {
|
|
|
118
139
|
leaders_data = leaders_data.concat(
|
|
119
140
|
leaders.map((leader) => {
|
|
120
141
|
let jobTypes: string[] = [];
|
|
142
|
+
let reputationNetworks: string[] = [];
|
|
121
143
|
|
|
122
144
|
if (typeof leader.jobTypes === 'string') {
|
|
123
145
|
jobTypes = leader.jobTypes.split(',');
|
|
@@ -125,9 +147,20 @@ export class OperatorUtils {
|
|
|
125
147
|
jobTypes = leader.jobTypes;
|
|
126
148
|
}
|
|
127
149
|
|
|
150
|
+
if (
|
|
151
|
+
leader.reputationNetworks &&
|
|
152
|
+
Array.isArray(leader.reputationNetworks)
|
|
153
|
+
) {
|
|
154
|
+
reputationNetworks = leader.reputationNetworks.map(
|
|
155
|
+
(network) => network.address
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
128
159
|
return {
|
|
129
160
|
...leader,
|
|
130
161
|
jobTypes,
|
|
162
|
+
reputationNetworks,
|
|
163
|
+
chainId: filter.chainId,
|
|
131
164
|
};
|
|
132
165
|
})
|
|
133
166
|
);
|
|
@@ -137,12 +170,14 @@ export class OperatorUtils {
|
|
|
137
170
|
/**
|
|
138
171
|
* Retrieves the reputation network operators of the specified address.
|
|
139
172
|
*
|
|
140
|
-
* @param {
|
|
173
|
+
* @param {ChainId} chainId Network in which the reputation network is deployed
|
|
174
|
+
* @param {string} address Address of the reputation oracle.
|
|
141
175
|
* @param {string} [role] - (Optional) Role of the operator.
|
|
142
176
|
* @returns {Promise<IOperator[]>} - Returns an array of operator details.
|
|
143
177
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
178
|
+
* **Code example**
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
146
181
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
147
182
|
*
|
|
148
183
|
* const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
@@ -186,9 +221,9 @@ export class OperatorUtils {
|
|
|
186
221
|
/**
|
|
187
222
|
* This function returns information about the rewards for a given slasher address.
|
|
188
223
|
*
|
|
224
|
+
* @param {ChainId} chainId Network in which the rewards are deployed
|
|
189
225
|
* @param {string} slasherAddress Slasher address.
|
|
190
|
-
* @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
191
|
-
*
|
|
226
|
+
* @returns {Promise<IReward[]>} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
192
227
|
*
|
|
193
228
|
* **Code example**
|
|
194
229
|
*
|