AllowanceCrowdsale.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pragma solidity ^0.4.21;
  2. import "../Crowdsale.sol";
  3. import "../../token/ERC20/ERC20.sol";
  4. import "../../math/SafeMath.sol";
  5. /**
  6. * @title AllowanceCrowdsale
  7. * @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale.
  8. */
  9. contract AllowanceCrowdsale is Crowdsale {
  10. using SafeMath for uint256;
  11. address public tokenWallet;
  12. /**
  13. * @dev Constructor, takes token wallet address.
  14. * @param _tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
  15. */
  16. function AllowanceCrowdsale(address _tokenWallet) public {
  17. require(_tokenWallet != address(0));
  18. tokenWallet = _tokenWallet;
  19. }
  20. /**
  21. * @dev Checks the amount of tokens left in the allowance.
  22. * @return Amount of tokens left in the allowance
  23. */
  24. function remainingTokens() public view returns (uint256) {
  25. return token.allowance(tokenWallet, this);
  26. }
  27. /**
  28. * @dev Overrides parent behavior by transferring tokens from wallet.
  29. * @param _beneficiary Token purchaser
  30. * @param _tokenAmount Amount of tokens purchased
  31. */
  32. function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
  33. token.transferFrom(tokenWallet, _beneficiary, _tokenAmount);
  34. }
  35. }