From 784be1f69a1dfbca4e14d278615b1b181b345999 Mon Sep 17 00:00:00 2001 From: Ed Noepel Date: Thu, 10 Aug 2023 18:19:59 -0400 Subject: [PATCH] fix scale issue with voting power used --- schema.graphql | 2 +- src/utils/grants/voter.ts | 6 ++---- src/utils/pool/reserve-auction.ts | 2 +- tests/grant-fund.test.ts | 8 ++++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/schema.graphql b/schema.graphql index b72797f..045ddd4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -856,7 +856,7 @@ type FundingVote @entity { voter: Account! # actor who cast votes proposal: Proposal! # proposal being voted on votesCast: BigDecimal! # uint256 - votingPowerUsed: BigDecimal! # uint256 # cost of the incremetnal funding vote to the voter's voting power + votingPowerUsed: BigDecimal! # uint256 # cost of the incremental funding vote to the voter's voting power blockNumber: BigInt! # block number the vote was cast } diff --git a/src/utils/grants/voter.ts b/src/utils/grants/voter.ts index 27544be..3380f50 100644 --- a/src/utils/grants/voter.ts +++ b/src/utils/grants/voter.ts @@ -3,7 +3,7 @@ import { Address, BigDecimal, BigInt, Bytes, dataSource, log } from "@graphproto import { Account, DistributionPeriodVote, FundingVote } from "../../../generated/schema" import { GrantFund } from "../../../generated/GrantFund/GrantFund" -import { EXP_18_BD, ZERO_BD, ZERO_BI } from "../constants" +import { ZERO_BD, ZERO_BI } from "../constants" import { bigIntToBytes, wadToDecimal } from "../convert" import { loadOrCreateDistributionPeriod } from "./distribution" @@ -48,9 +48,7 @@ export function getFundingVotingPowerUsed(distributionPeriodVote: DistributionPe const squaredAmount: BigDecimal[] = []; for (let i = 0; i < votes.length; i++) { const vote = loadOrCreateFundingVote(votes[i]); - // convert back from wad before squaring - const decimalVotesCast = vote.votesCast.times(EXP_18_BD) - squaredAmount.push(decimalVotesCast.times(decimalVotesCast).div(EXP_18_BD)); + squaredAmount.push(vote.votesCast.times(vote.votesCast)); } // sum the squared amounts diff --git a/src/utils/pool/reserve-auction.ts b/src/utils/pool/reserve-auction.ts index 5e7b715..334e31f 100644 --- a/src/utils/pool/reserve-auction.ts +++ b/src/utils/pool/reserve-auction.ts @@ -1,6 +1,6 @@ import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts" import { Pool, ReserveAuction } from "../../../generated/schema" -import { EXP_18_BD, ONE_BI, ZERO_BD, ZERO_BI } from "../constants" +import { ONE_BI, ZERO_BD, ZERO_BI } from "../constants" export function getReserveAuctionId(poolId: Bytes, burnEpoch: BigInt): Bytes { return poolId.concat(Bytes.fromUTF8('|' + burnEpoch.toHexString())) diff --git a/tests/grant-fund.test.ts b/tests/grant-fund.test.ts index af02722..b50c153 100644 --- a/tests/grant-fund.test.ts +++ b/tests/grant-fund.test.ts @@ -624,8 +624,8 @@ describe("Grant Fund assertions", () => { const screeningVoteId = getScreeningVoteId(bigIntToBytes(proposalId), addressToBytes(voter), BigInt.fromI32(1)); const expectedProposalId = bigIntToBytes(proposalId).toHexString(); const expectedDistributionId = bigIntToBytes(distributionId).toHexString(); - const expectedVotingPowerUsed = wadToDecimal(votesCast.times(votesCast)); - const expectedScreeningVotesReceived = wadToDecimal(votesCast.times(BigInt.fromI32(-1))); + const expectedVotingPowerUsed = wadToDecimal(votesCast).times(wadToDecimal(votesCast)); + const expectedScreeningVotesReceived = wadToDecimal(votesCast).times(NEG_ONE_BD); assert.fieldEquals( "Proposal", @@ -661,14 +661,14 @@ describe("Grant Fund assertions", () => { "DistributionPeriodVote", `${distributionPeriodVoteId.toHexString()}`, "estimatedInitialFundingStageVotingPowerForCalculatingRewards", - `${expectedVotingPowerUsed}` + '0.000000000000054756' ); assert.fieldEquals( "DistributionPeriodVote", `${distributionPeriodVoteId.toHexString()}`, "estimatedRemainingFundingStageVotingPowerForCalculatingRewards", - `${0}` + '0.000000000000054755999999999999945244' ); // check FundingVote attributes