Catalog npm
Back to packageRELEASE DETAILS

1.1.0

npm

@0xheyjo/uni-v2-artifacts

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

Published22 Aug 2025
Direct dependencies24
Transitive dependenciesNot calculated

README

Current package documentation

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)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 24

Native requirements
24 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@uniswap/v2-core
Environment
{
  "local_name": "@uniswap/v2-core",
  "alias": false,
  "peer_metadata": null
}
^1.0.1runtime
@uniswap/v2-periphery
Environment
{
  "local_name": "@uniswap/v2-periphery",
  "alias": false,
  "peer_metadata": null
}
^1.1.0-beta.0runtime
@nomicfoundation/hardhat-chai-matchers
Environment
{
  "local_name": "@nomicfoundation/hardhat-chai-matchers",
  "alias": false,
  "peer_metadata": null
}
^2.1.0development
@nomicfoundation/hardhat-ethers
Environment
{
  "local_name": "@nomicfoundation/hardhat-ethers",
  "alias": false,
  "peer_metadata": null
}
^3.1.0development
@nomicfoundation/hardhat-ignition
Environment
{
  "local_name": "@nomicfoundation/hardhat-ignition",
  "alias": false,
  "peer_metadata": null
}
^0.15.13development
@nomicfoundation/hardhat-ignition-ethers
Environment
{
  "local_name": "@nomicfoundation/hardhat-ignition-ethers",
  "alias": false,
  "peer_metadata": null
}
^0.15.14development
@nomicfoundation/hardhat-network-helpers
Environment
{
  "local_name": "@nomicfoundation/hardhat-network-helpers",
  "alias": false,
  "peer_metadata": null
}
^1.1.0development
@nomicfoundation/hardhat-toolbox
Environment
{
  "local_name": "@nomicfoundation/hardhat-toolbox",
  "alias": false,
  "peer_metadata": null
}
^6.1.0development
@nomicfoundation/hardhat-verify
Environment
{
  "local_name": "@nomicfoundation/hardhat-verify",
  "alias": false,
  "peer_metadata": null
}
^2.1.1development
@typechain/ethers-v6
Environment
{
  "local_name": "@typechain/ethers-v6",
  "alias": false,
  "peer_metadata": null
}
^0.5.1development
@typechain/hardhat
Environment
{
  "local_name": "@typechain/hardhat",
  "alias": false,
  "peer_metadata": null
}
^9.1.0development
@types/chai
Environment
{
  "local_name": "@types/chai",
  "alias": false,
  "peer_metadata": null
}
^4.3.20development
@types/mocha
Environment
{
  "local_name": "@types/mocha",
  "alias": false,
  "peer_metadata": null
}
^10.0.10development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^24.3.0development
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.5.0development
ethers
Environment
{
  "local_name": "ethers",
  "alias": false,
  "peer_metadata": null
}
^6.15.0development
hardhat
Environment
{
  "local_name": "hardhat",
  "alias": false,
  "peer_metadata": null
}
^2.26.3development
hardhat-abi-exporter
Environment
{
  "local_name": "hardhat-abi-exporter",
  "alias": false,
  "peer_metadata": null
}
^2.11.0development
hardhat-gas-reporter
Environment
{
  "local_name": "hardhat-gas-reporter",
  "alias": false,
  "peer_metadata": null
}
^2.3.0development
patch-package
Environment
{
  "local_name": "patch-package",
  "alias": false,
  "peer_metadata": null
}
^8.0.0development
solidity-coverage
Environment
{
  "local_name": "solidity-coverage",
  "alias": false,
  "peer_metadata": null
}
^0.8.16development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^10.9.2development
typechain
Environment
{
  "local_name": "typechain",
  "alias": false,
  "peer_metadata": null
}
^8.3.2development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.9.2development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-U18Ty761LrGDSUR0gj+dbRz2sVmjQPMx9zhSXKZdXZLuYCZ7vuRVJ0eXEHyIBw7m6llMDbiONkNmfy83rVA/0w==",
  "shasum": "a595220ad26638696fdd6ec42f47148b74689ff1",
  "tarball": "https://registry.npmjs.org/@0xheyjo/uni-v2-artifacts/-/uni-v2-artifacts-1.1.0.tgz",
  "fileCount": 13,
  "unpackedSize": 99199,
  "signatures": [
    {
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
      "sig": "MEUCIQC3Asp1k6X7VsQENBM8DecO9XF7tjDKrruRgrg/YWz1XgIgVK+oB4QFtQ/BQ1eV/AOaEbrNvs76tOoaQOgs4xNGMak="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 08:55 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:9aade7b8748d117d45b467ee09abe02f7855f6430ab1ddbc0791bdea33093af0

Other collected versions

1.0.020 AugView all collected versions →