Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with the Base chain? #380

Open
troublesprouter opened this issue Apr 2, 2024 · 10 comments
Open

How to use with the Base chain? #380

troublesprouter opened this issue Apr 2, 2024 · 10 comments

Comments

@troublesprouter
Copy link

I tried adding the data to constants.py in a fork but still get "execution reverted"

Any ideas on how to make it work?

@troublesprouter
Copy link
Author

here's my modified constants.py:

from typing import Set, cast
from web3.types import RPCEndpoint  # noqa: F401

# look at web3/middleware/cache.py for reference
# RPC methods that will be cached inside _get_eth_simple_cache_middleware
SIMPLE_CACHE_RPC_WHITELIST = cast(
    Set[RPCEndpoint],
    {
        "eth_chainId",
    },
)

ETH_ADDRESS = "0x0000000000000000000000000000000000000000"
WETH9_ADDRESS = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

# see: https://chainid.network/chains/
_netid_to_name = {
    1: "mainnet",
    3: "ropsten",
    4: "rinkeby",
    5: "görli",
    10: "optimism",
    42: "kovan",
    56: "binance",
    97: "binance_testnet",
    137: "polygon",
    100: "xdai",
    250: "fantom",
    42161: "arbitrum",
    421611: "arbitrum_testnet",
    1666600000: "harmony_mainnet",
    1666700000: "harmony_testnet",
    11155111: "sepolia",
    8453: "base",  # Added Base Mainnet
    84532: "base_sepolia",  # Added Base Testnet (Sepolia)
}

_factory_contract_addresses_v1 = {
    "mainnet": "0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95",
    "ropsten": "0x9c83dCE8CA20E9aAF9D3efc003b2ea62aBC08351",
    "rinkeby": "0xf5D915570BC477f9B8D6C0E980aA81757A3AaC36",
    "kovan": "0xD3E51Ef092B2845f10401a0159B2B96e8B6c3D30",
    "görli": "0x6Ce570d02D73d4c384b46135E87f8C592A8c86dA",
}

# For v2 the address is the same on mainnet, Ropsten, Rinkeby, Görli, and Kovan
# https://uniswap.org/docs/v2/smart-contracts/factory
_factory_contract_addresses_v2 = {
    "mainnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
    "ropsten": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
    "rinkeby": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
    "görli": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
    "xdai": "0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7",
    "binance": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
    "binance_testnet": "0x6725F303b657a9451d8BA641348b6761A6CC7a17",
    "harmony_mainnet": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",  # SushiSwap on Harmony
    "harmony_testnet": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
    "sepolia": "0x7E0987E5b3a30e3f2828572Bb659A548460a3003",
    "base": "0x33128a8fC17869897dcE68Ed026d694621f6FDfD",  # Added Base Mainnet factory address
    "base_sepolia": "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",  # Added Base Testnet (Sepolia) factory address
}

_router_contract_addresses_v2 = {
    "mainnet": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
    "ropsten": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
    "rinkeby": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
    "görli": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
    "xdai": "0x1C232F01118CB8B424793ae03F870aa7D0ac7f77",
    "binance": "0x10ED43C718714eb63d5aA57B78B54704E256024E",
    "binance_testnet": "0xD99D1c33F9fC3444f8101754aBC46c52416550D1",
    "harmony_mainnet": "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",  # SushiSwap on Harmony
    "harmony_testnet": "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",
    "sepolia": "0xC532a74256D3Db42D0Bf7a0400fEFDbad7694008",
    "base": "0x2626664c2603336E57B271c5C0b26F421741e481",  # Added Base Mainnet router address
    "base_sepolia": "0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4",  # Added Base Testnet (Sepolia) router address
}

MAX_UINT_128 = (2**128) - 1

# Source: https://github.com/Uniswap/v3-core/blob/v1.0.0/contracts/libraries/TickMath.sol#L8-L11
MIN_TICK = -887272
MAX_TICK = -MIN_TICK

# Source: https://github.com/Uniswap/v3-core/blob/v1.0.0/contracts/UniswapV3Factory.sol#L26-L31
_tick_spacing = {100: 1, 500: 10, 3_000: 60, 10_000: 200}

