fix: Fix discovery position KRAIKEN amount calculation

The discovery position was incorrectly calculating ETH amount instead
of KRAIKEN amount when determining how much to subtract from outstanding
supply. This caused the floor position to be placed at extreme ticks
(141k+) instead of bordering the anchor position.

When token0isWeth=true:
- Before: discoveryAmount = getAmount0 (ETH amount)
- After: discoveryAmount = getAmount1 (KRAIKEN amount)

This ensures the outstanding supply calculation properly excludes all
KRAIKEN tokens locked in liquidity positions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
johba 2025-08-18 17:05:32 +02:00
parent 516b7cc087
commit 61ea25517c
2 changed files with 4 additions and 3 deletions

View file

@ -200,7 +200,7 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle {
// Record price from anchor position for VWAP
if (i == uint256(Stage.ANCHOR)) {
int24 tick = position.tickLower + (position.tickUpper - position.tickLower / 2);
int24 tick = position.tickLower + ((position.tickUpper - position.tickLower) / 2);
currentPrice = _priceAtTick(token0isWeth ? -1 * tick : tick);
}
}

View file

@ -164,9 +164,9 @@ abstract contract ThreePositionStrategy is UniswapMath, VWAPTracker {
// Calculate discoveryAmount for floor position calculation
if (token0isWeth) {
discoveryAmount = LiquidityAmounts.getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
} else {
discoveryAmount = LiquidityAmounts.getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
} else {
discoveryAmount = LiquidityAmounts.getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
_mintPosition(Stage.DISCOVERY, tickLower, tickUpper, liquidity);
@ -201,6 +201,7 @@ abstract contract ThreePositionStrategy is UniswapMath, VWAPTracker {
uint256 ethBalance = _getEthBalance();
int24 vwapTick;
if (vwapX96 > 0) {
// vwapX96 is price² in X96 format, need to convert to regular price
// price = sqrt(price²) = sqrt(vwapX96) * 2^48 / 2^96 = sqrt(vwapX96) / 2^48