Last active
July 21, 2021 21:49
-
-
Save andrew-fleming/63c294d26bd3f391eaf1222f616d06bc to your computer and use it in GitHub Desktop.
Unstake
This file contains 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
pragma solidity 0.8.4; | |
function unstake(uint256 amount) public { | |
require( | |
isStaking[msg.sender] = true && | |
stakingBalance[msg.sender] >= amount, | |
"Nothing to unstake" | |
); | |
uint256 yieldTransfer = calculateYieldTotal(msg.sender); | |
startTime[msg.sender] = block.timestamp; // bug fix | |
uint256 balanceTransfer = amount; | |
amount = 0; | |
stakingBalance[msg.sender] -= balanceTransfer; | |
daiToken.transfer(msg.sender, balanceTransfer); | |
pmknBalance[msg.sender] += yieldTransfer; | |
if(stakingBalance[msg.sender] == 0){ | |
isStaking[msg.sender] = false; | |
} | |
emit Unstake(msg.sender, amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment