Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pair合约的bincode hash怎么算呢? #2

Open
xiangjie256329 opened this issue Sep 24, 2020 · 7 comments
Open

Pair合约的bincode hash怎么算呢? #2

xiangjie256329 opened this issue Sep 24, 2020 · 7 comments

Comments

@xiangjie256329
Copy link

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

@jiyilanzhou
Copy link
Contributor

        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
Copy link
Contributor

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

@jiyilanzhou
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@xiangjie256329 @jiyilanzhou and others