@0x/contract-staking
: Make solidity uniformly hideous ;-).
This commit is contained in:
@@ -89,8 +89,7 @@ contract MixinExchangeFees is
|
||||
return;
|
||||
}
|
||||
|
||||
uint256 poolStake =
|
||||
getTotalStakeDelegatedToPool(poolId).currentEpochBalance;
|
||||
uint256 poolStake = getTotalStakeDelegatedToPool(poolId).currentEpochBalance;
|
||||
// Ignore pools with dust stake.
|
||||
if (poolStake < minimumPoolStake) {
|
||||
return;
|
||||
@@ -105,12 +104,10 @@ contract MixinExchangeFees is
|
||||
// If the pool was previously inactive in this epoch, initialize it.
|
||||
if (pool.feesCollected == 0) {
|
||||
// Compute member and total weighted stake.
|
||||
(pool.membersStake, pool.weightedStake) =
|
||||
_computeMembersAndWeightedStake(poolId, poolStake);
|
||||
(pool.membersStake, pool.weightedStake) = _computeMembersAndWeightedStake(poolId, poolStake);
|
||||
|
||||
// Increase the total weighted stake.
|
||||
totalWeightedStakeThisEpoch =
|
||||
totalWeightedStakeThisEpoch.safeAdd(pool.weightedStake);
|
||||
totalWeightedStakeThisEpoch = totalWeightedStakeThisEpoch.safeAdd(pool.weightedStake);
|
||||
|
||||
// Increase the number of active pools.
|
||||
numActivePoolsThisEpoch += 1;
|
||||
|
@@ -71,9 +71,9 @@ library LibCobbDouglas {
|
||||
// `totalRewards * stakeRatio / e^(alpha * (ln(stakeRatio / feeRatio)))`
|
||||
|
||||
// Compute
|
||||
// `e^(alpha * (ln(feeRatio/stakeRatio)))` if feeRatio <= stakeRatio
|
||||
// `e^(alpha * ln(feeRatio/stakeRatio))` if feeRatio <= stakeRatio
|
||||
// or
|
||||
// `e^(ln(stakeRatio/feeRatio))` if feeRatio > stakeRatio
|
||||
// `e^(alpa * ln(stakeRatio/feeRatio))` if feeRatio > stakeRatio
|
||||
int256 n = feeRatio <= stakeRatio ?
|
||||
LibFixedMath.div(feeRatio, stakeRatio) :
|
||||
LibFixedMath.div(stakeRatio, feeRatio);
|
||||
|
@@ -162,8 +162,7 @@ contract MixinCumulativeRewards is
|
||||
internal
|
||||
{
|
||||
// Check if we should do any work
|
||||
uint256 currentMostRecentEpoch =
|
||||
_cumulativeRewardsByPoolLastStored[poolId];
|
||||
uint256 currentMostRecentEpoch = _cumulativeRewardsByPoolLastStored[poolId];
|
||||
if (epoch == currentMostRecentEpoch) {
|
||||
return;
|
||||
}
|
||||
|
@@ -81,8 +81,7 @@ contract MixinStakingPoolRewards is
|
||||
// rewards.
|
||||
IStructs.Pool memory pool = _poolById[poolId];
|
||||
// Get any unfinalized rewards.
|
||||
(uint256 unfinalizedTotalRewards, uint256 unfinalizedMembersStake) =
|
||||
_getUnfinalizedPoolRewards(poolId);
|
||||
(uint256 unfinalizedTotalRewards, uint256 unfinalizedMembersStake) = _getUnfinalizedPoolRewards(poolId);
|
||||
// Get the operators' portion.
|
||||
(reward,) = _computeSplitStakingPoolRewards(
|
||||
pool.operatorShare,
|
||||
@@ -203,21 +202,18 @@ contract MixinStakingPoolRewards is
|
||||
|
||||
// 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.
|
||||
IStructs.Fraction memory mostRecentCumulativeReward =
|
||||
_getMostRecentCumulativeReward(poolId);
|
||||
IStructs.Fraction memory mostRecentCumulativeReward = _getMostRecentCumulativeReward(poolId);
|
||||
|
||||
// Compute new cumulative reward
|
||||
IStructs.Fraction memory cumulativeReward;
|
||||
(cumulativeReward.numerator, cumulativeReward.denominator) =
|
||||
LibFractions.add(
|
||||
(cumulativeReward.numerator, cumulativeReward.denominator) = LibFractions.add(
|
||||
mostRecentCumulativeReward.numerator,
|
||||
mostRecentCumulativeReward.denominator,
|
||||
membersReward,
|
||||
membersStake
|
||||
);
|
||||
// Normalize to prevent overflows.
|
||||
(cumulativeReward.numerator, cumulativeReward.denominator) =
|
||||
LibFractions.normalize(
|
||||
(cumulativeReward.numerator, cumulativeReward.denominator) = LibFractions.normalize(
|
||||
cumulativeReward.numerator,
|
||||
cumulativeReward.denominator
|
||||
);
|
||||
@@ -404,8 +400,7 @@ contract MixinStakingPoolRewards is
|
||||
|
||||
// Get the most recent cumulative reward, which will serve as a
|
||||
// reference point when updating dependencies
|
||||
IStructs.Fraction memory mostRecentCumulativeReward =
|
||||
_getMostRecentCumulativeReward(poolId);
|
||||
IStructs.Fraction memory mostRecentCumulativeReward = _getMostRecentCumulativeReward(poolId);
|
||||
|
||||
// Record dependency on current epoch.
|
||||
if (_delegatedStakeToPoolByOwner.currentEpochBalance != 0
|
||||
|
@@ -286,8 +286,7 @@ contract MixinFinalizer is
|
||||
// Clip the reward to always be under
|
||||
// `rewardsAvailable - totalRewardsPaid`,
|
||||
// in case cobb-douglas overflows, which should be unlikely.
|
||||
uint256 rewardsRemaining =
|
||||
state.rewardsAvailable.safeSub(state.totalRewardsFinalized);
|
||||
uint256 rewardsRemaining = state.rewardsAvailable.safeSub(state.totalRewardsFinalized);
|
||||
if (rewardsRemaining < rewards) {
|
||||
rewards = rewardsRemaining;
|
||||
}
|
||||
|
@@ -82,8 +82,7 @@ contract TestDelegatorRewards is
|
||||
)
|
||||
external
|
||||
{
|
||||
unfinalizedPoolRewardsByEpoch[currentEpoch][poolId] =
|
||||
UnfinalizedPoolReward({
|
||||
unfinalizedPoolRewardsByEpoch[currentEpoch][poolId] = UnfinalizedPoolReward({
|
||||
operatorReward: operatorReward,
|
||||
membersReward: membersReward,
|
||||
membersStake: membersStake
|
||||
@@ -132,10 +131,8 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
_stake.isInitialized = true;
|
||||
_stake.currentEpochBalance += uint96(stake);
|
||||
_stake.nextEpochBalance += uint96(stake);
|
||||
@@ -159,10 +156,8 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
if (_stake.currentEpoch < currentEpoch) {
|
||||
_stake.currentEpochBalance = _stake.nextEpochBalance;
|
||||
}
|
||||
@@ -188,10 +183,8 @@ contract TestDelegatorRewards is
|
||||
external
|
||||
{
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
IStructs.StoredBalance memory initialStake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake =
|
||||
_delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance memory initialStake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
IStructs.StoredBalance storage _stake = _delegatedStakeToPoolByOwner[delegator][poolId];
|
||||
if (_stake.currentEpoch < currentEpoch) {
|
||||
_stake.currentEpochBalance = _stake.nextEpochBalance;
|
||||
}
|
||||
@@ -244,8 +237,7 @@ contract TestDelegatorRewards is
|
||||
uint256 membersStake
|
||||
)
|
||||
{
|
||||
UnfinalizedPoolReward memory reward =
|
||||
unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
|
||||
UnfinalizedPoolReward memory reward = unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
|
||||
delete unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
|
||||
|
||||
_setOperatorShare(poolId, reward.operatorReward, reward.membersReward);
|
||||
@@ -266,8 +258,7 @@ contract TestDelegatorRewards is
|
||||
uint256 membersStake
|
||||
)
|
||||
{
|
||||
UnfinalizedPoolReward storage reward =
|
||||
unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
|
||||
UnfinalizedPoolReward storage reward = unfinalizedPoolRewardsByEpoch[currentEpoch][poolId];
|
||||
totalReward = reward.operatorReward + reward.membersReward;
|
||||
membersStake = reward.membersStake;
|
||||
}
|
||||
|
@@ -77,8 +77,9 @@ contract TestFinalizer is
|
||||
external
|
||||
{
|
||||
require(feesCollected > 0, "FEES_MUST_BE_NONZERO");
|
||||
mapping (bytes32 => IStructs.ActivePool) storage activePools =
|
||||
_getActivePoolsFromEpoch(currentEpoch);
|
||||
mapping (bytes32 => IStructs.ActivePool) storage activePools = _getActivePoolsFromEpoch(
|
||||
currentEpoch
|
||||
);
|
||||
IStructs.ActivePool memory pool = activePools[poolId];
|
||||
require(pool.feesCollected == 0, "POOL_ALREADY_ADDED");
|
||||
_operatorSharesByPool[poolId] = operatorShare;
|
||||
@@ -128,8 +129,9 @@ contract TestFinalizer is
|
||||
view
|
||||
returns (UnfinalizedPoolReward memory reward)
|
||||
{
|
||||
(reward.totalReward, reward.membersStake) =
|
||||
_getUnfinalizedPoolRewards(poolId);
|
||||
(reward.totalReward, reward.membersStake) = _getUnfinalizedPoolRewards(
|
||||
poolId
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Expose `_getActivePoolFromEpoch`.
|
||||
@@ -151,8 +153,11 @@ contract TestFinalizer is
|
||||
returns (uint256 operatorReward, uint256 membersReward)
|
||||
{
|
||||
uint32 operatorShare = _operatorSharesByPool[poolId];
|
||||
(operatorReward, membersReward) =
|
||||
_computeSplitStakingPoolRewards(operatorShare, reward, membersStake);
|
||||
(operatorReward, membersReward) = _computeSplitStakingPoolRewards(
|
||||
operatorShare,
|
||||
reward,
|
||||
membersStake
|
||||
);
|
||||
address(_operatorRewardsReceiver).transfer(operatorReward);
|
||||
address(_membersRewardsReceiver).transfer(membersReward);
|
||||
emit DepositStakingPoolRewards(poolId, reward, membersStake);
|
||||
|
Reference in New Issue
Block a user