Full copy of the original contracts with some minor changes:
- All contracts were updated to version 0.8.13, with minor changes.
- Example contracts were not copied over due to a missing contract they require. PR is welcomed!
-
$ yarn $ alias hh="yarn hardhat" $ hh node
- In another terminal window:
$ hh run scripts/deploy.js $ hh console
- 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.
Each time you update UniswapV2Pair.sol
contract, you need to update the hex
value in this line:
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:
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!