I'm going to deploy the Uniswap contract on my customized Ethereum.
Could I replace fancy footwork in the factory by Solidity code?
I need to update this code assembly { pair := create2(0, add(bytecode, 32), mload(bytecode), salt)}
into general solidity code.
I tried this, but not working well.
CodePudding user response:
Uniswap version 1 uses library contracts with hardcoded pair contract addresses.
- First deploy the factory contract
- Then call Factory.pairCodeHash - the hardcoded hex string of the init code
- Replace the pair code hash in the source code, compile the rest of the contracts
More tips in this Python module.
CodePudding user response:
I found the solution
bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
I updated above code into
UniswapV2Pair newPair = new UniswapV2Pair();
IUniswapV2Pair(pair).initialize(token0, token1);