fix position calculation
This commit is contained in:
parent
548fd006c1
commit
af031877a5
2 changed files with 18 additions and 3 deletions
|
|
@ -248,13 +248,14 @@ abstract contract ThreePositionStrategy is UniswapMath, VWAPTracker {
|
|||
|
||||
uint128 liquidity;
|
||||
if (token0isWeth) {
|
||||
liquidity = LiquidityAmounts.getLiquidityForAmount1(
|
||||
// floor leg sits entirely above current tick when WETH is token0, so budget is token0
|
||||
liquidity = LiquidityAmounts.getLiquidityForAmount0(
|
||||
TickMath.getSqrtRatioAtTick(vwapTick),
|
||||
TickMath.getSqrtRatioAtTick(floorTick),
|
||||
actualFloorEthBalance
|
||||
);
|
||||
} else {
|
||||
liquidity = LiquidityAmounts.getLiquidityForAmount0(
|
||||
liquidity = LiquidityAmounts.getLiquidityForAmount1(
|
||||
TickMath.getSqrtRatioAtTick(vwapTick),
|
||||
TickMath.getSqrtRatioAtTick(floorTick),
|
||||
actualFloorEthBalance
|
||||
|
|
@ -263,4 +264,4 @@ abstract contract ThreePositionStrategy is UniswapMath, VWAPTracker {
|
|||
|
||||
_mintPosition(Stage.FLOOR, token0isWeth ? vwapTick : floorTick, token0isWeth ? floorTick : vwapTick, liquidity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,6 +139,20 @@ contract LiquidityManagerTest is UniSwapHelper {
|
|||
token0isWeth = _token0isWeth;
|
||||
}
|
||||
|
||||
function testRecenterUsesAvailableEthWhenToken0IsWeth() public {
|
||||
deployProtocolWithTokenOrder(true);
|
||||
vm.deal(address(lm), 1 ether);
|
||||
|
||||
uint256 initialEthBudget = address(lm).balance;
|
||||
assertEq(initialEthBudget, 1 ether, "precondition");
|
||||
|
||||
vm.prank(RECENTER_CALLER);
|
||||
lm.recenter();
|
||||
|
||||
uint256 remainingEthBudget = address(lm).balance + weth.balanceOf(address(lm));
|
||||
assertLe(remainingEthBudget, initialEthBudget, "should not overdraw ETH budget");
|
||||
}
|
||||
|
||||
/// @notice Recenter with intelligent error handling for extreme price conditions
|
||||
/// @param last Whether this is the last attempt (affects error handling)
|
||||
function recenterWithErrorHandling(bool last) internal {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue