Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active May 9, 2021 11:41
Show Gist options
  • Save percybolmer/fc0f43b40f3ab6cb7a4f2ba74032c794 to your computer and use it in GitHub Desktop.
Save percybolmer/fc0f43b40f3ab6cb7a4f2ba74032c794 to your computer and use it in GitHub Desktop.
/**
* @notice
* removeStake takes in an amount and a index of the stake and will remove tokens from that stake
*/
function removeStake(uint256 _stake, uint256 index) public {
require(stakes[msg.sender][index].amount >= _stake, "Cannot withdraw more than you have staked");
// Remove by subtracting the money unstaked
stakes[msg.sender][index].amount = stakes[msg.sender][index].amount - _stake;
// If stake is empty, 0, then remove it from the array of stakes
if(stakes[msg.sender][index].amount == 0){
delete stakes[msg.sender][index];
}
// Return staked tokens to user
_mint(msg.sender, _stake);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment