* Fix unnamed return variable warning This commit fixes warnings thrown by the solc 0.7.4 compiler: "Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable." * Fix function state mutability warning This commit fixes warnings thrown by the solc 0.7.4 compiler: "Warning: Function state mutability can be restricted to pure" * Fix shadows an existing declaration warning This commit fixes warnings thrown by the solc 0.7.4 compiler: "Warning: This declaration shadows an existing declaration." 1. Arguments by default are not underscored. 2. If the name isn't available due to shadowing, use prefix underscore. 3. If prefix underscore isn't available due to shadowing, use suffix underscore.
68 lines
1.8 KiB
Solidity
68 lines
1.8 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
import "./SafeERC20.sol";
|
|
|
|
/**
|
|
* @dev A token holder contract that will allow a beneficiary to extract the
|
|
* tokens after a given release time.
|
|
*
|
|
* Useful for simple vesting schedules like "advisors get all of their tokens
|
|
* after 1 year".
|
|
*/
|
|
contract TokenTimelock {
|
|
using SafeERC20 for IERC20;
|
|
|
|
// ERC20 basic token contract being held
|
|
IERC20 private _token;
|
|
|
|
// beneficiary of tokens after they are released
|
|
address private _beneficiary;
|
|
|
|
// timestamp when token release is enabled
|
|
uint256 private _releaseTime;
|
|
|
|
constructor (IERC20 token_, address beneficiary_, uint256 releaseTime_) {
|
|
// solhint-disable-next-line not-rely-on-time
|
|
require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time");
|
|
_token = token_;
|
|
_beneficiary = beneficiary_;
|
|
_releaseTime = releaseTime_;
|
|
}
|
|
|
|
/**
|
|
* @return the token being held.
|
|
*/
|
|
function token() public view returns (IERC20) {
|
|
return _token;
|
|
}
|
|
|
|
/**
|
|
* @return the beneficiary of the tokens.
|
|
*/
|
|
function beneficiary() public view returns (address) {
|
|
return _beneficiary;
|
|
}
|
|
|
|
/**
|
|
* @return the time when the tokens are released.
|
|
*/
|
|
function releaseTime() public view returns (uint256) {
|
|
return _releaseTime;
|
|
}
|
|
|
|
/**
|
|
* @notice Transfers tokens held by timelock to beneficiary.
|
|
*/
|
|
function release() public virtual {
|
|
// solhint-disable-next-line not-rely-on-time
|
|
require(block.timestamp >= _releaseTime, "TokenTimelock: current time is before release time");
|
|
|
|
uint256 amount = _token.balanceOf(address(this));
|
|
require(amount > 0, "TokenTimelock: no tokens to release");
|
|
|
|
_token.safeTransfer(_beneficiary, amount);
|
|
}
|
|
}
|