@@ -26,11 +26,12 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
26
26
bytes32 private parentPayoutDistributionHash;
27
27
IReputationToken private reputationToken;
28
28
IMarket private forkingMarket;
29
+ bytes32 private tentativeWinningChildUniversePayoutDistributionHash;
29
30
uint256 private forkEndTime;
30
31
uint256 private forkReputationGoal;
31
32
mapping (uint256 => IFeeWindow) private feeWindows;
32
33
mapping (address => bool ) private markets;
33
- IUniverse[] private childUniverses;
34
+ mapping ( bytes32 => IUniverse) private childUniverses;
34
35
uint256 private openInterestInAttoEth;
35
36
36
37
mapping (address => uint256 ) private validityBondInAttoeth;
@@ -60,8 +61,6 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
60
61
} else {
61
62
// We're using a hardcoded supply value instead of getting the total REP supply from the token since at launch we will start out with a 0 supply token and users will migrate legacy REP to this token. Since the first fork may occur before all REP migrates we want to count that unmigrated REP too since it may participate in the fork eventually.
62
63
forkReputationGoal = Reporting.getInitialREPSupply () / Reporting.getForkRepMigrationVictoryDivisor ();
63
- // Account for the bonus for migrating rep that occurs before finalization
64
- forkReputationGoal += forkReputationGoal / Reporting.getForkMigrationPercentageBonusDivisor ();
65
64
}
66
65
controller.getAugur ().logUniverseForked ();
67
66
return true ;
@@ -104,13 +103,7 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
104
103
}
105
104
106
105
function getChildUniverse (bytes32 _parentPayoutDistributionHash ) public view returns (IUniverse) {
107
- for (uint8 i= 0 ; i < childUniverses.length ; i++ ) {
108
- IUniverse _childUniverse = childUniverses[i];
109
- if (_childUniverse.getParentPayoutDistributionHash () == _parentPayoutDistributionHash) {
110
- return _childUniverse;
111
- }
112
- }
113
- return IUniverse (0 );
106
+ return childUniverses[_parentPayoutDistributionHash];
114
107
}
115
108
116
109
function getFeeWindowId (uint256 _timestamp ) public view returns (uint256 ) {
@@ -164,34 +157,41 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
164
157
return getOrCreateFeeWindowByTimestamp (_feeWindow.getStartTime () - 2 );
165
158
}
166
159
167
- function createChildUniverse (bytes32 _parentPayoutDistributionHash ) public returns (IUniverse) {
168
- IReportingParticipant _reportingParticipant = IReportingParticipant (msg .sender );
169
- require (isContainerForReportingParticipant (_reportingParticipant));
170
- require (_reportingParticipant.getMarket () == forkingMarket);
160
+ function createChildUniverse (uint256 [] _parentPayoutNumerators , bool _parentInvalid ) public returns (IUniverse) {
161
+ bytes32 _parentPayoutDistributionHash = forkingMarket.derivePayoutDistributionHash (_parentPayoutNumerators, _parentInvalid);
171
162
IUniverse _childUniverse = getChildUniverse (_parentPayoutDistributionHash);
172
163
if (_childUniverse == IUniverse (0 )) {
173
164
_childUniverse = controller.getAugur ().createChildUniverse (_parentPayoutDistributionHash);
174
- childUniverses. push ( _childUniverse) ;
165
+ childUniverses[_parentPayoutDistributionHash] = _childUniverse;
175
166
controller.getAugur ().logUniverseCreated (_childUniverse);
176
167
}
177
168
return _childUniverse;
178
169
}
179
170
171
+ function updateTentativeWinningChildUniverse (bytes32 _parentPayoutDistributionHash ) public returns (bool ) {
172
+ IUniverse _tentativeWinningUniverse = getChildUniverse (tentativeWinningChildUniversePayoutDistributionHash);
173
+ IUniverse _updatedUniverse = getChildUniverse (_parentPayoutDistributionHash);
174
+ uint256 _currentTentativeWinningChildUniverseRepMigrated = 0 ;
175
+ if (_tentativeWinningUniverse != IUniverse (0 )) {
176
+ _tentativeWinningUniverse.getReputationToken ().getTotalMigrated ();
177
+ }
178
+ uint256 _updatedUniverseRepMigrated = _updatedUniverse.getReputationToken ().getTotalMigrated ();
179
+ if (_updatedUniverseRepMigrated > _currentTentativeWinningChildUniverseRepMigrated) {
180
+ tentativeWinningChildUniversePayoutDistributionHash = _parentPayoutDistributionHash;
181
+ }
182
+ if (_updatedUniverseRepMigrated >= forkReputationGoal) {
183
+ forkingMarket.finalizeFork ();
184
+ }
185
+ return true ;
186
+ }
187
+
180
188
function getWinningChildUniverse () public view returns (IUniverse) {
181
189
require (forkingMarket != IMarket (0 ));
182
- require (childUniverses.length > 0 );
183
- uint256 _winningAmount = 0 ;
184
- IUniverse _winningUniverse;
185
- for (uint8 i = 0 ; i < childUniverses.length ; i++ ) {
186
- uint256 _balance = childUniverses[i].getReputationToken ().totalSupply ();
187
- if (_balance > _winningAmount) {
188
- _winningUniverse = childUniverses[i];
189
- _winningAmount = _balance;
190
- }
191
- }
192
- require (_winningUniverse != IUniverse (0 ));
190
+ require (tentativeWinningChildUniversePayoutDistributionHash != bytes32 (0 ));
191
+ IUniverse _tentativeWinningUniverse = getChildUniverse (tentativeWinningChildUniversePayoutDistributionHash);
192
+ uint256 _winningAmount = _tentativeWinningUniverse.getReputationToken ().getTotalMigrated ();
193
193
require (_winningAmount >= forkReputationGoal || controller.getTimestamp () > forkEndTime);
194
- return _winningUniverse ;
194
+ return _tentativeWinningUniverse ;
195
195
}
196
196
197
197
function isContainerForFeeWindow (IFeeWindow _shadyFeeWindow ) public view returns (bool ) {
0 commit comments