Skip to content

Commit

Permalink
More correctx
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Jun 8, 2022
1 parent 57b3a0b commit 73f12d5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 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,22 +294,23 @@ func (p *Pool) CalcJoinPoolShares(_ sdk.Context, tokensIn sdk.Coins, swapFee sdk
poolAssetsByDenom[coin.Denom] = poolAsset
}

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)
}
}

totalShares = totalShares.Add(numShares)

return numShares, newLiquidity, nil
}

Expand Down

0 comments on commit 73f12d5

Please sign in to comment.