Skip to content

Commit

Permalink
wip distributionPeriod start screening power tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Jul 26, 2023
1 parent 00c9d4b commit 101c87c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Bytes, ethereum, log } from '@graphprotocol/graph-ts'
import { Address, Bytes, ethereum } from '@graphprotocol/graph-ts'

import {
DelegateRewardClaimed as DelegateRewardClaimedEvent,
Expand Down Expand Up @@ -26,7 +26,7 @@ import {
DistributionPeriodVote
} from "../generated/schema"

import { ZERO_ADDRESS, ZERO_BD } from './utils/constants'
import { ONE_BI, ZERO_ADDRESS, ZERO_BD } from './utils/constants'
import { addressArrayToBytesArray, addressToBytes, bigIntToBytes, bytesToBigInt, wadToDecimal } from "./utils/convert"
import { getProposalParamsId, getProposalsInSlate, removeProposalFromList } from './utils/grants/proposal'
import { getCurrentDistributionId, getCurrentStage, loadOrCreateDistributionPeriod } from './utils/grants/distribution'
Expand Down Expand Up @@ -249,15 +249,21 @@ export function handleDistributionPeriodStarted(
distributionPeriod.startBlock = distributionStarted.startBlock
distributionPeriod.endBlock = distributionStarted.endBlock

// // loop through DistributionPeriodVotes for the current period and update voting power
// const votes = distributionPeriod.votes
// for (var i=0; i<votes.length; ++i) {
// const vote = DistributionPeriodVote.load(votes[i])!
// vote.screeningStageVotingPower = getScreeningStageVotingPower(event.address, bytesToBigInt(distributionId), Address.fromBytes(vote.voter))
// // vote.fundingStageVotingPower = getFundingStageVotingPower(event.address, bytesToBigInt(distributionId), Address.fromBytes(vote.voter))
// vote.initialFundingStageVotingPower =
// vote.save()
// }
// loop through DistributionPeriodVotes of the previous period, create new entities, and set their screening stage voting power
if (event.params.distributionId != ONE_BI) {
const prevDistributionPeriod = loadOrCreateDistributionPeriod(distributionId)
const votes = prevDistributionPeriod.votes
for (var i=0; i<votes.length; ++i) {
const prevVote = DistributionPeriodVote.load(votes[i])!
const prevVoter = prevVote.voter
const newDistributionPeriodVote = loadOrCreateDistributionPeriodVote(distributionPeriod.id, prevVoter)
newDistributionPeriodVote.screeningStageVotingPower = getScreeningStageVotingPower(event.address, bytesToBigInt(distributionId), Address.fromBytes(prevVoter))
newDistributionPeriodVote.save()
}
}
else {
distributionPeriod.votes = []
}

// update GrantFund entity
const grantFund = loadOrCreateGrantFund(event.address)
Expand Down
5 changes: 3 additions & 2 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ describe("Grant Fund assertions", () => {
// check Proposal attributes
assert.entityCount("Proposal", 1);

assert.entityCount("VoteCast", 2);
assert.entityCount("DistributionPeriod", 1);
assert.entityCount("DistributionPeriodVote", 1);
assert.entityCount("FundingVote", 1);
assert.entityCount("ScreeningVote", 1);
assert.entityCount("DistributionPeriodVote", 1);
assert.entityCount("VoteCast", 2);

const distributionPeriodVoteId = getDistributionPeriodVoteId(bigIntToBytes(distributionId), addressToBytes(voter));
const fundingVoteId = getFundingVoteId(bigIntToBytes(proposalId), addressToBytes(voter), BigInt.fromI32(2));
Expand Down

0 comments on commit 101c87c

Please sign in to comment.