TokenTimelock.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }