From 268d5af4771d2c5c39b8afa296af53d73f953ed3 Mon Sep 17 00:00:00 2001 From: Dhruv Chauhan Date: Tue, 7 Jan 2025 15:05:54 +0530 Subject: [PATCH] fix div by zero --- deployment/deployment.json | 4 ++-- .../convex-finance-ethereum/configurations.json | 4 ++-- subgraphs/convex-finance/src/prices/common/utils.ts | 8 ++++++++ .../convex-finance/src/prices/routers/CurveRouter.ts | 9 +++++---- subgraphs/convex-finance/yarn.lock | 5 +++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/deployment/deployment.json b/deployment/deployment.json index bba57fe04c..b9f37d602b 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -1072,7 +1072,7 @@ "status": "prod", "versions": { "schema": "1.3.0", - "subgraph": "1.3.0", + "subgraph": "1.4.0", "methodology": "1.0.0" }, "files": { @@ -1089,7 +1089,7 @@ }, "decentralized-network": { "slug": "convex-finance-ethereum", - "query-id": "7rFZ2x6aLQ7EZsNx8F5yenk4xcqwqR3Dynf9rdixCSME" + "query-id": "todo" } } } diff --git a/subgraphs/convex-finance/protocols/convex-finance/config/deployments/convex-finance-ethereum/configurations.json b/subgraphs/convex-finance/protocols/convex-finance/config/deployments/convex-finance-ethereum/configurations.json index 1fe560804b..ca9d9472f3 100644 --- a/subgraphs/convex-finance/protocols/convex-finance/config/deployments/convex-finance-ethereum/configurations.json +++ b/subgraphs/convex-finance/protocols/convex-finance/config/deployments/convex-finance-ethereum/configurations.json @@ -1,5 +1,5 @@ { "graft": false, - "base": "", - "block": 0 + "base": "QmTZozrLfSy3WtcbFcUFu9iruKYeBMaEdrsw1MnCZjVfLX", + "block": 21510541 } diff --git a/subgraphs/convex-finance/src/prices/common/utils.ts b/subgraphs/convex-finance/src/prices/common/utils.ts index c3032deb9f..dd091e660a 100644 --- a/subgraphs/convex-finance/src/prices/common/utils.ts +++ b/subgraphs/convex-finance/src/prices/common/utils.ts @@ -179,3 +179,11 @@ export function averagePrice(prices: CustomPriceType[]): CustomPriceType { constants.DEFAULT_USDC_DECIMALS ); } + +export function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal { + if (amount1.equals(constants.BIGDECIMAL_ZERO)) { + return constants.BIGDECIMAL_ZERO; + } else { + return amount0.div(amount1); + } +} diff --git a/subgraphs/convex-finance/src/prices/routers/CurveRouter.ts b/subgraphs/convex-finance/src/prices/routers/CurveRouter.ts index 70404123e8..fcd7b4cc43 100644 --- a/subgraphs/convex-finance/src/prices/routers/CurveRouter.ts +++ b/subgraphs/convex-finance/src/prices/routers/CurveRouter.ts @@ -203,13 +203,14 @@ export function cryptoPoolLpPriceUsdc( const totalSupply = utils.getTokenSupply(lpAddress); const totalValueUsdc = cryptoPoolLpTotalValueUsdc(lpAddress, block); - const priceUsdc = totalValueUsdc - .times( + const priceUsdc = utils.safeDiv( + totalValueUsdc.times( constants.BIGINT_TEN.pow( constants.DEFAULT_DECIMALS.toI32() as u8 ).toBigDecimal() - ) - .div(totalSupply.toBigDecimal()); + ), + totalSupply.toBigDecimal() + ); return CustomPriceType.initialize( priceUsdc, diff --git a/subgraphs/convex-finance/yarn.lock b/subgraphs/convex-finance/yarn.lock index b894ac719e..0c367c4871 100644 --- a/subgraphs/convex-finance/yarn.lock +++ b/subgraphs/convex-finance/yarn.lock @@ -1640,6 +1640,11 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" +"fsevents@~2.3.2": + "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" + "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + "version" "2.3.2" + "get-iterator@^1.0.2": "integrity" "sha512-v+dm9bNVfOYsY1OrhaCrmyOcYoSeVvbt+hHZ0Au+T+p1y+0Uyj9aMaGIeUTT6xdpRbWzDeYKvfOslPhggQMcsg==" "resolved" "https://registry.npmjs.org/get-iterator/-/get-iterator-1.0.2.tgz"