AllowanceCrowdsale.sol 1.3 KB

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