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

Use Curve Prices API for pool volume #277

Merged
merged 8 commits into from
Nov 1, 2023
Merged

Use Curve Prices API for pool volume #277

merged 8 commits into from
Nov 1, 2023

Conversation

nagakingg
Copy link
Collaborator

Description

Updates historical pool volume functionality to use the new Curve Prices API. Pool volume for each token pair is denominated in the pair's quote token, rather than pseudo-dollars, to allow for correct volume limiting for v2 pools. In the volume-limited arbitrage pipeline, volume multipliers are computed for each pair using this data. Volume limiter modes are removed as this method is more accurate than all of the previous modes, which relied on aggregate pool volume across all pairs.

  • Add network.curve_prices
  • Add ApiResultError to exceptions
  • Add vol_limited_arb.pool_volume.get_pool_volume()
  • Compute volume multiplier per asset pair
  • Remove volume multiplier modes
  • Remove pipelines.utils
  • Remove PriceVolume.total_volumes()
  • Remove volume from PoolDataCache

Hygiene checklist

  • Changelog entry
  • Everything public has a Numpy-style docstring
    (modules, public functions, classes, and public methods)
  • Commit history is cleaned-up with minor changes squashed together
    and descriptive commit messages following Tim Pope's style

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@nagakingg
Copy link
Collaborator Author

nagakingg commented Oct 26, 2023

A few open questions:

  • Should PoolDataCache be fully removed in this PR? Or hold off
  • Should vol_limited_arb.pool_volume.get_pool_volume() be moved to pool_data.get_pool_volume()? If so, I think it should also allow a pool address to be input in lieu of a pool metadata object

Edit:

  • PoolDataCache fully removed
  • get_pool_volume moved to pool_data

@github-actions
Copy link
Contributor

github-actions bot commented Oct 26, 2023

Coverage report

The coverage rate went from 76.03% to 78.08% ⬆️
The branch rate is 64%.

91.15% of new lines are covered.

Diff Coverage details (click to unfold)

curvesim/exceptions/init.py

100% of new lines are covered (100% of the complete file).

curvesim/network/curve_prices.py

91.42% of new lines are covered (86.84% of the complete file).
Missing lines: 47, 48, 122

curvesim/pipelines/vol_limited_arb/init.py

16.66% of new lines are covered (36.36% of the complete file).
Missing lines: 94, 103, 104, 105, 106

curvesim/pool/init.py

0% of new lines are covered (72.63% of the complete file).
Missing lines: 279

curvesim/pool_data/init.py

100% of new lines are covered (100% of the complete file).

curvesim/pool_data/queries/init.py

100% of new lines are covered (100% of the complete file).

curvesim/pool_data/queries/metadata.py

100% of new lines are covered (88% of the complete file).

curvesim/pool_data/queries/pool_volume.py

98.24% of new lines are covered (95.45% of the complete file).
Missing lines: 93

@nagakingg nagakingg force-pushed the curve-prices-volume branch 5 times, most recently from 3cf51af to 43567cc Compare October 26, 2023 14:19
- Add network.curve_prices
- Add ApiResultError to exceptions
- Add vol_limited_arb.pool_volume.get_pool_volume()
- Compute volume multiplier per asset pair
- Remove volume multiplier modes
- Remove pipelines.utils
- Remove PriceVolume.total_volumes()
- Remove volume from PoolDataCache
- Remove convex subgraph volume query
@nagakingg nagakingg force-pushed the curve-prices-volume branch from 43567cc to dff0508 Compare October 26, 2023 17:37
@nagakingg nagakingg force-pushed the curve-prices-volume branch from 83e64fb to 6f99d4e Compare October 26, 2023 20:23
@nagakingg
Copy link
Collaborator Author

Comparing 3pool sim results before and after the volume limit change. As expected:
(a) Old version volume limits are roughly the average of the new version volume limits
(b) the results are similar but not exactly the same

Volume Limits
Old version:
DAI/USDC: 0.000037
DAI/USDT: 0.000037
USDC/USDT: 0.000037

New version:
DAI/USDC: 0.000016
DAI/USDT: 0.000022
USDC/USDT: 0.000054

Results
Old Version:
3pool_old

New Version:
3pool_new

@nagakingg nagakingg marked this pull request as ready for review October 26, 2023 20:32
@nagakingg nagakingg requested a review from chanhosuh October 26, 2023 21:36
Copy link
Member

@chanhosuh chanhosuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks really nice, big improvements on the current codebase!

I would update the changelog entries tho :)

- Removed volume from PoolDataCache
- Removed convex subgraph volume query
- Removed PoolDataCache

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention we've removed volume support for chains other Mainnet (pending future support from the curve-prices API) and sims for the RAI pool are no longer supported.

Added
-----
- Added network.curve_prices
- Added ApiResultError to exceptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand stuff gets aggregated for the release changelog, but it helps to leave out clutter like this: nobody will ever care you added this error class, but probably most people would want to know what network.curve_prices is.

from curvesim.pool_data.metadata import PoolMetaData
from curvesim.utils import get_pairs

from ..unit.test_pool_metadata import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of imports like this because they couple tests together unexpectedly. Nobody working on pool metadata tests would expect the pool volume integration tests to fail because they changed something.

Probably we should have a better test setup of some sort, whether it's fixtures or something else, but from what we discussed, this will go away anyway due to volume functionality being injected into a ReferenceMarket class, so I don't think it's worth it.

In that case, I would expect better intermediate abstractions of some sort, e.g. pool metadata --> asset abstractions --> volume functions; this would be "happening" inside a ReferenceMarket (or its factory), but for testing, it would separate pool metadata rather cleanly from the volume functions via the intermediate asset abstractions.

@chanhosuh chanhosuh added this to the 0.5.0rc milestone Oct 26, 2023
@nagakingg nagakingg force-pushed the curve-prices-volume branch from 6f99d4e to 0bda59a Compare October 27, 2023 17:16
- replace pool_data.queries with folder
- move pool_volume to pool_data.queries
- support get_pool_volume() using pool address
@nagakingg nagakingg force-pushed the curve-prices-volume branch from 0bda59a to 048c0e8 Compare October 27, 2023 17:23
@nagakingg nagakingg marked this pull request as draft October 27, 2023 21:51
@nagakingg nagakingg marked this pull request as ready for review November 1, 2023 17:05
@nagakingg nagakingg merged commit 71c5518 into main Nov 1, 2023
1 check passed
@nagakingg nagakingg deleted the curve-prices-volume branch November 1, 2023 17:06
@allt0ld allt0ld mentioned this pull request Nov 2, 2023
3 tasks
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.

2 participants