Skip to content

Commit

Permalink
rebase onto latest core
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Dec 18, 2023
1 parent ffd1898 commit 433f4d5
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterBytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5848
5638
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactIn1Hop.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
215102
188383
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
293658
266802
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372171
352577
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
213371
186643
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactOut1Hop.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214809
187893
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
297577
267441
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
377309
352616
2 changes: 1 addition & 1 deletion .forge-snapshots/RouterExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212873
186092
25 changes: 15 additions & 10 deletions contracts/V4Router.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions contracts/interfaces/IV4Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions test/V4Router.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions test/shared/implementation/V4RouterImplementation.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down

0 comments on commit 433f4d5

Please sign in to comment.