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

Solidly curves #322

Merged
merged 14 commits into from
Mar 22, 2024
Merged

Solidly curves #322

merged 14 commits into from
Mar 22, 2024

Conversation

sklbancor
Copy link
Collaborator

@sklbancor sklbancor commented Jan 22, 2024

This is the second part of the Solidly curve implementation (part one is here). It adds a few further analytics, but more importantly, it now adds the ability to add Solidity curves to the optimizer.

This is implemented via the new CPC method from_solidly that should be called with the two token balances x and y (obviously consistent with the pair provided, in tokens as floats).

VERY IMPORTANTLY, THE METHOD RETURNS A LIST OF CURVERS, RATHER THAN A SINGLE CURVE. The calling code should be able to handle the following situations

  1. Exactly one curve is contained in the list; this is the current default case when the match works, ie the AMM is within the linear area and not in the wings
  2. The list is empty, which means that the AMM is in the wings, and our flat approximation does not work, so we ignore it
  3. There are multiple curves contained in the list; this case is not implemented yet, but it may be implemented soon. In this case, the traded against the Solidity curve should the the sum of all trades against the returned curves_

Integration instructions

The code in this PR is now ready for integration:

  • get the (x,y,pair) values from the relevant solidly curves
  • call CPC.from_solidly(...)
  • this returns a list and the following cases should be dealt with (even though the last can't at the moment happen, but it may be easier to deal with it right away rather than having to change the code later again)
    • empty list -> the Solidly AMM is outside the range we approximate and should be ignored
    • one element -> the Solidly curve is approximated by a single CPC curve
    • multiple elements -> the Solidly curve is appriximated by multiple CPC curves
  • when creating trade instruction, all dx and dy values across all curves returned should simply be added up* to obtain our best estimate of how the curve will react; note that this is an approximation and it may be off by up to one percent at the current calibration and the code may have to deal with this

*as discussed previously, currently we only have one curve; when we have multiple curves you can be sure that the signs of the dx will all be the same (or zero), and ditto for the dy; most likely all but one will be maxed out, but you should not rely on it (and I don't think you care anyway)

@sklbancor sklbancor force-pushed the solidly branch 8 times, most recently from b6c0f1c to 7d60f8c Compare January 23, 2024 21:15
@zavelevsky zavelevsky changed the base branch from main to develop February 7, 2024 18:05
@sklbancor sklbancor force-pushed the solidly branch 12 times, most recently from 52f9c25 to 7b6c2a7 Compare March 21, 2024 10:12
@sklbancor sklbancor marked this pull request as ready for review March 21, 2024 10:33
fastlane_bot/tools/cpc.py Show resolved Hide resolved
fastlane_bot/tools/cpc.py Show resolved Hide resolved
fastlane_bot/tools/cpc.py Show resolved Hide resolved
fastlane_bot/tools/cpc.py Show resolved Hide resolved
fastlane_bot/tools/invariants/vector.py Show resolved Hide resolved
Update README.md
Revert "Functions -- DerivativeFunction -> PriceFunction [v0.9.1]"

This reverts commit c434f3e.

Revert "Changing docstrings in tools to improve documentation"

This reverts commit 7d67d01.
Update functions.py

Update functions.py

Update functions.py
@sklbancor sklbancor closed this Mar 21, 2024
@sklbancor sklbancor reopened this Mar 21, 2024
@sklbancor sklbancor marked this pull request as draft March 21, 2024 13:40
@sklbancor sklbancor marked this pull request as ready for review March 22, 2024 13:42
@barakman barakman self-requested a review March 22, 2024 13:49
@mikewcasale mikewcasale merged commit 2445048 into develop Mar 22, 2024
3 checks passed
@mikewcasale mikewcasale deleted the solidly branch March 22, 2024 15:01
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.

4 participants