Skip to content

Commit

Permalink
add div by zero check (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
99adarsh authored Dec 9, 2024
1 parent 72b5aa5 commit 4349c0f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/amm/types/pool_calc_join_pool_no_swap_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func MaximalExactRatioJoin(p *Pool, tokensIn sdk.Coins) (numShares sdkmath.Int,
// Note: QuoInt implements floor division, unlike Quo
// This is because it calls the native golang routine big.Int.Quo
// https://pkg.go.dev/math/big#Int.Quo
// Division by zero check
if poolLiquidity.AmountOfNoDenomValidation(coin.Denom).IsZero() {
return numShares, remCoins, errors.New("pool liquidity is zero for denom: " + coin.Denom)
}
shareRatio := sdkmath.LegacyNewDecFromBigInt(coin.Amount.BigInt()).QuoInt(poolLiquidity.AmountOfNoDenomValidation(coin.Denom))
if shareRatio.LT(minShareRatio) {
minShareRatio = shareRatio
Expand Down

0 comments on commit 4349c0f

Please sign in to comment.