From 104826b0d55b27065a9ee1e5b8fa43d01bfc981c Mon Sep 17 00:00:00 2001 From: Arjun Porwal <65214523+ap211unitech@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:15:44 +0530 Subject: [PATCH] fix: curveThreshold function to handle zero length divisor case (#11953) --- packages/page-referenda/src/util.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/page-referenda/src/util.ts b/packages/page-referenda/src/util.ts index 62d81d0c02..dbe780c15b 100644 --- a/packages/page-referenda/src/util.ts +++ b/packages/page-referenda/src/util.ts @@ -67,6 +67,11 @@ export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN) if (curve.isLinearDecreasing) { const { ceil, floor, length } = curve.asLinearDecreasing; + // if divisor is zero, we return the max + if (length.isZero()) { + return BN_BILLION; + } + // *ceil - (x.min(*length).saturating_div(*length, Down) * (*ceil - *floor)) // NOTE: We first multiply, then divide (since we work with fractions) return ceil.sub(