-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Before after add/remove liquidity, remove all modifyPosition hooks #434
Changes from 29 commits
8bf9f1b
5babed0
bb11369
de292c1
c6a223c
38a1e5d
c7e4a72
b24c159
90af549
97779f5
b0fea97
25314e3
3f4467d
1a75990
33e602d
21514b4
518737a
3fd4079
cee4d82
0d37920
17b439a
689fab4
399f250
6c497bc
832e6b1
435c914
389789c
8c5e457
1260a27
43d5aea
e408681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
323249 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
200141 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
200109 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
194519 | ||
194300 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
146864 | ||
146667 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
137968 | ||
137771 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
185390 | ||
185216 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
26968 | ||
27033 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
15246 | ||
15224 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
74268 | ||
74200 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
255158 | ||
255129 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
58201 | ||
58013 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
38634 | ||
38699 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
23592 | ||
23823 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
106962 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
208322 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
204612 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
195835 | ||
195638 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
204403 | ||
204206 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
175669 | ||
175475 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
172331 | ||
172131 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
126463 | ||
126266 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
113954 | ||
113757 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
133127 | ||
132930 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
169598 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
216596 | ||
216399 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
193620 | ||
193401 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
113932 | ||
113735 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
51546 | ||
51304 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
200363 | ||
200144 |
+0 −21 | LICENSE | |
+1 −7 | README.md | |
+2 −5 | src/utils/UintString.sol |
+1 −1 | package.json | |
+3 −11 | src/StdChains.sol | |
+2 −2 | src/StdCheats.sol | |
+33 −61 | src/StdUtils.sol | |
+0 −84 | src/Vm.sol | |
+0 −216 | src/mocks/MockERC20.sol | |
+0 −221 | src/mocks/MockERC721.sol | |
+6 −2 | test/StdChains.t.sol | |
+2 −2 | test/Vm.t.sol | |
+0 −441 | test/mocks/MockERC20.t.sol | |
+0 −721 | test/mocks/MockERC721.t.sol |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,29 +11,33 @@ import {Lockers} from "./Lockers.sol"; | |
/// @notice V4 decides whether to invoke specific hooks by inspecting the leading bits of the address that | ||
/// the hooks contract is deployed to. | ||
/// For example, a hooks contract deployed to address: 0x9000000000000000000000000000000000000000 | ||
/// has leading bits '1001' which would cause the 'before initialize' and 'after modify position' hooks to be used. | ||
/// has leading bits '1001' which would cause the 'before initialize' and 'after add liquidity' hooks to be used. | ||
library Hooks { | ||
using FeeLibrary for uint24; | ||
using Hooks for IHooks; | ||
|
||
uint256 internal constant BEFORE_INITIALIZE_FLAG = 1 << 159; | ||
uint256 internal constant AFTER_INITIALIZE_FLAG = 1 << 158; | ||
uint256 internal constant BEFORE_MODIFY_POSITION_FLAG = 1 << 157; | ||
uint256 internal constant AFTER_MODIFY_POSITION_FLAG = 1 << 156; | ||
uint256 internal constant BEFORE_SWAP_FLAG = 1 << 155; | ||
uint256 internal constant AFTER_SWAP_FLAG = 1 << 154; | ||
uint256 internal constant BEFORE_DONATE_FLAG = 1 << 153; | ||
uint256 internal constant AFTER_DONATE_FLAG = 1 << 152; | ||
uint256 internal constant NO_OP_FLAG = 1 << 151; | ||
uint256 internal constant ACCESS_LOCK_FLAG = 1 << 150; | ||
uint256 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 157; | ||
uint256 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 156; | ||
uint256 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 155; | ||
uint256 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 154; | ||
uint256 internal constant BEFORE_SWAP_FLAG = 1 << 153; | ||
uint256 internal constant AFTER_SWAP_FLAG = 1 << 152; | ||
uint256 internal constant BEFORE_DONATE_FLAG = 1 << 151; | ||
uint256 internal constant AFTER_DONATE_FLAG = 1 << 150; | ||
uint256 internal constant NO_OP_FLAG = 1 << 149; | ||
uint256 internal constant ACCESS_LOCK_FLAG = 1 << 148; | ||
|
||
bytes4 public constant NO_OP_SELECTOR = bytes4(keccak256(abi.encodePacked("NoOp"))); | ||
|
||
struct Permissions { | ||
bool beforeInitialize; | ||
bool afterInitialize; | ||
bool beforeModifyPosition; | ||
bool afterModifyPosition; | ||
bool beforeAddLiquidity; | ||
bool afterAddLiquidity; | ||
bool beforeRemoveLiquidity; | ||
bool afterRemoveLiquidity; | ||
bool beforeSwap; | ||
bool afterSwap; | ||
bool beforeDonate; | ||
|
@@ -60,8 +64,10 @@ library Hooks { | |
if ( | ||
permissions.beforeInitialize != self.hasPermission(BEFORE_INITIALIZE_FLAG) | ||
|| permissions.afterInitialize != self.hasPermission(AFTER_INITIALIZE_FLAG) | ||
|| permissions.beforeModifyPosition != self.hasPermission(BEFORE_MODIFY_POSITION_FLAG) | ||
|| permissions.afterModifyPosition != self.hasPermission(AFTER_MODIFY_POSITION_FLAG) | ||
|| permissions.beforeAddLiquidity != self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG) | ||
|| permissions.afterAddLiquidity != self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG) | ||
|| permissions.beforeRemoveLiquidity != self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG) | ||
|| permissions.afterRemoveLiquidity != self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG) | ||
|| permissions.beforeSwap != self.hasPermission(BEFORE_SWAP_FLAG) | ||
|| permissions.afterSwap != self.hasPermission(AFTER_SWAP_FLAG) | ||
|| permissions.beforeDonate != self.hasPermission(BEFORE_DONATE_FLAG) | ||
|
@@ -76,10 +82,11 @@ library Hooks { | |
/// @notice Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address | ||
/// @param hook The hook to verify | ||
function isValidHookAddress(IHooks hook, uint24 fee) internal pure returns (bool) { | ||
// if NoOp is allowed, at least one of beforeModifyPosition, beforeSwap and beforeDonate should be allowed | ||
// if NoOp is allowed, at least one of beforeRemoveLiquidity, beforeAddLiquidity, beforeSwap and beforeDonate should be allowed | ||
if ( | ||
hook.hasPermission(NO_OP_FLAG) && !hook.hasPermission(BEFORE_MODIFY_POSITION_FLAG) | ||
&& !hook.hasPermission(BEFORE_SWAP_FLAG) && !hook.hasPermission(BEFORE_DONATE_FLAG) | ||
hook.hasPermission(NO_OP_FLAG) && !hook.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG) | ||
&& !hook.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG) && !hook.hasPermission(BEFORE_SWAP_FLAG) | ||
&& !hook.hasPermission(BEFORE_DONATE_FLAG) | ||
) { | ||
return false; | ||
} | ||
|
@@ -161,12 +168,16 @@ library Hooks { | |
IPoolManager.ModifyPositionParams memory params, | ||
bytes calldata hookData | ||
) internal returns (bool shouldExecute) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and same name change on these functions? Just thinking so that they are all standardized beforeModifyPosition -> beforeModifyLiquidity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed 👍 |
||
if (self.hasPermission(BEFORE_MODIFY_POSITION_FLAG)) { | ||
if (params.liquidityDelta > 0 && key.hooks.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)) { | ||
shouldExecute = self.callHookNoopable( | ||
abi.encodeWithSelector(IHooks.beforeModifyPosition.selector, msg.sender, key, params, hookData) | ||
abi.encodeWithSelector(IHooks.beforeAddLiquidity.selector, msg.sender, key, params, hookData) | ||
); | ||
} else if (params.liquidityDelta <= 0 && key.hooks.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)) { | ||
shouldExecute = self.callHookNoopable( | ||
abi.encodeWithSelector(IHooks.beforeRemoveLiquidity.selector, msg.sender, key, params, hookData) | ||
); | ||
} else { | ||
return true; | ||
shouldExecute = true; | ||
} | ||
} | ||
|
||
|
@@ -178,9 +189,13 @@ library Hooks { | |
BalanceDelta delta, | ||
bytes calldata hookData | ||
) internal { | ||
if (key.hooks.hasPermission(AFTER_MODIFY_POSITION_FLAG)) { | ||
if (params.liquidityDelta > 0 && key.hooks.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)) { | ||
self.callHook( | ||
abi.encodeWithSelector(IHooks.afterAddLiquidity.selector, msg.sender, key, params, delta, hookData) | ||
); | ||
} else if (params.liquidityDelta <= 0 && key.hooks.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)) { | ||
self.callHook( | ||
abi.encodeWithSelector(IHooks.afterModifyPosition.selector, msg.sender, key, params, delta, hookData) | ||
abi.encodeWithSelector(IHooks.afterRemoveLiquidity.selector, msg.sender, key, params, delta, hookData) | ||
); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laaaast lil nit: ModifyLiquidityParams ?