KywFactory 添加如下 bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(KywPair).creationCode 说明: 在智能合约中添加bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(KywPair).creationCode 这里详细解释一下: 创建代码的哈希值:keccak256(abi.encodePacked(type(KywPair).creationCode))这一表达式计算的是KywPair合约创建时的完整字节码的哈希值 在Solidity中,type(KywPair).creationCode直接引用了KywPair合约的创建字节码。
owner,uint _foo) public pure returns(bytes memory){ bytes memory bytecode= type(TestContract).creationCode
最关键的就是以下这几行代码: bytes memory bytecode = type(UniswapV2Pair).creationCode; bytes32 salt = keccak256(abi.encodePacked { pair := create2(0, add(bytecode, 32), mload(bytecode), salt) } 第一行获取 UniswapV2Pair 合约代码的创建字节码 creationCode 可以在工厂合约中添加一行代码保存这个创建字节码: bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair).creationCode
const creationCode = await provider.getCode(address);if (creationCode === '0x') return 0.0; // EOA账户,
abi.encodePacked( hex"ff", address(this), bytes32(i), keccak256(type(Helper).creationCode
该值其实是 UniswapV2Pair 合约的 creationCode 的哈希值。 合约中添加以下常量获取到该值: bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair).creationCode
添加一行代码: bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair).creationCode
uint256 salt) public { // get wallet init_code bytes memory bytecode = type(Wallet).creationCode
UniswapV2: PAIR_EXISTS'); // single check is sufficient bytes memory bytecode = type(UniswapV2Pair).creationCode keccak256(abi.encodePacked(token0, token1)), 且 token0 < token1 keccak256(type(Contract_to_Deploy).creationCode function pair_code() public view returns(bytes memory){ return type(UniswapV2Pair).creationCode function pair_codehash() public view returns(bytes32 ){ return keccak256( type(UniswapV2Pair).creationCode
; constructor() { // 将合约代码存储在 contractCode 变量中 contractCode = type(CodeExample).creationCode
Caller caller; uint i = 0; while (true) { bytes memory bytecode = type(Caller).creationCode
view returns (bytes memory) { bytes memory bytecode = type(SimpleWallet).creationCode
UniswapV2: PAIR_EXISTS'); // single check is sufficient bytes memory bytecode = type(UniswapV2Pair).creationCode 在创建时会首先检查TokenA是否与TokenB是同一币种,之后对两种Token地址进行一次简易排序,之后检查地址是否为空,之后检查交易对是否存在,然后用获取交易对模板合约UniswapV2Pair创建字节码creationCode UniswapV2: PAIR_EXISTS'); // single check is sufficient bytes memory bytecode = type(UniswapV2Pair).creationCode