Skip to content

Conversation

ChaituVR
Copy link
Member

@ChaituVR ChaituVR commented Mar 3, 2025

Related to. https://github.com/snapshot-labs/workflow/issues/281

This PR normalizes copeland score with voting power by allocating power to each choice with their copeland score

How to test

  • Just trust me bro (most of it is generated by AI)

@ChaituVR ChaituVR requested review from Copilot and bonustrack and removed request for Copilot March 3, 2025 10:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes the Copeland score calculation by normalizing it with voting power, ensuring that the score distribution reflects the actual vote balances. Key changes include:

  • Adding helper functions to generate examples with decimal and high voting powers.
  • Updating the core scoring logic in copeland.ts to normalize scores against the total voting power.
  • Extending test coverage in copeland.spec.js to verify normalization across various voting power scenarios.

Reviewed Changes

File Description
src/voting/copeland.spec.js Added test cases and helper functions to test normalization.
src/voting/copeland.ts Modified Copeland score computations to normalize voting power.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/voting/copeland.ts:107

  • Floating point precision issues may arise during normalization. Consider implementing a rounding strategy or using a fixed precision method when distributing voting power.
totalCopelandScore = scores.reduce((sum, score) => sum + score, 0);

src/voting/copeland.ts:130

  • [nitpick] For clarity, consider renaming 'strategyTotals' to 'totalVotingPowerPerStrategy' to better reflect its purpose.
const strategyTotals = Array(strategiesCount).fill(0);

Copy link
Member

@bonustrack bonustrack left a comment

Choose a reason for hiding this comment

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

utACK

@ChaituVR ChaituVR merged commit 25055c0 into master Mar 3, 2025
4 checks passed
@ChaituVR ChaituVR deleted the fix-normalize-copeland-score branch March 3, 2025 10:41
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.

2 participants