Conversation
Implemented UniswapV2Router02 contract along with the UniswapV2Library to support liquidity operations and token swaps. Added unit tests to validate `pairFor` address calculations and ensure compatibility with a custom init code hash.
benefacto
left a comment
There was a problem hiding this comment.
Not a smart contract dev but it sounds like your liquidity pool work depends on this, so approving on that basis. Deployment script will need to be updated at some point to match.
|
It might not be necessary. I see that you call The // calculates the CREATE2 address for a pair without making any external calls
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',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}I even have a test that verifies this. BUT the deployment script fails when I try to replace the router build artifact in your deployment script with the one added by this PR. // old
import routerArtifact from "@uniswap/v2-periphery/build/UniswapV2Router02.json";
// new
import routerArtifact from "../artifacts/contracts/uniswap/UniswapV2Router02.sol/UniswapV2Router02.json";If your deployment is working, that's all that matters. We can shelve this PR. |
Thanks for laying that out. Yeah, if you're rebuilding the pair contract, the init code hash has to be updated but as long as we’re using the canonical Uniswap V2 artifacts from the NPM package (which we are in the deployment script), it should all line up. Glad we can shelve this for now. |
It is necessary to use the right UniswapV2Pair.sol bytecode for the Router to work.