Skip to content

Commit

Permalink
fix: potentially problematic edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Sep 17, 2024
1 parent 036f14b commit 7168170
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
19 changes: 14 additions & 5 deletions src/mappings/curation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,16 @@ export function handleBurned(event: Burned): void {
let gnsID = graphNetwork.gns.toHexString()
// Update signal
let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString()
let signalID = joinID([id, subgraphDeploymentID])

let signal = Signal.load(signalID)!
// Assuming signal is created since it's a burn can't be done, as signals can be transferred and
// we currently can't track transfers. On those edge cases values will be weird here, but
// overall network wide should still make sense
let signal = createOrLoadSignal(
id,
subgraphDeploymentID,
(addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32(),
event.block.timestamp.toI32(),
)
let gnsSignalOldAmount = signal.signal.toBigDecimal()

let isSignalBecomingInactive = !signal.signal.isZero() && event.params.signal == signal.signal
Expand Down Expand Up @@ -205,8 +212,10 @@ export function handleBurned(event: Burned): void {
gnsSignalNewAmount = gnsSignal != null ? gnsSignal.signal.toBigDecimal() : zeroBD
}

// Update curator
let curator = Curator.load(id)!
// Assuming curator is created since it's a burn can't be done, as signals can be transferred and
// we currently can't track transfers, thus this might be the first curation interaction of this
// account
let curator = createOrLoadCurator(event.params.curator, event.block.timestamp)
curator.totalUnsignalledTokens = curator.totalUnsignalledTokens.plus(event.params.tokens)
curator.totalSignal = curator.totalSignal.minus(event.params.signal.toBigDecimal())
curator.totalSignalAverageCostBasis = curator.totalSignalAverageCostBasis.minus(diffACB)
Expand All @@ -229,7 +238,7 @@ export function handleBurned(event: Burned): void {

curator.save()

// Update subgraph
// Deployment can be safely assumed as existing, since someone had to have signaled in order to burn
let deployment = SubgraphDeployment.load(subgraphDeploymentID)!
let oldSignalAmount = deployment.signalAmount
let oldSignalledTokens = deployment.signalledTokens
Expand Down
26 changes: 15 additions & 11 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,13 @@ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void {
graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1
graphNetwork.save()

let version = SubgraphVersion.load(subgraph.currentVersion!)
if (version != null) {
let deployment = SubgraphDeployment.load(version.subgraphDeployment)
if (subgraph.currentVersion != null) {
let version = SubgraphVersion.load(subgraph.currentVersion!)
if (version != null) {
let deployment = SubgraphDeployment.load(version.subgraphDeployment)

updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true)
updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true)
}
}
}

Expand Down Expand Up @@ -612,7 +614,7 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void {
nameSignal.signalAverageCostBasisPerSignal = BigDecimal.fromString('0')
nameSignal.save()

let curator = Curator.load(event.params.nameCurator.toHexString())!
let curator = createOrLoadCurator(event.params.nameCurator, event.block.timestamp)
curator.totalWithdrawnTokens = curator.totalWithdrawnTokens.plus(event.params.withdrawnGRT)
curator.save()
}
Expand Down Expand Up @@ -701,11 +703,13 @@ export function handleSubgraphDeprecatedV2(event: SubgraphDeprecated1): void {
graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1
graphNetwork.save()

let version = SubgraphVersion.load(subgraph.currentVersion!)
if (version != null) {
let deployment = SubgraphDeployment.load(version.subgraphDeployment)
if (subgraph.currentVersion != null) {
let version = SubgraphVersion.load(subgraph.currentVersion!)
if (version != null) {
let deployment = SubgraphDeployment.load(version.subgraphDeployment)

updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true)
updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true)
}
}
}

Expand Down Expand Up @@ -990,7 +994,7 @@ export function handleGRTWithdrawnV2(event: GRTWithdrawn1): void {

nameSignal.save()

let curator = Curator.load(event.params.curator.toHexString())!
let curator = createOrLoadCurator(event.params.curator, event.block.timestamp)
curator.totalWithdrawnTokens = curator.totalWithdrawnTokens.plus(event.params.withdrawnGRT)
curator.save()
}
Expand Down Expand Up @@ -1131,7 +1135,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
// create deployment - named subgraph relationship, and update the old one
updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph)
subgraphVersion.save()

let context = new DataSourceContext()
context.setString('id', metadataId)
SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context)
Expand Down

0 comments on commit 7168170

Please sign in to comment.