TokenTimelock.sol 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. pragma solidity ^0.5.2;
  2. import "./SafeERC20.sol";
  3. /**
  4. * @title TokenTimelock
  5. * @dev TokenTimelock is a token holder contract that will allow a
  6. * beneficiary to extract the tokens after a given release time
  7. */
  8. contract TokenTimelock {
  9. using SafeERC20 for IERC20;
  10. // ERC20 basic token contract being held
  11. IERC20 private _token;
  12. // beneficiary of tokens after they are released
  13. address private _beneficiary;
  14. // timestamp when token release is enabled
  15. uint256 private _releaseTime;
  16. constructor (IERC20 token, address beneficiary, uint256 releaseTime) public {
  17. // solhint-disable-next-line not-rely-on-time
  18. require(releaseTime > block.timestamp);
  19. _token = token;
  20. _beneficiary = beneficiary;
  21. _releaseTime = releaseTime;
  22. }
  23. /**
  24. * @return the token being held.
  25. */
  26. function token() public view returns (IERC20) {
  27. return _token;
  28. }
  29. /**
  30. * @return the beneficiary of the tokens.
  31. */
  32. function beneficiary() public view returns (address) {
  33. return _beneficiary;
  34. }
  35. /**
  36. * @return the time when the tokens are released.
  37. */
  38. function releaseTime() public view returns (uint256) {
  39. return _releaseTime;
  40. }
  41. /**
  42. * @notice Transfers tokens held by timelock to beneficiary.
  43. */
  44. function release() public {
  45. // solhint-disable-next-line not-rely-on-time
  46. require(block.timestamp >= _releaseTime);
  47. uint256 amount = _token.balanceOf(address(this));
  48. require(amount > 0);
  49. _token.safeTransfer(_beneficiary, amount);
  50. }
  51. }