TokenTimelock.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. pragma solidity ^0.4.11;
  2. import './ERC20Basic.sol';
  3. import "../token/SafeERC20.sol";
  4. /**
  5. * @title TokenTimelock
  6. * @dev TokenTimelock is a token holder contract that will allow a
  7. * beneficiary to extract the tokens after a given release time
  8. */
  9. contract TokenTimelock {
  10. using SafeERC20 for ERC20Basic;
  11. // ERC20 basic token contract being held
  12. ERC20Basic token;
  13. // beneficiary of tokens after they are released
  14. address beneficiary;
  15. // timestamp when token release is enabled
  16. uint64 releaseTime;
  17. function TokenTimelock(ERC20Basic _token, address _beneficiary, uint64 _releaseTime) {
  18. require(_releaseTime > now);
  19. token = _token;
  20. beneficiary = _beneficiary;
  21. releaseTime = _releaseTime;
  22. }
  23. /**
  24. * @notice Transfers tokens held by timelock to beneficiary.
  25. * Deprecated: please use TokenTimelock#release instead.
  26. */
  27. function claim() {
  28. require(msg.sender == beneficiary);
  29. release();
  30. }
  31. /**
  32. * @notice Transfers tokens held by timelock to beneficiary.
  33. */
  34. function release() {
  35. require(now >= releaseTime);
  36. uint256 amount = token.balanceOf(this);
  37. require(amount > 0);
  38. token.safeTransfer(beneficiary, amount);
  39. }
  40. }