Function: withdraw(uint256 _amount)
The function allows users to withdraw tokens from the staking pool while ensuring that the user's staking and reward statuses are correctly updated.
Inputs
_amountControl: Arbitrary.
Constraints: Less than or equal to the
stakeTokenamount staked by the user.Impact: The amount of tokens the user wants to withdraw from the
StakePool.
Branches and code coverage
Intended branches
Check whether the user's stake amount is sufficient to withdraw the requested
_amount.Call
getAllRewardsto calculate and distribute all pending rewards for the user.Update the user's stake amount
user.amountand update therewardDebtof eachrewardPool.Transfer
_amountofstakeTokenfrom the contract back to the user.
Negative behavior
Revert if the
_amountthat the user withdraws is greater than theuser.amount.Revert if the current time (
block.timestamp) is less than the user'slastStakeTime + unstakingFrozenTime.