testing shift
This commit is contained in:
parent
047d1967e1
commit
0edf05a32d
2 changed files with 108 additions and 48 deletions
|
|
@ -22,6 +22,7 @@ import {Harb} from "./Harb.sol";
|
|||
contract BaseLineLP {
|
||||
int24 constant TICK_SPACING = 200;
|
||||
int24 constant ANCHOR_SPACING = 5 * TICK_SPACING;
|
||||
int24 constant DISCOVERY_SPACING = 11000;
|
||||
// default fee of 1%
|
||||
uint24 constant FEE = uint24(10_000);
|
||||
// uint256 constant FLOOR = 0;
|
||||
|
|
@ -166,7 +167,7 @@ contract BaseLineLP {
|
|||
tick_ = token0isWeth ? tick_ : -tick_;
|
||||
}
|
||||
|
||||
function _mint(int24 tickLower, int24 tickUpper, uint128 liquidity) internal {
|
||||
function _mint(Stage stage, int24 tickLower, int24 tickUpper, uint128 liquidity) internal {
|
||||
// create position
|
||||
pool.mint(
|
||||
address(this),
|
||||
|
|
@ -185,7 +186,7 @@ contract BaseLineLP {
|
|||
(, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128,,) = pool.positions(positionKey);
|
||||
|
||||
// put into storage
|
||||
positions[Stage.ANCHOR] = TokenPosition({
|
||||
positions[stage] = TokenPosition({
|
||||
liquidity: liquidity,
|
||||
tickLower: tickLower,
|
||||
tickUpper: tickUpper,
|
||||
|
|
@ -230,7 +231,7 @@ contract BaseLineLP {
|
|||
}
|
||||
// TODO: calculate liquidity correctly
|
||||
// or make sure that we don't have to pay more than we have
|
||||
_mint(tickLower, tickUpper, anchorLiquidity * 2);
|
||||
_mint(Stage.ANCHOR, tickLower, tickUpper, anchorLiquidity * 2);
|
||||
}
|
||||
|
||||
// ### set Floor position
|
||||
|
|
@ -263,13 +264,13 @@ contract BaseLineLP {
|
|||
);
|
||||
emit DEBUG(ethInFloor,uint256(liquidity),floorTick,startTick,token0isWeth);
|
||||
// mint
|
||||
_mint(startTick, floorTick, liquidity);
|
||||
_mint(Stage.FLOOR, startTick, floorTick, liquidity);
|
||||
}
|
||||
|
||||
// ## set Discovery position
|
||||
{
|
||||
int24 tickLower = token0isWeth ? currentTick + ANCHOR_SPACING : currentTick - 11400;
|
||||
int24 tickUpper = token0isWeth ? currentTick + 11400 : currentTick - ANCHOR_SPACING;
|
||||
int24 tickLower = token0isWeth ? currentTick - DISCOVERY_SPACING - ANCHOR_SPACING : currentTick + ANCHOR_SPACING;
|
||||
int24 tickUpper = token0isWeth ? currentTick - ANCHOR_SPACING : currentTick + DISCOVERY_SPACING + ANCHOR_SPACING;
|
||||
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
|
||||
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
|
||||
// discovery with 1.5 times as much liquidity per tick as anchor
|
||||
|
|
@ -279,48 +280,51 @@ contract BaseLineLP {
|
|||
uint128 liquidity = anchorLiquidity * 55 / 2;
|
||||
uint256 harbInDiscovery;
|
||||
if (token0isWeth) {
|
||||
harbInDiscovery = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96,
|
||||
sqrtRatioBX96,
|
||||
liquidity
|
||||
);
|
||||
} else {
|
||||
harbInDiscovery = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96,
|
||||
sqrtRatioBX96,
|
||||
liquidity
|
||||
);
|
||||
}
|
||||
// manage minting limits of harb here
|
||||
if (harbInDiscovery <= harb.balanceOf(address(this))) {
|
||||
_mint(tickLower, tickUpper, liquidity);
|
||||
harb.burn(harb.balanceOf(address(this)));
|
||||
} else {
|
||||
uint256 amount = availableMint(harbInDiscovery - harb.balanceOf(address(this)));
|
||||
harb.mint(amount);
|
||||
mintedToday += amount;
|
||||
amount = harb.balanceOf(address(this));
|
||||
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)) + ANCHOR_SPACING;
|
||||
|
||||
tickWidth = tickWidth / TICK_SPACING * TICK_SPACING;
|
||||
tickWidth = (tickWidth <= ANCHOR_SPACING) ? tickWidth + TICK_SPACING : tickWidth;
|
||||
tickLower = token0isWeth ? currentTick - tickWidth : currentTick + ANCHOR_SPACING;
|
||||
tickUpper = token0isWeth ? currentTick - ANCHOR_SPACING : currentTick + tickWidth;
|
||||
sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
|
||||
sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
|
||||
liquidity = LiquidityAmounts.getLiquidityForAmounts(
|
||||
sqrtPriceX96,
|
||||
sqrtRatioAX96,
|
||||
sqrtRatioBX96,
|
||||
token0isWeth ? 0 : amount,
|
||||
token0isWeth ? amount : 0
|
||||
);
|
||||
}
|
||||
_mint(tickLower, tickUpper, liquidity);
|
||||
harbInDiscovery = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96,
|
||||
sqrtRatioBX96,
|
||||
liquidity
|
||||
);
|
||||
}
|
||||
harb.mint(harbInDiscovery);
|
||||
_mint(Stage.DISCOVERY, tickLower, tickUpper, liquidity);
|
||||
harb.burn(harb.balanceOf(address(this)));
|
||||
// // manage minting limits of harb here
|
||||
// if (harbInDiscovery <= harb.balanceOf(address(this))) {
|
||||
// _mint(tickLower, tickUpper, liquidity);
|
||||
// harb.burn(harb.balanceOf(address(this)));
|
||||
// } else {
|
||||
// uint256 amount = availableMint(harbInDiscovery - harb.balanceOf(address(this)));
|
||||
// harb.mint(amount);
|
||||
// mintedToday += amount;
|
||||
// amount = harb.balanceOf(address(this));
|
||||
// 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)) + ANCHOR_SPACING;
|
||||
|
||||
// tickWidth = tickWidth / TICK_SPACING * TICK_SPACING;
|
||||
// tickWidth = (tickWidth <= ANCHOR_SPACING) ? tickWidth + TICK_SPACING : tickWidth;
|
||||
// tickLower = token0isWeth ? currentTick - tickWidth : currentTick + ANCHOR_SPACING;
|
||||
// tickUpper = token0isWeth ? currentTick - ANCHOR_SPACING : currentTick + tickWidth;
|
||||
// sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
|
||||
// sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
|
||||
// liquidity = LiquidityAmounts.getLiquidityForAmounts(
|
||||
// sqrtPriceX96,
|
||||
// sqrtRatioAX96,
|
||||
// sqrtRatioBX96,
|
||||
// token0isWeth ? 0 : amount,
|
||||
// token0isWeth ? amount : 0
|
||||
// );
|
||||
// }
|
||||
// _mint(tickLower, tickUpper, liquidity);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -341,8 +345,8 @@ contract BaseLineLP {
|
|||
int24 amplitudeTick = anchorTickLower + (anchorTickUpper - anchorTickLower) * 3 / 20;
|
||||
|
||||
// Determine the correct comparison direction based on token0isWeth
|
||||
bool isUp = token0isWeth ? currentTick > centerTick : currentTick < centerTick;
|
||||
bool isEnough = token0isWeth ? currentTick > amplitudeTick : currentTick < amplitudeTick;
|
||||
bool isUp = token0isWeth ? currentTick < centerTick : currentTick > centerTick;
|
||||
bool isEnough = token0isWeth ? currentTick < amplitudeTick : currentTick > amplitudeTick;
|
||||
|
||||
// Check Conditions
|
||||
require(isUp, "call slide(), not shift()");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue