Skip to content

Commit

Permalink
ProposalId Update (#45)
Browse files Browse the repository at this point in the history
* add proposalId field with original uint to Proposal entity

* add basic test

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
MikeHathaway and Mike authored Aug 9, 2023
1 parent bf64ab8 commit 14cb348
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!)!
Expand Down
10 changes: 6 additions & 4 deletions src/utils/grants/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ 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
.concat(Bytes.fromUTF8('|'))
.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
Expand Down
7 changes: 7 additions & 0 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
Expand Down

0 comments on commit 14cb348

Please sign in to comment.