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

Feature: Curve V2 Sim #96

Closed
14 tasks done
chanhosuh opened this issue Mar 2, 2023 · 3 comments
Closed
14 tasks done

Feature: Curve V2 Sim #96

chanhosuh opened this issue Mar 2, 2023 · 3 comments

Comments

@chanhosuh
Copy link
Member

chanhosuh commented Mar 2, 2023

@allt0ld
Copy link
Collaborator

allt0ld commented Mar 3, 2023

I tried to simulate two V2 pools, not knowing they were not yet supported. Thought I'd contribute my findings. TLDR: my specific errors result from the large difference between simulated Stableswap prices and actual (volatile) prices where the peg is not 1:1.

Both pools were basic two-token ones, crv-eth (symbol "crvCRVETH") and cvx-eth (symbol "crvCVXETH") on mainnet, using the following code:

import curvesim
res = curvesim.autosim("[symbol]")

No parameters were overridden or added. The output, which I've truncated, looked like the below (this is the cvx-eth pool)

Warning: Opt_arb error, Pair: (1, 0) Pool price: 0.9996 Target Price: 0.003889433647690374 Diff: 0.9957105663523097
Warning: Opt_arb error, Pair: (1, 0) Pool price: 0.9996 Target Price: 0.003916063090355466 Diff: 0.9956839369096446
Warning: Opt_arb error, Pair: (1, 0) Pool price: 0.9996 Target Price: 0.003888620809118686 Diff: 0.9957113791908814

Naturally, the simulated pool is behaving as if both tokens were stablecoins under Stableswap (pool price close to 1), since only V1 pools are supported at the moment. The specific error is a ValueError handled by the except clause on line 658 in curvesim/pipelines/arbitrage.py, in function get_trade_args. Possible reasons:

  • On lines 653-655 opt_arb(get_bounds, error_function, in_index, out_index, price) propagates a ValueError from subsequent calls in the call stack
  • On line 656, min(trade[2], limit) raises a ValueError due to taking in an empty iterable with no default placeholder specified. Source

The error_function passed in is post_trade_price_error(dx, i, j, price_target) defined on line 74 of curvesim/pool/sim_interface/pool.py, which calculates dydx - price_target. It doesn't look like root_scalar(error_function,...) imported from scipy.optimize (line 476 of arbitrage.py) or error_function itself return a ValueError. Therefore, it may be possible to reuse the arbitrage pipeline if you redefine the invariant to suit V2, and modify the logic where you raise an exception based on Pool Price - Target Price, wherever it is.

@nagakingg
Copy link
Collaborator

Thanks @PhilipLu97, that sounds about right. The arbitrage pipeline should work once we make sim_interfaces for v2, which will provide the error_functions, etc.

Once we merge the new metrics/plotter, we will also need add entries to compute the metrics for v2 pools.

@chanhosuh -- So we don't forget, we also need to make bonding_curve and order_book support v2

@chanhosuh chanhosuh added this to the Cryptopool Sims milestone Jun 23, 2023
@chanhosuh chanhosuh added epic and removed enhancement New feature or request labels Jul 5, 2023
This was referenced Jul 28, 2023
@chanhosuh
Copy link
Member Author

Epic finished with the release of 0.5.0.b1, although we will of course wrap up the data provider issues etc.

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

No branches or pull requests

3 participants