From 089ce41e082351b956c4da6a7f2afbbab2b69c2b Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 9 Jun 2022 11:09:33 -0500 Subject: [PATCH] Fix second source of (minor) over-LP shares (#1716) * Fix insufficient total share creation * More correctx * changelog entry Co-authored-by: Roman --- CHANGELOG.md | 1 + x/gamm/pool-models/balancer/amm.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0171a20bcf9..b1d1953084d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,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 b81b9cb4c3c..ec54e010981 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) } }