Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgraph - Bean: Fix volume calculation for single sided removals #686

Merged
merged 4 commits into from
Nov 13, 2023
Merged
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
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
Loading