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

Remove votesbook #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Remove votesbook #41

wants to merge 4 commits into from

Conversation

cabrador
Copy link
Contributor

@cabrador cabrador commented Feb 4, 2025

#33 and #34 must be merged before this PR
This PR removes the VotesBook contract and merges its funcionality into Governance contact.

@cabrador cabrador marked this pull request as draft February 4, 2025 09:24
@cabrador cabrador force-pushed the c/remove-common branch 6 times, most recently from 8fb57ad to 3e8cac4 Compare February 10, 2025 08:06
@cabrador cabrador force-pushed the c/remove-votesbook branch 3 times, most recently from 9e2c8f5 to 37bc330 Compare February 10, 2025 13:36
@cabrador cabrador changed the base branch from c/remove-common to master February 10, 2025 13:36
@cabrador cabrador marked this pull request as ready for review February 10, 2025 13:36
@cabrador cabrador requested a review from thaarok February 10, 2025 13:36
@cabrador cabrador marked this pull request as draft February 10, 2025 13:37
@cabrador cabrador marked this pull request as ready for review February 10, 2025 13:40

/// @notice Governance contract for voting on proposals
contract Governance is Initializable, ReentrancyGuardTransient, GovernanceSettings, Version {
contract Governance is ReentrancyGuardTransient, GovernanceSettings, Version, UUPSUpgradeable, OwnableUpgradeable {
Copy link

Choose a reason for hiding this comment

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

When using UUPSUpgradeable, you should always include constructor and disable initializers to prevent initialization of the implementation contract.

/** @custom:oz-upgrades-unsafe-allow constructor */
constructor() {
    _disableInitializers();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arent we supposed to call this in initialize instead? I cannot call initialize when this is in construct and I cannot call the init functions from ReentrancyGuardTransient, Ownable and UUPSUpgradeable inside constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved in private conversation.

@cabrador cabrador requested a review from Mike-CZ February 12, 2025 15:20
Copy link
Collaborator

@thaarok thaarok left a comment

Choose a reason for hiding this comment

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

This PR needs much deeper review to check if the behavior was not changed by the refactoring.
For now check these notes.

VotesBookKeeper votebook;
// list of all proposal to which voter has voted for
// voter => delegatedTo => []proposal IDs
mapping(address => mapping(address => uint256[])) public votesList;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use names of keys/values in the mappings:

mapping(address voter => mapping(address delegatedTo => uint256[] proposalId)) public votesList;

list of all proposal to which voter has voted for -> list of proposals the voter has voted on

/// @notice Get the proposal IDs for a voter
/// @param voter The address of the voter
/// @param delegatedTo The address of the delegator which the voter has delegated their stake to
/// @return An array of proposal IDs
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment is not much helpful:
Get the proposal IDs for a voter -> Get proposals for with the voter voted ?

// voter => delegatedTo => []proposal IDs
mapping(address => mapping(address => uint256[])) public votesList;
// voter => delegatedTo => proposal ID => {index in the list + 1}
mapping(address => mapping(address => mapping(uint256 => uint256))) public votesIndex;
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. we can add a comment like Index of vote positions in proposals
  2. index in the list -> index in the votesList

/// @dev Remove a vote from the list of votes
/// @param voter The address of the voter
/// @param delegatedTo The address of the delegator which the sender has delegated their stake to.
/// @param proposalID The ID of the proposal
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing doc for @param idx
Edit: suggested removing it bellow.

/// @param voter The address of the voter
/// @param delegatedTo The address of the delegator which the sender has delegated their stake to.
/// @param proposalID The ID of the proposal
/// @return The index of the vote plus 1 if the vote exists, otherwise 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

The index of the vote -> The index of the proposal in the list of voter's votes
maybe The index of the proposal in the votesList

return votesList[voter][delegatedTo];
}

/// @notice Get option for which the voter voted (indexed from 1), zero if not voted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to be wrong comment.
Get option for which the voter voted -> Get position of a proposal in the list of voter's votes

if (!isCanceled) {
i++;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a very courageous refactoring - I will have to review it more deeper later...

votebook.onVoteCanceled(voter, delegatedTo, proposalID);
uint256 idx = votesIndex[voter][delegatedTo][proposalID];
if (idx != 0) {
eraseVote(voter, delegatedTo, proposalID, idx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you can move the idx reading a the condition inside of the eraseVote() - then you can drop the idx param too.

// expect(await this.votesBookKeeper.getVoteIndex(this.otherAcc, this.defaultAcc, 1)).to.be.equal(0n);
// }
// });
// })
Copy link
Collaborator

Choose a reason for hiding this comment

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

These tests need to be reworked for the gov contract before this PR can be merged.

@cabrador cabrador force-pushed the c/remove-votesbook branch from ce53d55 to 6a06744 Compare March 10, 2025 13:38
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