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();