Skip to content

Commit 907d22d

Browse files
committed
fix: update allocation close to latest signature
Signed-off-by: Tomás Migone <[email protected]>
1 parent bae916e commit 907d22d

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

abis/SubgraphService.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@
574574
"internalType": "uint256",
575575
"name": "tokens",
576576
"type": "uint256"
577+
},
578+
{
579+
"indexed": false,
580+
"internalType": "bool",
581+
"name": "forceClosed",
582+
"type": "bool"
577583
}
578584
],
579585
"name": "AllocationClosed",

src/mappings/subgraphService.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,11 @@ export function handleAllocationClosed(event: AllocationClosed): void {
133133
// update indexer
134134
let indexer = Indexer.load(indexerID)!
135135
let allocation = Allocation.load(allocationID)!
136-
const indexerAccount = GraphAccount.load(indexer.account)!
137-
const closedByIndexer = event.transaction.from == event.params.indexer
138-
const closedByOperator = indexerAccount.operators.includes(event.transaction.from.toHexString())
139136

140-
if (!closedByIndexer && !closedByOperator) {
137+
if (event.params.forceClosed) {
141138
indexer.forcedClosures = indexer.forcedClosures + 1
142-
allocation.forceClosed = true
143-
} else {
144-
allocation.forceClosed = false
145139
}
140+
146141
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
147142
indexer.allocationCount = indexer.allocationCount - 1
148143
indexer.save()
@@ -154,6 +149,7 @@ export function handleAllocationClosed(event: AllocationClosed): void {
154149
provision.save()
155150

156151
// update allocation
152+
allocation.forceClosed = event.params.forceClosed
157153
allocation.poolClosedIn = graphNetwork.currentEpoch.toString()
158154
allocation.activeForIndexer = null
159155
allocation.closedAtEpoch = graphNetwork.currentEpoch
@@ -185,6 +181,11 @@ export function handleAllocationClosed(event: AllocationClosed): void {
185181
graphNetwork.activeAllocationCount = graphNetwork.activeAllocationCount - 1
186182
graphNetwork.totalTokensAllocated = graphNetwork.totalTokensAllocated.minus(event.params.tokens)
187183
graphNetwork.save()
184+
185+
// update data service
186+
let dataService = createOrLoadDataService(event.address)
187+
dataService.totalTokensAllocated = dataService.totalTokensAllocated.minus(event.params.tokens)
188+
dataService.save()
188189
}
189190

190191
export function handleAllocationResized(event: AllocationResized): void {

subgraph.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ dataSources:
467467
handler: handleAllocationCreated
468468
- event: AllocationResized(indexed address,indexed address,indexed bytes32,uint256,uint256)
469469
handler: handleAllocationResized
470-
- event: AllocationClosed(indexed address,indexed address,indexed bytes32,uint256)
470+
- event: AllocationClosed(indexed address,indexed address,indexed bytes32,uint256,bool)
471471
handler: handleAllocationClosed
472472
- event: IndexingRewardsCollected(indexed address,indexed address,indexed bytes32,uint256,uint256,uint256,bytes32,uint256)
473473
handler: handleIndexingRewardsCollected

0 commit comments

Comments
 (0)