Skip to content

Commit

Permalink
Update liquidity removal volume amount
Browse files Browse the repository at this point in the history
  • Loading branch information
cujowolf committed Sep 25, 2023
1 parent 40c7c05 commit 4e28af2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions projects/subgraph-bean/src/BeanWellHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function handleAddLiquidity(event: AddLiquidity): void {
event.block.timestamp,
event.block.number,
event.params.tokenAmountsIn[0],
event.params.tokenAmountsIn[1]
event.params.tokenAmountsIn[1],
false
);
}

Expand All @@ -23,7 +24,8 @@ export function handleRemoveLiquidity(event: RemoveLiquidity): void {
event.block.timestamp,
event.block.number,
event.params.tokenAmountsOut[0],
event.params.tokenAmountsOut[1]
event.params.tokenAmountsOut[1],
true
);
}

Expand All @@ -33,7 +35,8 @@ export function handleRemoveLiquidityOneToken(event: RemoveLiquidityOneToken): v
event.block.timestamp,
event.block.number,
event.params.tokenOut == BEAN_ERC20 ? event.params.tokenAmountOut : ZERO_BI,
event.params.tokenOut != BEAN_ERC20 ? event.params.tokenAmountOut : ZERO_BI
event.params.tokenOut != BEAN_ERC20 ? event.params.tokenAmountOut : ZERO_BI,
true
);
}

Expand All @@ -42,13 +45,13 @@ export function handleSync(event: Sync): void {

let deltaReserves = deltaBigIntArray(event.params.reserves, pool.reserves);

handleLiquidityChange(event.address.toHexString(), event.block.timestamp, event.block.number, deltaReserves[0], deltaReserves[1]);
handleLiquidityChange(event.address.toHexString(), event.block.timestamp, event.block.number, deltaReserves[0], deltaReserves[1], false);
}

export function handleSwap(event: Swap): void {
handleSwapEvent(
event.address.toHexString(),
event.params.fromToken,
event.params.toToken,
event.params.amountIn,
event.params.amountOut,
event.block.timestamp,
Expand Down Expand Up @@ -76,7 +79,8 @@ function handleLiquidityChange(
timestamp: BigInt,
blockNumber: BigInt,
token0Amount: BigInt,
token1Amount: BigInt
token1Amount: BigInt,
removal: boolean
): void {
// Get Price Details via Price contract
let beanstalkPrice = BeanstalkPrice.bind(BEANSTALK_PRICE);
Expand All @@ -97,8 +101,9 @@ function handleLiquidityChange(

let volumeUSD = ZERO_BD;
let volumeBean = ZERO_BI;
if (token0Amount == ZERO_BI || token1Amount == ZERO_BI) {
volumeUSD = deltaLiquidityUSD;
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());
}

Expand Down

0 comments on commit 4e28af2

Please sign in to comment.