@human-protocol/sdk 1.1.19 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +3 -3
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +4 -2
- package/dist/error.d.ts +0 -6
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -14
- package/dist/escrow.d.ts +23 -24
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +86 -90
- package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -0
- package/dist/graphql/queries/{staking.js → operator.js} +24 -1
- package/dist/graphql/types.d.ts +5 -6
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +28 -18
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +8 -9
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +18 -31
- package/dist/operator.d.ts +68 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +153 -0
- package/dist/staking.d.ts +24 -91
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +47 -166
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +7 -6
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +8 -28
- package/package.json +4 -4
- package/src/base.ts +5 -6
- package/src/decorators.ts +3 -2
- package/src/error.ts +0 -12
- package/src/escrow.ts +101 -114
- package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
- package/src/graphql/types.ts +5 -7
- package/src/index.ts +2 -0
- package/src/interfaces.ts +30 -18
- package/src/kvstore.ts +20 -38
- package/src/operator.ts +192 -0
- package/src/staking.ts +49 -182
- package/src/statistics.ts +8 -9
- package/src/types.ts +1 -3
- package/src/utils.ts +7 -29
- package/dist/graphql/queries/staking.d.ts.map +0 -1
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
1
|
import { EscrowStatus } from './types';
|
|
3
2
|
import { ChainId } from './enums';
|
|
4
3
|
export interface IAllocation {
|
|
5
4
|
escrowAddress: string;
|
|
6
5
|
staker: string;
|
|
7
|
-
tokens:
|
|
8
|
-
createdAt:
|
|
9
|
-
closedAt:
|
|
6
|
+
tokens: bigint;
|
|
7
|
+
createdAt: bigint;
|
|
8
|
+
closedAt: bigint;
|
|
10
9
|
}
|
|
11
10
|
export interface IReward {
|
|
12
11
|
escrowAddress: string;
|
|
13
|
-
amount:
|
|
12
|
+
amount: bigint;
|
|
14
13
|
}
|
|
15
14
|
export interface ILeader {
|
|
16
15
|
id: string;
|
|
16
|
+
chainId: ChainId;
|
|
17
17
|
address: string;
|
|
18
|
-
amountStaked:
|
|
19
|
-
amountAllocated:
|
|
20
|
-
amountLocked:
|
|
21
|
-
lockedUntilTimestamp:
|
|
22
|
-
amountWithdrawn:
|
|
23
|
-
amountSlashed:
|
|
24
|
-
reputation:
|
|
25
|
-
reward:
|
|
26
|
-
amountJobsLaunched:
|
|
18
|
+
amountStaked: bigint;
|
|
19
|
+
amountAllocated: bigint;
|
|
20
|
+
amountLocked: bigint;
|
|
21
|
+
lockedUntilTimestamp: bigint;
|
|
22
|
+
amountWithdrawn: bigint;
|
|
23
|
+
amountSlashed: bigint;
|
|
24
|
+
reputation: bigint;
|
|
25
|
+
reward: bigint;
|
|
26
|
+
amountJobsLaunched: bigint;
|
|
27
27
|
role?: string;
|
|
28
|
-
fee?:
|
|
28
|
+
fee?: bigint;
|
|
29
29
|
publicKey?: string;
|
|
30
30
|
webhookUrl?: string;
|
|
31
31
|
url?: string;
|
|
32
32
|
}
|
|
33
33
|
export interface ILeadersFilter {
|
|
34
|
+
networks: ChainId[];
|
|
35
|
+
role?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface IReputationNetwork {
|
|
38
|
+
id: string;
|
|
39
|
+
address: string;
|
|
40
|
+
operators: IOperator[];
|
|
41
|
+
}
|
|
42
|
+
export interface IOperator {
|
|
43
|
+
address: string;
|
|
34
44
|
role?: string;
|
|
35
45
|
}
|
|
36
46
|
export interface IEscrowsFilter {
|
|
@@ -48,9 +58,9 @@ export interface IEscrowConfig {
|
|
|
48
58
|
recordingOracle: string;
|
|
49
59
|
reputationOracle: string;
|
|
50
60
|
exchangeOracle: string;
|
|
51
|
-
recordingOracleFee:
|
|
52
|
-
reputationOracleFee:
|
|
53
|
-
exchangeOracleFee:
|
|
61
|
+
recordingOracleFee: bigint;
|
|
62
|
+
reputationOracleFee: bigint;
|
|
63
|
+
exchangeOracleFee: bigint;
|
|
54
64
|
manifestUrl: string;
|
|
55
65
|
manifestHash: string;
|
|
56
66
|
}
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,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AAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX"}
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Overrides, Signer } from 'ethers';
|
|
1
|
+
import { ContractRunner, Overrides } from 'ethers';
|
|
3
2
|
import { BaseEthersClient } from './base';
|
|
4
3
|
import { NetworkData } from './types';
|
|
5
4
|
/**
|
|
@@ -7,11 +6,11 @@ import { NetworkData } from './types';
|
|
|
7
6
|
*
|
|
8
7
|
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
9
8
|
*
|
|
10
|
-
* Internally, the SDK will use one network or another according to the network ID of the `
|
|
9
|
+
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
11
10
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
12
11
|
*
|
|
13
12
|
* ```ts
|
|
14
|
-
* static async build(
|
|
13
|
+
* static async build(runner: ContractRunner);
|
|
15
14
|
* ```
|
|
16
15
|
*
|
|
17
16
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
@@ -76,20 +75,20 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
76
75
|
/**
|
|
77
76
|
* **KVStoreClient constructor**
|
|
78
77
|
*
|
|
79
|
-
* @param {
|
|
78
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
80
79
|
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
81
80
|
*/
|
|
82
|
-
constructor(
|
|
81
|
+
constructor(runner: ContractRunner, networkData: NetworkData);
|
|
83
82
|
/**
|
|
84
|
-
* Creates an instance of KVStoreClient from a
|
|
83
|
+
* Creates an instance of KVStoreClient from a runner.
|
|
85
84
|
*
|
|
86
|
-
* @param {
|
|
85
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
87
86
|
*
|
|
88
87
|
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
89
88
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
90
89
|
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
91
90
|
*/
|
|
92
|
-
static build(
|
|
91
|
+
static build(runner: ContractRunner): Promise<KVStoreClient>;
|
|
93
92
|
/**
|
|
94
93
|
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
95
94
|
*
|
package/dist/kvstore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ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
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
24
24
|
*
|
|
25
|
-
* Internally, the SDK will use one network or another according to the network ID of the `
|
|
25
|
+
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
26
26
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
27
27
|
*
|
|
28
28
|
* ```ts
|
|
29
|
-
* static async build(
|
|
29
|
+
* static async build(runner: ContractRunner);
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
32
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
@@ -90,39 +90,33 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
90
90
|
/**
|
|
91
91
|
* **KVStoreClient constructor**
|
|
92
92
|
*
|
|
93
|
-
* @param {
|
|
93
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
94
94
|
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
95
95
|
*/
|
|
96
|
-
constructor(
|
|
97
|
-
super(
|
|
98
|
-
this.contract = typechain_types_1.KVStore__factory.connect(networkData.kvstoreAddress,
|
|
96
|
+
constructor(runner, networkData) {
|
|
97
|
+
super(runner, networkData);
|
|
98
|
+
this.contract = typechain_types_1.KVStore__factory.connect(networkData.kvstoreAddress, runner);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Creates an instance of KVStoreClient from a
|
|
101
|
+
* Creates an instance of KVStoreClient from a runner.
|
|
102
102
|
*
|
|
103
|
-
* @param {
|
|
103
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
104
104
|
*
|
|
105
105
|
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
106
106
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
107
107
|
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
108
108
|
*/
|
|
109
|
-
static async build(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!signerOrProvider.provider) {
|
|
113
|
-
throw error_1.ErrorProviderDoesNotExist;
|
|
114
|
-
}
|
|
115
|
-
network = await signerOrProvider.provider.getNetwork();
|
|
109
|
+
static async build(runner) {
|
|
110
|
+
if (!runner.provider) {
|
|
111
|
+
throw error_1.ErrorProviderDoesNotExist;
|
|
116
112
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
const chainId = network.chainId;
|
|
113
|
+
const network = await runner.provider?.getNetwork();
|
|
114
|
+
const chainId = Number(network?.chainId);
|
|
121
115
|
const networkData = constants_1.NETWORKS[chainId];
|
|
122
116
|
if (!networkData) {
|
|
123
117
|
throw error_1.ErrorUnsupportedChainID;
|
|
124
118
|
}
|
|
125
|
-
return new KVStoreClient(
|
|
119
|
+
return new KVStoreClient(runner, networkData);
|
|
126
120
|
}
|
|
127
121
|
/**
|
|
128
122
|
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
@@ -152,8 +146,6 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
152
146
|
* ```
|
|
153
147
|
*/
|
|
154
148
|
async set(key, value, txOptions = {}) {
|
|
155
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
156
|
-
throw error_1.ErrorSigner;
|
|
157
149
|
if (key === '')
|
|
158
150
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
159
151
|
try {
|
|
@@ -194,8 +186,6 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
194
186
|
* ```
|
|
195
187
|
*/
|
|
196
188
|
async setBulk(keys, values, txOptions = {}) {
|
|
197
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
198
|
-
throw error_1.ErrorSigner;
|
|
199
189
|
if (keys.length !== values.length)
|
|
200
190
|
throw error_1.ErrorKVStoreArrayLength;
|
|
201
191
|
if (keys.includes(''))
|
|
@@ -235,14 +225,11 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
235
225
|
* ```
|
|
236
226
|
*/
|
|
237
227
|
async setURL(url, urlKey = 'url', txOptions = {}) {
|
|
238
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
239
|
-
throw error_1.ErrorSigner;
|
|
240
|
-
}
|
|
241
228
|
if (!(0, utils_1.isValidUrl)(url)) {
|
|
242
229
|
throw error_1.ErrorInvalidUrl;
|
|
243
230
|
}
|
|
244
231
|
const content = await fetch(url).then((res) => res.text());
|
|
245
|
-
const contentHash = ethers_1.ethers.
|
|
232
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
246
233
|
const hashKey = urlKey + 'Hash';
|
|
247
234
|
try {
|
|
248
235
|
await (await this.contract.setBulk([urlKey, hashKey], [url, contentHash], txOptions)).wait();
|
|
@@ -279,7 +266,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
279
266
|
async get(address, key) {
|
|
280
267
|
if (key === '')
|
|
281
268
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
282
|
-
if (!ethers_1.ethers.
|
|
269
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
283
270
|
throw error_1.ErrorInvalidAddress;
|
|
284
271
|
try {
|
|
285
272
|
const result = await this.contract?.get(address, key);
|
|
@@ -318,7 +305,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
318
305
|
* ```
|
|
319
306
|
*/
|
|
320
307
|
async getURL(address, urlKey = 'url') {
|
|
321
|
-
if (!ethers_1.ethers.
|
|
308
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
322
309
|
throw error_1.ErrorInvalidAddress;
|
|
323
310
|
const hashKey = urlKey + 'Hash';
|
|
324
311
|
let url = '', hash = '';
|
|
@@ -341,7 +328,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
341
328
|
throw Error(`Failed to get Hash: ${e.message}`);
|
|
342
329
|
}
|
|
343
330
|
const content = await fetch(url).then((res) => res.text());
|
|
344
|
-
const contentHash = ethers_1.ethers.
|
|
331
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
345
332
|
if (hash !== contentHash) {
|
|
346
333
|
throw error_1.ErrorInvalidHash;
|
|
347
334
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ILeader, ILeadersFilter, IOperator, IReward } from './interfaces';
|
|
2
|
+
import { ChainId } from './enums';
|
|
3
|
+
export declare class OperatorUtils {
|
|
4
|
+
/**
|
|
5
|
+
* This function returns the leader data for the given address.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} address Leader address.
|
|
8
|
+
* @returns {ILeader} Returns the leader details.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* **Code example**
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
15
|
+
*
|
|
16
|
+
* const leader = await OperatorUtils.getLeader(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
static getLeader(chainId: ChainId, address: string): Promise<ILeader>;
|
|
20
|
+
/**
|
|
21
|
+
* This function returns all the leader details of the protocol.
|
|
22
|
+
*
|
|
23
|
+
* @param {ILeadersFilter} filter Filter for the leaders.
|
|
24
|
+
* @returns {ILeader[]} Returns an array with all the leader details.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* **Code example**
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
31
|
+
*
|
|
32
|
+
* const leaders = await OperatorUtils.getLeaders();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
static getLeaders(filter?: ILeadersFilter): Promise<ILeader[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the reputation network operators of the specified address.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} address - Address of the reputation oracle.
|
|
40
|
+
* @param {string} [role] - (Optional) Role of the operator.
|
|
41
|
+
* @returns {Promise<IOperator[]>} - Returns an array of operator details.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
46
|
+
*
|
|
47
|
+
* const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
static getReputationNetworkOperators(chainId: ChainId, address: string, role?: string): Promise<IOperator[]>;
|
|
51
|
+
/**
|
|
52
|
+
* This function returns information about the rewards for a given slasher address.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} slasherAddress Slasher address.
|
|
55
|
+
* @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
56
|
+
*
|
|
57
|
+
*
|
|
58
|
+
* **Code example**
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
62
|
+
*
|
|
63
|
+
* const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
static getRewards(chainId: ChainId, slasherAddress: string): Promise<IReward[]>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=operator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EAET,OAAO,EACR,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,MAAM,GAAE,cAAuD,GAC9D,OAAO,CAAC,OAAO,EAAE,CAAC;IAuBrB;;;;;;;;;;;;;OAaG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC;IAoBvB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC;CA2BtB"}
|
package/dist/operator.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OperatorUtils = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
9
|
+
const reward_1 = require("./graphql/queries/reward");
|
|
10
|
+
const operator_1 = require("./graphql/queries/operator");
|
|
11
|
+
const ethers_1 = require("ethers");
|
|
12
|
+
const error_1 = require("./error");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const enums_1 = require("./enums");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
class OperatorUtils {
|
|
17
|
+
/**
|
|
18
|
+
* This function returns the leader data for the given address.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} address Leader address.
|
|
21
|
+
* @returns {ILeader} Returns the leader details.
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* **Code example**
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
28
|
+
*
|
|
29
|
+
* const leader = await OperatorUtils.getLeader(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
static async getLeader(chainId, address) {
|
|
33
|
+
if (!ethers_1.ethers.isAddress(address)) {
|
|
34
|
+
throw error_1.ErrorInvalidStakerAddressProvided;
|
|
35
|
+
}
|
|
36
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
37
|
+
if (!networkData) {
|
|
38
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const { leader } = await (0, graphql_request_1.default)(networkData.subgraphUrl, operator_1.GET_LEADER_QUERY, {
|
|
42
|
+
address: address.toLowerCase(),
|
|
43
|
+
});
|
|
44
|
+
return leader;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return (0, utils_1.throwError)(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This function returns all the leader details of the protocol.
|
|
52
|
+
*
|
|
53
|
+
* @param {ILeadersFilter} filter Filter for the leaders.
|
|
54
|
+
* @returns {ILeader[]} Returns an array with all the leader details.
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
* **Code example**
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
61
|
+
*
|
|
62
|
+
* const leaders = await OperatorUtils.getLeaders();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
static async getLeaders(filter = { networks: [enums_1.ChainId.POLYGON_MUMBAI] }) {
|
|
66
|
+
try {
|
|
67
|
+
let leaders_data = [];
|
|
68
|
+
for (const chainId of filter.networks) {
|
|
69
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
70
|
+
if (!networkData) {
|
|
71
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
72
|
+
}
|
|
73
|
+
const { leaders } = await (0, graphql_request_1.default)(networkData.subgraphUrl, (0, operator_1.GET_LEADERS_QUERY)(filter), {
|
|
74
|
+
role: filter.role,
|
|
75
|
+
});
|
|
76
|
+
leaders_data = leaders_data.concat(leaders);
|
|
77
|
+
}
|
|
78
|
+
return leaders_data;
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return (0, utils_1.throwError)(e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves the reputation network operators of the specified address.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} address - Address of the reputation oracle.
|
|
88
|
+
* @param {string} [role] - (Optional) Role of the operator.
|
|
89
|
+
* @returns {Promise<IOperator[]>} - Returns an array of operator details.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
94
|
+
*
|
|
95
|
+
* const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
static async getReputationNetworkOperators(chainId, address, role) {
|
|
99
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
100
|
+
if (!networkData) {
|
|
101
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const { reputationNetwork } = await (0, graphql_request_1.default)(networkData.subgraphUrl, (0, operator_1.GET_REPUTATION_NETWORK_QUERY)(role), {
|
|
105
|
+
address: address,
|
|
106
|
+
role: role,
|
|
107
|
+
});
|
|
108
|
+
return reputationNetwork.operators;
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return (0, utils_1.throwError)(e);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* This function returns information about the rewards for a given slasher address.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} slasherAddress Slasher address.
|
|
118
|
+
* @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
119
|
+
*
|
|
120
|
+
*
|
|
121
|
+
* **Code example**
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
125
|
+
*
|
|
126
|
+
* const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
static async getRewards(chainId, slasherAddress) {
|
|
130
|
+
if (!ethers_1.ethers.isAddress(slasherAddress)) {
|
|
131
|
+
throw error_1.ErrorInvalidSlasherAddressProvided;
|
|
132
|
+
}
|
|
133
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
134
|
+
if (!networkData) {
|
|
135
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const { rewardAddedEvents } = await (0, graphql_request_1.default)(networkData.subgraphUrl, reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
139
|
+
slasherAddress: slasherAddress.toLowerCase(),
|
|
140
|
+
});
|
|
141
|
+
return rewardAddedEvents.map((reward) => {
|
|
142
|
+
return {
|
|
143
|
+
escrowAddress: reward.escrow,
|
|
144
|
+
amount: reward.amount,
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
return (0, utils_1.throwError)(e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.OperatorUtils = OperatorUtils;
|