Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions sdk/src/math/amm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(
Expand Down
Loading