Skip to content
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

Add state needed for calculating voting power to subgraph #664

Merged
merged 3 commits into from
Dec 22, 2024

Conversation

danielattilasimon
Copy link
Collaborator

@danielattilasimon danielattilasimon commented Dec 20, 2024

We add the necessary state needed for calculating both total and per-user voting power. This could be useful if one wants to know e.g. their share of the total votes. Voting power is internally represented by a pair of (lqty, offset) values, from which the voting power at time t can be calculated as: votingPower(t) = lqty * t - offset.

Also get Governance ABI from forge, just like for other contracts. We can do this now that Governance is a submodule of the repo.

Also fixes an issue where people's LQTY stake could be wrong in the subgraph if someone sent LQTY directly to their UserProxy.

Also, now we have events when the initial initiatives are being registered, so we no longer need the block handler.

// Create initial stats
let stats = new GovernanceStats("stats");
stats.totalLQTYStaked = BigInt.fromI32(0);
stats.totalOffset = BigInt.fromI32(0);
stats.totalInitiatives = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just noticed totalInitiatives is never increased. Is the idea to track the number of GovernanceInitiative entities (i.e. only increased, never decreased, not even on unregistration)?

Copy link
Contributor

Choose a reason for hiding this comment

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

No the idea was to track the number of active initiatives, this is something that was missing.

Copy link
Contributor

@bpierre bpierre left a comment

Choose a reason for hiding this comment

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

Thanks @danielattilasimon, that’s great!

I deployed this version, and I built on top of it for this PR: #672

Do you think we could add the total voting power somewhere in the graph? Or is it something I could calculate easily with what we have already? So that the app could show a % rather than a unitless number.

@danielattilasimon
Copy link
Collaborator Author

Thanks @danielattilasimon, that’s great!

I deployed this version, and I built on top of it for this PR: #672

Do you think we could add the total voting power somewhere in the graph? Or is it something I could calculate easily with what we have already? So that the app could show a % rather than a unitless number.

Both the total voting power and your individual voting power are linear functions of time, but their y-intercepts (called "offset" in the backend and subgraph) are different, hence your % share will change over time even if nobody changes their stake. As such, I would leave it to the frontend to calculate the user's most up-to-date share like this:

totalVotingPower(t) = governanceStats.totalLQTYStaked * t - governanceStats.totalOffset
userVotingPower(t) = governanceUser.stakedLQTY * t - governanceUser.stakedOffset
pctShare(t) = userVotingPower(t) / totalVotingPower(t)

where t is a seconds-based timestamp just like the block timestamp.

@danielattilasimon danielattilasimon merged commit 194d3fa into next Dec 22, 2024
@danielattilasimon danielattilasimon deleted the subgraph-voting-power branch December 22, 2024 05:53
@bpierre
Copy link
Contributor

bpierre commented Jan 7, 2025

@danielattilasimon added in #677, thank you 🙏

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