@human-protocol/sdk 5.2.0 → 6.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 +4 -5
- package/dist/constants.js +6 -6
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +66 -202
- package/dist/error.d.ts +0 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -26
- package/dist/escrow.d.ts +427 -780
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +314 -684
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/kvstore.d.ts +119 -181
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +119 -182
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +135 -134
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +135 -134
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +36 -15
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -15
- package/dist/types.d.ts +0 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -17
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -17
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +7 -24
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +425 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +135 -134
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -15
- package/src/types.ts +0 -57
- package/src/utils.ts +31 -17
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- package/src/storage.ts +0 -313
package/dist/operator.js
CHANGED
|
@@ -8,21 +8,40 @@ const error_1 = require("./error");
|
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const enums_1 = require("./enums");
|
|
10
10
|
const constants_1 = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* Utility helpers for operator-related queries.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
17
|
+
*
|
|
18
|
+
* const operator = await OperatorUtils.getOperator(
|
|
19
|
+
* ChainId.POLYGON_AMOY,
|
|
20
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
21
|
+
* );
|
|
22
|
+
* console.log('Operator:', operator);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
11
25
|
class OperatorUtils {
|
|
12
26
|
/**
|
|
13
27
|
* This function returns the operator data for the given address.
|
|
14
28
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @returns
|
|
19
|
-
*
|
|
20
|
-
*
|
|
29
|
+
* @param chainId - Network in which the operator is deployed
|
|
30
|
+
* @param address - Operator address.
|
|
31
|
+
* @param options - Optional configuration for subgraph requests.
|
|
32
|
+
* @returns Returns the operator details or null if not found.
|
|
33
|
+
* @throws ErrorInvalidStakerAddressProvided If the address is invalid
|
|
34
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
21
35
|
*
|
|
36
|
+
* @example
|
|
22
37
|
* ```ts
|
|
23
38
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
24
39
|
*
|
|
25
|
-
* const operator = await OperatorUtils.getOperator(
|
|
40
|
+
* const operator = await OperatorUtils.getOperator(
|
|
41
|
+
* ChainId.POLYGON_AMOY,
|
|
42
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
43
|
+
* );
|
|
44
|
+
* console.log('Operator:', operator);
|
|
26
45
|
* ```
|
|
27
46
|
*/
|
|
28
47
|
static async getOperator(chainId, address, options) {
|
|
@@ -45,19 +64,20 @@ class OperatorUtils {
|
|
|
45
64
|
/**
|
|
46
65
|
* This function returns all the operator details of the protocol.
|
|
47
66
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
50
|
-
* @returns
|
|
51
|
-
*
|
|
52
|
-
* **Code example**
|
|
67
|
+
* @param filter - Filter for the operators.
|
|
68
|
+
* @param options - Optional configuration for subgraph requests.
|
|
69
|
+
* @returns Returns an array with all the operator details.
|
|
70
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
53
71
|
*
|
|
72
|
+
* @example
|
|
54
73
|
* ```ts
|
|
55
|
-
* import {
|
|
74
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
56
75
|
*
|
|
57
|
-
* const filter
|
|
58
|
-
*
|
|
76
|
+
* const filter = {
|
|
77
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
59
78
|
* };
|
|
60
79
|
* const operators = await OperatorUtils.getOperators(filter);
|
|
80
|
+
* console.log('Operators:', operators.length);
|
|
61
81
|
* ```
|
|
62
82
|
*/
|
|
63
83
|
static async getOperators(filter, options) {
|
|
@@ -95,18 +115,22 @@ class OperatorUtils {
|
|
|
95
115
|
/**
|
|
96
116
|
* Retrieves the reputation network operators of the specified address.
|
|
97
117
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
102
|
-
* @returns
|
|
103
|
-
*
|
|
104
|
-
* **Code example**
|
|
118
|
+
* @param chainId - Network in which the reputation network is deployed
|
|
119
|
+
* @param address - Address of the reputation oracle.
|
|
120
|
+
* @param role - Role of the operator (optional).
|
|
121
|
+
* @param options - Optional configuration for subgraph requests.
|
|
122
|
+
* @returns Returns an array of operator details.
|
|
123
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
105
124
|
*
|
|
125
|
+
* @example
|
|
106
126
|
* ```ts
|
|
107
127
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
108
128
|
*
|
|
109
|
-
* const operators = await OperatorUtils.getReputationNetworkOperators(
|
|
129
|
+
* const operators = await OperatorUtils.getReputationNetworkOperators(
|
|
130
|
+
* ChainId.POLYGON_AMOY,
|
|
131
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
132
|
+
* );
|
|
133
|
+
* console.log('Operators:', operators.length);
|
|
110
134
|
* ```
|
|
111
135
|
*/
|
|
112
136
|
static async getReputationNetworkOperators(chainId, address, role, options) {
|
|
@@ -125,17 +149,22 @@ class OperatorUtils {
|
|
|
125
149
|
/**
|
|
126
150
|
* This function returns information about the rewards for a given slasher address.
|
|
127
151
|
*
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @param
|
|
131
|
-
* @returns
|
|
132
|
-
*
|
|
133
|
-
*
|
|
152
|
+
* @param chainId - Network in which the rewards are deployed
|
|
153
|
+
* @param slasherAddress - Slasher address.
|
|
154
|
+
* @param options - Optional configuration for subgraph requests.
|
|
155
|
+
* @returns Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
156
|
+
* @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
|
|
157
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
134
158
|
*
|
|
159
|
+
* @example
|
|
135
160
|
* ```ts
|
|
136
161
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
137
162
|
*
|
|
138
|
-
* const rewards = await OperatorUtils.getRewards(
|
|
163
|
+
* const rewards = await OperatorUtils.getRewards(
|
|
164
|
+
* ChainId.POLYGON_AMOY,
|
|
165
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
166
|
+
* );
|
|
167
|
+
* console.log('Rewards:', rewards.length);
|
|
139
168
|
* ```
|
|
140
169
|
*/
|
|
141
170
|
static async getRewards(chainId, slasherAddress, options) {
|
package/dist/staking.d.ts
CHANGED
|
@@ -5,9 +5,7 @@ import { ChainId } from './enums';
|
|
|
5
5
|
import { IStaker, IStakersFilter, StakerInfo, SubgraphOptions } from './interfaces';
|
|
6
6
|
import { NetworkData } from './types';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This client enables performing actions on staking contracts and obtaining staking information from both the contracts and subgraph.
|
|
8
|
+
* Client for staking actions on HUMAN Protocol.
|
|
11
9
|
*
|
|
12
10
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
13
11
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
@@ -21,37 +19,25 @@ import { NetworkData } from './types';
|
|
|
21
19
|
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
22
20
|
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
23
21
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* ### npm
|
|
27
|
-
* ```bash
|
|
28
|
-
* npm install @human-protocol/sdk
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ### yarn
|
|
32
|
-
* ```bash
|
|
33
|
-
* yarn install @human-protocol/sdk
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* ## Code example
|
|
22
|
+
* @example
|
|
37
23
|
*
|
|
38
|
-
* ### Signer
|
|
24
|
+
* ###Using Signer
|
|
39
25
|
*
|
|
40
|
-
*
|
|
26
|
+
* ####Using private key (backend)
|
|
41
27
|
*
|
|
42
28
|
* ```ts
|
|
43
29
|
* import { StakingClient } from '@human-protocol/sdk';
|
|
44
|
-
* import { Wallet,
|
|
30
|
+
* import { Wallet, JsonRpcProvider } from 'ethers';
|
|
45
31
|
*
|
|
46
32
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
47
33
|
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
48
34
|
*
|
|
49
|
-
* const provider = new
|
|
35
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
50
36
|
* const signer = new Wallet(privateKey, provider);
|
|
51
37
|
* const stakingClient = await StakingClient.build(signer);
|
|
52
38
|
* ```
|
|
53
39
|
*
|
|
54
|
-
*
|
|
40
|
+
* ####Using Wagmi (frontend)
|
|
55
41
|
*
|
|
56
42
|
* ```ts
|
|
57
43
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -61,15 +47,15 @@ import { NetworkData } from './types';
|
|
|
61
47
|
* const stakingClient = await StakingClient.build(signer);
|
|
62
48
|
* ```
|
|
63
49
|
*
|
|
64
|
-
* ### Provider
|
|
50
|
+
* ###Using Provider
|
|
65
51
|
*
|
|
66
52
|
* ```ts
|
|
67
53
|
* import { StakingClient } from '@human-protocol/sdk';
|
|
68
|
-
* import {
|
|
54
|
+
* import { JsonRpcProvider } from 'ethers';
|
|
69
55
|
*
|
|
70
56
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
71
57
|
*
|
|
72
|
-
* const provider = new
|
|
58
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
73
59
|
* const stakingClient = await StakingClient.build(provider);
|
|
74
60
|
* ```
|
|
75
61
|
*/
|
|
@@ -80,18 +66,30 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
80
66
|
/**
|
|
81
67
|
* **StakingClient constructor**
|
|
82
68
|
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
69
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
70
|
+
* @param networkData - The network information required to connect to the Staking contract
|
|
85
71
|
*/
|
|
86
72
|
constructor(runner: ContractRunner, networkData: NetworkData);
|
|
87
73
|
/**
|
|
88
74
|
* Creates an instance of StakingClient from a Runner.
|
|
89
75
|
*
|
|
90
|
-
* @param
|
|
76
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
77
|
+
* @returns An instance of StakingClient
|
|
78
|
+
* @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
|
|
79
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
91
80
|
*
|
|
92
|
-
* @
|
|
93
|
-
*
|
|
94
|
-
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { StakingClient } from '@human-protocol/sdk';
|
|
84
|
+
* import { Wallet, JsonRpcProvider } from 'ethers';
|
|
85
|
+
*
|
|
86
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
87
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
88
|
+
*
|
|
89
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
90
|
+
* const signer = new Wallet(privateKey, provider);
|
|
91
|
+
* const stakingClient = await StakingClient.build(signer);
|
|
92
|
+
* ```
|
|
95
93
|
*/
|
|
96
94
|
static build(runner: ContractRunner): Promise<StakingClient>;
|
|
97
95
|
/**
|
|
@@ -103,24 +101,17 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
103
101
|
/**
|
|
104
102
|
* This function approves the staking contract to transfer a specified amount of tokens when the user stakes. It increases the allowance for the staking contract.
|
|
105
103
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @param
|
|
108
|
-
* @returns
|
|
109
|
-
*
|
|
110
|
-
*
|
|
104
|
+
* @param amount - Amount in WEI of tokens to approve for stake.
|
|
105
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
106
|
+
* @returns -
|
|
107
|
+
* @throws ErrorInvalidStakingValueType If the amount is not a bigint
|
|
108
|
+
* @throws ErrorInvalidStakingValueSign If the amount is negative
|
|
111
109
|
*
|
|
110
|
+
* @example
|
|
112
111
|
* ```ts
|
|
113
|
-
* import { ethers
|
|
114
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
115
|
-
*
|
|
116
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
117
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
112
|
+
* import { ethers } from 'ethers';
|
|
118
113
|
*
|
|
119
|
-
* const
|
|
120
|
-
* const signer = new Wallet(privateKey, provider);
|
|
121
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
122
|
-
*
|
|
123
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
114
|
+
* const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
|
|
124
115
|
* await stakingClient.approveStake(amount);
|
|
125
116
|
* ```
|
|
126
117
|
*/
|
|
@@ -128,26 +119,20 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
128
119
|
/**
|
|
129
120
|
* This function stakes a specified amount of tokens on a specific network.
|
|
130
121
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param {bigint} amount Amount in WEI of tokens to stake.
|
|
134
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
135
|
-
* @returns Returns void if successful. Throws error if any.
|
|
122
|
+
* !!! note
|
|
123
|
+
* `approveStake` must be called before
|
|
136
124
|
*
|
|
137
|
-
*
|
|
125
|
+
* @param amount - Amount in WEI of tokens to stake.
|
|
126
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
127
|
+
* @returns -
|
|
128
|
+
* @throws ErrorInvalidStakingValueType If the amount is not a bigint
|
|
129
|
+
* @throws ErrorInvalidStakingValueSign If the amount is negative
|
|
138
130
|
*
|
|
131
|
+
* @example
|
|
139
132
|
* ```ts
|
|
140
|
-
* import { ethers
|
|
141
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
133
|
+
* import { ethers } from 'ethers';
|
|
142
134
|
*
|
|
143
|
-
* const
|
|
144
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
145
|
-
*
|
|
146
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
147
|
-
* const signer = new Wallet(privateKey, provider);
|
|
148
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
149
|
-
*
|
|
150
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
135
|
+
* const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
|
|
151
136
|
* await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
|
|
152
137
|
* await stakingClient.stake(amount);
|
|
153
138
|
* ```
|
|
@@ -156,51 +141,34 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
156
141
|
/**
|
|
157
142
|
* This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time.
|
|
158
143
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @param {bigint} amount Amount in WEI of tokens to unstake.
|
|
162
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
163
|
-
* @returns Returns void if successful. Throws error if any.
|
|
144
|
+
* !!! note
|
|
145
|
+
* Must have tokens available to unstake
|
|
164
146
|
*
|
|
165
|
-
*
|
|
147
|
+
* @param amount - Amount in WEI of tokens to unstake.
|
|
148
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
149
|
+
* @returns -
|
|
150
|
+
* @throws ErrorInvalidStakingValueType If the amount is not a bigint
|
|
151
|
+
* @throws ErrorInvalidStakingValueSign If the amount is negative
|
|
166
152
|
*
|
|
153
|
+
* @example
|
|
167
154
|
* ```ts
|
|
168
|
-
* import { ethers
|
|
169
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
170
|
-
*
|
|
171
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
172
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
173
|
-
*
|
|
174
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
175
|
-
* const signer = new Wallet(privateKey, provider);
|
|
176
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
155
|
+
* import { ethers } from 'ethers';
|
|
177
156
|
*
|
|
178
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
157
|
+
* const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
|
|
179
158
|
* await stakingClient.unstake(amount);
|
|
180
159
|
* ```
|
|
181
160
|
*/
|
|
182
161
|
unstake(amount: bigint, txOptions?: Overrides): Promise<void>;
|
|
183
162
|
/**
|
|
184
163
|
* This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
|
|
164
|
+
* !!! note
|
|
165
|
+
* Must have tokens available to withdraw
|
|
185
166
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
189
|
-
* @returns Returns void if successful. Throws error if any.
|
|
190
|
-
*
|
|
191
|
-
* **Code example**
|
|
167
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
168
|
+
* @returns -
|
|
192
169
|
*
|
|
170
|
+
* @example
|
|
193
171
|
* ```ts
|
|
194
|
-
* import { Wallet, providers } from 'ethers';
|
|
195
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
196
|
-
*
|
|
197
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
198
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
199
|
-
*
|
|
200
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
201
|
-
* const signer = new Wallet(privateKey, provider);
|
|
202
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
203
|
-
*
|
|
204
172
|
* await stakingClient.withdraw();
|
|
205
173
|
* ```
|
|
206
174
|
*/
|
|
@@ -208,72 +176,105 @@ export declare class StakingClient extends BaseEthersClient {
|
|
|
208
176
|
/**
|
|
209
177
|
* This function reduces the allocated amount by a staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
|
|
210
178
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
213
|
-
* @param
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
216
|
-
* @returns
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
179
|
+
* @param slasher - Wallet address from who requested the slash
|
|
180
|
+
* @param staker - Wallet address from who is going to be slashed
|
|
181
|
+
* @param escrowAddress - Address of the escrow that the slash is made
|
|
182
|
+
* @param amount - Amount in WEI of tokens to slash.
|
|
183
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
184
|
+
* @returns -
|
|
185
|
+
* @throws ErrorInvalidStakingValueType If the amount is not a bigint
|
|
186
|
+
* @throws ErrorInvalidStakingValueSign If the amount is negative
|
|
187
|
+
* @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
|
|
188
|
+
* @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
|
|
189
|
+
* @throws ErrorInvalidEscrowAddressProvided If the escrow address is invalid
|
|
190
|
+
* @throws ErrorEscrowAddressIsNotProvidedByFactory If the escrow is not provided by the factory
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
220
193
|
* ```ts
|
|
221
|
-
* import { ethers
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
232
|
-
* await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
|
|
194
|
+
* import { ethers } from 'ethers';
|
|
195
|
+
*
|
|
196
|
+
* const amount = ethers.parseUnits('5', 'ether'); //convert from ETH to WEI
|
|
197
|
+
* await stakingClient.slash(
|
|
198
|
+
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
199
|
+
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
200
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f',
|
|
201
|
+
* amount
|
|
202
|
+
* );
|
|
233
203
|
* ```
|
|
234
204
|
*/
|
|
235
205
|
slash(slasher: string, staker: string, escrowAddress: string, amount: bigint, txOptions?: Overrides): Promise<void>;
|
|
236
206
|
/**
|
|
237
207
|
* Retrieves comprehensive staking information for a staker.
|
|
238
208
|
*
|
|
239
|
-
* @param
|
|
240
|
-
* @returns
|
|
241
|
-
*
|
|
242
|
-
* **Code example**
|
|
209
|
+
* @param stakerAddress - The address of the staker.
|
|
210
|
+
* @returns Staking information for the staker
|
|
211
|
+
* @throws ErrorInvalidStakerAddressProvided If the staker address is invalid
|
|
243
212
|
*
|
|
213
|
+
* @example
|
|
244
214
|
* ```ts
|
|
245
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
246
|
-
*
|
|
247
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
248
|
-
*
|
|
249
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
250
|
-
* const stakingClient = await StakingClient.build(provider);
|
|
251
|
-
*
|
|
252
215
|
* const stakingInfo = await stakingClient.getStakerInfo('0xYourStakerAddress');
|
|
253
|
-
* console.log(stakingInfo.
|
|
216
|
+
* console.log('Tokens staked:', stakingInfo.stakedAmount);
|
|
254
217
|
* ```
|
|
255
218
|
*/
|
|
256
219
|
getStakerInfo(stakerAddress: string): Promise<StakerInfo>;
|
|
257
220
|
}
|
|
258
221
|
/**
|
|
259
|
-
* Utility
|
|
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
|
+
* ```
|
|
260
234
|
*/
|
|
261
235
|
export declare class StakingUtils {
|
|
262
236
|
/**
|
|
263
237
|
* Gets staking info for a staker from the subgraph.
|
|
264
238
|
*
|
|
265
|
-
* @param
|
|
266
|
-
* @param
|
|
267
|
-
* @param
|
|
268
|
-
* @returns
|
|
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
|
+
* ```
|
|
269
257
|
*/
|
|
270
258
|
static getStaker(chainId: ChainId, stakerAddress: string, options?: SubgraphOptions): Promise<IStaker>;
|
|
271
259
|
/**
|
|
272
260
|
* Gets all stakers from the subgraph with filters, pagination and ordering.
|
|
273
261
|
*
|
|
274
|
-
* @param
|
|
275
|
-
* @param
|
|
276
|
-
* @returns
|
|
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
|
+
* ```
|
|
277
278
|
*/
|
|
278
279
|
static getStakers(filter: IStakersFilter, options?: SubgraphOptions): Promise<IStaker[]>;
|
|
279
280
|
}
|
package/dist/staking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAYlD,OAAO,EACL,OAAO,EACP,cAAc,EACd,UAAU,EACV,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAYlD,OAAO,EACL,OAAO,EACP,cAAc,EACd,UAAU,EACV,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;;;OAoBG;IAEU,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB5E;;;;;;;;;;;;;;;;;;;OAmBG;IAEU,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAiBhB;;;;;;;;;;;;OAYG;IAEU,QAAQ,CAAC,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAoChB;;;;;;;;;;;;OAYG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAiCvE;AAED;;;;;;;;;;;;;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"}
|