From ecacdf0fa1d270d4e566863bc704f4dbb709d0c4 Mon Sep 17 00:00:00 2001 From: latent-9 <296084221+latent-9@users.noreply.github.com> Date: Mon, 10 Aug 2026 23:43:15 +1200 Subject: [PATCH 1/2] Fix APR math in nextRevenuePoolSettleApr --- sdk/src/math/insurance.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/src/math/insurance.ts b/sdk/src/math/insurance.ts index 6524b5d86c..9d78b23944 100644 --- a/sdk/src/math/insurance.ts +++ b/sdk/src/math/insurance.ts @@ -17,7 +17,7 @@ export function nextRevenuePoolSettleApr( SpotBalanceType.DEPOSIT ); - const payoutRatio = 0.1; + const payoutRatioDenominator = 10; const ratioForStakers = spotMarket.insuranceFund.totalFactor > 0 && spotMarket.insuranceFund.userFactor > 0 && @@ -34,11 +34,13 @@ export function nextRevenuePoolSettleApr( const projectedAnnualRev = revenuePoolBN .muln(settlesPerYear) - .muln(payoutRatio); + .divn(payoutRatioDenominator); - const uncappedApr = vaultBalance.add(amount).eq(ZERO) + const delta = amount ?? ZERO; + + const uncappedApr = vaultBalance.add(delta).eq(ZERO) ? 0 - : projectedAnnualRev.muln(1000).div(vaultBalance.add(amount)).toNumber() * + : projectedAnnualRev.muln(1000).div(vaultBalance.add(delta)).toNumber() * 100 * 1000; const cappedApr = Math.min(uncappedApr, MAX_APR.toNumber()); From 1cb9f781fc0db5411cbec965ae2af3c8896e80a0 Mon Sep 17 00:00:00 2001 From: latent-9 <296084221+latent-9@users.noreply.github.com> Date: Tue, 11 Aug 2026 01:18:47 +1200 Subject: [PATCH 2/2] sdk: use integer mul/div for settles-per-year in nextRevenuePoolSettleApr The fractional settlesPerYear was passed to BN.muln, which only accepts a small integer and truncates otherwise, so the projected annual revenue was wrong for any revenue settle period that does not evenly divide a year. Multiply then divide with integers to keep the value exact. --- sdk/src/math/insurance.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/src/math/insurance.ts b/sdk/src/math/insurance.ts index 9d78b23944..3e0baa0774 100644 --- a/sdk/src/math/insurance.ts +++ b/sdk/src/math/insurance.ts @@ -30,10 +30,9 @@ export function nextRevenuePoolSettleApr( const revSettlePeriod = spotMarket.insuranceFund.revenueSettlePeriod.toNumber() * 1000; - const settlesPerYear = 31536000000 / revSettlePeriod; - const projectedAnnualRev = revenuePoolBN - .muln(settlesPerYear) + .mul(new BN(31536000000)) + .div(new BN(revSettlePeriod)) .divn(payoutRatioDenominator); const delta = amount ?? ZERO;