Skip to content

Commit

Permalink
fix div by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv-chauhan committed Jan 7, 2025
1 parent fd25a9b commit 268d5af
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@
"status": "prod",
"versions": {
"schema": "1.3.0",
"subgraph": "1.3.0",
"subgraph": "1.4.0",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -1089,7 +1089,7 @@
},
"decentralized-network": {
"slug": "convex-finance-ethereum",
"query-id": "7rFZ2x6aLQ7EZsNx8F5yenk4xcqwqR3Dynf9rdixCSME"
"query-id": "todo"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"graft": false,
"base": "",
"block": 0
"base": "QmTZozrLfSy3WtcbFcUFu9iruKYeBMaEdrsw1MnCZjVfLX",
"block": 21510541
}
8 changes: 8 additions & 0 deletions subgraphs/convex-finance/src/prices/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 5 additions & 4 deletions subgraphs/convex-finance/src/prices/routers/CurveRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions subgraphs/convex-finance/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 268d5af

Please sign in to comment.