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

Add function to get amount of asset locked per tick in pool #283

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

IanMichaelHarper
Copy link

@IanMichaelHarper IanMichaelHarper commented Oct 11, 2022

This function is more or less the same as the get_tvl_in_pool() function but slightly modified to return the amount of each asset locked in a pool per tick.

I created a test to ensure that the amounts returned sum to the same result as get_tvl_in_pool(). I'm having trouble running the tests locally, so I thought I'd open a PR so the tests could run on Github.

@ErikBjare
Copy link
Member

Wow, well done!

I've allowed the test to run now. If you want to run them yourself without having to wait for me to approve the run, you can push to the master branch of your own fork, which should trigger a run (althought might be missing credentials).

@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Base: 84.17% // Head: 57.67% // Decreases project coverage by -26.50% ⚠️

Coverage data is based on head (acfa607) compared to base (dc053cd).
Patch coverage: 2.38% of modified lines in pull request are covered.

❗ Current head acfa607 differs from pull request most recent head 4a4cf25. Consider uploading reports for the commit 4a4cf25 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #283       +/-   ##
===========================================
- Coverage   84.17%   57.67%   -26.51%     
===========================================
  Files          10       10               
  Lines        1030     1082       +52     
===========================================
- Hits          867      624      -243     
- Misses        163      458      +295     
Impacted Files Coverage Δ
uniswap/constants.py 100.00% <ø> (ø)
uniswap/uniswap.py 50.58% <2.38%> (-31.88%) ⬇️
uniswap/util.py 64.86% <0.00%> (-22.10%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ErikBjare
Copy link
Member

Looks like we have a failure:

/home/runner/work/uniswap-python/uniswap-python/tests/test_uniswap.py:385: TypeError: 'function' object is not subscriptable

Was also picked up by the typechecking:

poetry run mypy --pretty
uniswap/uniswap.py:1454: error: Need type annotation for
"liquidity_per_tick_dict"
            liquidity_per_tick_dict = {
                                      ^
tests/test_uniswap.py:385: error: Value of type "Callable[[Uniswap], Any]" is
not indexable
            pool = client.get_pool_instance(tokens[token0], tokens[token1]...
                                            ^
Found 2 errors in 2 files (checked 12 source files)
make: *** [Makefile:7: typecheck] Error 1

@KeremP
Copy link
Contributor

KeremP commented Oct 13, 2022

@IanMichaelHarper looks like the error is here:

@pytest.mark.parametrize("token0, token1", [("DAI", "USDC")])
 def test_asset_locked_per_tick_sums_to_tvl(self, client: Uniswap, token0, token1):
          .....

whereas in order to use the tokens dict that is scoped with the pytest decorators you must pass it in as input:

@pytest.mark.parametrize("token0, token1", [("DAI", "USDC")])
 def test_asset_locked_per_tick_sums_to_tvl(self, client: Uniswap, tokens, token0, token1):
          .....

@IanMichaelHarper
Copy link
Author

Whoops. Sorry about that. Updated now.

@IanMichaelHarper
Copy link
Author

this is how I had the test passing originally for what I was working on, where approximately correct was fine. Finding the discrepancy for exact values requires more digging and debugging.

@KeremP
Copy link
Contributor

KeremP commented Oct 13, 2022

I think approximately correct is fine for now, working with the tickbitmap, etc. can get a little complex.

Apparently the subgraph bug has been fixed somewhat recently:
Uniswap/v3-subgraph#74 (comment)

I'll definitely take a look this weekend and see if there are any improvements to glean and update the tvl in pool code respectively.

Good work though! 👍

@shakibaei65

This comment has been minimized.

@Meryline
Copy link

Meryline commented Nov 7, 2023

This is true

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

Successfully merging this pull request may close these issues.

None yet

5 participants