tradingstrategy-ai / web3-ethereum-defi

A Python library for trading automation on DeFi, data research and integration. Supporting Uniswap, Aave, Chainlink, USDC and other protocols.
https://tradingstrategy.ai
MIT License
580 stars 125 forks source link

Negative Liquidity Gross #213

Open DanieleMDiNosse opened 1 month ago

DanieleMDiNosse commented 1 month ago

I observed that in certain pools, such as USDC/WETH .05% ('0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'), the liquidity gross column generated by first using create_tick_delta_csv and then create_tick_csv displays negative values. According to my knowledge of Uniswap v3's functionality, this should not be possible.

miohtama commented 1 day ago

Good spot.

We have not deeply vetted the code, so if you have insight what is causing this we are happy to fix.

hieuh25 commented 1 day ago

I observed that in certain pools, such as USDC/WETH .05% ('0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'), the liquidity gross column generated by first using create_tick_delta_csv and then create_tick_csv displays negative values. According to my knowledge of Uniswap v3's functionality, this should not be possible.

It all comes down to what is the range of events you have.

Breaking down the functionality of each function:

So both functions above don't handle the fetching part of the source data: events. If your source data (events) only contains events in a certain range of blocks in history, then liquidity delta is possible to be negative (more burns than mints)

DanieleMDiNosse commented 1 day ago

I observed that in certain pools, such as USDC/WETH .05% ('0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'), the liquidity gross column generated by first using create_tick_delta_csv and then create_tick_csv displays negative values. According to my knowledge of Uniswap v3's functionality, this should not be possible.

It all comes down to what is the range of events you have.

Breaking down the functionality of each function:

  • create_tick_delta_csv() basically outputs all the mint and burn events and tick range of each
  • create_tick_csv() uses data from tick delta to aggregate to have the liquidity delta, hence the name of the column is liquidity_gross_delta, not liquidity_gross

So both functions above don't handle the fetching part of the source data: events. If your source data (events) only contains events in a certain range of blocks in history, then liquidity delta is possible to be negative (more burns than mints)

I downloaded all the data since the first Uniswap V3 block via the official tutorial. If I am the only one that is experiencing this issue, I do not exclude the possibility that it can be a data fetching problem due to the Ethereum node. I will try using different sources and I will update this discussion.

If anyone has some other insight, please share it with us!

Good spot.

We have not deeply vetted the code, so if you have insight what is causing this we are happy to fix.

Of course!