Skip to content

Commit 234cde4

Browse files
committed
feat: BigInt usage refactor and fixes
1 parent fffaf84 commit 234cde4

File tree

7 files changed

+212
-200
lines changed

7 files changed

+212
-200
lines changed

src/mappings/curation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SubgraphDeployment,
1313
SignalTransaction,
1414
} from '../types/schema'
15-
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
15+
import { Bytes } from '@graphprotocol/graph-ts'
1616

1717
import {
1818
createOrLoadSignal,
@@ -23,6 +23,7 @@ import {
2323
calculatePricePerShare,
2424
getAndUpdateNetworkDailyData,
2525
compoundId,
26+
BIGINT_ZERO,
2627
} from './helpers'
2728

2829
/**
@@ -76,7 +77,7 @@ export function handleSignalled(event: Signalled): void {
7677
signalTransaction.type = 'MintSignal'
7778
signalTransaction.signal = event.params.signal
7879
signalTransaction.tokens = event.params.tokens.minus(event.params.curationTax)
79-
signalTransaction.withdrawalFees = BigInt.fromI32(0)
80+
signalTransaction.withdrawalFees = BIGINT_ZERO
8081
signalTransaction.subgraphDeployment = event.params.subgraphDeploymentID
8182
signalTransaction.save()
8283

@@ -127,7 +128,7 @@ export function handleBurned(event: Burned): void {
127128
signalTransaction.type = 'BurnSignal'
128129
signalTransaction.signal = event.params.signal
129130
signalTransaction.tokens = event.params.tokens
130-
signalTransaction.withdrawalFees = BigInt.fromI32(0)
131+
signalTransaction.withdrawalFees = BIGINT_ZERO
131132
signalTransaction.subgraphDeployment = event.params.subgraphDeploymentID
132133
signalTransaction.save()
133134

src/mappings/gns.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigDecimal, BigInt, Bytes, ipfs, json } from '@graphprotocol/graph-ts'
1+
import { BigDecimal, Bytes, ipfs, json } from '@graphprotocol/graph-ts'
22
import {
33
SubgraphPublished,
44
SubgraphDeprecated,
@@ -45,6 +45,7 @@ import {
4545
convertBigIntSubgraphIDToBase58,
4646
compoundId,
4747
joinIDString,
48+
BIGINT_ONE,
4849
} from './helpers'
4950

5051
export function handleSetDefaultName(event: SetDefaultName): void {
@@ -134,17 +135,16 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
134135
*/
135136
export function handleSubgraphPublished(event: SubgraphPublished): void {
136137
let subgraphID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber)
137-
let versionNumber: BigInt
138138

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

142-
versionNumber = subgraph.versionCount
142+
let versionNumber = subgraph.versionCount
143143
let versionIDNew = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
144144
subgraph.creatorAddress = event.params.graphAccount
145145
subgraph.subgraphNumber = event.params.subgraphNumber
146146
subgraph.oldID = joinIDString([event.params.graphAccount.toHexString(), event.params.subgraphNumber.toString()])
147-
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
147+
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
148148
subgraph.updatedAt = event.block.timestamp.toI32()
149149

150150
subgraph.currentVersion = versionIDNew
@@ -374,18 +374,18 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void {
374374
export function handleSubgraphPublishedV2(event: SubgraphPublished1): void {
375375
let bigIntID = event.params.subgraphID
376376
let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID)
377-
let versionID: Bytes
378-
let versionNumber: BigInt
377+
379378

380379
// Update subgraph
381380
let subgraph = createOrLoadSubgraph(
382381
event.params.subgraphID,
383382
event.transaction.from,
384383
event.block.timestamp,
385384
)
386-
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
385+
let versionNumber = subgraph.versionCount
386+
let versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
387387
subgraph.currentVersion = versionID
388-
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
388+
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
389389
subgraph.updatedAt = event.block.timestamp.toI32()
390390
subgraph.reserveRatio = event.params.reserveRatio.toI32()
391391
subgraph.migrated = true
@@ -602,7 +602,6 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
602602
let bigIntID = event.params.subgraphID
603603
let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID)
604604
let versionID: Bytes
605-
let versionNumber: BigInt
606605

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

614613
// Update already initialized subgraph version
615-
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount.minus(BigInt.fromI32(1)))))
614+
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount.minus(BIGINT_ONE))))
616615
let subgraphVersion = SubgraphVersion.load(versionID)!
617616
// let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
618617
// let base58Hash = hexHash.toBase58()
619618
subgraphVersion.metadataHash = event.params.versionMetadata
620619
//subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash)
621620
subgraphVersion.save()
622621
} else {
623-
versionNumber = subgraph.versionCount
622+
let versionNumber = subgraph.versionCount
624623
versionID = compoundId(subgraph.id, changetype<Bytes>(Bytes.fromBigInt(subgraph.versionCount)))
625624
subgraph.currentVersion = versionID
626-
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
625+
subgraph.versionCount = subgraph.versionCount.plus(BIGINT_ONE)
627626
subgraph.updatedAt = event.block.timestamp.toI32()
628627
subgraph.save()
629628

0 commit comments

Comments
 (0)