Rename variables and functions
This commit is contained in:
@@ -97,6 +97,7 @@ contract MixinExchangeFees is
|
||||
uint256 currentEpoch_ = currentEpoch;
|
||||
mapping (bytes32 => IStructs.ActivePool) storage activePoolsThisEpoch =
|
||||
_getActivePoolsFromEpoch(currentEpoch_);
|
||||
|
||||
IStructs.ActivePool memory pool = activePoolsThisEpoch[poolId];
|
||||
|
||||
// If the pool was previously inactive in this epoch, initialize it.
|
||||
|
||||
@@ -50,23 +50,23 @@ contract MixinStorage is
|
||||
mapping (uint8 => IStructs.StoredBalance) public globalStakeByStatus;
|
||||
|
||||
// mapping from Owner to Amount of Active Stake
|
||||
// (access using _loadAndSyncBalance or _loadUnsyncedBalance)
|
||||
// (access using _loadSyncedBalance or _loadUnsyncedBalance)
|
||||
mapping (address => IStructs.StoredBalance) internal _activeStakeByOwner;
|
||||
|
||||
// Mapping from Owner to Amount of Inactive Stake
|
||||
// (access using _loadAndSyncBalance or _loadUnsyncedBalance)
|
||||
// (access using _loadSyncedBalance or _loadUnsyncedBalance)
|
||||
mapping (address => IStructs.StoredBalance) internal _inactiveStakeByOwner;
|
||||
|
||||
// Mapping from Owner to Amount Delegated
|
||||
// (access using _loadAndSyncBalance or _loadUnsyncedBalance)
|
||||
// (access using _loadSyncedBalance or _loadUnsyncedBalance)
|
||||
mapping (address => IStructs.StoredBalance) internal _delegatedStakeByOwner;
|
||||
|
||||
// Mapping from Owner to Pool Id to Amount Delegated
|
||||
// (access using _loadAndSyncBalance or _loadUnsyncedBalance)
|
||||
// (access using _loadSyncedBalance or _loadUnsyncedBalance)
|
||||
mapping (address => mapping (bytes32 => IStructs.StoredBalance)) internal _delegatedStakeToPoolByOwner;
|
||||
|
||||
// Mapping from Pool Id to Amount Delegated
|
||||
// (access using _loadAndSyncBalance or _loadUnsyncedBalance)
|
||||
// (access using _loadSyncedBalance or _loadUnsyncedBalance)
|
||||
mapping (bytes32 => IStructs.StoredBalance) internal _delegatedStakeByPoolId;
|
||||
|
||||
// mapping from Owner to Amount of Withdrawable Stake
|
||||
|
||||
@@ -52,7 +52,7 @@ interface IStructs {
|
||||
/// @dev Encapsulates a balance for the current and next epochs.
|
||||
/// Note that these balances may be stale if the current epoch
|
||||
/// is greater than `currentEpoch`.
|
||||
/// Always load this struct using _loadAndSyncBalance or _loadUnsyncedBalance.
|
||||
/// Always load this struct using _loadSyncedBalance or _loadUnsyncedBalance.
|
||||
/// @param isInitialized
|
||||
/// @param currentEpoch the current epoch
|
||||
/// @param currentEpochBalance balance in the current epoch.
|
||||
|
||||
@@ -216,7 +216,7 @@ contract MixinStake is
|
||||
// Synchronizes reward state in the pool that the staker is delegating
|
||||
// to.
|
||||
IStructs.StoredBalance memory finalDelegatedStakeToPoolByOwner =
|
||||
_loadAndSyncBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
owner,
|
||||
@@ -255,7 +255,7 @@ contract MixinStake is
|
||||
// synchronizes reward state in the pool that the staker is undelegating
|
||||
// from
|
||||
IStructs.StoredBalance memory finalDelegatedStakeToPoolByOwner =
|
||||
_loadAndSyncBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
owner,
|
||||
|
||||
@@ -43,7 +43,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(
|
||||
globalStakeByStatus[uint8(IStructs.StakeStatus.ACTIVE)]
|
||||
);
|
||||
return IStructs.StakeBalance({
|
||||
@@ -59,7 +59,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(
|
||||
globalStakeByStatus[uint8(IStructs.StakeStatus.INACTIVE)]
|
||||
);
|
||||
return IStructs.StakeBalance({
|
||||
@@ -75,7 +75,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(
|
||||
globalStakeByStatus[uint8(IStructs.StakeStatus.DELEGATED)]
|
||||
);
|
||||
return IStructs.StakeBalance({
|
||||
@@ -103,7 +103,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(_activeStakeByOwner[owner]);
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(_activeStakeByOwner[owner]);
|
||||
return IStructs.StakeBalance({
|
||||
currentEpochBalance: storedBalance.currentEpochBalance,
|
||||
nextEpochBalance: storedBalance.nextEpochBalance
|
||||
@@ -118,7 +118,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(_inactiveStakeByOwner[owner]);
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(_inactiveStakeByOwner[owner]);
|
||||
return IStructs.StakeBalance({
|
||||
currentEpochBalance: storedBalance.currentEpochBalance,
|
||||
nextEpochBalance: storedBalance.nextEpochBalance
|
||||
@@ -133,7 +133,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(_delegatedStakeByOwner[owner]);
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(_delegatedStakeByOwner[owner]);
|
||||
return IStructs.StakeBalance({
|
||||
currentEpochBalance: storedBalance.currentEpochBalance,
|
||||
nextEpochBalance: storedBalance.nextEpochBalance
|
||||
@@ -160,7 +160,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(_delegatedStakeToPoolByOwner[owner][poolId]);
|
||||
return IStructs.StakeBalance({
|
||||
currentEpochBalance: storedBalance.currentEpochBalance,
|
||||
nextEpochBalance: storedBalance.nextEpochBalance
|
||||
@@ -176,7 +176,7 @@ contract MixinStakeBalances is
|
||||
view
|
||||
returns (IStructs.StakeBalance memory balance)
|
||||
{
|
||||
IStructs.StoredBalance memory storedBalance = _loadAndSyncBalance(_delegatedStakeByPoolId[poolId]);
|
||||
IStructs.StoredBalance memory storedBalance = _loadSyncedBalance(_delegatedStakeByPoolId[poolId]);
|
||||
return IStructs.StakeBalance({
|
||||
currentEpochBalance: storedBalance.currentEpochBalance,
|
||||
nextEpochBalance: storedBalance.nextEpochBalance
|
||||
|
||||
@@ -53,8 +53,8 @@ contract MixinStakeStorage is
|
||||
}
|
||||
|
||||
// load balance from storage and synchronize it
|
||||
IStructs.StoredBalance memory from = _loadAndSyncBalance(fromPtr);
|
||||
IStructs.StoredBalance memory to = _loadAndSyncBalance(toPtr);
|
||||
IStructs.StoredBalance memory from = _loadSyncedBalance(fromPtr);
|
||||
IStructs.StoredBalance memory to = _loadSyncedBalance(toPtr);
|
||||
|
||||
// sanity check on balance
|
||||
if (amount > from.nextEpochBalance) {
|
||||
@@ -81,7 +81,7 @@ contract MixinStakeStorage is
|
||||
/// was stored.
|
||||
/// @param balancePtr to load and sync.
|
||||
/// @return synchronized balance.
|
||||
function _loadAndSyncBalance(IStructs.StoredBalance storage balancePtr)
|
||||
function _loadSyncedBalance(IStructs.StoredBalance storage balancePtr)
|
||||
internal
|
||||
view
|
||||
returns (IStructs.StoredBalance memory balance)
|
||||
@@ -119,7 +119,7 @@ contract MixinStakeStorage is
|
||||
internal
|
||||
{
|
||||
// Remove stake from balance
|
||||
IStructs.StoredBalance memory balance = _loadAndSyncBalance(balancePtr);
|
||||
IStructs.StoredBalance memory balance = _loadSyncedBalance(balancePtr);
|
||||
balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeAdd(amount).downcastToUint96();
|
||||
balance.currentEpochBalance = uint256(balance.currentEpochBalance).safeAdd(amount).downcastToUint96();
|
||||
|
||||
@@ -134,7 +134,7 @@ contract MixinStakeStorage is
|
||||
internal
|
||||
{
|
||||
// Remove stake from balance
|
||||
IStructs.StoredBalance memory balance = _loadAndSyncBalance(balancePtr);
|
||||
IStructs.StoredBalance memory balance = _loadSyncedBalance(balancePtr);
|
||||
balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeSub(amount).downcastToUint96();
|
||||
balance.currentEpochBalance = uint256(balance.currentEpochBalance).safeSub(amount).downcastToUint96();
|
||||
|
||||
@@ -149,7 +149,7 @@ contract MixinStakeStorage is
|
||||
internal
|
||||
{
|
||||
// Add stake to balance
|
||||
IStructs.StoredBalance memory balance = _loadAndSyncBalance(balancePtr);
|
||||
IStructs.StoredBalance memory balance = _loadSyncedBalance(balancePtr);
|
||||
balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeAdd(amount).downcastToUint96();
|
||||
|
||||
// update state
|
||||
@@ -163,7 +163,7 @@ contract MixinStakeStorage is
|
||||
internal
|
||||
{
|
||||
// Remove stake from balance
|
||||
IStructs.StoredBalance memory balance = _loadAndSyncBalance(balancePtr);
|
||||
IStructs.StoredBalance memory balance = _loadSyncedBalance(balancePtr);
|
||||
balance.nextEpochBalance = uint256(balance.nextEpochBalance).safeSub(amount).downcastToUint96();
|
||||
|
||||
// update state
|
||||
|
||||
@@ -52,7 +52,7 @@ contract MixinStakingPoolRewards is
|
||||
address member = msg.sender;
|
||||
|
||||
IStructs.StoredBalance memory finalDelegatedStakeToPoolByOwner =
|
||||
_loadAndSyncBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
_loadSyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]);
|
||||
|
||||
_withdrawAndSyncDelegatorRewards(
|
||||
poolId,
|
||||
@@ -86,7 +86,7 @@ contract MixinStakingPoolRewards is
|
||||
_getUnfinalizedPoolRewards(poolId);
|
||||
|
||||
// Get the operators' portion.
|
||||
(reward,) = _computeSplitStakingPoolRewards(
|
||||
(reward,) = _computePoolRewardsSplit(
|
||||
pool.operatorShare,
|
||||
unfinalizedTotalRewards,
|
||||
unfinalizedMembersStake
|
||||
@@ -110,12 +110,12 @@ contract MixinStakingPoolRewards is
|
||||
_getUnfinalizedPoolRewards(poolId);
|
||||
|
||||
// Get the members' portion.
|
||||
(, uint256 unfinalizedMembersReward) = _computeSplitStakingPoolRewards(
|
||||
(, uint256 unfinalizedMembersReward) = _computePoolRewardsSplit(
|
||||
pool.operatorShare,
|
||||
unfinalizedTotalRewards,
|
||||
unfinalizedMembersStake
|
||||
);
|
||||
return _computeRewardBalanceOfDelegator(
|
||||
return _computeDelegatorReward(
|
||||
poolId,
|
||||
_loadUnsyncedBalance(_delegatedStakeToPoolByOwner[member][poolId]),
|
||||
currentEpoch,
|
||||
@@ -179,7 +179,7 @@ contract MixinStakingPoolRewards is
|
||||
/// will split the reward.
|
||||
/// @return operatorReward Portion of `reward` given to the pool operator.
|
||||
/// @return membersReward Portion of `reward` given to the pool members.
|
||||
function _depositStakingPoolRewards(
|
||||
function _syncPoolRewards(
|
||||
bytes32 poolId,
|
||||
uint256 reward,
|
||||
uint256 membersStake
|
||||
@@ -190,7 +190,7 @@ contract MixinStakingPoolRewards is
|
||||
IStructs.Pool memory pool = _poolById[poolId];
|
||||
|
||||
// Split the reward between operator and members
|
||||
(operatorReward, membersReward) = _computeSplitStakingPoolRewards(
|
||||
(operatorReward, membersReward) = _computePoolRewardsSplit(
|
||||
pool.operatorShare,
|
||||
reward,
|
||||
membersStake
|
||||
@@ -241,7 +241,7 @@ contract MixinStakingPoolRewards is
|
||||
/// to the pool in the epoch the rewards were earned.
|
||||
/// @return operatorReward Portion of `totalReward` given to the pool operator.
|
||||
/// @return membersReward Portion of `totalReward` given to the pool members.
|
||||
function _computeSplitStakingPoolRewards(
|
||||
function _computePoolRewardsSplit(
|
||||
uint32 operatorShare,
|
||||
uint256 totalReward,
|
||||
uint256 membersStake
|
||||
@@ -280,7 +280,7 @@ contract MixinStakingPoolRewards is
|
||||
finalizePool(poolId);
|
||||
|
||||
// Compute balance owed to delegator
|
||||
uint256 balance = _computeRewardBalanceOfDelegator(
|
||||
uint256 balance = _computeDelegatorReward(
|
||||
poolId,
|
||||
unsyncedStake,
|
||||
currentEpoch,
|
||||
@@ -308,7 +308,7 @@ contract MixinStakingPoolRewards is
|
||||
/// (if any).
|
||||
/// @param unfinalizedMembersStake Unfinalized total members stake (if any).
|
||||
/// @return totalReward Balance in ETH.
|
||||
function _computeRewardBalanceOfDelegator(
|
||||
function _computeDelegatorReward(
|
||||
bytes32 poolId,
|
||||
IStructs.StoredBalance memory unsyncedStake,
|
||||
uint256 currentEpoch,
|
||||
|
||||
@@ -77,7 +77,7 @@ contract MixinFinalizer is
|
||||
}
|
||||
|
||||
// Set up unfinalized state.
|
||||
state.rewardsAvailable = _wrapBalanceToWETHAndGetBalance();
|
||||
state.rewardsAvailable = _wrapEthAndGetWethBalance();
|
||||
state.poolsRemaining = poolsRemaining = numActivePoolsThisEpoch;
|
||||
state.totalFeesCollected = totalFeesCollectedThisEpoch;
|
||||
state.totalWeightedStake = totalWeightedStakeThisEpoch;
|
||||
@@ -239,17 +239,17 @@ contract MixinFinalizer is
|
||||
/// @dev Converts the entire ETH balance of the contract into WETH and
|
||||
/// returns the total WETH balance of this contract.
|
||||
/// @return The WETH balance of this contract.
|
||||
function _wrapBalanceToWETHAndGetBalance()
|
||||
function _wrapEthAndGetWethBalance()
|
||||
internal
|
||||
returns (uint256 balance)
|
||||
returns (uint256 wethBalance)
|
||||
{
|
||||
IEtherToken wethContract = _getWethContract();
|
||||
uint256 ethBalance = address(this).balance;
|
||||
if (ethBalance != 0) {
|
||||
wethContract.deposit.value(ethBalance)();
|
||||
}
|
||||
balance = wethContract.balanceOf(address(this));
|
||||
return balance;
|
||||
wethBalance = wethContract.balanceOf(address(this));
|
||||
return wethBalance;
|
||||
}
|
||||
|
||||
/// @dev Computes the reward owed to a pool during finalization.
|
||||
@@ -317,7 +317,7 @@ contract MixinFinalizer is
|
||||
// Pay the pool.
|
||||
// Note that we credit at the CURRENT epoch even though these rewards
|
||||
// were earned in the previous epoch.
|
||||
(operatorReward, membersReward) = _depositStakingPoolRewards(
|
||||
(operatorReward, membersReward) = _syncPoolRewards(
|
||||
poolId,
|
||||
rewards,
|
||||
pool.membersStake
|
||||
|
||||
@@ -85,8 +85,8 @@ contract TestDelegatorRewards is
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
}
|
||||
|
||||
/// @dev Expose/wrap `_depositStakingPoolRewards`.
|
||||
function depositStakingPoolRewards(
|
||||
/// @dev Expose/wrap `_syncPoolRewards`.
|
||||
function syncPoolRewards(
|
||||
bytes32 poolId,
|
||||
address payable operatorAddress,
|
||||
uint256 operatorReward,
|
||||
@@ -100,7 +100,7 @@ contract TestDelegatorRewards is
|
||||
_setOperatorShare(poolId, operatorReward, membersReward);
|
||||
_initGenesisCumulativeRewards(poolId);
|
||||
|
||||
_depositStakingPoolRewards(
|
||||
_syncPoolRewards(
|
||||
poolId,
|
||||
operatorReward + membersReward,
|
||||
membersStake
|
||||
@@ -210,7 +210,7 @@ contract TestDelegatorRewards is
|
||||
uint256 totalRewards = reward.operatorReward + reward.membersReward;
|
||||
membersStake = reward.membersStake;
|
||||
(operatorReward, membersReward) =
|
||||
_depositStakingPoolRewards(poolId, totalRewards, membersStake);
|
||||
_syncPoolRewards(poolId, totalRewards, membersStake);
|
||||
emit FinalizePool(poolId, operatorReward, membersReward, membersStake);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ contract TestFinalizer is
|
||||
}
|
||||
|
||||
/// @dev Overridden to log and transfer to receivers.
|
||||
function _depositStakingPoolRewards(
|
||||
function _syncPoolRewards(
|
||||
bytes32 poolId,
|
||||
uint256 reward,
|
||||
uint256 membersStake
|
||||
@@ -151,7 +151,7 @@ contract TestFinalizer is
|
||||
returns (uint256 operatorReward, uint256 membersReward)
|
||||
{
|
||||
uint32 operatorShare = _operatorSharesByPool[poolId];
|
||||
(operatorReward, membersReward) = _computeSplitStakingPoolRewards(
|
||||
(operatorReward, membersReward) = _computePoolRewardsSplit(
|
||||
operatorShare,
|
||||
reward,
|
||||
membersStake
|
||||
|
||||
@@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2;
|
||||
import "../src/Staking.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
|
||||
|
||||
|
||||
contract TestStaking is
|
||||
Staking
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ import "../src/Staking.sol";
|
||||
contract TestStakingNoWETH is
|
||||
Staking
|
||||
{
|
||||
function _wrapBalanceToWETHAndGetBalance()
|
||||
function _wrapEthAndGetWethBalance()
|
||||
internal
|
||||
returns (uint256 balance)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user