Skip to content
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

Move BaseHook to new utils directory #438

Merged
merged 7 commits into from
Feb 6, 2025
Merged

Move BaseHook to new utils directory #438

merged 7 commits into from
Feb 6, 2025

Conversation

gretzke
Copy link
Contributor

@gretzke gretzke commented Feb 3, 2025

Related Issue

Which issue does this pull request resolve?

Description of changes

saucepoint
saucepoint previously approved these changes Feb 3, 2025
Copy link
Collaborator

@saucepoint saucepoint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in favor of the change,

BUT in this tidy-up PR, it makes sense to change BaseHook to inherit ImmutableState instead

#436 (comment)

@gretzke
Copy link
Contributor Author

gretzke commented Feb 3, 2025

Only SafeCallback relied on the pool manager variable / modifier, we can remove ImmutableState entirely

@saucepoint
Copy link
Collaborator

saucepoint commented Feb 3, 2025

@gretzke we should decorate the hook functions with a onlyPoolManager modifier, so we should inherit ImmutableState i think

as much as I hate repeating code, the modifier lives in SafeCallback which we shouldnt change; so we'll need to redefine the modifier in BaseHook?

@gretzke
Copy link
Contributor Author

gretzke commented Feb 3, 2025

If someone overrides the hook function they also override the function modifier, because the functions are reverting anyways right now we could not have it there. If we want to ensure the modifier is not overwritten accidentally, we should split the functions into two:

-function beforeInitialize(address, PoolKey calldata, uint160) external virtual returns (bytes4) {
-    revert HookNotImplemented();
-}

+function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4) {
+    return _beforeInitialize(sender, key, sqrtPriceX96);
+}
+
+function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) internal virtual returns (bytes4)
+    revert HookNotImplemented();
+}

This ensures that the external function cannot be overwritten and is always protected

@gretzke
Copy link
Contributor Author

gretzke commented Feb 3, 2025

do we still need the selfOnly and onlyValidPools modifiers?

@hensha256
Copy link
Contributor

I'm pro moving the modifier to ImmutableState... 👀 @saucepoint interested in your reason that we cant? just because of code freeze?

And yeah I think I'm pro adding the modifier and then adding internal functions to baseHook.sol. We follow that same pattern in SafeCallback too.

@saucepoint
Copy link
Collaborator

just because of code freeze?

yeah, if were not careful -- we might end up deploying a version of posm with different bytecode than whats currently in the wild

@gretzke
Copy link
Contributor Author

gretzke commented Feb 3, 2025

bytecode for positionmanager did not change after my implementation, feel free to double check

src/utils/BaseHook.sol Outdated Show resolved Hide resolved
src/utils/BaseHook.sol Outdated Show resolved Hide resolved
@@ -10,6 +10,15 @@ contract ImmutableState is IImmutableState {
/// @inheritdoc IImmutableState
IPoolManager public immutable poolManager;

/// @notice Thrown when calling unlockCallback where the caller is not PoolManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not only thrown when calling unlockCallBack since its also being called elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a change here, in the future, could you suggest a change instead? e.g.,

Suggested change
/// @notice Thrown when calling unlockCallback where the caller is not PoolManager
/// @notice Thrown when the caller is not PoolManager

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah forgot again! my bad!

@hensha256 hensha256 merged commit fc37d17 into main Feb 6, 2025
3 checks passed
@hensha256 hensha256 deleted the move-base-hook branch February 6, 2025 18:20
@arora-anmol
Copy link

@hensha256 @dianakocsis @gretzke with this change, might need to update the V4 hook docs here -- https://docs.uniswap.org/contracts/v4/guides/hooks/your-first-hook as it uses base/hooks/BaseHook for import.

Also if you guys could tag the commit that works with v4-core@v4.0.0, that could help keep track of dependencies

@Hugoo
Copy link

Hugoo commented Feb 19, 2025

Note, the README.md was not updated to reflect the directory change, here is a fix: #450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants