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

feat: hooks refactor POC #411

Closed
wants to merge 1 commit into from
Closed

feat: hooks refactor POC #411

wants to merge 1 commit into from

Conversation

marktoda
Copy link
Contributor

The per-hook block is increasing in size over time and now is roughly
8 lines of code duplicated 8 times after #404 and #324. This commit
attempts to refactor some of this copied logic into the Hooks library
to improve readability of the core PoolManager code while also
removing duplicated code

This is a proof of concept, I'll wait until the above PRs are merged to
include them in this model and can improve testing a lot with this new
approach as well

Related Issue

Which issue does this pull request resolve?

Description of changes

The per-hook block is increasing in size over time and now is roughly
8 lines of code duplicated 8 times after #404 and #324. This commit
  attempts to refactor some of this copied logic into the Hooks library
  to improve readability of the core PoolManager code while also
  removing duplicated code

This is a proof of concept, I'll wait until the above PRs are merged to
include them in this model and can improve testing a lot with this new
approach as well
@marktoda
Copy link
Contributor Author

oof gas quite a bit worse due to extra jumps, will think about how to improve that

function validateHooksResponse(bytes4 selector, bytes4 expectedSelector) internal pure {
if (selector != expectedSelector) {
revert InvalidHookResponse();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to add: noop handling here

Copy link
Member

Choose a reason for hiding this comment

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

this refactor will be strange with NoOp because we have to run the clear currentHook logic before returning

IPoolManager.ModifyPositionParams memory params,
bytes memory hookData
) internal {
if (!key.hooks.shouldCall(BEFORE_MODIFY_POSITION_FLAG)) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to add: CA handling

@marktoda marktoda mentioned this pull request Nov 20, 2023
@snreynolds
Copy link
Member

One comment.. if we can find a nice way to use a helper for the callsite calls, I think it would be neater to do the if (set) Lockers.clearCurrentHook() check INSIDE the hook checks so that we aren't setting a current hook in the no hook case.

@marktoda marktoda closed this Dec 8, 2023
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.

2 participants