Function: stake(uint256 _amount)
The msg.sender
provides stakingToken
to the current contract. The _totalSupply
and _balances
of msg.sender
is increased by _amount
-provided tokens. Also, the updateReward
modifier is triggered.
Inputs
_amount
Control: The caller has full control but cannot use more tokens than owned.
Constraints: If
msg.sender
owns less amount ofstakingToken
, transaction will be reverted.Impact: The amount of staking tokens.
Branches and code coverage (including function calls)
Intended branches
After first
stake
call, therewards[msg.sender]
is zero.If the caller's balance is nonzero, the
rewards[msg.sender]
is calculated properly.
Negative behavior
Revert if
msg.sender
'sstakingToken
balance is less than_amount
._amount
is zero.
Function call analysis
stakingToken.safeTransferFrom(msg.sender, address(this), _amount)
External/internal? External.
Argument control?
_amount
.Impact Transfer
stakingToken
frommsg.sender
to current contract.
updateReward(msg.sender)
External/internal? Internal.
Argument control? N/A.
Impact Updates global
lastUpdateTime
andrewardPerTokenStored
. Setsrewards
anduserRewardPerTokenPaid
ofmsg.sender
.