Skip to content

Uniswap v4 Hook development stack, complete with testnet deployment and UI

License

Notifications You must be signed in to change notification settings

uniswapfoundation/scaffold-hook

Repository files navigation

scaffold-hook

Develop and test Uniswap v4 Hooks with minimal interfaces for the swap lifecycle (pool creation, liquidity provision, and swapping)

inspired by scaffold-eth

Features

✅ Template hook with deployment commands

✅ User interfaces for: pool creation, liquidity creation, and swapping

✅ Local network (anvil) with predeployed Uniswap v4

✅ Testnet support

✅ Foundry (hardhat support coming later)


Setup

requires foundry & node 18+

Linux / WSL2 (TSTORE)

Please update foundry.toml to use the linux solc

Mac users do not need to change anything by default

Install Dependencies

forge install

cd nextjs/
npm install

Define environment variables

cp .env.example .env

See Environment additional setup


Get Started

  1. Start the local network, with v4 contracts predeployed

    # root of the repository
    cd scaffold-hook/
    npm run anvil
  2. Deploy the template hook

    # root of the repository
    cd scaffold-hook/
    forge build
    npm run deploy:anvil
  3. Update wagmi.config.ts with the hook address from run-latest.json

  4. Regenerate react hooks, addresses, and ABIs

    cd nextjs/
    npm run wagmi
  5. Start the webapp

    cd nextjs/
    npm run dev

Hook Configuration

Modifying the file name, contract name, or hook flags will require configuration:

Renaming -- update .env

# Hook Contract, formatted: <filename.sol>:<contractName>
HOOK_CONTRACT="Counter.sol:Counter"

Changing hook flags -- update .env and ensure getHookCalls() is in agreement

# in .env
# Hook Flags
BEFORE_SWAP=true
AFTER_SWAP=true
BEFORE_MODIFY_POSITION=true
AFTER_MODIFY_POSITION=true
BEFORE_INITIALIZE=false
AFTER_INITIALIZE=false
BEFORE_DONATE=false
AFTER_DONATE=false
// in Hook Contract
function getHooksCalls() public pure returns (Hooks.Calls memory) {
    return Hooks.Calls({
        beforeInitialize: false,
        afterInitialize: false,
        beforeModifyPosition: true,
        afterModifyPosition: true,
        beforeSwap: true,
        afterSwap: true,
        beforeDonate: false,
        afterDonate: false
    });
}

Deploying to Testnets

Ensure your wallet is funded with testnet gas (ETH)

  • npm run deploy:anvil

  • npm run deploy:goerli

  • npm run deploy:arbitrum-goerli

  • npm run deploy:arbitrum-sepolia

  • npm run deploy:optimism-goerli

  • npm run deploy:base-goerli

  • npm run deploy:sepolia

  • npm run deploy:scroll-sepolia

  • npm run deploy:polygon-mumbai

  • npm run deploy:polygon-zkevm-testnet

Additional Configuration

Custom Tokens

While scaffold-hook ships solmate's MockERC20 on local and testnet, you can provide your own custom tokens:

  1. define them in wagmi.config.ts, and regenerate the codegen: npm run wagmi
  2. import the generated addresses and edit TOKEN_ADDRESSES

Debuggable Hook (etherscan-style contract interface)

  1. define the hook in wagmi.config.ts, and regenerate the codegen: npm run wagmi
  2. import the generated types and edit DEBUGGABLE_ADDRESSES

Environment Variables

  • ANVIL_FORK_URL: RPC URL for anvil fork mode
  • ETHERSCAN_API_KEY: Your Etherscan API Key
  • FORGE_PRIVATE_KEY: The private key of the wallet for testnet deployments

Learn more

To learn more about Next.js, Foundry or wagmi, check out the following resources:

About

Uniswap v4 Hook development stack, complete with testnet deployment and UI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •