diff --git a/schema.graphql b/schema.graphql index a8d83b3..3c500b2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -807,6 +807,7 @@ type DistributionPeriod @entity { type Proposal @entity { id: Bytes! # proposal id converted to Bytes from uint + proposalId: BigInt! # proposal id stored in original uint format 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 diff --git a/src/grant-fund.ts b/src/grant-fund.ts index c436d7b..7d72d9f 100644 --- a/src/grant-fund.ts +++ b/src/grant-fund.ts @@ -123,7 +123,7 @@ export function handleFundedSlateUpdated(event: FundedSlateUpdatedEvent): void { for (let i = 0; i < proposalsInSlate.length; i++) { const proposalId = proposalsInSlate[i] - const proposal = loadOrCreateProposal(bigIntToBytes(proposalId)) + const proposal = loadOrCreateProposal(proposalId) totalTokensRequested = totalTokensRequested.plus(proposal.totalTokensRequested) totalFundingVotesReceived = totalFundingVotesReceived.plus(proposal.fundingVotesReceived) @@ -162,7 +162,7 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void { // create Proposal entity const proposalId = bigIntToBytes(event.params.proposalId) - const proposal = loadOrCreateProposal(proposalId) + const proposal = loadOrCreateProposal(event.params.proposalId) proposal.description = event.params.description let totalTokensRequested = ZERO_BI @@ -222,7 +222,7 @@ export function handleProposalExecuted(event: ProposalExecutedEvent): void { proposalExecuted.transactionHash = event.transaction.hash // update proposal entity - const proposal = loadOrCreateProposal(bigIntToBytes(event.params.proposalId)) + const proposal = loadOrCreateProposal(event.params.proposalId) proposal.executed = true const distributionPeriod = DistributionPeriod.load(proposal.distribution!)! diff --git a/src/utils/grants/proposal.ts b/src/utils/grants/proposal.ts index 0dbdbcd..a739ecd 100644 --- a/src/utils/grants/proposal.ts +++ b/src/utils/grants/proposal.ts @@ -3,7 +3,7 @@ import { Proposal, ProposalParams } from "../../../generated/schema" import { GrantFund } from "../../../generated/GrantFund/GrantFund" import { ZERO_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from "../constants" -import { bytesToBigInt } from "../convert" +import { bigIntToBytes, bytesToBigInt } from "../convert" export function getProposalParamsId(proposalId: Bytes, paramIndex: number): Bytes { return proposalId @@ -11,11 +11,13 @@ export function getProposalParamsId(proposalId: Bytes, paramIndex: number): Byte .concat(Bytes.fromUTF8(paramIndex.toString())) } -export function loadOrCreateProposal(proposalId: Bytes): Proposal { - let proposal = Proposal.load(proposalId) +export function loadOrCreateProposal(proposalId: BigInt): Proposal { + const proposalIdBytes = bigIntToBytes(proposalId) + let proposal = Proposal.load(proposalIdBytes) if (proposal == null) { // create new proposal if one hasn't already been stored - proposal = new Proposal(proposalId) as Proposal + proposal = new Proposal(proposalIdBytes) as Proposal + proposal.proposalId = proposalId proposal.description = "" proposal.distribution = Bytes.empty() proposal.executed = false diff --git a/tests/grant-fund.test.ts b/tests/grant-fund.test.ts index 78a0da2..55b9d91 100644 --- a/tests/grant-fund.test.ts +++ b/tests/grant-fund.test.ts @@ -252,6 +252,13 @@ describe("Grant Fund assertions", () => { const expectedDistributionId = bigIntToBytes(distributionId).toHexString(); + assert.fieldEquals( + "Proposal", + `${bigIntToBytes(proposalId).toHexString()}`, + "proposalId", + `${proposalId}` + ); + assert.fieldEquals( "Proposal", `${bigIntToBytes(proposalId).toHexString()}`,