Skip to content

Commit

Permalink
convert totalTokensRequested to totalTokensDistributed in Distributio…
Browse files Browse the repository at this point in the history
…n Period
  • Loading branch information
Mike committed Jul 27, 2023
1 parent caa1ade commit 4e9be34
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/grants/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 9 additions & 2 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("Grant Fund assertions", () => {
assert.fieldEquals(
"DistributionPeriod",
`${expectedDistributionId}`,
"totalTokensRequested",
"totalTokensDistributed",
`${ZERO_BD}`
);

Expand Down Expand Up @@ -346,6 +346,8 @@ describe("Grant Fund assertions", () => {
/*** Assert State ***/
/********************/

const expectedDistributionId = bigIntToBytes(distributionId).toHexString();

// check GrantFund attributes
assert.entityCount("GrantFund", 1);

Expand Down Expand Up @@ -383,6 +385,12 @@ describe("Grant Fund assertions", () => {
"proposalId",
`${proposalId}`
);
assert.fieldEquals(
"DistributionPeriod",
`${expectedDistributionId}`,
"totalTokensDistributed",
`${wadToDecimal(BigInt.fromI32(2))}`
);

});

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4e9be34

Please sign in to comment.