Skip to content

Commit bc6038b

Browse files
fix(#patch); convex-finance; fix div by zero (#2672)
Co-authored-by: Chris Steege <[email protected]>
1 parent a81ff8b commit bc6038b

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"graft": false,
3-
"base": "",
4-
"block": 0
3+
"base": "QmTZozrLfSy3WtcbFcUFu9iruKYeBMaEdrsw1MnCZjVfLX",
4+
"block": 21510541
55
}

subgraphs/convex-finance/src/prices/common/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,11 @@ export function averagePrice(prices: CustomPriceType[]): CustomPriceType {
179179
constants.DEFAULT_USDC_DECIMALS
180180
);
181181
}
182+
183+
export function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal {
184+
if (amount1.equals(constants.BIGDECIMAL_ZERO)) {
185+
return constants.BIGDECIMAL_ZERO;
186+
} else {
187+
return amount0.div(amount1);
188+
}
189+
}

subgraphs/convex-finance/src/prices/routers/CurveRouter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ export function cryptoPoolLpPriceUsdc(
210210
const totalSupply = utils.getTokenSupply(lpAddress);
211211

212212
const totalValueUsdc = cryptoPoolLpTotalValueUsdc(lpAddress, block);
213-
const priceUsdc = totalValueUsdc
214-
.times(
213+
const priceUsdc = utils.safeDiv(
214+
totalValueUsdc.times(
215215
constants.BIGINT_TEN.pow(
216216
constants.DEFAULT_DECIMALS.toI32() as u8
217217
).toBigDecimal()
218-
)
219-
.div(totalSupply.toBigDecimal());
218+
),
219+
totalSupply.toBigDecimal()
220+
);
220221

221222
return CustomPriceType.initialize(
222223
priceUsdc,

subgraphs/convex-finance/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,11 @@
16401640
"resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
16411641
"version" "1.0.0"
16421642

1643+
"fsevents@~2.3.2":
1644+
"integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
1645+
"resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
1646+
"version" "2.3.2"
1647+
16431648
"get-iterator@^1.0.2":
16441649
"integrity" "sha512-v+dm9bNVfOYsY1OrhaCrmyOcYoSeVvbt+hHZ0Au+T+p1y+0Uyj9aMaGIeUTT6xdpRbWzDeYKvfOslPhggQMcsg=="
16451650
"resolved" "https://registry.npmjs.org/get-iterator/-/get-iterator-1.0.2.tgz"

0 commit comments

Comments
 (0)