AllowanceCrowdsale.sol 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }