From 52b304e4ca82a1c5b74f198912e7f17f7d9fc936 Mon Sep 17 00:00:00 2001 From: saucepoint Date: Wed, 12 Jun 2024 11:00:44 -0400 Subject: [PATCH] cleanup: TODOs and imports --- .forge-snapshots/decreaseLiquidity_erc20.snap | 2 +- .forge-snapshots/decreaseLiquidity_erc6909.snap | 2 +- .forge-snapshots/increaseLiquidity_erc20.snap | 2 +- .forge-snapshots/increaseLiquidity_erc6909.snap | 2 +- .forge-snapshots/mintWithLiquidity.snap | 2 +- contracts/NonfungiblePositionManager.sol | 4 ---- contracts/base/BaseLiquidityHandler.sol | 6 ------ contracts/base/BaseLiquidityManagement.sol | 3 --- contracts/interfaces/INonfungiblePositionManager.sol | 2 +- contracts/libraries/CurrencyDeltas.sol | 6 ++---- contracts/libraries/CurrencySenderLibrary.sol | 5 +---- contracts/types/LiquidityRange.sol | 3 +-- test/shared/fuzz/LiquidityFuzzers.sol | 4 ---- 13 files changed, 10 insertions(+), 33 deletions(-) diff --git a/.forge-snapshots/decreaseLiquidity_erc20.snap b/.forge-snapshots/decreaseLiquidity_erc20.snap index e34af74b..be10dbf2 100644 --- a/.forge-snapshots/decreaseLiquidity_erc20.snap +++ b/.forge-snapshots/decreaseLiquidity_erc20.snap @@ -1 +1 @@ -114257 \ No newline at end of file +114113 \ No newline at end of file diff --git a/.forge-snapshots/decreaseLiquidity_erc6909.snap b/.forge-snapshots/decreaseLiquidity_erc6909.snap index 9bf14262..510f90cd 100644 --- a/.forge-snapshots/decreaseLiquidity_erc6909.snap +++ b/.forge-snapshots/decreaseLiquidity_erc6909.snap @@ -1 +1 @@ -112378 \ No newline at end of file +112380 \ No newline at end of file diff --git a/.forge-snapshots/increaseLiquidity_erc20.snap b/.forge-snapshots/increaseLiquidity_erc20.snap index 79a741b2..ea276824 100644 --- a/.forge-snapshots/increaseLiquidity_erc20.snap +++ b/.forge-snapshots/increaseLiquidity_erc20.snap @@ -1 +1 @@ -74001 \ No newline at end of file +74115 \ No newline at end of file diff --git a/.forge-snapshots/increaseLiquidity_erc6909.snap b/.forge-snapshots/increaseLiquidity_erc6909.snap index c8a011cf..78a659ce 100644 --- a/.forge-snapshots/increaseLiquidity_erc6909.snap +++ b/.forge-snapshots/increaseLiquidity_erc6909.snap @@ -1 +1 @@ -77793 \ No newline at end of file +77907 \ No newline at end of file diff --git a/.forge-snapshots/mintWithLiquidity.snap b/.forge-snapshots/mintWithLiquidity.snap index 95aa41f9..1df963dc 100644 --- a/.forge-snapshots/mintWithLiquidity.snap +++ b/.forge-snapshots/mintWithLiquidity.snap @@ -1 +1 @@ -475768 \ No newline at end of file +475882 \ No newline at end of file diff --git a/contracts/NonfungiblePositionManager.sol b/contracts/NonfungiblePositionManager.sol index 500e95d8..b8a84a78 100644 --- a/contracts/NonfungiblePositionManager.sol +++ b/contracts/NonfungiblePositionManager.sol @@ -15,12 +15,8 @@ import {BalanceDelta, toBalanceDelta} from "@uniswap/v4-core/src/types/BalanceDe import {LiquidityAmounts} from "./libraries/LiquidityAmounts.sol"; import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; -import {FeeMath} from "./libraries/FeeMath.sol"; import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; -// TODO: remove -import {console2} from "forge-std/console2.sol"; - contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidityManagement, ERC721 { using CurrencyLibrary for Currency; using CurrencySettleTake for Currency; diff --git a/contracts/base/BaseLiquidityHandler.sol b/contracts/base/BaseLiquidityHandler.sol index 0b66c450..7790bffc 100644 --- a/contracts/base/BaseLiquidityHandler.sol +++ b/contracts/base/BaseLiquidityHandler.sol @@ -8,7 +8,6 @@ import {PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol"; import {BalanceDelta, toBalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol"; import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; -import {TransientStateLibrary} from "@uniswap/v4-core/src/libraries/TransientStateLibrary.sol"; import {SafeCallback} from "./SafeCallback.sol"; import {ImmutableState} from "./ImmutableState.sol"; import {FeeMath} from "../libraries/FeeMath.sol"; @@ -21,9 +20,6 @@ import {LiquiditySaltLibrary} from "../libraries/LiquiditySaltLibrary.sol"; import {LiquidityRange, LiquidityRangeId, LiquidityRangeIdLibrary} from "../types/LiquidityRange.sol"; -// TODO: remove -import {console2} from "forge-std/console2.sol"; - abstract contract BaseLiquidityHandler is SafeCallback { using LiquidityRangeIdLibrary for LiquidityRange; using CurrencyLibrary for Currency; @@ -31,7 +27,6 @@ abstract contract BaseLiquidityHandler is SafeCallback { using CurrencySenderLibrary for Currency; using CurrencyDeltas for IPoolManager; using StateLibrary for IPoolManager; - using TransientStateLibrary for IPoolManager; using LiquiditySaltLibrary for IHooks; using PoolIdLibrary for PoolKey; using SafeCast for uint256; @@ -68,7 +63,6 @@ abstract contract BaseLiquidityHandler is SafeCallback { } } - // TODO: selfOnly modifier function handleIncreaseLiquidity( address sender, LiquidityRange calldata range, diff --git a/contracts/base/BaseLiquidityManagement.sol b/contracts/base/BaseLiquidityManagement.sol index 13269f69..862b4734 100644 --- a/contracts/base/BaseLiquidityManagement.sol +++ b/contracts/base/BaseLiquidityManagement.sol @@ -17,9 +17,6 @@ import {CurrencySettleTake} from "../libraries/CurrencySettleTake.sol"; import {FeeMath} from "../libraries/FeeMath.sol"; import {BaseLiquidityHandler} from "./BaseLiquidityHandler.sol"; -// TODO: remove -import {console2} from "forge-std/console2.sol"; - abstract contract BaseLiquidityManagement is BaseLiquidityHandler { using LiquidityRangeIdLibrary for LiquidityRange; using CurrencyLibrary for Currency; diff --git a/contracts/interfaces/INonfungiblePositionManager.sol b/contracts/interfaces/INonfungiblePositionManager.sol index be182907..5fe1590e 100644 --- a/contracts/interfaces/INonfungiblePositionManager.sol +++ b/contracts/interfaces/INonfungiblePositionManager.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; -import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {LiquidityRange} from "../types/LiquidityRange.sol"; @@ -17,6 +16,7 @@ interface INonfungiblePositionManager { // NOTE: more expensive since LiquidityAmounts is used onchain // function mint(MintParams calldata params) external payable returns (uint256 tokenId, BalanceDelta delta); + function increaseLiquidity(uint256 tokenId, uint256 liquidity, bytes calldata hookData, bool claims) external returns (BalanceDelta delta); diff --git a/contracts/libraries/CurrencyDeltas.sol b/contracts/libraries/CurrencyDeltas.sol index 339e71f6..55389e4f 100644 --- a/contracts/libraries/CurrencyDeltas.sol +++ b/contracts/libraries/CurrencyDeltas.sol @@ -6,10 +6,8 @@ import {Currency} from "@uniswap/v4-core/src/types/Currency.sol"; import {BalanceDelta, toBalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {SafeCast} from "@uniswap/v4-core/src/libraries/SafeCast.sol"; -import {console2} from "forge-std/console2.sol"; - library CurrencyDeltas { - using SafeCast for uint256; + using SafeCast for int256; /// @notice Get the current delta for a caller in the two given currencies /// @param caller_ The address of the caller @@ -35,6 +33,6 @@ library CurrencyDeltas { slots[0] = key0; slots[1] = key1; bytes32[] memory result = manager.exttload(slots); - return toBalanceDelta(int128(int256(uint256(result[0]))), int128(int256(uint256(result[1])))); + return toBalanceDelta(int256(uint256(result[0])).toInt128(), int256(uint256(result[1])).toInt128()); } } diff --git a/contracts/libraries/CurrencySenderLibrary.sol b/contracts/libraries/CurrencySenderLibrary.sol index 65a44e07..eb991892 100644 --- a/contracts/libraries/CurrencySenderLibrary.sol +++ b/contracts/libraries/CurrencySenderLibrary.sol @@ -2,14 +2,11 @@ pragma solidity ^0.8.24; import {Currency, CurrencyLibrary} from "v4-core/types/Currency.sol"; -import {CurrencySettleTake} from "./CurrencySettleTake.sol"; import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol"; -import {IERC20Minimal} from "v4-core/interfaces/external/IERC20Minimal.sol"; /// @notice Library used to send Currencies from address to address library CurrencySenderLibrary { using CurrencyLibrary for Currency; - using CurrencySettleTake for Currency; /// @notice Send a custodied Currency to a recipient /// @dev If sending ERC20 or native, the PoolManager must be unlocked @@ -25,7 +22,7 @@ library CurrencySenderLibrary { manager.transfer(recipient, currency.toId(), amount); } else { manager.burn(address(this), currency.toId(), amount); - currency.take(manager, recipient, amount, false); + manager.take(currency, recipient, amount); } } } diff --git a/contracts/types/LiquidityRange.sol b/contracts/types/LiquidityRange.sol index 88545687..4d00fb4b 100644 --- a/contracts/types/LiquidityRange.sol +++ b/contracts/types/LiquidityRange.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.24; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; -// TODO: move into core? some of the mappings / pool.state seem to hash position id's struct LiquidityRange { PoolKey key; int24 tickLower; @@ -12,7 +11,7 @@ struct LiquidityRange { type LiquidityRangeId is bytes32; -/// @notice Library for computing the ID of a pool +/// @notice Library for computing the ID of a liquidity range library LiquidityRangeIdLibrary { function toId(LiquidityRange memory position) internal pure returns (LiquidityRangeId) { // TODO: gas, is it better to encodePacked? diff --git a/test/shared/fuzz/LiquidityFuzzers.sol b/test/shared/fuzz/LiquidityFuzzers.sol index 6f1e7f0a..03e50f9b 100644 --- a/test/shared/fuzz/LiquidityFuzzers.sol +++ b/test/shared/fuzz/LiquidityFuzzers.sol @@ -1,13 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {Vm} from "forge-std/Vm.sol"; - import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; -import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; -import {Pool} from "@uniswap/v4-core/src/libraries/Pool.sol"; import {Fuzzers} from "@uniswap/v4-core/src/test/Fuzzers.sol"; import {INonfungiblePositionManager} from "../../../contracts/interfaces/INonfungiblePositionManager.sol";