go-uniswap icon indicating copy to clipboard operation
go-uniswap copied to clipboard

Pair合约的bincode hash怎么算呢?

Open xiangjie256329 opened this issue 4 years ago • 7 comments

可以提供个计算的代码参考下吗

xiangjie256329 avatar Sep 24 '20 09:09 xiangjie256329

        bytes memory bytecode = type(UniswapV2Pair).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token0, token1));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        }
        pair = address(uint(keccak256(abi.encodePacked(
                hex'ff',
                factory,
                keccak256(abi.encodePacked(token0, token1)),
                hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
            ))));

这是两个计算pair地址的方法,这里用到了create2方法,这个在evm中的实现为

	codeAndHash := &codeAndHash{code: code}
	contractAddr = crypto.CreateAddress2(caller.Address(), common.Hash(salt.Bytes32()), codeAndHash.Hash().Bytes())

可以看到type(UniswapV2Pair).creationCode是计算create2需要的code,而create2中的hash是hash的code,所以96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f要和hash(creationCode)一致

@fern-xian @jackorjorn

jiyilanzhou avatar Oct 10 '20 09:10 jiyilanzhou

添加不了流动性报的什么错误,合约执行的错误可以帮忙看下,前端页面就帮助不了了。最近比较忙,没时间学前端。 @jackorjorn

jiyilanzhou avatar Oct 11 '20 05:10 jiyilanzhou

用这个https://github.com/D-CDC/go-uniswap/blob/master/contracts/deployUniswap/tx_test.go#L40例子测试下你的交易把,把交易参数填充下,可以获得执行结果。 @jackorjorn

jiyilanzhou avatar Oct 12 '20 02:10 jiyilanzhou