TokenTimelock.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. pragma solidity ^0.4.24;
  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(
  17. IERC20 token,
  18. address beneficiary,
  19. uint256 releaseTime
  20. )
  21. public
  22. {
  23. // solium-disable-next-line security/no-block-members
  24. require(releaseTime > block.timestamp);
  25. _token = token;
  26. _beneficiary = beneficiary;
  27. _releaseTime = releaseTime;
  28. }
  29. /**
  30. * @return the token being held.
  31. */
  32. function token() public view returns(IERC20) {
  33. return _token;
  34. }
  35. /**
  36. * @return the beneficiary of the tokens.
  37. */
  38. function beneficiary() public view returns(address) {
  39. return _beneficiary;
  40. }
  41. /**
  42. * @return the time when the tokens are released.
  43. */
  44. function releaseTime() public view returns(uint256) {
  45. return _releaseTime;
  46. }
  47. /**
  48. * @notice Transfers tokens held by timelock to beneficiary.
  49. */
  50. function release() public {
  51. // solium-disable-next-line security/no-block-members
  52. require(block.timestamp >= _releaseTime);
  53. uint256 amount = _token.balanceOf(address(this));
  54. require(amount > 0);
  55. _token.safeTransfer(_beneficiary, amount);
  56. }
  57. }