AllowanceCrowdsale.sol 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. pragma solidity ^0.4.23;
  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. constructor(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(
  33. address _beneficiary,
  34. uint256 _tokenAmount
  35. )
  36. internal
  37. {
  38. token.transferFrom(tokenWallet, _beneficiary, _tokenAmount);
  39. }
  40. }