anyone have a good idea how the INIT_CODE_HASH value is calculated to begin with? AI's seem to think its a hash of the deployed pool(s) bytecode.
I am deploying mocks of the [v3] factory, NonfungiblePositionManager, and Pool contracts. This involves some slight modifications of the contracts -- a thing that will likely alter theresulting abi and bytecode of the deployed pools, so I need a different INIT_CODE_HASH in order to replicate these pool addresses deterministically. For sure 'computeAddress' in the PoolAddress.sol library is not giving me the address of my deployed pool contracts.
I've tried AI's suggestions of hashing the bytecode of the deployed pool contract (i also tried inputing the mock factory address), using this as the value of INIT_CODE_HASH, then using this as a means to compute/ replicate the pool address(s). So far it does not work. The code for this [i.e. a mock version of PoolAddress.sol] is,
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.6;
pragma abicoder v2;
contract ComputePoolAddress {
// get bytecode of deployed pool, or any other contract
function getContractByteCode(address _addr) public view returns (bytes memory) {
uint length;
assembly {
length := extcodesize(_addr)
}
bytes memory bytecode = new bytes(length);
assembly {
extcodecopy(_addr, add(bytecode, 0x20), 0, length)
}
return bytecode;
}
// compute hash of bytecode
function computePoolInitCodeHash(address _contractAddress) public view returns (bytes32) {
// Get the bytecode of the pool contract
bytes memory poolBytecode = getContractByteCode(_contractAddress);
// Compute the keccak256 hash of the bytecode
bytes32 hash = keccak256(poolBytecode);
return hash;
}
// compute [replicate] deployed pool address deterministically
function computeAddress(address factory,
address token0,
address token1,
uint24 fee,
address contract_)
public view returns (address pool)
{
require(token0 < token1, "token1 > token0");
bytes32 POOL_INIT_CODE_HASH = computePoolInitCodeHash(contract_);
pool = address(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encode(token0, token1, fee)),
POOL_INIT_CODE_HASH
)
)
)
);
}
- note that compiling this with pragma solidity 0.8.0 or higher will cause errors because of casting an address to a uint256
}