Skip to content

Commit

Permalink
Bean subgraph - workaround for price contract irregularity (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking authored Aug 6, 2024
2 parents 2fc960a + ff2d63b commit 8bd11a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions projects/subgraph-bean/src/utils/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down
5 changes: 4 additions & 1 deletion projects/subgraph-bean/src/utils/price/BeanstalkPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down

0 comments on commit 8bd11a2

Please sign in to comment.