@@ -159,9 +159,6 @@ contract VaultCore is VaultStorage {
159159 whenNotCapitalPaused
160160 nonReentrant
161161 {
162- if (_amount > rebaseThreshold && ! rebasePaused) {
163- _rebase ();
164- }
165162 _redeem (_amount, _minimumUnitAmount);
166163 }
167164
@@ -173,14 +170,18 @@ contract VaultCore is VaultStorage {
173170 function _redeem (uint256 _amount , uint256 _minimumUnitAmount ) internal {
174171 require (_amount > 0 , "Amount must be greater than 0 " );
175172
176- uint256 _totalSupply = oUSD.totalSupply ();
177- uint256 _backingValue = _totalValue ();
173+ // Calculate redemption outputs
174+ (
175+ uint256 [] memory outputs ,
176+ uint256 _backingValue
177+ ) = _calculateRedeemOutputs (_amount);
178178
179+ // Check that OUSD is backed by enough assets
180+ uint256 _totalSupply = oUSD.totalSupply ();
179181 if (maxSupplyDiff > 0 ) {
180182 // Allow a max difference of maxSupplyDiff% between
181183 // backing assets value and OUSD total supply
182184 uint256 diff = _totalSupply.divPrecisely (_backingValue);
183-
184185 require (
185186 (diff > 1e18 ? diff.sub (1e18 ) : uint256 (1e18 ).sub (diff)) <=
186187 maxSupplyDiff,
@@ -190,8 +191,6 @@ contract VaultCore is VaultStorage {
190191
191192 emit Redeem (msg .sender , _amount);
192193
193- // Calculate redemption outputs
194- uint256 [] memory outputs = _calculateRedeemOutputs (_amount);
195194 // Send outputs
196195 for (uint256 i = 0 ; i < allAssets.length ; i++ ) {
197196 if (outputs[i] == 0 ) continue ;
@@ -248,11 +247,6 @@ contract VaultCore is VaultStorage {
248247 whenNotCapitalPaused
249248 nonReentrant
250249 {
251- // Unfortunately we have to do balanceOf twice, the rebase may change
252- // the account balance
253- if (oUSD.balanceOf (msg .sender ) > rebaseThreshold && ! rebasePaused) {
254- _rebase ();
255- }
256250 _redeem (oUSD.balanceOf (msg .sender ), _minimumUnitAmount);
257251 }
258252
@@ -513,7 +507,11 @@ contract VaultCore is VaultStorage {
513507 view
514508 returns (uint256 [] memory )
515509 {
516- return _calculateRedeemOutputs (_amount);
510+ (
511+ uint256 [] memory outputs ,
512+ uint256 totalValue
513+ ) = _calculateRedeemOutputs (_amount);
514+ return outputs;
517515 }
518516
519517 /**
@@ -524,7 +522,7 @@ contract VaultCore is VaultStorage {
524522 function _calculateRedeemOutputs (uint256 _amount )
525523 internal
526524 view
527- returns (uint256 [] memory outputs )
525+ returns (uint256 [] memory outputs , uint256 totalBalance )
528526 {
529527 // We always give out coins in proportion to how many we have,
530528 // Now if all coins were the same value, this math would easy,
@@ -559,7 +557,6 @@ contract VaultCore is VaultStorage {
559557 uint256 [] memory assetPrices = _getAssetPrices (true );
560558 uint256 [] memory assetBalances = new uint256 [](assetCount);
561559 uint256 [] memory assetDecimals = new uint256 [](assetCount);
562- uint256 totalBalance = 0 ;
563560 uint256 totalOutputRatio = 0 ;
564561 outputs = new uint256 [](assetCount);
565562
0 commit comments