Created
May 10, 2021 20:47
-
-
Save percybolmer/6ed7991f3899d5526f7c2308425bc860 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 { | |
// 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