Skip to content

Commit fa6b831

Browse files
committed
fix: few things about indexing rewards and pois
Signed-off-by: Tomás Migone <[email protected]>
1 parent 0cd6bfa commit fa6b831

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

abis/SubgraphService.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,12 @@
803803
"name": "poi",
804804
"type": "bytes32"
805805
},
806+
{
807+
"indexed": false,
808+
"internalType": "bytes32",
809+
"name": "publicPoi",
810+
"type": "bytes32"
811+
},
806812
{
807813
"indexed": false,
808814
"internalType": "uint256",

schema.graphql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,12 @@ type Allocation @entity {
10921092
poi: Bytes
10931093
"POIs submitted when collecting payments in Horizon"
10941094
pois: [PoiSubmission!]! @derivedFrom(field: "allocation")
1095+
"Public POIs submitted when collecting payments in Horizon"
1096+
publicPois: [PublicPoiSubmission!]! @derivedFrom(field: "allocation")
10951097
"Number of POIs submitted for this allocation. Only available for Horizon allocations"
10961098
poiCount: BigInt
1099+
"Timestamp for the latest POI presentation"
1100+
latestPoiPresentedAt: Int
10971101
"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"
10981102
isLegacy: Boolean!
10991103
"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"
@@ -1125,6 +1129,20 @@ type PoiSubmission @entity {
11251129
poi: Bytes!
11261130

11271131
submittedAtEpoch: Int!
1132+
1133+
presentedAtTimestamp: Int!
1134+
}
1135+
1136+
type PublicPoiSubmission @entity {
1137+
id: ID!
1138+
1139+
allocation: Allocation!
1140+
1141+
publicPoi: Bytes!
1142+
1143+
submittedAtEpoch: Int!
1144+
1145+
presentedAtTimestamp: Int!
11281146
}
11291147

11301148
enum AllocationStatus {

src/mappings/subgraphService.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigDecimal, BigInt, ethereum, log } from "@graphprotocol/graph-ts"
22
import { AllocationClosed, AllocationCreated, AllocationResized, CurationCutSet, DelegationRatioSet, IndexingRewardsCollected, MaxPOIStalenessSet, ProvisionTokensRangeSet, QueryFeesCollected, RewardsDestinationSet, ServiceProviderRegistered, StakeToFeesRatioSet, ThawingPeriodRangeSet, VerifierCutRangeSet } from "../types/SubgraphService/SubgraphService"
33
import { batchUpdateSubgraphSignalledTokens, calculatePricePerShare, createOrLoadDataService, createOrLoadEpoch, createOrLoadGraphNetwork, createOrLoadIndexerQueryFeePaymentAggregation, createOrLoadPaymentSource, createOrLoadProvision, createOrLoadSubgraphDeployment, joinID, updateDelegationExchangeRate } from "./helpers/helpers"
4-
import { Allocation, GraphAccount, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema"
4+
import { Allocation, PublicPoiSubmission, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema"
55
import { addresses } from "../../config/addresses"
66
import { tuplePrefixBytes } from "./helpers/decoder"
77
import { createOrLoadIndexer } from "./helpers/helpers"
@@ -260,8 +260,22 @@ export function handleIndexingRewardsCollected(event: IndexingRewardsCollected):
260260
poiSubmission.allocation = allocation.id
261261
poiSubmission.poi = event.params.poi
262262
poiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32()
263+
poiSubmission.presentedAtTimestamp = event.block.timestamp.toI32()
263264
poiSubmission.save()
264265

266+
// Create public PoI submission
267+
let publicPoiSubmission = new PublicPoiSubmission(joinID([event.transaction.hash.toHexString(), event.logIndex.toString()]))
268+
publicPoiSubmission.allocation = allocation.id
269+
publicPoiSubmission.publicPoi = event.params.publicPoi
270+
publicPoiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32()
271+
publicPoiSubmission.presentedAtTimestamp = event.block.timestamp.toI32()
272+
publicPoiSubmission.save()
273+
274+
// Update latest POI in allocation
275+
allocation.poi = event.params.poi
276+
allocation.latestPoiPresentedAt = event.block.timestamp.toI32()
277+
allocation.save()
278+
265279
// Update epoch
266280
let epoch = createOrLoadEpoch((addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!))
267281
epoch.totalRewards = epoch.totalRewards.plus(event.params.tokensRewards)

subgraph.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ dataSources:
477477
handler: handleAllocationResized
478478
- event: AllocationClosed(indexed address,indexed address,indexed bytes32,uint256,bool)
479479
handler: handleAllocationClosed
480-
- event: IndexingRewardsCollected(indexed address,indexed address,indexed bytes32,uint256,uint256,uint256,bytes32,uint256)
480+
- event: IndexingRewardsCollected(indexed address,indexed address,indexed bytes32,uint256,uint256,uint256,bytes32,bytes32,uint256)
481481
handler: handleIndexingRewardsCollected
482482
- event: QueryFeesCollected(indexed address,indexed address,indexed address,bytes32,uint256,uint256)
483483
handler: handleQueryFeesCollected

0 commit comments

Comments
 (0)