Skip to content

Commit

Permalink
fix tokensRequested
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Jul 27, 2023
1 parent 93cdff2 commit caa1ade
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
DistributionPeriodVote
} from "../generated/schema"

import { ONE_BI, THREE_PERCENT_BI, ZERO_ADDRESS, ZERO_BD } from './utils/constants'
import { EXP_18_BD, ONE_BI, THREE_PERCENT_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from './utils/constants'
import { addressArrayToBytesArray, addressToBytes, bigIntToBytes, bytesToBigInt, wadToDecimal } from "./utils/convert"
import { getProposalParamsId, getProposalsInSlate, loadOrCreateProposal, removeProposalFromList } from './utils/grants/proposal'
import { getCurrentDistributionId, getCurrentStage, loadOrCreateDistributionPeriod } from './utils/grants/distribution'
Expand Down Expand Up @@ -165,7 +165,7 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void {
const proposal = loadOrCreateProposal(proposalId)
proposal.description = event.params.description

let totalTokensRequested = ZERO_BD
let totalTokensRequested = ZERO_BI

// create ProposalParams entities for each separate proposal param
for (let i = 0; i < event.params.targets.length; i++) {
Expand All @@ -178,18 +178,19 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void {
// decode the calldata to get the recipient and tokens requested
const decoded = ethereum.decode('(address,uint256)', proposalParams.calldata)!
proposalParams.recipient = decoded.toTuple()[0].toAddress()
const tokensRequested = decoded.toTuple()[1].toBigInt().toBigDecimal()
proposalParams.tokensRequested = tokensRequested
const tokensRequested = decoded.toTuple()[1].toBigInt()
proposalParams.tokensRequested = wadToDecimal(tokensRequested)
totalTokensRequested = totalTokensRequested.plus(tokensRequested)

// add proposalParams information to proposal
proposal.params = proposal.params.concat([proposalParams.id])
proposal.totalTokensRequested = totalTokensRequested

// save each proposalParams entity to the store
proposalParams.save()
}

proposal.totalTokensRequested = wadToDecimal(totalTokensRequested)

proposalCreated.proposal = proposal.id

// update distribution entity
Expand Down
6 changes: 3 additions & 3 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe("Grant Fund assertions", () => {
"Proposal",
`${bigIntToBytes(proposalId).toHexString()}`,
"totalTokensRequested",
`${BigInt.fromI32(2)}`
`${wadToDecimal(BigInt.fromI32(2))}`
);

});
Expand Down Expand Up @@ -367,7 +367,7 @@ describe("Grant Fund assertions", () => {
"Proposal",
`${bigIntToBytes(proposalId).toHexString()}`,
"totalTokensRequested",
`${BigInt.fromI32(2)}`
`${wadToDecimal(BigInt.fromI32(2))}`
);

assert.fieldEquals(
Expand Down Expand Up @@ -822,7 +822,7 @@ describe("Grant Fund assertions", () => {
"FundedSlate",
`${fundedSlateHash.toHexString()}`,
"totalTokensRequested",
`${BigInt.fromI32(2)}`
`${wadToDecimal(BigInt.fromI32(2))}`
);
});
});

0 comments on commit caa1ade

Please sign in to comment.