2021-10-21 12:06:30 +00:00
|
|
|
// 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;
|
|
|
|
|
2021-11-04 10:40:03 +00:00
|
|
|
constructor(IERC20 __token) {
|
|
|
|
token = __token;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _token() internal view returns (IERC20) {
|
|
|
|
return token;
|
2021-10-21 12:06:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 14:17:19 +00:00
|
|
|
function _stake(address account) internal view returns (uint) {
|
2021-10-21 12:06:30 +00:00
|
|
|
return stakes[account];
|
|
|
|
}
|
|
|
|
|
2021-11-01 14:17:19 +00:00
|
|
|
function _increaseStake(uint amount) internal {
|
2021-10-21 12:06:30 +00:00
|
|
|
token.transferFrom(msg.sender, address(this), amount);
|
|
|
|
stakes[msg.sender] += amount;
|
|
|
|
}
|
|
|
|
|
2021-11-01 14:17:19 +00:00
|
|
|
function _withdrawStake() internal {
|
2021-10-21 12:06:30 +00:00
|
|
|
require(locks[msg.sender] == 0, "Stake locked");
|
|
|
|
token.transfer(msg.sender, stakes[msg.sender]);
|
|
|
|
}
|
|
|
|
|
2021-11-01 14:17:19 +00:00
|
|
|
function _lockStake(address account) internal {
|
2021-10-21 12:06:30 +00:00
|
|
|
locks[account] += 1;
|
|
|
|
}
|
|
|
|
|
2021-11-01 14:17:19 +00:00
|
|
|
function _unlockStake(address account) internal {
|
2021-10-21 12:06:30 +00:00
|
|
|
require(locks[account] > 0, "Stake already unlocked");
|
|
|
|
locks[account] -= 1;
|
|
|
|
}
|
2021-11-04 12:16:11 +00:00
|
|
|
|
|
|
|
function _slash(address account, uint percentage) internal {
|
|
|
|
stakes[account] = stakes[account] * (100 - percentage) / 100;
|
|
|
|
}
|
2021-10-21 12:06:30 +00:00
|
|
|
}
|