Skip to content

get_tvl_in_pool crashes with "Provided tick is out of bounds" error #321

Open

Description

@iurii2002

I am trying to use get_tvl_in_pool to get the best option between 0.3% and 1% pools on UniV3
When I use it for WETH/USDC pair 0.3% pair it gets reverted with "Provided tick is out of bounds: (-887220, 887220)" error.

My code:

from web3 import Web3
from uniswap import Uniswap
from config.config import get_provider

address = None                    # or None if you're not going to make transactions
private_key = None                # or None if you're not going to make transactions
version = 3                       # specify which version of Uniswap to use
provider = get_provider('ethereum')['rpc']    # can also be set through the environment variable `PROVIDER`

uniswap = Uniswap(address=address, private_key=private_key, provider=provider, version=version)

token_address_usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
# token_address_ape = '0x4d224452801ACEd8B2F0aebE155379bb5D594381'

weth_address = uniswap.get_weth_address()

token_address = Web3.toChecksumAddress(token_address_usdc)

pool_03 = uniswap.get_pool_instance(weth_address, token_address, 3000)
tvl = uniswap.get_tvl_in_pool(pool_03)
print(tvl)

Error

Traceback (most recent call last):
  File "/home/iurii/Desktop/blockchain/retrodrop/arbitrum/test.py", line 20, in <module>
    tvl = uniswap.get_tvl_in_pool(pool_03)
  File "/home/iurii/Desktop/blockchain/retrodrop/arbitrum/venv/lib/python3.8/site-packages/uniswap/uniswap.py", line 1342, in get_tvl_in_pool
    _min_tick = self.find_tick_from_bitmap(
  File "/home/iurii/Desktop/blockchain/retrodrop/arbitrum/venv/lib/python3.8/site-packages/uniswap/uniswap.py", line 1298, in find_tick_from_bitmap
    _min_tick = self.get_min_tick_from_wordpos(
  File "/home/iurii/Desktop/blockchain/retrodrop/arbitrum/venv/lib/python3.8/site-packages/uniswap/uniswap.py", line 1255, in get_min_tick_from_wordpos
    min_tick_in_word = nearest_tick(_tick, fee)
  File "/home/iurii/Desktop/blockchain/retrodrop/arbitrum/venv/lib/python3.8/site-packages/uniswap/util.py", line 111, in nearest_tick
    assert (
AssertionError: Provided tick is out of bounds: (-887220, 887220)

Process finished with exit code 1

However, for the WETH/APE pool it works just fine.
So this is probably some corner case that makes script fail. Not really sure how to fix it

Activity

  1. DS-12 commented on Oct 27, 2023

    @DS-12

    Is there a solution for this? I also experience the same on a WMATIC/USDC 0.3% pool for v3 on polygon.

  2. KeremP commented on Oct 27, 2023

    @KeremP
    Contributor

    This assertion error is being triggered because, when finding the nearest viable tick to the one derived from the bitmap, an "out of bounds" tick is being returned.

    May be some weird edge case - my solution to calculating tvl on-chain at the time was a bit hacky and had to do with reverse engineering how the tick-bitmap was built for each pool.

    Using the subgraph for now is probably your best proxy for TVL data.

    Edit: I have not been active in maintaining my contributions to this project lately so this would be a great first issue for someone else to tackle!

  3. ErikBjare commented on May 22, 2024

    @ErikBjare
    Member

    Just stumbled into the same issue when trying to use mint_liquidity.

    AssertionError: Provided tick is out of bounds: (-887200, 887200)
    

    Edit: I managed to fix it by doing the proper tick calculation with encode_sqrt_ratioX96 and the new get_tick_at_sqrt in 7f4d5c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions