StakingClient
@human-protocol/sdk / Modules / staking / StakingClient
Class: StakingClient
staking.StakingClient
Introduction
This client enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph.
Internally, the SDK will use one network or another according to the network ID of the runner
. To use this client, it is recommended to initialize it using the static build
method.
A Signer
or a Provider
should be passed depending on the use case of this module:
Signer: when the user wants to use this model in order to send transactions caling the contract functions.
Provider: when the user wants to use this model in order to get information from the contracts or subgraph.
Installation
npm
yarn
Code example
Signer
Using private key(backend)
Using Wagmi(frontend)
Provider
Hierarchy
↳
StakingClient
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new StakingClient(runner
, networkData
): StakingClient
StakingClient constructor
Parameters
Name | Type | Description |
---|---|---|
|
| The Runner object to interact with the Ethereum network |
|
| - |
Returns
Overrides
Defined in
Properties
escrowFactoryContract
• escrowFactoryContract: EscrowFactory
Defined in
networkData
• networkData: NetworkData
Inherited from
Defined in
rewardPoolContract
• rewardPoolContract: RewardPool
Defined in
runner
• Protected
runner: ContractRunner
Inherited from
Defined in
stakingContract
• stakingContract: Staking
Defined in
tokenContract
• tokenContract: HMToken
Defined in
Methods
allocate
▸ allocate(escrowAddress
, amount
, txOptions?
): Promise
<void
>
This function allocates a portion of the staked tokens to a specific escrow.
Must have tokens staked
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the escrow contract to allocate in. |
|
| Amount in WEI of tokens to allocate. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
approveStake
▸ approveStake(amount
, txOptions?
): Promise
<void
>
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.
Parameters
Name | Type | Description |
---|---|---|
|
| Amount in WEI of tokens to approve for stake. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
checkValidEscrow
▸ checkValidEscrow(escrowAddress
): Promise
<void
>
Check if escrow exists
Parameters
Name | Type | Description |
---|---|---|
|
| Escrow address to check against |
Returns
Promise
<void
>
Defined in
closeAllocation
▸ closeAllocation(escrowAddress
, txOptions?
): Promise
<void
>
This function drops the allocation from a specific escrow.
The escrow must have allocation The escrow must be cancelled or completed.
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the escrow contract to close allocation from. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
distributeReward
▸ distributeReward(escrowAddress
, txOptions?
): Promise
<void
>
This function drops the allocation from a specific escrow.
The escrow must have rewards added
Parameters
Name | Type | Description |
---|---|---|
|
| Escrow address from which rewards are distributed. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
getAllocation
▸ getAllocation(escrowAddress
): Promise
<IAllocation
>
This function returns information about the allocation of the specified escrow.
Parameters
Name | Type | Description |
---|---|---|
|
| Escrow address from which we want to get allocation information. |
Returns
Promise
<IAllocation
>
Returns allocation info if exists.
Code example
Defined in
slash
▸ slash(slasher
, staker
, escrowAddress
, amount
, txOptions?
): Promise
<void
>
This function reduces the allocated amount by an staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
Parameters
Name | Type | Description |
---|---|---|
|
| Wallet address from who requested the slash |
|
| Wallet address from who is going to be slashed |
|
| Address of the escrow which allocation will be slashed |
|
| Amount in WEI of tokens to unstake. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
stake
▸ stake(amount
, txOptions?
): Promise
<void
>
This function stakes a specified amount of tokens on a specific network.
approveStake
must be called before
Parameters
Name | Type | Description |
---|---|---|
|
| Amount in WEI of tokens to stake. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
unstake
▸ unstake(amount
, txOptions?
): Promise
<void
>
This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time.
Must have tokens available to unstake
Parameters
Name | Type | Description |
---|---|---|
|
| Amount in WEI of tokens to unstake. |
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
withdraw
▸ withdraw(txOptions?
): Promise
<void
>
This function withdraws unstaked and non locked tokens form staking contract to the user wallet.
Must have tokens available to withdraw
Parameters
Name | Type | Description |
---|---|---|
|
| Additional transaction parameters (optional, defaults to an empty object). |
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
build
▸ build(runner
): Promise
<StakingClient
>
Creates an instance of StakingClient from a Runner.
Parameters
Name | Type | Description |
---|---|---|
|
| The Runner object to interact with the Ethereum network |
Returns
Promise
<StakingClient
>
An instance of StakingClient
Throws
Thrown if the provider does not exist for the provided Signer
Throws
Thrown if the network's chainId is not supported
Defined in
Last updated