Skip to content

Commit 266f534

Browse files
committed
Force relayer to pass in position's ticks as input
1 parent d8dbd1e commit 266f534

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/libraries/UniswapV3Lib.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ library UniswapV3Lib {
307307

308308
require(pool.token0() == token0 && pool.token1() == token1 && pool.fee() == fee, "UniswapV3Lib/invalid-pool");
309309

310+
require(tickLower == params.tick.lower, "UniswapV3Lib/lower-tick-does-not-match-position");
311+
require(tickUpper == params.tick.upper, "UniswapV3Lib/upper-tick-does-not-match-position");
312+
310313
// Check that existing position's bounds are still within governance set range
311314
require(tickLower >= params.tickBounds.lower, "UniswapV3Lib/lower-tick-outside-bounds");
312315
require(tickUpper <= params.tickBounds.upper, "UniswapV3Lib/upper-tick-outside-bounds");

test/grove-base-fork/UniswapV3.t.sol

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,76 @@ contract ForeignControllerAddLiquidityFailureTests is UniswapV3TestBase {
620620
vm.stopPrank();
621621
}
622622

623+
624+
function test_addLiquidityUniswapV3_lowerTickDoesNotMatchPosition() public {
625+
// Create new default position
626+
(UniswapV3Lib.Tick memory tick, UniswapV3Lib.TokenAmounts memory desired, )
627+
= _prepareDefaultAddLiquidity();
628+
629+
vm.prank(ALM_RELAYER);
630+
(uint256 tokenId, , ,) = foreignController.addLiquidityUniswapV3(
631+
_getPool(),
632+
0,
633+
tick,
634+
desired,
635+
_minLiquidityPosition(desired.amount0, desired.amount1),
636+
block.timestamp + 1 hours
637+
);
638+
639+
vm.warp(block.timestamp + 2 hours);
640+
641+
// Adding liquidity with the different lower tick bound should fail
642+
vm.startPrank(ALM_RELAYER);
643+
vm.expectRevert("UniswapV3Lib/lower-tick-does-not-match-position");
644+
foreignController.addLiquidityUniswapV3(
645+
_getPool(),
646+
tokenId,
647+
UniswapV3Lib.Tick({
648+
lower: tick.lower + 1,
649+
upper: tick.upper
650+
}),
651+
desired,
652+
_minLiquidityPosition(desired.amount0, desired.amount1),
653+
block.timestamp + 1 hours
654+
);
655+
vm.stopPrank();
656+
}
657+
658+
function test_addLiquidityUniswapV3_upperTickDoesNotMatchPosition() public {
659+
// Create new default position
660+
(UniswapV3Lib.Tick memory tick, UniswapV3Lib.TokenAmounts memory desired, )
661+
= _prepareDefaultAddLiquidity();
662+
663+
vm.prank(ALM_RELAYER);
664+
(uint256 tokenId, , ,) = foreignController.addLiquidityUniswapV3(
665+
_getPool(),
666+
0,
667+
tick,
668+
desired,
669+
_minLiquidityPosition(desired.amount0, desired.amount1),
670+
block.timestamp + 1 hours
671+
);
672+
673+
vm.warp(block.timestamp + 2 hours);
674+
675+
// Adding liquidity with the different upper tick bound should fail
676+
vm.startPrank(ALM_RELAYER);
677+
vm.expectRevert("UniswapV3Lib/upper-tick-does-not-match-position");
678+
foreignController.addLiquidityUniswapV3(
679+
_getPool(),
680+
tokenId,
681+
UniswapV3Lib.Tick({
682+
lower: tick.lower,
683+
upper: tick.upper + 1
684+
}),
685+
desired,
686+
_minLiquidityPosition(desired.amount0, desired.amount1),
687+
block.timestamp + 1 hours
688+
);
689+
vm.stopPrank();
690+
}
691+
692+
623693
function test_addLiquidityUniswapV3_failsAfterLowerTickBoundChanges() public {
624694
// Create new default position
625695
(UniswapV3Lib.Tick memory tick, UniswapV3Lib.TokenAmounts memory desired, )

0 commit comments

Comments
 (0)