Skip to content

Commit

Permalink
Fix second source of (minor) over-LP shares (#1716)
Browse files Browse the repository at this point in the history
* Fix insufficient total share creation

* More correctx

* changelog entry

Co-authored-by: Roman <[email protected]>
(cherry picked from commit 089ce41)
  • Loading branch information
ValarDragon authored and mergify[bot] committed Jun 9, 2022
1 parent 2a729f8 commit 3025863
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions x/gamm/pool-models/balancer/amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 3025863

Please sign in to comment.