Skip to content

Uniswap V2 contracts, ready to be deployed to local or test network

Notifications You must be signed in to change notification settings

Jeiwan/uniswapv2-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uniswap V2 contracts, ready to be deployed to local or test network

Full copy of the original contracts with some minor changes:

  1. All contracts were updated to version 0.8.13, with minor changes.
  2. Example contracts were not copied over due to a missing contract they require. PR is welcomed!

Usage

  1. $ yarn
    $ alias hh="yarn hardhat"
    $ hh node
  2. In another terminal window:
    $ hh run scripts/deploy.js
    $ hh console
  3. Use this to load contract ABI and attach to a deployed contract:
    const Router = await ethers.getContractFactory("UniswapV2Router02");
    const router = Router.attach(ROUTER_ADDRESS);
    await router.swapExactTokensForTokens(...);

Refer to this if you need help interacting with contracts.

🚨 ATTENTION 🚨

Each time you update UniswapV2Pair.sol contract, you need to update the hex value in this line:

hex'c779f884b0d3b96c99d18260ba7f1b2c9a66dcddcacbcdf30f304d308cd4976e' // init code hash

Use this command to get a new value:

$ cat artifacts/contracts/UniswapV2Pair.sol/UniswapV2Pair.json| jq -r .bytecode| xargs cast keccak| cut -c 3-

(Ensure you have jq and cast installed)

Why? Uniswap V2 uses CREATE2 opcode to deploy pair contracts. This opcode allows to generate contract addresses deterministically without depending on external state (deployer's nonce). Instead, it uses the hash of the deployed contract code and salt:

pair := create2(0, add(bytecode, 32), mload(bytecode), salt)

Each time you update the Pair contract (even when you change compiler version), its bytecode changes, which means the hash of the bytecode also changes.

Have an idea how to automate this? PR is welcomed!

About

Uniswap V2 contracts, ready to be deployed to local or test network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published