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

Conversation

abandeali1
Copy link
Member

@abandeali1 abandeali1 commented Sep 23, 2019

Description

This PR:

  • Adds codesize tests to the staking contracts (currently disabled)
  • Consolidates MixinStakingPoolMakers, MixinStakingPoolModifiers, and MixinStakingPool into a single mixin. These contracts had a lot of overlap. The resulting contract is larger than I would like, but I think less confusing overall.
  • Consolidates the modifiers into a single onlyStakingPoolOperatorOrMaker. Registered makers now essentially have the same rights as an operator. This includes admitting new makers into the pool, removing makers from the pool, or decreasing the operator's share. I like how this new behavior incentivizes operators to only allow makers that they control into a pool.
  • Fixes a bug where anyone could decrease an operator's share.
  • Addresses minor comments from @dorothy-zbornak on Delete StakingPoolRewardVault and EthVault #2186

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 23, 2019

Coverage Status

Coverage remained the same at 75.804% when pulling 7f51822 on feat/3.0/consolidate-pool-mixins into c29a221 on 3.0.

@abandeali1 abandeali1 force-pushed the feat/3.0/consolidate-pool-mixins branch 2 times, most recently from 185d85e to a838a58 Compare September 24, 2019 03:36
@abandeali1 abandeali1 changed the base branch from feat/3.0/delete-vaults to 3.0 September 24, 2019 03:39
@abandeali1 abandeali1 marked this pull request as ready for review September 24, 2019 03:44
@abandeali1 abandeali1 force-pushed the feat/3.0/consolidate-pool-mixins branch from a838a58 to 8d91614 Compare September 24, 2019 04:03
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.

Looks good! Left a few comments and nits.
One thing to note is that I feel like with this change we need to be extra careful about communicating the fact that pools are intended only for makers controlled by a single entity, otherwise an operator might accidentally add an external maker who subsequently decreases the operator share to 0

senderAddress,
operator,
makerAddress
operator
Copy link
Contributor

Choose a reason for hiding this comment

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

idk if it still makes sense to use the operator address as a parameter for this error anymore –– maybe just the poolId instead? since you can get the operator from the poolId if you want

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 that change!

}

if (membersReward > 0) {
// Increment the balance of the pool
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: update these comments too

import * as chai from 'chai';

chaiSetup.configure();
const expect = chai.expect;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: import expect from test-utils instead

accounts = await env.getAccountAddressesAsync();
owner = accounts[0];
users = accounts.slice(1);
users = accounts.slice(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: [owner, ...users] = accounts; or even [owner, operator, ...users] = accounts;

const ethBalance = await this._web3Wrapper.getBalanceInWeiAsync(address);
const wethBalance = await this.wethContract.balanceOf.callAsync(address);
return BigNumber.sum(ethBalance, wethBalance);
getAvailableRewardsBalanceAsync: async (): Promise<BigNumber> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

😎

import { PoolOperatorActor } from './pool_operator_actor';

export class MakerActor extends BaseActor {
export class MakerActor extends PoolOperatorActor {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like the inheritance should go the other way around here, since (1) technically there's nothing stopping an operator from joining a staking pool, and (2) createStakingPool is kinda what differentiates a pool operator from a vanilla maker

Copy link
Member Author

Choose a reason for hiding this comment

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

There's nothing stopping a maker from creating a pool either, right? Maybe We should just combine these into one actor?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess my thought was that a maker "becomes" an operator by creating a pool (though I suppose the same can be said about an operator joining a pool). I think it's helpful to keep them as separate actors regardless, for clarity in e.g. rewards_test if nothing else; open to other opinions tho

new StakingRevertErrors.OnlyCallableByPoolOperatorOrMakerError(makerAddress, operatorAddress),
);
});
it('should fail to add a maker to a pool if not called by operator/registered maker', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test does the same thing as 'Should fail to add a maker when called by someone other than the pool operator', so we can delete the latter

LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
makerAddress,
getStakingPoolIdOfMaker(makerAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
getStakingPoolIdOfMaker(makerAddress)
poolJoinStatus.poolId

LibRichErrors.rrevert(LibStakingRichErrors.MakerPoolAssignmentError(
LibStakingRichErrors.MakerPoolAssignmentErrorCodes.MakerAddressAlreadyRegistered,
makerAddress,
getStakingPoolIdOfMaker(makerAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@abandeali1 abandeali1 force-pushed the feat/3.0/consolidate-pool-mixins branch from 496dffb to 01c7211 Compare September 24, 2019 18:45
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.

It is def much nicer to have these in one mixin.
Just some small suggestions but otherwise looks peachy keen!

/// @param newOperatorShare The newly decreased percentage of any rewards owned by the operator.
function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare)
external
onlyStakingPoolOperatorOrMaker(poolId)
Copy link
Contributor

Choose a reason for hiding this comment

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

😇

poolId: NIL_POOL_ID,
confirmed: false
});
poolJoinedByMakerAddress[makerAddress] = poolJoinStatus;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we just replace all the above with delete poolJoinedByMakerAddress[makerAddress]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

/// @param makerAddress Address of maker
/// @return Pool id, nil if maker is not yet assigned to a pool.
function getStakingPoolIdOfMaker(address makerAddress)
public
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just be internal/private since poolJoinedByMakerAddress is a public variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should have public getters for state variables that store a struct in a single word (the autogenerated getters don't play nicely with AbiV2). I'll actually make poolJoinedByMakerAddress internal.

// maker removes themselves from pool
await maker.removeMakerFromStakingPoolAsync(poolId, makerAddress);
});
it('should successful remove another maker from a pool', async () => {
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
it('should successful remove another maker from a pool', async () => {
it('operator can remove a maker from their pool', async () => {

await maker.joinStakingPoolAsMakerAsync(poolId);
// operator adds maker to pool
await poolOperator.addMakerToStakingPoolAsync(poolId, makerAddress);
// maker removes themselves from pool
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
// maker removes themselves from pool
// operator removes maker from pool

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.

👍 Maker/PoolOperatorActor inheritance thing is optional, should be a straightforward to change down the line should we decide to

@abandeali1 abandeali1 force-pushed the feat/3.0/consolidate-pool-mixins branch from 454c0ff to 7f51822 Compare September 24, 2019 20:39
@abandeali1 abandeali1 merged commit 0c5f027 into 3.0 Sep 24, 2019
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.

4 participants