forked from blockchainsllc/DAO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DAO.sol
938 lines (780 loc) · 33.8 KB
/
DAO.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/*
This file is part of the DAO.
The DAO is free software: you can redistribute it and/or modify
it under the terms of the GNU lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The DAO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.
You should have received a copy of the GNU lesser General Public License
along with the DAO. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Standard smart contract for a Decentralized Autonomous Organization (DAO)
to automate organizational governance and decision-making.
*/
import "./TokenCreation.sol";
import "./ManagedAccount.sol";
contract DAOInterface {
// The amount of days for which people who try to participate in the
// creation by calling the fallback function will still get their ether back
uint constant creationGracePeriod = 40 days;
// The minimum debate period that a generic proposal can have
uint constant minProposalDebatePeriod = 2 weeks;
// The minimum debate period that a split proposal can have
uint constant minSplitDebatePeriod = 1 weeks;
// Period of days inside which it's possible to execute a DAO split
uint constant splitExecutionPeriod = 27 days;
// Period of time after which the minimum Quorum is halved
uint constant quorumHalvingPeriod = 25 weeks;
// Period after which a proposal is closed
// (used in the case `executeProposal` fails because it throws)
uint constant executeProposalPeriod = 10 days;
// Denotes the maximum proposal deposit that can be given. It is given as
// a fraction of total Ether spent plus balance of the DAO
uint constant maxDepositDivisor = 100;
// Proposals to spend the DAO's ether or to choose a new Curator
Proposal[] public proposals;
// The quorum needed for each proposal is partially calculated by
// totalSupply / minQuorumDivisor
uint public minQuorumDivisor;
// The unix time of the last time quorum was reached on a proposal
uint public lastTimeMinQuorumMet;
// Address of the curator
address public curator;
// The whitelist: List of addresses the DAO is allowed to send ether to
mapping (address => bool) public allowedRecipients;
// Tracks the addresses that own Reward Tokens. Those addresses can only be
// DAOs that have split from the original DAO. Conceptually, Reward Tokens
// represent the proportion of the rewards that the DAO has the right to
// receive. These Reward Tokens are generated when the DAO spends ether.
mapping (address => uint) public rewardToken;
// Total supply of rewardToken
uint public totalRewardToken;
// The account used to manage the rewards which are to be distributed to the
// DAO Token Holders of this DAO
ManagedAccount public rewardAccount;
// The account used to manage the rewards which are to be distributed to
// any DAO that holds Reward Tokens
ManagedAccount public DAOrewardAccount;
// Amount of rewards (in wei) already paid out to a certain DAO
mapping (address => uint) public DAOpaidOut;
// Amount of rewards (in wei) already paid out to a certain address
mapping (address => uint) public paidOut;
// Map of addresses blocked during a vote (not allowed to transfer DAO
// tokens). The address points to the proposal ID.
mapping (address => uint) public blocked;
// The minimum deposit (in wei) required to submit any proposal that is not
// requesting a new Curator (no deposit is required for splits)
uint public proposalDeposit;
// the accumulated sum of all current proposal deposits
uint sumOfProposalDeposits;
// Contract that is able to create a new DAO (with the same code as
// this one), used for splits
DAO_Creator public daoCreator;
// A proposal with `newCurator == false` represents a transaction
// to be issued by this DAO
// A proposal with `newCurator == true` represents a DAO split
struct Proposal {
// The address where the `amount` will go to if the proposal is accepted
// or if `newCurator` is true, the proposed Curator of
// the new DAO).
address recipient;
// The amount to transfer to `recipient` if the proposal is accepted.
uint amount;
// A plain text description of the proposal
string description;
// A unix timestamp, denoting the end of the voting period
uint votingDeadline;
// True if the proposal's votes have yet to be counted, otherwise False
bool open;
// True if quorum has been reached, the votes have been counted, and
// the majority said yes
bool proposalPassed;
// A hash to check validity of a proposal
bytes32 proposalHash;
// Deposit in wei the creator added when submitting their proposal. It
// is taken from the msg.value of a newProposal call.
uint proposalDeposit;
// True if this proposal is to assign a new Curator
bool newCurator;
// Data needed for splitting the DAO
SplitData[] splitData;
// Number of Tokens in favor of the proposal
uint yea;
// Number of Tokens opposed to the proposal
uint nay;
// Simple mapping to check if a shareholder has voted for it
mapping (address => bool) votedYes;
// Simple mapping to check if a shareholder has voted against it
mapping (address => bool) votedNo;
// Address of the shareholder who created the proposal
address creator;
}
// Used only in the case of a newCurator proposal.
struct SplitData {
// The balance of the current DAO minus the deposit at the time of split
uint splitBalance;
// The total amount of DAO Tokens in existence at the time of split.
uint totalSupply;
// Amount of Reward Tokens owned by the DAO at the time of split.
uint rewardToken;
// The new DAO contract created at the time of split.
DAO newDAO;
}
// Used to restrict access to certain functions to only DAO Token Holders
modifier onlyTokenholders {}
/// @dev Constructor setting the Curator and the address
/// for the contract able to create another DAO as well as the parameters
/// for the DAO Token Creation
/// @param _curator The Curator
/// @param _daoCreator The contract able to (re)create this DAO
/// @param _proposalDeposit The deposit to be paid for a regular proposal
/// @param _minTokensToCreate Minimum required wei-equivalent tokens
/// to be created for a successful DAO Token Creation
/// @param _closingTime Date (in Unix time) of the end of the DAO Token Creation
/// @param _privateCreation If zero the DAO Token Creation is open to public, a
/// non-zero address means that the DAO Token Creation is only for the address
/// @param _tokenName The name that the DAO's token will have
/// @param _tokenSymbol The ticker symbol that this DAO token should have
/// @param _decimalPlaces The number of decimal places that the token is
/// counted from.
// This is the constructor: it can not be overloaded so it is commented out
// function DAO(
// address _curator,
// DAO_Creator _daoCreator,
// uint _proposalDeposit,
// uint _minTokensToCreate,
// uint _closingTime,
// address _privateCreation
// string _tokenName,
// string _tokenSymbol,
// uint8 _decimalPlaces
// );
/// @notice Create Token with `msg.sender` as the beneficiary
/// @return Whether the token creation was successful
function () returns (bool success);
/// @dev This function is used to send ether back
/// to the DAO, it can also be used to receive payments that should not be
/// counted as rewards (donations, grants, etc.)
/// @return Whether the DAO received the ether successfully
function receiveEther() returns(bool);
/// @notice `msg.sender` creates a proposal to send `_amount` Wei to
/// `_recipient` with the transaction data `_transactionData`. If
/// `_newCurator` is true, then this is a proposal that splits the
/// DAO and sets `_recipient` as the new DAO's Curator.
/// @param _recipient Address of the recipient of the proposed transaction
/// @param _amount Amount of wei to be sent with the proposed transaction
/// @param _description String describing the proposal
/// @param _transactionData Data of the proposed transaction
/// @param _debatingPeriod Time used for debating a proposal, at least 2
/// weeks for a regular proposal, 10 days for new Curator proposal
/// @param _newCurator Bool defining whether this proposal is about
/// a new Curator or not
/// @return The proposal ID. Needed for voting on the proposal
function newProposal(
address _recipient,
uint _amount,
string _description,
bytes _transactionData,
uint _debatingPeriod,
bool _newCurator
) onlyTokenholders returns (uint _proposalID);
/// @notice Check that the proposal with the ID `_proposalID` matches the
/// transaction which sends `_amount` with data `_transactionData`
/// to `_recipient`
/// @param _proposalID The proposal ID
/// @param _recipient The recipient of the proposed transaction
/// @param _amount The amount of wei to be sent in the proposed transaction
/// @param _transactionData The data of the proposed transaction
/// @return Whether the proposal ID matches the transaction data or not
function checkProposalCode(
uint _proposalID,
address _recipient,
uint _amount,
bytes _transactionData
) constant returns (bool _codeChecksOut);
/// @notice Vote on proposal `_proposalID` with `_supportsProposal`
/// @param _proposalID The proposal ID
/// @param _supportsProposal Yes/No - support of the proposal
function vote(uint _proposalID, bool _supportsProposal);
/// @notice Checks whether proposal `_proposalID` with transaction data
/// `_transactionData` has been voted for or rejected, and executes the
/// transaction in the case it has been voted for.
/// @param _proposalID The proposal ID
/// @param _transactionData The data of the proposed transaction
/// @return Whether the proposed transaction has been executed or not
function executeProposal(
uint _proposalID,
bytes _transactionData
) returns (bool _success);
/// @notice ATTENTION! I confirm to move my remaining ether to a new DAO
/// with `_newCurator` as the new Curator, as has been
/// proposed in proposal `_proposalID`. This will burn my tokens. This can
/// not be undone and will split the DAO into two DAO's, with two
/// different underlying tokens.
/// @param _proposalID The proposal ID
/// @param _newCurator The new Curator of the new DAO
/// @dev This function, when called for the first time for this proposal,
/// will create a new DAO and send the sender's portion of the remaining
/// ether and Reward Tokens to the new DAO. It will also burn the DAO Tokens
/// of the sender.
function splitDAO(
uint _proposalID,
address _newCurator
) returns (bool _success);
/// @dev can only be called by the DAO itself through a proposal
/// updates the contract of the DAO by sending all ether and rewardTokens
/// to the new DAO. The new DAO needs to be approved by the Curator
/// @param _newContract the address of the new contract
function newContract(address _newContract);
/// @notice Add a new possible recipient `_recipient` to the whitelist so
/// that the DAO can send transactions to them (using proposals)
/// @param _recipient New recipient address
/// @dev Can only be called by the current Curator
/// @return Whether successful or not
function changeAllowedRecipients(address _recipient, bool _allowed) external returns (bool _success);
/// @notice Change the minimum deposit required to submit a proposal
/// @param _proposalDeposit The new proposal deposit
/// @dev Can only be called by this DAO (through proposals with the
/// recipient being this DAO itself)
function changeProposalDeposit(uint _proposalDeposit) external;
/// @notice Move rewards from the DAORewards managed account
/// @param _toMembers If true rewards are moved to the actual reward account
/// for the DAO. If not then it's moved to the DAO itself
/// @return Whether the call was successful
function retrieveDAOReward(bool _toMembers) external returns (bool _success);
/// @notice Get my portion of the reward that was sent to `rewardAccount`
/// @return Whether the call was successful
function getMyReward() returns(bool _success);
/// @notice Withdraw `_account`'s portion of the reward from `rewardAccount`
/// to `_account`'s balance
/// @return Whether the call was successful
function withdrawRewardFor(address _account) internal returns (bool _success);
/// @notice Send `_amount` tokens to `_to` from `msg.sender`. Prior to this
/// getMyReward() is called.
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transfered
/// @return Whether the transfer was successful or not
function transferWithoutReward(address _to, uint256 _amount) returns (bool success);
/// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
/// is approved by `_from`. Prior to this getMyReward() is called.
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transfered
/// @return Whether the transfer was successful or not
function transferFromWithoutReward(
address _from,
address _to,
uint256 _amount
) returns (bool success);
/// @notice Doubles the 'minQuorumDivisor' in the case quorum has not been
/// achieved in 52 weeks
/// @return Whether the change was successful or not
function halveMinQuorum() returns (bool _success);
/// @return total number of proposals ever created
function numberOfProposals() constant returns (uint _numberOfProposals);
/// @param _proposalID Id of the new curator proposal
/// @return Address of the new DAO
function getNewDAOAddress(uint _proposalID) constant returns (address _newDAO);
/// @param _account The address of the account which is checked.
/// @return Whether the account is blocked (not allowed to transfer tokens) or not.
function isBlocked(address _account) internal returns (bool);
/// @notice If the caller is blocked by a proposal whose voting deadline
/// has exprired then unblock him.
/// @return Whether the account is blocked (not allowed to transfer tokens) or not.
function unblockMe() returns (bool);
event ProposalAdded(
uint indexed proposalID,
address recipient,
uint amount,
bool newCurator,
string description
);
event Voted(uint indexed proposalID, bool position, address indexed voter);
event ProposalTallied(uint indexed proposalID, bool result, uint quorum);
event NewCurator(address indexed _newCurator);
event AllowedRecipientChanged(address indexed _recipient, bool _allowed);
}
// The DAO contract itself
contract DAO is DAOInterface, Token, TokenCreation {
// Modifier that allows only shareholders to vote and create new proposals
modifier onlyTokenholders {
if (balanceOf(msg.sender) == 0) throw;
_
}
function DAO(
address _curator,
DAO_Creator _daoCreator,
uint _proposalDeposit,
uint _minTokensToCreate,
uint _closingTime,
address _privateCreation,
string _tokenName,
string _tokenSymbol,
uint8 _decimalPlaces
) TokenCreation(
_minTokensToCreate,
_closingTime,
_privateCreation,
_tokenName,
_tokenSymbol,
_decimalPlaces) {
curator = _curator;
daoCreator = _daoCreator;
proposalDeposit = _proposalDeposit;
rewardAccount = new ManagedAccount(address(this), false);
DAOrewardAccount = new ManagedAccount(address(this), false);
if (address(rewardAccount) == 0)
throw;
if (address(DAOrewardAccount) == 0)
throw;
lastTimeMinQuorumMet = now;
minQuorumDivisor = 5; // sets the minimal quorum to 20%
proposals.length = 1; // avoids a proposal with ID 0 because it is used
allowedRecipients[address(this)] = true;
allowedRecipients[curator] = true;
}
function () returns (bool success) {
if (now < closingTime + creationGracePeriod && msg.sender != address(extraBalance))
return createTokenProxy(msg.sender);
else
return receiveEther();
}
function receiveEther() returns (bool) {
return true;
}
function newProposal(
address _recipient,
uint _amount,
string _description,
bytes _transactionData,
uint _debatingPeriod,
bool _newCurator
) onlyTokenholders returns (uint _proposalID) {
// Sanity check
if (_newCurator && (
_amount != 0
|| _transactionData.length != 0
|| _recipient == curator
|| msg.value > 0
|| _debatingPeriod < minSplitDebatePeriod)) {
throw;
} else if (
!_newCurator
&& (!isRecipientAllowed(_recipient) || (_debatingPeriod < minProposalDebatePeriod))
) {
throw;
}
if (_debatingPeriod > 8 weeks)
throw;
if (!isFueled
|| now < closingTime
|| (msg.value < proposalDeposit && !_newCurator)) {
throw;
}
if (now + _debatingPeriod < now) // prevents overflow
throw;
// to prevent a 51% attacker to convert the ether into deposit
if (msg.sender == address(this))
throw;
// to prevent curator from halving quorum before first proposal
if (proposals.length == 1) // initial length is 1 (see constructor)
lastTimeMinQuorumMet = now;
_proposalID = proposals.length++;
Proposal p = proposals[_proposalID];
p.recipient = _recipient;
p.amount = _amount;
p.description = _description;
p.proposalHash = sha3(_recipient, _amount, _transactionData);
p.votingDeadline = now + _debatingPeriod;
p.open = true;
//p.proposalPassed = False; // that's default
p.newCurator = _newCurator;
if (_newCurator)
p.splitData.length++;
p.creator = msg.sender;
p.proposalDeposit = msg.value;
sumOfProposalDeposits += msg.value;
ProposalAdded(
_proposalID,
_recipient,
_amount,
_newCurator,
_description
);
}
function checkProposalCode(
uint _proposalID,
address _recipient,
uint _amount,
bytes _transactionData
) noEther constant returns (bool _codeChecksOut) {
Proposal p = proposals[_proposalID];
return p.proposalHash == sha3(_recipient, _amount, _transactionData);
}
function vote(uint _proposalID, bool _supportsProposal) onlyTokenholders noEther {
Proposal p = proposals[_proposalID];
if (p.votedYes[msg.sender]
|| p.votedNo[msg.sender]
|| now >= p.votingDeadline) {
throw;
}
if (_supportsProposal) {
p.yea += balances[msg.sender];
p.votedYes[msg.sender] = true;
} else {
p.nay += balances[msg.sender];
p.votedNo[msg.sender] = true;
}
if (blocked[msg.sender] == 0) {
blocked[msg.sender] = _proposalID;
} else if (p.votingDeadline > proposals[blocked[msg.sender]].votingDeadline) {
// this proposal's voting deadline is further into the future than
// the proposal that blocks the sender so make it the blocker
blocked[msg.sender] = _proposalID;
}
Voted(_proposalID, _supportsProposal, msg.sender);
}
function executeProposal(
uint _proposalID,
bytes _transactionData
) noEther returns (bool _success) {
Proposal p = proposals[_proposalID];
uint waitPeriod = p.newCurator
? splitExecutionPeriod
: executeProposalPeriod;
// If we are over deadline and waiting period, assert proposal is closed
if (p.open && now > p.votingDeadline + waitPeriod) {
closeProposal(_proposalID);
return;
}
// Check if the proposal can be executed
if (now < p.votingDeadline // has the voting deadline arrived?
// Have the votes been counted?
|| !p.open
|| p.proposalPassed // anyone trying to call us recursively?
// Does the transaction code match the proposal?
|| p.proposalHash != sha3(p.recipient, p.amount, _transactionData)) {
throw;
}
// If the curator removed the recipient from the whitelist, close the proposal
// in order to free the deposit and allow unblocking of voters
if (!isRecipientAllowed(p.recipient)) {
closeProposal(_proposalID);
p.creator.send(p.proposalDeposit);
return;
}
bool proposalCheck = true;
if (p.amount > actualBalance())
proposalCheck = false;
uint quorum = p.yea + p.nay;
// require 53% for calling newContract()
if (_transactionData.length >= 4 && _transactionData[0] == 0x68
&& _transactionData[1] == 0x37 && _transactionData[2] == 0xff
&& _transactionData[3] == 0x1e
&& quorum < minQuorum(actualBalance() + rewardToken[address(this)])) {
proposalCheck = false;
}
if (quorum >= minQuorum(p.amount)) {
if (!p.creator.send(p.proposalDeposit))
throw;
lastTimeMinQuorumMet = now;
// set the minQuorum to 20% again, in the case it has been reached
if (quorum > totalSupply / 5)
minQuorumDivisor = 5;
}
// Execute result
if (quorum >= minQuorum(p.amount) && p.yea > p.nay && proposalCheck) {
// we are setting this here before the CALL() value transfer to
// assure that in the case of a malicious recipient contract trying
// to call executeProposal() recursively money can't be transferred
// multiple times out of the DAO
p.proposalPassed = true;
if (!p.recipient.call.value(p.amount)(_transactionData))
throw;
_success = true;
// only create reward tokens when ether is not sent to the DAO itself and
// related addresses. Proxy addresses should be forbidden by the curator.
if (p.recipient != address(this) && p.recipient != address(rewardAccount)
&& p.recipient != address(DAOrewardAccount)
&& p.recipient != address(extraBalance)
&& p.recipient != address(curator)) {
rewardToken[address(this)] += p.amount;
totalRewardToken += p.amount;
}
}
closeProposal(_proposalID);
// Initiate event
ProposalTallied(_proposalID, _success, quorum);
}
function closeProposal(uint _proposalID) internal {
Proposal p = proposals[_proposalID];
if (p.open)
sumOfProposalDeposits -= p.proposalDeposit;
p.open = false;
}
function splitDAO(
uint _proposalID,
address _newCurator
) noEther onlyTokenholders returns (bool _success) {
Proposal p = proposals[_proposalID];
// Sanity check
if (now < p.votingDeadline // has the voting deadline arrived?
//The request for a split expires XX days after the voting deadline
|| now > p.votingDeadline + splitExecutionPeriod
// Does the new Curator address match?
|| p.recipient != _newCurator
// Is it a new curator proposal?
|| !p.newCurator
// Have you voted for this split?
|| !p.votedYes[msg.sender]
// Did you already vote on another proposal?
|| (blocked[msg.sender] != _proposalID && blocked[msg.sender] != 0) ) {
throw;
}
// If the new DAO doesn't exist yet, create the new DAO and store the
// current split data
if (address(p.splitData[0].newDAO) == 0) {
p.splitData[0].newDAO = createNewDAO(_newCurator);
// Call depth limit reached, etc.
if (address(p.splitData[0].newDAO) == 0)
throw;
// should never happen
if (this.balance < sumOfProposalDeposits)
throw;
p.splitData[0].splitBalance = actualBalance();
p.splitData[0].rewardToken = rewardToken[address(this)];
p.splitData[0].totalSupply = totalSupply;
p.proposalPassed = true;
}
// Move ether and assign new Tokens
uint fundsToBeMoved =
(balances[msg.sender] * p.splitData[0].splitBalance) /
p.splitData[0].totalSupply;
if (p.splitData[0].newDAO.createTokenProxy.value(fundsToBeMoved)(msg.sender) == false)
throw;
// Assign reward rights to new DAO
uint rewardTokenToBeMoved =
(balances[msg.sender] * p.splitData[0].rewardToken) /
p.splitData[0].totalSupply;
uint paidOutToBeMoved = DAOpaidOut[address(this)] * rewardTokenToBeMoved /
rewardToken[address(this)];
rewardToken[address(p.splitData[0].newDAO)] += rewardTokenToBeMoved;
if (rewardToken[address(this)] < rewardTokenToBeMoved)
throw;
rewardToken[address(this)] -= rewardTokenToBeMoved;
DAOpaidOut[address(p.splitData[0].newDAO)] += paidOutToBeMoved;
if (DAOpaidOut[address(this)] < paidOutToBeMoved)
throw;
DAOpaidOut[address(this)] -= paidOutToBeMoved;
// Burn DAO Tokens
Transfer(msg.sender, 0, balances[msg.sender]);
withdrawRewardFor(msg.sender); // be nice, and get his rewards
totalSupply -= balances[msg.sender];
balances[msg.sender] = 0;
paidOut[msg.sender] = 0;
return true;
}
function newContract(address _newContract){
if (msg.sender != address(this) || !allowedRecipients[_newContract]) return;
// move all ether
if (!_newContract.call.value(address(this).balance)()) {
throw;
}
//move all reward tokens
rewardToken[_newContract] += rewardToken[address(this)];
rewardToken[address(this)] = 0;
DAOpaidOut[_newContract] += DAOpaidOut[address(this)];
DAOpaidOut[address(this)] = 0;
}
function retrieveDAOReward(bool _toMembers) external noEther returns (bool _success) {
DAO dao = DAO(msg.sender);
if ((rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
totalRewardToken < DAOpaidOut[msg.sender])
throw;
uint reward =
(rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
totalRewardToken - DAOpaidOut[msg.sender];
reward = DAOrewardAccount.balance < reward ? DAOrewardAccount.balance : reward;
if(_toMembers) {
if (!DAOrewardAccount.payOut(dao.rewardAccount(), reward))
throw;
}
else {
if (!DAOrewardAccount.payOut(dao, reward))
throw;
}
DAOpaidOut[msg.sender] += reward;
return true;
}
function getMyReward() noEther returns (bool _success) {
return withdrawRewardFor(msg.sender);
}
function withdrawRewardFor(address _account) noEther internal returns (bool _success) {
if ((balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply < paidOut[_account])
throw;
uint reward =
(balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply - paidOut[_account];
reward = rewardAccount.balance < reward ? rewardAccount.balance : reward;
if (!rewardAccount.payOut(_account, reward))
throw;
paidOut[_account] += reward;
return true;
}
function transfer(address _to, uint256 _value) returns (bool success) {
if (isFueled
&& now > closingTime
&& !isBlocked(msg.sender)
&& _to != address(this)
&& transferPaidOut(msg.sender, _to, _value)
&& super.transfer(_to, _value)) {
return true;
} else {
throw;
}
}
function transferWithoutReward(address _to, uint256 _value) returns (bool success) {
if (!getMyReward())
throw;
return transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (isFueled
&& now > closingTime
&& !isBlocked(_from)
&& _to != address(this)
&& transferPaidOut(_from, _to, _value)
&& super.transferFrom(_from, _to, _value)) {
return true;
} else {
throw;
}
}
function transferFromWithoutReward(
address _from,
address _to,
uint256 _value
) returns (bool success) {
if (!withdrawRewardFor(_from))
throw;
return transferFrom(_from, _to, _value);
}
function transferPaidOut(
address _from,
address _to,
uint256 _value
) internal returns (bool success) {
uint transferPaidOut = paidOut[_from] * _value / balanceOf(_from);
if (transferPaidOut > paidOut[_from])
throw;
paidOut[_from] -= transferPaidOut;
paidOut[_to] += transferPaidOut;
return true;
}
function changeProposalDeposit(uint _proposalDeposit) noEther external {
if (msg.sender != address(this) || _proposalDeposit > (actualBalance() + rewardToken[address(this)])
/ maxDepositDivisor) {
throw;
}
proposalDeposit = _proposalDeposit;
}
function changeAllowedRecipients(address _recipient, bool _allowed) noEther external returns (bool _success) {
if (msg.sender != curator)
throw;
allowedRecipients[_recipient] = _allowed;
AllowedRecipientChanged(_recipient, _allowed);
return true;
}
function isRecipientAllowed(address _recipient) internal returns (bool _isAllowed) {
if (allowedRecipients[_recipient]
|| (_recipient == address(extraBalance)
// only allowed when at least the amount held in the
// extraBalance account has been spent from the DAO
&& totalRewardToken > extraBalance.accumulatedInput()))
return true;
else
return false;
}
function actualBalance() constant returns (uint _actualBalance) {
return this.balance - sumOfProposalDeposits;
}
function minQuorum(uint _value) internal constant returns (uint _minQuorum) {
// minimum of 20% and maximum of 53.33%
return totalSupply / minQuorumDivisor +
(_value * totalSupply) / (3 * (actualBalance() + rewardToken[address(this)]));
}
function halveMinQuorum() returns (bool _success) {
// this can only be called after `quorumHalvingPeriod` has passed or at anytime after
// fueling by the curator with a delay of at least `minProposalDebatePeriod`
// between the calls
if ((lastTimeMinQuorumMet < (now - quorumHalvingPeriod) || msg.sender == curator)
&& lastTimeMinQuorumMet < (now - minProposalDebatePeriod)
&& now >= closingTime
&& proposals.length > 1) {
lastTimeMinQuorumMet = now;
minQuorumDivisor *= 2;
return true;
} else {
return false;
}
}
function createNewDAO(address _newCurator) internal returns (DAO _newDAO) {
NewCurator(_newCurator);
return daoCreator.createDAO(
_newCurator,
0,
0,
now + splitExecutionPeriod,
name,
symbol,
decimals
);
}
function numberOfProposals() constant returns (uint _numberOfProposals) {
// Don't count index 0. It's used by isBlocked() and exists from start
return proposals.length - 1;
}
function getNewDAOAddress(uint _proposalID) constant returns (address _newDAO) {
return proposals[_proposalID].splitData[0].newDAO;
}
function isBlocked(address _account) internal returns (bool) {
if (blocked[_account] == 0)
return false;
Proposal p = proposals[blocked[_account]];
if (now > p.votingDeadline) {
blocked[_account] = 0;
return false;
} else {
return true;
}
}
function unblockMe() returns (bool) {
return isBlocked(msg.sender);
}
}
contract DAO_Creator {
function createDAO(
address _curator,
uint _proposalDeposit,
uint _minTokensToCreate,
uint _closingTime,
string _tokenName,
string _tokenSymbol,
uint8 _decimalPlaces
) returns (DAO _newDAO) {
return new DAO(
_curator,
DAO_Creator(this),
_proposalDeposit,
_minTokensToCreate,
_closingTime,
msg.sender,
_tokenName,
_tokenSymbol,
_decimalPlaces
);
}
}