Skip to content

Commit

Permalink
GrantFund Subgraph Improvements and Bugfixes (#38)
Browse files Browse the repository at this point in the history
* fix proposal calldata decoding

* remove succeeded attribute of Proposals; expand proposalExecuted testing

* record fundingVotesReceived on proposal

* add assertion

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>
  • Loading branch information
MikeHathaway and Mike committed Jul 27, 2023
1 parent 27918da commit ba6a1ff
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 55 deletions.
1 change: 0 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ type Proposal @entity {
description: String! # proposal description hashed as part of proposalId
distribution: DistributionPeriod # distributionPeriod in which the proposal was submitted if Standard, null otherwise
executed: Boolean! # bool
successful: Boolean! # bool
screeningVotesReceived: BigDecimal! # uint256
fundingVotesReceived: BigDecimal! # uint256
totalTokensRequested: BigDecimal! # uint256
Expand Down
41 changes: 14 additions & 27 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'
import { Address, BigInt, Bytes, ethereum, log } from '@graphprotocol/graph-ts'

import {
DelegateRewardClaimed as DelegateRewardClaimedEvent,
Expand Down Expand Up @@ -162,14 +162,8 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void {

// create Proposal entity
const proposalId = bigIntToBytes(event.params.proposalId)
const proposal = new Proposal(proposalId) as Proposal
const proposal = loadOrCreateProposal(proposalId)
proposal.description = event.params.description
proposal.distribution = Bytes.empty()
proposal.executed = false
proposal.successful = false
proposal.screeningVotesReceived = ZERO_BD
proposal.fundingVotesReceived = ZERO_BD
proposal.params = []

let totalTokensRequested = ZERO_BD

Expand All @@ -182,18 +176,11 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void {
proposalParams.calldata = event.params.calldatas[i]

// decode the calldata to get the recipient and tokens requested
const dataWithoutFunctionSelector = Bytes.fromUint8Array(proposalParams.calldata.subarray(3))
const decoded = ethereum.decode('(address,uint256)', dataWithoutFunctionSelector)
if (decoded != null) {
proposalParams.recipient = decoded.toTuple()[0].toAddress()
const tokensRequested = decoded.toTuple()[1].toBigInt().toBigDecimal()
proposalParams.tokensRequested = tokensRequested
totalTokensRequested = totalTokensRequested.plus(tokensRequested)
}
else {
proposalParams.recipient = ZERO_ADDRESS
proposalParams.tokensRequested = ZERO_BD
}
const decoded = ethereum.decode('(address,uint256)', proposalParams.calldata)!
proposalParams.recipient = decoded.toTuple()[0].toAddress()
const tokensRequested = decoded.toTuple()[1].toBigInt().toBigDecimal()
proposalParams.tokensRequested = tokensRequested
totalTokensRequested = totalTokensRequested.plus(tokensRequested)

// add proposalParams information to proposal
proposal.params = proposal.params.concat([proposalParams.id])
Expand Down Expand Up @@ -231,14 +218,11 @@ export function handleProposalExecuted(event: ProposalExecutedEvent): void {
proposalExecuted.transactionHash = event.transaction.hash

// update proposal entity
const proposal = Proposal.load(bigIntToBytes(event.params.proposalId)) as Proposal
if (proposal != null) {
proposal.executed = true
proposal.successful = true
const proposal = loadOrCreateProposal(bigIntToBytes(event.params.proposalId))
proposal.executed = true

// save entities to the store
proposal.save()
}
// save entities to the store
proposal.save()
proposalExecuted.save()
}

Expand Down Expand Up @@ -356,6 +340,9 @@ export function handleVoteCast(event: VoteCastEvent): void {
distributionPeriodVote.estimatedRemainingFundingStageVotingPowerForCalculatingRewards = getFundingStageVotingPower(event.address, bytesToBigInt(distributionId), Address.fromBytes(voter.id))
}

// record votes cast on the Proposal entity
proposal.fundingVotesReceived = proposal.fundingVotesReceived.plus(fundingVote.votesCast)

// save fundingVote to the store
fundingVote.save()
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/grants/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function loadOrCreateProposal(proposalId: Bytes): Proposal {
proposal.description = ""
proposal.distribution = Bytes.empty()
proposal.executed = false
proposal.successful = false
proposal.screeningVotesReceived = ZERO_BD
proposal.fundingVotesReceived = ZERO_BD
proposal.totalTokensRequested = ZERO_BD
Expand Down
2 changes: 0 additions & 2 deletions src/utils/grants/voter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export function getFundingVotesByProposalId(distributionPeriodVote: Distribution
const filteredVotes: Bytes[] = [];
const fundingVotes = distributionPeriodVote.fundingVotes;

log.info("getFundingVotesByProposalId: {} {}", [distributionPeriodVote.fundingVotes.length.toString(), proposalId.toString()])

for (let i = 0; i < fundingVotes.length; i++) {
const proposal = loadOrCreateFundingVote(fundingVotes[i]).proposal;
if (proposal.equals(proposalId)) {
Expand Down
Loading

0 comments on commit ba6a1ff

Please sign in to comment.