From 27e4b6a8949a49867fa314e43a14348bc6d76101 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Wed, 16 Jul 2025 12:35:47 +0200 Subject: [PATCH] feat(pool): add cumulative fee factor Add `cumulativeFeeFactor` to the Pool entity to improve fee calculations for delegators. This allows more precise tracking and distribution of fees over time. --- schema.graphql | 2 ++ src/mappings/ticketBroker.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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(); }