@airdao/swap-router-contracts
Version:
Smart contracts for swapping on Astra Classic and CL
23 lines (20 loc) • 887 B
text/typescript
import { bytecode } from '@airdao/astra-cl-core/artifacts/contracts/AstraCLPool.sol/AstraCLPool.json'
import { utils } from 'ethers'
export const POOL_BYTECODE_HASH = utils.keccak256(bytecode)
export function computePoolAddress(factoryAddress: string, [tokenA, tokenB]: [string, string], fee: number): string {
const [token0, token1] = tokenA.toLowerCase() < tokenB.toLowerCase() ? [tokenA, tokenB] : [tokenB, tokenA]
const constructorArgumentsEncoded = utils.defaultAbiCoder.encode(
['address', 'address', 'uint24'],
[token0, token1, fee]
)
const create2Inputs = [
'0xff',
factoryAddress,
// salt
utils.keccak256(constructorArgumentsEncoded),
// init code hash
POOL_BYTECODE_HASH,
]
const sanitizedInputs = `0x${create2Inputs.map((i) => i.slice(2)).join('')}`
return utils.getAddress(`0x${utils.keccak256(sanitizedInputs).slice(-40)}`)
}