RefundVault.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. pragma solidity ^0.4.18;
  2. import "../math/SafeMath.sol";
  3. import "../ownership/Ownable.sol";
  4. /**
  5. * @title RefundVault
  6. * @dev This contract is used for storing funds while a crowdsale
  7. * is in progress. Supports refunding the money if crowdsale fails,
  8. * and forwarding it if crowdsale is successful.
  9. */
  10. contract RefundVault is Ownable {
  11. using SafeMath for uint256;
  12. enum State { Active, Refunding, Closed }
  13. mapping (address => uint256) public deposited;
  14. address public wallet;
  15. State public state;
  16. event Closed();
  17. event RefundsEnabled();
  18. event Refunded(address indexed beneficiary, uint256 weiAmount);
  19. function RefundVault(address _wallet) public {
  20. require(_wallet != address(0));
  21. wallet = _wallet;
  22. state = State.Active;
  23. }
  24. function deposit(address investor) onlyOwner public payable {
  25. require(state == State.Active);
  26. deposited[investor] = deposited[investor].add(msg.value);
  27. }
  28. function close() onlyOwner public {
  29. require(state == State.Active);
  30. state = State.Closed;
  31. Closed();
  32. wallet.transfer(this.balance);
  33. }
  34. function enableRefunds() onlyOwner public {
  35. require(state == State.Active);
  36. state = State.Refunding;
  37. RefundsEnabled();
  38. }
  39. function refund(address investor) public {
  40. require(state == State.Refunding);
  41. uint256 depositedValue = deposited[investor];
  42. deposited[investor] = 0;
  43. investor.transfer(depositedValue);
  44. Refunded(investor, depositedValue);
  45. }
  46. }