Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save percybolmer/6ed7991f3899d5526f7c2308425bc860 to your computer and use it in GitHub Desktop.
Save percybolmer/6ed7991f3899d5526f7c2308425bc860 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 {
// Grab user_index which is the index to use to grab the Stake[]
uint256 user_index = stakeHolders[msg.sender];
require(stakes[user_index][index].amount >= _stake, "Cannot withdraw more than you have staked");
// Remove by subtracting the money unstaked
stakes[user_index][index].amount = stakes[user_index][index].amount - _stake;
// If stake is empty, 0, then remove it from the array of stakes
if(stakes[user_index][index].amount == 0){
delete stakes[user_index][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