@@ -14,7 +14,7 @@ import {
1414 TokenRateProviderSet ,
1515} from '../types/templates/StablePhantomPoolV2/ComposableStablePool' ;
1616import { ParametersSet } from '../types/templates/FXPool/FXPool' ;
17- import { Pool , PriceRateProvider , AmpUpdate , PoolContract } from '../types/schema' ;
17+ import { Pool , PriceRateProvider , AmpUpdate , PoolContract , Balancer } from '../types/schema' ;
1818
1919import {
2020 tokenToDecimal ,
@@ -24,6 +24,7 @@ import {
2424 loadPriceRateProvider ,
2525 getPoolShare ,
2626 computeCuratedSwapEnabled ,
27+ getProtocolFeeCollector ,
2728} from './helpers/misc' ;
2829import { ONE_BD , ProtocolFeeType , ZERO_ADDRESS , ZERO_BD } from './helpers/constants' ;
2930import { updateAmpFactor } from './helpers/stable' ;
@@ -371,6 +372,22 @@ export function handleTransfer(event: Transfer): void {
371372 poolShareTo . balance = poolShareTo . balance . plus ( tokenToDecimal ( event . params . value , BPT_DECIMALS ) ) ;
372373 poolShareTo . save ( ) ;
373374 pool . totalShares = pool . totalShares . plus ( tokenToDecimal ( event . params . value , BPT_DECIMALS ) ) ;
375+
376+ // mint of BPT to the fee collector means the pool is paying protocol fees
377+ let vault = Balancer . load ( '2' ) as Balancer ;
378+ let protocolFeeCollector = vault . protocolFeesCollector ;
379+ if ( ! protocolFeeCollector ) {
380+ protocolFeeCollector = getProtocolFeeCollector ( ) ;
381+ vault . protocolFeesCollector = protocolFeeCollector ;
382+ vault . save ( ) ;
383+ }
384+
385+ if ( protocolFeeCollector && poolShareTo . userAddress == protocolFeeCollector ) {
386+ let protocolFeePaid = tokenToDecimal ( event . params . value , BPT_DECIMALS ) ;
387+ let totalProtocolFee = pool . totalProtocolFeePaidInBPT ? pool . totalProtocolFeePaidInBPT : ZERO_BD ;
388+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
389+ pool . totalProtocolFeePaidInBPT = totalProtocolFee ! . plus ( protocolFeePaid ) ;
390+ }
374391 } else if ( isBurn ) {
375392 poolShareFrom . balance = poolShareFrom . balance . minus ( tokenToDecimal ( event . params . value , BPT_DECIMALS ) ) ;
376393 poolShareFrom . save ( ) ;
0 commit comments