-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDolphinSale.sol
91 lines (75 loc) · 2 KB
/
DolphinSale.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
pragma solidity ^0.4.18;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Crowdsale {
using SafeMath for uint256;
address public owner;
address public multisig;
uint256 public totalRaised;
uint256 public constant hardCap = 20000 ether;
mapping(address => bool) public whitelist;
modifier isWhitelisted() {
require(whitelist[msg.sender]);
_;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier belowCap() {
require(totalRaised < hardCap);
_;
}
function Crowdsale(address _multisig) {
require (_multisig != 0);
owner = msg.sender;
multisig = _multisig;
}
function whitelistAddress(address _user) onlyOwner {
whitelist[_user] = true;
}
function whitelistAddresses(address[] _users) onlyOwner {
for (uint i = 0; i < _users.length; i++) {
whitelist[_users[i]] = true;
}
}
function() payable isWhitelisted belowCap {
totalRaised = totalRaised.add(msg.value);
uint contribution = msg.value;
if (totalRaised > hardCap) {
uint refundAmount = totalRaised.sub(hardCap);
msg.sender.transfer(refundAmount);
contribution = contribution.sub(refundAmount);
refundAmount = 0;
totalRaised = hardCap;
}
multisig.transfer(contribution);
}
function withdrawStuck() onlyOwner {
multisig.transfer(this.balance);
}
}