StakingClient
Last updated
Last updated
/ / StakingClient
This client enables performing actions on staking contracts and obtaining 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 to send transactions calling the contract functions.
Provider: when the user wants to use this model to get information from the contracts or subgraph.
Using private key (backend)
Using Wagmi (frontend)
StakingClient constructor
Parameters
runner
ContractRunner
The Runner object to interact with the Ethereum network
networkData
The network information required to connect to the Staking contract
Returns
Overrides
Defined in
escrowFactoryContract:
EscrowFactory
Defined in
Inherited from
Defined in
protected
runner:ContractRunner
Inherited from
Defined in
stakingContract:
Staking
Defined in
tokenContract:
HMToken
Defined in
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
amount
bigint
Amount in WEI of tokens to approve for stake.
txOptions?
Overrides
= {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
Retrieves comprehensive staking information for a staker.
Parameters
stakerAddress
string
The address of the staker.
Returns
Code example
Defined in
slash(
slasher
,staker
,escrowAddress
,amount
,txOptions
?):Promise
<void
>
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.
Parameters
slasher
string
Wallet address from who requested the slash
staker
string
Wallet address from who is going to be slashed
escrowAddress
string
Address of the escrow that the slash is made
amount
bigint
Amount in WEI of tokens to slash.
txOptions?
Overrides
= {}
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(
amount
,txOptions
?):Promise
<void
>
This function stakes a specified amount of tokens on a specific network.
approveStake
must be called before
Parameters
amount
bigint
Amount in WEI of tokens to stake.
txOptions?
Overrides
= {}
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(
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
amount
bigint
Amount in WEI of tokens to unstake.
txOptions?
Overrides
= {}
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(
txOptions
?):Promise
<void
>
This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
Must have tokens available to withdraw
Parameters
txOptions?
Overrides
= {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
Creates an instance of StakingClient from a Runner.
Parameters
runner
ContractRunner
The Runner object to interact with the Ethereum network
Returns
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
new StakingClient(runner
, networkData
):
.
networkData:
.
.
getStakerInfo(stakerAddress
): Promise
<>
Promise
<>
static
build(runner
): Promise
<>
Promise
<>