@@ -28,6 +28,7 @@ import {
2828 GraphAccount ,
2929 Delegator ,
3030 DelegatedStake ,
31+ IndexerQueryFeePaymentAggregation ,
3132} from '../types/schema'
3233
3334import {
@@ -45,6 +46,8 @@ import {
4546 batchUpdateSubgraphSignalledTokens ,
4647 createOrLoadGraphNetwork ,
4748 calculateCapacities ,
49+ createOrLoadIndexerQueryFeePaymentAggregation ,
50+ createOrLoadPaymentSource ,
4851} from './helpers/helpers'
4952import { addresses } from '../../config/addresses'
5053
@@ -394,12 +397,17 @@ export function handleAllocationCollected(event: AllocationCollected): void {
394397 let subgraphDeploymentID = event . params . subgraphDeploymentID . toHexString ( )
395398 let indexerID = event . params . indexer . toHexString ( )
396399 let allocationID = event . params . allocationID . toHexString ( )
400+ let paymentAddress = event . transaction . from
397401
398402 // update indexer
399403 let indexer = Indexer . load ( indexerID ) !
400404 indexer . queryFeesCollected = indexer . queryFeesCollected . plus ( event . params . rebateFees )
401405 indexer . save ( )
402406
407+ let paymentAggregation = createOrLoadIndexerQueryFeePaymentAggregation ( paymentAddress , event . params . indexer )
408+ paymentAggregation . queryFeesCollected = paymentAggregation . queryFeesCollected . plus ( event . params . rebateFees )
409+ paymentAggregation . save ( )
410+
403411 // update allocation
404412 // rebateFees is the total token value minus the curation and protocol fees, as can be seen in the contracts
405413 let allocation = Allocation . load ( allocationID ) !
@@ -457,6 +465,20 @@ export function handleAllocationCollected(event: AllocationCollected): void {
457465 event . params . rebateFees ,
458466 )
459467 graphNetwork . save ( )
468+
469+ let paymentSource = createOrLoadPaymentSource ( paymentAddress )
470+ paymentSource . totalQueryFees = paymentSource . totalQueryFees . plus ( event . params . tokens )
471+ paymentSource . totalIndexerQueryFeesCollected = paymentSource . totalIndexerQueryFeesCollected . plus (
472+ event . params . rebateFees ,
473+ )
474+ paymentSource . totalCuratorQueryFees = paymentSource . totalCuratorQueryFees . plus (
475+ event . params . curationFees ,
476+ )
477+ paymentSource . totalTaxedQueryFees = paymentSource . totalTaxedQueryFees . plus ( taxedFees )
478+ paymentSource . totalUnclaimedQueryFeeRebates = paymentSource . totalUnclaimedQueryFeeRebates . plus (
479+ event . params . rebateFees ,
480+ )
481+ paymentSource . save ( )
460482}
461483
462484/**
@@ -683,6 +705,7 @@ export function handleRebateCollected(event: RebateCollected): void {
683705 let subgraphDeploymentID = event . params . subgraphDeploymentID . toHexString ( )
684706 let indexerID = event . params . indexer . toHexString ( )
685707 let allocationID = event . params . allocationID . toHexString ( )
708+ let paymentAddress = event . transaction . from
686709
687710 // update indexer
688711 let indexer = Indexer . load ( indexerID ) !
@@ -696,6 +719,13 @@ export function handleRebateCollected(event: RebateCollected): void {
696719 indexer = updateAdvancedIndexerMetrics ( indexer as Indexer )
697720 indexer . save ( )
698721
722+ // Replicate for payment source specific aggregation
723+ let paymentAggregation = createOrLoadIndexerQueryFeePaymentAggregation ( paymentAddress , event . params . indexer )
724+ paymentAggregation . queryFeesCollected = paymentAggregation . queryFeesCollected . plus ( event . params . queryFees )
725+ paymentAggregation . queryFeeRebates = paymentAggregation . queryFeeRebates . plus ( event . params . queryRebates )
726+ paymentAggregation . delegatorQueryFees = paymentAggregation . delegatorQueryFees . plus ( event . params . delegationRewards )
727+ paymentAggregation . save ( )
728+
699729 // update allocation
700730 // queryFees is the total token value minus the curation and protocol fees, as can be seen in the contracts
701731 let allocation = Allocation . load ( allocationID ) !
@@ -751,6 +781,30 @@ export function handleRebateCollected(event: RebateCollected): void {
751781 )
752782 graphNetwork . totalDelegatedTokens = graphNetwork . totalDelegatedTokens . plus ( event . params . delegationRewards )
753783 graphNetwork . save ( )
784+
785+ // Replicate for payment source specific data
786+ let paymentSource = createOrLoadPaymentSource ( paymentAddress )
787+ paymentSource . totalQueryFees = paymentSource . totalQueryFees . plus ( event . params . tokens )
788+ paymentSource . totalIndexerQueryFeesCollected = paymentSource . totalIndexerQueryFeesCollected . plus (
789+ event . params . queryFees ,
790+ )
791+ paymentSource . totalCuratorQueryFees = paymentSource . totalCuratorQueryFees . plus (
792+ event . params . curationFees ,
793+ )
794+ paymentSource . totalTaxedQueryFees = paymentSource . totalTaxedQueryFees . plus ( event . params . protocolTax )
795+ paymentSource . totalUnclaimedQueryFeeRebates = paymentSource . totalUnclaimedQueryFeeRebates . plus (
796+ event . params . queryFees ,
797+ )
798+ paymentSource . totalIndexerQueryFeeRebates = paymentSource . totalIndexerQueryFeeRebates . plus (
799+ event . params . queryRebates ,
800+ )
801+ paymentSource . totalDelegatorQueryFeeRebates = paymentSource . totalDelegatorQueryFeeRebates . plus (
802+ event . params . delegationRewards ,
803+ )
804+ paymentSource . totalUnclaimedQueryFeeRebates = paymentSource . totalUnclaimedQueryFeeRebates . minus (
805+ event . params . delegationRewards . plus ( event . params . queryRebates ) ,
806+ )
807+ paymentSource . save ( )
754808}
755809
756810/**
0 commit comments