// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {BaseHook} from "../../src/utils/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 {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol"; import {ModifyLiquidityParams, SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol"; contract MockCounterHook is BaseHook { using PoolIdLibrary for PoolKey; 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 }); } function _beforeSwap(address, PoolKey calldata key, SwapParams calldata, bytes calldata) internal override returns (bytes4, BeforeSwapDelta, uint24) { beforeSwapCount[key.toId()]++; return (BaseHook.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); } function _afterSwap(address, PoolKey calldata key, SwapParams calldata, BalanceDelta, bytes calldata) internal override returns (bytes4, int128) { afterSwapCount[key.toId()]++; return (BaseHook.afterSwap.selector, 0); } function _beforeAddLiquidity(address, PoolKey calldata key, ModifyLiquidityParams calldata, bytes calldata) internal override returns (bytes4) { beforeAddLiquidityCount[key.toId()]++; return BaseHook.beforeAddLiquidity.selector; } function _beforeRemoveLiquidity(address, PoolKey calldata key, ModifyLiquidityParams calldata, bytes calldata) internal override returns (bytes4) { beforeRemoveLiquidityCount[key.toId()]++; return BaseHook.beforeRemoveLiquidity.selector; } }