Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkpoints to staking contract #25

Merged
merged 10 commits into from
Nov 17, 2021

Conversation

cygnusv
Copy link
Member

@cygnusv cygnusv commented Nov 10, 2021

Adds checkpoints to staking contract, so that stakers can collect and delegate voting power in proportion to their stake size.
Some important aspects to note:

  • Delegation of stake voting power is controlled by the owner (i.e., the owner decides to whom delegate their vote)
  • Threshold model of staking roles allows for different stakes, associated to different operators, but with the same stake owner. Conversely, this means that the same owner address can have multiple stakes associated to different operators. In practice, in this situation the owner must delegate each stake individually.
  • Because of the particularities of the Threshold model of staking roles, the delegation function requires an extra parameter, that is, the operator address, in order to uniquely identify each stake:
    /// @notice Delegate voting power from the stake associated to the
    ///         `operator` to a `delegatee` address. Caller must be the owner
    ///         of this stake.
    function delegateVoting(address operator, address delegatee) public {
        delegate(operator, delegatee);
    }

@cygnusv cygnusv force-pushed the staking-points branch 4 times, most recently from 146454a to a3bac0b Compare November 15, 2021 16:45
@cygnusv cygnusv marked this pull request as ready for review November 16, 2021 10:44
Copy link
Contributor

@vzotova vzotova left a comment

Choose a reason for hiding this comment

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

I guess there is missing commit with new optimizer runs or something causing the TokenStaking deployment to fail during tests

contracts/staking/TokenStaking.sol Outdated Show resolved Hide resolved
contracts/staking/TokenStaking.sol Outdated Show resolved Hide resolved
@pdyraga
Copy link
Member

pdyraga commented Nov 16, 2021

I guess there is missing commit with new optimizer runs or something causing the TokenStaking deployment to fail during tests

Have we not just exceeded 24KB contract size limit with the additions from this PR?

@cygnusv
Copy link
Member Author

cygnusv commented Nov 16, 2021

I guess there is missing commit with new optimizer runs or something causing the TokenStaking deployment to fail during tests

Have we not just exceeded 24KB contract size limit with the additions from this PR?

Yeah, but reducing the number of optimization rounds allows to be right under 24KB

Copy link
Member

@pdyraga pdyraga left a comment

Choose a reason for hiding this comment

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

There is some infrastructure-level problem with the draft system tests job. Given system tests are still in draft, I am ignoring it and merging.

@@ -697,7 +714,7 @@ contract TokenStaking is Ownable, IStaking {
"Too much to unstake"
);
operatorStruct.nuInTStake -= amount;

decreaseStakeCheckpoint(operator, amount);
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick but we could keep the same order of operations of emitting event, updating staked amount, and decreasing checkpoint in unstake, unstakeKeep, and unstakeNu.

Comment on lines +966 to +968
function delegateVoting(address operator, address delegatee) external {
delegate(operator, delegatee);
}
Copy link
Member

Choose a reason for hiding this comment

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

What if we rename delegate function in T token contract to delegateVoting to keep them aligned?

function delegate(address delegatee) public virtual {

We could also rename the function in Checkpoint so that we do not need to have function delegate(address operator, address delegatee) a few lines below and just put this logic into delegateVoting.

expect(await tokenStaking.getVotes(delegatee.address)).to.equal(
expectedAmount
)
})
Copy link
Member

Choose a reason for hiding this comment

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

I think we should add a test that it should decrease the total voting power as well.

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

Successfully merging this pull request may close these issues.

3 participants