diff --git a/subgraphs/v3-vault/schema.graphql b/subgraphs/v3-vault/schema.graphql index ec23320..80430ef 100644 --- a/subgraphs/v3-vault/schema.graphql +++ b/subgraphs/v3-vault/schema.graphql @@ -151,6 +151,8 @@ type PoolToken @entity { balance: BigDecimal! "Total volume of this token traded in the Pool" volume: BigDecimal! + "Total swap fees collected for this token" + totalSwapFee: BigDecimal! "Buffer associated with this token, if any" buffer: Buffer "Nested Pool associated with this token, if any" diff --git a/subgraphs/v3-vault/src/helpers/entities.ts b/subgraphs/v3-vault/src/helpers/entities.ts index b6b295b..41a5293 100644 --- a/subgraphs/v3-vault/src/helpers/entities.ts +++ b/subgraphs/v3-vault/src/helpers/entities.ts @@ -79,7 +79,7 @@ export function createPoolSnapshot(pool: Pool, timestamp: i32): void { for (let i = 0; i < poolTokens.length; i++) { totalSwapVolumes[i] = poolTokens[i].volume; balances[i] = poolTokens[i].balance; - totalSwapFees[i] = poolTokens[i].totalProtocolSwapFee; + totalSwapFees[i] = poolTokens[i].totalSwapFee; totalProtocolSwapFees[i] = poolTokens[i].totalProtocolSwapFee; totalProtocolYieldFees[i] = poolTokens[i].totalProtocolYieldFee; } @@ -128,6 +128,7 @@ export function createPoolToken( poolToken.priceRate = ONE_BD; poolToken.balance = ZERO_BD; poolToken.volume = ZERO_BD; + poolToken.totalSwapFee = ZERO_BD; poolToken.totalProtocolSwapFee = ZERO_BD; poolToken.totalProtocolYieldFee = ZERO_BD; poolToken.buffer = buffer ? buffer.id : null; diff --git a/subgraphs/v3-vault/src/mappings/vault.ts b/subgraphs/v3-vault/src/mappings/vault.ts index 6ad39b3..00bc99c 100644 --- a/subgraphs/v3-vault/src/mappings/vault.ts +++ b/subgraphs/v3-vault/src/mappings/vault.ts @@ -312,11 +312,13 @@ export function handleSwap(event: SwapEvent): void { let newInAmount = poolTokenIn.balance.plus(tokenAmountIn); poolTokenIn.balance = newInAmount; poolTokenIn.volume = poolTokenIn.volume.plus(tokenAmountIn); + poolTokenIn.totalSwapFee = poolTokenIn.totalSwapFee.plus(swapFeeAmount); poolTokenIn.save(); let newOutAmount = poolTokenOut.balance.minus(tokenAmountOut); poolTokenOut.balance = newOutAmount; poolTokenOut.volume = poolTokenOut.volume.plus(tokenAmountOut); + poolTokenOut.totalSwapFee = poolTokenOut.totalSwapFee.plus(swapFeeAmount); poolTokenOut.save(); updateProtocolFeeAmounts(pool);