39 lines
914 B
Solidity
39 lines
914 B
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
contract Stakes {
|
|
|
|
IERC20 private token;
|
|
mapping(address=>uint) private stakes;
|
|
mapping(address=>uint) private locks;
|
|
|
|
constructor(IERC20 _token) {
|
|
token = _token;
|
|
}
|
|
|
|
function _stake(address account) internal view returns (uint) {
|
|
return stakes[account];
|
|
}
|
|
|
|
function _increaseStake(uint amount) internal {
|
|
token.transferFrom(msg.sender, address(this), amount);
|
|
stakes[msg.sender] += amount;
|
|
}
|
|
|
|
function _withdrawStake() internal {
|
|
require(locks[msg.sender] == 0, "Stake locked");
|
|
token.transfer(msg.sender, stakes[msg.sender]);
|
|
}
|
|
|
|
function _lockStake(address account) internal {
|
|
locks[account] += 1;
|
|
}
|
|
|
|
function _unlockStake(address account) internal {
|
|
require(locks[account] > 0, "Stake already unlocked");
|
|
locks[account] -= 1;
|
|
}
|
|
}
|