-
Notifications
You must be signed in to change notification settings - Fork 607
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
refactor: ExitSwapExternAmountOut #1244
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1244 +/- ##
==========================================
- Coverage 20.90% 20.14% -0.76%
==========================================
Files 196 203 +7
Lines 25425 26824 +1399
==========================================
+ Hits 5316 5405 +89
- Misses 19118 20412 +1294
- Partials 991 1007 +16
Continue to review full report at Codecov.
|
CHANGELOG.md
Outdated
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
### Features | |||
|
|||
* [#1244](https://github.com/osmosis-labs/osmosis/pull/1244) refactor: ExitSwapExternAmountOut |
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.
* [#1244](https://github.com/osmosis-labs/osmosis/pull/1244) refactor: ExitSwapExternAmountOut | |
* [#1244](https://github.com/osmosis-labs/osmosis/pull/1244) Refactor `x/gamm`'s `ExitSwapExternAmountOut`. |
x/gamm/pool-models/balancer/amm.go
Outdated
@@ -375,3 +375,62 @@ func (p *Pool) CalcExitPoolShares(ctx sdk.Context, exitingShares sdk.Int, exitFe | |||
} | |||
return exitedCoins, nil | |||
} | |||
|
|||
// balancer notation: pAi - poolshares amount in, given single out |
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.
// balancer notation: pAi - poolshares amount in, given single out | |
// balancer notation: pAi - pool shares amount in, given single out |
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.
What is "single out"? I'm not sure how to read this godoc :P
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.
Missed "asset" in "single out". Changed to:
// balancer notation: pAi - pool shares amount in, given single asset out
// the second argument requires the tokenWeightOut / total token weight.
Also, there is a similar function for the converse:
osmosis/x/gamm/pool-models/balancer/amm.go
Lines 188 to 190 in b9af906
// balancer notation: pAo - poolshares amount out, given single asset in | |
// the second argument requires the tokenWeightIn / total token weight. | |
func calcPoolOutGivenSingleIn( |
x/gamm/pool-models/balancer/amm.go
Outdated
p.GetSwapFee(ctx), | ||
p.GetExitFee(ctx)) | ||
|
||
if poolAmountInBeforeFee.LTE(sdk.ZeroInt().ToDec()) { |
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.
Pretty sure there is a sdk.ZeroDec
that we can use.
x/gamm/pool-models/balancer/amm.go
Outdated
return sdk.Int{}, sdkerrors.Wrapf(types.ErrInvalidMathApprox, "token amount is zero or negative") | ||
} | ||
|
||
if poolAmountInBeforeFee.GT(shareInMaxAmount.ToDec()) { |
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.
I'm not super familiar with the balancer amm arithmetic yet, but why do we compare balances to shares here?
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.
We should rename calcPoolOutGivenSingleIn
to calcPoolSharesOutGivenSingleIn
and the same for the variable, then this makes sense / is correct.
Thanks for catching this
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.
Although renaming calcPoolOutGivenSingleIn to calcPoolSharesOutGivenSingleIn makes sebse, I'm assuming that you are referring to renaming calcPoolInGivenSingleOut to calcPoolSharesInGivenSingleAssetOut in this particular example of ExitSwapExternAmountOut
?
if err != nil { | ||
return sdk.Int{}, err | ||
} | ||
|
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.
We need to update the total shares as well, ala
Maybe we refactor share updating + token balance updating for exits into a single re-used function between the two?
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.
Good idea, I extracted this functionality from ExitPool
into exitPool
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.
Nice! That change LGTM
…haresInGivenSingleAssetOut
…nAmountOutCmd uncommented
Closes: #1130
Description
ExitSwapExternAmountOut
with similar logic to v7PoolExitSwapExternAmountOutExtension
Risks
I was confused about the following part:
osmosis/x/gamm/keeper/pool_service.go
Lines 533 to 543 in 523ed35
I think that instead of doing that, it is possible to call
k.applyExitPoolStateChange(...)
so that it takes care of the fee since it doesk.BurnPoolShareFromAccount(ctx, pool, exiter, numShares)
wherenumShares
do not have theexitFee
subtracted.It seems to me that in the old logic subtracting the fee only to burn it separately was redundant, and I'm not sure if I'm missing some algebra reasoning behind it.
Next Steps
I'm planning to spend some time writing more unit tests for this in a separate PR. Then, spearhead more e2e tests by joining a swap and exiting it using this method.
For contributor use:
docs/
) or specification (x/<module>/spec/
)Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorer