diff --git a/.forge-snapshots/RouterBytecode.snap b/.forge-snapshots/RouterBytecode.snap index 2006215b..2fef3e2c 100644 --- a/.forge-snapshots/RouterBytecode.snap +++ b/.forge-snapshots/RouterBytecode.snap @@ -1 +1 @@ -5848 \ No newline at end of file +5638 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactIn1Hop.snap b/.forge-snapshots/RouterExactIn1Hop.snap index 33153fb6..e797c153 100644 --- a/.forge-snapshots/RouterExactIn1Hop.snap +++ b/.forge-snapshots/RouterExactIn1Hop.snap @@ -1 +1 @@ -215102 \ No newline at end of file +188383 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactIn2Hops.snap b/.forge-snapshots/RouterExactIn2Hops.snap index 170a0cb5..9e23b3e3 100644 --- a/.forge-snapshots/RouterExactIn2Hops.snap +++ b/.forge-snapshots/RouterExactIn2Hops.snap @@ -1 +1 @@ -293658 \ No newline at end of file +266802 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactIn3Hops.snap b/.forge-snapshots/RouterExactIn3Hops.snap index 0ce5b2aa..ebb5d10f 100644 --- a/.forge-snapshots/RouterExactIn3Hops.snap +++ b/.forge-snapshots/RouterExactIn3Hops.snap @@ -1 +1 @@ -372171 \ No newline at end of file +352577 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactInputSingle.snap b/.forge-snapshots/RouterExactInputSingle.snap index 0d7050ac..6bd80d8b 100644 --- a/.forge-snapshots/RouterExactInputSingle.snap +++ b/.forge-snapshots/RouterExactInputSingle.snap @@ -1 +1 @@ -213371 \ No newline at end of file +186643 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactOut1Hop.snap b/.forge-snapshots/RouterExactOut1Hop.snap index feb43b21..ed6dbcf9 100644 --- a/.forge-snapshots/RouterExactOut1Hop.snap +++ b/.forge-snapshots/RouterExactOut1Hop.snap @@ -1 +1 @@ -214809 \ No newline at end of file +187893 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactOut2Hops.snap b/.forge-snapshots/RouterExactOut2Hops.snap index 18caeb54..f75e93a4 100644 --- a/.forge-snapshots/RouterExactOut2Hops.snap +++ b/.forge-snapshots/RouterExactOut2Hops.snap @@ -1 +1 @@ -297577 \ No newline at end of file +267441 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactOut3Hops.snap b/.forge-snapshots/RouterExactOut3Hops.snap index b07233a8..6cd5c9ac 100644 --- a/.forge-snapshots/RouterExactOut3Hops.snap +++ b/.forge-snapshots/RouterExactOut3Hops.snap @@ -1 +1 @@ -377309 \ No newline at end of file +352616 \ No newline at end of file diff --git a/.forge-snapshots/RouterExactOutputSingle.snap b/.forge-snapshots/RouterExactOutputSingle.snap index fe945560..72632a8a 100644 --- a/.forge-snapshots/RouterExactOutputSingle.snap +++ b/.forge-snapshots/RouterExactOutputSingle.snap @@ -1 +1 @@ -212873 \ No newline at end of file +186092 \ No newline at end of file diff --git a/contracts/V4Router.sol b/contracts/V4Router.sol index 812a2adb..55349dab 100644 --- a/contracts/V4Router.sol +++ b/contracts/V4Router.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.19; -import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol"; -import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; -import {ILockCallback} from "@uniswap/v4-core/contracts/interfaces/callback/ILockCallback.sol"; -import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol"; -import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; -import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol"; -import {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol"; -import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol"; +import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {ILockCallback} from "@uniswap/v4-core/src/interfaces/callback/ILockCallback.sol"; +import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; +import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; +import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol"; +import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; +import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; import {PathKey} from "./libraries/PathKey.sol"; import {IV4Router} from "./interfaces/IV4Router.sol"; @@ -30,11 +30,16 @@ abstract contract V4Router is IV4Router, ILockCallback { } function _v4Swap(SwapType swapType, bytes memory params) internal { - poolManager.lock(abi.encode(SwapInfo(swapType, msg.sender, params))); + poolManager.lock(address(this), abi.encode(SwapInfo(swapType, msg.sender, params))); } /// @inheritdoc ILockCallback - function lockAcquired(bytes calldata encodedSwapInfo) external override poolManagerOnly returns (bytes memory) { + function lockAcquired(address, /*lockCaller*/ bytes calldata encodedSwapInfo) + external + override + poolManagerOnly + returns (bytes memory) + { SwapInfo memory swapInfo = abi.decode(encodedSwapInfo, (SwapInfo)); if (swapInfo.swapType == SwapType.ExactInput) { diff --git a/contracts/interfaces/IV4Router.sol b/contracts/interfaces/IV4Router.sol index 7de5a4cf..d59680be 100644 --- a/contracts/interfaces/IV4Router.sol +++ b/contracts/interfaces/IV4Router.sol @@ -2,13 +2,13 @@ pragma solidity ^0.8.19; import "forge-std/console.sol"; -import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol"; -import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; -import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol"; -import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; -import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol"; -import {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol"; -import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol"; +import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; +import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; +import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol"; +import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; +import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; import {PathKey} from "../libraries/PathKey.sol"; /// @title UniswapV4Routing diff --git a/test/V4Router.t.sol b/test/V4Router.t.sol index 6534910e..684512e0 100644 --- a/test/V4Router.t.sol +++ b/test/V4Router.t.sol @@ -2,24 +2,26 @@ pragma solidity ^0.8.19; import {Test} from "forge-std/Test.sol"; -import {Deployers} from "@uniswap/v4-core/test/foundry-tests/utils/Deployers.sol"; import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol"; +import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; +import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {Deployers} from "@uniswap/v4-core/test/utils/Deployers.sol"; import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; -import {PoolModifyPositionTest} from "@uniswap/v4-core/contracts/test/PoolModifyPositionTest.sol"; -import {PoolManager} from "@uniswap/v4-core/contracts/PoolManager.sol"; -import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; -import {V4Router} from "../contracts/V4Router.sol"; +import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol"; +import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol"; +import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; +import {PoolModifyPositionTest} from "@uniswap/v4-core/src/test/PoolModifyPositionTest.sol"; import {IV4Router} from "../contracts/interfaces/IV4Router.sol"; +import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; import {V4RouterImplementation} from "./shared/implementation/V4RouterImplementation.sol"; -import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; -import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol"; -import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol"; import {PathKey} from "../contracts/libraries/PathKey.sol"; +import {UniswapV4ERC20} from "../contracts/libraries/UniswapV4ERC20.sol"; +import {HookEnabledSwapRouter} from "./utils/HookEnabledSwapRouter.sol"; contract V4RouterTest is Test, Deployers, GasSnapshot { using CurrencyLibrary for Currency; - PoolManager manager; PoolModifyPositionTest positionManager; V4RouterImplementation router; @@ -35,7 +37,8 @@ contract V4RouterTest is Test, Deployers, GasSnapshot { MockERC20[] tokenPath; function setUp() public { - manager = new PoolManager(500000); + deployFreshManagerAndRouters(); + router = new V4RouterImplementation(manager); positionManager = new PoolModifyPositionTest(manager); @@ -278,8 +281,6 @@ contract V4RouterTest is Test, Deployers, GasSnapshot { uint256 prevBalance1 = token1.balanceOf(address(this)); snapStart("RouterExactOut1Hop"); - bytes memory encoded = abi.encode(params); - IV4Router.ExactOutputParams memory decoded = abi.decode(encoded, (IV4Router.ExactOutputParams)); router.swap(IV4Router.SwapType.ExactOutput, abi.encode(params)); snapEnd(); @@ -357,7 +358,7 @@ contract V4RouterTest is Test, Deployers, GasSnapshot { } function setupPool(PoolKey memory poolKey) internal { - manager.initialize(poolKey, SQRT_RATIO_1_1, ZERO_BYTES); + initializeRouter.initialize(poolKey, SQRT_RATIO_1_1, ZERO_BYTES); MockERC20(Currency.unwrap(poolKey.currency0)).approve(address(positionManager), type(uint256).max); MockERC20(Currency.unwrap(poolKey.currency1)).approve(address(positionManager), type(uint256).max); positionManager.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-887220, 887220, 200 ether), "0x"); diff --git a/test/shared/implementation/V4RouterImplementation.sol b/test/shared/implementation/V4RouterImplementation.sol index 420b4a63..aac7fde4 100644 --- a/test/shared/implementation/V4RouterImplementation.sol +++ b/test/shared/implementation/V4RouterImplementation.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.19; -import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; -import {IERC20Minimal} from "@uniswap/v4-core/contracts/interfaces/external/IERC20Minimal.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {IERC20Minimal} from "@uniswap/v4-core/src/interfaces/external/IERC20Minimal.sol"; import {IV4Router} from "../../../contracts/interfaces/IV4Router.sol"; import {V4Router} from "../../../contracts/V4Router.sol";