File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ type Pool @entity {
133133 rewardCut : BigInt !
134134 "Transcoder's fee share during the earnings pool's round"
135135 feeShare : BigInt !
136+ "Cumulative fee factor for delegator fees calculation"
137+ cumulativeFeeFactor : BigDecimal
138+ "Cumulative reward factor for delegator rewards calculation"
139+ cumulativeRewardFactor : BigDecimal
136140}
137141
138142"""
Original file line number Diff line number Diff line change 1- import { store } from "@graphprotocol/graph-ts" ;
1+ import { store , Address } from "@graphprotocol/graph-ts" ;
22import {
33 convertToDecimal ,
44 createOrLoadDelegator ,
88 createOrLoadTranscoder ,
99 EMPTY_ADDRESS ,
1010 getBlockNum ,
11+ integerFromString ,
1112 makeEventId ,
1213 makePoolId ,
1314 makeUnbondingLockId ,
@@ -500,6 +501,13 @@ export function reward(event: Reward): void {
500501 pool ! . feeShare = transcoder . feeShare ;
501502 pool ! . rewardCut = transcoder . rewardCut ;
502503
504+ let bondingManager = BondingManager . bind ( event . address ) ;
505+ let earningsPool = bondingManager . getTranscoderEarningsPoolForRound (
506+ Address . fromString ( transcoder . id ) ,
507+ integerFromString ( round . id )
508+ ) ;
509+ pool ! . cumulativeRewardFactor = convertToDecimal ( earningsPool . cumulativeRewardFactor ) ;
510+
503511 transcoder . save ( ) ;
504512 delegate . save ( ) ;
505513 pool ! . save ( ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 createOrLoadTranscoderDay ,
1111 getBlockNum ,
1212 getEthPriceUsd ,
13+ integerFromString ,
1314 makeEventId ,
1415 makePoolId ,
1516 ZERO_BD ,
@@ -29,6 +30,9 @@ import {
2930 WinningTicketRedeemed ,
3031 Withdrawal ,
3132} from "../types/TicketBroker/TicketBroker" ;
33+ import {
34+ BondingManager ,
35+ } from "../types/BondingManager/BondingManager" ;
3236
3337export function winningTicketRedeemed ( event : WinningTicketRedeemed ) : void {
3438 let round = createOrLoadRound ( getBlockNum ( ) ) ;
@@ -97,9 +101,17 @@ export function winningTicketRedeemed(event: WinningTicketRedeemed): void {
97101 protocol . winningTicketCount = protocol . winningTicketCount + 1 ;
98102 protocol . save ( ) ;
99103
100- // update the transcoder pool fees
104+ // update the transcoder pool fees and cummulative factors
101105 if ( pool ) {
102106 pool . fees = pool . fees . plus ( faceValue ) ;
107+
108+ let bondingManager = BondingManager . bind ( event . address ) ;
109+ let earningsPool = bondingManager . getTranscoderEarningsPoolForRound (
110+ Address . fromString ( transcoder . id ) ,
111+ integerFromString ( round . id )
112+ ) ;
113+ pool . cumulativeFeeFactor = convertToDecimal ( earningsPool . cumulativeFeeFactor ) ;
114+
103115 pool . save ( ) ;
104116 }
105117
You can’t perform that action at this time.
0 commit comments