diff --git a/sdk/src/math/amm.ts b/sdk/src/math/amm.ts index 88a9ec9f5..55680edc4 100644 --- a/sdk/src/math/amm.ts +++ b/sdk/src/math/amm.ts @@ -503,16 +503,10 @@ export function calculateReferencePriceOffset( .mul(PRICE_PRECISION) .div(reservePrice); - const inventoryPct = clampBN( - liquidityFraction.mul(new BN(maxOffsetPct)).div(PERCENTAGE_PRECISION), - new BN(maxOffsetPct).mul(new BN(-1)), - new BN(maxOffsetPct) - ); - // Only apply when inventory is consistent with recent and 24h market premium - let offsetPct = markPremiumAvgPct.add(inventoryPct); + let offsetPct = markPremiumAvgPct.mul(liquidityFraction.abs()).divn(2); - if (!sigNum(inventoryPct).eq(sigNum(markPremiumAvgPct))) { + if (!sigNum(liquidityFraction).eq(sigNum(markPremiumAvgPct))) { offsetPct = ZERO; } @@ -1032,11 +1026,15 @@ export function calculateSpreadReserves( let maxOffset = 0; let referencePriceOffset = 0; if (amm.curveUpdateIntensity > 100) { - maxOffset = Math.max( - amm.maxSpread / 2, - (PERCENTAGE_PRECISION.toNumber() / 10000) * - (amm.curveUpdateIntensity - 100) - ); + if (amm.curveUpdateIntensity == 200) { + maxOffset = Math.max(amm.maxSpread / 2, 10_000); + } else { + maxOffset = Math.min( + amm.maxSpread / 2, + (PERCENTAGE_PRECISION.toNumber() / 10000) * + (amm.curveUpdateIntensity - 100) + ); + } const liquidityFraction = calculateInventoryLiquidityRatioForReferencePriceOffset(