StakingClient
Last updated
Last updated
/ / / StakingClient
.StakingClient
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 signerOrProvider
. 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.
Using private key(backend)
Using Wagmi(frontend)
↳ StakingClient
• new StakingClient(signerOrProvider
, networkData
, gasPriceMultiplier?
)
StakingClient constructor
Parameters
signerOrProvider
Signer
| Provider
The Signer or Provider object to interact with the Ethereum network
networkData
NetworkData
-
gasPriceMultiplier?
number
The multiplier to apply to the gas price
Overrides
Defined in
• escrowFactoryContract: EscrowFactory
Defined in
• Protected
Optional
gasPriceMultiplier: number
Inherited from
Defined in
• networkData: NetworkData
Inherited from
Defined in
• rewardPoolContract: RewardPool
Defined in
• Protected
signerOrProvider: Signer
| Provider
Inherited from
Defined in
• stakingContract: Staking
Defined in
• tokenContract: HMToken
Defined in
▸ allocate(escrowAddress
, amount
): Promise
<void
>
This function allocates a portion of the staked tokens to a specific escrow.
Must have tokens staked
Parameters
escrowAddress
string
Address of the escrow contract to allocate in.
amount
BigNumber
Amount in WEI of tokens to allocate.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ approveStake(amount
): 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
BigNumber
Amount in WEI of tokens to approve for stake.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ Private
checkValidEscrow(escrowAddress
): Promise
<void
>
Check if escrow exists
Parameters
escrowAddress
string
Escrow address to check against
Returns
Promise
<void
>
Defined in
▸ closeAllocation(escrowAddress
): Promise
<void
>
This function drops the allocation from a specific escrow.
The escrow must have allocation The escrow must be cancelled or completed.
Parameters
escrowAddress
string
Address of the escrow contract to close allocation from.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ distributeReward(escrowAddress
): Promise
<void
>
This function drops the allocation from a specific escrow.
The escrow must have rewards added
Parameters
escrowAddress
string
Escrow address from which rewards are distributed.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ Protected
gasPriceOptions(): Promise
<Partial
<Overrides
>>
Adjust the gas price, and return as an option to be passed to a transaction
Returns
Promise
<Partial
<Overrides
>>
Returns the gas price options
Inherited from
Defined in
▸ getAllocation(escrowAddress
): Promise
<IAllocation
>
This function returns information about the allocation of the specified escrow.
Parameters
escrowAddress
string
Escrow address from which we want to get allocation information.
Returns
Promise
<IAllocation
>
Returns allocation info if exists.
Code example
Defined in
▸ getLeader(address
): Promise
<ILeader
>
This function returns all the leader details of the protocol.
Parameters
address
string
Returns
Promise
<ILeader
>
Returns an array with all the leader details.
Code example
Defined in
▸ getLeaders(filter?
): Promise
<ILeader
[]>
This function returns the leader data for the given address.
Parameters
filter
ILeadersFilter
Returns
Promise
<ILeader
[]>
Returns the leader details.
Code example
Defined in
▸ getRewards(slasherAddress
): Promise
<IReward
[]>
This function returns information about the rewards for a given slasher address.
Parameters
slasherAddress
string
Slasher address.
Returns
Promise
<IReward
[]>
Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
Code example
Defined in
▸ slash(slasher
, staker
, escrowAddress
, amount
): 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
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 which allocation will be slashed
amount
BigNumber
Amount in WEI of tokens to unstake.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ stake(amount
): Promise
<void
>
This function stakes a specified amount of tokens on a specific network.
approveStake
must be called before
Parameters
amount
BigNumber
Amount in WEI of tokens to stake.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ unstake(amount
): 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
BigNumber
Amount in WEI of tokens to unstake.
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
▸ withdraw(): Promise
<void
>
This function withdraws unstaked and non locked tokens form staking contract to the user wallet.
Must have tokens available to withdraw
Returns
Promise
<void
>
Returns void if successful. Throws error if any.
Code example
Defined in
Creates an instance of StakingClient from a Signer or Provider.
Parameters
signerOrProvider
Signer
| Provider
The Signer or Provider object to interact with the Ethereum network
gasPriceMultiplier?
number
The multiplier to apply to the gas price
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
.
.
.
.
.
▸ Static
build(signerOrProvider
, gasPriceMultiplier?
): Promise
<>
Promise
<>