* Error handling in ERC20 and ERC721 * Added message string for require. * Fixed solhint errors. * Updated PR as per issue #1709 * changes as per #1709 and openzeppelin forum. * Changes in require statement * Changes in require statement * build pipeline fix * Changes as per @nventuro's comment. * Update revert reason strings. * Fianal update of revert reason strings. * WIP: Updating reason strings in test cases * WIP: Added changes to ERC20 and ERC721 * Fixes linting errors in *.tes.js files * Achieved 100% code coverage * Updated the test cases with shouldFail.reverting.withMessage() * Fix package-lock. * address review comments * fix linter issues * fix remaining revert reasons
64 lines
1.7 KiB
Solidity
64 lines
1.7 KiB
Solidity
pragma solidity ^0.5.7;
|
|
|
|
import "./SafeERC20.sol";
|
|
|
|
/**
|
|
* @title TokenTimelock
|
|
* @dev TokenTimelock is a token holder contract that will allow a
|
|
* beneficiary to extract the tokens after a given release time.
|
|
*/
|
|
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 {
|
|
// 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);
|
|
}
|
|
}
|