Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/mappings/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,20 @@ export function handleSwapHelper(event: SwapEvent, subgraphConfig: SubgraphConfi
pool.liquidity = event.params.liquidity
pool.tick = BigInt.fromI32(event.params.tick as i32)
pool.sqrtPrice = event.params.sqrtPriceX96
pool.totalValueLockedToken0 = pool.totalValueLockedToken0.plus(amount0)
pool.totalValueLockedToken1 = pool.totalValueLockedToken1.plus(amount1)

let amount0WithFee = amount0
let amount1WithFee = amount1

if (amount0.gt(ZERO_BD)) {
const fee0 = amount0.times(pool.feeTier.toBigDecimal()).div(BigDecimal.fromString('1000000'))
amount0WithFee = amount0.minus(fee0)
} else if (amount1.gt(ZERO_BD)) {
const fee1 = amount1.times(pool.feeTier.toBigDecimal()).div(BigDecimal.fromString('1000000'))
amount1WithFee = amount1.minus(fee1)
}

pool.totalValueLockedToken0 = pool.totalValueLockedToken0.plus(amount0WithFee)
pool.totalValueLockedToken1 = pool.totalValueLockedToken1.plus(amount1WithFee)

// update token0 data
token0.volume = token0.volume.plus(amount0Abs)
Expand Down