forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IHooks.sol
95 lines (86 loc) · 4.41 KB
/
IHooks.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
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
import {IPoolManager} from "./IPoolManager.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
/// @notice The PoolManager contract decides whether to invoke specific hooks by inspecting the leading bits
/// of the hooks contract address. For example, a 1 bit in the first bit of the address will
/// cause the 'before swap' hook to be invoked. See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
/// @notice The hook called before the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @return bytes4 The function selector for the hook
function beforeInitialize(address sender, IPoolManager.PoolKey calldata key, uint160 sqrtPriceX96)
external
returns (bytes4);
/// @notice The hook called after the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @param tick The current tick after the state of a pool is initialized
/// @return bytes4 The function selector for the hook
function afterInitialize(address sender, IPoolManager.PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
external
returns (bytes4);
/// @notice The hook called before a position is modified
/// @param sender The initial msg.sender for the modify position call
/// @param key The key for the pool
/// @param params The parameters for modifying the position
/// @return bytes4 The function selector for the hook
function beforeModifyPosition(
address sender,
IPoolManager.PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params
) external returns (bytes4);
/// @notice The hook called after a position is modified
/// @param sender The initial msg.sender for the modify position call
/// @param key The key for the pool
/// @param params The parameters for modifying the position
/// @return bytes4 The function selector for the hook
function afterModifyPosition(
address sender,
IPoolManager.PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
BalanceDelta delta
) external returns (bytes4);
/// @notice The hook called before a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @return bytes4 The function selector for the hook
function beforeSwap(address sender, IPoolManager.PoolKey calldata key, IPoolManager.SwapParams calldata params)
external
returns (bytes4);
/// @notice The hook called after a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @param delta The amount owed to the locker (positive) or owed to the pool (negative)
/// @return bytes4 The function selector for the hook
function afterSwap(
address sender,
IPoolManager.PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta delta
) external returns (bytes4);
/// @notice The hook called before donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @return bytes4 The function selector for the hook
function beforeDonate(address sender, IPoolManager.PoolKey calldata key, uint256 amount0, uint256 amount1)
external
returns (bytes4);
/// @notice The hook called after donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @return bytes4 The function selector for the hook
function afterDonate(address sender, IPoolManager.PoolKey calldata key, uint256 amount0, uint256 amount1)
external
returns (bytes4);
}