I'm trying to do calculations for determining pool addresses. However my INIT HASH keeps being wrong.
I found some code which calculates pool addresses in a different way
export const POOL_INIT_CODE_HASH =
'0x010013f177ea1fcbc4520f9a3ca7cd2d1d77959e05aa66484027cb38e712aeed';
export const CONSTRUCTOR_INPUT_HASH =
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
export const PREFIX =
'0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494';
export function computeZkPoolAddress({
factoryAddress,
tokenA,
tokenB,
fee,
initCodeHashManualOverride,
}: {
factoryAddress: string;
tokenA: Token;
tokenB: Token;
fee: FeeAmount;
initCodeHashManualOverride?: string;
}): string {
const salt = solidityKeccak256(
['bytes'],
[
defaultAbiCoder.encode(
['address', 'address', 'uint24'],
[tokenA.address, tokenB.address, fee],
),
],
);
const pool = getAddress(
hexDataSlice(
keccak256(
concat([
PREFIX,
zeroPad(factoryAddress, 32),
salt,
initCodeHashManualOverride ?? POOL_INIT_CODE_HASH,
CONSTRUCTOR_INPUT_HASH,
]),
),
12,
),
);
return pool;
}
I tried calculating the init hash using the following answer:
https://ethereum.stackexchange.com/a/107643
However, it gave me bogus pools. I can add and remove liquidity fine but swap doesn't work since the routes can't calculate the pool addresses.
In this example it seems they're using multiple values, I'm wondering how to calculate the prefix here, and the other values?
computePoolAddress, also provide the factory address and the network you're trying to do this one – MShakeG Sep 19 '23 at 07:00