fetch_deployment

Documentation for eth_defi.uniswap_v2.deployment.fetch_deployment function.

fetch_deployment(web3, factory_address, router_address, init_code_hash=None, allow_different_weth_var=True)[source]

Construct Uniswap deployment based on on-chain data.

Fetches init code hash from on-chain.

Factory does not know about routers, so they must be explicitly given.

Read more details here.

Example how to get PancakeSwap v2 deployment:

@pytest.fixture()
def pancakeswap_v2(web3) -> UniswapV2Deployment:
    deployment = fetch_deployment(
        web3,
        "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
        "0x10ED43C718714eb63d5aA57B78B54704E256024E",
        # Taken from https://bscscan.com/address/0xca143ce32fe78f1f7019d7d551a6402fc5350c73#readContract
        init_code_hash="0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5",
        )
    return deployment
Parameters
  • init_code_hash (Optional[Union[HexStr, str]]) – Read init code hash from the caller. If not given call pairCodeHash (SushiSwap) on the factory.

  • allow_different_weth_var – We assume Uniswap v2 ABI that has router.WETH() accessor. Some DEXes like Trader Joe do not have it, using WAVAX instead, needing a different ABI file. If set (default) ignore this error and just have None as the value for the wrapped token.

  • web3 (web3.main.Web3) –

  • factory_address (Union[HexAddress, str]) –

  • router_address (Union[HexAddress, str]) –

Returns

Data class representing Uniswap v3 exchange deployment

Return type

eth_defi.uniswap_v2.deployment.UniswapV2Deployment