diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cddafa5f59..f003b119c52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes * [1700](https://github.com/osmosis-labs/osmosis/pull/1700) Upgrade sdk fork with missing snapshot manager fix. +* [1716](https://github.com/osmosis-labs/osmosis/pull/1716) Fix secondary over-LP shares bug with uneven swap amounts in `CalcJoinPoolShares`. ## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0) diff --git a/x/gamm/pool-models/balancer/amm.go b/x/gamm/pool-models/balancer/amm.go index 54004ad7c6a..f6cd09c40f0 100644 --- a/x/gamm/pool-models/balancer/amm.go +++ b/x/gamm/pool-models/balancer/amm.go @@ -257,6 +257,7 @@ func (p *Pool) JoinPool(_ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) ( return numShares, nil } +// CalcJoinPoolShares func (p *Pool) CalcJoinPoolShares(_ sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, newLiquidity sdk.Coins, err error) { poolAssets := p.GetAllPoolAssets() poolAssetsByDenom := make(map[string]PoolAsset) @@ -293,18 +294,19 @@ func (p *Pool) CalcJoinPoolShares(_ sdk.Context, tokensIn sdk.Coins, swapFee sdk poolAssetsByDenom[coin.Denom] = poolAsset } - totalShares = totalShares.Add(numShares) + newTotalShares := totalShares.Add(numShares) // If there are coins that couldn't be perfectly joined, do single asset joins // for each of them. if !remCoins.Empty() { for _, coin := range remCoins { - newShares, err := p.calcSingleAssetJoin(coin, swapFee, poolAssetsByDenom[coin.Denom], totalShares) + newShares, err := p.calcSingleAssetJoin(coin, swapFee, poolAssetsByDenom[coin.Denom], newTotalShares) if err != nil { return sdk.ZeroInt(), sdk.NewCoins(), err } newLiquidity = newLiquidity.Add(coin) + newTotalShares = newTotalShares.Add(newShares) numShares = numShares.Add(newShares) } }