diff --git a/schema.graphql b/schema.graphql index aa25ed2..0858d3c 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 fee factor for delegator fees calculation" + cumulativeFeeFactor: BigDecimal } """ diff --git a/src/mappings/ticketBroker.ts b/src/mappings/ticketBroker.ts index 90d08f4..602fd93 100644 --- a/src/mappings/ticketBroker.ts +++ b/src/mappings/ticketBroker.ts @@ -10,6 +10,7 @@ import { createOrLoadTranscoderDay, getBlockNum, getEthPriceUsd, + integerFromString, makeEventId, makePoolId, ZERO_BD, @@ -29,6 +30,9 @@ import { WinningTicketRedeemed, Withdrawal, } from "../types/TicketBroker/TicketBroker"; +import { + BondingManager, +} from "../types/BondingManager/BondingManager"; export function winningTicketRedeemed(event: WinningTicketRedeemed): void { let round = createOrLoadRound(getBlockNum()); @@ -97,9 +101,17 @@ export function winningTicketRedeemed(event: WinningTicketRedeemed): void { protocol.winningTicketCount = protocol.winningTicketCount + 1; protocol.save(); - // update the transcoder pool fees + // update the transcoder pool fees and cummulative factors if (pool) { pool.fees = pool.fees.plus(faceValue); + + let bondingManager = BondingManager.bind(event.address); + let earningsPool = bondingManager.getTranscoderEarningsPoolForRound( + Address.fromString(transcoder.id), + integerFromString(round.id) + ); + pool.cumulativeFeeFactor = convertToDecimal(earningsPool.cumulativeFeeFactor); + pool.save(); }