Skip to content

A template for writing Uniswap v4 Hooks with custom swap curve implemantion in Stylus.

License

Notifications You must be signed in to change notification settings

OpenZeppelin/uniswap-solidity-hooks-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uniswap Solidity Hooks Template

Warning

This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production.

A template for writing Uniswap v4 Hooks with custom swap curve implemantion in Stylus

This template is built on top of Uniswap V4 Template.

Use this Template

  1. The example hook Counter.sol demonstrates:
    • beforeSwap() hook calling external custom curve implementation written in Stylus,
    • afterSwap() hook,
    • beforeAddLiquidity() hook,
    • beforeRemoveLiquidity() hook,
    • getHookPermissions() function.
  2. The test template Counter.t.sol preconfigures the v4 pool manager, test tokens, and test liquidity.

Check Forge Installation

Ensure that you have correctly installed Foundry (Forge) and that it's up to date. You can update Foundry by running:

foundryup

Set up

requires foundry

forge install
forge test

Local Development (Nitro Testnode)

Other than writing unit tests, you can deploy & test hooks on Nitro Testnode.

You can follow this instruction to run Nitro Testnode.


Troubleshooting

Permission Denied

When installing dependencies with forge install, Github may throw a Permission Denied error

Typically caused by missing Github SSH keys, and can be resolved by following the steps here

Or adding the keys to your ssh-agent, if you have already uploaded SSH keys

Hook deployment failures

Hook deployment failures are caused by incorrect flags or incorrect salt mining

  1. Verify the flags are in agreement:
    • getHookCalls() returns the correct flags
    • flags provided to HookMiner.find(...)
  2. Verify salt mining is correct:
    • In forge test: the deployer for: new Hook{salt: salt}(...) and HookMiner.find(deployer, ...) are the same. This will be address(this). If using vm.prank, the deployer will be the pranking address
    • In forge script: the deployer must be the CREATE2 Proxy: 0x4e59b44847b379578588920cA78FbF26c0B4956C
      • If anvil does not have the CREATE2 deployer, your foundry may be out of date. You can update it with foundryup

Additional resources:

Uniswap v4 docs

v4-periphery contains advanced hook implementations that serve as a great reference

v4-core

v4-by-example

About

A template for writing Uniswap v4 Hooks with custom swap curve implemantion in Stylus.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published