generated from uniswapfoundation/v4-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.sol
49 lines (41 loc) · 1.5 KB
/
Counter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {BaseHook} from "v4-periphery/BaseHook.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {PoolId} from "@uniswap/v4-core/contracts/libraries/PoolId.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
contract Counter is BaseHook {
using PoolId for IPoolManager.PoolKey;
uint256 public beforeSwapCount;
uint256 public afterSwapCount;
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}
function getHooksCalls() public pure override returns (Hooks.Calls memory) {
return Hooks.Calls({
beforeInitialize: false,
afterInitialize: false,
beforeModifyPosition: false,
afterModifyPosition: false,
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false
});
}
function beforeSwap(address, IPoolManager.PoolKey calldata, IPoolManager.SwapParams calldata)
external
override
returns (bytes4)
{
beforeSwapCount++;
return BaseHook.beforeSwap.selector;
}
function afterSwap(address, IPoolManager.PoolKey calldata, IPoolManager.SwapParams calldata, BalanceDelta)
external
override
returns (bytes4)
{
afterSwapCount++;
return BaseHook.afterSwap.selector;
}
}