Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

feat: new query to get total vp_value#1066

Open
ChaituVR wants to merge 2 commits into
masterfrom
chaitu/feat-vp-value-query
Open

feat: new query to get total vp_value#1066
ChaituVR wants to merge 2 commits into
masterfrom
chaitu/feat-vp-value-query

Conversation

@ChaituVR

Copy link
Copy Markdown
Member

Summary:

  • Added the missing fields in schema.sql
  • Added a new query vp_value to get the total vp_value of user, also breakdown per space

How to test:

  • Run yarn dev
  • Go to http://localhost:3000/graphql
  • Run query:
    {
      vp_value(voter: "0x5BFCB4BE4d7B43437d5A0c57E908c048a4418390") {
        user
        totalVpValue
        votesCount
        spaces {
          id
          totalVpValue
          votesCount
        }
      }
    }

@ChaituVR
ChaituVR requested review from bonustrack, Copilot and wa0x6e and removed request for bonustrack and wa0x6e January 27, 2026 14:29
@ChaituVR ChaituVR self-assigned this Jan 27, 2026
@wa0x6e

wa0x6e commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Original idea was to expose it via the leaderboard object

@ChaituVR

Copy link
Copy Markdown
Member Author

Original idea was to expose it via the leaderboard object

Yes thats best way, but looks like we need a query like this for now to use internally

@bonustrack

Copy link
Copy Markdown
Member

Original idea was to expose it via the leaderboard object

Hum I forgot about that, that might simplify things actually to do this way. But I'm not sure it would scale well to query SUM of many users vp_value on the fly at once.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds a new GraphQL query vp_value that retrieves the total VP (voting power) value for a user along with a breakdown by space. It also adds the necessary database schema fields to support this functionality.

Changes:

  • Added vp_value column to the votes table with DECIMAL(13,3) type
  • Updated scores_total_value in the proposals table to use DECIMAL(13,3) type for consistency
  • Implemented new GraphQL query vp_value with resolver that aggregates VP values per space and returns total values

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/helpers/schema.sql Adds vp_value field to votes table and updates precision of scores_total_value in proposals table
src/graphql/schema.gql Defines new vp_value query and its return types (VpValue and VpValueSpace)
src/graphql/operations/vpValue.ts Implements the query resolver with address validation, SQL aggregation, and error handling
src/graphql/operations/index.ts Registers the new vp_value operation in the GraphQL operations index

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/graphql/operations/vpValue.ts
@wa0x6e

wa0x6e commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

What's the purpose of the votesCount field ?

Seems a little ambiguous, since when a space has 100 votes, but only 1 with value, it will return 100 (so include votes with 0 value)

But for a space with 100 votes without value, it will be skipped entirely

It does not seem to represent the total number of votes of the user, nor the number of votes with value either

@wa0x6e wa0x6e left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tAck code wise

FROM votes v
WHERE v.voter = ?
GROUP BY v.space
HAVING vp_value > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Without the votesCount, this could be refactored to use a simpler where, which will filtering out the no value votes before SUMing them

@wa0x6e

wa0x6e commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

See #1037

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants