Skip to content

Commit f715805

Browse files
committed
fix: track legacy allocated amount
Signed-off-by: Tomás Migone <[email protected]>
1 parent 3c959a6 commit f715805

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

schema.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,10 @@ type Indexer @entity(immutable: false) {
745745
provisionedTokens: BigInt!
746746
"CURRENT tokens thawing from provisions to data services in the protocol. Only for Horizon"
747747
thawingTokens: BigInt!
748-
"CURRENT tokens allocated on all subgraphs"
748+
"CURRENT tokens allocated on all subgraphs - including legacy and horizon allocations"
749749
allocatedTokens: BigInt!
750+
"[Legacy only] CURRENT tokens allocated on all subgraphs ONLY for legacy allocations"
751+
legacyAllocatedTokens: BigInt!
750752
"NOT IMPLEMENTED - Tokens that have been unstaked and withdrawn"
751753
unstakedTokens: BigInt! # will be used for return % calcs
752754
"CURRENT tokens locked"

src/mappings/helpers/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export function createOrLoadIndexer(indexerAddress: Bytes, timestamp: BigInt ):
146146
indexer.provisionedTokens = BigInt.fromI32(0)
147147
indexer.thawingTokens = BigInt.fromI32(0)
148148
indexer.allocatedTokens = BigInt.fromI32(0)
149+
indexer.legacyAllocatedTokens = BigInt.fromI32(0)
149150
indexer.lockedTokens = BigInt.fromI32(0)
150151
indexer.legacyLockedTokens = BigInt.fromI32(0)
151152
indexer.unstakedTokens = BigInt.fromI32(0)

src/mappings/staking.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function handleStakeSlashed(event: StakeSlashed): void {
163163

164164
// When tokens are slashed, locked tokens might need to be unlocked if indexer overallocated
165165
if (slashedTokens.gt(BigInt.fromI32(0))) {
166-
let tokensUsed = indexer.allocatedTokens.plus(indexer.legacyLockedTokens)
166+
let tokensUsed = indexer.legacyAllocatedTokens.plus(indexer.legacyLockedTokens)
167167
let tokensAvailable = tokensUsed.gt(indexer.stakedTokens)
168168
? BigInt.fromI32(0)
169169
: indexer.stakedTokens.minus(tokensUsed)
@@ -349,6 +349,7 @@ export function handleAllocationCreated(event: AllocationCreated): void {
349349

350350
// update indexer
351351
let indexer = Indexer.load(indexerID)!
352+
indexer.legacyAllocatedTokens = indexer.legacyAllocatedTokens.plus(event.params.tokens)
352353
indexer.allocatedTokens = indexer.allocatedTokens.plus(event.params.tokens)
353354
indexer.totalAllocationCount = indexer.totalAllocationCount.plus(BigInt.fromI32(1))
354355
indexer.allocationCount = indexer.allocationCount + 1
@@ -529,6 +530,7 @@ export function handleAllocationClosed(event: AllocationClosed): void {
529530
allocation.forceClosed = false
530531
}
531532
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
533+
indexer.legacyAllocatedTokens = indexer.legacyAllocatedTokens.minus(event.params.tokens)
532534
indexer.allocationCount = indexer.allocationCount - 1
533535
indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer)
534536
indexer = calculateCapacities(indexer as Indexer)
@@ -591,6 +593,7 @@ export function handleAllocationClosedCobbDouglas(event: AllocationClosed1): voi
591593
} else {
592594
allocation.forceClosed = false
593595
}
596+
indexer.legacyAllocatedTokens = indexer.legacyAllocatedTokens.minus(event.params.tokens)
594597
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
595598
indexer.allocationCount = indexer.allocationCount - 1
596599
indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer)

0 commit comments

Comments
 (0)