Skip to content

Commit

Permalink
fix scale issue with voting power used
Browse files Browse the repository at this point in the history
  • Loading branch information
EdNoepel committed Aug 11, 2023
1 parent 8aa9c28 commit 784be1f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 2 additions & 4 deletions src/utils/grants/voter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pool/reserve-auction.ts
Original file line number Diff line number Diff line change
@@ -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()))
Expand Down
8 changes: 4 additions & 4 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 784be1f

Please sign in to comment.