Skip to content

Commit 104826b

Browse files
authored
fix: curveThreshold function to handle zero length divisor case (#11953)
1 parent 338431f commit 104826b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/page-referenda/src/util.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN)
6767
if (curve.isLinearDecreasing) {
6868
const { ceil, floor, length } = curve.asLinearDecreasing;
6969

70+
// if divisor is zero, we return the max
71+
if (length.isZero()) {
72+
return BN_BILLION;
73+
}
74+
7075
// *ceil - (x.min(*length).saturating_div(*length, Down) * (*ceil - *floor))
7176
// NOTE: We first multiply, then divide (since we work with fractions)
7277
return ceil.sub(

0 commit comments

Comments
 (0)