From da2b0e6a1d48f9089f7b10265ffb7db85a0089fd Mon Sep 17 00:00:00 2001 From: emmaguo13 Date: Thu, 10 Aug 2023 16:53:26 -0400 Subject: [PATCH] cleanup and add custom tick spacing error --- .forge-snapshots/add liquidity.snap | 2 +- .forge-snapshots/initialize.snap | 2 +- .forge-snapshots/remove liquidity and rebalance.snap | 2 +- .forge-snapshots/remove liquidity.snap | 2 +- contracts/hooks/examples/FullRange.sol | 3 ++- contracts/libraries/UniswapV4ERC20.sol | 8 -------- test/FullRange.t.sol | 4 +--- 7 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.forge-snapshots/add liquidity.snap b/.forge-snapshots/add liquidity.snap index 32e6fcfd..e4e69e1d 100644 --- a/.forge-snapshots/add liquidity.snap +++ b/.forge-snapshots/add liquidity.snap @@ -1 +1 @@ -440343 \ No newline at end of file +440321 \ No newline at end of file diff --git a/.forge-snapshots/initialize.snap b/.forge-snapshots/initialize.snap index aeb4606d..39789138 100644 --- a/.forge-snapshots/initialize.snap +++ b/.forge-snapshots/initialize.snap @@ -1 +1 @@ -891626 \ No newline at end of file +878400 \ No newline at end of file diff --git a/.forge-snapshots/remove liquidity and rebalance.snap b/.forge-snapshots/remove liquidity and rebalance.snap index db8fb3ef..c0c409b9 100644 --- a/.forge-snapshots/remove liquidity and rebalance.snap +++ b/.forge-snapshots/remove liquidity and rebalance.snap @@ -1 +1 @@ -442540 \ No newline at end of file +442584 \ No newline at end of file diff --git a/.forge-snapshots/remove liquidity.snap b/.forge-snapshots/remove liquidity.snap index b0bc2736..0e2a213e 100644 --- a/.forge-snapshots/remove liquidity.snap +++ b/.forge-snapshots/remove liquidity.snap @@ -1 +1 @@ -112996 \ No newline at end of file +113040 \ No newline at end of file diff --git a/contracts/hooks/examples/FullRange.sol b/contracts/hooks/examples/FullRange.sol index 5137e1ed..84f823ca 100644 --- a/contracts/hooks/examples/FullRange.sol +++ b/contracts/hooks/examples/FullRange.sol @@ -34,6 +34,7 @@ contract FullRange is BaseHook, ILockCallback { /// @notice Thrown when trying to interact with a non-initialized pool error PoolNotInitialized(); + error TickSpacingNotDefault(); /// @dev Min tick for full range with tick spacing of 60 int24 internal constant MIN_TICK = -887220; @@ -154,7 +155,7 @@ contract FullRange is BaseHook, ILockCallback { } function beforeInitialize(address, PoolKey calldata key, uint160) external override returns (bytes4) { - require(key.tickSpacing == 60, "Tick spacing must be default"); + if (key.tickSpacing != 60) revert TickSpacingNotDefault(); PoolId poolId = key.toId(); diff --git a/contracts/libraries/UniswapV4ERC20.sol b/contracts/libraries/UniswapV4ERC20.sol index 63440830..fdd93ba4 100644 --- a/contracts/libraries/UniswapV4ERC20.sol +++ b/contracts/libraries/UniswapV4ERC20.sol @@ -1,17 +1,9 @@ pragma solidity ^0.8.19; -// import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; -// import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -// import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; - import {ERC20} from "solmate/tokens/ERC20.sol"; import {Owned} from "solmate/auth/Owned.sol"; contract UniswapV4ERC20 is ERC20, Owned { - // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); - - bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; - constructor(string memory name, string memory symbol) ERC20(name, symbol, 18) Owned(msg.sender) {} function mint(address account, uint256 amount) external onlyOwner { diff --git a/test/FullRange.t.sol b/test/FullRange.t.sol index eca0adee..da70cf1f 100644 --- a/test/FullRange.t.sol +++ b/test/FullRange.t.sol @@ -10,7 +10,6 @@ import {FullRangeImplementation} from "./shared/implementation/FullRangeImplemen import {PoolManager} from "@uniswap/v4-core/contracts/PoolManager.sol"; import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; import {Deployers} from "@uniswap/v4-core/test/foundry-tests/utils/Deployers.sol"; -// import {TestERC20} from "@uniswap/v4-core/contracts/test/TestERC20.sol"; import {MockERC20} from "@uniswap/v4-core/test/foundry-tests/utils/MockERC20.sol"; import {CurrencyLibrary, Currency} from "@uniswap/v4-core/contracts/types/Currency.sol"; import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol"; @@ -50,7 +49,6 @@ contract TestFullRange is Test, Deployers, GasSnapshot { ); int24 constant TICK_SPACING = 60; - uint160 constant SQRT_RATIO_2_1 = 112045541949572279837463876454; uint256 constant MAX_DEADLINE = 12329839823; /// @dev Min tick for full range with tick spacing of 60 @@ -130,7 +128,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot { PoolKey memory wrongKey = PoolKey(Currency.wrap(address(token0)), Currency.wrap(address(token1)), 0, TICK_SPACING + 1, fullRange); - vm.expectRevert("Tick spacing must be default"); + vm.expectRevert(FullRange.TickSpacingNotDefault.selector); manager.initialize(wrongKey, SQRT_RATIO_1_1); }