@human-protocol/sdk 6.1.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +26 -14
- package/dist/encryption/encryption.d.ts +84 -0
- package/dist/encryption/encryption.d.ts.map +1 -0
- package/dist/{encryption.js → encryption/encryption.js} +3 -161
- package/dist/encryption/encryption_utils.d.ts +101 -0
- package/dist/encryption/encryption_utils.d.ts.map +1 -0
- package/dist/encryption/encryption_utils.js +191 -0
- package/dist/encryption/index.d.ts +4 -0
- package/dist/encryption/index.d.ts.map +1 -0
- package/dist/encryption/index.js +7 -0
- package/dist/encryption/types.d.ts +9 -0
- package/dist/encryption/types.d.ts.map +1 -0
- package/dist/encryption/types.js +9 -0
- package/dist/error.d.ts +6 -10
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -14
- package/dist/{escrow.d.ts → escrow/escrow_client.d.ts} +4 -184
- package/dist/{escrow.d.ts.map → escrow/escrow_client.d.ts.map} +1 -1
- package/dist/{escrow.js → escrow/escrow_client.js} +35 -411
- package/dist/escrow/escrow_utils.d.ts +172 -0
- package/dist/escrow/escrow_utils.d.ts.map +1 -0
- package/dist/escrow/escrow_utils.js +388 -0
- package/dist/escrow/index.d.ts +3 -0
- package/dist/escrow/index.d.ts.map +1 -0
- package/dist/escrow/index.js +7 -0
- package/dist/graphql/queries/statistics.d.ts +1 -0
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +36 -2
- package/dist/graphql/types.d.ts +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -22
- package/dist/interfaces.d.ts +0 -5
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore/index.d.ts +3 -0
- package/dist/kvstore/index.d.ts.map +1 -0
- package/dist/kvstore/index.js +7 -0
- package/dist/{kvstore.d.ts → kvstore/kvstore_client.d.ts} +3 -108
- package/dist/kvstore/kvstore_client.d.ts.map +1 -0
- package/dist/{kvstore.js → kvstore/kvstore_client.js} +22 -184
- package/dist/kvstore/kvstore_utils.d.ts +105 -0
- package/dist/kvstore/kvstore_utils.d.ts.map +1 -0
- package/dist/kvstore/kvstore_utils.js +184 -0
- package/dist/operator/index.d.ts +2 -0
- package/dist/operator/index.d.ts.map +1 -0
- package/dist/operator/index.js +5 -0
- package/dist/{operator.d.ts → operator/operator_utils.d.ts} +3 -3
- package/dist/operator/operator_utils.d.ts.map +1 -0
- package/dist/{operator.js → operator/operator_utils.js} +6 -6
- package/dist/staking/index.d.ts +3 -0
- package/dist/staking/index.d.ts.map +1 -0
- package/dist/staking/index.js +7 -0
- package/dist/{staking.d.ts → staking/staking_client.d.ts} +4 -65
- package/dist/staking/staking_client.d.ts.map +1 -0
- package/dist/{staking.js → staking/staking_client.js} +6 -136
- package/dist/staking/staking_utils.d.ts +63 -0
- package/dist/staking/staking_utils.d.ts.map +1 -0
- package/dist/staking/staking_utils.js +137 -0
- package/dist/statistics/index.d.ts +2 -0
- package/dist/statistics/index.d.ts.map +1 -0
- package/dist/statistics/index.js +5 -0
- package/dist/{statistics.d.ts → statistics/statistics_utils.d.ts} +4 -13
- package/dist/statistics/statistics_utils.d.ts.map +1 -0
- package/dist/{statistics.js → statistics/statistics_utils.js} +8 -22
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +5 -0
- package/dist/{transaction.d.ts → transaction/transaction_utils.d.ts} +3 -3
- package/dist/transaction/transaction_utils.d.ts.map +1 -0
- package/dist/{transaction.js → transaction/transaction_utils.js} +5 -5
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -4
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +5 -0
- package/dist/{worker.d.ts → worker/worker_utils.d.ts} +3 -3
- package/dist/worker/worker_utils.d.ts.map +1 -0
- package/dist/{worker.js → worker/worker_utils.js} +5 -5
- package/package.json +4 -4
- package/src/constants.ts +38 -14
- package/src/{encryption.ts → encryption/encryption.ts} +1 -193
- package/src/encryption/encryption_utils.ts +179 -0
- package/src/encryption/index.ts +3 -0
- package/src/encryption/types.ts +15 -0
- package/src/error.ts +11 -17
- package/src/{escrow.ts → escrow/escrow_client.ts} +36 -556
- package/src/escrow/escrow_utils.ts +510 -0
- package/src/escrow/index.ts +2 -0
- package/src/graphql/queries/statistics.ts +37 -1
- package/src/graphql/types.ts +4 -1
- package/src/index.ts +11 -25
- package/src/interfaces.ts +0 -5
- package/src/kvstore/index.ts +2 -0
- package/src/{kvstore.ts → kvstore/kvstore_client.ts} +27 -241
- package/src/kvstore/kvstore_utils.ts +244 -0
- package/src/operator/index.ts +1 -0
- package/src/{operator.ts → operator/operator_utils.ts} +8 -8
- package/src/staking/index.ts +2 -0
- package/src/{staking.ts → staking/staking_client.ts} +8 -174
- package/src/staking/staking_utils.ts +170 -0
- package/src/statistics/index.ts +1 -0
- package/src/{statistics.ts → statistics/statistics_utils.ts} +14 -26
- package/src/transaction/index.ts +1 -0
- package/src/{transaction.ts → transaction/transaction_utils.ts} +7 -7
- package/src/types.ts +8 -0
- package/src/utils.ts +80 -3
- package/src/worker/index.ts +1 -0
- package/src/{worker.ts → worker/worker_utils.ts} +7 -7
- package/dist/encryption.d.ts +0 -189
- package/dist/encryption.d.ts.map +0 -1
- package/dist/kvstore.d.ts.map +0 -1
- package/dist/operator.d.ts.map +0 -1
- package/dist/staking.d.ts.map +0 -1
- package/dist/statistics.d.ts.map +0 -1
- package/dist/transaction.d.ts.map +0 -1
- package/dist/worker.d.ts.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ChainId } from '../enums';
|
|
2
|
+
import { IKVStore, SubgraphOptions } from '../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Utility helpers for KVStore-related queries.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
11
|
+
* ChainId.POLYGON_AMOY,
|
|
12
|
+
* "0x1234567890123456789012345678901234567890"
|
|
13
|
+
* );
|
|
14
|
+
* console.log('KVStore data:', kvStoreData);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class KVStoreUtils {
|
|
18
|
+
/**
|
|
19
|
+
* This function returns the KVStore data for a given address.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
22
|
+
* @param address - Address of the KVStore
|
|
23
|
+
* @param options - Optional configuration for subgraph requests.
|
|
24
|
+
* @returns KVStore data
|
|
25
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
26
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
31
|
+
* ChainId.POLYGON_AMOY,
|
|
32
|
+
* "0x1234567890123456789012345678901234567890"
|
|
33
|
+
* );
|
|
34
|
+
* console.log('KVStore data:', kvStoreData);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
static getKVStoreData(chainId: ChainId, address: string, options?: SubgraphOptions): Promise<IKVStore[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
40
|
+
*
|
|
41
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
42
|
+
* @param address - Address from which to get the key value.
|
|
43
|
+
* @param key - Key to obtain the value.
|
|
44
|
+
* @param options - Optional configuration for subgraph requests.
|
|
45
|
+
* @returns Value of the key.
|
|
46
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
47
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
48
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const value = await KVStoreUtils.get(
|
|
53
|
+
* ChainId.POLYGON_AMOY,
|
|
54
|
+
* '0x1234567890123456789012345678901234567890',
|
|
55
|
+
* 'role'
|
|
56
|
+
* );
|
|
57
|
+
* console.log('Value:', value);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
static get(chainId: ChainId, address: string, key: string, options?: SubgraphOptions): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the URL value of the given entity, and verifies its hash.
|
|
63
|
+
*
|
|
64
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
65
|
+
* @param address - Address from which to get the URL value.
|
|
66
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
67
|
+
* @param options - Optional configuration for subgraph requests.
|
|
68
|
+
* @returns URL value for the given address if it exists, and the content is valid
|
|
69
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
70
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
71
|
+
* @throws Error If fetching URL or hash fails
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(
|
|
76
|
+
* ChainId.POLYGON_AMOY,
|
|
77
|
+
* '0x1234567890123456789012345678901234567890'
|
|
78
|
+
* );
|
|
79
|
+
* console.log('Verified URL:', url);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static getFileUrlAndVerifyHash(chainId: ChainId, address: string, urlKey?: string, options?: SubgraphOptions): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the public key of the given entity, and verifies its hash.
|
|
85
|
+
*
|
|
86
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
87
|
+
* @param address - Address from which to get the public key.
|
|
88
|
+
* @param options - Optional configuration for subgraph requests.
|
|
89
|
+
* @returns Public key for the given address if it exists, and the content is valid
|
|
90
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
91
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
92
|
+
* @throws Error If fetching the public key fails
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const publicKey = await KVStoreUtils.getPublicKey(
|
|
97
|
+
* ChainId.POLYGON_AMOY,
|
|
98
|
+
* '0x1234567890123456789012345678901234567890'
|
|
99
|
+
* );
|
|
100
|
+
* console.log('Public key:', publicKey);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
static getPublicKey(chainId: ChainId, address: string, options?: SubgraphOptions): Promise<string>;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=kvstore_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kvstore_utils.d.ts","sourceRoot":"","sources":["../../src/kvstore/kvstore_utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAYnC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;;;;;;;;;;OAkBG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,QAAQ,EAAE,CAAC;IA0BtB;;;;;;;;;;;;;;;;;;;;;OAqBG;WACiB,GAAG,CACrB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;IAwBlB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,uBAAuB,CACzC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,SAAQ,EACd,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;IA8ClB;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,YAAY,CAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;CAgBnB"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KVStoreUtils = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const kvstore_1 = require("../graphql/queries/kvstore");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
/**
|
|
10
|
+
* Utility helpers for KVStore-related queries.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
15
|
+
*
|
|
16
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
17
|
+
* ChainId.POLYGON_AMOY,
|
|
18
|
+
* "0x1234567890123456789012345678901234567890"
|
|
19
|
+
* );
|
|
20
|
+
* console.log('KVStore data:', kvStoreData);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class KVStoreUtils {
|
|
24
|
+
/**
|
|
25
|
+
* This function returns the KVStore data for a given address.
|
|
26
|
+
*
|
|
27
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
28
|
+
* @param address - Address of the KVStore
|
|
29
|
+
* @param options - Optional configuration for subgraph requests.
|
|
30
|
+
* @returns KVStore data
|
|
31
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
32
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
37
|
+
* ChainId.POLYGON_AMOY,
|
|
38
|
+
* "0x1234567890123456789012345678901234567890"
|
|
39
|
+
* );
|
|
40
|
+
* console.log('KVStore data:', kvStoreData);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
static async getKVStoreData(chainId, address, options) {
|
|
44
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
45
|
+
if (!networkData) {
|
|
46
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
47
|
+
}
|
|
48
|
+
if (address && !ethers_1.ethers.isAddress(address)) {
|
|
49
|
+
throw error_1.ErrorInvalidAddress;
|
|
50
|
+
}
|
|
51
|
+
const { kvstores } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, kvstore_1.GET_KVSTORE_BY_ADDRESS_QUERY)(), { address: address.toLowerCase() }, options);
|
|
52
|
+
const kvStoreData = kvstores.map((item) => ({
|
|
53
|
+
key: item.key,
|
|
54
|
+
value: item.value,
|
|
55
|
+
}));
|
|
56
|
+
return kvStoreData || [];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
60
|
+
*
|
|
61
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
62
|
+
* @param address - Address from which to get the key value.
|
|
63
|
+
* @param key - Key to obtain the value.
|
|
64
|
+
* @param options - Optional configuration for subgraph requests.
|
|
65
|
+
* @returns Value of the key.
|
|
66
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
67
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
68
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const value = await KVStoreUtils.get(
|
|
73
|
+
* ChainId.POLYGON_AMOY,
|
|
74
|
+
* '0x1234567890123456789012345678901234567890',
|
|
75
|
+
* 'role'
|
|
76
|
+
* );
|
|
77
|
+
* console.log('Value:', value);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
static async get(chainId, address, key, options) {
|
|
81
|
+
if (key === '')
|
|
82
|
+
throw error_1.ErrorKVStoreEmptyKey;
|
|
83
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
84
|
+
throw error_1.ErrorInvalidAddress;
|
|
85
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
86
|
+
if (!networkData) {
|
|
87
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
88
|
+
}
|
|
89
|
+
const { kvstores } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, kvstore_1.GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY)(), { address: address.toLowerCase(), key }, options);
|
|
90
|
+
if (!kvstores || kvstores.length === 0) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
return kvstores[0].value;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Gets the URL value of the given entity, and verifies its hash.
|
|
97
|
+
*
|
|
98
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
99
|
+
* @param address - Address from which to get the URL value.
|
|
100
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
101
|
+
* @param options - Optional configuration for subgraph requests.
|
|
102
|
+
* @returns URL value for the given address if it exists, and the content is valid
|
|
103
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
104
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
105
|
+
* @throws Error If fetching URL or hash fails
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(
|
|
110
|
+
* ChainId.POLYGON_AMOY,
|
|
111
|
+
* '0x1234567890123456789012345678901234567890'
|
|
112
|
+
* );
|
|
113
|
+
* console.log('Verified URL:', url);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
static async getFileUrlAndVerifyHash(chainId, address, urlKey = 'url', options) {
|
|
117
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
118
|
+
throw error_1.ErrorInvalidAddress;
|
|
119
|
+
const hashKey = urlKey + '_hash';
|
|
120
|
+
let url;
|
|
121
|
+
try {
|
|
122
|
+
url = await this.get(chainId, address, urlKey, options);
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
if (e instanceof Error) {
|
|
126
|
+
throw Error(`Failed to get URL: ${e.message}`);
|
|
127
|
+
}
|
|
128
|
+
throw e;
|
|
129
|
+
}
|
|
130
|
+
if (!url) {
|
|
131
|
+
throw new Error('No URL found for the given address and key');
|
|
132
|
+
}
|
|
133
|
+
let hash;
|
|
134
|
+
try {
|
|
135
|
+
hash = await this.get(chainId, address, hashKey);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
if (e instanceof Error) {
|
|
139
|
+
throw Error(`Failed to get Hash: ${e.message}`);
|
|
140
|
+
}
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
if (!hash) {
|
|
144
|
+
throw new Error('No hash found for the given address and url');
|
|
145
|
+
}
|
|
146
|
+
const content = await fetch(url).then((res) => res.text());
|
|
147
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
148
|
+
const formattedHash = hash?.replace(/^0x/, '');
|
|
149
|
+
const formattedContentHash = contentHash?.replace(/^0x/, '');
|
|
150
|
+
if (formattedHash !== formattedContentHash) {
|
|
151
|
+
throw error_1.ErrorInvalidHash;
|
|
152
|
+
}
|
|
153
|
+
return url;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets the public key of the given entity, and verifies its hash.
|
|
157
|
+
*
|
|
158
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
159
|
+
* @param address - Address from which to get the public key.
|
|
160
|
+
* @param options - Optional configuration for subgraph requests.
|
|
161
|
+
* @returns Public key for the given address if it exists, and the content is valid
|
|
162
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
163
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
164
|
+
* @throws Error If fetching the public key fails
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const publicKey = await KVStoreUtils.getPublicKey(
|
|
169
|
+
* ChainId.POLYGON_AMOY,
|
|
170
|
+
* '0x1234567890123456789012345678901234567890'
|
|
171
|
+
* );
|
|
172
|
+
* console.log('Public key:', publicKey);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
static async getPublicKey(chainId, address, options) {
|
|
176
|
+
const publicKeyUrl = await this.getFileUrlAndVerifyHash(chainId, address, constants_1.KVStoreKeys.publicKey, options);
|
|
177
|
+
if (publicKeyUrl === '') {
|
|
178
|
+
return '';
|
|
179
|
+
}
|
|
180
|
+
const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
|
|
181
|
+
return publicKey;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.KVStoreUtils = KVStoreUtils;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperatorUtils = void 0;
|
|
4
|
+
var operator_utils_1 = require("./operator_utils");
|
|
5
|
+
Object.defineProperty(exports, "OperatorUtils", { enumerable: true, get: function () { return operator_utils_1.OperatorUtils; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IOperator, IOperatorsFilter, IReward, SubgraphOptions } from '
|
|
2
|
-
import { ChainId } from '
|
|
1
|
+
import { IOperator, IOperatorsFilter, IReward, SubgraphOptions } from '../interfaces';
|
|
2
|
+
import { ChainId } from '../enums';
|
|
3
3
|
/**
|
|
4
4
|
* Utility helpers for operator-related queries.
|
|
5
5
|
*
|
|
@@ -102,4 +102,4 @@ export declare class OperatorUtils {
|
|
|
102
102
|
*/
|
|
103
103
|
static getRewards(chainId: ChainId, slasherAddress: string, options?: SubgraphOptions): Promise<IReward[]>;
|
|
104
104
|
}
|
|
105
|
-
//# sourceMappingURL=
|
|
105
|
+
//# sourceMappingURL=operator_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator_utils.d.ts","sourceRoot":"","sources":["../../src/operator/operator_utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,eAAe,EAChB,MAAM,eAAe,CAAC;AAmBvB,OAAO,EAAE,OAAO,EAAkB,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,WAAW,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAwB5B;;;;;;;;;;;;;;;;;;OAkBG;WACiB,YAAY,CAC9B,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC;IA+CvB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC;IAyBvB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CA8BtB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OperatorUtils = void 0;
|
|
4
|
-
const reward_1 = require("
|
|
5
|
-
const operator_1 = require("
|
|
4
|
+
const reward_1 = require("../graphql/queries/reward");
|
|
5
|
+
const operator_1 = require("../graphql/queries/operator");
|
|
6
6
|
const ethers_1 = require("ethers");
|
|
7
|
-
const error_1 = require("
|
|
8
|
-
const utils_1 = require("
|
|
9
|
-
const enums_1 = require("
|
|
10
|
-
const constants_1 = require("
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const enums_1 = require("../enums");
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
11
|
/**
|
|
12
12
|
* Utility helpers for operator-related queries.
|
|
13
13
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/staking/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StakingUtils = exports.StakingClient = void 0;
|
|
4
|
+
var staking_client_1 = require("./staking_client");
|
|
5
|
+
Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_client_1.StakingClient; } });
|
|
6
|
+
var staking_utils_1 = require("./staking_utils");
|
|
7
|
+
Object.defineProperty(exports, "StakingUtils", { enumerable: true, get: function () { return staking_utils_1.StakingUtils; } });
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { EscrowFactory, HMToken, Staking } from '@human-protocol/core/typechain-types';
|
|
2
2
|
import { ContractRunner } from 'ethers';
|
|
3
|
-
import { BaseEthersClient } from '
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { NetworkData, TransactionOverrides } from './types';
|
|
3
|
+
import { BaseEthersClient } from '../base';
|
|
4
|
+
import { StakerInfo } from '../interfaces';
|
|
5
|
+
import { NetworkData, TransactionOverrides } from '../types';
|
|
7
6
|
/**
|
|
8
7
|
* Client for staking actions on HUMAN Protocol.
|
|
9
8
|
*
|
|
@@ -218,64 +217,4 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
218
217
|
*/
|
|
219
218
|
getStakerInfo(stakerAddress: string): Promise<StakerInfo>;
|
|
220
219
|
}
|
|
221
|
-
|
|
222
|
-
* Utility helpers for Staking-related queries.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```ts
|
|
226
|
-
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
227
|
-
*
|
|
228
|
-
* const staker = await StakingUtils.getStaker(
|
|
229
|
-
* ChainId.POLYGON_AMOY,
|
|
230
|
-
* '0xYourStakerAddress'
|
|
231
|
-
* );
|
|
232
|
-
* console.log('Staked amount:', staker.stakedAmount);
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
export declare class StakingUtils {
|
|
236
|
-
/**
|
|
237
|
-
* Gets staking info for a staker from the subgraph.
|
|
238
|
-
*
|
|
239
|
-
* @param chainId - Network in which the staking contract is deployed
|
|
240
|
-
* @param stakerAddress - Address of the staker
|
|
241
|
-
* @param options - Optional configuration for subgraph requests.
|
|
242
|
-
* @returns Staker info from subgraph
|
|
243
|
-
* @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
|
|
244
|
-
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
245
|
-
* @throws ErrorStakerNotFound If the staker is not found
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```ts
|
|
249
|
-
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
250
|
-
*
|
|
251
|
-
* const staker = await StakingUtils.getStaker(
|
|
252
|
-
* ChainId.POLYGON_AMOY,
|
|
253
|
-
* '0xYourStakerAddress'
|
|
254
|
-
* );
|
|
255
|
-
* console.log('Staked amount:', staker.stakedAmount);
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
static getStaker(chainId: ChainId, stakerAddress: string, options?: SubgraphOptions): Promise<IStaker>;
|
|
259
|
-
/**
|
|
260
|
-
* Gets all stakers from the subgraph with filters, pagination and ordering.
|
|
261
|
-
*
|
|
262
|
-
* @param filter - Stakers filter with pagination and ordering
|
|
263
|
-
* @param options - Optional configuration for subgraph requests.
|
|
264
|
-
* @returns Array of stakers
|
|
265
|
-
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```ts
|
|
269
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
270
|
-
*
|
|
271
|
-
* const filter = {
|
|
272
|
-
* chainId: ChainId.POLYGON_AMOY,
|
|
273
|
-
* minStakedAmount: '1000000000000000000', // 1 token in WEI
|
|
274
|
-
* };
|
|
275
|
-
* const stakers = await StakingUtils.getStakers(filter);
|
|
276
|
-
* console.log('Stakers:', stakers.length);
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
static getStakers(filter: IStakersFilter, options?: SubgraphOptions): Promise<IStaker[]>;
|
|
280
|
-
}
|
|
281
|
-
//# sourceMappingURL=staking.d.ts.map
|
|
220
|
+
//# sourceMappingURL=staking_client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking_client.d.ts","sourceRoot":"","sources":["../../src/staking/staking_client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAc3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IAC1C,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAmB5D;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBzE;;;;OAIG;YACW,gBAAgB;IAU9B;;;;;;;;;;;;;;;;OAgBG;IAEU,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,oBAAyB,GACnC,OAAO,CAAC,IAAI,CAAC;IAyBhB;;;;;;;;;;;;;;;;;;;;OAoBG;IAEU,KAAK,CAChB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,oBAAyB,GACnC,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;;;;;;;;;;;;;;;OAmBG;IAEU,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,oBAAyB,GACnC,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;;;;;;;;OAYG;IAEU,QAAQ,CAAC,SAAS,GAAE,oBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,oBAAyB,GACnC,OAAO,CAAC,IAAI,CAAC;IAsChB;;;;;;;;;;;;OAYG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAiCvE"}
|
|
@@ -9,16 +9,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.StakingClient = void 0;
|
|
13
13
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
|
-
const base_1 = require("
|
|
16
|
-
const constants_1 = require("
|
|
17
|
-
const decorators_1 = require("
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
const staking_1 = require("./graphql/queries/staking");
|
|
15
|
+
const base_1 = require("../base");
|
|
16
|
+
const constants_1 = require("../constants");
|
|
17
|
+
const decorators_1 = require("../decorators");
|
|
18
|
+
const error_1 = require("../error");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
22
20
|
/**
|
|
23
21
|
* Client for staking actions on HUMAN Protocol.
|
|
24
22
|
*
|
|
@@ -380,131 +378,3 @@ __decorate([
|
|
|
380
378
|
__metadata("design:paramtypes", [String, String, String, BigInt, Object]),
|
|
381
379
|
__metadata("design:returntype", Promise)
|
|
382
380
|
], StakingClient.prototype, "slash", null);
|
|
383
|
-
/**
|
|
384
|
-
* Utility helpers for Staking-related queries.
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```ts
|
|
388
|
-
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
389
|
-
*
|
|
390
|
-
* const staker = await StakingUtils.getStaker(
|
|
391
|
-
* ChainId.POLYGON_AMOY,
|
|
392
|
-
* '0xYourStakerAddress'
|
|
393
|
-
* );
|
|
394
|
-
* console.log('Staked amount:', staker.stakedAmount);
|
|
395
|
-
* ```
|
|
396
|
-
*/
|
|
397
|
-
class StakingUtils {
|
|
398
|
-
/**
|
|
399
|
-
* Gets staking info for a staker from the subgraph.
|
|
400
|
-
*
|
|
401
|
-
* @param chainId - Network in which the staking contract is deployed
|
|
402
|
-
* @param stakerAddress - Address of the staker
|
|
403
|
-
* @param options - Optional configuration for subgraph requests.
|
|
404
|
-
* @returns Staker info from subgraph
|
|
405
|
-
* @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
|
|
406
|
-
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
407
|
-
* @throws ErrorStakerNotFound If the staker is not found
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* ```ts
|
|
411
|
-
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
412
|
-
*
|
|
413
|
-
* const staker = await StakingUtils.getStaker(
|
|
414
|
-
* ChainId.POLYGON_AMOY,
|
|
415
|
-
* '0xYourStakerAddress'
|
|
416
|
-
* );
|
|
417
|
-
* console.log('Staked amount:', staker.stakedAmount);
|
|
418
|
-
* ```
|
|
419
|
-
*/
|
|
420
|
-
static async getStaker(chainId, stakerAddress, options) {
|
|
421
|
-
if (!ethers_1.ethers.isAddress(stakerAddress)) {
|
|
422
|
-
throw error_1.ErrorInvalidStakerAddressProvided;
|
|
423
|
-
}
|
|
424
|
-
const networkData = constants_1.NETWORKS[chainId];
|
|
425
|
-
if (!networkData) {
|
|
426
|
-
throw error_1.ErrorUnsupportedChainID;
|
|
427
|
-
}
|
|
428
|
-
const { staker } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), staking_1.GET_STAKER_BY_ADDRESS_QUERY, { id: stakerAddress.toLowerCase() }, options);
|
|
429
|
-
if (!staker) {
|
|
430
|
-
throw error_1.ErrorStakerNotFound;
|
|
431
|
-
}
|
|
432
|
-
return mapStaker(staker);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Gets all stakers from the subgraph with filters, pagination and ordering.
|
|
436
|
-
*
|
|
437
|
-
* @param filter - Stakers filter with pagination and ordering
|
|
438
|
-
* @param options - Optional configuration for subgraph requests.
|
|
439
|
-
* @returns Array of stakers
|
|
440
|
-
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
441
|
-
*
|
|
442
|
-
* @example
|
|
443
|
-
* ```ts
|
|
444
|
-
* import { ChainId } from '@human-protocol/sdk';
|
|
445
|
-
*
|
|
446
|
-
* const filter = {
|
|
447
|
-
* chainId: ChainId.POLYGON_AMOY,
|
|
448
|
-
* minStakedAmount: '1000000000000000000', // 1 token in WEI
|
|
449
|
-
* };
|
|
450
|
-
* const stakers = await StakingUtils.getStakers(filter);
|
|
451
|
-
* console.log('Stakers:', stakers.length);
|
|
452
|
-
* ```
|
|
453
|
-
*/
|
|
454
|
-
static async getStakers(filter, options) {
|
|
455
|
-
const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
456
|
-
const skip = filter.skip || 0;
|
|
457
|
-
const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
|
|
458
|
-
const orderBy = filter.orderBy || 'lastDepositTimestamp';
|
|
459
|
-
const networkData = constants_1.NETWORKS[filter.chainId];
|
|
460
|
-
if (!networkData) {
|
|
461
|
-
throw error_1.ErrorUnsupportedChainID;
|
|
462
|
-
}
|
|
463
|
-
const { stakers } = await (0, utils_1.customGqlFetch)((0, utils_1.getSubgraphUrl)(networkData), (0, staking_1.GET_STAKERS_QUERY)(filter), {
|
|
464
|
-
minStakedAmount: filter.minStakedAmount
|
|
465
|
-
? filter.minStakedAmount
|
|
466
|
-
: undefined,
|
|
467
|
-
maxStakedAmount: filter.maxStakedAmount
|
|
468
|
-
? filter.maxStakedAmount
|
|
469
|
-
: undefined,
|
|
470
|
-
minLockedAmount: filter.minLockedAmount
|
|
471
|
-
? filter.minLockedAmount
|
|
472
|
-
: undefined,
|
|
473
|
-
maxLockedAmount: filter.maxLockedAmount
|
|
474
|
-
? filter.maxLockedAmount
|
|
475
|
-
: undefined,
|
|
476
|
-
minWithdrawnAmount: filter.minWithdrawnAmount
|
|
477
|
-
? filter.minWithdrawnAmount
|
|
478
|
-
: undefined,
|
|
479
|
-
maxWithdrawnAmount: filter.maxWithdrawnAmount
|
|
480
|
-
? filter.maxWithdrawnAmount
|
|
481
|
-
: undefined,
|
|
482
|
-
minSlashedAmount: filter.minSlashedAmount
|
|
483
|
-
? filter.minSlashedAmount
|
|
484
|
-
: undefined,
|
|
485
|
-
maxSlashedAmount: filter.maxSlashedAmount
|
|
486
|
-
? filter.maxSlashedAmount
|
|
487
|
-
: undefined,
|
|
488
|
-
orderBy: orderBy,
|
|
489
|
-
orderDirection: orderDirection,
|
|
490
|
-
first: first,
|
|
491
|
-
skip: skip,
|
|
492
|
-
}, options);
|
|
493
|
-
if (!stakers) {
|
|
494
|
-
return [];
|
|
495
|
-
}
|
|
496
|
-
return stakers.map((s) => mapStaker(s));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
exports.StakingUtils = StakingUtils;
|
|
500
|
-
function mapStaker(s) {
|
|
501
|
-
return {
|
|
502
|
-
address: s.address,
|
|
503
|
-
stakedAmount: BigInt(s.stakedAmount),
|
|
504
|
-
lockedAmount: BigInt(s.lockedAmount),
|
|
505
|
-
withdrawableAmount: BigInt(s.withdrawnAmount),
|
|
506
|
-
slashedAmount: BigInt(s.slashedAmount),
|
|
507
|
-
lockedUntil: Number(s.lockedUntilTimestamp) * 1000,
|
|
508
|
-
lastDepositTimestamp: Number(s.lastDepositTimestamp) * 1000,
|
|
509
|
-
};
|
|
510
|
-
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ChainId } from '../enums';
|
|
2
|
+
import { IStaker, IStakersFilter, SubgraphOptions } from '../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Utility helpers for Staking-related queries.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const staker = await StakingUtils.getStaker(
|
|
11
|
+
* ChainId.POLYGON_AMOY,
|
|
12
|
+
* '0xYourStakerAddress'
|
|
13
|
+
* );
|
|
14
|
+
* console.log('Staked amount:', staker.stakedAmount);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class StakingUtils {
|
|
18
|
+
/**
|
|
19
|
+
* Gets staking info for a staker from the subgraph.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - Network in which the staking contract is deployed
|
|
22
|
+
* @param stakerAddress - Address of the staker
|
|
23
|
+
* @param options - Optional configuration for subgraph requests.
|
|
24
|
+
* @returns Staker info from subgraph
|
|
25
|
+
* @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
|
|
26
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
27
|
+
* @throws ErrorStakerNotFound If the staker is not found
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { StakingUtils, ChainId } from '@human-protocol/sdk';
|
|
32
|
+
*
|
|
33
|
+
* const staker = await StakingUtils.getStaker(
|
|
34
|
+
* ChainId.POLYGON_AMOY,
|
|
35
|
+
* '0xYourStakerAddress'
|
|
36
|
+
* );
|
|
37
|
+
* console.log('Staked amount:', staker.stakedAmount);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
static getStaker(chainId: ChainId, stakerAddress: string, options?: SubgraphOptions): Promise<IStaker>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets all stakers from the subgraph with filters, pagination and ordering.
|
|
43
|
+
*
|
|
44
|
+
* @param filter - Stakers filter with pagination and ordering
|
|
45
|
+
* @param options - Optional configuration for subgraph requests.
|
|
46
|
+
* @returns Array of stakers
|
|
47
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
52
|
+
*
|
|
53
|
+
* const filter = {
|
|
54
|
+
* chainId: ChainId.POLYGON_AMOY,
|
|
55
|
+
* minStakedAmount: '1000000000000000000', // 1 token in WEI
|
|
56
|
+
* };
|
|
57
|
+
* const stakers = await StakingUtils.getStakers(filter);
|
|
58
|
+
* console.log('Stakers:', stakers.length);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static getStakers(filter: IStakersFilter, options?: SubgraphOptions): Promise<IStaker[]>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=staking_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking_utils.d.ts","sourceRoot":"","sources":["../../src/staking/staking_utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,UAAU,CAAC;AAWnD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGzE;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;;;;;;;;;;;;;OAqBG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IAwBnB;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,UAAU,CAC5B,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CAqDtB"}
|