-
Notifications
You must be signed in to change notification settings - Fork 0
systemcontract: add transferVote method #182
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
Changes from all commits
1fbdb9c
de36f37
2d26b15
ca856ce
dd3d1e5
0445ef9
51786b4
a46fdb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,9 @@ interface IGovernance { | |
| // revoke votes and claim rewards | ||
| function revokeVote() external; | ||
|
|
||
| // revoke votes, claim rewards and vote to another candidate | ||
| function transferVote(address candidateTo) external; | ||
|
|
||
| // only claim rewards | ||
| function claimReward() external; | ||
|
|
||
|
|
@@ -258,6 +261,28 @@ contract Governance is IGovernance, ReentrancyGuard, UUPSUpgradeable { | |
| _safeTransferETH(msg.sender, amount + unclaimedReward); | ||
| } | ||
|
|
||
| function transferVote(address candidateTo) external nonReentrant { | ||
| address candidateFrom = votedTo[msg.sender]; | ||
| uint amount = votedAmount[msg.sender]; | ||
| if (candidateFrom == address(0) || amount <= 0) revert Errors.NoVote(); | ||
| if (candidateFrom == candidateTo) revert Errors.SameCandidate(); | ||
| if (!candidateList.contains(candidateTo)) revert Errors.CandidateNotExists(); | ||
|
|
||
| // settle reward here | ||
| uint unclaimedReward = _settleReward(msg.sender, candidateFrom); | ||
|
|
||
| // update votes | ||
| receivedVotes[candidateFrom] -= amount; | ||
| receivedVotes[candidateTo] += amount; | ||
| votedTo[msg.sender] = candidateTo; | ||
| voterGasPerVote[msg.sender] = candidateGasPerVote[candidateTo]; | ||
| voteHeight[msg.sender] = block.number; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest not to change the height so that if voter changes the vote target, then it still receives the reward for the rest of the epoch. Exactly like if candidate performs the second vote for the same address.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it's a subject of discussion.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a case that a voter first vote to candidate A whose But if the voter change back to A before the next epoch change. There will be a fact that the voter puts its effective votes to A, but shares rewards from B. Is that what the candidate B expects to see? I suggest that we delay this change till the future, e.g. when we reduce the epoch length.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, your second example is reasonable, we probably need to think about this case a bit more.
Could you create an issue for that?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ref. #222. |
||
|
|
||
| emit Revoke(msg.sender, candidateFrom, amount); | ||
| emit Vote(msg.sender, candidateTo, amount); | ||
| if (unclaimedReward > 0) _safeTransferETH(msg.sender, unclaimedReward); | ||
| } | ||
|
|
||
| function claimReward() external nonReentrant { | ||
| address votedCandidate = votedTo[msg.sender]; | ||
| if (votedCandidate == address(0)) revert Errors.NoVote(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.