diff --git a/projects/subgraph-bean/src/utils/Pool.ts b/projects/subgraph-bean/src/utils/Pool.ts index 1b57b8eccf..92beff98d1 100644 --- a/projects/subgraph-bean/src/utils/Pool.ts +++ b/projects/subgraph-bean/src/utils/Pool.ts @@ -129,7 +129,9 @@ export function updatePoolValues( poolHourly.deltaVolume = poolHourly.deltaVolume.plus(volumeBean); poolHourly.deltaVolumeUSD = poolHourly.deltaVolumeUSD.plus(volumeUSD); poolHourly.deltaLiquidityUSD = poolHourly.deltaLiquidityUSD.plus(deltaLiquidityUSD); - poolHourly.utilization = poolHourly.deltaVolumeUSD.div(poolHourly.liquidityUSD); + if (poolHourly.liquidityUSD.gt(ZERO_BD)) { + poolHourly.utilization = poolHourly.deltaVolumeUSD.div(poolHourly.liquidityUSD); + } poolHourly.updatedAt = timestamp; poolHourly.save(); @@ -140,7 +142,9 @@ export function updatePoolValues( poolDaily.deltaVolume = poolDaily.deltaVolume.plus(volumeBean); poolDaily.deltaVolumeUSD = poolDaily.deltaVolumeUSD.plus(volumeUSD); poolDaily.deltaLiquidityUSD = poolDaily.deltaLiquidityUSD.plus(deltaLiquidityUSD); - poolDaily.utilization = poolDaily.deltaVolumeUSD.div(poolDaily.liquidityUSD); + if (poolDaily.liquidityUSD.gt(ZERO_BD)) { + poolDaily.utilization = poolDaily.deltaVolumeUSD.div(poolDaily.liquidityUSD); + } poolDaily.updatedAt = timestamp; poolDaily.save(); diff --git a/projects/subgraph-bean/src/utils/price/BeanstalkPrice.ts b/projects/subgraph-bean/src/utils/price/BeanstalkPrice.ts index ade39fa4de..f0d92d8b12 100644 --- a/projects/subgraph-bean/src/utils/price/BeanstalkPrice.ts +++ b/projects/subgraph-bean/src/utils/price/BeanstalkPrice.ts @@ -121,7 +121,10 @@ export function BeanstalkPrice_try_price(beanAddr: Address, blockNumber: BigInt) // Extracts the pool price from the larger result export function getPoolPrice(priceResult: BeanstalkPriceResult, pool: Address): PricePoolStruct | null { for (let i = 0; i < priceResult.value.ps.length; ++i) { - if (priceResult.value.ps[i].pool == pool) { + // Zero liquidity responses are also omitted - this can be caused on a legacy price contract implementation + // due to extreme discrepancies in chainlink vs uniswap oracle price. Particularly for the bean subgraph, + // it is preferable to omit those events from being handled than to have periods where zero liquidity is reported. + if (priceResult.value.ps[i].pool == pool && priceResult.value.ps[i].liquidity.gt(ZERO_BI)) { return priceResult.value.ps[i]; } }