npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@0xheyjo/uni-v2-artifacts

v1.1.0

Published

## [Uniswap v2 deep dive](./Uniswap.md)

Readme

Uniswap V2 playground

Uniswap v2 deep dive

This project deploys Uniswap V2 locally. I am running foundry anvil but hardhat local node can be used too.

Compiler version and hardhat settings

  • UniV2, Univ2periphery and my Token contracts has different compiler version
  • So hardhat.config.ts has settings for different versions
  • Also in order to import Uni contracts, I create two sol files ImportCore.sol and ImportPeriphery.sol
  • These imports have to be in different files as the compiler version is different for both

v2-core contracts

  1. UniswapV2Pair.sol (Main contract which has pairs, swap, update(TWAP) etc)
  2. UniswapV2Factory.sol (Main contract which creates pairs, and setsFee) 3.UniswapV2Router02 (All najor operations are orchestrated from here, addLiquidity,removeLiquidity, swapforTokens,getAmountIn getAmountOut etc)
  3. UniswapV2Library.sol (getPairs(), hardcoded initcode as seen above, sortTokens() for deterministic ordering, getReserves etc )
  4. UniswapV2ERC20.sol (ERC 20 for LP tokens, have Permit functionality)
  5. UniswapV2OracleLibrary (Helpers for TWAP calculation)
  6. UniswapV2Migrator (Migaret from v1 to v2)

A note on pairFor() method issues

  • In the UniswapV2Library.sol, initcode hash is hardcoded is the pairFor method 0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f
  • This is the hex of the constructor code for UniswapV2Pair.sol
  • My compiler could not produce the same hex as was hardcoded in Uniswap code. Not sure why. So I has to change the initcode to what my compiler was generating
  • with this you will get the pair corectly
    // calculates the CREATE2 address for a pair without making any external calls
    // Create 2 formula address = keccak256(0xff + deployer + salt + bytecodeHash)[12:]
    function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(uint(keccak256(abi.encodePacked(
                hex'ff', // CREATE2 prefix
                factory, // Factory contract address
                keccak256(abi.encodePacked(token0, token1)), // Salt
                hex'e699c2c70a1e9ca16c58b40782745b5d609738b755845b6ee18a18d21352f753' // init code hash
            ))));
    }

where hex'e699c2c70a1e9ca16c58b40782745b5d609738b755845b6ee18a18d21352f753' is the bytecode of UniswapV2Pair.sol (the constructor part). This might be different if you do this in future or with different compiler settings.

  • As I made changes in my Node Modules to make this work. These changes would not persist for someone who takes my code and does npm install, so I will persist these changes using patch-package
npm i -D patch-package
npx patch-package @uniswap/v2-periphery

Compiling the contracts which also generates typings

## clean artifacts, not needed everytime
rm -rf cache artifacts typechain typechain-types
## clean and compile, needed only if you added new contracts, probablu can just compile without cleaning
npx hardhat clean && npx hardhat compile    

Running tests

npx hardhat test ./test/AMM-v2.test.ts --network anvil  

You can report gas in test if you want

REPORT_GAS=true npx hardhat test ./test/AMM-v2.test.ts --network anvil  

If you want to use local hardhat node instead of anvil, if not SKIP npx hardhat node

Deploy to network of choice, i deploy to anvil

npx hardhat ignition deploy ignition/modules/UniV2.ts --network anvil

Publish the contracts to npm for consumption by UI

npm run build:artifacts npm pack # sanity check tarball contents npm publish --access public --ignore-scripts

To Update version npm version patch (minor/major)