Skip to content

Commit

Permalink
stableswap: Add check for correct input asset denoms to implementatio…
Browse files Browse the repository at this point in the history
…n of JoinPool (#2301)

* ensure that assets in pool not change after joining

* check joining assets already exist in pool

* format

* refactor panic
  • Loading branch information
hieuvubk authored Aug 4, 2022
1 parent 4c990f5 commit fd23552
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/gamm/pool-models/stableswap/amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (p *Pool) joinPoolSharesInternal(ctx sdk.Context, tokensIn sdk.Coins, swapF
numShares, err = p.calcSingleAssetJoinShares(tokensIn[0], swapFee)
newLiquidity = tokensIn
return numShares, newLiquidity, err
} else if len(tokensIn) != p.NumAssets() {
} else if len(tokensIn) != p.NumAssets() || !tokensIn.DenomsSubsetOf(p.GetTotalPoolLiquidity(ctx)) {
return sdk.ZeroInt(), sdk.NewCoins(), errors.New(
"stableswap pool only supports LP'ing with one asset, or all assets in pool")
}
Expand Down
4 changes: 4 additions & 0 deletions x/gamm/pool-models/stableswap/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func (p *Pool) updatePoolLiquidityForExit(tokensOut sdk.Coins) {
}

func (p *Pool) updatePoolForJoin(tokensIn sdk.Coins, newShares sdk.Int) {
numTokens := p.NumAssets()
p.PoolLiquidity = p.PoolLiquidity.Add(tokensIn...)
if len(p.PoolLiquidity) != numTokens {
panic(fmt.Sprintf("updatePoolForJoin changed number of tokens in pool from %d to %d", numTokens, len(p.PoolLiquidity)))
}
p.TotalShares.Amount = p.TotalShares.Amount.Add(newShares)
}

Expand Down

0 comments on commit fd23552

Please sign in to comment.