Rename functions and variables for clarity
This commit is contained in:
		@@ -129,7 +129,7 @@ contract MixinExchangeFees is
 | 
				
			|||||||
    /// @dev Returns the total balance of this contract, including WETH,
 | 
					    /// @dev Returns the total balance of this contract, including WETH,
 | 
				
			||||||
    ///      minus any WETH that has been reserved for rewards.
 | 
					    ///      minus any WETH that has been reserved for rewards.
 | 
				
			||||||
    /// @return totalBalance Total balance.
 | 
					    /// @return totalBalance Total balance.
 | 
				
			||||||
    function getAvailableBalance()
 | 
					    function getAvailableRewardsBalance()
 | 
				
			||||||
        external
 | 
					        external
 | 
				
			||||||
        view
 | 
					        view
 | 
				
			||||||
        returns (uint256 totalBalance)
 | 
					        returns (uint256 totalBalance)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,7 +83,7 @@ contract MixinStorage is
 | 
				
			|||||||
    mapping (bytes32 => IStructs.Pool) internal _poolById;
 | 
					    mapping (bytes32 => IStructs.Pool) internal _poolById;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // mapping from PoolId to balance of members
 | 
					    // mapping from PoolId to balance of members
 | 
				
			||||||
    mapping (bytes32 => uint256) public balanceByPoolId;
 | 
					    mapping (bytes32 => uint256) public rewardsByPoolId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // current epoch
 | 
					    // current epoch
 | 
				
			||||||
    uint256 public currentEpoch = INITIAL_EPOCH;
 | 
					    uint256 public currentEpoch = INITIAL_EPOCH;
 | 
				
			||||||
@@ -147,7 +147,7 @@ contract MixinStorage is
 | 
				
			|||||||
    IStructs.UnfinalizedState public unfinalizedState;
 | 
					    IStructs.UnfinalizedState public unfinalizedState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// @dev The WETH balance of this contract that is reserved for pool reward payouts.
 | 
					    /// @dev The WETH balance of this contract that is reserved for pool reward payouts.
 | 
				
			||||||
    uint256 _reservedWethBalance;
 | 
					    uint256 _wethReservedForPoolRewards;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// @dev Adds owner as an authorized address.
 | 
					    /// @dev Adds owner as an authorized address.
 | 
				
			||||||
    constructor()
 | 
					    constructor()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -203,8 +203,7 @@ contract MixinStakingPoolRewards is
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (membersReward > 0) {
 | 
					        if (membersReward > 0) {
 | 
				
			||||||
            // Increment the balance of the pool
 | 
					            // Increment the balance of the pool
 | 
				
			||||||
            balanceByPoolId[poolId] = balanceByPoolId[poolId].safeAdd(membersReward);
 | 
					            _incrementPoolRewards(poolId, membersReward);
 | 
				
			||||||
            _reservedWethBalance = _reservedWethBalance.safeAdd(membersReward);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Fetch the last epoch at which we stored an entry for this pool;
 | 
					            // Fetch the last epoch at which we stored an entry for this pool;
 | 
				
			||||||
            // this is the most up-to-date cumulative rewards for this pool.
 | 
					            // this is the most up-to-date cumulative rewards for this pool.
 | 
				
			||||||
@@ -297,8 +296,7 @@ contract MixinStakingPoolRewards is
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Decrement the balance of the pool
 | 
					        // Decrement the balance of the pool
 | 
				
			||||||
        balanceByPoolId[poolId] = balanceByPoolId[poolId].safeSub(balance);
 | 
					        _decrementPoolRewards(poolId, balance);
 | 
				
			||||||
        _reservedWethBalance = _reservedWethBalance.safeSub(balance);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Withdraw the member's WETH balance
 | 
					        // Withdraw the member's WETH balance
 | 
				
			||||||
        _getWethContract().transfer(member, balance);
 | 
					        _getWethContract().transfer(member, balance);
 | 
				
			||||||
@@ -432,4 +430,24 @@ contract MixinStakingPoolRewards is
 | 
				
			|||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// @dev Increments rewards for a pool.
 | 
				
			||||||
 | 
					    /// @param poolId Unique id of pool.
 | 
				
			||||||
 | 
					    /// @param amount Amount to increment rewards by.
 | 
				
			||||||
 | 
					    function _incrementPoolRewards(bytes32 poolId, uint256 amount)
 | 
				
			||||||
 | 
					        private
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        rewardsByPoolId[poolId] = rewardsByPoolId[poolId].safeAdd(amount);
 | 
				
			||||||
 | 
					        _wethReservedForPoolRewards = _wethReservedForPoolRewards.safeAdd(amount);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// @dev Decrements rewards for a pool.
 | 
				
			||||||
 | 
					    /// @param poolId Unique id of pool.
 | 
				
			||||||
 | 
					    /// @param amount Amount to decrement rewards by.
 | 
				
			||||||
 | 
					    function _decrementPoolRewards(bytes32 poolId, uint256 amount)
 | 
				
			||||||
 | 
					        private
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        rewardsByPoolId[poolId] = rewardsByPoolId[poolId].safeSub(amount);
 | 
				
			||||||
 | 
					        _wethReservedForPoolRewards = _wethReservedForPoolRewards.safeSub(amount);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -257,7 +257,7 @@ contract MixinFinalizer is
 | 
				
			|||||||
        returns (uint256 wethBalance)
 | 
					        returns (uint256 wethBalance)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        wethBalance = _getWethContract().balanceOf(address(this))
 | 
					        wethBalance = _getWethContract().balanceOf(address(this))
 | 
				
			||||||
            .safeSub(_reservedWethBalance);
 | 
					            .safeSub(_wethReservedForPoolRewards);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return wethBalance;
 | 
					        return wethBalance;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -230,7 +230,7 @@ export class FinalizerActor extends BaseActor {
 | 
				
			|||||||
        for (const poolId of poolIds) {
 | 
					        for (const poolId of poolIds) {
 | 
				
			||||||
            rewardVaultBalanceByPoolId[
 | 
					            rewardVaultBalanceByPoolId[
 | 
				
			||||||
                poolId
 | 
					                poolId
 | 
				
			||||||
            ] = await this._stakingApiWrapper.stakingContract.balanceByPoolId.callAsync(poolId);
 | 
					            ] = await this._stakingApiWrapper.stakingContract.rewardsByPoolId.callAsync(poolId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return rewardVaultBalanceByPoolId;
 | 
					        return rewardVaultBalanceByPoolId;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -241,7 +241,7 @@ export class FinalizerActor extends BaseActor {
 | 
				
			|||||||
                this._stakingApiWrapper.stakingContract.getActiveStakingPoolThisEpoch.callAsync(poolId),
 | 
					                this._stakingApiWrapper.stakingContract.getActiveStakingPoolThisEpoch.callAsync(poolId),
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        const totalRewards = await this._stakingApiWrapper.stakingContract.getAvailableBalance.callAsync();
 | 
					        const totalRewards = await this._stakingApiWrapper.stakingContract.getAvailableRewardsBalance.callAsync();
 | 
				
			||||||
        const totalFeesCollected = BigNumber.sum(...activePools.map(p => p.feesCollected));
 | 
					        const totalFeesCollected = BigNumber.sum(...activePools.map(p => p.feesCollected));
 | 
				
			||||||
        const totalWeightedStake = BigNumber.sum(...activePools.map(p => p.weightedStake));
 | 
					        const totalWeightedStake = BigNumber.sum(...activePools.map(p => p.weightedStake));
 | 
				
			||||||
        if (totalRewards.eq(0) || totalFeesCollected.eq(0) || totalWeightedStake.eq(0)) {
 | 
					        if (totalRewards.eq(0) || totalFeesCollected.eq(0) || totalWeightedStake.eq(0)) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,7 +131,7 @@ blockchainTests.resets('Testing Rewards', env => {
 | 
				
			|||||||
                // operator
 | 
					                // operator
 | 
				
			||||||
                stakingApiWrapper.wethContract.balanceOf.callAsync(poolOperator.getOwner()),
 | 
					                stakingApiWrapper.wethContract.balanceOf.callAsync(poolOperator.getOwner()),
 | 
				
			||||||
                // undivided balance in reward pool
 | 
					                // undivided balance in reward pool
 | 
				
			||||||
                stakingApiWrapper.stakingContract.balanceByPoolId.callAsync(poolId),
 | 
					                stakingApiWrapper.stakingContract.rewardsByPoolId.callAsync(poolId),
 | 
				
			||||||
            ]);
 | 
					            ]);
 | 
				
			||||||
            expect(finalEndBalancesAsArray[0], 'stakerRewardBalance_1').to.be.bignumber.equal(
 | 
					            expect(finalEndBalancesAsArray[0], 'stakerRewardBalance_1').to.be.bignumber.equal(
 | 
				
			||||||
                expectedEndBalances.stakerRewardBalance_1,
 | 
					                expectedEndBalances.stakerRewardBalance_1,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user