Uniswap / v3-polars

GNU General Public License v2.0
96 stars 16 forks source link

No data returned is not necessarily an error #16

Closed ankile closed 2 months ago

ankile commented 2 months ago

Hey, in this piece of code, the program crashes if the Allium connector does not return any data. In my expoerience, though, this may happen for totally valid queries.

https://github.com/Uniswap/v3-polars/blob/e23531b8eaf2261e967d59f26d7151d675a61d68/v3/helpers/connectors/allium.py#L218-L219

For example, the basic example crashes when I run it because it checks what the latest block I have in my data, realizes that it's not the latest on the blockchain that we have access to in Allium, but when trying to pull the blovks between my latest and the latest in Allium, there happens to be no swaps/liquidity events/etc. in those blocks, causing Allium to (correctly) return no rows.

Is this the right understanding or am I doing something wrong? For reference, I'm trying to run this code to produce the error:

address = "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"

eth = state.v3Pool(
    address,
    "ethereum",
    update=True,
    update_from="allium",
)

I get the error:

Exception: No data returned from Allium query select * 
            FROM 
            (
                select 
                    'ethereum' as "chain_name",
                    block_timestamp as "block_timestamp",
                    block_number as "block_number",
                    transaction_hash as "transaction_hash",
                    log_index as "log_index",
                    token0_address as "token0",
                    token1_address as "token1",
                    fee as "fee",
                    tick_spacing as "tick_spacing", -- will be renamed to camel case
                    liquidity_pool_address as "pool"
                from ethereum.dex.pools
                where 1=1 and protocol='uniswap_v3'
            )

            where 1=1
            AND "block_number" <= 20248885
            AND "block_number" >= 20248611

As a temporary fix on my end, I've allowed the query to be empty, and instead returning None and handling the None on the level above:

        if not data:
            return None

And add this on line 220 in data_update.py

            if df is None:
                print(f"No more data to pull for {table}")
                break

~I'm happy to make~ I've made a pull request (#17) if this is the fix you'd want to do—otherwise please advise on what I'm doing wrong to get this error!

Thank you :)

Lars

aadams commented 2 months ago

Nice catch and thanks for the PR! I'm closing this issue since I merged your PR.