-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0xcc4ef9eeaf656ac1a2ab886743e98e97e090ed38-DDF-Digital_Developers_Fund_Token.sol
361 lines (304 loc) · 11.8 KB
/
0xcc4ef9eeaf656ac1a2ab886743e98e97e090ed38-DDF-Digital_Developers_Fund_Token.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
pragma solidity ^0.4.11;
/*
* Ownable
*
* Base contract with an owner.
* Provides onlyOwner modifier, which prevents function from running if it is called by anyone other than the owner.
*/
contract Ownable {
address public owner;
function Ownable() {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
_;
}
function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) {
owner = newOwner;
}
}
}
/* taking ideas from FirstBlood token */
contract SafeMath {
/* function assert(bool assertion) internal { */
/* if (!assertion) { */
/* throw; */
/* } */
/* } // assert no longer needed once solidity is on 0.4.10 */
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
uint256 z = x + y;
assert((z >= x) && (z >= y));
return z;
}
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
assert(x >= y);
uint256 z = x - y;
return z;
}
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
uint256 z = x * y;
assert((x == 0)||(z/x == y));
return z;
}
}
contract Token {
uint256 public totalSupply;
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 _value) returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
/* ERC 20 token */
contract StandardToken is Token {
modifier onlyPayloadSize(uint size) {
if(msg.data.length < size + 4) {
throw;
}
_;
}
function transfer(address _to, uint256 _value) onlyPayloadSize(2 * 32) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else {
return false;
}
}
function transferFrom(address _from, address _to, uint256 _value) onlyPayloadSize(3 * 32) returns (bool success) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}
contract splitterContract is Ownable{
event ev(string msg, address whom, uint256 val);
struct xRec {
bool inList;
address next;
address prev;
uint256 val;
}
struct l8r {
address whom;
uint256 val;
}
address public myAddress = this;
address public first;
address public last;
address public ddf;
bool public thinkMode;
uint256 public pos;
mapping (address => xRec) public theList;
l8r[] afterParty;
modifier onlyMeOrDDF() {
if (msg.sender == ddf || msg.sender == myAddress || msg.sender == owner) {
_;
return;
}
}
function setDDF(address ddf_) onlyOwner {
ddf = ddf_;
}
function splitterContract(address seed, uint256 seedVal) {
first = seed;
last = seed;
theList[seed] = xRec(true,0x0,0x0,seedVal);
}
function startThinking() onlyOwner {
thinkMode = true;
pos = 0;
}
function stopThinking(uint256 num) onlyOwner {
thinkMode = false;
for (uint256 i = 0; i < num; i++) {
if (pos >= afterParty.length) {
delete afterParty;
return;
}
update(afterParty[pos].whom,afterParty[pos].val);
pos++;
}
thinkMode = true;
}
function thinkLength() constant returns (uint256) {
return afterParty.length;
}
function addRec4L8R(address whom, uint256 val) internal {
afterParty.push(l8r(whom,val));
}
function add(address whom, uint256 value) internal {
theList[whom] = xRec(true,0x0,last,value);
theList[last].next = whom;
last = whom;
ev("add",whom,value);
}
function remove(address whom) internal {
if (first == whom) {
first = theList[whom].next;
theList[whom] = xRec(false,0x0,0x0,0);
return;
}
address next = theList[whom].next;
address prev = theList[whom].prev;
if (prev != 0x0) {
theList[prev].next = next;
}
if (next != 0x0) {
theList[next].prev = prev;
}
theList[whom] = xRec(false,0x0,0x0,0);
ev("remove",whom,0);
}
function update(address whom, uint256 value) onlyMeOrDDF {
if (thinkMode) {
addRec4L8R(whom,value);
return;
}
if (value != 0) {
if (!theList[whom].inList) {
add(whom,value);
} else {
theList[whom].val = value;
ev("update",whom,value);
}
return;
}
if (theList[whom].inList) {
remove(whom);
}
}
}
contract DDFToken is StandardToken, SafeMath {
// metadata
string public constant name = "Digital Developers Fund Token";
string public constant symbol = "DDF";
uint256 public constant decimals = 18;
string public version = "1.0";
// contracts
address public ethFundDeposit; // deposit address for ETH for Domain Development Fund
address public ddftFundDeposit; // deposit address for Domain Development Fund reserve
address public splitter; // DA 8/6/2017 - splitter contract
// crowdsale parameters
bool public isFinalized; // switched to true in operational state
uint256 public fundingStartTime;
uint256 public fundingEndTime;
uint256 public constant ddftFund = 25 * (10**5) * 10**decimals; // 1m DDFT reserved for DDF use
uint256 public constant tokenExchangeRate = 1000; // 1000 DDFT tokens per 1 ETH
uint256 public constant tokenCreationCap = 250 * (10**6) * 10**decimals;
uint256 public constant tokenCreationMin = 1 * (10**6) * 10**decimals;
// events
event LogRefund(address indexed _to, uint256 _value);
event CreateDDFT(address indexed _to, uint256 _value);
// constructor
function DDFToken(
address _ethFundDeposit,
address _ddftFundDeposit,
address _splitter, // DA 8/6/2017
uint256 _fundingStartTime,
uint256 duration)
{
isFinalized = false; //controls pre through crowdsale state
ethFundDeposit = _ethFundDeposit;
ddftFundDeposit = _ddftFundDeposit;
splitter = _splitter ; // DA 8/6/2017
fundingStartTime = _fundingStartTime;
fundingEndTime = fundingStartTime + duration * 1 days;
totalSupply = ddftFund;
balances[ddftFundDeposit] = ddftFund; // Deposit DDF share
CreateDDFT(ddftFundDeposit, ddftFund); // logs DDF fund
}
function () payable { // DA 8/6/2017 prefer to use fallback function
createTokens(msg.value);
}
/// @dev Accepts ether and creates new DDFT tokens.
function createTokens(uint256 _value) internal {
if (isFinalized) throw;
if (now < fundingStartTime) throw;
if (now > fundingEndTime) throw;
if (msg.value == 0) throw;
uint256 tokens = safeMult(_value, tokenExchangeRate); // check that we're not over totals
uint256 checkedSupply = safeAdd(totalSupply, tokens);
// DA 8/6/2017 to fairly allocate the last few tokens
if (tokenCreationCap < checkedSupply) {
if (tokenCreationCap <= totalSupply) throw; // CAP reached no more please
uint256 tokensToAllocate = safeSubtract(tokenCreationCap,totalSupply);
uint256 tokensToRefund = safeSubtract(tokens,tokensToAllocate);
totalSupply = tokenCreationCap;
balances[msg.sender] += tokensToAllocate; // safeAdd not needed; bad semantics to use here
uint256 etherToRefund = tokensToRefund / tokenExchangeRate;
msg.sender.transfer(etherToRefund);
CreateDDFT(msg.sender, tokensToAllocate); // logs token creation
LogRefund(msg.sender,etherToRefund);
splitterContract(splitter).update(msg.sender,balances[msg.sender]);
return;
}
// DA 8/6/2017 end of fair allocation code
totalSupply = checkedSupply;
balances[msg.sender] += tokens; // safeAdd not needed; bad semantics to use here
CreateDDFT(msg.sender, tokens); // logs token creation
splitterContract(splitter).update(msg.sender,balances[msg.sender]);
}
/// @dev Ends the funding period and sends the ETH home
function finalize() external {
if (isFinalized) throw;
if (msg.sender != ethFundDeposit) throw; // locks finalize to the ultimate ETH owner
if(totalSupply < tokenCreationMin + ddftFund) throw; // have to sell minimum to move to operational
if(now <= fundingEndTime && totalSupply != tokenCreationCap) throw;
// move to operational
isFinalized = true;
// DA 8/6/2017 change send/throw to transfer
ethFundDeposit.transfer(this.balance); // send the eth to DDF
}
/// @dev Allows contributors to recover their ether in the case of a failed funding campaign.
function refund() external {
if(isFinalized) throw; // prevents refund if operational
if (now <= fundingEndTime) throw; // prevents refund until sale period is over
if(totalSupply >= tokenCreationMin + ddftFund) throw; // no refunds if we sold enough
if(msg.sender == ddftFundDeposit) throw; // DDF not entitled to a refund
uint256 ddftVal = balances[msg.sender];
if (ddftVal == 0) throw;
balances[msg.sender] = 0;
totalSupply = safeSubtract(totalSupply, ddftVal); // extra safe
uint256 ethVal = ddftVal / tokenExchangeRate; // should be safe; previous throws covers edges
LogRefund(msg.sender, ethVal); // log it
// DA 8/6/2017 change send/throw to transfer
msg.sender.transfer(ethVal); // if you're using a contract; make sure it works with .send gas limits
}
// DA 8/6/2017
/// @dev Updates splitter contract with ownership changes
function transfer(address _to, uint _value) returns (bool success) {
success = super.transfer(_to,_value);
splitterContract sc = splitterContract(splitter);
sc.update(msg.sender,balances[msg.sender]);
sc.update(_to,balances[_to]);
return;
}
}