From c5a0ef484b672ecb2e0904722cc9f81a96170df1 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Wed, 16 Jul 2025 12:33:40 +0200 Subject: [PATCH] feat(pool): add cumulative reward factor Add `cumulativeRewardFactor` to the Pool entity to improve reward calculations for delegators. This enables more accurate tracking and distribution of rewards over time. --- schema.graphql | 2 ++ src/mappings/bondingManager.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/schema.graphql b/schema.graphql index aa25ed2..eb8d51f 100755 --- a/schema.graphql +++ b/schema.graphql @@ -133,6 +133,8 @@ type Pool @entity { rewardCut: BigInt! "Transcoder's fee share during the earnings pool's round" feeShare: BigInt! + "Cumulative reward factor for delegator rewards calculation" + cumulativeRewardFactor: BigDecimal } """ diff --git a/src/mappings/bondingManager.ts b/src/mappings/bondingManager.ts index fa94260..6c9cafb 100755 --- a/src/mappings/bondingManager.ts +++ b/src/mappings/bondingManager.ts @@ -1,4 +1,4 @@ -import { store } from "@graphprotocol/graph-ts"; +import { store, Address } from "@graphprotocol/graph-ts"; import { convertToDecimal, createOrLoadDelegator, @@ -8,6 +8,7 @@ import { createOrLoadTranscoder, EMPTY_ADDRESS, getBlockNum, + integerFromString, makeEventId, makePoolId, makeUnbondingLockId, @@ -500,6 +501,13 @@ export function reward(event: Reward): void { pool!.feeShare = transcoder.feeShare; pool!.rewardCut = transcoder.rewardCut; + let bondingManager = BondingManager.bind(event.address); + let earningsPool = bondingManager.getTranscoderEarningsPoolForRound( + Address.fromString(transcoder.id), + integerFromString(round.id) + ); + pool!.cumulativeRewardFactor = convertToDecimal(earningsPool.cumulativeRewardFactor); + transcoder.save(); delegate.save(); pool!.save();