Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Delete StakingPoolRewardVault and EthVault #2186

Merged
merged 13 commits into from
Sep 24, 2019
Merged

Conversation

abandeali1
Copy link
Member

@abandeali1 abandeali1 commented Sep 22, 2019

Description

  • Removes StakingPoolRewardVault. These balances are now tracked internally in the StakingProxy state.
  • Removes EthVault. Deposits to the EthVault have been completely replaced with WETH withdrawals directly to the user's account.
  • Renames a bunch of functions.
  • Removes storage layout tests (these assertions will be added back in the actual staking contracts in a separate PR).

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@coveralls
Copy link

coveralls commented Sep 22, 2019

Coverage Status

Coverage remained the same at 75.804% when pulling abb2b46 on feat/3.0/delete-vaults into 2d77fce on 3.0.

@abandeali1 abandeali1 changed the title Delete both vaults Delete StakingPoolRewardVault and EthVault Sep 23, 2019
@abandeali1 abandeali1 marked this pull request as ready for review September 23, 2019 21:45
@abandeali1 abandeali1 changed the base branch from feat/staking/hurts-like-a-mbf to 3.0 September 23, 2019 23:04
Copy link
Contributor

@hysz hysz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic! Dropped a few nits but then g2g!

/// @dev Returns the total balance of this contract, including WETH,
/// minus any WETH that has been reserved for rewards.
/// @return totalBalance Total balance.
function getAvailableBalance()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - could we disambiguate this from other balances (like, stake)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this to getAvailableRewardsBalance 👍

@@ -84,6 +82,9 @@ contract MixinStorage is
// mapping from Pool Id to Pool
mapping (bytes32 => IStructs.Pool) internal _poolById;

// mapping from PoolId to balance of members
mapping (bytes32 => uint256) public balanceByPoolId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also disambiguate this from other balances? Is this the weth balance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wethRewardsByPoolId?

@@ -151,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - we may be able to communicate what this is reserved for in the name, like _wethReservedForPools or something.

@@ -1,70 +0,0 @@
/*

Copyright 2019 ZeroEx Intl.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP

@@ -1,73 +0,0 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP^2


import { artifacts, TestStorageLayoutContract } from '../src';

blockchainTests.resets('Storage layout tests', env => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this superseded by a similar test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note- spoke offline, this will be handled by #2186

// Transfer to EthVault.
ethVault.depositFor(member, balance);
// Decrement the balance of the pool
balanceByPoolId[poolId] = balanceByPoolId[poolId].safeSub(balance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like balanceByPoolId and reservedWethBalance must always move together.

A pattern we've used in similar scenarios is to encapsulate this behavior in a single function, then document in MixinStorage that these variables should be modified via the functions opposed to directly.

Copy link
Contributor

@hysz hysz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! https://merge.it (~‾▿‾)~

Copy link
Contributor

@moodlezoup moodlezoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice rips, just a few nits and g2g!

expect(actual[7]).to.eq(_params.ethVaultAddress);
expect(actual[8]).to.eq(_params.rewardVaultAddress);
expect(actual[9]).to.eq(_params.zrxVaultAddress);
expect(actual[7]).to.eq(_params.zrxVaultAddress);
Copy link
Contributor

@moodlezoup moodlezoup Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, we should consider using this pattern so that we can use .deep.equal

@@ -84,6 +82,9 @@ contract MixinStorage is
// mapping from Pool Id to Pool
mapping (bytes32 => IStructs.Pool) internal _poolById;

// mapping from PoolId to balance of members
mapping (bytes32 => uint256) public rewardsByPoolId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not lump this into _poolById?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would bump _poolById to 2 words, which means we would pay for an extra sload whenever we access it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this isn't always the case. @hysz has some examples that show solidity will only load the fields that are used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I don't see a ton of benefit of doing this 🤷‍♂

@@ -159,21 +159,21 @@ export class FinalizerActor extends BaseActor {
return delegatorBalancesByPoolId;
}

private async _computeExpectedRewardVaultBalanceAsyncByPoolIdAsync(
private _computeExpectedRewardVaultBalanceAsyncByPoolId(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _computeExpectedRewardVaultBalanceAsyncByPoolId(
private _computeExpectedRewardVaultBalanceByPoolId(

expect(params[7]).to.eq(ethVaultAddress);
expect(params[8]).to.eq(rewardVaultAddress);
expect(params[9]).to.eq(zrxVaultAddress);
expect(params[7]).to.eq(zrxVaultAddress);
Copy link
Contributor

@moodlezoup moodlezoup Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, we should consider using this pattern so that we can use .deep.equal

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave these for now because of some quirks with some params being numbers/BigNumbers (the event types won't match whatever wrapper we write), and we're not doing this too frequently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @mzhu25 is on to something. I added it to the backlog.

@abandeali1 abandeali1 merged commit 2587cd3 into 3.0 Sep 24, 2019
Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEIWING ANYWAYYY

/// @dev Returns the total balance of this contract, including WETH,
/// minus any WETH that has been reserved for rewards.
/// @return totalBalance Total balance.
function getAvailableRewardsBalance()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interest of saving codesize, should we remove this function? It wouldn't be difficult to figure this out off-chain if we made _wethReservedForRewards public.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having getters for things that use multiple storage slots, since we can reduce the number of RPC calls we need to make.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we have devutils for staking?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright you got me, removed it in #2190 😎

function _getWethContract()
internal
view
returns (IEtherToken wethContract)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

@@ -84,6 +82,9 @@ contract MixinStorage is
// mapping from Pool Id to Pool
mapping (bytes32 => IStructs.Pool) internal _poolById;

// mapping from PoolId to balance of members
mapping (bytes32 => uint256) public rewardsByPoolId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this isn't always the case. @hysz has some examples that show solidity will only load the fields that are used.

/// @dev Increments rewards for a pool.
/// @param poolId Unique id of pool.
/// @param amount Amount to increment rewards by.
function _incrementPoolRewards(bytes32 poolId, uint256 amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: _increasePoolRewards

/// @dev Decrements rewards for a pool.
/// @param poolId Unique id of pool.
/// @param amount Amount to decrement rewards by.
function _decrementPoolRewards(bytes32 poolId, uint256 amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: _decreasePoolRewards.

view
returns (IEtherToken)
{
return IEtherToken(address(this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

expect(params[7]).to.eq(ethVaultAddress);
expect(params[8]).to.eq(rewardVaultAddress);
expect(params[9]).to.eq(zrxVaultAddress);
expect(params[7]).to.eq(zrxVaultAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @mzhu25 is on to something. I added it to the backlog.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants