-
Notifications
You must be signed in to change notification settings - Fork 0
/
WavestreamPresale.sol
105 lines (89 loc) · 2.99 KB
/
WavestreamPresale.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
pragma solidity ^0.4.18;
import "zeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
/**
* @title WavestreamPresale
* @dev Capped crowdsale with two wallets.
*/
contract WavestreamPresale is CappedCrowdsale, Ownable {
using SafeMath for uint256;
bool public isClosed = false;
event Closed();
// The raised funds are being forwarded to two wallets. First, until total
// amout of wei raised is less than or equal to `priorityCap`, raised funds
// are forwarded to `priorityWallet`. After that, raised funds are
// forwarded to `wallet`.
uint256 public priorityCap;
// Address where first priorityCap raised wei are forwarded.
address public priorityWallet;
/**
* @dev Constructor
* @param _rate Number of token units a buyer gets per wei
* @param _priorityWallet Address where first priorityCap raised wei are forwarded
* @param _priorityCap Max amount of wei to be forwarded to _priorityWallet
* @param _wallet Address where collected funds will be forwarded after hitting _priorityCap
* @param _cap Max amount of wei to be contributed
* @param _token Address of the token being sold
*/
function WavestreamPresale(
uint256 _rate,
address _priorityWallet,
uint256 _priorityCap,
address _wallet,
uint256 _cap,
ERC20 _token
) public
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)
Ownable()
{
require(_priorityCap > 0);
require(_priorityCap < _cap);
require(_priorityWallet != address(0));
require(_priorityWallet != _wallet);
priorityWallet = _priorityWallet;
priorityCap = _priorityCap;
}
/**
* @dev Closes crowdsale. Can be only called by contract owner.
*/
function closeCrowdsale() onlyOwner public {
require(!isClosed);
isClosed = true;
uint256 tokenBalance = token.balanceOf(address(this));
if (tokenBalance > 0) {
token.transfer(owner, tokenBalance);
}
Closed();
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
* Part of OpenZeppelin internal interface.
*/
function _forwardFunds() internal {
if (weiRaised <= priorityCap) {
priorityWallet.transfer(msg.value);
} else {
uint256 weiRaisedBefore = weiRaised.sub(msg.value);
if (weiRaisedBefore < priorityCap) {
uint256 transferToPriorityWallet = priorityCap.sub(weiRaisedBefore);
uint256 transferToWallet = weiRaised.sub(priorityCap);
priorityWallet.transfer(transferToPriorityWallet);
wallet.transfer(transferToWallet);
} else {
wallet.transfer(msg.value);
}
}
}
/**
* @dev Validation of an incoming purchase.
* Part of OpenZeppelin internal interface.
*
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
require(!isClosed);
super._preValidatePurchase(_beneficiary, _weiAmount);
}
}