-
Notifications
You must be signed in to change notification settings - Fork 465
Delete StakingPoolRewardVault
and EthVault
#2186
Conversation
3ff1aee
to
b4cb9c8
Compare
StakingPoolRewardVault
and EthVault
943d4eb
to
62663ed
Compare
There was a problem hiding this 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() |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 @@ | |||
/* |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 (~‾▿‾)~
There was a problem hiding this 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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Description
StakingPoolRewardVault
. These balances are now tracked internally in theStakingProxy
state.EthVault
. Deposits to theEthVault
have been completely replaced with WETH withdrawals directly to the user's account.Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.