Skip to content

Commit 6858042

Browse files
committed
restore totalProtocolFeePaidInBPT
1 parent 04556da commit 6858042

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ type Balancer @entity(immutable: false) {
33
id: ID!
44
poolCount: Int!
55
pools: [Pool!] @derivedFrom(field: "vaultID")
6+
protocolFeesCollector: Bytes
67
}
78
type Pool @entity(immutable: false) {
89
id: ID!

src/mappings/poolController.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
TokenRateProviderSet,
1515
} from '../types/templates/StablePhantomPoolV2/ComposableStablePool';
1616
import { 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

1919
import {
2020
tokenToDecimal,
@@ -24,6 +24,7 @@ import {
2424
loadPriceRateProvider,
2525
getPoolShare,
2626
computeCuratedSwapEnabled,
27+
getProtocolFeeCollector,
2728
} from './helpers/misc';
2829
import { ONE_BD, ProtocolFeeType, ZERO_ADDRESS, ZERO_BD } from './helpers/constants';
2930
import { 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

Comments
 (0)