-
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
NoOp implementation with flag #324
Changes from 22 commits
f8f4a2f
eb91bfe
33138c5
aa8d988
646034f
311d086
7599fd9
6e3c350
68a42b3
51c8afc
06659bb
e84f739
5251f35
98fefe8
ba21f75
63965f9
074fcec
feff1ad
9a2e0d2
f0c8226
6c35c7e
c9ce471
7273540
24eb878
2267508
90647a3
f70a8f5
3f0ebcb
bcfe08b
dd3e523
06c85b8
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 |
---|---|---|
@@ -1 +1 @@ | ||
189798 | ||
189980 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
145314 | ||
145476 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
134915 | ||
137124 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
186636 | ||
186845 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
53843 | ||
53941 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
319184 | ||
319291 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
198926 | ||
199013 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
202041 | ||
202128 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
52263 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
24805 | ||
25025 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
132772 | ||
132954 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
190722 | ||
190884 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
202425 | ||
202587 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
121318 | ||
121480 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
109143 | ||
109305 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
127882 | ||
128044 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
212594 | ||
212756 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
189038 | ||
189220 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
109122 | ||
109284 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
47418 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
44944 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
195628 | ||
195804 |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,16 +185,20 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { | |
IPoolManager.ModifyPositionParams memory params, | ||
bytes calldata hookData | ||
) external override noDelegateCall onlyByLocker returns (BalanceDelta delta) { | ||
PoolId id = key.toId(); | ||
if (pools[id].isNotInitialized()) revert PoolNotInitialized(); | ||
|
||
if (key.hooks.shouldCallBeforeModifyPosition()) { | ||
if ( | ||
key.hooks.beforeModifyPosition(msg.sender, key, params, hookData) | ||
!= IHooks.beforeModifyPosition.selector | ||
) { | ||
revert Hooks.InvalidHookResponse(); | ||
bytes4 selector = key.hooks.beforeModifyPosition(msg.sender, key, params, hookData); | ||
hensha256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (selector != IHooks.beforeModifyPosition.selector) { | ||
if (key.hooks.isValidNoOpCall(selector)) { | ||
hensha256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return BalanceDelta.wrap(0); | ||
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. Maybe some return indication here to tell the caller that custom accounting was used? 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. Hmm interesting.. I like that idea. That would definitely make writing tests (or any integrating contract) a little easier so I'm in favor. 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. Changed it to return the maximum uint256... it feels unlikely that a legit trade would ever return that? |
||
} else { | ||
revert Hooks.InvalidHookResponse(); | ||
} | ||
} | ||
} | ||
|
||
PoolId id = key.toId(); | ||
Pool.FeeAmounts memory feeAmounts; | ||
(delta, feeAmounts) = pools[id].modifyPosition( | ||
Pool.ModifyPositionParams({ | ||
|
@@ -243,14 +247,20 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { | |
onlyByLocker | ||
returns (BalanceDelta delta) | ||
{ | ||
PoolId id = key.toId(); | ||
if (pools[id].isNotInitialized()) revert PoolNotInitialized(); | ||
|
||
if (key.hooks.shouldCallBeforeSwap()) { | ||
if (key.hooks.beforeSwap(msg.sender, key, params, hookData) != IHooks.beforeSwap.selector) { | ||
revert Hooks.InvalidHookResponse(); | ||
bytes4 selector = key.hooks.beforeSwap(msg.sender, key, params, hookData); | ||
if (selector != IHooks.beforeSwap.selector) { | ||
if (key.hooks.isValidNoOpCall(selector)) { | ||
return BalanceDelta.wrap(0); | ||
} else { | ||
revert Hooks.InvalidHookResponse(); | ||
} | ||
} | ||
} | ||
|
||
PoolId id = key.toId(); | ||
|
||
uint256 feeForProtocol; | ||
uint256 feeForHook; | ||
uint24 swapFee; | ||
|
@@ -295,13 +305,21 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { | |
onlyByLocker | ||
returns (BalanceDelta delta) | ||
{ | ||
PoolId id = key.toId(); | ||
if (pools[id].isNotInitialized()) revert PoolNotInitialized(); | ||
|
||
if (key.hooks.shouldCallBeforeDonate()) { | ||
if (key.hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData) != IHooks.beforeDonate.selector) { | ||
revert Hooks.InvalidHookResponse(); | ||
bytes4 selector = key.hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData); | ||
if (selector != IHooks.beforeDonate.selector) { | ||
if (key.hooks.isValidNoOpCall(selector)) { | ||
return BalanceDelta.wrap(0); | ||
} else { | ||
revert Hooks.InvalidHookResponse(); | ||
} | ||
} | ||
} | ||
|
||
delta = _getPool(key).donate(amount0, amount1); | ||
hensha256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delta = pools[id].donate(amount0, amount1); | ||
|
||
_accountPoolBalanceDelta(key, delta); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.19; | ||
|
||
import {BaseTestHooks} from "./BaseTestHooks.sol"; | ||
import {Hooks} from "../libraries/Hooks.sol"; | ||
import {IPoolManager} from "../interfaces/IPoolManager.sol"; | ||
import {PoolKey} from "../types/PoolKey.sol"; | ||
import {BalanceDelta} from "../types/BalanceDelta.sol"; | ||
|
||
contract NoOpTestHooks is BaseTestHooks { | ||
constructor() { | ||
Hooks.validateHookAddress( | ||
this, | ||
Hooks.Calls({ | ||
beforeInitialize: false, | ||
afterInitialize: false, | ||
beforeModifyPosition: true, | ||
afterModifyPosition: false, | ||
beforeSwap: true, | ||
afterSwap: false, | ||
beforeDonate: true, | ||
afterDonate: false, | ||
noOp: true | ||
}) | ||
); | ||
} | ||
|
||
function beforeModifyPosition(address, PoolKey calldata, IPoolManager.ModifyPositionParams calldata, bytes calldata) | ||
external | ||
pure | ||
override | ||
returns (bytes4) | ||
{ | ||
return Hooks.NO_OP_SELECTOR; | ||
} | ||
|
||
function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata) | ||
external | ||
pure | ||
override | ||
returns (bytes4) | ||
{ | ||
return Hooks.NO_OP_SELECTOR; | ||
} | ||
|
||
function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) | ||
external | ||
pure | ||
override | ||
returns (bytes4) | ||
{ | ||
return Hooks.NO_OP_SELECTOR; | ||
} | ||
} |
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.
Why move this to the top level? Seems cleaner to have it in
Pool.sol
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.
Because if its in the pool, then its after the hook call. So that means on an uninitialized pool, a
swap
transaction succeeds with a hook that NoOps (even though the pool doesnt exist). So I've moved it top level so that we can maintain the invariant that actions on an uninitialized pool always revertThere 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.
maybe new modifier
onlyInitializedPool(key)
? that duplicates id hashing in code but id guess it gets compiled out, could check?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.
modifier or helper func sgtm :)
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.
Modifier put gas up by 1000 for swaps because of repeated hashing. I've put in a helper function instead