Skip to content

Commit

Permalink
Subgraph - Bean: Fix volume calculation for single sided removals (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromguy authored Nov 13, 2023
2 parents 6367f90 + 821f8ff commit e15b954
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions projects/subgraph-bean/src/BeanWellHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,21 @@ function handleLiquidityChange(
let volumeUSD = ZERO_BD;
let volumeBean = ZERO_BI;
if ((token0Amount == ZERO_BI || token1Amount == ZERO_BI) && removal) {
// This is a removal and delta liquidity should always be negative.
volumeUSD = deltaLiquidityUSD.times(BigDecimal.fromString("-1")).div(BigDecimal.fromString("2"));
volumeBean = BigInt.fromString(volumeUSD.div(newPrice).times(BigDecimal.fromString("1000000")).truncate(0).toString());
if (token0Amount != ZERO_BI) {
volumeBean = token0Amount.div(BigInt.fromI32(2));
volumeUSD = toDecimal(token0Amount).times(toDecimal(wellPrice.value.price));
} else {
let wellPairInBean = toDecimal(wellPrice.value.balances[0]).div(toDecimal(wellPrice.value.balances[1], 18));
volumeBean = BigInt.fromString(
toDecimal(token1Amount, 18)
.times(wellPairInBean)
.times(BigDecimal.fromString("1000000"))
.div(BigDecimal.fromString("2"))
.truncate(0)
.toString()
);
volumeUSD = toDecimal(volumeBean).times(toDecimal(wellPrice.value.price));
}
}

setPoolReserves(poolAddress, wellPrice.value.balances, blockNumber);
Expand Down

0 comments on commit e15b954

Please sign in to comment.