AllowanceCrowdsale.sol 1.3 KB

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