Last active
May 9, 2021 11:41
-
-
Save percybolmer/fc0f43b40f3ab6cb7a4f2ba74032c794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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