Remove arguments that are unnecessarily passed around
This commit is contained in:
@@ -187,10 +187,6 @@ contract MixinStake is
|
||||
// Sanity check the pool we're delegating to exists.
|
||||
_assertStakingPoolExists(poolId);
|
||||
|
||||
// Cache amount delegated to pool by staker.
|
||||
IStructs.StoredBalance memory initDelegatedStake =
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[staker][poolId]);
|
||||
|
||||
// Increment how much stake the staker has delegated to the input pool.
|
||||
_increaseNextBalance(
|
||||
_delegatedStakeToPoolByOwner[staker][poolId],
|
||||
@@ -200,16 +196,9 @@ contract MixinStake is
|
||||
// Increment how much stake has been delegated to pool.
|
||||
_increaseNextBalance(_delegatedStakeByPoolId[poolId], amount);
|
||||
|
||||
// Synchronizes reward state in the pool that the owner is delegating
|
||||
// to.
|
||||
IStructs.StoredBalance memory finalDelegatedStake =
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[staker][poolId]);
|
||||
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
staker,
|
||||
initDelegatedStake,
|
||||
finalDelegatedStake
|
||||
staker
|
||||
);
|
||||
}
|
||||
|
||||
@@ -227,10 +216,6 @@ contract MixinStake is
|
||||
// sanity check the pool we're undelegating from exists
|
||||
_assertStakingPoolExists(poolId);
|
||||
|
||||
// cache amount delegated to pool by staker
|
||||
IStructs.StoredBalance memory initDelegatedStake =
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[staker][poolId]);
|
||||
|
||||
// decrement how much stake the staker has delegated to the input pool
|
||||
_decreaseNextBalance(
|
||||
_delegatedStakeToPoolByOwner[staker][poolId],
|
||||
@@ -240,16 +225,9 @@ contract MixinStake is
|
||||
// decrement how much stake has been delegated to pool
|
||||
_decreaseNextBalance(_delegatedStakeByPoolId[poolId], amount);
|
||||
|
||||
// synchronizes reward state in the pool that the owner is undelegating
|
||||
// from
|
||||
IStructs.StoredBalance memory finalDelegatedStake =
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[staker][poolId]);
|
||||
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
staker,
|
||||
initDelegatedStake,
|
||||
finalDelegatedStake
|
||||
staker
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,23 +44,15 @@ contract MixinStakingPoolRewards is
|
||||
{
|
||||
address member = msg.sender;
|
||||
|
||||
IStructs.StoredBalance memory finalDelegatedStake =
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
|
||||
IStructs.StoredBalance memory initDelegatedStake =
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
member,
|
||||
initDelegatedStake,
|
||||
finalDelegatedStake
|
||||
member
|
||||
);
|
||||
|
||||
// Update stored balance with synchronized version; this prevents
|
||||
// redundant withdrawals.
|
||||
_delegatedStakeToPoolByOwner[member][poolId] =
|
||||
finalDelegatedStake;
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
}
|
||||
|
||||
/// @dev Computes the reward balance in ETH of the operator of a pool.
|
||||
@@ -110,7 +102,7 @@ contract MixinStakingPoolRewards is
|
||||
);
|
||||
return _computeDelegatorReward(
|
||||
poolId,
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]),
|
||||
member,
|
||||
unfinalizedMembersReward,
|
||||
unfinalizedMembersStake
|
||||
);
|
||||
@@ -120,15 +112,9 @@ contract MixinStakingPoolRewards is
|
||||
/// withdrawing rewards and adding/removing dependencies on cumulative rewards.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @param member of the pool.
|
||||
/// @param initDelegatedStake The member's delegated
|
||||
/// balance at the beginning of this transaction.
|
||||
/// @param finalDelegatedStake The member's delegated balance
|
||||
/// at the end of this transaction.
|
||||
function _withdrawAndSyncDelegatorRewards(
|
||||
bytes32 poolId,
|
||||
address member,
|
||||
IStructs.StoredBalance memory initDelegatedStake,
|
||||
IStructs.StoredBalance memory finalDelegatedStake
|
||||
address member
|
||||
)
|
||||
internal
|
||||
{
|
||||
@@ -138,7 +124,7 @@ contract MixinStakingPoolRewards is
|
||||
// Compute balance owed to delegator
|
||||
uint256 balance = _computeDelegatorReward(
|
||||
poolId,
|
||||
initDelegatedStake,
|
||||
member,
|
||||
// No unfinalized values because we ensured the pool is already
|
||||
// finalized.
|
||||
0,
|
||||
@@ -158,7 +144,7 @@ contract MixinStakingPoolRewards is
|
||||
// epoch, if necessary.
|
||||
_setCumulativeRewardDependenciesForDelegator(
|
||||
poolId,
|
||||
finalDelegatedStake
|
||||
member
|
||||
);
|
||||
}
|
||||
|
||||
@@ -261,13 +247,13 @@ contract MixinStakingPoolRewards is
|
||||
|
||||
/// @dev Computes the reward balance in ETH of a specific member of a pool.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @param unsyncedStake Unsynced delegated stake to pool by staker
|
||||
/// @param member of the pool.
|
||||
/// @param unfinalizedMembersReward Unfinalized total members reward (if any).
|
||||
/// @param unfinalizedMembersStake Unfinalized total members stake (if any).
|
||||
/// @return reward Balance in WETH.
|
||||
function _computeDelegatorReward(
|
||||
bytes32 poolId,
|
||||
IStructs.StoredBalance memory unsyncedStake,
|
||||
address member,
|
||||
uint256 unfinalizedMembersReward,
|
||||
uint256 unfinalizedMembersStake
|
||||
)
|
||||
@@ -282,6 +268,9 @@ contract MixinStakingPoolRewards is
|
||||
return 0;
|
||||
}
|
||||
|
||||
IStructs.StoredBalance memory unsyncedStake =
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
|
||||
// There can be no rewards if the last epoch when stake was synced is
|
||||
// equal to the current epoch, because all prior rewards, including
|
||||
// rewards finalized this epoch have been claimed.
|
||||
@@ -368,17 +357,15 @@ contract MixinStakingPoolRewards is
|
||||
/// A delegator always depends on the cumulative reward for the current
|
||||
/// and next epoch, if they would still have stake in the next epoch.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @param finalDelegatedStake Amount of stake the member has
|
||||
/// delegated to the pool.
|
||||
/// @param member of the pool.
|
||||
function _setCumulativeRewardDependenciesForDelegator(
|
||||
bytes32 poolId,
|
||||
IStructs.StoredBalance memory finalDelegatedStake
|
||||
address member
|
||||
)
|
||||
private
|
||||
{
|
||||
// Get the most recent cumulative reward, which will serve as a
|
||||
// reference point when updating dependencies
|
||||
IStructs.Fraction memory mostRecentCumulativeReward = _getMostRecentCumulativeReward(poolId);
|
||||
IStructs.StoredBalance memory finalDelegatedStake =
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
|
||||
// The delegator depends on the Cumulative Reward for this epoch
|
||||
// only if they are currently staked or will be staked next epoch.
|
||||
@@ -386,6 +373,10 @@ contract MixinStakingPoolRewards is
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the most recent cumulative reward, which will serve as a
|
||||
// reference point when updating dependencies
|
||||
IStructs.Fraction memory mostRecentCumulativeReward = _getMostRecentCumulativeReward(poolId);
|
||||
|
||||
// Delegator depends on the Cumulative Reward for this epoch - ensure it is set.
|
||||
if (!_isCumulativeRewardSet(_cumulativeRewardsByPool[poolId][finalDelegatedStake.currentEpoch])) {
|
||||
_forceSetCumulativeReward(
|
||||
|
||||
@@ -110,7 +110,6 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
_stake.isInitialized = true;
|
||||
_stake.currentEpochBalance += uint96(stake);
|
||||
@@ -118,9 +117,7 @@ contract TestDelegatorRewards is
|
||||
_stake.currentEpoch = uint32(currentEpoch);
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
delegator,
|
||||
initialStake,
|
||||
_stake
|
||||
delegator
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +132,6 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
if (_stake.currentEpoch < currentEpoch) {
|
||||
_stake.currentEpochBalance = _stake.nextEpochBalance;
|
||||
@@ -145,9 +141,7 @@ contract TestDelegatorRewards is
|
||||
_stake.currentEpoch = uint32(currentEpoch);
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
delegator,
|
||||
initialStake,
|
||||
_stake
|
||||
delegator
|
||||
);
|
||||
}
|
||||
|
||||
@@ -162,7 +156,6 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
if (_stake.currentEpoch < currentEpoch) {
|
||||
_stake.currentEpochBalance = _stake.nextEpochBalance;
|
||||
@@ -172,9 +165,7 @@ contract TestDelegatorRewards is
|
||||
_stake.currentEpoch = uint32(currentEpoch);
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
delegator,
|
||||
initialStake,
|
||||
_stake
|
||||
delegator
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user