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

use deployCodeTo cheatcode for testing hooks #122

Closed
wants to merge 3 commits into from
Closed

Conversation

saucepoint
Copy link
Collaborator

Related Issue

The mock & etch pattern for testing hooks is very verbose and adds repo clutter. Conversely, mining addresses for a 14-bit pattern has been reported to be slow by some users on older hardware.

We should replace mock & etch with the deployCodeTo cheatcode which is much more concise and easier to reference for hook developers

Description of changes

Replaced mock & etch with deployCodeTo cheatcode

@akshatmittal
Copy link

Consider doing something like this in order to avoid etching over precompiles:

uint160 flags = uint160(Hooks.AFTER_SWAP_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG | Hooks.BEFORE_INITIALIZE_FLAG) ^ (0x7634 << 144);
TargetHook hook = TargetHook(address(flags));
deployCodeTo("...", abi.encode(manager), address(hook));

This is what I usually do in tests, gives a separate namespace to hooks as well. (add another xor if you are testing multiple hooks at once)

(0x7634 is v4 in hex)

Copy link
Collaborator Author

@saucepoint saucepoint Jun 21, 2024

Choose a reason for hiding this comment

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

would prefer to see this in v4-core's Deployers (or periphery's equivalent) to remove one less import required for devs

@saucepoint
Copy link
Collaborator Author

closing because example hooks were removed from the main branch

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

Successfully merging this pull request may close these issues.

3 participants