From 532f60ce3ddf4f384a21a205cf6ea72b00cd445a Mon Sep 17 00:00:00 2001 From: Junion <69495294+Jun1on@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:14:55 -0400 Subject: [PATCH] move files --- contracts/middleware/BaseMiddleware.sol | 6 +- lib/openzeppelin-contracts | 2 +- test/BaseMiddleware.t.sol | 2 +- test/MiddlewareRemove.t.sol | 6 +- test/MiddlewareRemoveFactory.t.sol | 8 +- test/middleware/CouterPayable.sol | 88 +++++++++++++++++++ .../middleware}/FeeTakingLite.sol | 2 +- .../middleware}/HooksOutOfGas.sol | 2 +- .../test => test/middleware}/HooksRevert.sol | 2 +- .../FeeTakingLiteImplementation.sol | 2 +- 10 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 test/middleware/CouterPayable.sol rename {contracts/middleware/test => test/middleware}/FeeTakingLite.sol (98%) rename {contracts/middleware/test => test/middleware}/HooksOutOfGas.sol (98%) rename {contracts/middleware/test => test/middleware}/HooksRevert.sol (98%) diff --git a/contracts/middleware/BaseMiddleware.sol b/contracts/middleware/BaseMiddleware.sol index c9f6334d..ce7bbe68 100644 --- a/contracts/middleware/BaseMiddleware.sol +++ b/contracts/middleware/BaseMiddleware.sol @@ -25,7 +25,7 @@ contract BaseMiddleware is Proxy { return implementation; } - receive() external payable { - // ?? - } + // yo how do i remove this warning + // receive() external payable { + // } } diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts index 5ae63068..337bfd5e 160000 --- a/lib/openzeppelin-contracts +++ b/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 5ae630684a0f57de400ef69499addab4c32ac8fb +Subproject commit 337bfd5ea4df9f7ebc755cd3cb4ecb3bd3d33fc7 diff --git a/test/BaseMiddleware.t.sol b/test/BaseMiddleware.t.sol index 56093d31..e2c7bdf0 100644 --- a/test/BaseMiddleware.t.sol +++ b/test/BaseMiddleware.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {Test} from "forge-std/Test.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; -import {FeeTakingLite} from "../contracts/middleware/test/FeeTakingLite.sol"; +import {FeeTakingLite} from "./middleware/FeeTakingLite.sol"; import {BaseMiddleware} from "../contracts/middleware/BaseMiddleware.sol"; import {BaseMiddlewareImplementation} from "./shared/implementation/BaseMiddlewareImplementation.sol"; import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; diff --git a/test/MiddlewareRemove.t.sol b/test/MiddlewareRemove.t.sol index fb198463..6bafa59b 100644 --- a/test/MiddlewareRemove.t.sol +++ b/test/MiddlewareRemove.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {Test} from "forge-std/Test.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; -import {FeeTakingLite} from "../contracts/middleware/test/FeeTakingLite.sol"; +import {FeeTakingLite} from "./middleware/FeeTakingLite.sol"; import {MiddlewareRemove} from "../contracts/middleware/MiddlewareRemove.sol"; import {MiddlewareRemoveImplementation} from "./shared/implementation/MiddlewareRemoveImplementation.sol"; import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; @@ -18,8 +18,8 @@ import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; import {console} from "../../../lib/forge-std/src/console.sol"; -import {HooksRevert} from "../contracts/middleware/test/HooksRevert.sol"; -import {HooksOutOfGas} from "../contracts/middleware/test/HooksOutOfGas.sol"; +import {HooksRevert} from "./middleware/HooksRevert.sol"; +import {HooksOutOfGas} from "./middleware/HooksOutOfGas.sol"; contract MiddlewareRemoveTest is Test, Deployers { using PoolIdLibrary for PoolKey; diff --git a/test/MiddlewareRemoveFactory.t.sol b/test/MiddlewareRemoveFactory.t.sol index 3e4a5ce8..d769e077 100644 --- a/test/MiddlewareRemoveFactory.t.sol +++ b/test/MiddlewareRemoveFactory.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {Test} from "forge-std/Test.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; -import {FeeTakingLite} from "../contracts/middleware/test/FeeTakingLite.sol"; +import {FeeTakingLite} from "./middleware/FeeTakingLite.sol"; import {MiddlewareRemove} from "../contracts/middleware/MiddlewareRemove.sol"; import {MiddlewareRemoveImplementation} from "./shared/implementation/MiddlewareRemoveImplementation.sol"; import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; @@ -18,8 +18,8 @@ import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; import {console} from "../../../lib/forge-std/src/console.sol"; -import {HooksRevert} from "../contracts/middleware/test/HooksRevert.sol"; -import {HooksOutOfGas} from "../contracts/middleware/test/HooksOutOfGas.sol"; +import {HooksRevert} from "./middleware/HooksRevert.sol"; +import {HooksOutOfGas} from "./middleware/HooksOutOfGas.sol"; import {MiddlewareRemoveFactory} from "./../contracts/middleware/MiddlewareRemoveFactory.sol"; import {HookMiner} from "./utils/HookMiner.sol"; @@ -64,6 +64,7 @@ contract MiddlewareRemoveFactoryTest is Test, Deployers { abi.encode(address(manager), address(feeTakingLite)) ); testOn(address(feeTakingLite), salt); + HooksRevert hooksRevert = new HooksRevert(manager); flags = uint160(Hooks.BEFORE_REMOVE_LIQUIDITY_FLAG | Hooks.AFTER_REMOVE_LIQUIDITY_FLAG); (hookAddress, salt) = HookMiner.find( @@ -73,6 +74,7 @@ contract MiddlewareRemoveFactoryTest is Test, Deployers { abi.encode(address(manager), address(hooksRevert)) ); testOn(address(hooksRevert), salt); + HooksOutOfGas hooksOutOfGas = new HooksOutOfGas(manager); flags = uint160(Hooks.BEFORE_REMOVE_LIQUIDITY_FLAG | Hooks.AFTER_REMOVE_LIQUIDITY_FLAG); (hookAddress, salt) = HookMiner.find( diff --git a/test/middleware/CouterPayable.sol b/test/middleware/CouterPayable.sol new file mode 100644 index 00000000..13bcc521 --- /dev/null +++ b/test/middleware/CouterPayable.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {BaseHook} from "./../../contracts/BaseHook.sol"; +import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; +import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol"; +import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol"; +import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; + +contract Counter is BaseHook { + using PoolIdLibrary for PoolKey; + + // NOTE: --------------------------------------------------------- + // state variables should typically be unique to a pool + // a single hook contract should be able to service multiple pools + // --------------------------------------------------------------- + + mapping(PoolId => uint256 count) public beforeSwapCount; + mapping(PoolId => uint256 count) public afterSwapCount; + + mapping(PoolId => uint256 count) public beforeAddLiquidityCount; + mapping(PoolId => uint256 count) public beforeRemoveLiquidityCount; + + constructor(IPoolManager _poolManager) BaseHook(_poolManager) {} + + function getHookPermissions() public pure override returns (Hooks.Permissions memory) { + return Hooks.Permissions({ + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: true, + afterAddLiquidity: false, + beforeRemoveLiquidity: true, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false + }); + } + + // ----------------------------------------------- + // NOTE: see IHooks.sol for function documentation + // ----------------------------------------------- + + function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata) + external + override + returns (bytes4, BeforeSwapDelta, uint24) + { + beforeSwapCount[key.toId()]++; + return (BaseHook.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); + } + + function afterSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) + external + override + returns (bytes4, int128) + { + afterSwapCount[key.toId()]++; + return (BaseHook.afterSwap.selector, 0); + } + + function beforeAddLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + bytes calldata + ) external override returns (bytes4) { + beforeAddLiquidityCount[key.toId()]++; + return BaseHook.beforeAddLiquidity.selector; + } + + function beforeRemoveLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + bytes calldata + ) external override returns (bytes4) { + beforeRemoveLiquidityCount[key.toId()]++; + return BaseHook.beforeRemoveLiquidity.selector; + } +} diff --git a/contracts/middleware/test/FeeTakingLite.sol b/test/middleware/FeeTakingLite.sol similarity index 98% rename from contracts/middleware/test/FeeTakingLite.sol rename to test/middleware/FeeTakingLite.sol index e4195ff2..3781ece6 100644 --- a/contracts/middleware/test/FeeTakingLite.sol +++ b/test/middleware/FeeTakingLite.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {BaseHook} from "../../BaseHook.sol"; +import {BaseHook} from "./../../contracts/BaseHook.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; diff --git a/contracts/middleware/test/HooksOutOfGas.sol b/test/middleware/HooksOutOfGas.sol similarity index 98% rename from contracts/middleware/test/HooksOutOfGas.sol rename to test/middleware/HooksOutOfGas.sol index db441bfe..d7b35a37 100644 --- a/contracts/middleware/test/HooksOutOfGas.sol +++ b/test/middleware/HooksOutOfGas.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {BaseHook} from "../../BaseHook.sol"; +import {BaseHook} from "./../../contracts/BaseHook.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; diff --git a/contracts/middleware/test/HooksRevert.sol b/test/middleware/HooksRevert.sol similarity index 98% rename from contracts/middleware/test/HooksRevert.sol rename to test/middleware/HooksRevert.sol index bb125d3a..f3f31401 100644 --- a/contracts/middleware/test/HooksRevert.sol +++ b/test/middleware/HooksRevert.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import {BaseHook} from "../../BaseHook.sol"; +import {BaseHook} from "./../../contracts/BaseHook.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; diff --git a/test/shared/implementation/FeeTakingLiteImplementation.sol b/test/shared/implementation/FeeTakingLiteImplementation.sol index 51d2cd0f..346b3099 100644 --- a/test/shared/implementation/FeeTakingLiteImplementation.sol +++ b/test/shared/implementation/FeeTakingLiteImplementation.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.19; import {BaseHook} from "../../../contracts/BaseHook.sol"; -import {FeeTakingLite} from "../../../contracts/middleware/test/FeeTakingLite.sol"; +import {FeeTakingLite} from "../../middleware/FeeTakingLite.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";