diff --git a/schema.graphql b/schema.graphql index f265128..9ae2e04 100644 --- a/schema.graphql +++ b/schema.graphql @@ -800,7 +800,7 @@ type DistributionPeriod @entity { screeningVotesCast: BigDecimal! # number of screening votes cast votes: [DistributionPeriodVote!]! # Voter info for the distribution period proposals: [Proposal!]! # List of proposals submitted in the distribution period - totalTokensRequested: BigDecimal! # Total ajna tokens requested by all proposals in the distribution period + totalTokensDistributed: BigDecimal! # Total ajna tokens distributed to executed proposals in a distribution period } type Proposal @entity { diff --git a/src/grant-fund.ts b/src/grant-fund.ts index e457cb7..8416ae6 100644 --- a/src/grant-fund.ts +++ b/src/grant-fund.ts @@ -197,7 +197,6 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void { const distributionId = bigIntToBytes(getCurrentDistributionId(event.address)) const distributionPeriod = DistributionPeriod.load(distributionId)! distributionPeriod.proposals = distributionPeriod.proposals.concat([proposal.id]) - distributionPeriod.totalTokensRequested = distributionPeriod.totalTokensRequested.plus(proposal.totalTokensRequested) // record proposals distributionId proposal.distribution = distributionPeriod.id @@ -222,7 +221,11 @@ export function handleProposalExecuted(event: ProposalExecutedEvent): void { const proposal = loadOrCreateProposal(bigIntToBytes(event.params.proposalId)) proposal.executed = true + const distributionPeriod = DistributionPeriod.load(proposal.distribution!)! + distributionPeriod.totalTokensDistributed = distributionPeriod.totalTokensDistributed.plus(proposal.totalTokensRequested) + // save entities to the store + distributionPeriod.save() proposal.save() proposalExecuted.save() } diff --git a/src/utils/grants/distribution.ts b/src/utils/grants/distribution.ts index 8a336f6..5da0781 100644 --- a/src/utils/grants/distribution.ts +++ b/src/utils/grants/distribution.ts @@ -53,7 +53,7 @@ export function loadOrCreateDistributionPeriod(distributionId: Bytes): Distribut distributionPeriod.screeningVotesCast = ZERO_BD distributionPeriod.votes = [] distributionPeriod.proposals = [] - distributionPeriod.totalTokensRequested = ZERO_BD + distributionPeriod.totalTokensDistributed = ZERO_BD } return distributionPeriod } diff --git a/tests/grant-fund.test.ts b/tests/grant-fund.test.ts index abf1a6b..67e021d 100644 --- a/tests/grant-fund.test.ts +++ b/tests/grant-fund.test.ts @@ -126,7 +126,7 @@ describe("Grant Fund assertions", () => { assert.fieldEquals( "DistributionPeriod", `${expectedDistributionId}`, - "totalTokensRequested", + "totalTokensDistributed", `${ZERO_BD}` ); @@ -346,6 +346,8 @@ describe("Grant Fund assertions", () => { /*** Assert State ***/ /********************/ + const expectedDistributionId = bigIntToBytes(distributionId).toHexString(); + // check GrantFund attributes assert.entityCount("GrantFund", 1); @@ -383,6 +385,12 @@ describe("Grant Fund assertions", () => { "proposalId", `${proposalId}` ); + assert.fieldEquals( + "DistributionPeriod", + `${expectedDistributionId}`, + "totalTokensDistributed", + `${wadToDecimal(BigInt.fromI32(2))}` + ); }); @@ -582,7 +590,6 @@ describe("Grant Fund assertions", () => { /*** Funding Vote Proposal ***/ /*****************************/ - // TODO: need to convert back from WAD const fundingVotingPower = votesCast.times(votesCast); mockGetVotesFunding(grantFundAddress, distributionId, voter, fundingVotingPower);