generated from uniswapfoundation/v4-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.sol
84 lines (71 loc) · 2.92 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {BaseHook} from "v4-periphery/BaseHook.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.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 beforeModifyPositionCount;
mapping(PoolId => uint256 count) public afterModifyPositionCount;
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}
function getHooksCalls() public pure override returns (Hooks.Calls memory) {
return Hooks.Calls({
beforeInitialize: false,
afterInitialize: false,
beforeModifyPosition: true,
afterModifyPosition: true,
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false
});
}
// -----------------------------------------------
// NOTE: see IHooks.sol for function documentation
// -----------------------------------------------
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata)
external
override
returns (bytes4)
{
beforeSwapCount[key.toId()]++;
return BaseHook.beforeSwap.selector;
}
function afterSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata)
external
override
returns (bytes4)
{
afterSwapCount[key.toId()]++;
return BaseHook.afterSwap.selector;
}
function beforeModifyPosition(
address,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata,
bytes calldata
) external override returns (bytes4) {
beforeModifyPositionCount[key.toId()]++;
return BaseHook.beforeModifyPosition.selector;
}
function afterModifyPosition(
address,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata,
BalanceDelta,
bytes calldata
) external override returns (bytes4) {
afterModifyPositionCount[key.toId()]++;
return BaseHook.afterModifyPosition.selector;
}
}