This commit is contained in:
JulesCrown 2024-04-11 21:41:48 +02:00
parent d9ee15f812
commit af6da0daae

View file

@ -208,7 +208,7 @@ contract BaseLineLP {
return amount;
}
event FLOOR_TICK(int24 indexed floorTick, int24 indexed startTick);
event DEBUG(uint256 indexed eth, uint256 indexed outstanding, int24 indexed floorTick, int24 startTick);
function _set(uint160 sqrtPriceX96, int24 currentTick, uint256 ethInNewAnchor) internal {
// ### set Anchor position
@ -236,12 +236,16 @@ contract BaseLineLP {
// all remaining eth will be put into this position
uint256 ethInFloor = address(this).balance;
int24 floorTick;
// calculate price at which all HARB can be bought back
int24 floorTick = tickAtPrice(outstanding(), ethInFloor);
emit FLOOR_TICK(floorTick, startTick);
// put a position symetrically around the price, startTick being edge on one side
floorTick = token0isWeth ? floorTick - (startTick - floorTick) : startTick + (floorTick - startTick);
emit FLOOR_TICK(floorTick, startTick);
uint256 _outstanding = outstanding();
if (_outstanding > 0) {
floorTick = tickAtPrice(_outstanding, ethInFloor);
// put a position symetrically around the price, startTick being edge on one side
floorTick = token0isWeth ? startTick + (floorTick - startTick) : floorTick - (startTick - floorTick);
} else {
floorTick = startTick + ((token0isWeth ? int24(1) : int24(-1)) * 200);
}
// calculate liquidity
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(floorTick);
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(startTick);
@ -249,8 +253,8 @@ contract BaseLineLP {
sqrtPriceX96,
sqrtRatioAX96,
sqrtRatioBX96,
token0isWeth ? ethInFloor : 0,
token0isWeth ? 0: ethInFloor
token0isWeth ? 0 : ethInFloor,
token0isWeth ? ethInFloor : 0
);
// mint
_mint(floorTick, startTick, liquidity);
@ -258,8 +262,8 @@ contract BaseLineLP {
// ## set Discovery position
{
int24 tickLower = token0isWeth ? currentTick + 401 : currentTick - 11401;
int24 tickUpper = token0isWeth ? currentTick + 11401 : currentTick - 401;
int24 tickLower = token0isWeth ? currentTick + 400 : currentTick - 11400;
int24 tickUpper = token0isWeth ? currentTick + 11400 : currentTick - 400;
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
// discovery with 1.5 times as much liquidity per tick as anchor
@ -290,21 +294,25 @@ contract BaseLineLP {
harb.mint(amount);
mintedToday += amount;
amount = harb.balanceOf(address(this));
emit DEBUG(amount, harbInDiscovery, 0, 0);
if(amount < harbInDiscovery) {
// calculate new ticks so that discovery liquidity is still
// deeper than anchor, but less wide
int24 tickWidth = int24(int256(11000 * amount / harbInDiscovery)) + 401;
int24 tickWidth = int24(int256(11000 * amount / harbInDiscovery)) + 400;
tickWidth = tickWidth / TICK_SPACING * TICK_SPACING;
tickLower = token0isWeth ? currentTick + 401 : currentTick - tickWidth;
tickUpper = token0isWeth ? currentTick + tickWidth : currentTick - 401;
tickWidth = (tickWidth <= 400) ? tickWidth + TICK_SPACING : tickWidth;
tickLower = token0isWeth ? currentTick - tickWidth : currentTick + 400;
tickUpper = token0isWeth ? currentTick - 400 : currentTick + tickWidth;
sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
emit DEBUG(uint256(sqrtRatioAX96), uint256(sqrtRatioBX96), tickLower, tickWidth);
liquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
sqrtRatioAX96,
sqrtRatioBX96,
token0isWeth ? 0 : amount,
token0isWeth ? amount: 0
token0isWeth ? amount : 0
);
}
_mint(tickLower, tickUpper, liquidity);