staking/contracts/StakeVault.sol
r4bbit 2e7c5148b4
refactor: migrate repository to foundry-template (#6)
This commit migrates the repo to our foundry template, which ensures we
have consistent tooling across smart contract repositories that are
maintained by Vac.

This removes all hardhat related files and workflows and replaces them
with more perfomant foundry workflows.

It also sets up tests, CI and linting.
2023-09-12 18:37:30 +02:00

57 lines
1.7 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { StakeManager } from "./StakeManager.sol";
/**
* @title StakeVault
* @author Ricardo Guilherme Schmidt <ricardo3@status.im>
* @notice Secures user stake
*/
contract StakeVault is Ownable {
StakeManager private stakeManager;
ERC20 immutable stakedToken;
event Staked(address from, address to, uint256 _amount, uint256 time);
constructor(address _owner, ERC20 _stakedToken, StakeManager _stakeManager) {
_transferOwnership(_owner);
stakedToken = _stakedToken;
stakeManager = _stakeManager;
}
function stake(uint256 _amount, uint256 _time) external onlyOwner {
stakedToken.transferFrom(msg.sender, address(this), _amount);
stakeManager.stake(_amount, _time);
emit Staked(msg.sender, address(this), _amount, _time);
}
function lock(uint256 _time) external onlyOwner {
stakeManager.lock(_time);
}
function unstake(uint256 _amount) external onlyOwner {
stakeManager.unstake(_amount);
stakedToken.transferFrom(address(this), msg.sender, _amount);
}
function leave() external onlyOwner {
stakeManager.leave();
stakedToken.transferFrom(address(this), msg.sender, stakedToken.balanceOf(address(this)));
}
/**
* @notice Opt-in migration to a new StakeManager contract.
*/
function updateManager() external onlyOwner {
StakeManager migrated = stakeManager.migrate();
require(address(migrated) != address(0), "Migration not available.");
stakeManager = migrated;
}
}