-
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
feat(stableswap): implement and test JoinPoolNoSwap and CalcJoinPoolNoSwapShares abstractions #2916
Conversation
@@ -52,4 +81,6 @@ var ( | |||
ErrInvalidStableswapScalingFactors = sdkerrors.Register(ModuleName, 62, "length between liquidity and scaling factors mismatch") | |||
ErrNotScalingFactorGovernor = sdkerrors.Register(ModuleName, 63, "not scaling factor governor") | |||
ErrInvalidScalingFactors = sdkerrors.Register(ModuleName, 64, "invalid scaling factor") | |||
|
|||
ErrStableSwapNoSwapJoinNeedsMultiAssetsIn = errors.New("no swap join needs multiple assets in, one was given") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for not making it an sdkerrors!
// N.B. we simulate the calculation by attempting to join a copy of the original pool. | ||
// The original pool is not modified. | ||
pCopy := p.Copy() | ||
numShares, tokensJoined, err = pCopy.joinPoolNoSwapSharesInternal(ctx, tokensIn, swapFee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right, because JP no swap attempts to swap when all assets are given in non-perfect ratios.
Should use cfmm_common.MaximalExactRatioJoin(p, ctx, tokensIn)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is joinPoolNoSwapSharesInternal
though that doesn't do that. I implemented a separate method, similar to how we do this in balancer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
osmosis/x/gamm/pool-models/stableswap/amm.go
Line 328 in 99dcf1c
func (p *Pool) joinPoolNoSwapSharesInternal(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error) { |
Closes: #2376
What is the purpose of the change
Implements
JoinPoolNoSwap
andCalcJoinPoolNoSwapShares
Brief Changelog
Test_StableSwap_CalculateAmountOutAndIn_InverseRelationship
wasn't run due toStableSwapTestSuite
not started. Upon properly enabling it, realized that it was breaking. Skipped it for now. To be fixed later.joinPoolSharesInternal
joinPoolSharesInternal
to utilize the no swap methodCalcJoinPoolNoSwapShares
JoinPool
to utilizeCalcJoinPoolNoSwapShares
instead of joining directly becauseCalcJoinPoolNoSwapShares
has extra validation after performing the calculationTesting and Verifying
This change added tests and can be verified as follows:
Run:
TestJoinPoolNoSwapShares
TestCalcJoinPoolNoSwapShares
TestJoinPoolNoSwapSharesInternal
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? no