Separate wrapping ETH and querying available WETH balance

This commit is contained in:
Amir Bandeali
2019-09-23 15:14:21 -07:00
parent fd35249de8
commit 3965d8f8c6
2 changed files with 18 additions and 10 deletions

View File

@@ -134,7 +134,7 @@ contract MixinExchangeFees is
returns (uint256 totalBalance) returns (uint256 totalBalance)
{ {
totalBalance = address(this).balance.safeAdd( totalBalance = address(this).balance.safeAdd(
_getWethContract().balanceOf(address(this)) _getAvailableWethBalance()
); );
return totalBalance; return totalBalance;
} }

View File

@@ -76,8 +76,11 @@ contract MixinFinalizer is
); );
} }
// Convert all ETH to WETH
_wrapEth();
// Set up unfinalized state. // Set up unfinalized state.
state.rewardsAvailable = _wrapEthAndGetWethBalance(); state.rewardsAvailable = _getAvailableWethBalance();
state.poolsRemaining = poolsRemaining = numActivePoolsThisEpoch; state.poolsRemaining = poolsRemaining = numActivePoolsThisEpoch;
state.totalFeesCollected = totalFeesCollectedThisEpoch; state.totalFeesCollected = totalFeesCollectedThisEpoch;
state.totalWeightedStake = totalWeightedStakeThisEpoch; state.totalWeightedStake = totalWeightedStakeThisEpoch;
@@ -236,19 +239,24 @@ contract MixinFinalizer is
return activePools; return activePools;
} }
/// @dev Converts the entire ETH balance of the contract into WETH and /// @dev Converts the entire ETH balance of this contract into WETH.
/// returns the total WETH balance of this contract. function _wrapEth()
/// @return The WETH balance of this contract.
function _wrapEthAndGetWethBalance()
internal internal
returns (uint256 wethBalance)
{ {
IEtherToken wethContract = _getWethContract();
uint256 ethBalance = address(this).balance; uint256 ethBalance = address(this).balance;
if (ethBalance != 0) { if (ethBalance != 0) {
wethContract.deposit.value(ethBalance)(); _getWethContract().deposit.value(ethBalance)();
} }
wethBalance = wethContract.balanceOf(address(this)) }
/// @dev Returns the WETH balance of this contract, minus
/// any WETH that has already been reserved for rewards.
function _getAvailableWethBalance()
internal
view
returns (uint256 wethBalance)
{
wethBalance = _getWethContract().balanceOf(address(this))
.safeSub(_reservedWethBalance); .safeSub(_reservedWethBalance);
return wethBalance; return wethBalance;