diff --git a/.forge-snapshots/PositionManager_burn_empty.snap b/.forge-snapshots/PositionManager_burn_empty.snap index 492cae30..856ec3b4 100644 --- a/.forge-snapshots/PositionManager_burn_empty.snap +++ b/.forge-snapshots/PositionManager_burn_empty.snap @@ -1 +1 @@ -47167 \ No newline at end of file +47158 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_burn_empty_native.snap b/.forge-snapshots/PositionManager_burn_empty_native.snap index 6ad16fc4..c3b5ff40 100644 --- a/.forge-snapshots/PositionManager_burn_empty_native.snap +++ b/.forge-snapshots/PositionManager_burn_empty_native.snap @@ -1 +1 @@ -46984 \ No newline at end of file +46976 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap b/.forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap index 130b6ee7..9cd54e27 100644 --- a/.forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap +++ b/.forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap @@ -1 +1 @@ -122980 \ No newline at end of file +122971 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap b/.forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap index 1cddf5e5..d06ed4e0 100644 --- a/.forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap +++ b/.forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap @@ -1 +1 @@ -122689 \ No newline at end of file +122680 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_burn_nonEmpty_withClose.snap b/.forge-snapshots/PositionManager_burn_nonEmpty_withClose.snap index 211bfaf9..44efeb87 100644 --- a/.forge-snapshots/PositionManager_burn_nonEmpty_withClose.snap +++ b/.forge-snapshots/PositionManager_burn_nonEmpty_withClose.snap @@ -1 +1 @@ -130058 \ No newline at end of file +130049 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap b/.forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap index 58bede9f..75b82d5a 100644 --- a/.forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap +++ b/.forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap @@ -1 +1 @@ -129768 \ No newline at end of file +129759 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_decrease_burnEmpty.snap b/.forge-snapshots/PositionManager_decrease_burnEmpty.snap index de137414..02110f25 100644 --- a/.forge-snapshots/PositionManager_decrease_burnEmpty.snap +++ b/.forge-snapshots/PositionManager_decrease_burnEmpty.snap @@ -1 +1 @@ -134137 \ No newline at end of file +134128 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_decrease_burnEmpty_native.snap b/.forge-snapshots/PositionManager_decrease_burnEmpty_native.snap index ab7b40f5..c9a2b5b8 100644 --- a/.forge-snapshots/PositionManager_decrease_burnEmpty_native.snap +++ b/.forge-snapshots/PositionManager_decrease_burnEmpty_native.snap @@ -1 +1 @@ -126876 \ No newline at end of file +126868 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_multicall_initialize_mint.snap b/.forge-snapshots/PositionManager_multicall_initialize_mint.snap index 93b17f36..993285bf 100644 --- a/.forge-snapshots/PositionManager_multicall_initialize_mint.snap +++ b/.forge-snapshots/PositionManager_multicall_initialize_mint.snap @@ -1 +1 @@ -416486 \ No newline at end of file +416464 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_permit.snap b/.forge-snapshots/PositionManager_permit.snap index 296e82ca..ee34c59c 100644 --- a/.forge-snapshots/PositionManager_permit.snap +++ b/.forge-snapshots/PositionManager_permit.snap @@ -1 +1 @@ -79467 \ No newline at end of file +79445 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_permit_secondPosition.snap b/.forge-snapshots/PositionManager_permit_secondPosition.snap index 3f96aa23..0b63319b 100644 --- a/.forge-snapshots/PositionManager_permit_secondPosition.snap +++ b/.forge-snapshots/PositionManager_permit_secondPosition.snap @@ -1 +1 @@ -62355 \ No newline at end of file +62333 \ No newline at end of file diff --git a/.forge-snapshots/PositionManager_permit_twice.snap b/.forge-snapshots/PositionManager_permit_twice.snap index 913eee8f..7772c13d 100644 --- a/.forge-snapshots/PositionManager_permit_twice.snap +++ b/.forge-snapshots/PositionManager_permit_twice.snap @@ -1 +1 @@ -45243 \ No newline at end of file +45221 \ No newline at end of file diff --git a/src/PositionManager.sol b/src/PositionManager.sol index 720275d4..c8a43f3b 100644 --- a/src/PositionManager.sol +++ b/src/PositionManager.sol @@ -302,7 +302,7 @@ contract PositionManager is uint128 amount1Min, bytes calldata hookData ) internal onlyIfApproved(msgSender(), tokenId) onlyValidConfig(tokenId, config) { - uint256 liquidity = uint256(_getPositionLiquidity(config, tokenId)); + uint256 liquidity = uint256(getPositionLiquidity(tokenId, config)); BalanceDelta liquidityDelta; // Can only call modify if there is non zero liquidity. @@ -338,16 +338,6 @@ contract PositionManager is } } - function _getPositionLiquidity(PositionConfig calldata config, uint256 tokenId) - internal - view - returns (uint128 liquidity) - { - bytes32 positionId = - Position.calculatePositionKey(address(this), config.tickLower, config.tickUpper, bytes32(tokenId)); - liquidity = poolManager.getPositionLiquidity(config.poolKey.toId(), positionId); - } - /// @notice Sweeps the entire contract balance of specified currency to the recipient function _sweep(Currency currency, address to) internal { uint256 balance = currency.balanceOfSelf(); @@ -370,6 +360,16 @@ contract PositionManager is if (positionConfigs.hasSubscriber(id)) _notifyTransfer(id, from, to); } + function getPositionLiquidity(uint256 tokenId, PositionConfig calldata config) + public + view + returns (uint128 liquidity) + { + bytes32 positionId = + Position.calculatePositionKey(address(this), config.tickLower, config.tickUpper, bytes32(tokenId)); + liquidity = poolManager.getPositionLiquidity(config.poolKey.toId(), positionId); + } + /// @inheritdoc IPositionManager function getPositionConfigId(uint256 tokenId) external view returns (bytes32) { return positionConfigs.getConfigId(tokenId); diff --git a/src/interfaces/IPositionManager.sol b/src/interfaces/IPositionManager.sol index 0fde8d62..3c45df7d 100644 --- a/src/interfaces/IPositionManager.sol +++ b/src/interfaces/IPositionManager.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.24; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; import {Currency} from "@uniswap/v4-core/src/types/Currency.sol"; +import {PositionConfig} from "../libraries/PositionConfig.sol"; import {INotifier} from "./INotifier.sol"; @@ -22,4 +23,13 @@ interface IPositionManager is INotifier { /// @return configId a truncated hash of the position's poolkey, tickLower, and tickUpper /// @dev truncates the least significant bit of the hash function getPositionConfigId(uint256 tokenId) external view returns (bytes32 configId); + + /// @param tokenId the ERC721 tokenId + /// @param config the corresponding PositionConfig for the tokenId + /// @return liquidity the position's liquidity, as a liquidityAmount + /// @dev this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library + function getPositionLiquidity(uint256 tokenId, PositionConfig calldata config) + external + view + returns (uint128 liquidity); } diff --git a/test/position-managers/Execute.t.sol b/test/position-managers/Execute.t.sol index c443d173..5417c71a 100644 --- a/test/position-managers/Execute.t.sol +++ b/test/position-managers/Execute.t.sol @@ -72,9 +72,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { increaseLiquidity(tokenId, config, liquidityToAdd, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, initialLiquidity + liquidityToAdd); } @@ -104,9 +102,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { bytes memory calls = planner.finalizeModifyLiquidityWithClose(config.poolKey); lpm.modifyLiquidities(calls, _deadline); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, initialLiquidity + liquidityToAdd + liquidityToAdd2); } @@ -136,9 +132,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { bytes memory calls = planner.finalizeModifyLiquidityWithSettlePair(config.poolKey); lpm.modifyLiquidities(calls, _deadline); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, initialLiquidity + liquidityToAdd + liquidityToAdd2); } @@ -171,9 +165,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { bytes memory calls = planner.finalizeModifyLiquidityWithClose(config.poolKey); lpm.modifyLiquidities(calls, _deadline); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, initialLiquidity + liquidityToAdd); } @@ -242,9 +234,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { { // old position has no liquidity - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - uint128 liquidity = manager.getPositionLiquidity(config.poolKey.toId(), positionId); + uint128 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); // new token was minted @@ -252,10 +242,8 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers { assertEq(lpm.ownerOf(newTokenId), address(this)); // new token has expected liquidity - positionId = Position.calculatePositionKey( - address(lpm), newConfig.tickLower, newConfig.tickUpper, bytes32(newTokenId) - ); - liquidity = manager.getPositionLiquidity(config.poolKey.toId(), positionId); + + liquidity = lpm.getPositionLiquidity(newTokenId, newConfig); assertEq(liquidity, newLiquidity); } } diff --git a/test/position-managers/IncreaseLiquidity.t.sol b/test/position-managers/IncreaseLiquidity.t.sol index 018765e5..f1a65efd 100644 --- a/test/position-managers/IncreaseLiquidity.t.sol +++ b/test/position-managers/IncreaseLiquidity.t.sol @@ -305,16 +305,14 @@ contract IncreaseLiquidityTest is Test, PosmTestSetup, Fuzzers { mint(config, liquidityAlice, alice, ZERO_BYTES); vm.stopPrank(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenIdAlice)); - uint128 oldLiquidity = StateLibrary.getPositionLiquidity(manager, config.poolKey.toId(), positionId); + uint128 oldLiquidity = lpm.getPositionLiquidity(tokenIdAlice, config); // bob can increase liquidity for alice even though he is not the owner / not approved vm.startPrank(bob); increaseLiquidity(tokenIdAlice, config, 100e18, ZERO_BYTES); vm.stopPrank(); - uint128 newLiquidity = StateLibrary.getPositionLiquidity(manager, config.poolKey.toId(), positionId); + uint128 newLiquidity = lpm.getPositionLiquidity(tokenIdAlice, config); // assert liqudity increased by the correct amount assertEq(newLiquidity, oldLiquidity + uint128(100e18)); @@ -645,9 +643,7 @@ contract IncreaseLiquidityTest is Test, PosmTestSetup, Fuzzers { mint(config, liquidityAlice, alice, ZERO_BYTES); uint256 tokenIdAlice = lpm.nextTokenId() - 1; - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenIdAlice)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenIdAlice, config); assertEq(liquidity, liquidityAlice); // alice increases with the balance in the position manager @@ -682,7 +678,7 @@ contract IncreaseLiquidityTest is Test, PosmTestSetup, Fuzzers { uint256 amount0 = uint128(-delta.amount0()); uint256 amount1 = uint128(-delta.amount1()); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenIdAlice, config); assertEq(liquidity, 2 * liquidityAlice); // The balances were swept back to this address. diff --git a/test/position-managers/NativeToken.t.sol b/test/position-managers/NativeToken.t.sol index ee3779da..691a1445 100644 --- a/test/position-managers/NativeToken.t.sol +++ b/test/position-managers/NativeToken.t.sol @@ -91,9 +91,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities{value: amount0 + 1}(calls, _deadline); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); assertEq(balance0Before - currency0.balanceOfSelf(), uint256(int256(-delta.amount0())), "incorrect amount0"); @@ -145,9 +143,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities{value: amount0 * 2 + 1}(calls, _deadline); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // only paid the delta amount, with excess tokens returned to caller @@ -192,9 +188,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities{value: amount0 * 2 + 1}(calls, _deadline); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // only paid the delta amount, with excess tokens returned to caller @@ -218,9 +212,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { uint256 tokenId = lpm.nextTokenId(); mintWithNative(SQRT_PRICE_1_1, config, liquidityToAdd, ActionConstants.MSG_SENDER, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // burn liquidity @@ -235,7 +227,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { // No decrease/modifyLiq call will actually happen on the call to burn so the deltas array will be the same length. assertEq(numDeltas, hook.numberDeltasReturned()); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); // TODO: slightly off by 1 bip (0.0001%) @@ -273,9 +265,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { uint256 tokenId = lpm.nextTokenId(); mintWithNative(SQRT_PRICE_1_1, config, liquidityToAdd, ActionConstants.MSG_SENDER, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // burn liquidity @@ -295,7 +285,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { // No decrease/modifyLiq call will actually happen on the call to burn so the deltas array will be the same length. assertEq(numDeltas, hook.numberDeltasReturned()); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); // TODO: slightly off by 1 bip (0.0001%) @@ -333,9 +323,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { uint256 tokenId = lpm.nextTokenId(); mintWithNative(SQRT_PRICE_1_1, config, liquidityToAdd, ActionConstants.MSG_SENDER, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // burn liquidity @@ -345,7 +333,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { burn(tokenId, config, ZERO_BYTES); BalanceDelta deltaBurn = getLastDelta(); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); // TODO: slightly off by 1 bip (0.0001%) @@ -383,9 +371,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { uint256 tokenId = lpm.nextTokenId(); mintWithNative(SQRT_PRICE_1_1, config, liquidityToAdd, ActionConstants.MSG_SENDER, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); // burn liquidity @@ -400,7 +386,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities(calls, _deadline); BalanceDelta deltaBurn = getLastDelta(); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); // TODO: slightly off by 1 bip (0.0001%) @@ -451,9 +437,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { BalanceDelta delta = getLastDelta(); // verify position liquidity increased - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, liquidityToAdd + liquidityToAdd); // liquidity was doubled // verify native token balances changed as expected @@ -505,9 +489,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { BalanceDelta delta = getLastDelta(); // verify position liquidity increased - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, liquidityToAdd + liquidityToAdd); // liquidity was doubled // verify native token balances changed as expected, with overpaid tokens returned @@ -557,9 +539,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { BalanceDelta delta = getLastDelta(); // verify position liquidity increased - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, liquidityToAdd + liquidityToAdd); // liquidity was doubled // verify native token balances changed as expected, with overpaid tokens returned @@ -596,9 +576,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { decreaseLiquidity(tokenId, config, decreaseLiquidityDelta, ZERO_BYTES); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); // verify native token balances changed as expected @@ -643,9 +621,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities(calls, _deadline); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); // verify native token balances changed as expected @@ -815,9 +791,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.multicall{value: 10e18}(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 100e18); assertEq(sub.notifySubscribeCount(), 1); diff --git a/test/position-managers/Permit.t.sol b/test/position-managers/Permit.t.sol index 8de6b6c5..22f887f0 100644 --- a/test/position-managers/Permit.t.sol +++ b/test/position-managers/Permit.t.sol @@ -88,9 +88,7 @@ contract PermitTest is Test, PosmTestSetup { vm.stopPrank(); // alice's position decreased liquidity - bytes32 positionId = - keccak256(abi.encodePacked(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenIdAlice))); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenIdAlice, config); assertEq(liquidity, liquidityAlice - liquidityToRemove); } @@ -209,9 +207,7 @@ contract PermitTest is Test, PosmTestSetup { decreaseLiquidity(tokenId, config, liquidityToRemove, ZERO_BYTES); vm.stopPrank(); - bytes32 positionId = - keccak256(abi.encodePacked(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId))); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, liquidityAlice - liquidityToRemove); } @@ -240,9 +236,8 @@ contract PermitTest is Test, PosmTestSetup { decreaseLiquidity(tokenId, config, liquidityToRemove, ZERO_BYTES); vm.stopPrank(); - bytes32 positionId = - keccak256(abi.encodePacked(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId))); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); + assertEq(liquidity, liquidityAlice - liquidityToRemove); } } diff --git a/test/position-managers/PositionManager.multicall.t.sol b/test/position-managers/PositionManager.multicall.t.sol index 1106f733..da9734c0 100644 --- a/test/position-managers/PositionManager.multicall.t.sol +++ b/test/position-managers/PositionManager.multicall.t.sol @@ -215,9 +215,7 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest vm.prank(bob); lpm.multicall(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, liquidityAlice - liquidityToRemove); } @@ -258,9 +256,7 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest vm.prank(bob); lpm.multicall(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); (_amount,,) = permit2.allowance(address(bob), Currency.unwrap(currency0), address(lpm)); @@ -316,9 +312,7 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest vm.prank(bob); lpm.multicall(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); (_amount0,,) = permit2.allowance(address(bob), Currency.unwrap(currency0), address(lpm)); (_amount1,,) = permit2.allowance(address(bob), Currency.unwrap(currency1), address(lpm)); diff --git a/test/position-managers/PositionManager.notifier.t.sol b/test/position-managers/PositionManager.notifier.t.sol index a1544f13..9a15ebad 100644 --- a/test/position-managers/PositionManager.notifier.t.sol +++ b/test/position-managers/PositionManager.notifier.t.sol @@ -234,9 +234,7 @@ contract PositionManagerNotifierTest is Test, PosmTestSetup, GasSnapshot { lpm.multicall(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 100e18); assertEq(sub.notifySubscribeCount(), 1); @@ -272,9 +270,7 @@ contract PositionManagerNotifierTest is Test, PosmTestSetup, GasSnapshot { lpm.multicall(calls); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 110e18); assertEq(sub.notifySubscribeCount(), 1); diff --git a/test/position-managers/PositionManager.t.sol b/test/position-managers/PositionManager.t.sol index 64e4045a..6daf517d 100644 --- a/test/position-managers/PositionManager.t.sol +++ b/test/position-managers/PositionManager.t.sol @@ -115,9 +115,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { assertEq(lpm.nextTokenId(), 2); assertEq(lpm.ownerOf(tokenId), address(this)); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); assertEq(balance0Before - currency0.balanceOfSelf(), uint256(int256(-delta.amount0())), "incorrect amount0"); @@ -322,9 +320,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { assertEq(tokenId, 1); assertEq(lpm.ownerOf(1), address(this)); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); @@ -339,7 +335,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { burn(tokenId, config, ZERO_BYTES); assertEq(numDeltas, hook.numberDeltasReturned()); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); @@ -368,9 +364,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { assertEq(tokenId, 1); assertEq(lpm.ownerOf(1), address(this)); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta)); @@ -392,7 +386,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { assertEq(uint256(int256(deltaBurn.amount0())), amount0); assertEq(uint256(int256(deltaBurn.amount1())), amount1); - (liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, 0); @@ -484,9 +478,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { decreaseLiquidity(tokenId, config, decreaseLiquidityDelta, ZERO_BYTES); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); assertEq(currency0.balanceOfSelf(), balance0Before + uint256(uint128(delta.amount0()))); @@ -522,9 +514,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { lpm.modifyLiquidities(calls, _deadline); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); // did not recieve tokens, as they were forfeited with CLEAR @@ -599,9 +589,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { uint256 balance1Before = currency1.balanceOfSelf(); decreaseLiquidity(tokenId, config, decreaseLiquidityDelta, ZERO_BYTES); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); @@ -702,9 +690,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { decreaseLiquidity(tokenId, config, decreaseLiquidityDelta, ZERO_BYTES); BalanceDelta delta = getLastDelta(); - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 liquidity,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 liquidity = lpm.getPositionLiquidity(tokenId, config); assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta); @@ -789,9 +775,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { vm.stopPrank(); // position liquidity increased - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 newLiq,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 newLiq = lpm.getPositionLiquidity(tokenId, config); assertEq(newLiq, liquidity + liquidityToAdd); // alice paid the tokens @@ -833,9 +817,7 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers { { // position liquidity decreased - bytes32 positionId = - Position.calculatePositionKey(address(lpm), config.tickLower, config.tickUpper, bytes32(tokenId)); - (uint256 newLiq,,) = manager.getPositionInfo(config.poolKey.toId(), positionId); + uint256 newLiq = lpm.getPositionLiquidity(tokenId, config); assertEq(newLiq, liquidity - liquidityToRemove); }