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

ProposalId Update #45

Merged
merged 2 commits into from
Aug 9, 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: 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
Loading