-
Notifications
You must be signed in to change notification settings - Fork 654
Test/mint slippage revert rollback #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -652,7 +652,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { | |
| uint256 tokenId = lpm.nextTokenId(); | ||
| mint(config, 1e18, ActionConstants.MSG_SENDER, ZERO_BYTES); | ||
| BalanceDelta delta = getLastDelta(); | ||
| uint128 amount1Delta = uint128(-delta.amount0()); | ||
| uint128 amount1Delta = uint128(-delta.amount1()); | ||
|
|
||
| bytes memory calls = | ||
| getDecreaseEncoded(tokenId, config, 1e18, MIN_SLIPPAGE_DECREASE, amount1Delta + 1 wei, ZERO_BYTES); | ||
|
|
@@ -745,7 +745,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { | |
| bytes memory calls = getBurnEncoded(tokenId, config, ZERO_BYTES); | ||
|
|
||
| uint256 balance0BeforeAlice = currency0.balanceOf(alice); | ||
| uint256 balance1BeforeAlice = currency0.balanceOf(alice); | ||
| uint256 balance1BeforeAlice = currency1.balanceOf(alice); | ||
|
|
||
| vm.prank(alice); | ||
| lpm.modifyLiquidities(calls, _deadline); | ||
|
|
@@ -974,5 +974,42 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { | |
| assertLt(uint256(int256(deltaDecrease.amount1())), uint256(int256(-deltaMint.amount1()))); // amount1 in the second position was greater than amount1 in the first position | ||
| } | ||
|
|
||
| function test_mint_slippageRevert() public {} | ||
| function test_mint_slippageRevert() public { | ||
| PositionConfig memory config = PositionConfig({poolKey: key, tickLower: -120, tickUpper: 120}); | ||
| uint256 liquidity = 100e18; | ||
|
|
||
| (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity( | ||
| SQRT_PRICE_1_1, | ||
| TickMath.getSqrtPriceAtTick(config.tickLower), | ||
| TickMath.getSqrtPriceAtTick(config.tickUpper), | ||
| uint128(liquidity) | ||
| ); | ||
|
|
||
| // Snapshot state to prove full rollback on revert. | ||
| uint256 nextTokenIdBefore = lpm.nextTokenId(); | ||
| uint256 balance0Before = currency0.balanceOfSelf(); | ||
| uint256 balance1Before = currency1.balanceOfSelf(); | ||
|
|
||
| // Make both slippage limits intentionally too strict by 1 wei. | ||
| bytes memory calls = getMintEncoded( | ||
| config, | ||
| liquidity, | ||
| uint128(amount0 - 1 wei), | ||
| uint128(amount1 - 1 wei), | ||
| ActionConstants.MSG_SENDER, | ||
| ZERO_BYTES | ||
| ); | ||
|
|
||
| // Position manager checks amount0 first for this path. | ||
| vm.expectRevert( | ||
| abi.encodeWithSelector( | ||
| SlippageCheck.MaximumAmountExceeded.selector, uint128(amount0 - 1 wei), uint128(amount0 + 1 wei) | ||
| ) | ||
|
Comment on lines
+993
to
+1007
|
||
| ); | ||
| lpm.modifyLiquidities(calls, _deadline); | ||
|
|
||
| assertEq(lpm.nextTokenId(), nextTokenIdBefore); | ||
| assertEq(currency0.balanceOfSelf(), balance0Before); | ||
| assertEq(currency1.balanceOfSelf(), balance1Before); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test name
test_mint_slippageRevertbreaks the underscore naming pattern used throughout this file (e.g.,test_mint_slippage_revertAmount0,test_decreaseLiquidity_slippage_revertAmount1). Renaming to match the existingtest_<action>_<scenario>convention will make the test suite easier to scan and search.