Git Product home page Git Product logo

scaffold-hook's Introduction

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+

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:

scaffold-hook's People

Contributors

saucepoint avatar 0xaaiden avatar 0xsamgreen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.