This question is quite related to Compute uniswap pair address via python
I am trying to do the same but for panckage swap v2.
I am using the CAKE/WBNB pair as an example:
CONTRACTS = {
"CAKE": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
}
PANCAKE_SWAP_FACTORY = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"
PANCAKE_SWAP_ROUTER = "0x10ED43C718714eb63d5aA57B78B54704E256024E"
WBNB_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
hexadem_ ='0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5'
factory = PANCAKE_SWAP_FACTORY
abiEncoded_1 = encode_abi_packed(['address', 'address'], (CONTRACTS['CAKE'], WBNB_ADDRESS))
salt_ = pancakeswap.w3.solidityKeccak(['bytes'], ['0x' +abiEncoded_1.hex()])
abiEncoded_2 = encode_abi_packed([ 'address', 'bytes32'], ( factory, salt_))
resPair = pancakeswap.w3.solidityKeccak(['bytes','bytes'], ['0xff' + abiEncoded_2.hex(), hexadem_])[12:]
# resPair is the address for the pancakeswap CAKE/WBNB pair
print(resPair.hex())
print('0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6')
print(resPair.hex() == '0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6')
print()
My first problem is the code is not working, it is not producint the correct contract address, in fact it prints:
0x0ed7e52944161450477ee417de9cd3a859b14fd0
0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6
False
I think the problem is the value of the constant hexadem_, which can be found in:
The address you obtained is correct. The address that you are attempting to match to is for pancake V1. You can see this by clicking on "contract creator" for the 2 addresses, and you will see the pancake factory versions for 0x0ed7e52944161450477ee417de9cd3a859b14fd0 and 0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6.