* Initial migration to Solidity 0.6.x - v3.0 first steps (#2063) * Initial migration, missing GSN, 721, 777 and Crowdsales. * Add _beforeTokenOperation and _afterTokenOperation. * Add documentation for hooks. * Add hooks doc * Add missing drafts * Add back ERC721 with hooks * Bring back ERC777 * Notes on hooks * Bring back GSN * Make functions virtual * Make GSN overrides explicit * Fix ERC20Pausable tests * Remove virtual from some view functions * Update linter * Delete examples * Remove unnecessary virtual * Remove roles from Pausable * Remove roles * Remove users of roles * Adapt ERC20 tests * Fix ERC721 tests * Add all ERC721 hooks * Add ERC777 hooks * Fix remaining tests * Bump compiler version * Move 721BurnableMock into mocks directory * Remove _before hooks * Fix tests * Upgrade linter * Put modifiers last * Remove _beforeTokenApproval and _beforeOperatorApproval hooks
68 lines
1.9 KiB
Solidity
68 lines
1.9 KiB
Solidity
pragma solidity ^0.6.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".
|
|
*
|
|
* For a more complete vesting schedule, see {TokenVesting}.
|
|
*/
|
|
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) public {
|
|
// 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);
|
|
}
|
|
}
|