# Derived from (MIN_TICK//tick_spacing) >> 8 and (MAX_TICK//tick_spacing) >> 8
_tick_bitmap_range = {
    100: (-3466, 3465),
    500: (-347, 346),
    3_000: (-58, 57),
    10_000: (-18, 17),
}

@troublesprouter
Copy link
Author

If anyone could please add compatibility to base it would be amazing. I've tried but to no avail.

@woodychanjm
Copy link

I tried adding the data to constants.py in a fork but still get "execution reverted"

Any ideas on how to make it work?

Hi, do you have the solution already?

@jhcdx9999
Copy link

I have the same issue of "execution reverted", and the error starts from "self.router.functions". However, I know that Uniswap Base chain uses Universal Router (0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad). This router has different functions. Therefore, I think some new logic needs to be added into uniswap.py file.

@LiangPG
Copy link

LiangPG commented Apr 23, 2024

router: 0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24
factory: 0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6

@jhcdx9999
Copy link

router: 0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24 factory: 0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6

Thanks! It works on swapping tokens on Uniswap V2, but do you also know the ROUTER of Uniswap V3 compiled with uniswap.py?

@jfbloom22
Copy link

Here are all the Uniswap Base deployed contracts for V3: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments

@woodychanjm
Copy link

Here are all the Uniswap Base deployed contracts for V3: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments

I have set up all the contracts as below, but still getting 'execution reverted' error.

elif self.version == 3:
            # https://github.com/Uniswap/uniswap-v3-periphery/blob/main/deploys.md
            # factory_contract_address = _str_to_addr(
            #     "0x1F98431c8aD98523631AE4a59f267346ea31F984"
            # )
            factory_contract_address = _str_to_addr(
                "0x33128a8fC17869897dcE68Ed026d694621f6FDfD"
            )
            self.factory_contract = _load_contract(
                self.w3, abi_name="uniswap-v3/factory", address=factory_contract_address
            )
            # quoter_addr = _str_to_addr("0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6")
            quoter_addr = _str_to_addr("0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a")
            # self.router_address = _str_to_addr(
            #     "0xE592427A0AEce92De3Edee1F18E0157C05861564"
            # )
            self.router_address = _str_to_addr(
                "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD"
            )
            self.quoter = _load_contract(
                self.w3, abi_name="uniswap-v3/quoter", address=quoter_addr
            )
            self.router = _load_contract(
                self.w3, abi_name="uniswap-v3/router", address=self.router_address
            )
            # self.positionManager_addr = _str_to_addr(
            #     "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
            # )
            self.positionManager_addr = _str_to_addr(
                "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1"
            )
            self.nonFungiblePositionManager = _load_contract(
                self.w3,
                abi_name="uniswap-v3/nonFungiblePositionManager",
                address=self.positionManager_addr,
            )
            if self.netname == "arbitrum":
                multicall2_addr = _str_to_addr(
                    "0x50075F151ABC5B6B448b1272A0a1cFb5CFA25828"
                )
            else:
                # multicall2_addr = _str_to_addr(
                #     "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
                # )
                multicall2_addr = _str_to_addr(
                    "0x091e99cb1C49331a94dD62755D168E941AbD0693"
                )
            self.multicall2 = _load_contract(
                self.w3, abi_name="uniswap-v3/multicall", address=multicall2_addr
            )
        else:
            raise Exception(
                f"Invalid version '{self.version}', only 1, 2 or 3 supported"
            )

        if hasattr(self, "factory_contract"):
            logger.info(f"Using factory contract: {self.factory_contract}")

@jfbloom22
Copy link

Interesting. I am trying to do something similar with the official Typescript SDK, but I am running into a similar error.
In my case I am testing trying to get a quote. Does anyone know if the Universal Router is involved in quoting? At a glance, it does not appear to be involved.

Uniswap/examples#79

@jfbloom22
Copy link

Not sure if it will help, but I resolved the issue I was running into after I learned the contract I was targeting was a different version.

I discovered it my downloading the ABI directly from Etherscan and running a diff.

Here is what I changed just in case it helps you:
Uniswap/examples#79

FYI I found some updated examples from Uniswap here: https://discord.com/channels/597638925346930701/607978109089611786/948847107744333844

Hope it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants