-
Notifications
You must be signed in to change notification settings - Fork 608
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
solver for multi-asset CFMM #1429
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
the
C:x/gamm
Changes, features and bugs related to the gamm module.
label
May 5, 2022
AlpinYukseloglu
changed the title
multi-asset swap / LP equations, and tests
solver for multi-asset CFMM
May 5, 2022
Codecov Report
@@ Coverage Diff @@
## main #1429 +/- ##
==========================================
- Coverage 19.82% 19.51% -0.32%
==========================================
Files 202 226 +24
Lines 27685 30995 +3310
==========================================
+ Hits 5489 6048 +559
- Misses 21175 23842 +2667
- Partials 1021 1105 +84
Continue to review full report at Codecov.
|
AlpinYukseloglu
commented
May 6, 2022
ValarDragon
reviewed
May 6, 2022
ValarDragon
reviewed
May 6, 2022
AlpinYukseloglu
commented
May 6, 2022
ValarDragon
reviewed
May 6, 2022
ValarDragon
reviewed
May 6, 2022
Co-authored-by: Dev Ojha <[email protected]>
ValarDragon
approved these changes
May 6, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #1369
What is the purpose of the change
This PR implements the solver for our multi-asset CFMM (as outlined in the previous PR for issue #1369).
This is an extension of the original two-asset CFMM used in Solidly, which we expand here to accommodate n-asset pools without significantly increasing complexity or runtime. While this type of multi-asset pool was one that we found was perhaps unnecessarily complex for volatile assets, it is critical from a capital efficiency standpoint that we have the option for Curve-like 3pools and 4pools for our stableswap so as to not fragment stablecoin liquidity.
Our final multi-asset CFMM is
xyz(x^2 + y^2 + w) = k
, where z represents the product of the reserves of all assets that are not being swapped between, and w represents the sum of all of their squares. This PR implements a solver that finds the correct output for of a requested tokena
given an input of another tokenb
in the pool and accommodates swaps between any two assetsx
andy
in an n-asset stableswap. The polynomial we solve for can be described as:(x - a)(y + b)z((x - a)^2 + (y +b)^2 + w) = k
, where we solve fora
. The solution is pasted below, but given how it is quite complex and not easy to visually parse without the abstractions we have laid out in the code comments, please refer to those for more comprehensive and readable implementation details.Brief change log
solveCfmmMulti
function inx/gamm/pool-models/stableswap/amm.go
using the derivations set up in code commentsTesting and Verifying
The tests for this change line up in coverage with those for our two-asset stableswap CFMM and can be found in
amm_test.go
.Documentation and Release Note
Unreleased
section inCHANGELOG.md
? (no)