-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpresale.sol
220 lines (195 loc) · 6.62 KB
/
presale.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
pragma solidity 0.4.18;
import './SafeMath.sol';
import './Administration.sol';
interface ArcaneBearToken {
function transfer(address _recipient, uint256 _amount);
}
contract Crowdsale is Administration {
using SafeMath for uint256;
address public hotWallet;
uint256 public crowdsaleReserve;
uint256 public remainingTokens;
uint256 public tokenCostInWei;
uint256 public periodOneEnd; // 7 days
uint256 public periodOneBonus; // 20%
uint256 public currentPeriodBonus;
uint256 public tokenSold;
uint256 public hardCap = 108000000000000000000000000;
uint256 public minContributionAmount = 1000000000000000000; // 1 eth in wei
bool public contractLaunched;
bool public crowdsaleLaunched;
bool public crowdsalePaused;
bool public crowdsaleClosed; // this is only set to true at the beginning and end
bool public withdrawalsEnabled;
ArcaneBearToken public bearToken;
mapping (address => uint256) public balances;
mapping (address => uint256) public ethBalances;
event LaunchCrowdsale(address indexed _invoker, bool indexed _launched);
event PauseCrowdsale(address indexed _invoker, bool indexed _paused);
event ResumeCrowdsale(address indexed _invoker, bool indexed _resumed);
event LogContribution(address _backer, uint256 _bearTokensBought, uint256 _amountEther, bool _contributed);
event LogRefund(address indexed _backer, uint256 indexed _amountEther, bool indexed _refunded);
event TokenTransfer(address indexed _sender, address indexed _recipient, uint256 _amount);
modifier preLaunch() {
require(!contractLaunched);
_;
}
modifier afterLaunch() {
require(contractLaunched);
_;
}
modifier withdrawalEnabled() {
require(withdrawalsEnabled);
_;
}
function Crowdsale(address _bearTokenContractAddress, address _hotWallet, uint256 _crowdsaleReserve) {
bearToken = ArcaneBearToken(_bearTokenContractAddress);
hotWallet = _hotWallet;
contractLaunched = false;
crowdsaleLaunched = false;
crowdsalePaused = true;
crowdsaleClosed = true;
crowdsaleReserve = _crowdsaleReserve;
}
function() payable {
require(!crowdsaleClosed);
require(contribute(msg.sender));
}
function launchedContract()
public
onlyAdmin
preLaunch
returns (bool launched)
{
periodOneEnd = now + 7 days;
periodOneBonus = 200000000000000000;
crowdsalePaused = false;
crowdsaleClosed = false;
crowdsaleLaunched = true;
contractLaunched = true;
tokenSold = 0;
balances[owner] = crowdsaleReserve;
currentPeriodBonus = periodOneBonus;
LaunchCrowdsale(msg.sender, true);
return true;
}
function enableWithdrawals()
public
onlyAdmin
afterLaunch
returns (bool _withdrawalsEnabled)
{
withdrawalsEnabled = true;
return true;
}
function pauseCrowdsale()
public
onlyAdmin
afterLaunch
returns (bool paused)
{
require(!crowdsalePaused);
crowdsalePaused = true;
PauseCrowdsale(msg.sender, true);
return true;
}
function broadcastWithdrawal(address _backer)
public
onlyAdmin
withdrawalEnabled
returns (bool _withdrawn)
{
require(balances[_backer] > 0);
uint256 _rewardAmount = balances[_backer];
balances[_backer] = 0;
bearToken.transfer(_backer, _rewardAmount);
TokenTransfer(this, _backer, _rewardAmount);
return true;
}
function withdrawBEAR()
public
withdrawalEnabled
returns (bool _withdrawn)
{
require(balances[msg.sender] > 0);
uint256 _rewardAmount = balances[msg.sender];
balances[msg.sender] = 0;
bearToken.transfer(msg.sender, _rewardAmount);
TokenTransfer(this, msg.sender, _rewardAmount);
return true;
}
function withdrawEth()
public
returns (bool _ethWithdrawn)
{
require(ethBalances[msg.sender] > 0);
uint256 _refundAmount = ethBalances[msg.sender];
ethBalances[msg.sender] = 0;
msg.sender.transfer(_refundAmount);
LogRefund(msg.sender, _refundAmount, true);
return true;
}
function resumeCrowdsale()
public
onlyAdmin
afterLaunch
returns (bool paused)
{
require(crowdsalePaused);
crowdsalePaused = false;
ResumeCrowdsale(msg.sender, true);
return true;
}
function refundCalculation(address _backer, uint256 _amountRefund)
private
returns (bool valid)
{
require(ethBalances[_backer].add(_amountRefund) > ethBalances[_backer]);
ethBalances[_backer] = ethBalances[_backer].add(_amountRefund);
return true;
}
function contribute(address _backer)
payable
returns (bool _contributed)
{
require(contractLaunched);
require(now <= periodOneEnd);
require(_backer != address(0x0));
require(msg.value >= minContributionAmount);
// Run a period check to determine how much of a bonus they get.
uint256 _amountBEAR = msg.value / tokenCostInWei;
uint256 amountBEAR = _amountBEAR.mul(1 ether);
uint256 amountCharged = 0;
uint256 amountRefund = 0;
uint256 _bonusAmount = amountBEAR.mul(currentPeriodBonus);
uint256 bonusAmount = _bonusAmount.div(1 ether);
amountBEAR = amountBEAR.add(bonusAmount);
if (amountBEAR >= remainingTokens) {
amountBEAR = remainingTokens;
uint256 _amountCharged = amountBEAR.div(tokenCostInWei);
amountCharged = _amountCharged.mul(1 ether);
amountRefund = msg.value.sub(amountCharged);
// No more tokens available so lets end the crowdsale
crowdsaleClosed = true;
} else {
amountCharged = msg.value;
}
if (amountRefund > 0) {
require(refundCalculation(_backer, amountRefund));
}
require(balances[this].sub(amountBEAR) >= 0);
require(balances[_backer].add(amountBEAR) > balances[_backer]);
balances[this] = balances[this].sub(amountBEAR);
balances[_backer] = balances[_backer].add(amountBEAR);
hotWallet.transfer(amountCharged);
LogContribution(_backer, amountBEAR, amountCharged, true);
return true;
}
function getStatus()
public
view
returns (bool _status)
{
return crowdsalePaused;
}
}