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

  • _amount

    • Control: Arbitrary.

    • Constraints: Less than or equal to the stakeToken amount 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 getAllRewards to calculate and distribute all pending rewards for the user.

  • Update the user's stake amount user.amount and update the rewardDebt of each rewardPool.

  • Transfer _amount of stakeToken from the contract back to the user.

Negative behavior

  • Revert if the _amount that the user withdraws is greater than the user.amount.

  • Revert if the current time (block.timestamp) is less than the user's lastStakeTime + unstakingFrozenTime.

Zellic © 2025Back to top ↑