Skip to content

Commit

Permalink
fix pool swap fees snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mendesfabio committed Dec 12, 2024
1 parent 8c96cda commit 678f3ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions subgraphs/v3-vault/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion subgraphs/v3-vault/src/helpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/v3-vault/src/mappings/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 678f3ba

Please sign in to comment.