Remove vaults from variable names and comments
This commit is contained in:
@@ -69,7 +69,6 @@ contract MixinStakingPoolRewards is
|
||||
}
|
||||
|
||||
/// @dev Computes the reward balance in ETH of the operator of a pool.
|
||||
/// This does not include the balance in the ETH vault.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @return totalReward Balance in ETH.
|
||||
function computeRewardBalanceOfOperator(bytes32 poolId)
|
||||
@@ -77,7 +76,7 @@ contract MixinStakingPoolRewards is
|
||||
view
|
||||
returns (uint256 reward)
|
||||
{
|
||||
// Because operator rewards are immediately sent to the ETH vault
|
||||
// Because operator rewards are immediately withdrawn as WETH
|
||||
// on finalization, the only factor in this function are unfinalized
|
||||
// rewards.
|
||||
IStructs.Pool memory pool = _poolById[poolId];
|
||||
@@ -95,7 +94,6 @@ contract MixinStakingPoolRewards is
|
||||
}
|
||||
|
||||
/// @dev Computes the reward balance in ETH of a specific member of a pool.
|
||||
/// This does not include the balance in the ETH vault.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @param member The member of the pool.
|
||||
/// @return totalReward Balance in ETH.
|
||||
@@ -125,8 +123,7 @@ contract MixinStakingPoolRewards is
|
||||
}
|
||||
|
||||
/// @dev Syncs rewards for a delegator. This includes transferring rewards
|
||||
/// from the Reward Vault to the Eth Vault, and adding/removing
|
||||
/// dependencies on cumulative rewards.
|
||||
/// withdrawing rewards and adding/removing dependencies on cumulative rewards.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @param member of the pool.
|
||||
/// @param initialDelegatedStakeToPoolByOwner The member's delegated
|
||||
@@ -141,7 +138,7 @@ contract MixinStakingPoolRewards is
|
||||
)
|
||||
internal
|
||||
{
|
||||
// Transfer any rewards from the transient pool vault to the eth vault;
|
||||
// Withdraw any rewards from.
|
||||
// this must be done before we can modify the owner's portion of the
|
||||
// delegator pool.
|
||||
_finalizePoolAndWithdrawDelegatorRewards(
|
||||
|
||||
@@ -27,8 +27,8 @@ import "../interfaces/IStructs.sol";
|
||||
contract MixinAbstract {
|
||||
|
||||
/// @dev Instantly finalizes a single pool that was active in the previous
|
||||
/// epoch, crediting it rewards and sending those rewards to the reward
|
||||
/// and eth vault. This can be called by internal functions that need
|
||||
/// epoch, crediting it rewards for members and withdrawing operator's
|
||||
/// rewards as WETH. This can be called by internal functions that need
|
||||
/// to finalize a pool immediately. Does nothing if the pool is already
|
||||
/// finalized or was not active in the previous epoch.
|
||||
/// @param poolId The pool ID to finalize.
|
||||
|
||||
@@ -111,8 +111,8 @@ contract MixinFinalizer is
|
||||
}
|
||||
|
||||
/// @dev Instantly finalizes a single pool that was active in the previous
|
||||
/// epoch, crediting it rewards and sending those rewards to the reward
|
||||
/// and eth vault. This can be called by internal functions that need
|
||||
/// epoch, crediting it rewards for members and withdrawing operator's
|
||||
/// rewards as WETH. This can be called by internal functions that need
|
||||
/// to finalize a pool immediately. Does nothing if the pool is already
|
||||
/// finalized or was not active in the previous epoch.
|
||||
/// @param poolId The pool ID to finalize.
|
||||
|
||||
@@ -106,7 +106,7 @@ contract TestDelegatorRewards is
|
||||
|
||||
/// @dev Create and delegate stake that is active in the current epoch.
|
||||
/// Only used to test purportedly unreachable states.
|
||||
/// Also withdraws pending rewards to the eth vault.
|
||||
/// Also withdraws pending rewards.
|
||||
function delegateStakeNow(
|
||||
address delegator,
|
||||
bytes32 poolId,
|
||||
@@ -131,7 +131,7 @@ contract TestDelegatorRewards is
|
||||
|
||||
/// @dev Create and delegate stake that will occur in the next epoch
|
||||
/// (normal behavior).
|
||||
/// Also withdraws pending rewards to the eth vault.
|
||||
/// Also withdraws pending rewards.
|
||||
function delegateStake(
|
||||
address delegator,
|
||||
bytes32 poolId,
|
||||
@@ -158,7 +158,7 @@ contract TestDelegatorRewards is
|
||||
|
||||
/// @dev Clear stake that will occur in the next epoch
|
||||
/// (normal behavior).
|
||||
/// Also withdraws pending rewards to the eth vault.
|
||||
/// Also withdraws pending rewards.
|
||||
function undelegateStake(
|
||||
address delegator,
|
||||
bytes32 poolId,
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
OperatorBalanceByPoolId,
|
||||
OperatorByPoolId,
|
||||
OperatorShareByPoolId,
|
||||
RewardBalanceByPoolId,
|
||||
RewardByPoolId,
|
||||
RewardVaultBalanceByPoolId,
|
||||
} from '../utils/types';
|
||||
|
||||
import { BaseActor } from './base_actor';
|
||||
@@ -40,7 +40,7 @@ export class FinalizerActor extends BaseActor {
|
||||
public async finalizeAsync(): Promise<void> {
|
||||
// cache initial info and balances
|
||||
const operatorShareByPoolId = await this._getOperatorShareByPoolIdAsync(this._poolIds);
|
||||
const rewardVaultBalanceByPoolId = await this._getRewardVaultBalanceByPoolIdAsync(this._poolIds);
|
||||
const rewardBalanceByPoolId = await this._getRewardBalanceByPoolIdAsync(this._poolIds);
|
||||
const delegatorBalancesByPoolId = await this._getDelegatorBalancesByPoolIdAsync(this._delegatorsByPoolId);
|
||||
const delegatorStakesByPoolId = await this._getDelegatorStakesByPoolIdAsync(this._delegatorsByPoolId);
|
||||
const operatorBalanceByPoolId = await this._getOperatorBalanceByPoolIdAsync(this._operatorByPoolId);
|
||||
@@ -48,11 +48,11 @@ export class FinalizerActor extends BaseActor {
|
||||
// compute expected changes
|
||||
const [
|
||||
expectedOperatorBalanceByPoolId,
|
||||
expectedRewardVaultBalanceByPoolId,
|
||||
] = this._computeExpectedRewardVaultBalanceAsyncByPoolId(
|
||||
expectedRewardBalanceByPoolId,
|
||||
] = this._computeExpectedRewardBalanceByPoolId(
|
||||
rewardByPoolId,
|
||||
operatorBalanceByPoolId,
|
||||
rewardVaultBalanceByPoolId,
|
||||
rewardBalanceByPoolId,
|
||||
delegatorStakesByPoolId,
|
||||
operatorShareByPoolId,
|
||||
);
|
||||
@@ -65,19 +65,19 @@ export class FinalizerActor extends BaseActor {
|
||||
);
|
||||
// finalize
|
||||
await this._stakingApiWrapper.utils.skipToNextEpochAndFinalizeAsync();
|
||||
// assert reward vault changes
|
||||
const finalRewardVaultBalanceByPoolId = await this._getRewardVaultBalanceByPoolIdAsync(this._poolIds);
|
||||
expect(finalRewardVaultBalanceByPoolId, 'final pool balances in reward vault').to.be.deep.equal(
|
||||
expectedRewardVaultBalanceByPoolId,
|
||||
// assert reward changes
|
||||
const finalRewardBalanceByPoolId = await this._getRewardBalanceByPoolIdAsync(this._poolIds);
|
||||
expect(finalRewardBalanceByPoolId, 'final pool reward balances').to.be.deep.equal(
|
||||
expectedRewardBalanceByPoolId,
|
||||
);
|
||||
// assert delegator balances
|
||||
const finalDelegatorBalancesByPoolId = await this._getDelegatorBalancesByPoolIdAsync(this._delegatorsByPoolId);
|
||||
expect(finalDelegatorBalancesByPoolId, 'final delegator balances in reward vault').to.be.deep.equal(
|
||||
expect(finalDelegatorBalancesByPoolId, 'final delegator reward balances').to.be.deep.equal(
|
||||
expectedDelegatorBalancesByPoolId,
|
||||
);
|
||||
// assert operator balances
|
||||
const finalOperatorBalanceByPoolId = await this._getOperatorBalanceByPoolIdAsync(this._operatorByPoolId);
|
||||
expect(finalOperatorBalanceByPoolId, 'final operator balances in eth vault').to.be.deep.equal(
|
||||
expect(finalOperatorBalanceByPoolId, 'final operator weth balance').to.be.deep.equal(
|
||||
expectedOperatorBalanceByPoolId,
|
||||
);
|
||||
}
|
||||
@@ -159,37 +159,37 @@ export class FinalizerActor extends BaseActor {
|
||||
return delegatorBalancesByPoolId;
|
||||
}
|
||||
|
||||
private _computeExpectedRewardVaultBalanceAsyncByPoolId(
|
||||
private _computeExpectedRewardBalanceByPoolId(
|
||||
rewardByPoolId: RewardByPoolId,
|
||||
operatorBalanceByPoolId: OperatorBalanceByPoolId,
|
||||
rewardVaultBalanceByPoolId: RewardVaultBalanceByPoolId,
|
||||
rewardBalanceByPoolId: RewardBalanceByPoolId,
|
||||
delegatorStakesByPoolId: DelegatorBalancesByPoolId,
|
||||
operatorShareByPoolId: OperatorShareByPoolId,
|
||||
): [RewardVaultBalanceByPoolId, OperatorBalanceByPoolId] {
|
||||
): [RewardBalanceByPoolId, OperatorBalanceByPoolId] {
|
||||
const expectedOperatorBalanceByPoolId = _.cloneDeep(operatorBalanceByPoolId);
|
||||
const expectedRewardVaultBalanceByPoolId = _.cloneDeep(rewardVaultBalanceByPoolId);
|
||||
const expectedRewardBalanceByPoolId = _.cloneDeep(rewardBalanceByPoolId);
|
||||
for (const poolId of Object.keys(rewardByPoolId)) {
|
||||
const operatorShare = operatorShareByPoolId[poolId];
|
||||
[
|
||||
expectedOperatorBalanceByPoolId[poolId],
|
||||
expectedRewardVaultBalanceByPoolId[poolId],
|
||||
] = this._computeExpectedRewardVaultBalance(
|
||||
expectedRewardBalanceByPoolId[poolId],
|
||||
] = this._computeExpectedRewardBalance(
|
||||
poolId,
|
||||
rewardByPoolId[poolId],
|
||||
expectedOperatorBalanceByPoolId[poolId],
|
||||
expectedRewardVaultBalanceByPoolId[poolId],
|
||||
expectedRewardBalanceByPoolId[poolId],
|
||||
delegatorStakesByPoolId[poolId],
|
||||
operatorShare,
|
||||
);
|
||||
}
|
||||
return [expectedOperatorBalanceByPoolId, expectedRewardVaultBalanceByPoolId];
|
||||
return [expectedOperatorBalanceByPoolId, expectedRewardBalanceByPoolId];
|
||||
}
|
||||
|
||||
private _computeExpectedRewardVaultBalance(
|
||||
private _computeExpectedRewardBalance(
|
||||
poolId: string,
|
||||
reward: BigNumber,
|
||||
operatorBalance: BigNumber,
|
||||
rewardVaultBalance: BigNumber,
|
||||
rewardBalance: BigNumber,
|
||||
stakeBalances: BalanceByOwner,
|
||||
operatorShare: BigNumber,
|
||||
): [BigNumber, BigNumber] {
|
||||
@@ -200,7 +200,7 @@ export class FinalizerActor extends BaseActor {
|
||||
? reward
|
||||
: reward.times(operatorShare).dividedToIntegerBy(PPM_100_PERCENT);
|
||||
const membersPortion = reward.minus(operatorPortion);
|
||||
return [operatorBalance.plus(operatorPortion), rewardVaultBalance.plus(membersPortion)];
|
||||
return [operatorBalance.plus(operatorPortion), rewardBalance.plus(membersPortion)];
|
||||
}
|
||||
|
||||
private async _getOperatorBalanceByPoolIdAsync(
|
||||
@@ -225,14 +225,14 @@ export class FinalizerActor extends BaseActor {
|
||||
return operatorShareByPoolId;
|
||||
}
|
||||
|
||||
private async _getRewardVaultBalanceByPoolIdAsync(poolIds: string[]): Promise<RewardVaultBalanceByPoolId> {
|
||||
const rewardVaultBalanceByPoolId: RewardVaultBalanceByPoolId = {};
|
||||
private async _getRewardBalanceByPoolIdAsync(poolIds: string[]): Promise<RewardBalanceByPoolId> {
|
||||
const rewardBalanceByPoolId: RewardBalanceByPoolId = {};
|
||||
for (const poolId of poolIds) {
|
||||
rewardVaultBalanceByPoolId[
|
||||
poolId
|
||||
] = await this._stakingApiWrapper.stakingContract.rewardsByPoolId.callAsync(poolId);
|
||||
rewardBalanceByPoolId[poolId] = await this._stakingApiWrapper.stakingContract.rewardsByPoolId.callAsync(
|
||||
poolId,
|
||||
);
|
||||
}
|
||||
return rewardVaultBalanceByPoolId;
|
||||
return rewardBalanceByPoolId;
|
||||
}
|
||||
|
||||
private async _getRewardByPoolIdAsync(poolIds: string[]): Promise<RewardByPoolId> {
|
||||
|
||||
@@ -344,7 +344,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
membersRewardBalance: rewardForOnlyFirstDelegator.plus(totalSharedRewards),
|
||||
});
|
||||
});
|
||||
it('Should send existing rewards from reward vault to eth vault correctly when undelegating stake', async () => {
|
||||
it('Should withdraw existing rewards when undelegating stake', async () => {
|
||||
const stakeAmount = toBaseUnitAmount(4);
|
||||
// first staker delegates (epoch 0)
|
||||
await stakers[0].stakeWithPoolAsync(poolId, stakeAmount);
|
||||
@@ -353,7 +353,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
// earn reward
|
||||
const reward = toBaseUnitAmount(10);
|
||||
await payProtocolFeeAndFinalize(reward);
|
||||
// undelegate (moves delegator's from the transient reward vault into the eth vault)
|
||||
// undelegate (withdraws delegator's rewards)
|
||||
await stakers[0].moveStakeAsync(
|
||||
new StakeInfo(StakeStatus.Delegated, poolId),
|
||||
new StakeInfo(StakeStatus.Active),
|
||||
@@ -365,7 +365,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
stakerWethBalance_1: reward,
|
||||
});
|
||||
});
|
||||
it('Should send existing rewards from reward vault to eth vault correctly when delegating more stake', async () => {
|
||||
it('Should withdraw existing rewards correctly when delegating more stake', async () => {
|
||||
const stakeAmount = toBaseUnitAmount(4);
|
||||
// first staker delegates (epoch 0)
|
||||
await stakers[0].stakeWithPoolAsync(poolId, stakeAmount);
|
||||
@@ -560,7 +560,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
poolRewardBalance: constants.ZERO_AMOUNT,
|
||||
});
|
||||
});
|
||||
it('Should withdraw delegator rewards to eth vault when calling `syncDelegatorRewards`', async () => {
|
||||
it('Should withdraw delegator rewards when calling `withdrawDelegatorRewards`', async () => {
|
||||
// first staker delegates (epoch 0)
|
||||
const rewardForDelegator = toBaseUnitAmount(10);
|
||||
const stakeAmount = toBaseUnitAmount(4);
|
||||
@@ -602,7 +602,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
// finalize
|
||||
const reward = toBaseUnitAmount(10);
|
||||
await payProtocolFeeAndFinalize(reward);
|
||||
// Sync rewards to move the rewards into the EthVault.
|
||||
// withdraw rewards
|
||||
await staker.withdrawDelegatorRewardsAsync(poolId);
|
||||
await validateEndBalances({
|
||||
stakerRewardBalance_1: toBaseUnitAmount(0),
|
||||
@@ -622,7 +622,7 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
// finalize
|
||||
const reward = toBaseUnitAmount(10);
|
||||
await payProtocolFeeAndFinalize(reward);
|
||||
// Sync rewards to move rewards from RewardVault into the EthVault.
|
||||
// withdraw rewards
|
||||
for (const [staker] of _.reverse(stakersAndStake)) {
|
||||
await staker.withdrawDelegatorRewardsAsync(poolId);
|
||||
}
|
||||
@@ -658,25 +658,23 @@ blockchainTests.resets('Testing Rewards', env => {
|
||||
poolRewardBalance: reward,
|
||||
membersRewardBalance: reward,
|
||||
});
|
||||
// First staker will sync rewards to get rewards transferred to EthVault.
|
||||
// First staker will withdraw rewards.
|
||||
const sneakyStaker = stakers[0];
|
||||
const sneakyStakerExpectedEthVaultBalance = expectedStakerRewards[0];
|
||||
const sneakyStakerExpectedWethBalance = expectedStakerRewards[0];
|
||||
await sneakyStaker.withdrawDelegatorRewardsAsync(poolId);
|
||||
// Should have been credited the correct amount of rewards.
|
||||
let sneakyStakerEthVaultBalance = await stakingApiWrapper.wethContract.balanceOf.callAsync(
|
||||
let sneakyStakerWethBalance = await stakingApiWrapper.wethContract.balanceOf.callAsync(
|
||||
sneakyStaker.getOwner(),
|
||||
);
|
||||
expect(sneakyStakerEthVaultBalance, 'EthVault balance after first undelegate').to.bignumber.eq(
|
||||
sneakyStakerExpectedEthVaultBalance,
|
||||
expect(sneakyStakerWethBalance, 'WETH balance after first undelegate').to.bignumber.eq(
|
||||
sneakyStakerExpectedWethBalance,
|
||||
);
|
||||
// Now he'll try to do it again to see if he gets credited twice.
|
||||
await sneakyStaker.withdrawDelegatorRewardsAsync(poolId);
|
||||
/// The total amount credited should remain the same.
|
||||
sneakyStakerEthVaultBalance = await stakingApiWrapper.wethContract.balanceOf.callAsync(
|
||||
sneakyStaker.getOwner(),
|
||||
);
|
||||
expect(sneakyStakerEthVaultBalance, 'EthVault balance after second undelegate').to.bignumber.eq(
|
||||
sneakyStakerExpectedEthVaultBalance,
|
||||
sneakyStakerWethBalance = await stakingApiWrapper.wethContract.balanceOf.callAsync(sneakyStaker.getOwner());
|
||||
expect(sneakyStakerWethBalance, 'WETH balance after second undelegate').to.bignumber.eq(
|
||||
sneakyStakerExpectedWethBalance,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ export interface StakeBalances {
|
||||
totalDelegatedStakeByPool: StakeBalanceByPool;
|
||||
}
|
||||
|
||||
export interface RewardVaultBalanceByPoolId {
|
||||
export interface RewardBalanceByPoolId {
|
||||
[key: string]: BigNumber;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user