我將在我定制的以太坊上部署 Uniswap 合約。
我可以 用 Solidity 代碼代替工廠里花哨的步法嗎?
我需要將此代碼更新assembly { pair := create2(0, add(bytecode, 32), mload(bytecode), salt)}為一般的可靠性代碼。
我試過這個,但效果不好。
uj5u.com熱心網友回復:
Uniswap 版本 1 使用帶有硬編碼對合約地址的庫合約。
- 首先部署工廠合約
- 然后呼叫Factory.pairCodeHash - 初始化代碼的硬編碼十六進制字串
- 替換源代碼中的pair code hash,編譯剩下的合約
此 Python 模塊中的更多提示。
uj5u.com熱心網友回復:
我找到了解決方案
bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
我將上面的代碼更新為
UniswapV2Pair newPair = new UniswapV2Pair();
IUniswapV2Pair(pair).initialize(token0, token1);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/443220.html
下一篇:如何在QT中為我的類指定樣式表
