Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jaglinux opened this issue Oct 21, 2021 · 0 comments

Comments

@jaglinux
Copy link

jaglinux commented Oct 21, 2021

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);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant