Track WETH reserved for rewards

This commit is contained in:
Amir Bandeali 2019-09-23 14:21:13 -07:00
parent 156560ae22
commit fd35249de8
5 changed files with 11 additions and 2 deletions

View File

@ -146,6 +146,9 @@ contract MixinStorage is
/// @dev State for unfinalized rewards.
IStructs.UnfinalizedState public unfinalizedState;
/// @dev The WETH balance of this contract that is reserved for pool reward payouts.
uint256 _reservedWethBalance;
/// @dev Adds owner as an authorized address.
constructor()
public

View File

@ -217,6 +217,7 @@ contract MixinStake is
// to.
IStructs.StoredBalance memory finalDelegatedStakeToPoolByOwner =
_loadSyncedBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
_withdrawAndSyncDelegatorRewards(
poolId,
owner,
@ -256,6 +257,7 @@ contract MixinStake is
// from
IStructs.StoredBalance memory finalDelegatedStakeToPoolByOwner =
_loadSyncedBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
_withdrawAndSyncDelegatorRewards(
poolId,
owner,

View File

@ -204,6 +204,7 @@ contract MixinStakingPoolRewards is
if (membersReward > 0) {
// Increment the balance of the pool
balanceByPoolId[poolId] = balanceByPoolId[poolId].safeAdd(membersReward);
_reservedWethBalance = _reservedWethBalance.safeAdd(membersReward);
// 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.
@ -297,6 +298,7 @@ contract MixinStakingPoolRewards is
// Decrement the balance of the pool
balanceByPoolId[poolId] = balanceByPoolId[poolId].safeSub(balance);
_reservedWethBalance = _reservedWethBalance.safeSub(balance);
// Withdraw the member's WETH balance
_getWethContract().transfer(member, balance);

View File

@ -248,7 +248,9 @@ contract MixinFinalizer is
if (ethBalance != 0) {
wethContract.deposit.value(ethBalance)();
}
wethBalance = wethContract.balanceOf(address(this));
wethBalance = wethContract.balanceOf(address(this))
.safeSub(_reservedWethBalance);
return wethBalance;
}

View File

@ -12,7 +12,7 @@ import { DelegatorsByPoolId, OperatorByPoolId, StakeInfo, StakeStatus } from './
// tslint:disable:no-unnecessary-type-assertion
// tslint:disable:max-file-line-count
blockchainTests.resets.skip('Testing Rewards', env => {
blockchainTests.resets('Testing Rewards', env => {
// tokens & addresses
let accounts: string[];
let owner: string;