Skip to content

Commit c0fa6da

Browse files
committed
fix: addressed AllocationManagement pr feedback
1 parent de79068 commit c0fa6da

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ type Allocation @entity {
10441044
poi: Bytes
10451045
"POIs submitted when collecting payments in Horizon"
10461046
pois: [PoiSubmission!]! @derivedFrom(field: "allocation")
1047+
"Number of POIs submitted for this allocation. Only available for Horizon allocations"
1048+
poiCount: BigInt
1049+
"Whether this allocation was created in the legacy protocol. If true, the allocation will not have a provision since it's not a Horizon allocation"
1050+
isLegacy: Boolean!
1051+
"Whether this allocation was forced closed. Force closures in Horizon can happen when the latest PoI is stale, compared to the legacy protocol, where force closures can happen when the allocation hasn't been closed within the max amount of epochs"
1052+
forceClosed: Boolean
10471053

10481054
# Indexer/Provision cut settings at start and close
10491055
indexingRewardCutAtStart: Int!

src/mappings/staking.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ export function handleAllocationCreated(event: AllocationCreated): void {
374374
allocation.indexingRewardEffectiveCutAtStart = indexer.indexingRewardEffectiveCut
375375
allocation.queryFeeCutAtStart = indexer.queryFeeCut
376376
allocation.queryFeeEffectiveCutAtStart = indexer.queryFeeEffectiveCut
377+
allocation.isLegacy = true
377378
allocation.save()
378379
}
379380

@@ -493,12 +494,16 @@ export function handleAllocationClosed(event: AllocationClosed): void {
493494

494495
// update indexer
495496
let indexer = Indexer.load(indexerID)!
497+
let allocation = Allocation.load(allocationID)!
496498
const indexerAccount = GraphAccount.load(indexer.account)!
497499
const closedByIndexer = event.params.sender == event.params.indexer
498500
const closedByOperator = indexerAccount.operators.includes(event.params.sender.toHexString())
499501

500502
if (!closedByIndexer && !closedByOperator) {
501503
indexer.forcedClosures = indexer.forcedClosures + 1
504+
allocation.forceClosed = true
505+
} else {
506+
allocation.forceClosed = false
502507
}
503508
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
504509
indexer.allocationCount = indexer.allocationCount - 1
@@ -507,7 +512,6 @@ export function handleAllocationClosed(event: AllocationClosed): void {
507512
indexer.save()
508513

509514
// update allocation
510-
let allocation = Allocation.load(allocationID)!
511515
allocation.poolClosedIn = event.params.epoch.toString()
512516
allocation.activeForIndexer = null
513517
allocation.closedAtEpoch = event.params.epoch.toI32()
@@ -561,12 +565,16 @@ export function handleAllocationClosedCobbDouglas(event: AllocationClosed1): voi
561565

562566
// update indexer
563567
let indexer = Indexer.load(indexerID)!
568+
let allocation = Allocation.load(allocationID)!
564569
const indexerAccount = GraphAccount.load(indexer.account)!
565570
const closedByIndexer = event.params.sender == event.params.indexer
566571
const closedByOperator = indexerAccount.operators.includes(event.params.sender.toHexString())
567572

568573
if (!closedByIndexer && !closedByOperator) {
569574
indexer.forcedClosures = indexer.forcedClosures + 1
575+
allocation.forceClosed = true
576+
} else {
577+
allocation.forceClosed = false
570578
}
571579
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
572580
indexer.allocationCount = indexer.allocationCount - 1
@@ -575,7 +583,6 @@ export function handleAllocationClosedCobbDouglas(event: AllocationClosed1): voi
575583
indexer.save()
576584

577585
// update allocation
578-
let allocation = Allocation.load(allocationID)!
579586
allocation.poolClosedIn = event.params.epoch.toString()
580587
allocation.activeForIndexer = null
581588
allocation.closedAtEpoch = event.params.epoch.toI32()

src/mappings/subgraphService.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ export function handleAllocationCreated(event: AllocationCreated): void {
8888
allocation.annualizedReturn = BigDecimal.fromString('0')
8989
allocation.createdAt = event.block.timestamp.toI32()
9090
allocation.indexingRewardCutAtStart = provision.indexingRewardsCut.toI32()
91-
allocation.indexingRewardEffectiveCutAtStart = provision.indexingRewardsCut.toBigDecimal()
91+
allocation.indexingRewardEffectiveCutAtStart = provision.indexingRewardEffectiveCut
9292
allocation.queryFeeCutAtStart = provision.queryFeeCut.toI32()
93-
allocation.queryFeeEffectiveCutAtStart = provision.queryFeeCut.toBigDecimal()
93+
allocation.queryFeeEffectiveCutAtStart = provision.queryFeeEffectiveCut
94+
allocation.poiCount = BigInt.fromI32(0)
95+
allocation.isLegacy = false
9496
allocation.save()
9597
}
9698

@@ -101,12 +103,16 @@ export function handleAllocationClosed(event: AllocationClosed): void {
101103

102104
// update indexer
103105
let indexer = Indexer.load(indexerID)!
106+
let allocation = Allocation.load(allocationID)!
104107
const indexerAccount = GraphAccount.load(indexer.account)!
105108
const closedByIndexer = event.transaction.from == event.params.indexer
106109
const closedByOperator = indexerAccount.operators.includes(event.transaction.from.toHexString())
107110

108111
if (!closedByIndexer && !closedByOperator) {
109112
indexer.forcedClosures = indexer.forcedClosures + 1
113+
allocation.forceClosed = true
114+
} else {
115+
allocation.forceClosed = false
110116
}
111117
indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens)
112118
indexer.allocationCount = indexer.allocationCount - 1
@@ -119,7 +125,6 @@ export function handleAllocationClosed(event: AllocationClosed): void {
119125
provision.save()
120126

121127
// update allocation
122-
let allocation = Allocation.load(allocationID)!
123128
allocation.poolClosedIn = graphNetwork.currentEpoch.toString()
124129
allocation.activeForIndexer = null
125130
allocation.closedAtEpoch = graphNetwork.currentEpoch
@@ -129,10 +134,10 @@ export function handleAllocationClosed(event: AllocationClosed): void {
129134
).toI32()
130135
allocation.status = 'Closed'
131136
allocation.closedAt = event.block.timestamp.toI32()
132-
allocation.indexingRewardCutAtStart = provision.indexingRewardsCut.toI32()
133-
allocation.indexingRewardEffectiveCutAtStart = provision.indexingRewardsCut.toBigDecimal()
134-
allocation.queryFeeCutAtStart = provision.queryFeeCut.toI32()
135-
allocation.queryFeeEffectiveCutAtStart = provision.queryFeeCut.toBigDecimal()
137+
allocation.indexingRewardCutAtClose = provision.indexingRewardsCut.toI32()
138+
allocation.indexingRewardEffectiveCutAtClose = provision.indexingRewardEffectiveCut
139+
allocation.queryFeeCutAtClose = provision.queryFeeCut.toI32()
140+
allocation.queryFeeEffectiveCutAtClose = provision.queryFeeEffectiveCut
136141
allocation.save()
137142

138143
// update epoch - We do it here to have more epochs created, instead of seeing none created
@@ -201,6 +206,7 @@ export function handleIndexingRewardsCollected(event: IndexingRewardsCollected):
201206
allocation.indexingDelegatorRewards = allocation.indexingDelegatorRewards.plus(
202207
event.params.tokensDelegationRewards,
203208
)
209+
allocation.poiCount = allocation.poiCount!.plus(BigInt.fromI32(1))
204210
allocation.save()
205211

206212
// Create PoI submission

0 commit comments

Comments
 (0)