StakingToken
StakingToken copied to clipboard
createStake, removeStake: Use contract address itself to store the staked balance
Would it be better to transfer the _stake amount to contract address itself instead of burn in createStake() ? https://github.com/HQ20/StakingToken/blob/master/contracts/StakingToken.sol#L50 _burn subtracts the totalSupply and hence the suggestion. Similarly for removeStake(), transfer back the amount from contract address to the msg.sender Example:
mapping(address => uint256) public staked;
function stake(uint256 amount) external {
require(balanceOf(msg.sender) >= amount, "staking amount is more than balance");
transfer(address(this), amount);
staked[msg.sender] += amount;
}
function unstake(uint256 amount) external {
require(staked[msg.sender] >= amount, "staked amount is less than withdrawl amount");
staked[msg.sender] -= amount;
_transfer(address(this), msg.sender, amount);
}