Skip to content

Commit

Permalink
updated grant fund events to use bigdecimal for decimal amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
EdNoepel committed Aug 9, 2023
1 parent 34bad1a commit 0dd39f0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
10 changes: 5 additions & 5 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ type DelegateChanged @entity(immutable: true) {
type DelegateVotesChanged @entity(immutable: true) {
id: Bytes!
delegate: Bytes! # address
previousBalance: BigInt! # uint256
newBalance: BigInt! # uint256
previousBalance: BigDecimal! # uint256
newBalance: BigDecimal! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
Expand All @@ -901,7 +901,7 @@ type DelegateRewardClaimed @entity(immutable: true) {
type FundTreasury @entity(immutable: true) {
id: Bytes!
amount: BigInt! # uint256
treasuryBalance: BigInt! # uint256
treasuryBalance: BigDecimal! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
Expand All @@ -921,7 +921,7 @@ type ProposalCreated @entity(immutable: true) {
proposal: Proposal!
proposer: Bytes! # address
targets: [Bytes!]! # address[]
values: [BigInt!]! # uint256[]
values: [BigDecimal!]! # uint256[]
signatures: [String!]! # string[]
calldatas: [Bytes!]! # bytes[]
startBlock: BigInt! # uint256
Expand Down Expand Up @@ -955,7 +955,7 @@ type VoteCast @entity(immutable: true) {
voter: Bytes! # address # TODO: should be Account
proposalId: BigInt! # uint256
support: Int! # uint8
weight: BigInt! # uint256
weight: BigDecimal! # uint256
reason: String! # string
blockNumber: BigInt!
blockTimestamp: BigInt!
Expand Down
4 changes: 2 additions & 2 deletions src/ajna-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function handleDelegateVotesChanged(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.delegate = event.params.delegate
entity.previousBalance = event.params.previousBalance
entity.newBalance = event.params.newBalance
entity.previousBalance = wadToDecimal(event.params.previousBalance)
entity.newBalance = wadToDecimal(event.params.newBalance)
const changeInBalance = wadToDecimal(event.params.newBalance.minus(event.params.previousBalance))

entity.blockNumber = event.block.number
Expand Down
8 changes: 4 additions & 4 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "../generated/schema"

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 { addressArrayToBytesArray, addressToBytes, bigIntArrayToBigDecimalArray, bigIntToBytes, bytesToBigInt, wadToDecimal } from "./utils/convert"
import { getProposalParamsId, getProposalsInSlate, loadOrCreateProposal, removeProposalFromList } from './utils/grants/proposal'
import { getCurrentDistributionId, getCurrentStage, loadOrCreateDistributionPeriod } from './utils/grants/distribution'
import { getFundingStageVotingPower, getFundingVoteId, getFundingVotingPowerUsed, getScreeningStageVotingPower, getScreeningVoteId, loadOrCreateDistributionPeriodVote } from './utils/grants/voter'
Expand Down Expand Up @@ -79,7 +79,7 @@ export function handleFundTreasury(event: FundTreasuryEvent): void {
event.transaction.hash.concatI32(event.logIndex.toI32())
)
fundTreasury.amount = event.params.amount
fundTreasury.treasuryBalance = event.params.treasuryBalance
fundTreasury.treasuryBalance = wadToDecimal(event.params.treasuryBalance)

fundTreasury.blockNumber = event.block.number
fundTreasury.blockTimestamp = event.block.timestamp
Expand Down Expand Up @@ -149,7 +149,7 @@ export function handleProposalCreated(event: ProposalCreatedEvent): void {
)
proposalCreated.proposer = event.params.proposer
proposalCreated.targets = addressArrayToBytesArray(event.params.targets)
proposalCreated.values = event.params.values
proposalCreated.values = bigIntArrayToBigDecimalArray(event.params.values)
proposalCreated.signatures = event.params.signatures
proposalCreated.calldatas = event.params.calldatas
proposalCreated.startBlock = event.params.startBlock
Expand Down Expand Up @@ -275,7 +275,7 @@ export function handleVoteCast(event: VoteCastEvent): void {
voteCast.voter = event.params.voter
voteCast.proposalId = event.params.proposalId
voteCast.support = event.params.support
voteCast.weight = event.params.weight
voteCast.weight = wadToDecimal(event.params.weight)
voteCast.reason = event.params.reason

voteCast.blockNumber = event.block.number
Expand Down
8 changes: 8 additions & 0 deletions src/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ export function bigIntArrayToIntArray(indexes: BigInt[]): i32[] {
return retval
}

export function bigIntArrayToBigDecimalArray(indexes: BigInt[]): BigDecimal[] {
const retval: BigDecimal[] = [];
for (let i=0; i<indexes.length; ++i) {
retval.push(wadToDecimal(indexes[i]))
}
return retval
}

export function indexToPrice(index: u32): BigDecimal {
const bucketIndex = MAX_BUCKET_INDEX - index;
assert(bucketIndex >= MIN_BUCKET_INDEX && bucketIndex <= MAX_BUCKET_INDEX, 'Invalid bucket index')
Expand Down
2 changes: 1 addition & 1 deletion tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe("Grant Fund assertions", () => {
"FundTreasury",
`0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000`,
"treasuryBalance",
`${treasuryBalance}`
`${wadToDecimal(treasuryBalance)}`
);
});

Expand Down

0 comments on commit 0dd39f0

Please sign in to comment.