AllowanceCrowdsale.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pragma solidity ^0.4.24;
  2. import "../Crowdsale.sol";
  3. import "../../token/ERC20/IERC20.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 IERC20;
  13. address private _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. * @return the address of the wallet that will hold the tokens.
  24. */
  25. function tokenWallet() public view returns(address) {
  26. return _tokenWallet;
  27. }
  28. /**
  29. * @dev Checks the amount of tokens left in the allowance.
  30. * @return Amount of tokens left in the allowance
  31. */
  32. function remainingTokens() public view returns (uint256) {
  33. return token().allowance(_tokenWallet, this);
  34. }
  35. /**
  36. * @dev Overrides parent behavior by transferring tokens from wallet.
  37. * @param beneficiary Token purchaser
  38. * @param tokenAmount Amount of tokens purchased
  39. */
  40. function _deliverTokens(
  41. address beneficiary,
  42. uint256 tokenAmount
  43. )
  44. internal
  45. {
  46. token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount);
  47. }
  48. }