Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GrantFund Subgraph Improvements and Bugfixes #38

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable was removed from the contract

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
Loading