Skip to content

Commit

Permalink
feat: BigInt usage refactor and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed May 22, 2024
1 parent d76fa7e commit 1bdfebe
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 200 deletions.
7 changes: 4 additions & 3 deletions src/mappings/curation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SubgraphDeployment,
SignalTransaction,
} from '../types/schema'
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
import { Bytes } from '@graphprotocol/graph-ts'

import {
createOrLoadSignal,
Expand All @@ -23,6 +23,7 @@ import {
calculatePricePerShare,
getAndUpdateNetworkDailyData,
compoundId,
BIGINT_ZERO,
} from './helpers'

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ export function handleSignalled(event: Signalled): void {
signalTransaction.type = 'MintSignal'
signalTransaction.signal = event.params.signal
signalTransaction.tokens = event.params.tokens.minus(event.params.curationTax)
signalTransaction.withdrawalFees = BigInt.fromI32(0)
signalTransaction.withdrawalFees = BIGINT_ZERO
signalTransaction.subgraphDeployment = event.params.subgraphDeploymentID
signalTransaction.save()

Expand Down Expand Up @@ -127,7 +128,7 @@ export function handleBurned(event: Burned): void {
signalTransaction.type = 'BurnSignal'
signalTransaction.signal = event.params.signal
signalTransaction.tokens = event.params.tokens
signalTransaction.withdrawalFees = BigInt.fromI32(0)
signalTransaction.withdrawalFees = BIGINT_ZERO
signalTransaction.subgraphDeployment = event.params.subgraphDeploymentID
signalTransaction.save()

Expand Down
23 changes: 11 additions & 12 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigDecimal, BigInt, Bytes, ipfs, json } from '@graphprotocol/graph-ts'
import { BigDecimal, Bytes, ipfs, json } from '@graphprotocol/graph-ts'
import {
SubgraphPublished,
SubgraphDeprecated,
Expand Down Expand Up @@ -45,6 +45,7 @@ import {
convertBigIntSubgraphIDToBase58,
compoundId,
joinIDString,
BIGINT_ONE,
} from './helpers'

export function handleSetDefaultName(event: SetDefaultName): void {
Expand Down Expand Up @@ -134,17 +135,16 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
*/
export function handleSubgraphPublished(event: SubgraphPublished): void {
let subgraphID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber)
let versionNumber: BigInt

// Update subgraph
let subgraph = createOrLoadSubgraph(subgraphID, event.params.graphAccount, event.block.timestamp)

versionNumber = subgraph.versionCount
let versionNumber = subgraph.versionCount
let versionIDNew = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
subgraph.creatorAddress = event.params.graphAccount
subgraph.subgraphNumber = event.params.subgraphNumber
subgraph.oldID = joinIDString([event.params.graphAccount.toHexString(), event.params.subgraphNumber.toString()])
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
subgraph.updatedAt = event.block.timestamp.toI32()

subgraph.currentVersion = versionIDNew
Expand Down Expand Up @@ -374,18 +374,18 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void {
export function handleSubgraphPublishedV2(event: SubgraphPublished1): void {
let bigIntID = event.params.subgraphID
let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID)
let versionID: Bytes
let versionNumber: BigInt


// Update subgraph
let subgraph = createOrLoadSubgraph(
event.params.subgraphID,
event.transaction.from,
event.block.timestamp,
)
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
let versionNumber = subgraph.versionCount
let versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
subgraph.currentVersion = versionID
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
subgraph.updatedAt = event.block.timestamp.toI32()
subgraph.reserveRatio = event.params.reserveRatio.toI32()
subgraph.migrated = true
Expand Down Expand Up @@ -602,7 +602,6 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
let bigIntID = event.params.subgraphID
let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID)
let versionID: Bytes
let versionNumber: BigInt

// Update subgraph
let subgraph = Subgraph.load(subgraphID)!
Expand All @@ -612,18 +611,18 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
subgraph.save()

// Update already initialized subgraph version
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount.minus(BigInt.fromI32(1)))))
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount.minus(BIGINT_ONE))))
let subgraphVersion = SubgraphVersion.load(versionID)!
// let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
// let base58Hash = hexHash.toBase58()
subgraphVersion.metadataHash = event.params.versionMetadata
//subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash)
subgraphVersion.save()
} else {
versionNumber = subgraph.versionCount
let versionNumber = subgraph.versionCount
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
subgraph.currentVersion = versionID
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
subgraph.updatedAt = event.block.timestamp.toI32()
subgraph.save()

Expand Down
Loading

0 comments on commit 1bdfebe

Please sign in to comment.