TokenTimelock.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. pragma solidity ^0.4.23;
  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 ERC20Basic;
  10. // ERC20 basic token contract being held
  11. ERC20Basic public token;
  12. // beneficiary of tokens after they are released
  13. address public beneficiary;
  14. // timestamp when token release is enabled
  15. uint256 public releaseTime;
  16. constructor(
  17. ERC20Basic _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. * @notice Transfers tokens held by timelock to beneficiary.
  31. */
  32. function release() public {
  33. // solium-disable-next-line security/no-block-members
  34. require(block.timestamp >= releaseTime);
  35. uint256 amount = token.balanceOf(this);
  36. require(amount > 0);
  37. token.safeTransfer(beneficiary, amount);
  38. }
  39. }