Skip to content

feat: set vote fiat value #566

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

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

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Jul 30, 2025

Vote Value Computation

Closes https://github.com/snapshot-labs/workflow/issues/614

This PR assigns a fiat value to a vote, when available

Key Features

🎯 Core Enhancement

  • Add vp_value column to votes table for storing fiat values (13 digits, 3 decimal precision, see https://github.com/snapshot-labs/workflow/issues/618)
  • Calculate vote value by multiplying voting power with corresponding strategy values
  • Seamless integration with existing voting power calculation system: work when proposal had not any fiat values set

💰 Value Calculation Logic

  • Fallback Handling: Graceful degradation to 0 value when calculations fail, cb column will not be updated
  • Real-time Computation: Values calculated during vote processing

🔧 Technical Implementation

  • Centralized Logic: All value calculations consolidated in src/helpers/entityValue.ts
  • Database Schema: New vp_value column with appropriate precision (DECIMAL(13,3))
  • Error Resilience: Robust error handling prevents vote processing failures

Database Changes

  • Added vp_value DECIMAL(13,3) column to votes table
  • Maintains backwards compatibility with existing vote records

Testing

Create the column vp_value

  ALTER TABLE votes ADD COLUMN vp_value DECIMAL(13,3) NOT NULL DEFAULT 0.000;
  CREATE INDEX vp_value ON votes(vp_value);
  • On a proposal with vp value set, vote (edit the db rows to manually set some values in vp_value_by_strategy)
  • The vote's should have some value in the vp_value column (voting power x strategy value)

@wa0x6e wa0x6e requested a review from Copilot July 30, 2025 22:57
Copilot

This comment was marked as outdated.

@wa0x6e wa0x6e force-pushed the feat-assign-fiat-value-to-vote branch 2 times, most recently from bfe6e45 to ddee8cc Compare July 31, 2025 13:30
@wa0x6e wa0x6e requested a review from Copilot July 31, 2025 13:30
Copilot

This comment was marked as outdated.

@wa0x6e wa0x6e force-pushed the feat-assign-fiat-value-to-vote branch from ddee8cc to 6aecdde Compare August 5, 2025 17:39
feat: add index to vp_value

fix: handle high precision computation

perf:

fix: handle error

fix: increase last vote cb
@wa0x6e wa0x6e force-pushed the feat-assign-fiat-value-to-vote branch from 6aecdde to 4383ded Compare August 5, 2025 17:41
@wa0x6e wa0x6e requested a review from Copilot August 5, 2025 17:47
Copilot

This comment was marked as outdated.

@wa0x6e wa0x6e requested a review from Copilot August 5, 2025 17:55
Copilot

This comment was marked as outdated.

@wa0x6e wa0x6e changed the title feat: compute vote fiat value feat: set vote fiat value Aug 5, 2025
@wa0x6e wa0x6e requested a review from Copilot August 6, 2025 17:01
Copilot

This comment was marked as outdated.

@wa0x6e wa0x6e requested a review from Copilot August 7, 2025 16:33
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.

Pull Request Overview

This PR implements vote fiat value calculation functionality by adding a new vp_value column to the votes table to store the calculated fiat value of each vote. The value is computed by multiplying each strategy's voting power by its corresponding fiat value from the proposal.

  • Added vp_value column to votes table with appropriate database schema changes
  • Implemented getVoteValue helper function to calculate vote values based on strategy values
  • Updated vote writer to compute and store vote values with error handling fallback

Reviewed Changes

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

Show a summary per file
File Description
test/schema.sql Adds vp_value column and index to votes table schema
src/helpers/entityValue.ts New helper function to calculate vote value from proposal and vote data
src/writer/vote.ts Integrates vote value calculation into vote processing with error handling
src/helpers/actions.ts Parses vp_value_by_strategy from proposal data
test/unit/helpers/entityValue.test.ts Comprehensive test coverage for vote value calculation
.env.example Adds LAST_CB environment variable configuration

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.

1 participant