Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
keep track of lost transfers on ranked choice irv
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed Sep 12, 2020
1 parent 3bd5952 commit 1aedb4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/dai-plugin-governance/src/GovPollingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ export default class GovPollingService extends PrivateService {
});

tally.options[optionToEliminate].eliminated = true;
tally.options[optionToEliminate].transfer = BigNumber(0);

// a vote needs to be moved if...
// 1) it's currently for the eliminated candidate
Expand All @@ -313,12 +312,18 @@ export default class GovPollingService extends PrivateService {

// move votes to the next choice on their preference list
votesToBeMoved.forEach(vote => {
const prevChoice = votes[vote.index].choice;
votes[vote.index].choice = votes[vote.index].ballot.pop();
if (!tally.options[votes[vote.index].choice])
tally.options[votes[vote.index].choice] = { ...defaultOptionObj };

tally.options[votes[vote.index].choice].transfer = BigNumber(
tally.options[votes[vote.index].choice].transfer
).plus(vote.mkrSupport || 0);

tally.options[prevChoice].transfer = BigNumber(
tally.options[prevChoice].transfer
).minus(vote.mkrSupport || 0);
});

// look for a candidate with the majority
Expand Down
6 changes: 3 additions & 3 deletions packages/dai-plugin-governance/test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const dummyBallotNoMajorityExpect = {
options: {
'1': {
firstChoice: '60.025',
transfer: '0',
transfer: '-60.025',
winner: false,
eliminated: true
},
Expand Down Expand Up @@ -210,7 +210,7 @@ export const dummyBallotMultipleRoundsExpect = {
options: {
'1': {
firstChoice: '60.025',
transfer: '0',
transfer: '-56.025',
winner: false,
eliminated: true
},
Expand All @@ -228,7 +228,7 @@ export const dummyBallotMultipleRoundsExpect = {
},
'4': {
firstChoice: '4',
transfer: '0',
transfer: '-4',
winner: false,
eliminated: true
}
Expand Down

0 comments on commit 1aedb4e

Please sign in to comment.