Skip to content

createStake, removeStake: Use contract address itself to store the staked balance #12

@jaglinux

Description

@jaglinux

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions